﻿var n = 0;
var debug = false;

$(function() {
	sp.Reg.initBackground();
	function btnhover(cls){
		//cls.hover(function(){$(this).addClass("hov");},function(){$(this).removeClass("hov");})
	}
	btnhover($(".btn input"));
	
	//文本框获取焦点和失去焦点事件
		function inputfunc(){
		$("input:text").each(function(){
			var v = $(this).val();
			$(this).attr("v",v);
		})
		$("input:password").blur(function(){
			if($(this).val()=="")
			$(this).next(".passpan").show();
		}).focus(function(){
			$(this).next(".passpan").hide();
		}) 
		$("input.text").each(function(e){
			$(this).focus(function(){
			    var v = $(this).attr("v");
				if($(this).val() == $(this).attr("v")){
					if(e==0 && $(this).val() != "Email/手机号"){
					    $(this).attr("value",v);	
					}else{
					    $(this).attr("value","");	
					}
				}
				$(this).addClass("focus").removeClass("font");
				
			})
			$(this).blur(function(){
				if($(this).val()=="" || $(this).val() == $(this).attr("v")){
					$(this).attr("value",$(this).attr("v"));
					$(this).removeClass("focus");
					if(e==0 && $(this).val() != "Email/手机号"){
					    $(this).addClass("font");
					 }else{
					    $(this).removeClass("font");
					}
				}else{
					$(this).removeClass("focus").addClass("font");
				}
			})
			$(this).mouseover(function(){	
				$(this).addClass("hovs");					   
			}).mouseout(function(){
				$(this).removeClass("hovs");
			})
		})
		if($("input.text").eq(0).val() != "Email/手机号"){
		    $("input.text").eq(0).addClass("font");
	    };
	    $(".def").each(function(e){
		    $(this).one("click",function(){
		        var val = $(this).val();
		        if(e==0 && $(this).val() != "Email/手机号"){
			    	$(this).attr("value",val);
			    }else{
			        $(this).attr("value","");
			        $(this).removeClass("def");	
			    }			
		    })
		})
		$(".passpan").click(function(){
		$(this).hide();	
		$(this).prev().focus();
	})
	}
	inputfunc();
	
		//按钮切换效果
	function btnhov(cls){
		$("."+cls).hover(function(){
			var imgurl = $(this).attr("hov");
			var imgsrc = $(this).attr("src");
			$(this).attr("src",imgurl);	
			$(this).attr("hov",imgsrc);
		},function(){
			var imgurl = $(this).attr("hov");
			var imgsrc = $(this).attr("src");
			$(this).attr("src",imgurl);	
			$(this).attr("hov",imgsrc);
		})
	}
	btnhov("imgbtn");
	btnhov("funcbtn img");
	//切换背景图片
	var n = Math.round(Math.random()*10) % 3;
	$("#btn1").click(function(){
		$(".func").append('<div id="loading"><img src="../images/loadinfo.gif" /></div>');
		num();
	})
	function getImg(n){
	    var url = '/getloginbg.html?'+new Date().getTime();
		$.get(url,{"num":n},function(data){	
			$("#background").html(data);
			$("#background").fadeIn("slow");
			$("#loading").remove();	
			$(window).trigger('resize');								   
		})	
	}
	function num(){
//		n++;
//		if(n>=4){n=1;}
        n = 2;
		getImg(n);
//		$(window).trigger('resize');
//		$("#background").fadeIn("slow");								   
	}
	$("#btn2").click(function(){
	    var url = '/saveloginbg.html?'+new Date().getTime() + "&num="+n;
		window.location.href = url;
	})
	//
	$(".Forget").bind("click",function(){
		$("#login").hide();
		$("#login form")[0].reset();
		bindInputFocusEvent("login");
		$("#Forget").fadeIn(500);
		$(".signin").animate({height:242},300,function(){});
		$("#footer").animate({top:242},300,function(){});
				$(".rongzi").animate({top:198},300,function(){});
		Callback("Forget");
		return false;
	})
	$(".actbtn").bind("click",function(){
		$("#login").hide();
		$("#login form")[0].reset();
		bindInputFocusEvent("login");
		$("#act").fadeIn(500);
		$(".signin").animate({height:242},300,function(){});
		$("#footer").animate({top:242},300,function(){});
			$(".rongzi").animate({top:198},300,function(){});
		Callback("act");
		return false;
	})
//	$(".resbtn").bind("click",function(){
//		$("#login").hide();
//		$("#login form")[0].reset();
//		bindInputFocusEvent("login");
//		$("#res").fadeIn(500);
//		$(".signin").animate({height:295},300,function(){});
//		$("#footer").animate({top:305},300,function(){});
//		Callback("res");
//		return false;
//	})
	$("#btnApplySuccess").bind("click",function(){
		$("#login").fadeIn(500);
		$("#shenqingv").hide();
		$(".signin").animate({height:192},300,function(){});
					//	$(".rongzi").animate({top:300},300,function(){});
		$("#footer").animate({top:202},300,function(){});

		return false;
	})		
	$("#btnRetrievePwdSuccess").bind("click",function(){
        $("#login").fadeIn(500);
        $("#Forgetv").hide();
        $(".signin").animate({height:192},300,function(){});
        $(".rongzi").animate({top:185},300,function(){});  
        $("#footer").animate({top:227},300,function(){});
        return false;
	})
	$("#btnCreateAccountSuccess").bind("click",function(){
        $("#login").fadeIn(500);
        $("#complatev").hide();
        $(".signin").animate({height:192},300,function(){});
        $("#footer").animate({top:202},300,function(){});
        return false;
	})		
	function Callback(id){
		$(".back").bind("click",function(){
			$("#login").fadeIn(500);
			$("#"+id).hide();
			$("#"+id+ " form")[0].reset();
			bindInputFocusEvent(id);
			$(".signin").animate({height:206},300,function(){});
			$("#footer").animate({top:242},300,function(){});
				$(".rongzi").animate({top:198},300,function(){});
			resetValidateTipState();
			return false;
		})
	}
//	$("#formSignIn_MailAddress").bind("blur", function(){validateLoginName(this.value)})
//	$("#formSignIn_MailAddress").bind("focus", function(){clearLoginErrorMsg()})
//	$("#formSignIn_Password").bind("blur", function(){validateLoginPassword(this.value)})
//	$("#formSignIn_Password").bind("focus", function(){clearLoginErrorMsg()})
	$("#btnLogin").bind("click", function(){clickLogin()})
	$("#btnLogin").bind("blur", function(){resetStyle()})
	$("#btnRetrievePwd").bind("click", function(){clickRetrievePwd()})
	$("#btnMemberApply").bind("click", function(){clickMemberApply()})
	$("#btnActivateAccount").bind("click", function(){clickActivateAccount()})
	$("#btnCreateAccount").bind("click", function(){clickCreateAccount()})
	
	$("#formSignIn_Password").blur(function(){
			if($(this).val()=="")
			$(this).next(".passpan").show();
		}).focus(function(){
			$(this).next(".passpan").hide();
		})
//	
//	$("#formRetrievePwd_MailAddress").bind("focus", function(){clearRetrievePwdMsg()})
	num();
	
	var url = location.href;  
	var str = url.split("code=");
	if(str[1] != undefined){
			$("#login").hide();
		    $("#login form")[0].reset();
		    bindInputFocusEvent("login");
		    $("#act").fadeIn(500);

		    $(".signin").animate({height:135},300,function(){});
		    $("#footer").animate({top:145},300,function(){});
		    Callback("act");
	}
});

