//trim spaces with regular expression
String.prototype.trim = function()
{
	return this.replace(/(^\s*)|(\s*$)/g, "");
}

//Count string byte number, return integer
String.prototype.ByteCount = function()
{
	txt = this.replace(/(<.*?>)/ig,"");
	txt = txt.replace(/([\u0391-\uFFE5])/ig, "11");
	var count = txt.length;
	return count;
}

//filter keywords
function check_durty_words(thisinput)
{
	var durty_words = new Array("系统","管理","佳缘","master","版主","斑竹","龙女","客服","root","颁奖","活动","提示","兑奖","通知");
	for(i=0;i<durty_words.length;i++)
	{
		if (thisinput.indexOf(durty_words[i])	>=	0)
		{
			return durty_words[i];
		}
	}
	return false;
}
function click_url(url)
{
	xajax_processFormEmail('',url);
}
//mouse onclick the email box
function click_email_input(thisinput)
{
	document.getElementById('regemailinfo').className = "show exactness";
	document.getElementById('regemailinfo').innerHTML = "填写常用邮箱名，用于登陆";
}

//mouse lost the email box
function check_email_input(thisinput)
{
	var re = /^[_a-zA-Z0-9\-\.]+@([\-_a-zA-Z0-9]+\.)+[a-zA-Z0-9]{2,3}$/;
	if ( (thisinput.value.trim() == "") ) {
		document.getElementById('regemailinfo').className = "show null";
		document.getElementById('regemailinfo').innerHTML = "系统未检测到您的输入";
	}
	else if (!thisinput.value.match(re))
	{
		document.getElementById('regemailinfo').className = "show err";
		document.getElementById('regemailinfo').innerHTML = "输入不符合规范";
	}
	else
	{
		alert(xajax.getFormValues("Form1"));
		//xajax_processTraceUser(xajax.getFormValues("Form1"),'password');
		xajax_processFormEmail(xajax.getFormValues("Form1"));
		//xajax_processTraceUser(xajax.getFormValues("Form1"),'password');
	}
}

//mouse onclick the password box
function click_password_input(thisinput)
{
	document.getElementById('regpassinfo').className = "show exactness";
	document.getElementById('regpassinfo').innerHTML = "填写6～20位的密码";
	//xajax_processTraceUser(xajax.getFormValues("Form1"),'password');
}

//mouse lost the password box
function check_password_input(thisinput)
{
	var count = thisinput.value.trim().ByteCount();

	if (thisinput.value.trim() == "") {
		document.getElementById('regpassinfo').className="show null";
		document.getElementById('regpassinfo').innerHTML="系统未检测到您的输入";
	}
	else if (count < 6 || count > 20)
	{
		document.getElementById('regpassinfo').className = "show err";
		document.getElementById('regpassinfo').innerHTML = "输入不符合规范";
	}
	else
	{
		document.getElementById('regpassinfo').className = "show exactness";
		document.getElementById('regpassinfo').innerHTML = "内容符合规范，可以使用";
	}
	xajax_processFormEmail(xajax.getFormValues("Form1"),'password');
}

//mouse onclick the chkpass box
function click_chkpass_input(thisinput)
{
	var oPass = document.Form1.password.value;
	if( oPass == "")
	{
		document.Form1.password.focus();
	}else{
		document.getElementById('regpass2info').className="show exactness";
		document.getElementById('regpass2info').innerHTML="请输入确认密码";
	}
}

//mouse lost the chkpass box
function check_chkpass_input(thisinput)
{
	var oPass = document.Form1.password.value;
	if(thisinput.value.trim() == "")
	{
		document.getElementById('regpass2info').className="show null";
		document.getElementById('regpass2info').innerHTML = "系统未检测到您的输入";
	}
	else if(thisinput.value != oPass)
	{
		document.getElementById('regpass2info').className="show err";
		document.getElementById('regpass2info').innerHTML = "确认密码与密码不一致";
	}
	else
	{
		document.getElementById('regpass2info').className = "show exactness";
		document.getElementById('regpass2info').innerHTML = "密码确认通过";
	}
	xajax_processFormEmail(xajax.getFormValues("Form1"),'chkpass');
}

//mouse onclick the nickname box
function click_nickname_input(thisinput)
{
	document.getElementById('regnicknameinfo').className="show exactness";
	document.getElementById('regnicknameinfo').innerHTML="昵称限制在10个汉字以内";
}

