//验证用户注册表单
function check_reg() {
	username= document.reg.username.value;
	password= document.reg.password.value;
	passwordagain= document.reg.passwordagain.value;
	realname= document.reg.realname.value;
	nickname= document.reg.nickname.value;
	validate=  document.reg.validate.value;
	
	if(username == "") 
	{ document.getElementById("username1").innerHTML ="<table border=0 style='border:#ff0000 1px solid' cellpadding=5><tr><td><font color=red class=f131red>Please input your email to take user.</font></td></tr></table>";
	document.reg.username.focus();
    return false;
	}
	else{ document.getElementById("username1").innerHTML=""}	 
	var pattern = /^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
	
	if(!pattern.test(username)) 
	{ document.getElementById("username1").innerHTML="<table border=0 style='border:#ff0000 1px solid' cellpadding=5><tr><td><font color=red class=f131red>Please specify a valid email address.</font></td></tr></table>";
	 document.reg.username.focus();
	 return false;}
	 else{ document.getElementById("username1").innerHTML=""}

	if(password == "") 
	{ document.getElementById("password1").innerHTML="<table border=0 style='border:#ff0000 1px solid' cellpadding=5><tr><td><font color=red class=f131red>Please enter a password to create an account.</font></td></tr></table>";
	 document.reg.password.focus();
	 return false;}
	 else{ document.getElementById("password1").innerHTML=""}
	 var patrn=/^(\w){4,20}$/;
	if(!patrn.exec(password)) 
	{ document.getElementById("password1").innerHTML="<table border=0 style='border:#ff0000 1px solid' cellpadding=5><tr><td><font color=red class=f131red>Please enter a valid password.</font></td></tr></table>";
	 document.reg.password.focus();
     return false;}
	 else{ document.getElementById("password1").innerHTML=""}
	 
	if(passwordagain == "" || passwordagain!=password) 
	{document.getElementById("passwordagain1").innerHTML="<table border=0 style='border:#ff0000 1px solid' cellpadding=5><tr><td><font color=red class=f131red>Please enter password again.</font></td></tr></table>"
	 document.reg.passwordagain.focus();
	 return false;}
	 else{document.getElementById("passwordagain1").innerHTML=""}
	 
	if(realname == "") 
	{document.getElementById("realname1").innerHTML="<table border=0 style='border:#ff0000 1px solid' cellpadding=5><tr><td><font color=red class=f131red>Please enter your name.</font></td></tr></table>"
	 document.reg.realname.focus();
     return false;}
	 else{document.getElementById("realname1").innerHTML=""}
	 
	 if(nickname == "") 
	{document.getElementById("nickname1").innerHTML="<table border=0 style='border:#ff0000 1px solid' cellpadding=5><tr><td><font color=red class=f131red>Please enter your nickname.</font></td></tr></table>"
	 document.reg.nickname.focus();
     return false;}
	 else{document.getElementById("nickname1").innerHTML=""}
	 var patrn=/^.{4,15}$/;
	 if(!patrn.exec(nickname)) 
	 { document.getElementById("nickname1").innerHTML="<table border=0 style='border:#ff0000 1px solid' cellpadding=5><tr><td><font color=red class=f131red>Nickname cannot surpass 15 characters.</font></td></tr></table>"
	 document.reg.nickname.focus();
     return false;}
	 else{ document.getElementById("nickname1").innerHTML=""}
 
	 if(validate == "") 
	{document.getElementById("validate1").innerHTML="<table border=0 style='border:#ff0000 1px solid' cellpadding=5><tr><td><font color=red class=f131red>Please input confirms the code.</font></td></tr></table>"
	 document.reg.validate.focus();
     return false;}
	 else{document.getElementById("validate1").innerHTML=""}
	 
}