function resetStyle()
{
    $("#formSignIn_MailAddress").removeClass("error");
    $("#formSignIn_Password").removeClass("error");
}

function bindInputFocusEvent(parentId)
{
    $("#"+parentId+" .def").one("focus",function(){
	    if (this.defaultValue == this.value)
	    { 
	        $(this).attr("value","");
	    }
	    });
	 clearLoginErrorMsg();      
}

function validateLoginName(input, id)
{
    var result = true;
    var defaultValue = $("#formSignIn_MailAddress")[0].defaultValue; 
    if (!isEmptyString(input) && input != '手机号/Email')
    {
        if (!isEmail(input))
        {
            if (!isMobile(input))
            {
                result = false; 
            }   
        }   
    }
    else
    {
        result = false; 
    }
   return result;      
}

function validateLoginPassword(input)
{
    var result = true;
    if (isEmptyString(input))
    {
        result = false; 
    }
    return result;  
}

function loginClick()
{
    if (validateLoginName($("#formSignIn_MailAddress").val()))
    {
        if (validateLoginPassword($("#formSignIn_Password").val()))
        {
            $("#formSignIn").submit(); 
        }   
    } 
}

function clickLogin()
{
    validate("5");
}

function clickRetrievePwd()
{
    validate("1");
}

function submitRetrievePwd()
{
    var data = getRequestBody("formRetrievePwd");
    var url = "/RetrievePwdPost.html"; 
    $.ajax({
      type: "POST",
      url: url,
      data: data,
      complete: function(msg){ 
					    retrievePwdSuccess(msg.responseText);
		       },
      dataType : "html"
     }); 
}

function retrievePwdSuccess(msg)
{
    switch(msg)
    {
        case "1" :
            $("#Forget").hide();
	        $("#Forgetv").fadeIn(500);
	        $(".signin").animate({height:250},300,function(){});
	      	$(".rongzi").animate({top:230},300,function(){}); 
	        $("#footer").animate({top:260},300,function(){}); 
        break;
        default :
            showErrorMsg("formRetrievePwd_MailAddress", "Email：您填写的邮箱账号不存在"); 
        break;    
    }  
}

function clickMemberApply()
{
    validate("2");
}

function submitMemberApply()
{
        var data = getRequestBody("formMemberApply");
        var url = "/MemberApplyPost.html"; 
        $.ajax({
	      type: "POST",
	      url: url,
	      data: data,
	      complete: function(msg){ 
						    memberApplySuccess(msg.responseText);
			       },
	      dataType : "html"
	     }); 
}

function memberApplySuccess(msg)
{
        switch(msg)
        {
            case "1" :  
                $("#res").hide();
		        $("#shenqingv").fadeIn(500);
		        $(".signin").animate({height:295},300,function(){});
		        $("#footer").animate({top:305},300,function(){});
		    break;
		    case "2" :  
                $("#formMemberApply_Mobile_msg").html("该Email或手机已被使用");
                $("#formMemberApply_Mobile_msg").removeClass("onCorrect");
                $("#formMemberApply_Mobile_msg").addClass("onError");
		        break;
		   default  :
		        if (debug)
		        {  
		            alert(msg);  
		        }    
		    break; 
		}    
}

function clickActivateAccount()
{
    validate("3");
}

function submitActivateOptional()
{
if($("#formCreateAjaxAccountNocode_Serialno").val()=="" || $("#formCreateAjaxAccountNocode_Serialno").val()=="输入可得到优惠或方便找到朋友")
{
 $("#formCreateAjaxAccountNocode_Serialno_msg").html(""); return;
}
$("#formCreateAjaxAccountNocode_Serialno").val($("#formCreateAjaxAccountNocode_Serialno").val().replace("输入可得到优惠或方便找到朋友",""));

   var data = getRequestBody("formActivateAccount2");
        var url = "/ActivateAccountPost.html"; 
        $.ajax({
	      type: "POST",
	      url: url,
	      data: data,
	      complete: function(msg){ 
						      switch(msg.responseText)
                                        {
                     
                                            case "1" :
                                              $("#formCreateAjaxAccountNocode_Serialno_msg").html(""); 
                                            break;
                                              default :
                                             $("#formCreateAjaxAccountNocode_Serialno_msg").html("您输入的邀请码无效"); 
                                             break;
                                            }
			       },
	      dataType : "html"
	     }); 
}

function submitActivate()
{
   var data = getRequestBody("formActivateAccount");
        var url = "/ActivateAccountPost.html"; 
        $.ajax({
	      type: "POST",
	      url: url,
	      data: data,
	      complete: function(msg){ 
						    submitActivateSuccess(msg.responseText);
			       },
	      dataType : "html"
	     }); 
}

