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

var pwdC = false;
var repwdC = false;
var emailC = false;
var ReEmailC = false;
var firstNameC = false;

var HiddenString = "visibility: hidden;";
var ViewString = "visibility: visible;";
var RightCss = "font-family: Arial, Helvetica, sans-serif; font-size: 15px; color: 67ae00;";
var WrongCss = "font-family: Arial, Helvetica, sans-serif; font-size: 15px; color: ff0000;";

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

function clearForm() 
{        
	document.getElementById('firstName').value = '';
	$("#firstNamevalid").text("");
	document.getElementById('lastName').value = '';
	document.getElementById('Email').value = '';
	$("#Emailvalid").text("");
	document.getElementById('ReEmail').value = '';
	$("#ReEmailvalid").text("");
	document.getElementById('Pwd').value = '';
	$("#Pwdvalid").text("");
	document.getElementById('RePwd').value = '';
	$("#RePwdvalid").text("");
	document.getElementById('cbRead').checked = false;
	document.getElementById('message').checked = true;
}

///姓名驗證
function firstNameCheck() {
    var firstName = $("#firstName").val();
    var firstNamehid = $("#firstNamehid").val();
	var lang = $("#lang").val();
    if (firstName == "") {
		if (lang==1) {
			$("#firstNamevalid").text("Missing First Name!");
		}
		else if (lang==2) {
			$("#firstNamevalid").text("名不能為空！");
		}
		else if (lang==3) {
			$("#firstNamevalid").text("名不能为空！");
		}
		else if (lang==4) {
			$("#firstNamevalid").text("名不能為空！");
		}		
		$("#firstNamehid").val(firstName);		
		$("#firstName_valid_div").attr("style", ViewString);
		$("#firstNamevalid").attr("style", WrongCss);
		firstNameC = false;
		return;
    }
    if (firstName == firstNamehid) {
        return;
    }
    else {
        if (firstName.length > 0 && firstName.length < 50) {
            $("#firstNamevalid").text("OK！");
			$("#firstNamehid").val(firstName);
            $("#firstName_valid_div").attr("style", ViewString);
            $("#firstNamevalid").attr("style", RightCss);
			firstNameC = true;
            return;
        }
        else {
			if (lang==1) {
				$("#firstNamevalid").text("Invalid First Name!");
			}
			else if (lang==2) {
				$("#firstNamevalid").text("請輸入真實的姓名！");
			}
			else if (lang==3) {
				$("#firstNamevalid").text("请输入真实的姓名！");
			}
			else if (lang==4) {
				$("#firstNamevalid").text("請輸入真實的姓名！");
			}            
            $("#firstNamehid").val(firstName);
            $("#firstName_valid_div").attr("style", ViewString);
            $("#firstNamevalid").attr("style", WrongCss);
			firstNameC = false;
			return;
        }
    }
}


