///定义变量，用作判断是否通过JS验证

var loginNameC = false;
var pwdC = false;
var repwdC = false;
var emailC = false;
var ReEmailC = false;
var addressC = false;
var imgC = false;

var telC = true;
var phoneC = true;
var msnC = true;
var nameC = true;
var faxC = true;
var companyC = true;

var imgIconRight = "images/member/icon_right.jpg";
var imgIconWrong = "images/member/icon_wrong.jpg";
var HiddenString = "visibility: hidden;";
var ViewString = "visibility: visible;";
var ColorRight = "font-family: Georgia, \"Times New Roman\", Times, serif; font-size: 12px; line-height: normal; font-weight: normal; color: Green;";
var ColorWrong = "font-family: Georgia, \"Times New Roman\", Times, serif; font-size: 12px; line-height: normal; font-weight: normal; color: #FF0000;";

///定义一个类型，用来判断当前需要设置哪个判断值
var Register = {
    valida: ""
}

function ltrim(s){ 
    return s.replace( /^\s*/,""); 
} 
//去右空格; 
function rtrim(s){ 
    return s.replace( /\s*jQuery/,""); 
} 
//去左右空格; 
function trim(s){
    return ltrim(rtrim(s));
}

function Refresh() {
	var img = document.getElementById('imgcode');
    img.src='checkNum.php?authnum='+Math.random();
	imgC = false;
}

//登入名稱驗證
function loginNameCheck(sUserName) {
    var loginName = jQuery("#loginName").val();
    var bkloginName = jQuery("#loginNamehid").val();
	var lang = jQuery("#lang").val();
	
	if (loginName == "") {
		if (lang==1) {
			jQuery("#loginNamevalid").text("You must enter login name！");
		}
		else if (lang==2) {
			jQuery("#loginNamevalid").text("登入名稱不可為空！");
		}
		else if (lang==3) {
			jQuery("#loginNamevalid").text("登入名称不可为空！");
		}        
        jQuery("#loginNamevalid").attr("style", ColorWrong);
        jQuery("#loginName_valid_div").attr("style", ViewString);
        jQuery("#imgloginName").attr("src", imgIconWrong);
		loginNameC = false;
        return;
    }
    if (loginName == bkloginName) {
        return;
    }
	else {
		jQuery("#loginNamehid").val(loginName);
		
		//接收表单的URL地址
		var url = "checkData.php";
		
		//需要POST的值，把每个变量都通过&来联接
		var postStr   = "username=" + loginName +"&randNum=" + Math.random();
			
		var ajax = false;
		//开始初始化XMLHttpRequest对象
		if(window.XMLHttpRequest) { //Mozilla 浏览器
			 ajax = new XMLHttpRequest();
			 if (ajax.overrideMimeType) {//设置MiME类别
					 ajax.overrideMimeType("text/xml");
			 }
		}
		else if (window.ActiveXObject) { // IE浏览器
			 try {
					 ajax = new ActiveXObject("Msxml2.XMLHTTP");
			 } catch (e) {
					 try {
							 ajax = new ActiveXObject("Microsoft.XMLHTTP");
					 } catch (e) {}
			 }
		}
		if (!ajax) { // 异常，创建对象实例失败
			 window.alert("不能创建XMLHttpRequest对象实例.");
			 return false;
		}
		
		//通过Post方式打开连接
		ajax.open("POST", url, true); 
		
		//定义传输的文件HTTP头信息
		ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
		
		//发送POST数据
		ajax.send(postStr);
		
		//获取执行状态
		ajax.onreadystatechange = function() {
		   //如果执行状态成功，那么就把返回信息写到指定的层里
		   if (ajax.readyState == 4 && ajax.status == 200) {
				if (ajax.responseText=="OK") {
					jQuery("#loginName_valid_div").attr("style", ViewString);
					jQuery("#imgloginName").attr("src", imgIconRight);
					jQuery("#loginNamevalid").attr("style", ColorRight);
					if (lang==1) {
						jQuery("#loginNamevalid").text("You can use this login name！");
					}
					else if (lang==2) {
						jQuery("#loginNamevalid").text("該登入名稱可以使用！");
					}
					else if (lang==3) {
						jQuery("#loginNamevalid").text("该登入名称可以使用！");
					}
					loginNameC = true;
					return;
				}
				
				else if (ajax.responseText=="Error") {
					if (lang==1) {
						jQuery("#loginNamevalid").text("The login name already exists. Please use another login name.");
					}
					else if (lang==2) {
						jQuery("#loginNamevalid").text("該登入名稱已經有人使用！");
					}
					else if (lang==3) {
						jQuery("#loginNamevalid").text("该登入名称已经有人使用！");
					}
					jQuery("#loginName_valid_div").attr("style", ViewString);
					jQuery("#imgloginName").attr("src", imgIconWrong);
					jQuery("#loginNamevalid").attr("style", ColorWrong);
					loginNameC = false;
					return;
				}
			}
			else if (ajax.readyState == 4 && ajax.status != 200) {
				if (lang==1) {
					jQuery("#loginNamevalid").text("System Error！");
				}
				else if (lang==2) {
					jQuery("#loginNamevalid").text("系統錯誤！");
				}
				else if (lang==3) {
					jQuery("#loginNamevalid").text("系统错误！");
				}
				jQuery("#loginName_valid_div").attr("style", ViewString);
				jQuery("#imgloginName").attr("src", imgIconWrong);
				jQuery("#loginNamevalid").attr("style", ColorWrong);
				loginNameC = false;
				return;
			}
		}
	}
}

///密碼驗證
function pwdCheck() {
    var pwd = jQuery("#Pwd").val();
    var bkpwd = jQuery("#Pwdhid").val();
	var lang = jQuery("#lang").val();
	
	pwd = ltrim(pwd);
	
    if (pwd == "") {
       if (lang==1) {
			jQuery("#Pwdvalid").text("You must enter password!");
		}
		else if (lang==2) {
			jQuery("#Pwdvalid").text("密碼不能為空！");
		}
		else if (lang==3) {
			jQuery("#Pwdvalid").text("密码不能为空！");
		}        
        jQuery("#Pwdvalid").attr("style", ColorWrong);
        jQuery("#pwd_valid_div").attr("style", ViewString);
        jQuery("#imgpwd").attr("src", imgIconWrong);
		pwdC = false;
        return;
    }
    if (pwd == bkpwd) {
        return;
    }
    else {
        jQuery("#Pwdhid").val(pwd);
		if (5 < pwd.length && pwd.length < 17) {
            pwdC = true;
            jQuery("#Pwdvalid").text("OK！");
            jQuery("#Pwdvalid").attr("style", ColorRight);
            jQuery("#pwd_valid_div").attr("style", ViewString);
            jQuery("#imgpwd").attr("src", imgIconRight);
            return;
        }
        else {
            if (lang==1) {
				jQuery("#Pwdvalid").text("Password should be between 6-16 characters!");
			}
			else if (lang==2) {
				jQuery("#Pwdvalid").text("密碼長度必須在6-16位之間！");
			}
			else if (lang==3) {
				jQuery("#Pwdvalid").text("密码长度必须在6-16位之间！");
			}
            jQuery("#Pwdvalid").attr("style", ColorWrong);            
            jQuery("#pwd_valid_div").attr("style", ViewString);
            jQuery("#imgpwd").attr("src", imgIconWrong);
			pwdC = false;
            return;
        }
    }
}

///確認密碼驗證
function repwdCheck() {
    var pwd = jQuery("#Pwd").val();
    var RePwd = jQuery("#RePwd").val();
	var lang = jQuery("#lang").val();
    if (RePwd == "") {
		if (lang==1) {
			jQuery("#RePwdvalid").text("You must enter confirm password!");
		}
		else if (lang==2) {
			jQuery("#RePwdvalid").text("確認密碼不能為空！");
		}
		else if (lang==3) {
			jQuery("#RePwdvalid").text("确认密码不能为空！");
		}
        jQuery("#RePwd_valid_div").attr("style", ViewString);
        jQuery("#imgRePwd").attr("src", imgIconWrong);
        jQuery("#RePwdvalid").attr("style", ColorWrong);
        repwdC = false;
        return;
    }
    if (pwd != RePwd) {
		if (lang==1) {
			jQuery("#RePwdvalid").text("Passwords do not match!");
		}
		else if (lang==2) {
			jQuery("#RePwdvalid").text("2次輸入密碼不同！");
		}
		else if (lang==3) {
			jQuery("#RePwdvalid").text("2次输入密码不同！");
		}
        jQuery("#RePwd_valid_div").attr("style", ViewString);
        jQuery("#imgRePwd").attr("src", imgIconWrong);        
        jQuery("#RePwdvalid").attr("style", ColorWrong);
        repwdC = false;
    }
    else {
        jQuery("#RePwd_valid_div").attr("style", ViewString);
        jQuery("#imgRePwd").attr("src", imgIconRight);
        jQuery("#RePwdvalid").attr("style", ColorRight);
        jQuery("#RePwdvalid").text("OK！");
        repwdC = true;
    }
}