//mouse lost the nickname box
function check_nickname_input(thisinput)
{
	var filter = check_durty_words(thisinput.value.trim());
	var count = thisinput.value.trim().ByteCount();
	if( count == 0 )
	{
		document.getElementById('regnicknameinfo').className="show null";
		document.getElementById('regnicknameinfo').innerHTML="系统未检测到您的输入";
	}
	else if ((thisinput.value.trim() != "") && (count < 2 || count > 20)) {
		document.getElementById('regnicknameinfo').className="show err";
		document.getElementById('regnicknameinfo').innerHTML="输入不符合规范";
	}
	else if (filter)
	{
		document.getElementById('regnicknameinfo').className = "show err";
		document.getElementById('regnicknameinfo').innerHTML = "“"+filter+"”不能在昵称中使用";
	}
	else
	{
		document.getElementById('regnicknameinfo').className = "show exactness";
		document.getElementById('regnicknameinfo').innerHTML = "内容符合规范，可以使用";
	}
	/*else
	{
		xajax_processFormNickName(xajax.getFormValues("Form1"));
	}*/
	xajax_processFormEmail(xajax.getFormValues("Form1"),'nickname');
}

//mouse onclick the height box
function click_height_input(thisinput)
{
	document.getElementById('regheightinfo').className="show exactness";
	document.getElementById('regheightinfo').innerHTML="请认真填写，注册后不可改";
}

//mouse lost the height box
function check_height_input(thisinput)
{
	var count = thisinput.value.trim().ByteCount();
	var rs = /^[0-9]{3}$/;

	if( count == 0 )
	{
		document.getElementById('regheightinfo').className="show null";
		document.getElementById('regheightinfo').innerHTML="系统未检测到您的输入";
	}
	else if((!thisinput.value.match(rs)) || (thisinput.value < 130 || thisinput.value > 260))
	{
		document.getElementById('regheightinfo').className="show err";
		document.getElementById('regheightinfo').innerHTML="输入不符合规范";
	}
	else
	{
		document.getElementById('regheightinfo').className = "show exactness";
		document.getElementById('regheightinfo').innerHTML = "内容符合规范，可以使用";
		
		if(document.getElementById('sexm').checked)
		{
			document.getElementById('needheight_max').value	=	thisinput.value-5;
		}
		if(document.getElementById('sexf').checked)
		{
			document.getElementById('needheight_min').value	=	parseInt(thisinput.value)+5;			
		}
	}
	xajax_processFormEmail(xajax.getFormValues("Form1"),'height');
}

function check_age_input()
{
	var year	=	document.getElementById('year').value;
	var date = new Date();
	var now  = date.getYear();
	var age  = now - year;
	if(document.getElementById('sexm').checked)
	{
		document.getElementById('needage_min').value	=	age-7;
		if(document.getElementById('needage_min').value	<	18)
		{
			document.getElementById('needage_min').value	=	18;
		}
		document.getElementById('needage_max').value	=	age;
	}
	if(document.getElementById('sexf').checked)
	{
		document.getElementById('needage_min').value	=	age;
		document.getElementById('needage_max').value	=	parseInt(age)+7;
		if(document.getElementById('needage_max').value	>	99)
		{
			document.getElementById('needage_max').value	=	99;
		}
	}
}

//mouse onclick the workprovince box
function click_workprovince_input(thisinput)
{
	document.getElementById('regworkareainfo').className="show exactness";
	document.getElementById('regworkareainfo').innerHTML="请选择您所在的省份";
}

//mouse lost the workprovince box
function check_workprovince_input(thisinput)
{
	if( thisinput.value.trim() == 0 )
	{
		document.getElementById('regworkareainfo').className="show null";
		document.getElementById('regworkareainfo').innerHTML="系统未检测到您的输入";
	}
	else
	{
		document.getElementById('regworkareainfo').className = "show null";
		document.getElementById('regworkareainfo').innerHTML = "请选择您所在的城市";
	}
	xajax_processFormEmail(xajax.getFormValues("Form1"),'province');
}

//mouse onclick the workcity box
function click_workcity_input(thisinput)
{
	document.getElementById('regworkareainfo').className="show exactness";
	document.getElementById('regworkareainfo').innerHTML="请选择您所在的城市";
}

//mouse lost the workcity box
function check_workcity_input(thisinput)
{
	if( thisinput.value.trim() == 0 )
	{
		document.getElementById('regworkareainfo').className="show null";
		document.getElementById('regworkareainfo').innerHTML="系统未检测到您的输入";
	}
	else
	{
		document.getElementById('regworkareainfo').className = "show exactness";
		document.getElementById('regworkareainfo').innerHTML = "内容符合规范，可以使用";
	}
	xajax_processFormEmail(xajax.getFormValues("Form1"),'city');
}