function userinfo(){
	password= document.reg.password.value;
	passwordagain= document.reg.passwordagain.value;
	realname= document.reg.realname.value;
	nickname= document.reg.nickname.value;
	tel= document.reg.tel.value;
	address= document.reg.address.value;
	zip= document.reg.zip.value;
    if(password != ""){
	 var patrn=/^(\w){4,20}$/;	
	if(!patrn.exec(password))
	{alert("Please enter a valid password.");
	return false;
	}
	} 
	 
	if( passwordagain!=password) 
	{alert("Please enter password again.");
     return false;}
	
	if(realname == "") 
	{alert("Please enter your name.");
     return false;}

	 
	 if(nickname == ""){
		alert("Please enter your nickname.");
     	return false;
	 }
	 else{
			var patrn=/^.{4,15}$/;
			if(!patrn.exec(nickname)){
				alert("Nickname must be 4 to 15 characters.");
				return false;
			}	
	 }
	
}


//验证用户登录表单
function check_login(){
	username=document.login_form.username.value;	
	password=document.login_form.password.value;
	validate=document.login_form.validate.value;
	
	if(username==""){
	alert("Please enter your member id!");
	document.login_form.username.focus();
	return false;
	}
	
	if(password==""){
	alert("Please enter password!");
	document.login_form.password.focus();
	return false;
	}
	
	if(validate==""){
	alert("Please enter the security word!");
	document.login_form.validate.focus();
	return false;
	}
}

//验证栏目表单
function check_section(){
	sec_type=document.addform.sec_type.value;
	subject=document.addform.subject.value;
//	FCKeditor1=document.getElementById("FCKeditor1").value;
	
	if(sec_type==""){
	alert("Please select the section type!");
	document.addform.sec_type.focus();
	return false;
	}
	if(subject==""){
	alert("Please input the subject!");
	document.addform.subject.focus();
	return false;
	}
//	if(FCKeditor1==""){
//	alert("Please input the content!");
//	document.addform.FCKeditor1.focus();
//	return false;
//	}

}
//验证栏目表单(修改内容)
function check_section_modi(){
	subject=document.section_modi.subject.value;
	if(subject==""){
	alert("Please input the subject!");
	document.section_modi.subject.focus();
	return false;
	}
}
//验证栏目表单(修改图片)
function check_section_modi_p(){
	file=document.modiform_p.file.value;
	if(file==""){
	alert("Please input the file path!");
	document.modiform_p.file.focus();
	return false;
	}
}
//验证地区表单
function check_region(){
	region_name=document.addform.region_name.value;
	
	if(region_name==""){
			alert("Please input the region name!");
			document.addform.region_name.focus();
			return false;
		}
	}
//验证地区修改表单
function check_region_modi(){
	region_name=document.modiform.region_name.value;
	
	if(region_name==""){
			alert("Please input the region name!");
			document.modiform.region_name.focus();
			return false;
		}
	}
//验证评论表单
function check_review(){
	Scenery=document.reviewform.Scenery.value;
	Dining=document.reviewform.Dining.value;
	Transportation=document.reviewform.Transportation.value;
	Lodgings=document.reviewform.Lodgings.value;
	commentary=document.reviewform.commentary.value;
	
	if(Scenery==""){
			alert("Please select the Scenery!");
			document.reviewform.Scenery.focus();
			return false;
		}
	if(Dining==""){
			alert("Please select the Dining!");
			document.reviewform.Dining.focus();
			return false;
		}
	if(Transportation==""){
			alert("Please select the Transportation!");
			document.reviewform.Transportation.focus();
			return false;
		}
	if(Lodgings==""){
			alert("Please select the Lodgings!");
			document.reviewform.Lodgings.focus();
			return false;
		}
	if(commentary==""){
			alert("Please input the brief commentary!");
			document.reviewform.commentary.focus();
			return false;
		}
	var   theNum=0;   
    var   theCheckboxInputs=document.all.degree;
    for   (var i=0;i<theCheckboxInputs.length;i++){   
  			if(theCheckboxInputs[i].checked)   theNum++;   
  		}
	if(theNum==0) {
	alert("Please select the Affection degree!");
	return false;
	}
}
//设定图片大小，保证原图片长高比例,且不超过最大高度或宽度
function initimg(parpic,maxwidth,maxheight)
{
var scale=maxwidth/maxheight;
var realscale=parpic.width/parpic.height;
if((parpic.width>maxwidth)||(parpic.height>maxheight))
{
if(realscale>scale)
{
parpic.width=maxwidth;
}
else
{
parpic.height=maxheight;
}
}
}