///姓名驗證
function NameCheck() {
    var name = jQuery("#Name").val();
    var namehid = jQuery("#namehid").val();
	var lang = jQuery("#lang").val();
    if (name == "") {
        jQuery("#Name_valid_div").attr("style", HiddenString);
        jQuery("#namevalid").text("");
		nameC = true;
        return;
    }
    if (name == namehid) {
        return;
    }
    else {
        jQuery("#namehid").val(name);
		if (name.length > 0 && name.length < 50) {
            jQuery("#namevalid").text("OK！");
            jQuery("#Name_valid_div").attr("style", ViewString);
            jQuery("#imgName").attr("src", imgIconRight);
            jQuery("#namevalid").attr("style", ColorRight);
			nameC = true;
            return;
        }
        else {
			if (lang==1) {
				jQuery("#namevalid").text("Please enter a real name!");
			}
			else if (lang==2) {
				jQuery("#namevalid").text("請輸入真實的姓名！");
			}
			else if (lang==3) {
				jQuery("#namevalid").text("请输入真实的姓名！");
			}
            jQuery("#Name_valid_div").attr("style", ViewString);
            jQuery("#imgName").attr("src", imgIconWrong);
            jQuery("#namevalid").attr("style", ColorWrong);
			nameC = false;
			return;
        }
    }
}


//電郵驗證
function emailCheck(linkParth) {
    var email = jQuery("#Email").val();
    var bkemail = jQuery("#Emailhid").val();
	var lang = jQuery("#lang").val();
    if (email == "") {
		if (lang==1) {
			jQuery("#Emailvalid").text("You must enter E-mail！");
		}
		else if (lang==2) {
			jQuery("#Emailvalid").text("電郵不能為空！");
		}
		else if (lang==3) {
			jQuery("#Emailvalid").text("电邮不能为空！");
		}        
        jQuery("#Emailvalid").attr("style", ColorWrong);
        jQuery("#Email_valid_div").attr("style", ViewString);
        jQuery("#imgEmai").attr("src", imgIconWrong);
		emailC = false;
        return;
    }
    if (email == bkemail) {
        return;
    }
    if (!isemail(email)) {
		if (lang==1) {
			jQuery("#Emailvalid").text("Invalid E-mail format!");
		}
		else if (lang==2) {
			jQuery("#Emailvalid").text("電郵格式錯誤！");
		}
		else if (lang==3) {
			jQuery("#Emailvalid").text("电邮格式错误！");
		}
        jQuery("#Emailvalid").attr("style", ColorWrong);
        jQuery("#Email_valid_div").attr("style", ViewString);
        jQuery("#imgEmai").attr("src", imgIconWrong);
		emailC = false;
        return;
    }
    else {
		jQuery("#Emailhid").val(email);
		
		//接收表单的URL地址
		var url = "checkData.php";
		
		//需要POST的值，把每个变量都通过&来联接
		var postStr   = "email=" + email;
			
		var ajax = false;
		//开始初始化XMLHttpRequest对象
		if(window.XMLHttpRequest) { //Mozilla 浏览器
			 ajax = new XMLHttpRequest();
			 if (ajax.overrideMimeType) {//设置MiME类别
					 ajax.overrideMimeType("text/xml");
			 }
		}
		else if (window.ActiveXObject) { // IE浏览器
			 try {
					 ajax = new ActiveXObject("Msxml2.XMLHTTP");
			 } catch (e) {
					 try {
							 ajax = new ActiveXObject("Microsoft.XMLHTTP");
					 } catch (e) {}
			 }
		}
		if (!ajax) { // 异常，创建对象实例失败
			 window.alert("不能创建XMLHttpRequest对象实例.");
			 return false;
		}
		
		//通过Post方式打开连接
		ajax.open("POST", url, true); 
		
		//定义传输的文件HTTP头信息
		ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
		
		//发送POST数据
		ajax.send(postStr);
		
		//获取执行状态
		ajax.onreadystatechange = function() {
		   //如果执行状态成功，那么就把返回信息写到指定的层里
		   if (ajax.readyState == 4 && ajax.status == 200) {
			   if ((ajax.responseText)=="OK")
				{
					emailC = true;
								
					jQuery("#Email_valid_div").attr("style", ViewString);
					jQuery("#imgEmai").attr("src", imgIconRight);
					jQuery("#Emailvalid").attr("style", ColorRight)
					jQuery("#Emailvalid").text("OK！");
					return;
				}
				else if ((ajax.responseText)=="Error")
				{
					if (lang==1) {
						jQuery("#Emailvalid").text("The E-mail address you entered is already in use. Please enter another E-mail address.");
					}
					else if (lang==2) {
						jQuery("#Emailvalid").text("電郵已經有人使用！");
					}
					else if (lang==3) {
						jQuery("#Emailvalid").text("电邮已经有人使用！");
					}
					
					jQuery("#Email_valid_div").attr("style", ViewString);
					jQuery("#imgEmai").attr("src", imgIconWrong);
					jQuery("#Emailvalid").attr("style", ColorWrong);
					emailC = false;
					return;
				}
		   }
		   else if (ajax.readyState == 4 && ajax.status != 200) {
				if (lang==1) {
					jQuery("#Emailvalid").text("System Error!");
				}
				else if (lang==2) {
					jQuery("#Emailvalid").text("系統錯誤！");
				}
				else if (lang==3) {
					jQuery("#Emailvalid").text("系统错误！");
				}
				jQuery("#Email_valid_div").attr("style", ViewString);
				jQuery("#imgEmai").attr("src", imgIconWrong);
				jQuery("#Emailvalid").attr("style", ColorWrong);
				emailC = false;
				return;
			}
		}
    }
}

//確認電郵驗證
function reEmailCheck() {
    var email = jQuery("#Email").val();
    var ReEmail = jQuery("#ReEmail").val();
	var lang = jQuery("#lang").val();
    if (ReEmail == "") {
		if (lang==1) {
			jQuery("#ReEmailvalid").text("You muse enter confirm E-mail!");
		}
		else if (lang==2) {
			jQuery("#ReEmailvalid").text("確認電郵不可為空！");
		}
		else if (lang==3) {
			jQuery("#ReEmailvalid").text("确认电邮不可为空！");
		}
        jQuery("#ReEmail_valid_div").attr("style", ViewString);
        jQuery("#imgReEmail").attr("src", imgIconWrong);
        jQuery("#ReEmailvalid").attr("style", ColorWrong)
        ReEmailC = false;
        return;
    }
    if (email != ReEmail) {
		if (lang==1) {
			jQuery("#ReEmailvalid").text("E-mail addresses do not match. Please confirm your E-mail address.");
		}
		else if (lang==2) {
			jQuery("#ReEmailvalid").text("2次輸入電郵不同！");
		}
		else if (lang==3) {
			jQuery("#ReEmailvalid").text("2次输入电邮不同！");
		}
        jQuery("#ReEmail_valid_div").attr("style", ViewString);
        jQuery("#imgReEmail").attr("src", imgIconWrong);
        jQuery("#ReEmailvalid").attr("style", ColorWrong)
        ReEmailC = false;
		return;
    }
	if (!isemail(email)) {
		if (lang==1) {
			jQuery("#ReEmailvalid").text("Invalid E-mail format!");
		}
		else if (lang==2) {
			jQuery("#ReEmailvalid").text("電郵格式錯誤！");
		}
		else if (lang==3) {
			jQuery("#ReEmailvalid").text("电邮格式错误！");
		}
        jQuery("#ReEmailvalid").attr("style", ColorWrong);
        jQuery("#ReEmail_valid_div").attr("style", ViewString);
        jQuery("#imgReEmail").attr("src", imgIconWrong);
		emailC = false;
        return;
    }
    else {
        jQuery("#ReEmail_valid_div").attr("style", ViewString);
        jQuery("#imgReEmail").attr("src", imgIconRight);
        jQuery("#ReEmailvalid").attr("style", ColorRight)
        jQuery("#ReEmailvalid").text("OK！");
        ReEmailC = true;
		return;
    }
}

