function textClear (input) {

        if ( input.value == input.defaultValue ) {

                input.value = "";

        }

}



function clearAll (input) {

        input.value = "";

}



function changeInput (input) {

        var text = input.value;

        if(text == "Chinese") text = "Chinese Name";

        if(text == "district") input.form["inputbox"].value = "输入行政区名";

        if(text == "address") input.form["inputbox"].value = "请输入道路名称";

        if(text == "name") input.form["inputbox"].value = "请输入餐馆名称";

        if(text == "bestdishes") input.form["inputbox"].value = "请输入招牌菜名称";

}



function textRestore (input) {

        if ( input.value == "" ) {

                input.value = input.defaultValue;

        }

}



function checkTerms() {

        if(document.getElementById("terms").checked == false) {

                alert("You must agree to the Terms of Use!");

                return false;

        } else { return true; }

}



function changeLanguage(element) {

        if(element.value == "Chinese") {

                document.forms["chinese_form"].submit();

        }

}



function a_changeLanguage(element) {

        if(element.value == "Chinese") {

                document.forms["a_chinese_form"].submit();

        }



        if(element.value == "English") {

                document.forms["a_english_form"].submit();

        }

}



function checkEmail(input){

        var str = input.value;

        var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i

        if (filter.test(str)) return true;

        else {

                alert("请输入正确的邮件地址");

                return false;

        }

}



function checkSearch(form)

{

        if(form["inputbox"].value.match(/Enter /)){

                alert(form["inputbox"].value);

                return false;

        } else return true;

}



function checkInvite()

{

        if(document.getElementById("invite_email").value == "") {

                alert("Please enter your email address.");

                return false;

        }



        if(!checkEmail(document.getElementById("invite_email"))) return false;



        if(document.getElementById("invite_host").value == "") {

                alert("Please enter a host.");

                return false;

        }



        if(document.getElementById("invite_event").value == "") {

                alert("Please enter an event.");

                return false;

        }



        if(document.getElementById("invite_remail").value == "") {

                alert("Please select who you wish to mail this invitation to.");

                return false;

        }



        if(document.getElementById("invite_message").value == "") {

                alert("Please enter a message.");

                return false;

        }



        return true;

}



function checkReview()

{

        if(document.getElementById("review_name").value == "Enter your name" && document.getElementById("review_radio").checked == true) {

                alert("Please enter a name.");

                return false;

        }



        if(document.getElementById("review_email").value == "") {

                alert("Please enter an email.");

                return false;

        }



        if(!checkEmail(document.getElementById("review_email"))) return false;



        if(document.getElementById("review_title").value == "") {

                alert("Please enter a title for your review.");

                return false;

        }



        alert(document.getElementById("review_food").checked);



        if(document.getElementById("review_detail").value == "") {

                alert("Please enter your review.");

                return false;

        }



        return true;

}

function checkLogin()

{

        //if(document.getElementById("newsletter_city").value == "Enter City") {

        //      alert("Please enter a city.");

        //      return false;

        //}



        if(document.getElementById("username").value == "") {

                alert("请输入用户名。");

                return false;

        }

        if(document.getElementById("password").value == "") {

                alert("请输入密码.");

                return false;

        }



        return true;

}



function checkRegister()

{

    var thisForm = document.addconsumer;
    if(thisForm.usercard.value == "" ) {
        alert("请输入会员卡号");
        thisForm.usercard.focus();
        return false;
     }

     if(isNaN(thisForm.usercard.value)  ) {
        alert("会员卡号不正确,必须为16位数字。");
        thisForm.usercard.focus();
        return false;
     }


     if(thisForm.usercard.value.length !=16) {
        alert("会员卡号不正确,必须为16位数字。");
        thisForm.usercard.focus();
        return false;
     }

/*
     if(thisForm.cellphone.value == "" ) {
        alert("请输入手机号码");
        thisForm.cellphone.focus();
        return false;
     }
*/
     if(isNaN(thisForm.cellphone.value)) {
        alert("请输入正确的手机号码");
        thisForm.cellphone.focus();
        return false;
     }
     if(thisForm.cellphone.value.length != 11) {
        alert("请输入正确的手机号码");
        thisForm.cellphone.focus();
        return false;
     }
	
     if(thisForm.username.value == "" ) {
        alert("请输入用户名");
        thisForm.username.focus();
        return false;
     }
	 if(thisForm.username.value.length <5 | thisForm.username.value.length>20) {

        alert("用户名输入5至20个字符");

        thisForm.username.focus();

        return false;

     }	 
	 if(thisForm.userPassword.value == "" ) {

        alert("请输入密码");

        thisForm.userPassword.focus();

        return false;

     }
	 if(thisForm.userPassword.value.length <5 | thisForm.userPassword.value.length>20) {

        alert("密码输入5至20个字符");

        thisForm.username.focus();

        return false;

     }	 
	 if(thisForm.userPassword.value != thisForm.confirmPassword.value ) {

        alert("前后两次输入的密码不一致");

        thisForm.confirmPassword.focus();

        return false;

     }     

 /* 
	 if(thisForm.confirmCode[0].checked && thisForm.cellphone.value == ""){
	 	alert("开通优惠券下载，请先输入手机号码");
        thisForm.cellphone.focus();
        return false;
			 		
	 }
*/
 if(thisForm.cellphone.value == "" && thisForm.phone.value == "" ) {
        alert("不填手机号码，则必须填联系电话");
        thisForm.phone.focus();
        return false;
     }
 if(thisForm.email.value == "" ) {
        alert("必须填邮件地址");
        thisForm.email.focus();
        return false;

     }	 	 
	 if(thisForm.phone.value != "" && thisForm.phone.value.length < 8) {

        alert("请输入正确的电话号码");

        thisForm.phone.focus();

        return false;

     }
	 
     if(thisForm.phone.value != "" && isNaN(thisForm.phone.value)) {

        alert("请输入正确的电话号码");

        thisForm.phone.focus();

        return false;

     }	

     if(thisForm.email.value != "") {

        if(!checkEmail(document.getElementById("email"))) {

            thisForm.email.focus();

            return false;

        }

     }

     return true;

}