//删除确定
function confirmdel(con) {
  if(confirm("Determination deletion?")){
  	location.href=con;
  }
  else{
  	return;
  }  
}
//树形目录
function ShowMenu(MenuID)
{ 
 if(MenuID.style.display=="none"){ 
    MenuID.style.display=""; 
 } 
 else{ 
 MenuID.style.display="none"; 
 } 
} 
//********************************************************** food begin ***************************************************************
//验证餐馆英文注册表单

function check_reg_en(){
	username=document.reg_en.username.value;
	password=document.reg_en.password.value;
	passwordagain=document.reg_en.passwordagain.value;
	linkman=document.reg_en.linkman.value;
	enname=document.reg_en.enname.value;
	aid_a=document.reg_en.aid_a.value;
	address=document.reg_en.address.value;
	city=document.reg_en.city.value;
	email=document.reg_en.email.value;
	othertel=document.reg_en.othertel.value;
	zip=document.reg_en.zip.value;
	pricelow=Number(document.reg_en.pricelow.value);
	pricehigh=Number(document.reg_en.pricehigh.value);
	validate=document.reg_en.validate.value;
	
	if(username==""){
		alert("Please enter your telephone number as the login name!");
		document.reg_en.username.focus();
		return false;
	}
	var patrn=/^[0-9]{10}$/;
	if(!patrn.test(username)) {
		alert("Telephone number is 10 numbers!");
		document.reg_en.username.focus();
		return false;
	}
	if(password==""){
		alert("Passwords can not be empty!");
		document.reg_en.password.focus();
		return false;
	}
	var patrn=/^(\w){4,20}$/;
	if(!patrn.exec(password)) {
		alert("Password can be consist of 4 -20 english letters or numbers!");
		document.reg_en.password.focus();
		return false;
	}
	if(passwordagain==""){
		alert(" Please repeat password!");
		document.reg_en.passwordagain.focus();
		return false;
	}
	if(passwordagain!=password){
		alert("Please repeat the correct password!");
		document.reg_en.passwordagain.focus();
		return false;
	}
	if(linkman==""){
		alert("Contact person  can not be empty!");
		document.reg_en.linkman.focus();
		return false;
	}
	if(enname==""){
		alert("Restaurant name can not be empty!");
		document.reg_en.enname.focus();
		return false;
	}
	var theNum=0;
	for(var i=0;i<document.reg_en("foodtype[]").length;i++){
		if(document.reg_en("foodtype[]")[i].checked) theNum++; 
	}
	if(theNum==0){
		alert("Please choose the restaurants type!");
		return false;
	}
	if(address==""){
		alert("Please enter the detailed  address of restaurants!");
		document.reg_en.address.focus();
		return false;
	}
	if(city==""){
		alert("Please enter the city!");
		document.reg_en.city.focus();
		return false;
	}
    if(aid_a==""){
		alert("Please choose the location of restaurants!");
		document.reg_en.aid_a.focus();
		return false;
	}
	if(email!=""){
	var patrn = /^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
	if(!patrn.exec(email)) {
		alert("Please enter the correct mailing address!");
		document.reg_en.email.focus();
		return false;
	}
	}
	if(othertel!=""){
	var patrn=/^[0-9]{10}$/;
	if(!patrn.exec(othertel)) {
		alert(" Please enter  the correct othertel number!");
		document.reg_en.othertel.focus();
		return false;
	}
	}
	if(zip==""){
		alert("Please enter the ZIP!");
		document.reg_en.zip.focus();
		return false;
	}
	var patrn=/^[0-9 ]{3,12}$/;
	if(!patrn.exec(zip)) {
		alert("Please enter the correct ZIP!");
		document.reg_en.zip.focus();
		return false;
	}
	if(pricelow=="" | pricehigh==""){
		alert("Please enter the amount of restaurant per consumption!");
		document.reg_en.pricelow.focus();
		return false;
	}
	var patrn=/^([0-9]|[.]){1,5}$/;
	if(!patrn.exec(pricelow) || !patrn.exec(pricehigh)){
		alert("Please enter the correct amount of restaurants per consumption!");
		document.reg_en.pricelow.focus();
		return false;
	}
	if(pricehigh<pricelow){
		alert("Please enter the correct price range!");
		document.reg_en.pricelow.focus();
		return false;
	}
	var theNum=0;
	for(var i=0;i<document.reg_en("credit[]").length;i++){
		if(document.reg_en("credit[]")[i].checked) theNum++; 
	}
	if(theNum==0){
		alert("Please choose credit cards!");
		return false;
	}
	if(validate==""){
		alert("please input validation code!");
		document.reg_en.validate.focus();
		return false;
	}

}