//電郵驗證
function emailCheck() {
    var email = $("#Email").val();
    var bkemail = $("#Emailhid").val();
	var lang = $("#lang").val();
    if (email == "") {
		if (lang==1) {
			$("#Emailvalid").text("Missing Email!");
		}
		else if (lang==2) {
			$("#Emailvalid").text("電郵不能為空！");
		}
		else if (lang==3) {
			$("#Emailvalid").text("电邮不能为空！");
		}
		else if (lang==4) {
			$("#Emailvalid").text("電郵不能為空！");
		}
        $("#Emailvalid").attr("style", WrongCss);
        $("#Email_valid_div").attr("style", ViewString);
		emailC = false;
        return;
    }
    if (email == bkemail) {
        return;
    }
    if (!isemail(email)) {
		if (lang==1) {
			$("#Emailvalid").text("Invalid Email Format!");
		}
		else if (lang==2) {
			$("#Emailvalid").text("電郵格式錯誤！");
		}
		else if (lang==3) {
			$("#Emailvalid").text("电邮格式错误！");
		}
		else if (lang==4) {
			$("#Emailvalid").text("電郵格式錯誤！");
		}
        $("#Emailhid").val(email);
        $("#Emailvalid").attr("style", WrongCss);
        $("#Email_valid_div").attr("style", ViewString);
		emailC = false;
        return;
    }
    else {
		//接收表单的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") 
				{
					$("#Emailvalid").text("OK！");
					$("#Emailhid").val(email);			
					$("#Email_valid_div").attr("style", ViewString);
					$("#Emailvalid").attr("style", RightCss);			
					emailC = true;
					return;
				}
				else if ((ajax.responseText)=="No") 
				{
					if (lang==1) {
						$("#Emailvalid").text("Email has been used!");
					}
					else if (lang==2) {
						$("#Emailvalid").text("電郵已經有人使用！");
					}
					else if (lang==3) {
						$("#Emailvalid").text("电邮已经有人使用！");
					}
					else if (lang==4) {
						$("#Emailvalid").text("電郵已經有人使用！");
					}		
					$("#Emailhid").val(email);
					$("#Email_valid_div").attr("style", ViewString);
					$("#Emailvalid").attr("style", WrongCss);			
					emailC = false;
					return;
				}
		   }
		   else if (ajax.readyState == 4 && ajax.status != 200) {
				if (lang==1) {
					$("#Emailvalid").text("System Error！");
				}
				else if (lang==2) {
					$("#Emailvalid").text("系統錯誤！");
				}
				else if (lang==3) {
					$("#Emailvalid").text("系统错误！");
				}
				else if (lang==4) {
					$("#Emailvalid").text("系統錯誤！");
				}
				$("#Emailhid").val(email);
				$("#Email_valid_div").attr("style", ViewString);
				$("#Emailvalid").attr("style", WrongCss);			
				emailC = false;
				return;
			}
		}
    }
}

//確認電郵驗證
function reEmailCheck() {
    var email = $("#Email").val();
    var ReEmail = $("#ReEmail").val();
	var lang = $("#lang").val();
    if (ReEmail == "") {
		if (lang==1) {
			$("#ReEmailvalid").text("重复输入電郵不可为空！");
		}
		else if (lang==2) {
			$("#ReEmailvalid").text("重复输入電郵不可为空！");
		}
		else if (lang==3) {
			$("#ReEmailvalid").text("重复输入电邮不能为空！");
		}
		else if (lang==4) {
			$("#ReEmailvalid").text("重复输入電郵不可为空！");
		}
        $("#ReEmail_valid_div").attr("style", ViewString);        
        $("#ReEmailvalid").attr("style", WrongCss);
        ReEmailC = false;
        return;
    }
    if (email != ReEmail) {
		if (lang==1) {
			$("#ReEmailvalid").text("2次输入電郵不同！");
		}
		else if (lang==2) {
			$("#ReEmailvalid").text("2次输入電郵不同！");
		}
		else if (lang==3) {
			$("#ReEmailvalid").text("2次输入电邮不同！");
		}
		else if (lang==4) {
			$("#ReEmailvalid").text("2次输入電郵不同！");
		}
        $("#ReEmail_valid_div").attr("style", ViewString);        
        $("#ReEmailvalid").attr("style", WrongCss);
        ReEmailC = false;
		return;
    }
	if (!isemail(email)) {
		if (lang==1) {
			$("#ReEmailvalid").text("Invalid Email Format!");
		}
		else if (lang==2) {
			$("#ReEmailvalid").text("電郵格式錯誤！");
		}
		else if (lang==3) {
			$("#ReEmailvalid").text("电邮格式错误！");
		}
		else if (lang==4) {
			$("#ReEmailvalid").text("電郵格式錯誤！");
		}        
        $("#ReEmailhid").val(ReEmail);
        $("#ReEmailvalid").attr("style", WrongCss);
        $("#ReEmail_valid_div").attr("style", ViewString);
		emailC = false;
        return;
    }
    else {
		$("#ReEmailvalid").text("OK！");
        $("#ReEmail_valid_div").attr("style", ViewString);
        $("#ReEmailvalid").attr("style", RightCss);        
        ReEmailC = true;
		return;
    }
}