///電話驗證
function telCheck() {
    var tel = jQuery("#tel").val();
    var telhid = jQuery("#telhid").val();
	var lang = jQuery("#lang").val();
	
    if (tel == "") {
        jQuery("#tel_valid_div").attr("style", HiddenString);
        jQuery("#telvalid").text("");
        telC = true;
        return;
    }
    if (tel == telhid) {
        return;
    }
    else {  ///对tel进行验证
       jQuery("#telhid").val(tel);
	   if (isnumber(tel)) {
            if (tel.length > 5) {
                jQuery("#tel_valid_div").attr("style", ViewString);
                jQuery("#imgtel").attr("src", imgIconRight);
				jQuery("#telvalid").attr("style", ColorRight);
                jQuery("#telvalid").text("OK！");
				telC = true;
                return;
            }
            else {
				if (lang==1) {
					jQuery("#telvalid").text("Please enter a valid telephone number!");
				}
				else if (lang==2) {
					jQuery("#telvalid").text("請輸入正確的電話號碼！");
				}
				else if (lang==3) {
					jQuery("#telvalid").text("请输入正确的电话号码！");
				}
                jQuery("#tel_valid_div").attr("style", ViewString);
                jQuery("#imgtel").attr("src", imgIconWrong);
				jQuery("#telvalid").attr("style", ColorWrong);
                telC = false;
                return;
            }
        }
        else {
			if (lang==1) {
				jQuery("#telvalid").text("Please enter a valid telephone number!");
			}
			else if (lang==2) {
				jQuery("#telvalid").text("請輸入正確的電話號碼！");
			}
			else if (lang==3) {
				jQuery("#telvalid").text("请输入正确的电话号码！");
			}         
			jQuery("#tel_valid_div").attr("style", ViewString);
			jQuery("#imgtel").attr("src", imgIconWrong);			
			jQuery("#telvalid").attr("style", ColorWrong);
			telC = false;
			return;
        }
    }
}

///手機驗證
function phoneCheck() {
    var phone = jQuery("#Phone").val();
    var phonehid = jQuery("#phonehid").val();
	var lang = jQuery("#lang").val();
	
    if (phone == "") {
        jQuery("#Phone_valid_div").attr("style", HiddenString);
        jQuery("#phonevalid").text("");
        phoneC = true;
        return;
    }
    if (phone == phonehid) {
        return;
    }
    else {  ///对Phone进行验证
         jQuery("#phonehid").val(phone);
		if (isnumber(phone)) {
            if (phone.length > 7) {
                jQuery("#Phone_valid_div").attr("style", ViewString);
                jQuery("#imgphone").attr("src", imgIconRight);
                jQuery("#phonevalid").text("OK！");
                jQuery("#phonevalid").attr("style", ColorRight);
				phoneC = true;
                return;
            }
            else {
				if (lang==1) {
					jQuery("#phonevalid").text("Please enter a valid mobile phone number!");
				}
				else if (lang==2) {
					jQuery("#phonevalid").text("請輸入正確的手機號碼！");
				}
				else if (lang==3) {
					jQuery("#phonevalid").text("请输入正确的手机号码！");
				}
                jQuery("#Phone_valid_div").attr("style", ViewString);
                jQuery("#imgphone").attr("src", imgIconWrong);                
                jQuery("#phonevalid").attr("style", ColorWrong);
				phoneC = false;
                return;
            }
        }
        else {
			if (lang==1) {
				jQuery("#phonevalid").text("Please enter a valid mobile phone number!");
			}
			else if (lang==2) {
				jQuery("#phonevalid").text("請輸入正確的手機號碼！");
			}
			else if (lang==3) {
				jQuery("#phonevalid").text("请输入正确的手机号码！");
			}
            jQuery("#Phone_valid_div").attr("style", ViewString);
            jQuery("#imgphone").attr("src", imgIconWrong);
            jQuery("#phonevalid").attr("style", ColorWrong);
			phoneC = false;
            return;
        }
    }
}

///傳真驗證
function checkFax(){
	var fax = jQuery("#fax").val();
	var faxhid = jQuery("#faxhid").val();
	var lang = jQuery("#lang").val();
	
	if(fax == "")
	{
		jQuery("#fax_valid_div").attr("style", HiddenString);
        jQuery("#faxhid").val(fax);
        jQuery("#faxvalid").text("");
        faxC = true;
        return;
	}
	if (fax == faxhid) {
        return;
    }
	else {  ///对fax进行验证
        jQuery("#faxhid").val(fax);
		if (isnumber(fax)) {
            if (fax.length > 6) {
				jQuery("#faxvalid").text("OK！");
                jQuery("#fax_valid_div").attr("style", ViewString);
                jQuery("#imgfax").attr("src", imgIconRight);                
                jQuery("#faxvalid").attr("style", ColorRight);
				faxC = true;
                return;
            }
            else {
				if (lang==1) {
					jQuery("#faxvalid").text("Please enter a valid fax number!");
				}
				else if (lang==2) {
					jQuery("#faxvalid").text("請輸入正確的傳真號碼！");
				}
				else if (lang==3) {
					jQuery("#faxvalid").text("请输入正确的传真号码！");
				}
                jQuery("#fax_valid_div").attr("style", ViewString);
                jQuery("#imgfax").attr("src", imgIconWrong);
                jQuery("#faxvalid").attr("style", ColorWrong);
				faxC = false;
                return;
            }
        }
        else {
			if (lang==1) {
				jQuery("#faxvalid").text("Please enter a valid fax number!");
			}
			else if (lang==2) {
				jQuery("#faxvalid").text("請輸入正確的傳真號碼！");
			}
			else if (lang==3) {
				jQuery("#faxvalid").text("请输入正确的传真号码！");
			}
			jQuery("#fax_valid_div").attr("style", ViewString);
			jQuery("#imgfax").attr("src", imgIconWrong);
			jQuery("#faxvalid").attr("style", ColorWrong);
			faxC = false;
			return;
        }
	}
}

///公司名稱驗證
//

///地址驗證
function AddressCheck() {
    var address = jQuery("#Address").val();
    var addresshid = jQuery("#addhid").val();
	var lang = jQuery("#lang").val();
	
	address = ltrim(address);
	
    if (address == "") {
		if (lang==1) {
			jQuery("#addrvalid").text("Please enter a valid address!");
		}
		else if (lang==2) {
			jQuery("#addrvalid").text("地址不可為空！");
		}
		else if (lang==3) {
			jQuery("#addrvalid").text("地址不可为空！");
		}
        jQuery("#Address_valid_div").attr("style", ViewString);
		jQuery("#imgAddress").attr("src", imgIconWrong);
		jQuery("#addrvalid").attr("style", ColorWrong);
		addressC = false;
        return;
    }
    if (address == addresshid) {
        return;
    }
    else {
        jQuery("#addhid").val(address);
		if (address.length < 300) {
            jQuery("#addrvalid").text("OK！");
            jQuery("#Address_valid_div").attr("style", ViewString);
            jQuery("#imgAddress").attr("src", imgIconRight);
            jQuery("#addrvalid").attr("style", ColorRight);
			addressC = true;
            return;
        } 
		else {
			if (lang==1) {
				jQuery("#addrvalid").text("Please enter a valid address!");
			}
			else if (lang==2) {
				jQuery("#addrvalid").text("請輸入正確的通訊地址！");
			}
			else if (lang==3) {
				jQuery("#addrvalid").text("请输入正确的通讯地址！");
			}
            jQuery("#Address_valid_div").attr("style", ViewString);
            jQuery("#imgAddress").attr("src", imgIconWrong);
            jQuery("#addrvalid").attr("style", ColorWrong);
			addressC = false;
            return;
        }
    }
}