/*
mouse onclick the checkcode box
function click_checkcode_input(thisinput)
{
	regcheckcodeinfo.className="show exactness";
	regcheckcodeinfo.innerHTML="请填写图片中的数字";
}
*/

//mouse lost the checkcode box
function check_checkcode_input(thisinput)
{
	if(thisinput	==	'force')
	{
		document.getElementById('regcheckcodeinfo').className="show null";
		document.getElementById('regcheckcodeinfo').innerHTML="请重新输入验证码";	
		return;	
	}


	var count = thisinput.value.trim().ByteCount();
	var rc = /^[a-zA-Z0-9]{5}$/;


	if (count == 0)
	{
		document.getElementById('regcheckcodeinfo').className="show null";
		document.getElementById('regcheckcodeinfo').innerHTML="系统未检测到您的输入";
	}
	else if (!thisinput.value.match(rc))
	{
		document.getElementById('regcheckcodeinfo').className="show err";
		document.getElementById('regcheckcodeinfo').innerHTML="输入不符合规范";
	}
	else
	{
		document.getElementById('regcheckcodeinfo').className = "show exactness";
		document.getElementById('regcheckcodeinfo').innerHTML = "内容符合规范，可以使用";
	}
	xajax_processFormEmail(xajax.getFormValues("Form1"),'validate_code');
}

//mouse onclick the note textarea
function click_note_input(thisinput)
{
	document.getElementById('regnoteinfo').className="show exactness";
	document.getElementById('regnoteinfo').innerHTML="限20字到1000字之间";
}

//mouse lost the note textarea
function check_note_input(thisinput)
{
	if( thisinput.value.length == 0 )
	{
		document.getElementById('regnoteinfo').className="show null";
		document.getElementById('regnoteinfo').innerHTML="系统未检测到您的输入";
	}
	else if((thisinput.value != "") && (thisinput.value.length < 20 || thisinput.value.length > 1000))
	{
		document.getElementById('regnoteinfo').className="show err";
		document.getElementById('regnoteinfo').innerHTML="输入不符合规范";
	}
	else
	{
		document.getElementById('regnoteinfo').className = "show exactness";
		document.getElementById('regnoteinfo').innerHTML = "内容符合规范，可以使用";
	}
	xajax_processFormEmail(xajax.getFormValues("Form1"),'note');
}

function check_mobile()
{
	var mobile	=	document.getElementById('mobile').value;
	if(mobile	==	'')
	{
		return true;
	}
	var div_obj		=	document.getElementById('mobile_div');
	var reg1=/^13\d{9}$/gi;
	var reg2=/^15\d{9}$/gi;

	if (reg1.test(mobile)==false	&&	reg2.test(mobile)==false)
	{
		div_obj.className	=	'show err';
		div_obj.innerHTML	=	'输入不符合规范';
		return false;
	}
	else
	{
		div_obj.className	=	'show exactness';
		div_obj.innerHTML	=	'内容符合规范，可以使用';
		return true;
	}
}

function check_needage()
{
	var neagemin	=	document.getElementById('needage_min').value;
	var neagemax	=	document.getElementById('needage_max').value;
	
	if(neagemin	==	''	&&	neagemax	==	'')
	{
		return true;
	}
	
	if(neagemin	==	'')
	{
		neagemin	=	0;
	}
	if(neagemax	==	'')
	{
		neagemax	=	0;
	}
	
	var div_obj		=	document.getElementById('needage_div');

	neagemin	=	parseInt(neagemin);
	neagemax	=	parseInt(neagemax);

	if((neagemin	<	18	&&	neagemin	!=	0)	||	neagemax	> 99)
	{
		div_obj.className	=	'show err';
		div_obj.innerHTML	=	'输入不符合规范';
		return false;
	}

	if(neagemin	!=	0	&&	neagemax	!=	0)
	{
		if(neagemax	<	neagemin)
		{
			div_obj.className	=	'show err';
			div_obj.innerHTML	=	'输入不符合规范';
			return false;
		}
	}
	div_obj.className	=	'show exactness';
	div_obj.innerHTML	=	'内容符合规范，可以使用';
	return true;
}