function submitActivateSuccess(msg)
{
    switch(msg)
    {
        case "1" :
        $("#registerdiv").show();
//            window.location.href = "/perfect.html";
//            $("#act").hide();
//	        $("#complate").slideDown(500);
//	        $(".signin").animate({height:295},300,function(){});
//	        $("#footer").animate({top:305},300,function(){});
//	        $(".back").bind("click",function(){
//			        $("#login").fadeIn(500);
//			        $("#complate").hide();
//			        $(".signin").animate({height:192},300,function(){});
//			        $("#footer").animate({top:202},300,function(){});
//			        resetValidateTipState();
//			        return false; 
//		        });
	   break;
	   default :
	        if (debug)
	        {
	            alert(msg); 
	        }  
	        else
	       {  
	            showErrorMsg("formActivateAccount_ActivateCode", "邀请码：您输入的邀请码无效");
	       }     
	        break;
	 }        
}

function clickCreateAccount()
{
    validate("4");
}

function submitCreateAccount()
{
     var data = getRequestBody("formRegister");
     var url = "/RegisterPost.html"; 
     $.ajax({
      type: "POST",
      url: url,
      data: data,
      complete: function(msg){ 
					    submitCreateAccountSuccess(msg.responseText);
		       },
      dataType : "html"
     }); 
}

function submitCreateAccountSuccess(msg)
{
    switch(msg)
    { 
        case "1" : 
            $("#complate").hide();
            $("#complatev").fadeIn(500);
            $(".signin").animate({height:295},300,function(){});
            $("#footer").animate({top:305},300,function(){});
            $(".back").bind("click",function(){
	                $("#login").fadeIn(500);
	                $("#complatev").hide();
	                $(".signin").animate({height:192},300,function(){});
	                $("#footer").animate({top:202},300,function(){});
	                resetValidateTipState();
	                return false; 
                });
        break;
        default :
            if (debug)
            {
                alert(msg); 
            }   
            break; 
    }          
}

function showErrorMsg(id, msg)
{
//    $("#" + id).addClass("error");
    $("#" + id + "_msg").html(msg);
    $("#" + id + "_msg").removeClass();
    $("#" + id).addClass("error") 
    $("#" + id + "_msg").addClass("onError"); 
}

function clearErrorMsg(id, msg)
{
//    $("#" + id).removeClass("error");
    $("#" + id + "_msg").html(msg);
    $("#" + id + "_msg").removeClass("error"); 
}

function clearLoginErrorMsg()
{
    $("#formSignIn_Error_msg").html("");
}

function showLoginErrorMsg(msg)
{
    $("#formSignIn_Error_msg").html(msg);
}

function validateMailAddress(value, id)
{
    $("#formValidateEmail_MailAddress").val(value);
    var data = getRequestBody("formValidateEmail");
     var url = "/ValidateEmailPost.html"; 
     $.ajax({
      type: "POST",
      url: url,
      data: data,
      complete: function(msg){ 
					    validateMailAddressSuccess(msg.responseText, id);
		       },
      dataType : "html"
     });  
    return true;
}

function validateMailAddress1(value, id)
{
    $("#formValidateEmail_MailAddress").val(value);
    var data = getRequestBody("formValidateEmail");
     var url = "/ValidateEmailPost.html"; 
     $.ajax({
      type: "POST",
      url: url,
      data: data,
      complete: function(msg){ 
					    validateMailAddressSuccess1(msg.responseText, id);
		       },
      dataType : "html"
     });  
    return true;
}

function validateMailAddressSuccess1(msg, input)
{
    switch(msg)
    {
        case "-1" :
            showErrorMsg(input.id, "Email：Email已经被注册");
        break;
       default :
       break;    
    }  
}

function validateMobile1(value, id)
{
    $("#formValidateEmail_MailAddress1").val(value);
    var data = getRequestBody("formValidateEmail1");
     var url = "/ValidateEmailPost.html"; 
     $.ajax({
      type: "POST",
      url: url,
      data: data,
      complete: function(msg){ 
					    validateMobileSuccess1(msg.responseText, id);
		       },
      dataType : "html"
     });  
    return true;
}

function validateMobileSuccess1(msg, input)
{
    switch(msg)
    {
        case "-1" :
            showErrorMsg(input.id, "手机：手机已经被注册");
        break;
       default :
       break;    
    }  
}

function validateMailAddressSuccess(msg, input)
{
    switch(msg)
    {
        case "-1" :
            showErrorMsg(input.id, "Email：Email已经被注册");
        break;
       default :
       break;    
    }  
}

