// JavaScript Document
//<!---------------------------------+
//  Developed by Roshan Bhattarai 
//  Visit http://roshanbh.com.np for this script and more.
//  This notice MUST stay intact for legal use

function Trim(myval)
{
	var chklen=myval.length; 
	var pos=0;
	mychar = myval.charAt(0);
	while(pos>=0 || lstpos >=0)
	{
		pos=myval.indexOf(" ");
		if (pos==0)
		{
			myval=myval.substring(1,chklen);
			chklen = myval.length;
			mychar = myval.charAt(0);
		}

		lstpos=myval.lastIndexOf(" ");
		if (lstpos==chklen-1)
		{	
			myval=myval.substring(0,chklen-1);
			chklen=myval.length;
			mychar = myval.charAt(chklen-1);
		}		

		if(mychar!=" ")
			break;
	}
	return myval;
}

function passwordStrength(password)
{
	var desc = new Array();
	desc[0] = "Very Weak";
	desc[1] = "Weak";
	desc[2] = "Better";
	desc[3] = "Medium";
	desc[4] = "Strong";
	desc[5] = "Strongest";

	var score   = 0;

	//if password bigger than 6 give 1 point
	if (password.length > 6) score++;

	//if password has both lower and uppercase characters give 1 point	
	if ( ( password.match(/[a-z]/) ) && ( password.match(/[A-Z]/) ) ) score++;

	//if password has at least one number give 1 point
	if (password.match(/\d+/)) score++;

	//if password has at least one special caracther give 1 point
	if ( password.match(/.[!,@,#,$,%,^,&,*,?,_,~,-,(,)]/) )	score++;

	//if password bigger than 12 give another 1 point
	if (password.length > 12) score++;

	 document.getElementById("passwordDescription").innerHTML = desc[score];
	 document.getElementById("passwordStrength").className = "strength" + score;
}


function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char; 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;   
}

function validate()
{
	if(document.frm.name.value.split(" ").join("") == "")
	{
		alert("请输入名字");
		document.frm.name.focus();
		document.frm.name.select();
		return false;
	}		
	else if(document.frm.english_name.value.split(" ").join("") == "")
	{
		alert("请输入英文姓名");
		document.frm.english_name.focus();
		document.frm.english_name.select();
		return false;
	}		
	/*else if(document.frm.marriage.checked==false)
	{
		alert("请选择婚姻状况");
		document.frm.marriage.focus();
		return false;
	}	
	else if(document.frm.phone.value.split(" ").join("") == "")
	{
		alert("请输入电话");
		document.frm.phone.focus();
		document.frm.phone.select();
		return false;
	}	*/
	else if(document.frm.country_id.selectedIndex==0)
	{
		alert("请选择国家");
		return false;
	}
	else if(document.frm.e_id.selectedIndex==0)
	{
		alert("请选择学历");
		document.frm.e_id.focus();
		return false;
	}	
	else if(document.frm.state.value.split(" ").join("")=="")
	{
		alert("请输入州");
		document.frm.state.focus();
		document.frm.state.select();
		return false;
	}
	else if(document.frm.postcode.value.split(" ").join("")=="")
	{
		alert("请输入邮递区号");
		document.frm.postcode.focus();
		document.frm.postcode.select();
		return false;
	}
	/*else if(document.frm.organization.value.split(" ").join("") == "")
	{
		alert("请输入服务单位");
		document.frm.organization.focus();
		document.frm.organization.select();
		return false;
	}*/
	else if(document.frm.gender[0].checked==false && document.frm.gender[1].checked==false)
	{
		alert("请选择性别");
		return false;
	}			
	else if(document.frm.address.value.split(" ").join("") == "")
	{
		alert("请输入地址");
		document.frm.address.focus();
		document.frm.address.select();
		return false;
	}	
	else if(document.frm.oc_id.selectedIndex==0)
	{
		alert("请选择职称");
		document.frm.oc_id.focus();
		return false;
	}	
	/*else if(document.frm.b_id.selectedIndex==0)
	{
		alert("请选择职业类别");
		document.frm.b_id.focus();
		return false;
	}	
	else if(document.frm.income_id.selectedIndex==0)
	{
		alert("请选择月收入");
		document.frm.income_id.focus();
		return false;
	}	*/
	else if(document.frm.how_id.selectedIndex==0)
	{
		alert("请选择如何得知我们");
		document.frm.how_id.focus();
		return false;
	}	
	return true;

}

function validatePasswd()
{
	
	if(Trim(document.frm_passwd.oldpass.value)=="")
	{
		alert("请输入旧密码");
		document.frm_passwd.oldpass.select();
		document.frm_passwd.oldpass.focus();
		return false;
	}
	else if(Trim(document.frm_passwd.pass.value)=="")
	{
		alert("请输入密码");
		document.frm_passwd.pass.select();
		document.frm_passwd.pass.focus();
		return false;
	}
	else if (document.frm_passwd.pass.value.length < 5) {
		alert("请输入密码长度 >5");
		document.frm_passwd.pass.select();
		document.frm_passwd.pass.focus();
		return false;
	}
	else if(Trim(document.frm_passwd.Repasswd.value)=="")
	{
		alert("请输入确认密码");
		document.frm_passwd.Repasswd.select();
		document.frm_passwd.Repasswd.focus();
		return false;
	}
	else if(Trim(document.frm_passwd.passwd.value)!=Trim(document.frm_passwd.Repasswd.value))
	{
		alert("确认密码不符");
		document.frm_passwd.Repasswd.select();
		document.frm_passwd.Repasswd.focus();
		return false;
	}
	return true;
}

function validSubject()
{
	if(document.frm.name.value.split(" ").join("") == "")
	{
		alert("请输入名字");
		document.frm.name.select();
		document.frm.name.focus();
		return false;
	}
	else if(document.frm.email.value.split(" ").join("") == "")
	{
		alert("请输入电子邮件地址");
		document.frm.email.select();
		document.frm.email.focus();
		return false;
	}

	var x = document.frm.email.value;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	var valid="123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

	if (!filter.test(x))
	{
		 alert('电子邮件地址错误');
		 return false;		 
	}	
	else if(document.frm.msg.value.split(" ").join("") == "")
	{
		alert("请输入讯息");
		document.frm.msg.select();
		document.frm.msg.focus();
		return false;
	}

	return true;
}


function validSubscribe2()
{
	if(document.frmS.english_name.value.split(" ").join("") == "")
	{
		alert("请输入英文姓名");
		document.frmS.english_name.select();
		document.frmS.english_name.focus();
		return false;
	}
	else if(document.frmS.email.value.split(" ").join("") == "")
	{
		alert("请输入电子邮件地址");
		document.frmS.email.select();
		document.frmS.email.focus();
		return false;
	}

	var x = document.frmS.email.value;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	var valid="123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

	if (!filter.test(x))
	{
		 alert('电子邮件地址错误');
		 return false;		 
	}	
	return true;
}

function validateRegister()
{
	if(document.frm.username.value.split(" ").join("") == "")
	{
		alert("请输入电子邮件地址");
		document.frm.username.focus();
		document.frm.username.select();
		return false;
	}
	
	var x = document.frm.username.value;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	var valid="123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

	if (!filter.test(x))
	{
		 alert('电子邮件地址错误');
		 return false;		 
	}	
	else if(document.frm.pass.value.split(" ").join("") == "")
	{
		alert("请输入密码");
		document.frm.pass.select();
		document.frm.pass.focus();
		return false;
	}
	else if (document.frm.pass.value.length < 5) {
		alert("请输入密码长度 >5");
		document.frm.pass.select();
		document.frm.pass.focus();
		return false;
	}
	else if(Trim(document.frm.pass.value)!=Trim(document.frm.Repasswd.value))
	{
		alert("确认密码不符");
		document.frm.Repasswd.select();
		document.frm.Repasswd.focus();
		return false;
	}
	else if(document.frm.english_name.value.split(" ").join("") == "")
	{
		alert("请输入英文姓名");
		document.frm.english_name.focus();
		document.frm.english_name.select();
		return false;
	}		
	else if(document.frm.name.value.split(" ").join("") == "")
	{
		alert("请输入名字");
		document.frm.name.focus();
		document.frm.name.select();
		return false;
	}	
	else if(document.frm.gender[0].checked==false && document.frm.gender[1].checked==false)
	{
		alert("请选择性别");
		return false;
	}				
	else if(document.frm.year.value.split(" ").join("") == "" || document.frm.year.value == "19")
	{
		alert("请输入生日日期");
		document.frm.year.focus();
		document.frm.year.select();
		return false;
	}
	else if(document.frm.country_id.selectedIndex==0)
	{
		alert("请选择国家");
		return false;
	}
	else if(document.frm.state.value.split(" ").join("")=="")
	{
		alert("请输入州");
		document.frm.state.focus();
		document.frm.state.select();
		return false;
	}
	else if(document.frm.postcode.value.split(" ").join("")=="")
	{
		alert("请输入邮递区号");
		document.frm.postcode.focus();
		document.frm.postcode.select();
		return false;
	}
	else if(document.frm.address.value.split(" ").join("") == "")
	{
		alert("请输入地址");
		document.frm.address.focus();
		document.frm.address.select();
		return false;
	}	
	else if(document.frm.phone.value.split(" ").join("") == "")
	{
		alert("请输入电话");
		document.frm.phone.focus();
		document.frm.phone.select();
		return false;
	}	
	else if(document.frm.e_id.selectedIndex==0)
	{
		alert("请选择学历");
		document.frm.e_id.focus();
		return false;
	}	
	/*else if(document.frm.organization.value.split(" ").join("") == "")
	{
		alert("请输入服务单位");
		document.frm.organization.focus();
		document.frm.organization.select();
		return false;
	}*/
	else if(document.frm.oc_id.selectedIndex==0)
	{
		alert("请选择职称");
		document.frm.oc_id.focus();
		return false;
	}	
	/*else if(document.frm.b_id.selectedIndex==0)
	{
		alert("请选择职业类别");
		document.frm.b_id.focus();
		return false;
	}	
	else if(document.frm.income_id.selectedIndex==0)
	{
		alert("请选择月收入");
		document.frm.income_id.focus();
		return false;
	}	*/
	else if(document.frm.how_id.selectedIndex==0)
	{
		alert("请选择如何得知我们");
		document.frm.how_id.focus();
		return false;
	}	
	else if(document.frm.agree.checked==false)
	{
		 alert("您必须同意该协议");
     	 document.frm.agree.focus();
    	 return false;
	}	
	return true;
}

function validateLogin()
{
	if(document.frm_login.username.value.split(" ").join("")=="")
	{
		alert("请输入电子邮件地址");
		document.frm_login.username.focus();
		return false;
	}
	if(document.frm.passwd.value.split(" ").join("")=="")
	{
		alert("请输入密码");
		document.frm_login.passwd.focus();
		return false;
	}
	return true;	
}

function validFPasswd()
{
	if(document.frm_pwd.username.value.split(" ").join("")=="")
	{
		alert("请输入电子邮件地址");
		document.frm_pwd.username.focus();
		return false;
	}		
	return true;	
}

function setValue(){
 document.frmAd.city.value=document.frmAd.hCity.value;
 document.frmAd.company.value=document.frmAd.hCompany.value;
 document.frmAd.address.value=document.frmAd.hAddress.value;
 document.frmAd.postcode.value=document.frmAd.hPostcode.value;
 document.frmAd.state.value=document.frmAd.hStateID.value;
 document.frmAd.phone.value=document.frmAd.hPhone.value;
}

// JavaScript Document
function SelectAll(id, text)
{	
	if(document.getElementById(id).value==text)
	{
		/*if(document.getElementById(id).value=="Password")
		{
			document.getElementById(id).type="password";
		}	*/
		document.getElementById(id).value="";
		document.getElementById(id).focus();
		document.getElementById(id).select();
	}		
}

function checkSub()
{
	if(document.frmSubscribe.txtEmail.value.split(" ").join("")=="")
	{
		alert("请输入电子邮件地址");
		document.frmSubscribe.txtEmail.focus();
		document.frmSubscribe.txtEmail.select();		
		return false;
	}
	if(!validateEmail(document.frmSubscribe.txtEmail))
	{
		alert("电子邮件地址无效");
		document.frmSubscribe.txtEmail.focus();
		document.frmSubscribe.txtEmail.select();		
		return false;
	}
	return true
}

function show_other()
{
	if(document.frm.delete_reason.selectedIndex==5)
	{
		document.getElementById("div_other").visibility=visible;
	}
	else
	{
		document.getElementById("div_other").visibility=hidden;
		document.frm.delete_reason_other.value="";
	}
}

function checkForumReply()
{
	if(document.frmForum.answer.value.split(" ").join("")=="")
	{
		alert("请输入发言");
		document.frmForum.answer.focus();
		document.frmForum.answer.select();		
		return false;
	}
	return true
}

function checkForum()
{
	if(document.frmForum.subject.value.split(" ").join("")=="")
	{
		alert("请输入主题");
		document.frmForum.subject.focus();
		document.frmForum.subject.select();		
		return false;
	}
	else if(document.frmForum.question.value.split(" ").join("")=="")
	{
		alert("请输入内文");
		document.frmForum.question.focus();
		document.frmForum.question.select();		
		return false;
	}
	return true
}

function validateJob()
{
	if(document.frm.name.value.split(" ").join("") == "")
	{
		alert("请输入名字");
		document.frm.name.select();
		document.frm.name.focus();
		return false;
	}
	else if(document.frm.email.value.split(" ").join("") == "")
	{
		alert("请输入电子邮件地址");
		document.frm.email.select();
		document.frm.email.focus();
		return false;
	}

	var x = document.frm.email.value;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	var valid="123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

	if (!filter.test(x))
	{
		 alert('电子邮件地址错误');
		 return false;		 
	}		

	return true;
}

function validateShipping()
{
	if(document.getElementById("div_1").style.display=="block")
	{
		mycount = 0;
		for(i=0;i<document.frm.elements.length;i++)
		{
			if(document.frm.elements[i].name.substr(0,9)=="pickup_id" && document.frm.elements[i].checked)
				mycount++;	
		}
	
		if(mycount==0)
		{
			alert("You must check one of the location for pickup.");
			return false;
		}
	
	}
	
	if(document.getElementById("div_2").style.display=="block")
	{
		if(document.frm.d_name.value.split(" ").join("") == "")
		{
			alert("请输入收货人");
			document.frm.d_name.focus();
			document.frm.d_name.select();
			return false;
		}		
		else if(document.frm.d_organization.value.split(" ").join("") == "")
		{
			alert("请输入服务单位");
			document.frm.d_organization.focus();
			document.frm.d_organization.select();
			return false;
		}	
		else if(document.frm.d_country_id.selectedIndex==0)
		{
			alert("请选择所在国家");
			document.frm.d_country_id.focus();
			return false;
		}			
		else if(document.frm.d_state.selectedIndex==0)
		{
			alert("请选择州");
			document.frm.d_state.focus();
			return false;
		}			
		else if(document.frm.d_city.value.split(" ").join("") == "")
		{
			alert("请输入镇区");
			document.frm.d_city.focus();
			document.frm.d_city.select();
			return false;
		}	
		else if(document.frm.d_postcode.value.split(" ").join("") == "")
		{
			alert("请输入邮递区号");
			document.frm.d_postcode.focus();
			document.frm.d_postcode.select();
			return false;
		}	
		else if(document.frm.d_address.value.split(" ").join("") == "")
		{
			alert("请输入地址");
			document.frm.d_address.focus();
			document.frm.d_address.select();
			return false;
		}	
		else if(document.frm.d_phone.value.split(" ").join("") == "")
		{
			alert("请输入电话");
			document.frm.d_phone.focus();
			document.frm.d_phone.select();
			return false;
		}	
		else if(document.frm.d_mobile.value.split(" ").join("") == "")
		{
			alert("请输入行动电话");
			document.frm.d_mobile.focus();
			document.frm.d_mobile.select();
			return false;
		}		

	}
	return true;
}

function validateRecruite()
{
	if(document.frm1.contact_email.value.split(" ").join("") == "")
	{
		alert("请输入联络电子信箱");
		document.frm1.contact_email.focus();
		document.frm1.contact_email.select();
		return false;
	}
	
	var x = document.frm1.contact_email.value;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	var valid="123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

	if (!filter.test(x))
	{
		 alert('联络电子信箱错误');
		 return false;		 
	}		
	else if(document.frm1.organization.value.split(" ").join("") == "")
	{
		alert("请输入幼儿园名称");
		document.frm1.organization.focus();
		document.frm1.organization.select();
		return false;
	}		
	else if(document.frm1.position.value.split(" ").join("") == "")
	{
		alert("请输入职称");
		document.frm1.position.focus();
		document.frm1.position.select();
		return false;
	}		
	else if(document.frm1.expected_salary.selectedIndex==0)
	{
		alert("请输入期望薪金");
		document.frm1.expected_salary.focus();
		return false;
	}		
	else if(document.frm1.vacancy.selectedIndex==0)
	{
		alert("请选择人数");
		document.frm1.vacancy.focus();
		return false;
	}	
	else if(document.frm1.education.selectedIndex==0)
	{
		alert("请选择学术资格");
		document.frm1.education.focus();
		return false;
	}	
	else if(document.frm1.edu_background.selectedIndex==0)
	{
		alert("请选择学术背景");
		document.frm1.edu_background.focus();
		return false;
	}	
	else if(document.frm1.experience_year.selectedIndex==0)
	{
		alert("请选择经验");
		document.frm1.experience_year.focus();
		return false;
	}	
	else if(document.frm1.s_id.selectedIndex==0)
	{
		alert("请选择征聘职位");
		document.frm1.s_id.focus();
		return false;
	}	
	else if(document.frm1.address.value.split(" ").join("")=="")
	{
		alert("请输入地址");
		document.frm1.address.focus();
		document.frm1.address.select();
		return false;
	}
	else if(document.frm1.city.value.split(" ").join("")=="")
	{
		alert("请输入镇区");
		document.frm1.city.focus();
		document.frm1.city.select();
		return false;
	}
	else if(document.frm1.state.value.split(" ").join("")=="")
	{
		alert("请输入州");
		document.frm1.state.focus();
		document.frm1.state.select();
		return false;
	}
	else if(document.frm1.postcode.value.split(" ").join("")=="")
	{
		alert("请输入邮递区号");
		document.frm1.postcode.focus();
		document.frm1.postcode.select();
		return false;
	}
	else if(document.frm1.contact_person.value.split(" ").join("") == "")
	{
		alert("请输入联络姓名");
		document.frm1.contact_person.focus();
		document.frm1.contact_person.select();
		return false;
	}	
	else if(document.frm1.contact_number.value.split(" ").join("") == "")
	{
		alert("请输入联络电话");
		document.frm1.contact_number.focus();
		document.frm1.contact_number.select();
		return false;
	}	
	else if(document.frm1.agree.checked==false)
	{
		 alert("您必须同意该协议");
     	 document.frm1.agree.focus();
    	 return false;
	}	
	return true;
}


function validateSchool()
{
	if(document.frm.email.value.split(" ").join("") == "")
	{
		alert("请输入电邮");
		document.frm.email.focus();
		document.frm.email.select();
		return false;
	}	
	
	var x = document.frm.email.value;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	var valid="123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

	if (!filter.test(x))
	{
		 alert('联络电邮错误');
		 return false;		 
	}		
	else if(document.frm.name.value.split(" ").join("") == "")
	{
		alert("请输入名称");
		document.frm.name.focus();
		document.frm.name.select();
		return false;
	}		
	else if(document.frm.address.value.split(" ").join("") == "")
	{
		alert("请输入地址");
		document.frm.address.focus();
		document.frm.address.select();
		return false;
	}		
	else if(document.frm.state.value.split(" ").join("") == "")
	{
		alert("请输入州");
		document.frm.state.focus();
		document.frm.state.select();
		return false;
	}	
	else if(document.frm.city.value.split(" ").join("") == "")
	{
		alert("请输入镇区");
		document.frm.city.focus();
		document.frm.city.select();
		return false;
	}	
	else if(document.frm.phone.value.split(" ").join("") == "")
	{
		alert("请输入联络电话（公司）");
		document.frm.phone.focus();
		document.frm.phone.select();
		return false;
	}		
	else if(document.frm.contact_person.value.split(" ").join("") == "")
	{
		alert("请输入联络人");
		document.frm.contact_person.focus();
		document.frm.contact_person.select();
		return false;
	}		
		
	if(document.frm.type.value == "1")
	{
		if(document.frm.philosophy.value.split(" ").join("") == "")
		{
			alert("请输入园所理念");
			document.frm.philosophy.focus();
			document.frm.philosophy.select();
			return false;
		}	
		else if(document.frm.teaching_approach.value.split(" ").join("") == "")
		{
			alert("请输入教学模式");
			document.frm.teaching_approach.focus();
			document.frm.teaching_approach.select();
			return false;
		}	
		
		else if(document.frm.ratio.value.split(" ").join("") == "")
		{
			alert("请输入师生对比");
			document.frm.ratio.focus();
			document.frm.ratio.select();
			return false;
		}	
		else if(document.frm.age_group.value.split(" ").join("") == "")
		{
			alert("请输入年龄");
			document.frm.age_group.focus();
			document.frm.age_group.select();
			return false;
		}		
	}
	else if(document.frm.type.value == "2")
	{
		if(document.frm.philosophy.value.split(" ").join("") == "")
		{
			alert("请输入厂商理念");
			document.frm.philosophy.focus();
			document.frm.philosophy.select();
			return false;
		}	
		else if(document.frm.business_approach.selectedIndex==0)
		{
			alert("请选择交易模式");
			document.frm.business_approach.focus();
			return false;
		}	
		else if(document.frm.product.value.split(" ").join("") == "")
		{
			alert("请输入产品");
			document.frm.product.focus();
			document.frm.product.select();
			return false;
		}		
	}
	
	if(document.frm.agree.checked==false)
	{
		 alert("您必须同意该协议");
     	 document.frm.agree.focus();
    	 return false;
	}	
	
	return true;
}

