/**************************** 以下是注册验证 st ***************************/

/****************用户注册验证 st*********************/
//2010.6.12
$(document).ready(function(){
	var order = new Array("regTheEmail", "regTheUserName", "regThePassword", "regThePassword1", "regTheScode", "buyer_name", "shipping_address", "purchaser_phone");
	//按分类执行相应功能
	$("input[type='text'],input[type='password']").blur(function(){
		if(order.join(" ").match($(this).attr("id")) != null)
		{
			eval($(this).attr("id")+"_blur"+"()");
			//alert($(this).attr("id"));
		}
		else
		{
			return false;
		}
	});

//用户注册
function regTheUserName_blur()
{
	var value = $("#regTheUserName").val();
	//alert(value);
	var is_username = ckusername(value);	//调用ckusername(), 匹配用户名规则
	if(is_username == 3)
	{
		requestError('regTheUserName','昵称不能为空')
	}
	else if(is_username == 4)
	{
		requestError('regTheUserName','合法长度为6-18个字符')
	}
	
	else if(is_username == 5)
	{
		requestError('regTheUserName','昵称不能以数字开头')
	}
	/*
	else if(is_username == 6)
	{
		requestError('regTheUserName','昵称只能包含_,英文字母,数字')
	}
	else if(is_username == 7)
	{
		requestError('regTheUserName','昵称请用字母开头')
	}
	*/
	else if(is_username == 8)
	{
		requestRight('regTheUserName')
	}
	
}

//匹配用户名规则
function ckusername(value)
{
	value = $.trim(value)
	if(value == "")
	{
		return 3;
	}
	else if(value.length <1)
	{	

		return 4;
	}
	
	else if(value.match(/^[0-9]{6,}.*/g) != null)
	{
		return 5;
	}
//	
//	else if(value.match(/^[A-Za-z]{1,}[\w.]{5,}[^\w._]/g) != null)
//	{
//		return 6;
//	}
////	
//	
//	else if(value.match(/^[^A-Za-z]{1,}[\w.]{5,}/g) != null)
//	{
//		return 7;
//	}


//	else if(value.match(/^[A-Za-z]{1,}[\w_]{5,}/g) != null)
//	{
//		return 8;
//	}
	else
	{
		return 8;
	}
}


//检查用户密码(首次)
function regThePassword_blur()
{
	var value = $("#regThePassword").val();
	var is_password = ckpassword(value);	//调用ckpassword(), 匹配密码规则
	if(is_password == 3)
	{
		requestError('regThePassword','密码不能为空')
	}
	else if(is_password == 4)
	{
		requestError('regThePassword','请输入6～16位字符的密码')
	}
	else if(is_password == 5)
	{
		requestNotice('regThePassword','6-16个字符区分大小写,强')
	}
	else if(is_password == 6)
	{
		requestNotice('regThePassword','6-16个字符区分大小写,最弱')
	}
	else if(is_password == 7)
	{
		requestNotice('regThePassword','6-16个字符区分大小写,较弱')
	}
	
}

//匹配密码规则, 检查是否合法或强弱程度
function ckpassword(value)
{
	if(value == "")
	{
		return 3;
	}
	else if(value.length < 6)
	{
		return 4;
	}
	else if(value.match(/^([A-Z])([a-z])([0-9])([^\w]|\.)(.){2,}|([A-Z])([a-z])([^\w]|\.)([0-9])(.){2,}|([A-Z])([0-9])([a-z])([^\w]|\.)(.){2,}|([A-Z])([0-9])([^\w]|\.)([a-z])(.){2,}|([A-Z])([^\w]|\.)([a-z])([0-9])(.){2,}|([A-Z])([^\w]|\.)([0-9])([a-z])(.){2,}|([a-z])([A-Z])([0-9])([^\w]|\.)(.){2,}|([a-z])([A-Z])([^\w]|\.)([0-9])(.){2,}|([a-z])([^\w]|\.)([A-Z])([0-9])(.){2,}|([a-z])([^\w]|\.)([0-9])([A-Z])(.){2,}|([0-9])([A-Z])([a-z])([^\w]|\.)(.){2,}|([0-9])([A-Z])([^\w]|\.)([a-z])(.){2,}|([0-9])([a-z])([A-Z])([^\w]|\.)(.){2,}|([0-9])([a-z])([^\w]|\.)([A-Z])(.){2,}|([0-9])([^\w]|\.)([A-Z])([a-z])(.){2,}|([0-9])([^\w]|\.)([a-z])([A-Z])(.){2,}|([^\w]|\.)([A-Z])([a-z])([0-9])(.){2,}|([^\w]|\.)([A-Z])([0-9])([a-z])(.){2,}|([^\w]|\.)([a-z])([A-Z])([0-9])(.){2,}|([^\w]|\.)([a-z])([0-9])([A-Z])(.){2,}|([^\w]|\.)([0-9])([A-Z])([a-z])(.){2,}|([^\w]|\.)([0-9])([a-z])([A-Z])(.){2,}$/g) != null)
	{
		return 5;
	}
	else if(value.match(/^([A-Za-z]{6,12})|([0-9]{6,12})|([^\w]{6,12})|(\.{6,12})$/g) != null)
	{
		return 6;
	}	
	else if(value.match(/^((([A-Za-z]){2,}([0-9]){1,}){6,}|(\2{1,}\1{2,}){6,})|((([A-Za-z]){2,}([^\w.]){1,}(\.){1,}){6,}|(\2{2,}\3{2,}\1{1,}){6,})|((([0-9]){2,}([^\w.]){1,}(\.){1,}){6,}|(\2{2,}\3{2,}\1{1,}){6,})$/g) != null)
	{
		return 7;
	}	
}


//检查再次输入的密码
function regThePassword1_blur()
{
	var value = $("#regThePassword1").val();
	var is_password2 = ckpassword2(value);	//调用ckpassword2(), 与原密码匹配
	if(is_password2 == 3)
	{
		requestError('regThePassword1','输入的密码有误');
	}
	else if(is_password2 == 4)
	{
		requestError('regThePassword1','两次密码不相同,请再次输入密码');
	}
	else if(is_password2 == 5)
	{
		requestRight('regThePassword1');
	}	
}

//匹配再次输入密码, 是否合法或与首次密码匹配
function ckpassword2(value)
{
	var password = $("#regThePassword").val();
	if(value.length < 6)
	{
		return 3;
	}
	else if(value != password)
	{
		return 4;
	}
	else if(value == password)
	{
		return 5;
	}	
}


//检查邮箱
function regTheEmail_blur()
{
	var value = $("#regTheEmail").val();
	var is_email = ckemail(value);
	if(is_email == 3)
	{
		requestError('regTheEmail','输入的Email不合法');
	}
	else if(is_email == 4)
	{
		requestRight('regTheEmail');
	}
}

//匹配邮箱规则, 检查是否合法
function ckemail(value)
{
	if(value.match(/^[A-Za-z]+[\w._]*@{1}[\w.]+\.[A-Za-z]+/ig) == null)
	{
		return 3;
	}
	else if(value.match(/^[A-Za-z]+[\w._]*@{1}[\w.]+\.[A-Za-z]+/ig) != null)
	{
		return 4;
	}
	
}


//检查验证码, 是否为空
function regTheScode_blur()
{
	var value = $("#regTheScode").val();
	var is_regTheScode = ckregTheScode(value);
	if(is_regTheScode == 3)
	{
		requestError('regTheScode','输入的验证码不能为空');
	}
	else if(is_regTheScode == 4)
	{
		requestError('regTheScode','输入4位数验证码');
	}
	else if(is_regTheScode == 5)
	{
		requestNotCfm('regTheScode');
	}
}

//匹配是否为空
function ckregTheScode(value)
{
	if(value == "")
	{
		return 3;
	}
	else if(value.length < 4)
	{
		return 4;
	}
	else if(value.length == 4)
	{
		return 5;
	}
	
}


//创建帐号前的检查
$("#regTheDone").click(function()
		{	
			if($("#regTheEmail").attr("class").match(/\bhaveRight\b/) == null || $("#regTheEmail").val() == "")
			{
				alert("请检查Email");	
				return false;
			}
			else if($("#regTheUserName").attr("class").match(/\bhaveRight\b/) == null || $("#regTheUserName").val() == "")
			{
				alert("请检查昵称");
				return false;
			}
			else if($("#regThePassword").attr("class").match(/\bhaveRight\b/) == null || $("#regThePassword").val() == "")
			{
				alert("请检查输入的密码");
				return false;
			}
			else if($("#regThePassword1").attr("class").match(/\bhaveRight\b/) == null || $("#regThePassword1").val() == "")
			{
				alert("请检查再次输入的密码");
				return false;
			}
			else if($("#regTheScode").attr("class").match(/\bhaveRight\b/) == null || $("#regTheScode").val() == "")
			{
				alert("请检查验证码");
				return false;
			}	
			else
			{
				return true;
			}
		});
/****************用户注册验证 end*********************/


/****************{{product5}} 验证 st*********************/
//验证收货人姓名
function buyer_name_blur()
{
	var value = $.trim( $("#buyer_name").val() );
	var is_buyerName = ckBuyerName(value);
	if(is_buyerName == 3)
	{
		requestError_chr_style("buyer_name", "请提供收货人姓名");
	}
	else if( value.match(/^[\u4e00-\u9fa5]*$/g) == null )
	{
		requestError_chr_style("buyer_name", "收货人姓名只能是中文字符");
	}
	else if(is_buyerName == 4)
	{
		requestRight_nochr_style("buyer_name");
	}
}

function ckBuyerName(value)
{
	if(value == "")
	{
		return 3;
	}
	else
	{
		return 4;
	}
}


//验证送货地址
function shipping_address_blur()
{
	var value = $.trim( $("#shipping_address").val() );
	var is_shipping_address = ckShippingAddress(value);
	
	if(is_shipping_address == 3)
	{
		requestError_chr_style("shipping_address", "请提供收货详细地址");
	}
	else if(is_shipping_address == 4)
	{
		requestRight_nochr_style("shipping_address");
	}
}

function ckShippingAddress(value)
{
	if(value == "")
	{
		return 3;
	}
	else
	{
		return 4;
	}
}


//检测省,市,区/县每次change时是否合法
$(document).ready(function(){
	chk_cityAndCounty();
});
function chk_cityAndCounty()
{
	$("#province").change(function(){
		if( $(this).val() == "empty" || $("#city").val() == "empty" || $("#county").val() == "empty" )
		{
			$("#province").parent("td").find(".cityOrcountyIsEmpty").html("请选择市,区/县");
		}
		else
		{
			$("#province").parent("td").find(".cityOrcountyIsEmpty").html("");
		}
	});
	
	$("#city").change(function(){
		if( $(this).val() == "empty" || $("#county").val() == "empty" || $("#province").val() == "empty" )
		{
			$("#province").parent("td").find(".cityOrcountyIsEmpty").html("请选择市,区/县");
		}
		else
		{
			$("#province").parent("td").find(".cityOrcountyIsEmpty").html("");
		}
	});
	
	$("#county").change(function(){
		if( $(this).val() == "empty"|| $("#city").val() == "empty" || $("#province").val() == "empty" )
		{
			$("#province").parent("td").find(".cityOrcountyIsEmpty").html("请选择市,区/县");
		}
		else
		{
			$("#province").parent("td").find(".cityOrcountyIsEmpty").html("");
		}
	});
}


//验证手机
//页面加载完 激活 只允许数字输入的文本框 事件
/*$(document).ready(function(){
	inputOnlyNum("purchaser_phone");												 
})*/
function purchaser_phone_blur()
{	
	var value = $.trim( $("#purchaser_phone").val() );
	var is_purchaser_phone = ckPurchaserPhone(value);
	if(is_purchaser_phone == 3)
	{
		requestError_chr_style("purchaser_phone", "手机号码只能是数字,11-13位,请正确填写方便客服人员与您取得联系");
	}
	else if(is_purchaser_phone == 4)
	{
		requestRight_nochr_style("purchaser_phone");
	}
}

function ckPurchaserPhone(value)
{
	if(value == "")
	{
		return 3;
		return false;
	}
	else if(value.match(/[^0-9]+/g) != null)
	{
		//$("#purchaser_phone").val("");
		return 3;
		return false;
	}
	else if(value.length < 11 || value.length  > 13 )
	{
		return 3;
		return false;
	}
	else
	{
		return 4;
	}
}

//用户提交购买信息时的验证
$("#shippingCfm").click(function(){
	/*if($("#formProductInfo2 .choosecolor input").attr("bechoosed") == null)
	{
		alert("请选择商品颜色");
		return false;
	}
	else*/ if($("#shipping_address").attr("class").match(/\bhaveRight\b/g) == null || $("#shipping_address").val() == "")
	{
		alert("请检查收货详细地址");
		return false;
	}
	else if( $("#province").val() == "empty" || $("#city").val() == "empty" || $("#county").val() == "empty" )
	{
		alert("请检查省,市,区/线县的选择");
		$("#province").parent("td").find(".cityOrcountyIsEmpty").html("请选择市,区/县");
		return false;
	}
	else if($("#purchaser_phone").attr("class").match(/\bhaveRight\b/g) == null || $("#purchaser_phone").val() == "")
	{
		alert("请检查收货人手机");
		return false;
	}	
	else if($("#buyer_name").attr("class").match(/\bhaveRight\b/g) == null || $("#buyer_name").val() == "")
	{
		alert("请检查收货人姓名");
		return false;
	}
	else 
	{
		return true;
	}
})

/****************{{product5}} 验证 end*********************/


//阻止键盘非数字键的输入, idname为参数, 左匹配ID之用
function inputOnlyNum(idName)
{
$("#"+idName).keypress(function(e)
	{
		code = e.keyCode ? e.keyCode : e.which;
		if(code > 45 && code < 58 || code == 8)
		{
			return true;
		}
		else{return false};		
	});	
}

//用户输入有误时反馈的结果，并有文字信息。theIdName为返回显示结果位置参数;theContent为输出的文字内容参数 
function requestError(theIdName,theContent)
{
	$("#"+theIdName).css({backgroundColor:"#F9E6EE",borderColor:"#f00"}).removeClass("haveRight");
	$("#"+theIdName+"_bk").css({background:"url(assets/themes/v100409/images/input-wrong.gif) no-repeat 0px 0px",color:"#f00",padding:"3px 0px 3px 25px",height:"18px"}).html(theContent);
}
//根据文本框的id修改边框样式，此样式为红
function requestErrorRedBk(theIdName)
{
	$("#"+theIdName).css({backgroundColor:"#F9E6EE",borderColor:"#f00"});
}

//用户输入合法时反馈的结果，并有文字信息。theIdName为返回显示结果位置参数;theContent为输出的文字内容参数
function requestRightCon(theIdName,theContent)
{
	$("#"+theIdName).css({backgroundColor:"#fff",borderColor:"#A4AFC3"}).addClass("haveRight");
	$("#"+theIdName+"_bk").css({background:"url(assets/themes/v100409/images/input-right.gif) no-repeat 0px 0px",color:"#f00",padding:"4px 0px 3px 25px",height:"18px"}).html(theContent);
}

//用户输入无误时反馈的结果，没有文字信息。theIdName为返回显示结果位置参数
function requestRight(theIdName)
{
	$("#"+theIdName).css({backgroundColor:"#fff",borderColor:"#A4AFC3"}).addClass("haveRight");
	$("#"+theIdName+"_bk").css({background:"url(assets/themes/v100409/images/input-right.gif) no-repeat 0px 0px",color:"#f00",padding:"4px 0px 3px 25px",height:"18px"}).html("");
}

//用户输入无误，仅作提示信息。theIdName为返回显示结果位置参数;theContent为输出的文字内容参数
function requestNotice(theIdName,theContent)
{
	$("#"+theIdName).css({backgroundColor:"#fff",borderColor:"#A4AFC3"}).addClass("haveRight");
	$("#"+theIdName+"_bk").css({background:"url(assets/themes/v100409/images/input-notice.gif) no-repeat 0px 0px",color:"#999",padding:"3px 0px 3px 25px",height:"18px"}).html(theContent);
}

//保持当前输入文本框样式不改变及不显示任何反馈结果
function requestNotCfm(theIdName)
{
	$("#"+theIdName).css({backgroundColor:"#fff",borderColor:"#A4AFC3"}).addClass("haveRight");
	$("#"+theIdName+"_bk").css({background:"none",color:"#999"}).html("");
}

//用户输入有误, 当前输入文本框样式改变(border:#f00; background-color:#F9E6EE),  并出现文字提示
function requestError_chr_style(theIdName, theContent)
{
	$("#"+theIdName).css({backgroundColor:"#F9E6EE",borderColor:"#f00"}).removeClass("haveRight");
	$("#"+theIdName+"_bk").css({color:"#f00"}).html(theContent);
	
}
//用户输入正确, 当前输入文本框样式改变(border:#cdcdcd; background-color:#fff), 不出现文字提示
function requestRight_nochr_style(theIdName)
{
	$("#"+theIdName).css({backgroundColor:"#fff",borderColor:"#cdcdcd"}).addClass("haveRight");
	$("#"+theIdName+"_bk").html("");
	
}

});		//$(document).ready(function(){})加载完成




/**************************** 以下是注册验证 end ***************************/