///驗證碼驗證
function imageCheck()
{
    var imageCode = jQuery("#code").val();
    var bknumber = jQuery("#numberhid").val();
	var lang = jQuery("#lang").val();
	
	if (imageCode == "") {
		if (lang==1) {
			jQuery("#imgcodevalid").text("You must enter verification code!");
		}
		else if (lang==2) {
			jQuery("#imgcodevalid").text("驗證碼不可為空！");
		}
		else if (lang==3) {
			jQuery("#imgcodevalid").text("验证码不可为空！");
		}		
        jQuery("#imgcodevalid").attr("style", ColorWrong);
        jQuery("#imageCode_valid_div").attr("style", ViewString);
        jQuery("#imgimageCode").attr("src", imgIconWrong);
		imgC = false;
        return;
    }
	if (imageCode == bknumber) {
        return;
    }
	else {
		jQuery("#numberhid").val(imageCode);
		
		//接收表单的URL地址
		var url = "checkNum.php";
		
		//需要POST的值，把每个变量都通过&来联接
		var postStr   = "SEC=" + imageCode;
			
		var ajax = false;
		//开始初始化XMLHttpRequest对象
		if(window.XMLHttpRequest) { //Mozilla 浏览器
			 ajax = new XMLHttpRequest();
			 if (ajax.overrideMimeType) {//设置MiME类别
					 ajax.overrideMimeType("text/xml");
			 }
		}
		else if (window.ActiveXObject) { // IE浏览器
			 try {
					 ajax = new ActiveXObject("Msxml2.XMLHTTP");
			 } catch (e) {
					 try {
							 ajax = new ActiveXObject("Microsoft.XMLHTTP");
					 } catch (e) {}
			 }
		}
		if (!ajax) { // 异常，创建对象实例失败
			 window.alert("不能创建XMLHttpRequest对象实例.");
			 return false;
		}
		
		//通过Post方式打开连接
		ajax.open("POST", url, true); 
		
		//定义传输的文件HTTP头信息
		ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
		
		//发送POST数据
		ajax.send(postStr);
		
		//获取执行状态
		ajax.onreadystatechange = function() {
		   //如果执行状态成功，那么就把返回信息写到指定的层里
		   if (ajax.readyState == 4 && ajax.status == 200) {
			   if (ajax.responseText=="OK") {
					jQuery("#imageCode_valid_div").attr("style", ViewString);
					jQuery("#imgimageCode").attr("src", imgIconRight);
					jQuery("#imgcodevalid").attr("style", ColorRight)
					jQuery("#imgcodevalid").text("OK");
					imgC = true;
					return;
				}
				
				else {
					if (lang==1) {
						jQuery("#imgcodevalid").text("Incorrect verification code!");
					}
					else if (lang==2) {
						jQuery("#imgcodevalid").text("驗證碼錯誤！");
					}
					else if (lang==3) {
						jQuery("#imgcodevalid").text("验证码错误！");
					}
					jQuery("#imageCode_valid_div").attr("style", ViewString);
					jQuery("#imgimageCode").attr("src", imgIconWrong);
					jQuery("#imgcodevalid").attr("style", ColorWrong)
					imgC = false;
					return;
				}
		   }
		   else if (ajax.readyState == 4 && ajax.status != 200) {
				if (lang==1) {
					jQuery("#imgcodevalid").text("System Error！");
				}
				else if (lang==2) {
					jQuery("#imgcodevalid").text("系統錯誤！");
				}
				else if (lang==3) {
					jQuery("#imgcodevalid").text("系统错误！");
				}
				jQuery("#imageCode_valid_div").attr("style", ViewString);
				jQuery("#imgimageCode").attr("src", imgIconWrong);
				jQuery("#imgcodevalid").attr("style", ColorWrong)
				imgC = false;
				return;
			}
		}
	}
}

///服務條款驗證
function checkService() {
    if (jQuery("#cbRead").attr("checked")) {
        jQuery("#btnRegister").attr("disabled", false);
    }
    else {
        jQuery("#btnRegister").attr("disabled", true);
    }
}


///提交前查看所有的验证是否通过
function SubmitCheck() {
	var lang = jQuery("#lang").val();
	var loginName = jQuery("#loginName").val();
    var pwd = jQuery("#Pwd").val();
	var RePwd = jQuery("#RePwd").val();
    var email = jQuery("#Email").val();
	var ReEmail = jQuery("#ReEmail").val();
	var name = jQuery("#Name").val();
	var year = jQuery("#selYear").val();
	var month = jQuery("#selMonth").val();
	var day = jQuery("#selDay").val();
	var tel = jQuery("#tel").val();
    var phone = jQuery("#Phone").val();
	var fax = jQuery("#fax").val();
	var company = jQuery("#company").val();
    var address = jQuery("#Address").val();
	var address1 = jQuery("#Address1").val();
    var imgcode = jQuery("#code").val();
    for(var i=0;i<form1.gender.length;i++){
        if(form1.gender[i].checked){
			var userGender = form1.gender[i].value;
        }
    }
	var message = "0";
    if (jQuery("#message").attr("checked")) {
        message = "1";
	}	
	if (!loginNameC || loginName=='')
	{
        jQuery("#loginName").focus();
        return false;
    }
    if (!pwdC || pwd=='')
	{
        jQuery("#Pwd").focus();
        return false;
    }
    if (!repwdC || RePwd=='')
	{
        jQuery("#RePwd").focus();
        return false;
    }
	if (pwd != RePwd)
	{
		if (lang==1) {
			jQuery("#RePwdvalid").text("Passwords do not match!");
		}
		else if (lang==2) {
			jQuery("#RePwdvalid").text("2次輸入密碼不同！");
		}
		else if (lang==3) {
			jQuery("#RePwdvalid").text("2次输入密码不同！");
		}
        jQuery("#RePwd_valid_div").attr("style", ViewString);
        jQuery("#RePwdvalid").attr("style", ColorWrong);
        repwdC = false;
		return;
	}
	
    if (!emailC || email=='')
	{
        jQuery("#Email").focus();
        return false;
    }
	if (!ReEmailC || ReEmail=='')
	{
        jQuery("#ReEmail").focus();
        return false;
    }
	if (email != ReEmail)
	{
		if (lang==1) {
			jQuery("#ReEmailvalid").text("E-mail addresses do not match. Please confirm your E-mail address.");
		}
		else if (lang==2) {
			jQuery("#ReEmailvalid").text("2次輸入電郵不同！");
		}
		else if (lang==3) {
			jQuery("#ReEmailvalid").text("2次输入电邮不同！");
		}
        jQuery("#ReEmail_valid_div").attr("style", ViewString);        
        jQuery("#ReEmailvalid").attr("style", ColorWrong);
        ReEmailC = false;
		return;
	}
	
	if (!nameC)
	{
        jQuery("#Name").focus();
        return false;
    }
	if (!telC)
	{
        jQuery("#tel").focus();
        return false;
    }
    if (!phoneC)
	{
        jQuery("#Phone").focus();
        return false;
    }
	if (!faxC)
	{
        jQuery("#fax").focus();
        return false;
    }
	if (!companyC) {
        jQuery("#company").focus();
        return false;
    }
    if (!addressC || address=='') {
        jQuery("#Address").focus();
        return false;
    }
    if (!imgC || imgcode=='') {
        jQuery("#imageCode").focus();
        return false;
    }
	
	//接收表单的URL地址
	var url = "memberRegistInfo.php";
	
	//需要POST的值，把每个变量都通过&来联接
	var postStr   = "loginName=" + loginName
		+ "&pwd=" + pwd
		+ "&rePwd=" + RePwd
        + "&email=" + email
		+ "&name=" + name
		+ "&year=" + year
		+ "&month=" + month
		+ "&day=" + day
		+ "&tel=" + tel
        + "&phone=" + phone
        + "&fax=" + fax
		+ "&company=" + company
        + "&address=" + address
		+ "&address1=" + address1
        + "&imgcode=" + imgcode
        + "&gender=" + userGender
		+ "&message=" + message
		+ "&lang=" + lang;
		
		var ajax = false;
		//开始初始化XMLHttpRequest对象
		if(window.XMLHttpRequest) { //Mozilla 浏览器
			 ajax = new XMLHttpRequest();
			 if (ajax.overrideMimeType) {//设置MiME类别
					 ajax.overrideMimeType("text/xml");
			 }
		}
		else if (window.ActiveXObject) { // IE浏览器
			 try {
					 ajax = new ActiveXObject("Msxml2.XMLHTTP");
			 } catch (e) {
					 try {
							 ajax = new ActiveXObject("Microsoft.XMLHTTP");
					 } catch (e) {}
			 }
		}
		if (!ajax) { // 异常，创建对象实例失败
			 window.alert("不能创建XMLHttpRequest对象实例.");
			 return false;
		}
		
		//通过Post方式打开连接
		ajax.open("POST", url, true); 
		
		//定义传输的文件HTTP头信息
		ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
		
		//发送POST数据
		ajax.send(postStr);
		
		//获取执行状态
		ajax.onreadystatechange = function() { 
		   //如果执行状态成功，那么就把返回信息写到指定的层里
		   if (ajax.readyState == 4 && ajax.status == 200) {
				if (ajax.responseText == 'Error') {
					if (lang==1) {
						jQuery("#errorid").text("System Error！");
					}
					else if (lang==2) {
						jQuery("#errorid").text("系統錯誤！");
					}
					else if (lang==3) {
						jQuery("#errorid").text("系统错误！");
					}
					jQuery("#errorid").attr("style", ColorWrong);
					jQuery("#error_valid_div").attr("style", ViewString);
					return;
				}
				else if (ajax.responseText == 'Error1') {
					if (lang==1) {
						jQuery("#errorid").text("Email send fail！");
					}
					else if (lang==2) {
						jQuery("#errorid").text("電郵發送失敗！");
					}
					else if (lang==3) {
						jQuery("#errorid").text("电邮发送失败！");
					}
					jQuery("#errorid").attr("style", ColorWrong);
					jQuery("#error_valid_div").attr("style", ViewString);
					return;
				}
				else if (ajax.responseText == 'System Error') {
					if (lang==1) {
						jQuery("#errorid").text("System Error！");
					}
					else if (lang==2) {
						jQuery("#errorid").text("系統錯誤！");
					}
					else if (lang==3) {
						jQuery("#errorid").text("系统错误！");
					}
					jQuery("#errorid").attr("style", ColorWrong);
					jQuery("#error_valid_div").attr("style", ViewString);
					return;
				}
				else if (ajax.responseText == 'Successfully') {
					window.location.href='memberRegisted.php?msg=Successfully&lang='+lang;
				}
		   }
		   else if (ajax.readyState == 4 && ajax.status != 200) { 
				if (lang==1) {
					jQuery("#errorid").text("Registration Fail！");
				}
				else if (lang==2) {
					jQuery("#errorid").text("登記失敗！");
				}
				else if (lang==3) {
					jQuery("#errorid").text("登记失败！");
				}
				jQuery("#errorid").attr("style", ColorWrong);
				jQuery("#error_valid_div").attr("style", ViewString);
				return;
			}
		} 
}