$(
		function()
		{	
		    $.formValidator.initConfig(
			{
				autotip: true,
				errorfocus: false,
				onsuccess: function(){submitRetrievePwd();},
				validatorgroup: "1"
			});
			$("#formRetrievePwd_MailAddress")
			    .formValidator(
					{
						validatorgroup: "1",
						tipid: "formRetrievePwd_MailAddress_msg",
						onshow: "Email：",
						onfocus: "Email：",
						oncorrect: "Email：",
						defaultvalue: ""
					})
			    .inputValidator(
					{
						min: 1,
						onerror: "Email：请填写注册时的Email"
					})
			    .regexValidator(
					{
						regexp: "email",
						datatype: "enum",
						onerror: "Email：请填写正确Email"
					});
			$.formValidator.initConfig(
				{
					autotip: true,
					errorfocus: false,
					onsuccess: function(){submitMemberApply();},
					validatorgroup: "2"
			});
			$("#formMemberApply_TrueName")
			    .formValidator(
					{
						validatorgroup: "2",
						tipid: "formMemberApply_TrueName_msg",
						onshow: "姓名：",
						onfocus: "姓名：",
						oncorrect: "姓名：",
						defaultvalue: ""
					})
			    .inputValidator(
					{
						min: 1,
						defaultvalue:"姓名",
						onerror: "姓名：请填写姓名"
					})
			    .regexValidator(
					{
						regexp: "chinese",
						datatype: "enum",
						onerror: "姓名：请填写正确的中文姓名"
					});
			$("#formMemberApply_MailAddress")
				.formValidator(
					{
						validatorgroup: "2",
						tipid: "formMemberApply_MailAddress_msg",
						onshow: "Email：",
						onfocus: "Email：",
						oncorrect: "Email："
					})
			    .inputValidator(
					{
						min: 1,
						defaultvalue:"Email",
						onerror: "Email：请填写Email"
					})
			    .regexValidator(
					{
						regexp: "email",
						datatype: "enum",
						onerror: "Email：请填写正确的Email"
					})
					.functionValidator(
				    {
				        fun: validateMailAddress1,
				        onerror: ""
				     })	;
			$("#formMemberApply_Mobile")
				.formValidator(
					{
						validatorgroup: "2",
						tipid: "formMemberApply_Mobile_msg",
						onshow: "手机：",
						onfocus: "手机：",
						oncorrect: "手机："
					})
			    .inputValidator(
					{
						min: 1,
						defaultvalue:"手机号",
						onerror: "手机：请填写手机号"
					})
			    .regexValidator(
					{
						regexp: "mobile",
						datatype: "enum",
						onerror: "手机：请填写正确的手机号"
					})
					.functionValidator(
				    {
				        fun: validateMobile1,
				        onerror: ""
				     })	;
			$("#formMemberApply_Corporation")
				.formValidator(
					{
						validatorgroup: "2",
						tipid: "formMemberApply_Corporation_msg",
						onshow: "行业：",
						onfocus: "行业：",
						oncorrect: "行业："
					})
			    .inputValidator(
					{
						min: 1,
						defaultvalue:"行业",
						onerror: "行业：请填写行业"
					});
			$("#formMemberApply_Position")
				.formValidator(
					{
						validatorgroup: "2",
						tipid: "formMemberApply_Position_msg",
						onshow: "职位：",
						onfocus: "职位：",
						oncorrect: "职位："
					})
			    .inputValidator(
					{
						min: 1,
						defaultvalue:"职位",
						onerror: "职位：请填写职位"
				});		
            $.formValidator.initConfig(
			{
				autotip: true,
				errorfocus: false,
				onsuccess: function(){submitActivate();},
				validatorgroup: "3"
			});
			$("#formActivateAccount_ActivateCode")
			    .formValidator(
					{
						validatorgroup: "3",
						tipid: "formActivateAccount_ActivateCode_msg",
						onshow: "邀请码：",
						onfocus: "邀请码：",
						oncorrect: "邀请码：",
						defaultvalue: ""
					})
			    .inputValidator(
					{
						min: 1,
						defaultvalue:"输入邀请码",
						onerror: "邀请码：请填写邀请码"
					});
			$.formValidator.initConfig(
			{
				autotip: true,
				errorfocus: false,
				onsuccess: function(){submitCreateAccount();},
				validatorgroup: "4"
			});
			$("#formRegister_MailAddress")
			    .formValidator(
					{
						validatorgroup: "4",
						tipid: "formRegister_MailAddress_msg",
						onshow: "Email：",
						onfocus: "Email：",
						oncorrect: "Email：",
						defaultvalue: ""
					})
			    .inputValidator(
					{
						min: 1,
						onerror: "Email：请填写Email"
					})
				.regexValidator(
					{
						regexp: "email",
						datatype: "enum",
						onerror: "Email：请填写正确的Email"
					})
				.functionValidator(
				    {
				        fun: validateMailAddress,
				        onerror: ""
				     })	;
				$("#formRegister_Password")
			    .formValidator(
					{
						validatorgroup: "4",
						tipid: "formRegister_Password_msg",
						onshow: "设置密码：",
						onfocus: "设置密码：",
						oncorrect: "设置密码：",
						defaultvalue: ""
					})
			    .inputValidator(
					{
						min: 6,
						max: 16,
						onerror: "设置密码：6-16位中英文数字"
					})
				.regexValidator(
					{
						regexp: "password",
						datatype: "enum",
						onerror: "设置密码：6-16位中英文数字"
					});			
				$("#formRegister_CPassword")
			    .formValidator(
					{
						validatorgroup: "4",
						tipid: "formRegister_CPassword_msg",
						onshow: "确认密码：",
						onfocus: "确认密码：",
						oncorrect: "确认密码：",
						defaultvalue: ""
					})
			    .inputValidator(
					{
						min: 6,
						max: 16,
						onerror: "确认密码：请填写6-16位字母或数字"
					})
				.regexValidator(
					{
						regexp: "password",
						datatype: "enum",
						onerror: "确认密码：请填写6-16位字母或数字"
					})
				 .compareValidator(
				    {
				        desid: "formRegister_Password",
				        operateor: "=",
				        datatype: "string",
				        onerror: "确认密码：两次输入的密码不一致,请重新输入!"
				    });				
				  $("#formRegister_TrueName")
			    .formValidator(
					{
						validatorgroup: "4",
						tipid: "formRegister_TrueName_msg",
						onshow: "真实姓名：",
						onfocus: "真实姓名：",
						oncorrect: "真实姓名：",
						defaultvalue: ""
					})
			    .inputValidator(
					{
						min: 1,
						onerror: "真实姓名：请填写真实姓名"
					})
			    .regexValidator(
					{
						regexp: "chinese",
						datatype: "enum",
						onerror: "真实姓名：请填写正确的中文姓名"
					});
			$.formValidator.initConfig(
			{
				autotip: true,
				errorfocus: false,
				onsuccess: function(){loginClick();},
				validatorgroup: "5"
			});
			$("#formSignIn_MailAddress")
			    .formValidator(
					{
						validatorgroup: "5",
						tipid: "formSignIn_Error_msg",
						//onshow: "",
						//onfocus: " ",
						oncorrect: " ",
						defaultvalue: ""
					})
			    .functionValidator(
				    {
				        fun: validateLoginName,
				        defaultvalue: "手机号/Email",
				        onerror: "请填写正确邮箱或手机号"
				     })	;	
				$("#formSignIn_Password")
			    .formValidator(
					{
						validatorgroup: "5",
						tipid: "formSignIn_Error_msg",
						onshow: "",
						onfocus: " ",
						oncorrect: " ",
						defaultvalue: ""
					})
				.functionValidator(
				{
				    fun : validateLoginPassword,
				    defaultvalue:"      ",
				    onerror: "请填写密码"
				})	
			    .inputValidator(
					{
						min: 6,
						max: 16,
						defaultvalue:"      ",
						onerror: "密码可使用6-16位字母或数字"
					})				
		
		}
)