function checkRegisterCell()
{
	var thisForm = document.addconsumer;
//	if(thisForm.confirmCode[0].checked) alert("1111111111");
//	 else alert("00000000");
	if(thisForm.username.value == "" ) {

        alert("请输入用户名");

        thisForm.username.focus();

        return false;

     }
	 if(thisForm.username.value.length <5 | thisForm.username.value.length>20) {

        alert("用户名输入5至20个字符");

        thisForm.username.focus();

        return false;

     }	 
	 if(thisForm.userPassword.value == "" ) {

        alert("请输入密码");

        thisForm.userPassword.focus();

        return false;

     }
	 if(thisForm.userPassword.value.length <5 | thisForm.userPassword.value.length>20) {

        alert("密码输入5至20个字符");

        thisForm.username.focus();

        return false;

     }	 
	 if(thisForm.userPassword.value != thisForm.confirmPassword.value ) {

        alert("前后两次输入的密码不一致");

        thisForm.confirmPassword.focus();

        return false;

     }     

     if(thisForm.cellphone.value != "" && thisForm.cellphone.value.length != 11) {

        alert("请输入正确的手机号码");

        thisForm.cellphone.focus();

        return false;

     }

     if(thisForm.cellphone.value != "" && isNaN(thisForm.cellphone.value)) {

        alert("请输入正确的手机号码");

        thisForm.cellphone.focus();

        return false;

     }
	 
/*
	 if(thisForm.confirmCode[0].checked && thisForm.cellphone.value == ""){
	 
	 	alert("开通优惠券下载，请先输入手机号码");

        thisForm.cellphone.focus();

        return false;
			 		
	 }
*/
	 
	 if(thisForm.email.value == "" ) {

        alert("必须填邮件地址");

        thisForm.email.focus();

        return false;

     }	 	 
	 
    
     if(thisForm.email.value != "") {

        if(!checkEmail(document.getElementById("email"))) {

            thisForm.email.focus();

            return false;

        }

     }

     return true;

}


function checkRegpass()
{

    var thisForm = document.addconsumer;
	
	if(thisForm.username.value == "" ) {

        alert("请输入用户名");

        thisForm.username.focus();

        return false;

     }
	if(thisForm.cellphone.value == "" && thisForm.email.value == "" ) {

        alert("手机号码和邮件地址至少应填一个");

        thisForm.cellphone.focus();

        return false;

     }    

    if((thisForm.loginid.value !="")&&(thisForm.loginid.value.length != 11)) {

       alert("请输入正确的手机号码");

       return false;

    }
	if(thisForm.email.value != "") {

        if(!checkEmail(document.getElementById("email"))) {

            thisForm.email.focus();

            return false;

        }

     }
    return true;

}

function checkUpdpwd()

{

    var thisForm = document.addconsumer;



    if(thisForm.cur_pwd.value == "") {

       alert("请输入现用密码");

       return false;

    }

    if(thisForm.new_pwd.value == "") {

       alert("请输入新密码");

       return false;

    }


    if((thisForm.new_pwd2.value.length < 5) || (this_Form.new_pwd.value.legnth < 5)) {

       alert("密码长度5至20位");

       return false;

    }
	
    if(thisForm.new_pwd2.value == "") {

       alert("请再一次输入新密码");

       return false;

    }
	 if(thisForm.new_pwd2.value != this_Form.new_pwd.value) {
	 
		alert("两次输入的密码不一致");

       return false;

    }

    return true;

}

function isMakeOf( sValue, sElement ){

        var nIndex = 0;

        sValue = sValue.toUpperCase();

        sElement = sElement.toUpperCase();



        for( nIndex = 0; nIndex < sValue.length; nIndex++ ){

                cCheck = sValue.charAt(nIndex);

                if (sElement.indexOf( cCheck )< 0)

                        return false;

        }

        return true;

}



function isNumber( sValue ){

        if( sValue == "" ) return false;

        return isMakeOf( sValue, "+-.0123456789" );

}

function isPhone( sValue ){

        if( sValue == "" ) return false;

        return isMakeOf( sValue, "+-ext().0123456789" );

}

function isEmail( sValue ){

        if( sValue == "" ) return true;

        if ( (sValue.length < 5) )

                return false;

        else if(sValue.indexOf("@")<=0 )

                return false;

        else if(sValue.indexOf(".")<=0 )

                return false;

        else if( !isMakeOf( sValue, "abcdefghijklmnopqrstuvwxyz0123456789-_.@" ) )

                return false;

        return true;

}

function checkClubForm()
{
		var thisForm = document.ClubForm;
		
		if(thisForm.title.value == "" ) {

			alert("请输入标题");
	
			thisForm.title.focus();
	
			return false;

     	}
		if(thisForm.content.value == "" ) {

			alert("请输入内容");
	
			thisForm.content.focus();
	
			return false;

     	}
		if(thisForm.district.value == "" ) {

			alert("请选择餐厅所在地区");
	
			thisForm.district.focus();
	
			return false;

     	}
		
	if(thisForm.hotel_name.value == "" || thisForm.hotel_name.value =="输入相关餐厅名称") {
			alert("请输入相关餐厅的名称并点击搜索，若无资料，那你输入什么就是什么了 :-)！");
			thisForm.hotel_name.focus();
			return false;

     	}
		return true;
}