//
function loginCheck() {
	var lang = jQuery("#lang").val();
	var Link = jQuery("#link").val();
	var LoginName = jQuery("#LoginName").val();
    var loginPwd = jQuery("#loginPwd").val();
	
	if (LoginName=='')
	{
		if (lang==1) {
			jQuery("#LoginNamevalid").text("Login Name Not Null!");
		}
		else if (lang==2) {
			jQuery("#LoginNamevalid").text("登入名稱不能為空！");
		}
		else if (lang==3) {
			jQuery("#LoginNamevalid").text("登入名称不能为空！");
		}
		jQuery("#LoginNamevalid").attr("style", ColorWrong);
		jQuery("#LoginName_valid_div").attr("style", ViewString);
		jQuery("#LoginName").focus();
		return false;
	}
	
	if (loginPwd == "") {
		if (lang==1) {
			jQuery("#Pwdvalid").text("Password Not Null!");
		}
		else if (lang==2) {
			jQuery("#Pwdvalid").text("密碼不能為空！");
		}
		else if (lang==3) {
			jQuery("#Pwdvalid").text("密码不能为空！");
		}
        jQuery("#Pwdvalid").attr("style", ColorWrong);
        jQuery("#pwd_valid_div").attr("style", ViewString);
		jQuery("#loginPwd").focus();
        return;
    }
    else if (5 > loginPwd.length || loginPwd.length > 16) {
		if (lang==1) {
			jQuery("#Pwdvalid").text("Wrong password!");
		}
		else if (lang==2) {
			jQuery("#Pwdvalid").text("密碼長度必須在6-16位之間！");
		}
		else if (lang==3) {
			jQuery("#Pwdvalid").text("密码长度必须在6-16位之间！");
		}
		jQuery("#Pwdvalid").attr("style", ColorWrong);
		jQuery("#pwd_valid_div").attr("style", ViewString);
		jQuery("#loginPwd").focus();
        return;
    }
	
	if (!imgC) {
		if (lang==1) {
			jQuery("#imgcodevalid").text("Incorrect verification code!");
		}
		else if (lang==2) {
			jQuery("#imgcodevalid").text("驗證碼錯誤！");
		}
		else if (lang==3) {
			jQuery("#imgcodevalid").text("验证码错误！");
		}
		jQuery("#imageCode_valid_div").attr("style", ViewString);
		jQuery("#imgimageCode").attr("src", imgIconWrong);
		jQuery("#imgcodevalid").attr("style", ColorWrong)
        jQuery("#number").focus();
        return;
    }
	
	//接收表单的URL地址
	var url = "memberLoginInfo.php";
	
	//需要POST的值，把每个变量都通过&来联接
	var postStr   = "loginName=" + LoginName + "&loginPwd=" + loginPwd;
		
		var ajax = false;
		//开始初始化XMLHttpRequest对象
		if(window.XMLHttpRequest) { //Mozilla 浏览器
			 ajax = new XMLHttpRequest();
			 if (ajax.overrideMimeType) {//设置MiME类别
					 ajax.overrideMimeType("text/xml");
			 }
		}
		else if (window.ActiveXObject) { // IE浏览器
			 try {
					 ajax = new ActiveXObject("Msxml2.XMLHTTP");
			 } catch (e) {
					 try {
							 ajax = new ActiveXObject("Microsoft.XMLHTTP");
					 } catch (e) {}
			 }
		}
		if (!ajax) { // 异常，创建对象实例失败
			 window.alert("不能创建XMLHttpRequest对象实例.");
			 return false;
		}
		
		//通过Post方式打开连接
		ajax.open("POST", url, true); 
		
		//定义传输的文件HTTP头信息
		ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
		
		//发送POST数据
		ajax.send(postStr);
		
		//获取执行状态
		ajax.onreadystatechange = function() { 
			//如果执行状态成功，那么就把返回信息写到指定的层里
			if (ajax.readyState == 4 && ajax.status == 200) {
				if (ajax.responseText == 'Error') {
					if (lang==1) {
						jQuery("#errorid").text("Please don't repeat login!");
					}
					else if (lang==2) {
						jQuery("#errorid").text("請勿重覆登入！");
					}
					else if (lang==3) {
						jQuery("#errorid").text("请勿重复登入！");
					}
					jQuery("#errorid").attr("style", ColorWrong);
					jQuery("#error_valid_div").attr("style", ViewString);
					return;
				}
				else if (ajax.responseText == 'Error1') {
					if (lang==1) {
						jQuery("#errorid").text("Incorrect login name or password!");
					}
					else if (lang==2) {
						jQuery("#errorid").text("登入名稱或密碼錯誤！");
					}
					else if (lang==3) {
						jQuery("#errorid").text("登入名称或密码错误！");
					}
					jQuery("#errorid").attr("style", ColorWrong);
					jQuery("#error_valid_div").attr("style", ViewString);
					return;
				}
				else if (ajax.responseText == 'Error2') {
					if (lang==1) {
						jQuery("#errorid").text("Your account has not been activited. Please check your E-mail to complete the verification process.");
					}
					else if (lang==2) {
						jQuery("#errorid").text("您的帳號尚未激活，請進入您的郵箱完成最后一步激活！");
					}
					else if (lang==3) {
						jQuery("#errorid").text("您的帐号尚未激活，请进入您的邮箱完成最后一步激活！");
					}
					jQuery("#errorid").attr("style", ColorWrong);
					jQuery("#error_valid_div").attr("style", ViewString);
					return;
				}
				else if (ajax.responseText == 'System Error') {
					if (lang==1) {
						jQuery("#errorid").text("System Error！");
					}
					else if (lang==2) {
						jQuery("#errorid").text("系統錯誤！");
					}
					else if (lang==3) {
						jQuery("#errorid").text("系统错误！");
					}
					jQuery("#errorid").attr("style", ColorWrong);
					jQuery("#error_valid_div").attr("style", ViewString);
					return;
				}
				else if (ajax.responseText == 'Successfully') {
					if (Link !='') {
						window.location.href= Link;
					}
					else {
						window.location.href='memberProfile.php?lang='+lang;
					}
				}
			}
			else if (ajax.readyState == 4 && ajax.status != 200) { 
				if (lang==1) {
					jQuery("#errorid").text("Login Fail！");
				}
				else if (lang==2) {
					jQuery("#errorid").text("登入失敗！");
				}
				else if (lang==3) {
					jQuery("#errorid").text("登入失敗！");
				}
				jQuery("#errorid").attr("style", ColorWrong);
				jQuery("#error_valid_div").attr("style", ViewString);
				return;
			}
		} 
}