function validate(group)
{
	return $.formValidator.pageIsValid(group);
}

function resetValidateTipState()
{
     $.formValidator.resetTipState("1");   
     $.formValidator.resetTipState("2");    
     $.formValidator.resetTipState("3"); 
}

$(function()
{
    if(document.addEventListener)
    {
        document.addEventListener("keypress",defaultPost, true);
    }
    else
    {
        document.attachEvent("onkeydown",defaultPost);
    }
})					

function defaultPost(evt)
{
    if(evt.keyCode==13)
    {
        if(document.getElementById("login").style.display!="none")
        {
            document.getElementById("btnLogin").click();
            return false;
        }
        else if(document.getElementById("act").style.display!="none")
        {
            document.getElementById("btnActivateAccount").click();
            return false;
        }
        else if(document.getElementById("res").style.display!="none")
        {
            document.getElementById("btnMemberApply").click();
            return false;
        }
        else if(document.getElementById("shenqingv").style.display!="none")
        {
            document.getElementById("btnApplySuccess").click();
            return false;
        }
        else if(document.getElementById("Forget").style.display!="none")
        {
            document.getElementById("btnRetrievePwd").click();
            return false;
        }
        else if(document.getElementById("Forgetv").style.display!="none")
        {
            document.getElementById("btnRetrievePwdSuccess").click();
            return false;
        }
        else if(document.getElementById("complate").style.display!="none")
        {
            document.getElementById("btnCreateAccount").click();
            return false;
        }
        else if(document.getElementById("complatev").style.display!="none")
        {
            document.getElementById("btnCreateAccountSuccess").click();
            return false;
        }
    }
}

function setErr(id, errInfo)
{
    $("#" + id + "_msg").addClass("error");
    $("#" + id + "_msg").html(errInfo); 
    $("#" + id).addClass("error"); 
}

function removeErr(id, info)
{
    $("#" + id + "_msg").removeClass("error");
    if (info != "")
    {
        $("#" + id + "_msg").html(info); 
    }   
    $("#" + id).removeClass("error"); 
}

function removeErrorInfo(id, info)
{
    $("#" + id + "_msg").removeClass("error");    
    $("#" + id + "_msg").html(info);   
}

function DIVShow(i){
    if( document.getElementById(i).style.display=='')
       //document.getElementById(i).style.display = 'none';
       $("#"+i).fadeOut(600);
       //document.getElementById(i).style.display = 'none';
    else
       //document.getElementById(i).style.display = '';
       $("#"+i).fadeIn(600);
       $("#shenqing_s1").show();
       $("#shenqing_s2").hide();
       document.getElementById(i).style.display = '';
}

function clearErrorInfo()
{
    $("#formSMemberApply_TrueName").val("请输入您的真实姓名");
    $("#formSMemberApply_MailAddress").val("请使用常用Email地址作为登录名");
    $("#formSMemberApply_Mobile").val("方便您接收通过审核信息");
    removeErrorInfo("formSMemberApply_TrueName", "");
    removeErrorInfo("formSMemberApply_MailAddress", "");
    removeErrorInfo("formSMemberApply_Mobile", "");
    $("#formMemberApply_Leaveword").html("");
    $("#formMemberApply_Leaveword").val("");
    //$("#hidden").hide();
    $("#hidden").fadeOut(600);
   
   //
    $("#formCreateAjaxAccountNocode_MailAddress").val("请使用常用Email地址作为登录名");
    $("#formCreateAjaxAccountNocode_Password").val("");
    $("#formCreateAjaxAccountNocode_Password").siblings().html("设置密码");
    $("#formCreateAjaxAccountNocode_CPassword").val("");
    $("#formCreateAjaxAccountNocode_CPassword").siblings().html("再次输入密码");
    $("#formCreateAjaxAccountNocode_TrueName").val("请输入您的真实姓名");
    $("#formCreateAjaxAccountNocode_Mobile").val("方便您获得最新私卖信息");
       $("#formCreateAjaxAccountNocode_Serialno").val("输入可得到优惠或方便找到朋友"); 
    
    removeErrorInfo("formCreateAjaxAccountNocode_MailAddress", "");
    removeErrorInfo("formCreateAjaxAccountNocode_Password", "");
    removeErrorInfo("formCreateAjaxAccountNocode_CPassword", "");
    removeErrorInfo("formCreateAjaxAccountNocode_TrueName", "");
    removeErrorInfo("formCreateAjaxAccountNocode_Mobile", "");
     removeErrorInfo("formCreateAjaxAccountNocode_Serialno", ""); 
        $("#registerdivnocode").fadeOut(600);
}

function clearRegisterInfo()
{    
    $("#formCreateAjaxAccount_MailAddress").val("请使用常用Email地址作为登录名");
    $("#formCreateAjaxAccount_Password").val("");
    $("#formCreateAjaxAccount_Password").siblings().html("设置密码");
    $("#formCreateAjaxAccount_CPassword").val("");
    $("#formCreateAjaxAccount_CPassword").siblings().html("再次输入密码");
    $("#formCreateAjaxAccount_TrueName").val("请输入您的真实姓名");
    $("#formCreateAjaxAccount_Mobile").val("方便您获得最新私卖信息");
    
    removeErrorInfo("formCreateAjaxAccount_MailAddress", "");
    removeErrorInfo("formCreateAjaxAccount_Password", "");
    removeErrorInfo("formCreateAjaxAccount_CPassword", "");
    removeErrorInfo("formCreateAjaxAccount_TrueName", "");
    removeErrorInfo("formCreateAjaxAccount_Mobile", "");
    $("#registerdiv").hide();
}