///密碼驗證
function pwdCheck() {
    var pwd = $("#Pwd").val();
    var bkpwd = $("#Pwdhid").val();
	var lang = $("#lang").val();
    if (pwd == "") {
		if (lang==1) {
			$("#Pwdvalid").text("Password Not Null!");
		}
		else if (lang==2) {
			$("#Pwdvalid").text("密碼不能為空！");
		}
		else if (lang==3) {
			$("#Pwdvalid").text("密码不能为空！");
		}
		else if (lang==4) {
			$("#Pwdvalid").text("密碼不能為空！");
		}
        $("#Pwdvalid").attr("style", WrongCss);
        $("#Pwdhid").val(pwd);
        $("#pwd_valid_div").attr("style", ViewString);
		pwdC = false;
        return;
    }
    if (pwd == bkpwd) {
        return;
    }
    else {
        if (5 < pwd.length && pwd.length < 17) {            
            $("#Pwdvalid").text("OK！");
            $("#Pwdvalid").attr("style", RightCss);
            $("#Pwdhid").val(pwd);
            $("#pwd_valid_div").attr("style", ViewString);
			pwdC = true;
            return;
        }
        else {
			if (lang==1) {
				$("#Pwdvalid").text("Passward Length!");
			}
			else if (lang==2) {
				$("#Pwdvalid").text("密碼長度必須在6-16位之間！");
			}
			else if (lang==3) {
				$("#Pwdvalid").text("密码长度必须在6-16位之间！");
			}
			else if (lang==4) {
				$("#Pwdvalid").text("密碼長度必須在6-16位之間！");
			}
            $("#Pwdvalid").attr("style", WrongCss);
            $("#Pwdhid").val(pwd);
            $("#pwd_valid_div").attr("style", ViewString);
			pwdC = false;
            return;
        }
    }
}

///確定密碼驗證
function repwdCheck() {
    var pwd = $("#Pwd").val();
    var RePwd = $("#RePwd").val();
	var lang = $("#lang").val();
    if (RePwd == "") {
		if (lang==1) {
			$("#RePwdvalid").text("Confirm Password Not Null!");
		}
		else if (lang==2) {
			$("#RePwdvalid").text("確定密碼不能為空！");
		}
		else if (lang==3) {
			$("#RePwdvalid").text("确定密码不能为空！");
		}
		else if (lang==4) {
			$("#RePwdvalid").text("確定密碼不能為空！");
		}
        $("#RePwd_valid_div").attr("style", ViewString);
        $("#RePwdvalid").attr("style", WrongCss);
        repwdC = false;
        return;
    }
    if (pwd != RePwd) {
		if (lang==1) {
			$("#RePwdvalid").text("Password!");
		}
		else if (lang==2) {
			$("#RePwdvalid").text("2次輸入密碼不同！");
		}
		else if (lang==3) {
			$("#RePwdvalid").text("2次输入密码不同！");
		}
		else if (lang==4) {
			$("#RePwdvalid").text("2次輸入密碼不同！");
		}
        $("#RePwd_valid_div").attr("style", ViewString);
        $("#RePwdvalid").attr("style", WrongCss);
        repwdC = false;
		return;
    }
    else {
		$("#RePwdvalid").text("OK！");
        $("#RePwd_valid_div").attr("style", ViewString);
        $("#RePwdvalid").attr("style", RightCss);
        repwdC = true;
		return;
    }
}

