jQuery.noConflict();
function login(){
	var loginName = $('#loginName').val();
	var loginPwd = $('#loginPwd').val();
	var loginVerfy = $('#loginVerfy').val();
	if(loginName==''){
    	WST.msg('请输入账号','info');
        return false;
    }
	if(loginPwd==''){
    	WST.msg('请输入密码','info');
        return false;
    }
	if(loginVerfy==''){
    	WST.msg('请输入验证码','info');
        return false;
    }
	WST.load('登录中···');
    var param = {};
    param.loginName = loginName;
    param.loginPwd = loginPwd;
    param.verifyCode = loginVerfy;
	$('#loginButton').addClass("active").attr('disabled', 'disabled');
    $.post(WST.U('mobile/users/checkLogin'), param, function(data){
        var json = WST.toJson(data);
        if( json.status == 1 ){
        	WST.msg('登录成功','success');
        	var url = json.url;
            setTimeout(function(){
            	if(WST.blank(url)){
            		location.href = url;
            	}else{
                	location.href = WST.U('mobile/users/index');
            	}
            },2000);
        }else{
        	WST.msg(json.msg,'warn');
        	WST.getVerify("#verifyImg1");
        	$('#loginButton').removeAttr('disabled').removeClass("active");
        }
        WST.noload();
        data = json = null;
    });
}
function login2(){
	var loginName = $('#regName').val();
	var mobileCode = $('#phoneCode').val();
	if(loginName==''){
		WST.msg('请输入手机号','info');
		return false;
	}
	if(mobileCode==''){
		WST.msg('请输入短信验证码','info');
		return false;
	}

	WST.load('登录中···');
	var param = {};
	param.loginNamea = loginName;
	param.mobileCode = mobileCode;
	$('#loginButton').addClass("active").attr('disabled', 'disabled');
	$.post(WST.U('mobile/users/checkLoginByPhone'), param, function(data){
		var json = WST.toJson(data);
		if( json.status == 1 ){
			WST.msg(json.msg,'success');
			var url = json.url;
			setTimeout(function(){
				if(WST.blank(url)){
					location.href = url;
				}else{
					location.href = WST.U('mobile/users/index');
				}
			},2000);
		}else{
			WST.msg(json.msg,'warn');
			WST.getVerify("#verifyImg3");
			$('#loginButton').removeAttr('disabled').removeClass("active");
		}
		WST.noload();
		data = json = null;
	});
}
var nameType = 3;
function onTesting(obj){
	//不能输入中文
	WST.isChinese(obj,1);
	var data = $(obj).val();
	var  regMobile = /^0?1[3|4|5|8][0-9]\d{8}$/;
	if(regMobile.test(data)){//手机
	    $.post(WST.U('mobile/users/checkUserPhone'), {userPhone:data}, function(data){
	        var json = WST.toJson(data);
	        if( json.status == 1 ){
	        }else{
	    	    var dia=$.dialog({
	    	        title:'',
	    	        content:'<p style="text-align: center;">手机号已注册</p>',
	    	        button:["确认"]
	    	    });
	        }
	        data = json = null;
	    });
	}
}

