var mailStatus = true;
var vmailStatus = true;
var pwdStatus = true;
var vpwdStatus = true;
var verifyCodeStatus = true;
var agreementStatus = true;
var checkOK = true;


$(document).ready(function() {
	renewVerifyImage();
	$("#email").focus();


	$("input").focus(function() {
		$(this).addClass("focus");
	})
    .blur(function() {
    	$(this).removeClass("focus");
    });

	$("#email").focus(function() {
		$(this).next("span").addClass("note").removeClass("ok").removeClass("error").text("请输入email地址");
	});

	$("#pwd").focus(function() {
		$(this).next("span").addClass("note").removeClass("ok").removeClass("error").text("密码必须是6-30位字符，请正确输入");
	});


	$("#checkimg").focus(function() {
		$(this).siblings("span").addClass("note").removeClass("ok").removeClass("error").text("请输入四位验证码");
		//$("#spanServerError").hide();
	});

	$("#email").blur(function() { CheckEmail($(this)); });

	$("#pwd").blur(function() { CheckPwd($(this)); });

	$("#checkimg").blur(function() { CheckVeryCode($(this)); });
});


function CheckEmail(obj) {
	var regs = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
	if ($(obj).val() != "") {
		var email = $(obj).val();
		if (email.indexOf("@m18comm.com") > 0) {
			$(obj).next("span").addClass("note error").removeClass("ok").text("请输入正确的Email地址");
			mailStatus = false;
			return;
		}
		if (!regs.test(email)) {
			$(obj).next("span").addClass("note error").removeClass("ok").text("请输入正确的Email地址");
			mailStatus = false;
		}
		else {
			
							validateOnce.Exists = false;
							$(obj).next("span").addClass("ok").text("");
							mailStatus = true;

		}
	}
	else {
		$(obj).next("span").addClass("note error").removeClass("ok").text("请输入正确的Email地址");
		mailStatus = false;
	}
}


function CheckVEmail(obj) {
	if ($(obj).val() != "") {
		if ($(obj).val() != $("#email").val()) {
			$(obj).next("span").text("两次输入的Email地址不一致").addClass("error").removeClass("ok");
			vmailStatus = false;
		}
		else {
			$(obj).next("span").addClass("ok").text("");
			vmailStatus = true;
		}
	}
	else {
		$(obj).next("span").addClass("note error").text("请再输一次你的Email地址").removeClass("ok");
		vmailStatus = false;
	}
}


function CheckPwd(obj) {
	if ($(obj).val() != "") {
		var reg = /^(\w|@|#|\$){6,30}/;
		if (!reg.test($("#pwd").val())) {
			$(obj).next("span").addClass("note error").removeClass("ok").text("密码必须是6-30位字符，请正确输入");
			pwdStatus = false;
		}
		else {
			$(obj).next("span").addClass("ok").text("");
			pwdStatus = true;
		}
	}
	else {
		$(obj).next("span").addClass("note error").removeClass("ok").text("密码必须是6-30位字符，请正确输入");
		pwdStatus = false;
	}
}



function CheckVPwd(obj) {
	if ($(obj).val() != "") {
		if ($(obj).val() != $("#pwd").val()) {
			$(obj).next("span").text("您两次输入的密码不一致，请重新输入").addClass("note error").removeClass("ok");
			vpwdStatus = false;
		}
		else {
			$(obj).next("span").addClass("note ok").text("");
			vpwdStatus = true;
		}
	} else {
		$(obj).next("span").addClass("note error").removeClass("ok").text("请再输一次你的密码");
		vpwdStatus = false;
	}
}


function CheckVeryCode(obj) {
	if ($(obj).val().length == 4 && $(obj).val()==$("#imgc").val()) {
		//$("#spanVerifyCodeTip").addClass("note ok").text("");
		//$(obj).val==

		$("#spanVerifyCodeTip").removeClass().text("");
		//$("#ctl00_cpBody_checkimg").text("");
		verifyCodeStatus = true;
	}
	else {
		$("#spanVerifyCodeTip").addClass("note error").text("请输入正确的四位验证码");
		verifyCodeStatus = false;
	}
}


function CheckAgreement(obj) {
	if ($(obj).attr("checked") == true) {
		$(obj).siblings("span").removeClass("note error").text("")
		agreementStatus = true;
	}
	else {
		$(obj).siblings("span").addClass("note error").text("请先阅读并同意《麦网用户服务协议》");
		agreementStatus = false;
	}
}


function renewVerifyImage() {
	//var img = $("#appPath").val() + "VerifyImage.axd?seed=" + Math.round(Math.random() * 100000);
	//$(".checkimg").attr("src", img);
	//var vguid = $("#hidVerifyCodeReg").val();
	//---GetVerifyCode("register", $("#hidVerifyCodeReg").val());
}
function CheckRegister() {
	CheckEmail($("#email"));
	CheckPwd($("#pwd"));
	CheckVeryCode($("#checkimg"));
	//CheckAgreement($("#chkAgreement"));
	if (!mailStatus ||  !pwdStatus  || !verifyCodeStatus ) {
		checkOK = false;
	}
	else {
		checkOK = true;
	}
	return checkOK;
}
//取验证码
function GetVerifyCode(catalog, oldGuid) {
	var VerifyCodeUrl = $("#hidVerifyCodeUrl").val();
	$.ContentLoader(loginService + "/GetVerifyCode", "{oldGuid:'" + oldGuid + "'}",
			 function(data) {
			 	var msg = eval('(' + data + ')');
			 	if (catalog == "login") {
			 		$("#hidVerifyCodeLogin").val(msg.d);
			 		$("#verImglogin").attr("src", VerifyCodeUrl + "?guid=" + msg.d)
			 	}
			 	else {
			 		$("#hidVerifyCodeReg").val(msg.d);
			 		$("#registerVerifyCodeImg").attr("src", VerifyCodeUrl + "?guid=" + msg.d);
			 	}
			 }, function() {

			 });
}


//----------------------------------Static Method-----------------------
$.ContentLoader = function(url, data, callback, error) {
	$.ajax({
		url: url,
		data: data,
		type: "POST",
		contentType: "application/json; charset=utf-8",
		success: callback,
		error: error
	});
};