function forgotCheck()
{
	var lang = jQuery("#lang").val();
	var loginName = jQuery("#loginName").val();
	var email = jQuery("#email").val();
	
	jQuery("#error_valid_div").attr("style", HiddenString);
	jQuery("#LoginName_valid_div").attr("style", HiddenString);
	
	if (loginName=='')
	{
		if (lang==1) {
			jQuery("#LoginNamevalid").text("Login Name Not Null!");
		}
		else if (lang==2) {
			jQuery("#LoginNamevalid").text("登入名稱不能為空！");
		}
		else if (lang==3) {
			jQuery("#LoginNamevalid").text("登入名称不能为空！");
		}
		jQuery("#LoginNamevalid").attr("style", ColorWrong);
		jQuery("#LoginName_valid_div").attr("style", ViewString);
		jQuery("#loginName").focus();
		return false;
	}
	if (email=='')
	{
		if (lang==1) {
			jQuery("#Emailvalid").text("Missing E-mail!");
		}
		else if (lang==2) {
			jQuery("#Emailvalid").text("電郵不能為空！");
		}
		else if (lang==3) {
			jQuery("#Emailvalid").text("电邮不能为空！");
		}
		jQuery("#Emailvalid").attr("style", ColorWrong);
		jQuery("#Email_valid_div").attr("style", ViewString);
		jQuery("#email").focus();
		return;
	}
	if (!isemail(email)) {
		if (lang==1) {
			jQuery("#Emailvalid").text("Invalid E-mail Format!");
		}
		else if (lang==2) {
			jQuery("#Emailvalid").text("電郵格式錯誤！");
		}
		else if (lang==3) {
			jQuery("#Emailvalid").text("电邮格式错误！");
		}
		jQuery("#Emailvalid").attr("style", ColorWrong);
		jQuery("#Email_valid_div").attr("style", ViewString);
		jQuery("#email").focus();
		return;
	}
	
	jQuery("#Email_valid_div").attr("style", HiddenString);
	
	//接收表单的URL地址
	var url = "memberForgotInfo.php";
	
	//需要POST的值，把每个变量都通过&来联接
	var postStr   = "loginName=" + loginName + "&email=" + email + "&lang=" + lang;
		
		var ajax = false;
		//开始初始化XMLHttpRequest对象
		if(window.XMLHttpRequest) { //Mozilla 浏览器
			 ajax = new XMLHttpRequest();
			 if (ajax.overrideMimeType) {//设置MiME类别
					 ajax.overrideMimeType("text/xml");
			 }
		}
		else if (window.ActiveXObject) { // IE浏览器
			 try {
					 ajax = new ActiveXObject("Msxml2.XMLHTTP");
			 } catch (e) {
					 try {
							 ajax = new ActiveXObject("Microsoft.XMLHTTP");
					 } catch (e) {}
			 }
		}
		if (!ajax) { // 异常，创建对象实例失败
			 window.alert("不能创建XMLHttpRequest对象实例.");
			 return false;
		}
		
		//通过Post方式打开连接
		ajax.open("POST", url, true); 
		
		//定义传输的文件HTTP头信息
		ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
		
		//发送POST数据
		ajax.send(postStr);
		
		//获取执行状态
		ajax.onreadystatechange = function() { 
			//如果执行状态成功，那么就把返回信息写到指定的层里
			if (ajax.readyState == 4 && ajax.status == 200) {
				//window.alert(ajax.responseText);
				//
				if (ajax.responseText == 'Error') {
					if (lang==1) {
						jQuery("#errorid").text("Login name does not exist or this e-mail had not register!");
					}
					else if (lang==2) {
						jQuery("#errorid").text("用戶名不存在或該電郵沒有登記!");
					}
					else if (lang==3) {
						jQuery("#errorid").text("用户名不存在或该电邮没有登记！");
					}
					jQuery("#errorid").attr("style", ColorWrong);
					jQuery("#error_valid_div").attr("style", ViewString);
					return;
				}
				else if (ajax.responseText == 'Error1') {
					if (lang==1) {
						jQuery("#errorid").text("You had been login！");
					}
					else if (lang==2) {
						jQuery("#errorid").text("您已經登入！");
					}
					else if (lang==3) {
						jQuery("#errorid").text("您已经登入！");
					}
					jQuery("#errorid").attr("style", ColorWrong);
					jQuery("#error_valid_div").attr("style", ViewString);
					return;
				}
				else if (ajax.responseText == 'Error2') {
					if (lang==1) {
						jQuery("#errorid").text("Email send fail！");
					}
					else if (lang==2) {
						jQuery("#errorid").text("電郵發送失敗！");
					}
					else if (lang==3) {
						jQuery("#errorid").text("电邮发送失败！");
					}
					jQuery("#errorid").attr("style", ColorWrong);
					jQuery("#error_valid_div").attr("style", ViewString);
					return;
				}
				else if (ajax.responseText == 'System Error') {
					if (lang==1) {
						jQuery("#errorid").text("System Error！");
					}
					else if (lang==2) {
						jQuery("#errorid").text("系統錯誤！");
					}
					else if (lang==3) {
						jQuery("#errorid").text("系统错误！");
					}
					jQuery("#errorid").attr("style", ColorWrong);
					jQuery("#error_valid_div").attr("style", ViewString);
					return;
				}
				else if (ajax.responseText == 'Successfully') {
					jQuery("#loginName").val('');
					jQuery("#email").val('');
					if (lang==1) {
						jQuery("#errorid").text("An E-mail has been sent to you to reset your password.");
					}
					else if (lang==2) {
						jQuery("#errorid").text("電郵發送成功！");
					}
					else if (lang==3) {
						jQuery("#errorid").text("電郵發送成功！");
					}
					jQuery("#errorid").attr("style", ColorRight);
					jQuery("#error_valid_div").attr("style", ViewString);
				}
			}
			else if (ajax.readyState == 4 && ajax.status != 200) {
				if (lang==1) {
					jQuery("#errorid").text("E-mail send failed!");
				}
				else if (lang==2) {
					jQuery("#errorid").text("電郵發送失敗！");
				}
				else if (lang==3) {
					jQuery("#errorid").text("电邮发送失败！");
				}
				jQuery("#errorid").attr("style", ColorWrong);
				jQuery("#error_valid_div").attr("style", ViewString);
				return;
			}
		} 
}

function updatePwdCheck() {
	var lang = jQuery("#lang").val();
	var pwd = jQuery("#Pwd").val();
	var RePwd = jQuery("#RePwd").val();
	var userName = jQuery("#userName").val();
	var forgotToken = jQuery("#forgotToken").val();
	
	if (!pwdC)
	{
        jQuery("#Pwd").focus();
        return;
    }
    if (!repwdC)
	{
        jQuery("#RePwd").focus();
        return;
    }
	
	if (pwd != RePwd)
	{
		if (lang==1) {
			jQuery("#RePwdvalid").text("You enter a different password!");
		}
		else if (lang==2) {
			jQuery("#RePwdvalid").text("2次輸入密碼不同！");
		}
		else if (lang==3) {
			jQuery("#RePwdvalid").text("2次输入密码不同！");
		}
        jQuery("#RePwd_valid_div").attr("style", ViewString);
        jQuery("#RePwdvalid").attr("style", ColorWrong);
        repwdC = false;
		return;
	}
    
	//接收表单的URL地址
	var url = "resetPasswordInfo.php";
	
	//需要POST的值，把每个变量都通过&来联接
	var postStr   = "pwd=" + pwd + "&rePwd=" + RePwd + "&userName=" + userName + "&forgotToken=" + forgotToken;
		
		var ajax = false;
		//开始初始化XMLHttpRequest对象
		if(window.XMLHttpRequest) { //Mozilla 浏览器
			 ajax = new XMLHttpRequest();
			 if (ajax.overrideMimeType) {//设置MiME类别
					 ajax.overrideMimeType("text/xml");
			 }
		}
		else if (window.ActiveXObject) { // IE浏览器
			 try {
					 ajax = new ActiveXObject("Msxml2.XMLHTTP");
			 } catch (e) {
					 try {
							 ajax = new ActiveXObject("Microsoft.XMLHTTP");
					 } catch (e) {}
			 }
		}
		if (!ajax) { // 异常，创建对象实例失败
			 window.alert("不能创建XMLHttpRequest对象实例.");
			 return false;
		}
		
		//通过Post方式打开连接
		ajax.open("POST", url, true); 
		
		//定义传输的文件HTTP头信息
		ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
		
		//发送POST数据
		ajax.send(postStr);
		
		//获取执行状态
		ajax.onreadystatechange = function() { 
			//如果执行状态成功，那么就把返回信息写到指定的层里
			if (ajax.readyState == 4 && ajax.status == 200) {
				//msg.innerHTML = ajax.responseText; 
				//alert(ajax.responseText);
				if (ajax.responseText == 'Error') {
					if (lang==1) {
						jQuery("#errorid").text("Reset password failed!");
					}
					else if (lang==2) {
						jQuery("#errorid").text("重設密碼失敗！");
					}
					else if (lang==3) {
						jQuery("#errorid").text("重设密码失败！");
					}
					jQuery("#errorid").attr("style", ColorWrong);
					jQuery("#error_valid_div").attr("style", ViewString);
					return;
				}
				else if (ajax.responseText == 'System Error') {
					if (lang==1) {
						jQuery("#errorid").text("System Error！");
					}
					else if (lang==2) {
						jQuery("#errorid").text("系統錯誤！");
					}
					else if (lang==3) {
						jQuery("#errorid").text("系统错误！");
					}
					jQuery("#errorid").attr("style", ColorWrong);
					jQuery("#error_valid_div").attr("style", ViewString);
					return;
				}
				else if (ajax.responseText == 'Successfully') {
					window.location.href='memberLogin.php?lang='+lang;
				}
			}
			else if (ajax.readyState == 4 && ajax.status != 200) { 
				if (lang==1) {
					jQuery("#errorid").text("Reset password failed!");
				}
				else if (lang==2) {
					jQuery("#errorid").text("重設密碼失敗！");
				}
				else if (lang==3) {
					jQuery("#errorid").text("重设密码失败！");
				}
				jQuery("#errorid").attr("style", ColorWrong);
				jQuery("#error_valid_div").attr("style", ViewString);
				return;
			}
		} 
}