function clearRegisterInfoNocode()
{    
    $("#formCreateAjaxAccountNocode_MailAddress").val("请使用常用Email地址作为登录名");
    $("#formCreateAjaxAccountNocode_Password").val("");
    $("#formCreateAjaxAccountNocode_Password").siblings().html("设置密码");
    $("#formCreateAjaxAccountNocode_CPassword").val("");
    $("#formCreateAjaxAccountNocode_CPassword").siblings().html("再次输入密码");
    $("#formCreateAjaxAccountNocode_TrueName").val("请输入您的真实姓名");
    $("#formCreateAjaxAccountNocode_Mobile").val("方便您获得最新私卖信息");
       $("#formCreateAjaxAccountNocode_Serialno").val("输入可得到优惠或方便找到朋友"); 
    
    removeErrorInfo("formCreateAjaxAccountNocode_MailAddress", "");
    removeErrorInfo("formCreateAjaxAccountNocode_Password", "");
    removeErrorInfo("formCreateAjaxAccountNocode_CPassword", "");
    removeErrorInfo("formCreateAjaxAccountNocode_TrueName", "");
    removeErrorInfo("formCreateAjaxAccountNocode_Mobile", "");
     removeErrorInfo("formCreateAjaxAccountNocode_Serialno", ""); 
    $("#registerdivnocode").hide();
}


$(document).ready(function(){initMemberApply();})


function initMemberApply()
{
    $("#formSMemberApply_TrueName").blur(function(){if(!isEmptyString($("#formSMemberApply_TrueName").val()) && $("#formSMemberApply_TrueName").val() != "请输入您的真实姓名"){validMemberApplyTrueName("formSMemberApply_TrueName");}});
    $("#formSMemberApply_MailAddress").blur(function(){if(!isEmptyString($("#formSMemberApply_MailAddress").val()) && $("#formSMemberApply_MailAddress").val()!="请使用常用Email地址作为登录名"){validMemberApplyMailAddress("formSMemberApply_MailAddress");}});    
    $("#formSMemberApply_Mobile").blur(function(){if(!isEmptyString($("#formSMemberApply_Mobile").val()) && $("#formSMemberApply_Mobile").val() != "方便您接收通过审核信息"){validMemberApplyMobile("formSMemberApply_Mobile");}});
   
    $("#formCreateAjaxAccount_MailAddress").blur(function(){if(!isEmptyString($("#formCreateAjaxAccount_MailAddress").val()) && $("#formCreateAjaxAccount_MailAddress").val()!="请使用常用Email地址作为登录名"){validMemberApplyMailAddress("formCreateAjaxAccount_MailAddress");}});     
    $("#formCreateAjaxAccount_Password").blur(function(){if(!isEmptyString($("#formCreateAjaxAccount_Password").val())){validPassword("formCreateAjaxAccount_Password");}});     
    $("#formCreateAjaxAccount_CPassword").blur(function(){if(!isEmptyString($("#formCreateAjaxAccount_CPassword").val())){validCPassword("formCreateAjaxAccount_CPassword");}});     
    $("#formCreateAjaxAccount_TrueName").blur(function(){if(!isEmptyString($("#formCreateAjaxAccount_TrueName").val()) && $("#formCreateAjaxAccount_TrueName").val() != "请输入您的真实姓名"){validMemberApplyTrueName("formCreateAjaxAccount_TrueName");}});   
    $("#formCreateAjaxAccount_Mobile").blur(function(){
    if(!isEmptyString($("#formCreateAjaxAccount_Mobile").val()) && $("#formCreateAjaxAccount_Mobile").val() != "方便您获得最新私卖信息")
    {validMemberApplyMobile("formCreateAjaxAccount_Mobile");}});
    
    
    
    $("#btnApply").click(function(){submitSMemberApply()});
    $("#createAjaxAccount").click(function(){createAjaxAccountSubmit()})
   
    $("#createAjaxAccountNoCode").click(function(){createAjaxAccountSubmitNoCode()}) 
   
   
    $("#formCreateAjaxAccountNocode_MailAddress").blur(function(){if(!isEmptyString($("#formCreateAjaxAccountNocode_MailAddress").val()) && $("#formCreateAjaxAccountNocode_MailAddress").val()!="请使用常用Email地址作为登录名"){validMemberApplyMailAddress("formCreateAjaxAccountNocode_MailAddress");}});
    $("#formCreateAjaxAccountNocode_Password").blur(function(){if(!isEmptyString($("#formCreateAjaxAccountNocode_Password").val())){validPassword("formCreateAjaxAccountNocode_Password");}});     
     $("#formCreateAjaxAccountNocode_CPassword").blur(function(){if(!isEmptyString($("#formCreateAjaxAccountNocode_CPassword").val())){validCPasswordNocode("formCreateAjaxAccountNocode_CPassword");}});     
    $("#formCreateAjaxAccountNocode_TrueName").blur(function(){if(!isEmptyString($("#formCreateAjaxAccountNocode_TrueName").val()) && $("#formCreateAjaxAccountNocode_TrueName").val() != "请输入您的真实姓名"){validMemberApplyTrueName("formCreateAjaxAccountNocode_TrueName");}});   
    $("#formCreateAjaxAccountNocode_Mobile").blur(function(){validMemberApplyMobileOptional("formCreateAjaxAccountNocode_Mobile");});
//    $("#formCreateAjaxAccountNocode_Mobile").blur(function(){if(!isEmptyString($("#formCreateAjaxAccountNocode_Mobile").val()) && $("#formCreateAjaxAccountNocode_Mobile").val() != "方便您获得最新私卖信息"){validMemberApplyMobileOptional("formCreateAjaxAccountNocode_Mobile");}});
//    $("#formCreateAjaxAccountNocode_Mobile").focus(function(){if(isEmptyString($("#formCreateAjaxAccountNocode_Mobile").val())) 
//    $("#formCreateAjaxAccountNocode_Mobile").val("方便您获得最新私卖信息");
//   else if( $("#formCreateAjaxAccountNocode_Mobile").val()=="方便您获得最新私卖信息")
//    
//   $("#formCreateAjaxAccountNocode_Mobile").val("");
//    });

    $("#formCreateAjaxAccountNocode_Serialno").blur(function(){$("#serialno").val($("#formCreateAjaxAccountNocode_Serialno").val());submitActivateOptional();});

}