///提交前查看所有的验证是否通过
function SubmitCheck() {
	var lang = $("#lang").val();
	var pwd = $("#Pwd").val();
	var RePwd = $("#RePwd").val();
    var email = $("#Email").val();
	var ReEmail = $("#ReEmail").val();
	var firstName = $("#firstName").val();
	var lastName = $("#lastName").val();
	var message = "0";
    if ($("#message").attr("checked")) {
        message = "1";
	}	
	if (!firstNameC)
	{
        $("#firstName").focus();
        return;
    }
	if (!emailC)
	{
        $("#Email").focus();
        return;
    }
	if (!ReEmailC)
	{
        $("#ReEmail").focus();
        return;
    }
	if (email != ReEmail)
	{
		if (lang==1) {
			$("#ReEmailvalid").text("2次输入電郵不同！");
		}
		else if (lang==2) {
			$("#ReEmailvalid").text("2次输入電郵不同！");
		}
		else if (lang==3) {
			$("#ReEmailvalid").text("2次输入电邮不同！");
		}
		else if (lang==4) {
			$("#ReEmailvalid").text("2次输入電郵不同！");
		}
        $("#ReEmail_valid_div").attr("style", ViewString);        
        $("#ReEmailvalid").attr("style", WrongCss);
        ReEmailC = false;
		return;
	}
	if (!pwdC)
	{
        $("#Pwd").focus();
        return;
    }
    if (!repwdC)
	{
        $("#RePwd").focus();
        return;
    }
	if (pwd != RePwd)
	{
		if (lang==1) {
			$("#RePwdvalid").text("Password!");
		}
		else if (lang==2) {
			$("#RePwdvalid").text("2次輸入密碼不同！");
		}
		else if (lang==3) {
			$("#RePwdvalid").text("2次输入密码不同！");
		}
		else if (lang==4) {
			$("#RePwdvalid").text("2次輸入密碼不同！");
		}
        $("#RePwd_valid_div").attr("style", ViewString);
        $("#RePwdvalid").attr("style", WrongCss);
        repwdC = false;
		return;
	}
    if ($("#cbRead").attr("checked")) {
    }
    else {
		if (lang==1) {
			alert("請先閱讀並同意使用條款及私穩政策");
		}
		else if (lang==2) {
			alert("請先閱讀並同意使用條款及私穩政策");
		}
		else if (lang==3) {
			alert("请先阅读并同意使用条款及私隐政策");
		}
		else if (lang==4) {
			alert("請先閱讀並同意使用條款及私穩政策");
		}        
        $("#cbRead").focus();
        return;
    }
    
	
	//获取接受返回信息层
	//var msg = document.getElementById("msg");
	
	//接收表单的URL地址
	var url = "memberRegistInfo.php";
	
	//需要POST的值，把每个变量都通过&来联接
	var postStr   = "pwd=" + pwd
        + "&email=" + email
		+ "&firstName=" + firstName
		+ "&lastName=" + lastName
		+ "&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) {
				//msg.innerHTML = ajax.responseText; 
				//alert(ajax.responseText);
				if (ajax.responseText == 'error') {
					if (lang==1) {
						$("#errorid").text("System Error！");
					}
					else if (lang==2) {
						$("#errorid").text("系統錯誤！");
					}
					else if (lang==3) {
						$("#errorid").text("系统错误！");
					}
					else if (lang==4) {
						$("#errorid").text("系統錯誤！");
					}
					$("#errorid").attr("style", WrongCss);
					$("#error_valid_div").attr("style", ViewString);
					return;
				}
				else if (ajax.responseText == 'error1') {
					if (lang==1) {
						$("#errorid").text("Email send fail！");
					}
					else if (lang==2) {
						$("#errorid").text("電郵發送失敗！");
					}
					else if (lang==3) {
						$("#errorid").text("电邮发送失败！");
					}
					else if (lang==4) {
						$("#errorid").text("電郵發送失敗！");
					}
					$("#errorid").attr("style", WrongCss);
					$("#error_valid_div").attr("style", ViewString);
					return;
				}
				else {
					window.location.href='memberRegisted.php?msg=Successfully';
				}
			}
			else if (ajax.readyState == 4 && ajax.status != 200) { 
				if (lang==1) {
					window.alert("注册失败");
				}
				else if (lang==2) {
					window.alert("注冊失敗");
				}
				else if (lang==3) {
					window.alert("注册失败");
				}
				else if (lang==4) {
					window.alert("注册失败");
				}
			}
		} 
}