function editCheck() {
	var id = jQuery("#member").val();
	var oldPwd = jQuery("#oldPwd").val();
    var Pwd = jQuery("#Pwd").val();
	var RePwd = jQuery("#RePwd").val();
    var email = jQuery("#Email").val();
	var bkEmail = jQuery("#bkEmail").val();
	var name = jQuery("#Name").val();
	var year = jQuery("#selYear").val();
	var month = jQuery("#selMonth").val();
	var day = jQuery("#selDay").val();
	var tel = jQuery("#tel").val();
    var phone = jQuery("#Phone").val();
	var fax = jQuery("#fax").val();
	var company = jQuery("#company").val();
    var address = jQuery("#Address").val();
	var address1 = jQuery("#Address1").val();
	var bkAddress = jQuery("#bkAddress").val();
    for(var i=0;i<form1.gender.length;i++){
        if(form1.gender[i].checked){
			var userGender = form1.gender[i].value;
        }
    }
	var message = "0";
    if (jQuery("#message").attr("checked")) {
        message = "1";
	}
	
	var lang = jQuery("#lang").val();
	
	if (Pwd !='' || RePwd !='')
	{
		if (!pwdC)
		{
			jQuery("#Pwd").focus();
			return;
		}
		if (!repwdC)
		{
			jQuery("#RePwd").focus();
			return;
		}
		if (Pwd != RePwd)
		{
			if (lang==1) {
				jQuery("#RePwdvalid").text("You enter a different password!");
			}
			else if (lang==2) {
				jQuery("#RePwdvalid").text("2次輸入密碼不同！");
			}
			else if (lang==3) {
				jQuery("#RePwdvalid").text("2次输入密码不同！");
			}
			jQuery("#RePwd_valid_div").attr("style", ViewString);
			jQuery("#RePwdvalid").attr("style", ColorWrong);
			repwdC = false;
			return;
		}
	}
	
	if (!emailC && (email != bkEmail))
	{
        if (lang==1) {
			jQuery("#Emailvalid").text("Invalid E-mail Format!");
		}
		else if (lang==2) {
			jQuery("#Emailvalid").text("電郵格式錯誤！");
		}
		else if (lang==3) {
			jQuery("#Emailvalid").text("电邮格式错误！");
		}
		jQuery("#Email_valid_div").attr("style", ViewString);
		jQuery("#Emailvalid").attr("style", ColorWrong);
		jQuery("#email").focus();
		emailC = false;
        return;
    }
	
	if (!nameC)
	{
        jQuery("#Name").focus();
        return false;
    }
	if (!telC)
	{
        jQuery("#tel").focus();
        return false;
    }
    if (!phoneC)
	{
        jQuery("#Phone").focus();
        return false;
    }
	if (!faxC)
	{
        jQuery("#fax").focus();
        return false;
    }
	if (!companyC) {
        jQuery("#company").focus();
        return false;
    }
	if (!addressC && (address != bkAddress)) {
        if (lang==1) {
			jQuery("#addrvalid").text("Please enter a real address!");
		}
		else if (lang==2) {
			jQuery("#addrvalid").text("請輸入正確的通訊地址！");
		}
		else if (lang==3) {
			jQuery("#addrvalid").text("请输入正确的通讯地址！");
		}
		jQuery("#Address_valid_div").attr("style", ViewString);
		jQuery("#addrvalid").attr("style", ColorWrong);
		jQuery("#Address").focus();
		addressC = false;		
        return false;
    }
    
	//接收表单的URL地址
	var url = "memberProfileInfo.php";
	
	//需要POST的值，把每个变量都通过&来联接
	var postStr   = "id=" + id
		+ "&oldPwd=" + oldPwd
		+ "&pwd=" + Pwd
		+ "&rePwd=" + RePwd
        + "&email=" + email
		+ "&name=" + name
		+ "&year=" + year
		+ "&month=" + month
		+ "&day=" + day
		+ "&tel=" + tel
        + "&phone=" + phone
        + "&fax=" + fax
		+ "&company=" + company
        + "&address=" + address
		+ "&address1=" + address1
        + "&gender=" + userGender
		+ "&message=" + message;
		
		var ajax = false;
		//开始初始化XMLHttpRequest对象
		if(window.XMLHttpRequest) { //Mozilla 浏览器
			 ajax = new XMLHttpRequest();
			 if (ajax.overrideMimeType) {//设置MiME类别
					 ajax.overrideMimeType("text/xml");
			 }
		}
		else if (window.ActiveXObject) { // IE浏览器
			 try {
					 ajax = new ActiveXObject("Msxml2.XMLHTTP");
			 } catch (e) {
					 try {
							 ajax = new ActiveXObject("Microsoft.XMLHTTP");
					 } catch (e) {}
			 }
		}
		if (!ajax) { // 异常，创建对象实例失败
			 window.alert("不能创建XMLHttpRequest对象实例.");
			 return false;
		}
		
		//通过Post方式打开连接
		ajax.open("POST", url, true); 
		
		//定义传输的文件HTTP头信息
		ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
		
		//发送POST数据
		ajax.send(postStr);
		
		//获取执行状态
		ajax.onreadystatechange = function() { 
			//如果执行状态成功，那么就把返回信息写到指定的层里
			if (ajax.readyState == 4 && ajax.status == 200) {
				//msg.innerHTML = ajax.responseText; 
				//alert(ajax.responseText);
				jQuery("#msg_div").attr("style", HiddenString);
				if (ajax.responseText == 'Error1') {
					if (lang==1) {
						jQuery("#errorid").text("Old Password Error！");
					}
					else if (lang==2) {
						jQuery("#errorid").text("舊密碼錯誤！");
					}
					else if (lang==3) {
						jQuery("#errorid").text("旧密码错误！");
					}
					jQuery("#errorid").attr("style", ColorWrong);
					jQuery("#error_valid_div").attr("style", ViewString);
					jQuery("#oldPwd").focus();
					return;
				}
				else if (ajax.responseText == 'Error2') {
					if (lang==1) {
						jQuery("#errorid").text("Edit Fail 1!");
					}
					else if (lang==2) {
						jQuery("#errorid").text("更改失敗 1！");
					}
					else if (lang==3) {
						jQuery("#errorid").text("更改失敗 1！");
					}
					jQuery("#errorid").attr("style", ColorWrong);
					jQuery("#error_valid_div").attr("style", ViewString);
					return;
				}
				else if (ajax.responseText == 'Successfully') {
					window.location.href='memberProfile.php?msg=Successfully&lang='+lang;
				}
			}
			else if (ajax.readyState == 4 && ajax.status != 200) {
				jQuery("#msg_div").attr("style", HiddenString);
				if (lang==1) {
					jQuery("#errorid").text("Edit Fail 2!");
				}
				else if (lang==2) {
					jQuery("#errorid").text("更改失敗 2！");
				}
				else if (lang==3) {
					jQuery("#errorid").text("更改失敗 2！");
				}
				jQuery("#errorid").attr("style", ColorWrong);
				jQuery("#error_valid_div").attr("style", ViewString);
				return;
			}
		} 
}