function submitSMemberApply()
{
    if($("#formCreateAjaxAccount_Agree").attr("checked")==false)
	{				
		$("#formCreateAjaxAccount_Error_msg").html("请您确认已经阅读尚品网社区条款");
		return false;
	}
    if(validMemberApplyTrueName("formSMemberApply_TrueName"))
    {
        if(validMemberApplyMailAddress("formSMemberApply_MailAddress"))
        {
            if(validMemberApplyMobile("formSMemberApply_Mobile"))
            {
                var data = getRequestBody("formSMemberApply");
	            var url = "/MemberApplyPost.html"; 
	            $.ajax({
	              type: "POST",
	              url: url,
	              data: data,
	              async: false,
	              complete: function(msg){ 
						            submitSMemberApplySuccess(msg.responseText);
			               },
	              dataType : "html"
	             });  
            }
        }
    }
}

function submitSMemberApplySuccess(msg)
{
    switch(msg)
    {
        case "1":
                $("#shenqing_s1").hide();
                $("#shenqing_s2").show();
            break;  
        case "-1":
                setErr("formSMemberApply_TrueName","请输入您的真实姓名");
            break;
       case "-2":
                setErr("formSMemberApply_MailAddress","请填写Email地址");
            break;
       case "-3":
                setErr("formSMemberApply_MailAddress","Email地址不正确，请重新填写");
            break;
       case "-4":
                setErr("formSMemberApply_Mobile","手机号码不正确，请重新填写");
            break;
       case "-5":
                setErr("formSMemberApply_MailAddress","Email已经被注册");
            break;
       case "-6":
                setErr("formSMemberApply_Mobile","手机号已被注册");
            break;  
       case "-7":
                setErr("formSMemberApply_MailAddress","请填写正确的Email");
            break;             
       default:
            break;                  
    }  
}


function validMemberApplyTrueName(tid)
{
    $("#"+tid).val($.trim($("#"+tid).val()));
    if(isEmptyString($("#"+tid).val()) || $("#"+tid).val() == "请输入您的真实姓名")
        {setErr(tid,"请输入您的真实姓名");return false;}       
    else
    {
        if($("#"+tid).val().length<2)
        {
            setErr(tid,"请填写两个以上的汉字或者英文字母");
            return false;
        }
        if($("#"+tid).val().match(/^[a-zA-Z\s\u4e00-\u9fa5]+$/g))
        {
             removeErrorInfo(tid, "");
            return true;
        }        
        else
        {
            setErr(tid,"请填写两个以上的汉字或者英文字母");return false;
        }
    }
}