//
function loginCheck() {
	var lang = $("#lang").val();
	var Link = $("#link").val();
	var loginEmail = $("#loginEmail").val();
    var loginPwd = $("#loginPwd").val();    
	
	if (loginEmail=='')
	{
		if (lang==1) {
			$("#Emailvalid").text("Missing Email!");
		}
		else if (lang==2) {
			$("#Emailvalid").text("電郵不能為空！");
		}
		else if (lang==3) {
			$("#Emailvalid").text("电邮不能为空！");
		}
		else if (lang==4) {
			$("#Emailvalid").text("電郵不能為空！");
		}
		$("#Emailvalid").attr("style", WrongCss);
		$("#Email_valid_div").attr("style", ViewString);
		$("#loginEmail").focus();
		return;
	}
	if (!isemail(loginEmail)) {
		if (lang==1) {
			$("#Emailvalid").text("Invalid Email Format!");
		}
		else if (lang==2) {
			$("#Emailvalid").text("電郵格式錯誤！");
		}
		else if (lang==3) {
			$("#Emailvalid").text("电邮格式错误！");
		}
		else if (lang==4) {
			$("#Emailvalid").text("電郵格式錯誤！");
		}
		$("#Emailvalid").attr("style", WrongCss);
		$("#Email_valid_div").attr("style", ViewString);
		$("#loginEmail").focus();
		return;
	}
	
	if (loginPwd == "") {
		if (lang==1) {
			$("#Pwdvalid").text("Password Not Null!");
		}
		else if (lang==2) {
			$("#Pwdvalid").text("密碼不能為空！");
		}
		else if (lang==3) {
			$("#Pwdvalid").text("密码不能为空！");
		}
		else if (lang==4) {
			$("#Pwdvalid").text("密碼不能為空！");
		}
        $("#Pwdvalid").attr("style", WrongCss);
        $("#pwd_valid_div").attr("style", ViewString);
		$("#loginPwd").focus();
        return;
    }
    else if (5 > loginPwd.length || loginPwd.length > 17) {
		if (lang==1) {
			$("#Pwdvalid").text("Passward Length!");
		}
		else if (lang==2) {
			$("#Pwdvalid").text("密碼長度必須在6-16位之間！");
		}
		else if (lang==3) {
			$("#Pwdvalid").text("密码长度必须在6-16位之间！");
		}
		else if (lang==4) {
			$("#Pwdvalid").text("密碼長度必須在6-16位之間！");
		}
		$("#Pwdvalid").attr("style", WrongCss);
		$("#pwd_valid_div").attr("style", ViewString);
		$("#loginPwd").focus();
        return;
    }
	
	//接收表单的URL地址
	var url = "memberLoginInfo.php";
	
	//需要POST的值，把每个变量都通过&来联接
	var postStr   = "loginEmail=" + loginEmail + "&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) {
						$("#errorid").text("請勿重復登入");
					}
					else if (lang==2) {
						$("#errorid").text("請勿重復登入！");
					}
					else if (lang==3) {
						$("#errorid").text("请勿重复登入！");
					}
					else if (lang==4) {
						$("#errorid").text("請勿重復登入！");
					}
					$("#errorid").attr("style", WrongCss);
					$("#error_valid_div").attr("style", ViewString);
					return;
				}
				else if (ajax.responseText == 'error1') {
					if (lang==1) {
						$("#errorid").text("System Error！");
					}
					else if (lang==2) {
						$("#errorid").text("系統錯誤！");
					}
					else if (lang==3) {
						$("#errorid").text("系统错误！");
					}
					else if (lang==4) {
						$("#errorid").text("系統錯誤！");
					}
					$("#errorid").attr("style", WrongCss);
					$("#error_valid_div").attr("style", ViewString);
					return;
				}
				else if (ajax.responseText == 'error2') {
					if (lang==1) {
						$("#errorid").text("電郵或密碼錯誤！");
					}
					else if (lang==2) {
						$("#errorid").text("電郵或密碼錯誤！");
					}
					else if (lang==3) {
						$("#errorid").text("電郵或密碼錯誤！");
					}
					else if (lang==4) {
						$("#errorid").text("電郵或密碼錯誤！");
					}
					$("#errorid").attr("style", WrongCss);
					$("#error_valid_div").attr("style", ViewString);
					return;
				}
				else if (ajax.responseText == 'error3') {
					if (lang==1) {
						$("#errorid").text("您的帳號尚未激活，請進入您的郵箱完成最后一步激活！");
					}
					else if (lang==2) {
						$("#errorid").text("您的帳號尚未激活，請進入您的郵箱完成最后一步激活！");
					}
					else if (lang==3) {
						$("#errorid").text("您的帐号尚未激活，请进入您的邮箱完成最后一步激活！");
					}
					else if (lang==4) {
						$("#errorid").text("您的帳號尚未激活，請進入您的郵箱完成最后一步激活！");
					}
					$("#errorid").attr("style", WrongCss);
					$("#error_valid_div").attr("style", ViewString);
					return;
				}
				else {
					if (Link !='') {
						window.location.href= Link;
					}
					else {
						window.location.href='index.php?msg=Successfully';
					}
				}
			}
			else if (ajax.readyState == 4 && ajax.status != 200) { 
				if (lang==1) {
					$("#errorid").text("電郵或密碼錯誤！");
				}
				else if (lang==2) {
					$("#errorid").text("電郵或密碼錯誤！");
				}
				else if (lang==3) {
					$("#errorid").text("電郵或密碼錯誤！");
				}
				else if (lang==4) {
					$("#errorid").text("電郵或密碼錯誤！");
				}
				$("#errorid").attr("style", WrongCss);
				$("#error_valid_div").attr("style", ViewString);
				return;
			}
		} 
}