//日期
function DateSelector(selYear, selMonth, selDay)
{
    this.selYear = selYear;
    this.selMonth = selMonth;
    this.selDay = selDay;
    this.selYear.Group = this;
    this.selMonth.Group = this;
    // 给年份、月份下拉菜单添加处理onchange事件的函数
    if(window.document.all != null) // IE
    {
        this.selYear.attachEvent("onchange", DateSelector.Onchange);
        this.selMonth.attachEvent("onchange", DateSelector.Onchange);
    }
    else // Firefox
    {
        this.selYear.addEventListener("change", DateSelector.Onchange, false);
        this.selMonth.addEventListener("change", DateSelector.Onchange, false);
    }

    if(arguments.length == 4) // 如果传入参数个数为4，最后一个参数必须为Date对象
        this.InitSelector(arguments[3].getFullYear(), arguments[3].getMonth() + 1, arguments[3].getDate());
    else if(arguments.length == 6) // 如果传入参数个数为6，最后三个参数必须为初始的年月日数值
        this.InitSelector(arguments[3], arguments[4], arguments[5]);
    else // 默认使用当前日期
    {
        var dt = new Date();
        this.InitSelector(dt.getFullYear(), dt.getMonth() + 1, dt.getDate());
    }
}

// 增加一个最大年份的属性
DateSelector.prototype.MinYear = 1900;

// 增加一个最大年份的属性
DateSelector.prototype.MaxYear = (new Date()).getFullYear();

// 初始化年份
DateSelector.prototype.InitYearSelect = function()
{
    // 循环添加OPION元素到年份select对象中
    for(var i = this.MaxYear; i >= this.MinYear; i--)
    {
        // 新建一个OPTION对象
        var op = window.document.createElement("OPTION");
        
        // 设置OPTION对象的值
        op.value = i;
        
        // 设置OPTION对象的内容
        op.innerHTML = i;
        
        // 添加到年份select对象
        this.selYear.appendChild(op);
    }
}

// 初始化月份
DateSelector.prototype.InitMonthSelect = function()
{
    // 循环添加OPION元素到月份select对象中
    for(var i = 1; i < 13; i++)
    {
        // 新建一个OPTION对象
        var op = window.document.createElement("OPTION");
        
        // 设置OPTION对象的值
        op.value = i;
        
        // 设置OPTION对象的内容
        op.innerHTML = i;
        
        // 添加到月份select对象
        this.selMonth.appendChild(op);
    }
}

// 根据年份与月份获取当月的天数
DateSelector.DaysInMonth = function(year, month)
{
    var date = new Date(year, month, 0);
    return date.getDate();
}

// 初始化天数
DateSelector.prototype.InitDaySelect = function()
{
    // 使用parseInt函数获取当前的年份和月份
    var year = parseInt(this.selYear.value);
    var month = parseInt(this.selMonth.value);
    
    // 获取当月的天数
    var daysInMonth = DateSelector.DaysInMonth(year, month);
    
    // 清空原有的选项
    this.selDay.options.length = 0;
    // 循环添加OPION元素到天数select对象中
    for(var i = 1; i <= daysInMonth ; i++)
    {
        // 新建一个OPTION对象
        var op = window.document.createElement("OPTION");
        
        // 设置OPTION对象的值
        op.value = i;
        
        // 设置OPTION对象的内容
        op.innerHTML = i;
        
        // 添加到天数select对象
        this.selDay.appendChild(op);
    }
}

// 处理年份和月份onchange事件的方法，它获取事件来源对象（即selYear或selMonth）
// 并调用它的Group对象（即DateSelector实例，请见构造函数）提供的InitDaySelect方法重新初始化天数
// 参数e为event对象
DateSelector.Onchange = function(e)
{
    var selector = window.document.all != null ? e.srcElement : e.target;
    selector.Group.InitDaySelect();
}

// 根据参数初始化下拉菜单选项
DateSelector.prototype.InitSelector = function(year, month, day)
{
    // 由于外部是可以调用这个方法，因此我们在这里也要将selYear和selMonth的选项清空掉
    // 另外因为InitDaySelect方法已经有清空天数下拉菜单，因此这里就不用重复工作了
    this.selYear.options.length = 0;
    this.selMonth.options.length = 0;
    
    // 初始化年、月
    this.InitYearSelect();
    this.InitMonthSelect();
    
    // 设置年、月初始值
    this.selYear.selectedIndex = this.MaxYear - year;
    this.selMonth.selectedIndex = month - 1;
    
    // 初始化天数
    this.InitDaySelect();
    
    // 设置天数初始值
    this.selDay.selectedIndex = day - 1;
}
//

//
function leftLoginCheck() {
	var lang = jQuery("#lang").val();
	var LoginName = jQuery("#leftName").val();
    var loginPwd = jQuery("#leftPwd").val();
	
	if (LoginName=='')
	{
		if (lang==1) {
			alert("Login Name Not Null!");
		}
		else if (lang==2) {
			alert("登入名稱不能為空！");
		}
		else if (lang==3) {
			alert("登入名称不能为空！");
		}
		jQuery("#leftName").focus();
		return false;
	}
	
	if (loginPwd == "") {
		if (lang==1) {
			alert("Password Not Null!");
		}
		else if (lang==2) {
			alert("密碼不能為空！");
		}
		else if (lang==3) {
			alert("密码不能为空！");
		}
		jQuery("#leftPwd").focus();
        return;
    }
    else if (5 > loginPwd.length || loginPwd.length > 16) {
		if (lang==1) {
			alert("Passward length wrong!");
		}
		else if (lang==2) {
			alert("密碼長度必須在6-16位之間！");
		}
		else if (lang==3) {
			alert("密码长度必须在6-16位之间！");
		}
		jQuery("#leftPwd").focus();
        return;
    }
	
	//接收表单的URL地址
	var url = "memberLoginInfo.php";
	
	//需要POST的值，把每个变量都通过&来联接
	var postStr   = "loginName=" + LoginName + "&loginPwd=" + loginPwd;
		
		var ajax = false;
		//开始初始化XMLHttpRequest对象
		if(window.XMLHttpRequest) { //Mozilla 浏览器
			 ajax = new XMLHttpRequest();
			 if (ajax.overrideMimeType) {//设置MiME类别
					 ajax.overrideMimeType("text/xml");
			 }
		}
		else if (window.ActiveXObject) { // IE浏览器
			 try {
					 ajax = new ActiveXObject("Msxml2.XMLHTTP");
			 } catch (e) {
					 try {
							 ajax = new ActiveXObject("Microsoft.XMLHTTP");
					 } catch (e) {}
			 }
		}
		if (!ajax) { // 异常，创建对象实例失败
			 window.alert("不能创建XMLHttpRequest对象实例.");
			 return false;
		}
		
		//通过Post方式打开连接
		ajax.open("POST", url, true); 
		
		//定义传输的文件HTTP头信息
		ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
		
		//发送POST数据
		ajax.send(postStr);
		
		//获取执行状态
		ajax.onreadystatechange = function() { 
			//如果执行状态成功，那么就把返回信息写到指定的层里
			if (ajax.readyState == 4 && ajax.status == 200) {
				//window.alert(ajax.responseText);
				//
				if (ajax.responseText == 'Error') {
					if (lang==1) {
						alert("Please don't repeat login!");
					}
					else if (lang==2) {
						alert("請勿重覆登入！");
					}
					else if (lang==3) {
						alert("请勿重复登入！");
					}
					return;
				}
				else if (ajax.responseText == 'Error1') {
					if (lang==1) {
						alert("Incorrect login name or password!");
					}
					else if (lang==2) {
						alert("登入名稱或密碼錯誤！");
					}
					else if (lang==3) {
						alert("登入名称或密码错误！");
					}
					return;
				}
				else if (ajax.responseText == 'Error2') {
					if (lang==1) {
						alert("Your account has not been activated,please check your e-mail to complete the final step of activation!");
					}
					else if (lang==2) {
						alert("您的帳號尚未激活，請進入您的郵箱完成最后一步激活！");
					}
					else if (lang==3) {
						alert("您的帐号尚未激活，请进入您的邮箱完成最后一步激活！");
					}
					return;
				}
				else if (ajax.responseText == 'System Error') {
					if (lang==1) {
						alert("System Error！");
					}
					else if (lang==2) {
						alert("系統錯誤！");
					}
					else if (lang==3) {
						alert("系统错误！");
					}
					return;
				}
				else if (ajax.responseText == 'Successfully') {
					window.location.reload();
				}
			}
			else if (ajax.readyState == 4 && ajax.status != 200) { 
				if (lang==1) {
					alert("Login Fail！");
				}
				else if (lang==2) {
					alert("登入失敗！");
				}
				else if (lang==3) {
					alert("登入失敗！");
				}
				return;
			}
		} 
}