function validMemberApplyMailAddress(mid)
{
      if($("#"+mid).val()=="" || $("#"+mid).val()=="建议您使用常用的Email地址")
        {setErr(mid,"请填写Email地址");return false;}
    else
    {
        var re=/^[a-zA-Z0-9_\.-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
        if (re.test($("#"+mid).val()))  
            {
            removeErrorInfo(mid, "");
            emailApply(mid);
            return true;
            }
        else
            {
            setErr(mid,"请填写正确格式的Email地址");
            return false;
            }
    }
}



function emailApply(mid)
{
    $("#formValidateEmail_MailAddress").val($("#"+mid).val());
    var data = getRequestBody("formValidateEmail");
     var url = "/ValidateEmailPost.html"; 
     $.ajax({
      type: "POST",
      url: url,
      data: data,
      complete: function(msg){ 
					    emailApplySuccess(msg.responseText,mid);
		       },
      dataType : "html"
     });  
    //return true;
}

						
function emailApplySuccess(msg,mid)
{
	if(msg=="2")
	{
        setErr(mid,"该Email已注册");
        return false;
	}
	else if(msg=="-1")
	{
        //setErr(mid,"该Email已经是尚品会员，如需变更请致电4006-900-900解决");
        setErr(mid,"该Email已经是尚品会员");
        return false;
	}
	else
	{
	    removeErrorInfo(mid, "");
	    return true;
	}   	
}


function validMemberApplyMobile(bid)
{
    if(isEmptyString($("#"+bid).val()) || $("#"+bid).val() == "请输入您的真实手机号码")
        {setErr(bid,"请填写您的手机号");return false;}       
    else
    {
        var re=/^(13|15|18)[0-9]{9}|(123)[0-9]{8}$/;
        
        if(re.test($("#"+bid).val()))
        {
            removeErrorInfo(bid,"");
            applyMobile(bid);
            return true;
        }
        else
        {
            
            setErr(bid,"请填写正确格式的手机号");
            return false;                
        }
    }
}

function validMemberApplyMobileOptional(bid)
{

    if(isEmptyString($("#"+bid).val()) || $("#"+bid).val() == "方便您获得最新私卖信息")
       {
      $("#formCreateAjaxAccountNocode_Mobile_msg").html("") 
      return true;
      }    
    else
    {
        var re=/^(13|15|18)[0-9]{9}|(123)[0-9]{8}$/;
        
        if(re.test($("#"+bid).val()))
        {
            removeErrorInfo(bid,"");
            applyMobile(bid);
            return true;
        }
        else
        {
            
            setErr(bid,"请填写正确格式的手机号");
            return false;                
        }
    }
}


function applyMobile(bid)
{
    $("#formValidateEmail_MailAddress1").val($("#"+bid).val());
    var data = getRequestBody("formValidateEmail1");
     var url = "/ValidateEmailPost.html"; 
     $.ajax({
      type: "POST",
      url: url,
      data: data,
      complete: function(msg){ 
					    applyMobileSuccess(msg.responseText, bid);
		       },
      dataType : "html"
     });  
    return true;
}

function applyMobileSuccess(msg, input)
{
    switch(msg)
    {
        case "-1" :
            setErr(input, "手机已经被注册");
        break;
       default :
       break;    
    }  
}








function submitCreateAjaxAccount()
{
     var data = getRequestBody("formCreateAjaxAccount");
     var url = "/register/createlppost.html"; 
     $("#createAjaxAccount").attr("disabled", true);
     $.ajax({
	     type: "POST",
	     url: url,
	     data: data,
	     complete: function(msg){ 
			        submitCreateAjaxAccountSuccess(msg.responseText);
			                 },
	     dataType : "html"
	   });      
}


function submitCreateAjaxAccountSuccess(msg)
{
    switch(msg)
    {
        case "1":
            window.location.href="/index.html";
            break;
        case "-1":
            $("#spanErrorMsg").html("请填写Email");
            break;
        case "-2":
            $("#spanErrorMsg").html("请填写正确的Email");
            break;
        case "-3":
            $("#spanErrorMsg").html("请填写登录密码");
            break;
        case "-4":
            $("#spanErrorMsg").html("密码必须超过 6 个字符");
            break;
        case "-5":
            $("#spanErrorMsg").html("激活码已无效");
            break;
        case "-6":
            $("#spanErrorMsg").html("Email已经被注册");
            break;
	    case "-7":
		    $("#spanErrorMsg").html("手机号已被注册");
		    break;
      }
      
      $("#createAjaxAccount").attr("disabled", false);
            
}



function createAjaxAccountSubmit()
{   
    if($("#formCreateAjaxAccount_Agree").attr("checked")==false)
	{				
		$("#error").html("请您确认已经阅读尚品网社区条款");
		return false;
	}
    if(validMemberApplyMailAddress("formCreateAjaxAccount_MailAddress"))
    {
        if(validPassword("formCreateAjaxAccount_Password"))
        {
            if(validCPassword("formCreateAjaxAccount_CPassword"))
             {
                if(validMemberApplyTrueName("formCreateAjaxAccount_TrueName"))
                {
                    if(validMemberApplyMobile("formCreateAjaxAccount_Mobile"))
                    {               
                        submitCreateAjaxAccount();
                    }
                }
             }
        }
    }
}



function createAjaxAccountSubmitNoCode()
{   
    if($("#formCreateAjaxAccountNocode_Agree").attr("checked")==false)
	{				
		$("#error2").html("请您确认已经阅读尚品网社区条款");
		return false;
	}

    if(validMemberApplyMailAddress("formCreateAjaxAccountNocode_MailAddress"))
    {
        if(validPassword("formCreateAjaxAccountNocode_Password"))
        {
            if(validCPasswordNocode("formCreateAjaxAccountNocode_CPassword"))
             {
                if(validMemberApplyTrueName("formCreateAjaxAccountNocode_TrueName"))
                {
                    if(validMemberApplyMobileOptional("formCreateAjaxAccountNocode_Mobile"))
                    {               
                        submitCreateAjaxAccount2();
                    }
                }
             }
        }
    }
}
function submitCreateAjaxAccount2()
{$("#formCreateAjaxAccountNocode_Serialno").val($("#formCreateAjaxAccountNocode_Serialno").val().replace("输入可得到优惠或方便找到朋友",""));

     var data = getRequestBody("formCreateAjaxAccountNocode");
     var url = "/register/createlppost.html"; 
     

     $("#createAjaxAccountNoCode").attr("disabled", true);
     $.ajax({
	     type: "POST",
	     url: url,
	     data: data,
	     complete: function(msg){ 
			        submitCreateAjaxAccountSuccess2(msg.responseText);
			                 },
	     dataType : "html"
	   });      
}

function submitCreateAjaxAccountSuccess2(msg)
{
    switch(msg)
    {
        case "1":
            window.location.href="/index.html";
            break;
        case "-1":
            $("#formCreateAjaxAccountNocode_MailAddress_msg").html("请填写Email");
            break;
        case "-2":
            $("#formCreateAjaxAccountNocode_MailAddress_msg").html("请填写正确的Email");
            break;
        case "-3":
            $("#formCreateAjaxAccountNocode_Password_msg").html("请填写登录密码");
            break;
        case "-4":
            $("#formCreateAjaxAccountNocode_Password_msg").html("密码必须超过 6 个字符");
            break;
        case "-5":
            $("#formCreateAjaxAccountNocode_Serialno_msg").html("激活码已无效");
            break;
        case "-6":
            $("#formCreateAjaxAccountNocode_MailAddress_msg").html("Email已经被注册");
            break;
	    case "-7":
		    $("#formCreateAjaxAccountNocode_Mobile_msg").html("手机号已被注册");
		    break;
		case "-8":
		    $("#formCreateAjaxAccountNocode_CPassword_msg").html("两次输入密码不一致");
		    break;
      }
      
      $("#createAjaxAccountNoCode").attr("disabled", false);
            
}

function validPassword(pid)
{
    if($("#"+pid).val()=="")
    {setErr(pid,"请填写密码");return false;}
    else
    {
    var re=/^[a-zA-Z0-9]{6,16}$/ ;
    if (re.test($("#"+pid).val()))
    {setErr(pid," ");return true;}
    else
    {setErr(pid,"密码可使用6-16位字母或数字");return false;}
    }
}

function validCPassword(cpid)
{
    if(isEmptyString($("#"+cpid).val()))
    {
        setErr(cpid,"请再次输入密码");
        return false;
    }
    else
    {
        var re=/^[a-zA-Z0-9]{6,16}$/;
        if (re.test($("#"+cpid).val()))  
        {
            if ($("#formCreateAjaxAccount_Password").val() != $("#"+cpid).val())
            {
                setErr(cpid,"两次输入的密码不一致,请重新输入!");
                return false; 
            }
            else
            {     
                setErr(cpid, "");
                return true;
            }
        }    
        else
        {
                setErr(cpid,"密码可使用6-16位字母或数字");
                return false;
        }
    }
}

function validCPasswordNocode(cpid)
{
    if(isEmptyString($("#"+cpid).val()))
    {
        setErr(cpid,"请再次输入密码");
        return false;
    }
    else
    {
        var re=/^[a-zA-Z0-9]{6,16}$/;
        if (re.test($("#"+cpid).val()))  
        {
            if ($("#formCreateAjaxAccountNocode_Password").val() != $("#"+cpid).val())
            {
                setErr(cpid,"两次输入的密码不一致,请重新输入!");
                return false; 
            }
            else
            {     
                setErr(cpid, "");
                return true;
            }
        }    
        else
        {
                setErr(cpid,"密码可使用6-16位字母或数字");
                return false;
        }
    }
}

$("#create_account").click(
function(){
$("#registerdivnocode").show();

}
);