function forgotCheck()
{
	var lang = $("#lang").val();
	var loginEmail = $("#loginEmail").val();
	
	$("#error_valid_div").attr("style", HiddenString);
	
	if (loginEmail=='')
	{
		if (lang==1) {
			$("#Emailvalid").text("Missing Email!");
		}
		else if (lang==2) {
			$("#Emailvalid").text("電郵不能為空！");
		}
		else if (lang==3) {
			$("#Emailvalid").text("电邮不能为空！");
		}
		else if (lang==4) {
			$("#Emailvalid").text("電郵不能為空！");
		}
		$("#Emailvalid").attr("style", WrongCss);
		$("#Email_valid_div").attr("style", ViewString);
		$("#loginEmail").focus();
		return;
	}
	if (!isemail(loginEmail)) {
		if (lang==1) {
			$("#Emailvalid").text("Invalid Email Format!");
		}
		else if (lang==2) {
			$("#Emailvalid").text("電郵格式錯誤！");
		}
		else if (lang==3) {
			$("#Emailvalid").text("电邮格式错误！");
		}
		else if (lang==4) {
			$("#Emailvalid").text("電郵格式錯誤！");
		}
		$("#Emailvalid").attr("style", WrongCss);
		$("#Email_valid_div").attr("style", ViewString);
		$("#loginEmail").focus();
		return;
	}
	
	$("#Email_valid_div").attr("style", HiddenString);
	
	//接收表单的URL地址
	var url = "memberForgotInfo.php";
	
	//需要POST的值，把每个变量都通过&来联接
	var postStr   = "loginEmail=" + loginEmail + "&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) {
						$("#errorid").text("該電郵沒有登記");
					}
					else if (lang==2) {
						$("#errorid").text("該電郵沒有登記！");
					}
					else if (lang==3) {
						$("#errorid").text("该电邮没有登记！");
					}
					else if (lang==4) {
						$("#errorid").text("該電郵沒有登記！");
					}
					$("#errorid").attr("style", WrongCss);
					$("#error_valid_div").attr("style", ViewString);
					return;
				}
				else if (ajax.responseText == 'error1') {
					if (lang==1) {
						$("#errorid").text("System Error！");
					}
					else if (lang==2) {
						$("#errorid").text("系統錯誤！");
					}
					else if (lang==3) {
						$("#errorid").text("系统错误！");
					}
					else if (lang==4) {
						$("#errorid").text("系統錯誤！");
					}
					$("#errorid").attr("style", WrongCss);
					$("#error_valid_div").attr("style", ViewString);
					return;
				}
				else if (ajax.responseText == 'error2') {
					if (lang==1) {
						$("#errorid").text("Email send fail！");
					}
					else if (lang==2) {
						$("#errorid").text("電郵發送失敗！");
					}
					else if (lang==3) {
						$("#errorid").text("电邮发送失败！");
					}
					else if (lang==4) {
						$("#errorid").text("電郵發送失敗！");	
					}
					$("#errorid").attr("style", WrongCss);
					$("#error_valid_div").attr("style", ViewString);
					return;
				}
				else {
					document.getElementById('loginEmail').value = '';
					$("#errorid").text("電郵發送成功！");
					$("#errorid").attr("style", RightCss);
					$("#error_valid_div").attr("style", ViewString);
				}
			}
			else if (ajax.readyState == 4 && ajax.status != 200) { 
				if (lang==1) {
					$("#errorid").text("電郵發送失敗！");
				}
				else if (lang==2) {
					$("#errorid").text("電郵發送失敗！");
				}
				else if (lang==3) {
					$("#errorid").text("电邮发送失败！");
				}
				else if (lang==4) {
					$("#errorid").text("電郵發送失敗！");
				}
				$("#errorid").attr("style", WrongCss);
					$("#error_valid_div").attr("style", ViewString);
					return;
			}
		} 
}