function check_needheight()
{
	var neheimin	=	document.getElementById('needheight_min').value;
	var neheimax	=	document.getElementById('needheight_max').value;
	
	if(neheimin	==	''	&&	neheimax	==	'')
	{
		return true;
	}
	
	if(neheimin	==	'')
	{
		neheimin	=	0;
	}
	if(neheimax	==	'')
	{
		neheimax	=	0;
	}
	
	var div_obj		=	document.getElementById('needheight_div');

	neheimin	=	parseInt(neheimin);
	neheimax	=	parseInt(neheimax);

	if((neheimin	<	130	&&	neheimin	!=	0)	||	neheimax	> 260)
	{
		div_obj.className	=	'show err';
		div_obj.innerHTML	=	'输入不符合规范';
		return false;
	}

	if(neheimin	!=	0	&&	neheimax	!=	0)
	{
		if(neheimax	<	neheimin)
		{
			div_obj.className	=	'show err';
			div_obj.innerHTML	=	'输入不符合规范';
			return false;
		}
	}
	div_obj.className	=	'show exactness';
	div_obj.innerHTML	=	'内容符合规范，可以使用';
	return true;
}
//Check submit form error
function chkForm(objForm)
{
	var objForm;
	var re = /^[_a-zA-Z0-9\-\.]+@([\-_a-zA-Z0-9]+\.)+[a-zA-Z0-9]{2,3}$/;
	var rs = /^[0-9]{3}$/;
	var rc = /^[0-9]{5}$/;

	var email		= objForm.email.value;
	var password	 = objForm.password.value;
	var nickname	 = objForm.nickname.value;
	var year		 = objForm.year.value;
	var month		= objForm.month.value;
	var day		  = objForm.day.value;
	var height	   = objForm.height.value;
	var marriage	 = objForm.marriage.value;
	var degree	   = objForm.degree.value;
	var income	   = objForm.income.value;
	var province	 = objForm.province.value;
	var city		 = objForm.city.value;
	var checkcode	= objForm.checkcode.value;
	var note		 = objForm.note.value;

	var date = new Date();
	var now  = date.getYear();
	var age  = now - year;
	var filter = check_durty_words(objForm.nickname.value);

	if (email == "" || (!email.match(re)))
	{
		alert("【注册邮箱】不能为空或格式不符合规范\n");
		objForm.email.focus();
		return false;
	}

	if (password == "" || (password.length < 6 || password.length > 20))
	{
		alert("【佳缘密码】不能为空或长度不符合规范\n");
		objForm.password.focus();
		return false;
	}

	if (objForm.password.value != objForm.chkpass.value)
	{
		alert("【确认密码】与密码不一致\n");
		objForm.chkpass.focus();
		return false;
	}

	if (nickname == "" || (nickname.trim().ByteCount()<2 || nickname.trim().ByteCount()>20))
	{
		alert("【会员昵称】不能为空或格式不符合规范\n");
		objForm.nickname.focus();
		return false;
	}

	if (filter)
	{
		alert("“"+filter+"”不能在昵称中使用\n");
		objForm.nickname.focus();
		return false;
	}

	if(!(document.getElementById("sexf").checked || document.getElementById("sexm").checked))
	{
		//regsexinfo.className="show err";
		//regsexinfo.innerHTML="性别、生日、身高不能修改，请认真填写。";
		alert("请选择您的【性别】<性别、生日、身高注册后不能修改>\n");
		return false;
	}

	if (year == 0)
	{
		alert("请选择【出生年月】 - 年\n");
		objForm.year.focus();
		return false;
	}

	if (month == 0)
	{
		alert("请选择【出生年月】 - 月\n");
		objForm.month.focus();
		return false;
	}

	if (day == 0)
	{
		alert("请选择【出生年月】 - 日\n");
		objForm.day.focus();
		return false;
	}

	if (height == "" || (!height.match(rs))  || (height < 130 || height > 260))
	{
		alert("【我的身高】不能为空或数值不符合规范\n");
		objForm.height.focus();
		return false;
	}

	if (marriage == 0)
	{
		objForm.marriage.focus();
		alert("请选择【婚姻状况】\n");
		return false;
	}

	if (degree == 0)
	{
		alert("请选择【学历】\n");
		objForm.degree.focus();
		return false;
	}

	if (income == 0)
	{
		alert("请选择【月薪】\n");
		objForm.income.focus();
		return false;
	}

	if (age <= 19)
	{
		if(income >= 40)
		{
			alert("【出生年月】对应的【月薪】不符合实际情况\n");
			objForm.income.focus();
			return false;
		}
		if (degree >= 50)
		{
			alert("【出生年月】对应的【学历】不符合实际情况\n");
			objForm.degree.focus();
			return false;
		}		
		if (document.getElementById("sexf").checked && marriage >= 2)
		{
			alert("【出生年月】对应的【婚姻状况】不符合实际情况\n");
			objForm.year.focus();
			return false;
		}
		if (document.getElementById("sexm").checked && marriage >= 2)
		{
			alert("【出生年月】对应的【婚姻状况】不符合实际情况\n");
			objForm.year.focus();
			return false;
		}
	}
	else if (age <= 20)
	{
		if(income >= 40)
		{
			alert("【出生年月】对应的【月薪】不符合实际情况\n");
			objForm.income.focus();
			return false;
		}
		if (degree >= 50)
		{
			alert("【出生年月】对应的【学历】不符合实际情况\n");
			objForm.degree.focus();
			return false;
		}		
		if (document.getElementById("sexf").checked && marriage >= 2)
		{
			alert("【出生年月】对应的【婚姻状况】不符合实际情况\n");
			objForm.year.focus();
			return false;
		}
		if (document.getElementById("sexm").checked && marriage >= 2)
		{
			alert("【出生年月】对应的【婚姻状况】不符合实际情况\n");
			objForm.year.focus();
			return false;
		}
	}
	else if (age <= 21)
	{
		if (degree >= 60 && income >= 40)
		{
			alert("【出生年月】对应的【学历】【月薪】都不符合实际情况\n");
			objForm.degree.focus();
			return false;
		}
		if (degree >= 60)
		{
			alert("【出生年月】对应的【学历】不符合实际情况\n");
			objForm.degree.focus();
			return false;
		}
		if (income >= 40)
		{
			alert("【出生年月】对应的【月薪】不符合实际情况\n");
			objForm.income.focus();
			return false;
		}
		if (document.getElementById("sexm").checked && marriage >= 2)
		{
			alert("【出生年月】对应的【婚姻状况】不符合实际情况\n");
			objForm.year.focus();
			return false;
		}
	}
	else if (age <= 22)
	{
		if (document.getElementById("sexm").checked && marriage >= 2)
		{
			alert("【出生年月】对应的【婚姻状况】不符合实际情况\n");
			objForm.year.focus();
			return false;
		}
		if (income >= 50)
		{
			alert("【出生年月】对应的【月薪】不符合实际情况\n");
			objForm.income.focus();
			return false;
		}
	}
	else if (age <= 23 && (degree >= 70))
	{
		alert("【出生年月】对应的【学历】不符合实际情况\n");
		objForm.degree.focus();
		return false;
	}
	else if (age <= 26 && income >= 70)
	{
		alert("【出生年月】对应的【月薪】不符合实际情况\n");
		objForm.income.focus();
		return false;
	}
	else
	{
		//虚假用户判断完毕
	}

	if (province == 0)
	{
		alert("请选择【所在地区】 - 省份\n");
		objForm.province.focus();
		return false;
	}

	if (city == 0)
	{
		alert("请选择【所在地区】 - 城市\n");
		objForm.city.focus();
		return false;
	}

	if (checkcode == "" || (!checkcode.match(rc)))
	{
		alert("【验证码】不能为空或字符不符合规范\n");
		objForm.checkcode.focus();
		return false;
	}

	if (note != "" && (note.length < 20 || note.length >1000))
	{
		alert("【内心独白】长度不符合规范\n");
		objForm.note.focus();
		return false;
	}

	if (note == "")
	{
		alert("请您补充【内心独白】，打动有缘人\n");
		objForm.note.focus();
		return false;
	}
	/*if(!check_mobile())
	{
		document.getElementById('mobile').focus();
		alert("请填写正确的手机号");
		return false;
	}*/
	if(!check_needage())
	{
		document.getElementById('needage_min').focus();
		alert("请认真填写您的征友要求");
		return false;
	}
	if(!check_needheight())
	{
		document.getElementById('needheight_min').focus();
		alert("请认真填写您的征友要求");
		return false;
	}
	if(!document.getElementById("readme").checked)
	{
		//regreadmeinfo.className="show err xianding";
		//regreadmeinfo.innerHTML="必须同意本条款才能注册";
		alert("请勾选【世纪佳缘条款】才能完成注册\n");
		return false;
	}

	return true;
}

function default_focus(objName)
{
	eval("document.Form1."+objName+".focus();");
}