//验证餐馆资料修改表单

function check_modi_en(){
	linkman=document.modi_en.linkman.value;
	name=document.modi_en.name.value;
	aid_a=document.modi_en.aid_a.value;
	address=document.modi_en.address.value;
	city=document.modi_en.city.value;
	email=document.modi_en.email.value;
	othertel=document.modi_en.othertel.value;
	zip=document.modi_en.zip.value;
	pricelow=Number(document.modi_en.pricelow.value);
	pricehigh=Number(document.modi_en.pricehigh.value);
//	introduce=document.modi_en.introduce.value;

	if(linkman==""){
		alert("Contact person  can not be empty!");
		document.modi_en.linkman.focus();
		return false;
	}
	if(name==""){
		alert("Restaurant name can not be empty!");
		document.modi_en.name.focus();
		return false;
	}
	var theNum=0;
	for(var i=0;i<document.modi_en("foodtype[]").length;i++){
		if(document.modi_en("foodtype[]")[i].checked) theNum++; 
	}
	if(theNum==0){
		alert("Please choose the restaurants type!");
		return false;
	}
	if(address==""){
		alert("Please enter the detailed  address of restaurants!");
		document.modi_en.address.focus();
		return false;
	}
	if(city==""){
		alert("Please enter the city!");
		document.modi_en.city.focus();
		return false;
	}
    if(aid_a==""){
		alert("Please choose the location of restaurants!");
		document.modi_en.aid_a.focus();
		return false;
	}
	if(email!=""){
	var patrn = /^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
	if(!patrn.exec(email)) {
		alert("Please enter the correct mailing address!");
		document.modi_en.email.focus();
		return false;
	}
	}
	if(othertel!=""){
	var patrn=/^[0-9]{10}$/;
	if(!patrn.exec(othertel)) {
		alert(" Please enter  the correct othertel number!");
		document.modi_en.othertel.focus();
		return false;
	}
	}
	if(zip==""){
		alert("Please enter the ZIP!");
		document.modi_en.zip.focus();
		return false;
	}
	var patrn=/^[0-9 ]{3,12}$/;
	if(!patrn.exec(zip)) {
		alert("Please enter the correct ZIP!");
		document.modi_en.zip.focus();
		return false;
	}
	if(pricelow=="" | pricehigh==""){
		alert("Please enter the amount of restaurant per consumption!");
		document.modi_en.pricelow.focus();
		return false;
	}
	var patrn=/^([0-9]|[.]){1,5}$/;
	if(!patrn.exec(pricelow) || !patrn.exec(pricehigh)){
		alert("Please enter the correct amount of restaurants per consumption!");
		document.modi_en.pricelow.focus();
		return false;
	}
	if(pricehigh<pricelow){
		alert("Please enter the correct price range!");
		document.modi_en.pricelow.focus();
		return false;
	}
	var theNum=0;
	for(var i=0;i<document.modi_en("credit[]").length;i++){
		if(document.modi_en("credit[]")[i].checked) theNum++; 
	}
	if(theNum==0){
		alert("Please choose credit cards!");
		return false;
	}
//	if(introduce==""){
//		alert("Please enter the restaurants introduction!");
//		document.modi_en.introduce.focus();
//		return false;
//	}
}