///提交前查看所有的验证是否通过
function updatePwdCheck() {
	var lang = $("#lang").val();
	var pwd = $("#Pwd").val();
	var RePwd = $("#RePwd").val();
	var userName = $("#userName").val();
	var forgotToken = $("#forgotToken").val();
	
	if (!pwdC)
	{
        $("#Pwd").focus();
        return;
    }
    if (!repwdC)
	{
        $("#RePwd").focus();
        return;
    }
	
	if (pwd != RePwd)
	{
		if (lang==1) {
			$("#RePwdvalid").text("Password!");
		}
		else if (lang==2) {
			$("#RePwdvalid").text("2次輸入密碼不同！");
		}
		else if (lang==3) {
			$("#RePwdvalid").text("2次输入密码不同！");
		}
		else if (lang==4) {
			$("#RePwdvalid").text("2次輸入密碼不同！");
		}
        $("#RePwd_valid_div").attr("style", ViewString);
        $("#RePwdvalid").attr("style", WrongCss);
        repwdC = false;
		return;
	}
    
	//接收表单的URL地址
	var url = "resetPasswordInfo.php";
	
	//需要POST的值，把每个变量都通过&来联接
	var postStr   = "pwd=" + pwd + "&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) {
						$("#errorid").text("重設密碼失敗！");
					}
					else if (lang==2) {
						$("#errorid").text("重設密碼失敗！");
					}
					else if (lang==3) {
						$("#errorid").text("重设密码失败！");
					}
					else if (lang==4) {
						$("#errorid").text("重設密碼失敗！");
					}
					$("#errorid").attr("style", WrongCss);
					$("#error_valid_div").attr("style", ViewString);
					return;
				}
				else {
					window.location.href='memberLogin.php';
				}
			}
			else if (ajax.readyState == 4 && ajax.status != 200) { 
				if (lang==1) {
					window.alert("重設密碼失敗");
				}
				else if (lang==2) {
					window.alert("重設密碼失敗");
				}
				else if (lang==3) {
					window.alert("重设密码失败");
				}
				else if (lang==4) {
					window.alert("重設密碼失敗");
				}
			}
		} 
}