//type=1账号注册，type=2手机注册
function register(type){
	var regName = (type==2)?$('#regName').val():$('#regName2').val();
	var regPwd = (type==2)?$('#regPwd').val():$('#regPwd2').val();
	var regcoPwd = (type==2)?$('#regcoPwd').val():$('#regcoPwd2').val();
    var param = {};
    if(type==1){
        var verifyCode = $('#verifyCode').val();
        if($('#defaults').hasClass('ui-icon-unchecked-s')){
            WST.msg('请阅读用户注册协议','info');
            return false;
        }
        if(regName==''){
            WST.msg('请输入用户名','info');
            return false;
        }
        if(regName.length < 6){
            WST.msg('用户名为6位以上数字或字母或下划线','info');
            return false;
        }
        if(verifyCode==''){
            WST.msg('请输入图形验证码','info');
            return false;
        }
        param.verifyCode = verifyCode;
    }else{
        var phoneCode = $('#phoneCode').val();
        if($('#defaults2').hasClass('ui-icon-unchecked-s')){
            WST.msg('请阅读用户注册协议','info');
            return false;
        }
        if(regName==''){
            WST.msg('请输入手机号','info');
            return false;
        }
        if(window.conf.SMS_OPEN==1 && phoneCode==''){
            WST.msg('请输入短信验证码','info');
            return false;
        }
        param.mobileCode = phoneCode;
    }
	if(regPwd==''){
    	WST.msg('请输入密码','info');
        return false;
    }
	if(regPwd.length < 6 || regPwd.length > 16){
	    WST.msg('请输入密码为6-16位字符','info');
	    return false;
	}
	if(regcoPwd==''){
    	WST.msg('请输入确认密码','info');
        return false;
    }
    if(regcoPwd.length < 6 || regcoPwd.length > 16){
        WST.msg('请输入确认密码为6-16位字符','info');
        return false;
    }
	if(regPwd!=regcoPwd){
    	WST.msg('两次输入的密码不一致','info');
        return false;
    }
	WST.load('注册中···');
    param.loginName = regName;
    param.loginPwd = regPwd;
    param.reUserPwd = regcoPwd;
    param.type = type;
    if(type==1) {
        $('#regButton2').addClass("active").attr('disabled', 'disabled');
    }else{
        $('#regButton').addClass("active").attr('disabled', 'disabled');
    }
    $.post(WST.U('mobile/users/register'), param, function(data){
        var json = WST.toJson(data);
        if( json.status == 1 ){
        	WST.msg('注册成功','success');
        	var url = json.url;
            setTimeout(function(){
            	if(WST.blank(url)){
            		location.href = url;
            	}else{
                	location.href = WST.U('mobile/users/index');
            	}
            },2000);
        }else{
        	WST.msg(json.msg,'warn');
            if(type==1) {
                WST.getVerify("#verifyImg4");
                $('#regButton2').removeAttr('disabled').removeClass("active");
            }else{
                WST.getVerify("#verifyImg3");
                $('#regButton').removeAttr('disabled').removeClass("active");
            }
        }
        WST.noload();
        data = json = null;
    });
}

var time = 0;
var isSend = false;
function obtainCode(type){
	var userPhone = $('#regName').val();
	if(userPhone ==''){
		WST.msg('请输入帐号为手机号码','info');
		$('#regName').focus();
		return false;
	}
	if(WST.conf.SMS_VERFY==1){
		var smsVerfy = $('#smsVerfy').val();
		if(smsVerfy ==''){
			WST.msg('请输入验证码','info');
			$('#smsVerfy').focus();
			return false;
		}
	}
	var param = {};
	param.userPhone = userPhone;
	param.smsVerfy = smsVerfy;
	if(isSend)return;
	isSend = true;
	var url = 'mobile/users/getPhoneVerifyCode';
	if(type==2){
		url = 'mobile/users/getPhoneVerifyCode2';
	}
	$.post(WST.U(url), param, function(data){
		var json = WST.toJson(data);
		if( json.status == 1 ){
			WST.msg(json.msg,'success');
			time = 120;
			var href = $('#obtain').attr('href');
			$('#obtain').attr('href', 'javascript:void(0)').html('120秒获取');
			var task = setInterval(function(){
				time--;
				$('#obtain').html(''+time+"秒获取");
				if(time==0){
					isSend = false;
					clearInterval(task);
					$('#obtain').attr('href', href).html("重新发送");
				}
			},1000);
		}else{
			WST.msg(json.msg,'warn');
			WST.getVerify("#verifyImg3");
			isSend = false;
		}
		data = json = null;
	});
}
//弹框
function wholeShow(type){
    jQuery('#'+type).animate({"right": 0}, 500);
}
function wholeHide(type){
    var dataWidth = $('#'+type).css('width');
    jQuery('#'+type).animate({'right': '-'+dataWidth}, 500);
}
//协议
function inAgree(obj,type){
    if(type==1){
        if($('#defaults').hasClass('wst-active')){
            $(obj).addClass('ui-icon-unchecked-s');
            $(obj).removeClass('ui-icon-success-block wst-active');
        }else{
            $(obj).removeClass('ui-icon-unchecked-s');
            $(obj).addClass('ui-icon-success-block wst-active');
        }
    }else{
        if($('#defaults2').hasClass('wst-active')){
            $(obj).addClass('ui-icon-unchecked-s');
            $(obj).removeClass('ui-icon-success-block wst-active');
        }else{
            $(obj).removeClass('ui-icon-unchecked-s');
            $(obj).addClass('ui-icon-success-block wst-active');
        }
    }
}
$(document).ready(function(){
	var w = WST.pageWidth();
	var h = WST.pageHeight();
    $('#protocol .content').css('overflow-y','scroll').css('height',h-61);
    $("#protocol").css('right',-w);
});