//修改餐馆密码验证表单
function check_modi_pwd(){
	password= document.modi_pwd.password.value;
	passwordagain= document.modi_pwd.passwordagain.value;
	oldpassword= document.modi_pwd.oldpassword.value;	
	if(oldpassword==""){
	alert("please input the old password!");
	document.modi_pwd.oldpassword.focus();
	return false;
	}
	
	if(password==""){
	alert("please input the password!");
	document.modi_pwd.password.focus();
	return false;
	}
	var patrn=/^(\w){4,20}$/;
	if(!patrn.exec(password)) 
	{
     alert("Please enter a valid password.");
		document.modi_pwd.password.focus();
		return false;
	}
	if(passwordagain == "" || passwordagain!=password) 
	{
	  alert("Please enter password again.");
	document.modi_pwd.passwordagain.focus();
     return false;
	}
}

//验证菜谱添加表单
function check_add_recipes(){
	it=document.add_recipes.it.value;
	subject=document.add_recipes.subject.value;
	aid=document.add_recipes.aid.value;
	
	if(it==""){
			alert("Please select the recipes type!");
			document.add_recipes.it.focus();
			return false;
		}
	if(aid==""){
			alert("Please select the recipes area!");
			document.add_recipes.aid.focus();
			return false;
		}
	if(subject==""){
			alert("Please input the recipes name!");
			document.add_recipes.subject.focus();
			return false;
		}
		
}

//验证餐馆用户登录表单
function check_member(){
		username=document.member_login.username.value;
		password=document.member_login.password.value;
		validate=document.member_login.validate.value;
		if(username==""){
			alert("Please enter username!");
			document.member_login.username.focus();
			return false;
		}
		if(password==""){
			alert("Please enter password!");
			document.member_login.password.focus();
			return false;
		}
		if(validate==""){
			alert("Please enter validate!");
			document.member_login.validate.focus();
			return false;
		}
}
//博客推荐文章发送
function check_sendmail(){
	m1=document.sendmailform.m1.value;
	m2=document.sendmailform.m2.value;
	m3=document.sendmailform.m3.value;
	m4=document.sendmailform.m4.value;
	m5=document.sendmailform.m5.value;
	myname=document.sendmailform.myname.value;

	if(m1=="" && m2=="" && m3=="" && m4=="" && m5=="" ){
		document.getElementById("n1").innerHTML="* Please at least fills in a complete Email address.";
		return false;
	}

	var patrn = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/;
	if(!patrn.exec(m1) && m1!="") {
		document.getElementById("nn1").innerHTML="* Please enter the correct mailing address.";
		return false;
	}
	if(!patrn.exec(m2) && m2!="") {
		document.getElementById("nn2").innerHTML="* Please enter the correct mailing address.";
		return false;
	}
	if(!patrn.exec(m3) && m3!="") {
		document.getElementById("nn3").innerHTML="* Please enter the correct mailing address.";
		return false;
	}
	if(!patrn.exec(m4) && m4!="") {
		document.getElementById("nn4").innerHTML="* Please enter the correct mailing address.";
		return false;
	}
	if(!patrn.exec(m5) && m5!="") {
		document.getElementById("nn5").innerHTML="* Please enter the correct mailing address.";
		return false;
	}
	
	if(myname==""){
		document.getElementById("n2").innerHTML="* Please input your name.";
		return false;
	}
	

}