function editCheck() {
	var lang = $("#lang").val();
	var id = $("#memberId").val();
	var firstName = $("#firstName").val();
	var firstName01 = $("#firstName01").val();
	var lastName = $("#lastName").val();
	var oldPwd = $("#oldPwd").val();
	var Pwd = $("#Pwd").val();
    var RePwd = $("#RePwd").val();
	
	if (!firstNameC && (firstName != firstName01))
	{
        $("#firstName").focus();
        return;
    }
	if (Pwd !='' || RePwd !='')
	{
		if (!pwdC)
		{
			$("#Pwd").focus();
			return;
		}
		if (!repwdC)
		{
			$("#RePwd").focus();
			return;
		}
		if (Pwd != RePwd)
		{
			if (lang==1) {
				$("#RePwdvalid").text("Password!");
			}
			else if (lang==2) {
				$("#RePwdvalid").text("2次輸入密碼不同！");
			}
			else if (lang==3) {
				$("#RePwdvalid").text("2次输入密码不同！");
			}
			else if (lang==4) {
				$("#RePwdvalid").text("2次輸入密碼不同！");
			}
			$("#RePwd_valid_div").attr("style", ViewString);
			$("#RePwdvalid").attr("style", WrongCss);
			repwdC = false;
			return;
		}
	}
	
	var message = "0";
    if ($("#message").attr("checked")) {
        message = "1";
	}
    
	//接收表单的URL地址
	var url = "memberProfileInfo.php";
	
	//需要POST的值，把每个变量都通过&来联接
	var postStr = "&firstName=" + firstName
		+ "&lastName=" + lastName
		+ "&id=" + id
		+ "&oldPwd=" + oldPwd
		+ "&pwd=" + Pwd
		+ "&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);
				$("#msg_div").attr("style", HiddenString);
				if (ajax.responseText == 'error1') {
					if (lang==1) {
						$("#errorid").text("Old Password Error！");
					}
					else if (lang==2) {
						$("#errorid").text("舊密碼錯誤！");
					}
					else if (lang==3) {
						$("#errorid").text("旧密码错误！");
					}
					else if (lang==4) {
						$("#errorid").text("舊密碼錯誤！");
					}
					$("#errorid").attr("style", WrongCss);
					$("#error_valid_div").attr("style", ViewString);
					$("#oldPwd").focus();
					return;
				}
				else if (ajax.responseText == 'error2' || ajax.responseText == 'error3') {
					if (lang==1) {
						$("#errorid").text("Edit Fail!");
					}
					else if (lang==2) {
						$("#errorid").text("更改失敗！");
					}
					else if (lang==3) {
						$("#errorid").text("更改失敗！");
					}
					else if (lang==4) {
						$("#errorid").text("更改失敗！");
					}
					$("#errorid").attr("style", WrongCss);
					$("#error_valid_div").attr("style", ViewString);
					return;
				}
				else {
					window.location.href='memberProfile.php?msg=Successful';
				}
			}
			else if (ajax.readyState == 4 && ajax.status != 200) {
				$("#msg_div").attr("style", HiddenString);
				if (lang==1) {
					window.alert("Edit Fail");
				}
				else if (lang==2) {
					window.alert("更改失敗");
				}
				else if (lang==3) {
					window.alert("更改失败");
				}
				else if (lang==4) {
					window.alert("更改失敗");
				}
			}
		} 
}