var xmlHttp = createXmlHttpRequestObject();
function createXmlHttpRequestObject()
{
	var xmlHttp;
	try
	{
		xmlHttp = new XMLHttpRequest();
	}
	catch(e)
	{
		var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",
										"MSXML2.XMLHTTP.5.0",
										"MSXML2.XMLHTTP.4.0",
										"MSXML2.XMLHTTP.3.0",
										"MSXML2.XMLHTTP",
										"Microsoft.XMLHTTP");
		for(var i=0;i<XmlHttpVersions.length && !xmlHttp; i++)
		{
			try
			{
				xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
			}
			catch(e){}
		}
	}
	if(!xmlHttp)
	{
		alert("Error creating the XMLHttpRequest object.");
	}
	else
	{
		return xmlHttp;
	}
}
//==========不需回傳接收function======
function ReturnNothing()
{
	if(xmlHttp.readyState == 4)						//回傳回來必須這某寫~!??
	{
		if(xmlHttp.status == 200)					////回傳回來必須這某寫~!??
		{
			//為了把下面錯誤用不見
		}
		else
		{
			alert("There was a problem accessing the server:"+xmlHttp.statusText);
		}
	}
}
//=============檢查Email==============
function CheckEmail(emailtoCheck)
{
	// 規則: 1.只有一個 "@"
	//       2.網址中, 至少要有一個".", 且不能連續出現
	//       3.不能有空白
	var regExp = /^[^@^\s]+@[^\.@^\s]+(\.[^\.@^\s]+)+$/;
	if ( emailtoCheck.match(regExp) )
		return true;
	else
		return false;
}
//====================================
//=============檢查家電===============
function CheckPhone(rtel) 
{ 
	var Phone = "";
	for(var idx = 0 ; idx<rtel.length; idx++) 
	{
		if(rtel.charAt(idx)>= '0' && rtel.charAt(idx) <= '9') 
        {
			Phone +=rtel.charAt(idx);
		}
	}
	if (Phone.search(/^[0][1-9]{1,2}([0-9]{7,8})+((#([0-9]{1,5})){0,1})$/)!=-1 && Phone.length<=10) 
	{
		return true; 
	}else
	{
		return false;
	}
}
//====================================
//=============檢查手機===============
function CheckMobile(rmobile) 
{
	if (rmobile.search(/^09[0-9]{8}$/)!=-1) 
	{return true;}
	else 
	{return false;}
}
//====================================
//=============Jquery效果===============
function HideJquery(DivID)
{
	$(DivID).removeAttr( "style" ).fadeOut();
	setTimeout(function() 
	{
		$(DivID).removeAttr( "style" ).hide().fadeIn();
	}, 1000 );
	
}
function BlindJquery(DivID)
{
	var options = {};
	$('#'+DivID).toggle("blind",options,500,null);
}
var BlindJqueryConfirm=0;
function BlindJqueryProList(DivID,who,all)
{
	if(BlindJqueryConfirm==0)
	{
		var options = {};
		for(var i=1;i<=all;i++)
		{
			var ForDivID=DivID+i;
			if(i==who)
			{
				//$('#'+ForDivID).toggle("blind",options,800,null);
				if(document.getElementById(ForDivID).style.display=="none"){
					$('#'+ForDivID).show("blind",options,500,null);
					BlindJqueryConfirm=1;
				}
			}else
			{
			
				if(document.getElementById(ForDivID).style.display!="none"){
					$('#'+ForDivID).hide("blind",options,500,null);
				}
			}
		}
	}
	setTimeout(function()
	{
		BlindJqueryConfirm=0;
	},500)
}
//----------------------------------------------
//====================================
//-----------------產品類別簡介----------------------
function OnLoadProductsAbout()
{
	try
	{
		var KeyWord = document.getElementById("KeyWord").value;
		if(KeyWord!='')
		{
			var time= new Date().getTime();		//因為ajax的時間戳讓每次的網址都不一樣，就會在讀一次xml檔。所以需url+time。
			var PostMain="KeyWord="+KeyWord+"&time="+time;
			xmlHttp.open("POST","ajax/OnLoadProductsAbout.php",true);											//將值傳進另一個網頁
			xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			xmlHttp.setRequestHeader("Content-length", PostMain.length);
			xmlHttp.setRequestHeader("Connection", "close");
			xmlHttp.onreadystatechange = ReturnSelectProductsAboutContent;						//將結果傳回來給function
			xmlHttp.send(PostMain);		
		}
	}
	catch(e)
	{
		alert("Error");
	}
}
function SelectProductsAboutContent(id)
{
	try
		{
			//HideJquery('#Content');
			var time= new Date().getTime();		//因為ajax的時間戳讓每次的網址都不一樣，就會在讀一次xml檔。所以需url+time。
			var PostMain="id="+id+"&time="+time;
			xmlHttp.open("POST","ajax/SelectProductsAboutContent.php",true);											//將值傳進另一個網頁
			xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			xmlHttp.setRequestHeader("Content-length", PostMain.length);
			xmlHttp.setRequestHeader("Connection", "close");
			xmlHttp.onreadystatechange = ReturnSelectProductsAboutContent;						//將結果傳回來給function
			xmlHttp.send(PostMain);															//傳post的值需放進send(值)裡
			
		}																					//傳的值跟GET一樣。例：name=Dennis&content=good
		catch(e)																			//如要傳陣列的話。列：name[]=Dennis&name[]=Don這樣的話接收者就可用name[]這個陣列/ 
		{
			alert("Error");
		}
}
function ReturnSelectProductsAboutContent()
{
	if(xmlHttp.readyState == 4)						//回傳回來必須這某寫~!??
	{
		if(xmlHttp.status == 200)					////回傳回來必須這某寫~!??
		{
			var XMLhtml = xmlHttp.responseText;				//將整個網頁(xml)放進變數裡
			document.getElementById("ProductsContent").innerHTML = XMLhtml;
		}
	}
}
//GGlisten增加 , 產品類別主頁
function SelectProductsRotatrachType(id)
{
	try
		{
			//HideJquery('#Content');
			var time= new Date().getTime();		//因為ajax的時間戳讓每次的網址都不一樣，就會在讀一次xml檔。所以需url+time。
			var PostMain="id="+id+"&time="+time;
			xmlHttp.open("POST","ajax/SelectProductsRotatrachType.php",true);											//將值傳進另一個網頁
			xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			xmlHttp.setRequestHeader("Content-length", PostMain.length);
			xmlHttp.setRequestHeader("Connection", "close");
			xmlHttp.onreadystatechange = ReturnSelectProductsAboutContent;						//將結果傳回來給function
			xmlHttp.send(PostMain);															//傳post的值需放進send(值)裡
			
		}																					//傳的值跟GET一樣。例：name=Dennis&content=good
		catch(e)																			//如要傳陣列的話。列：name[]=Dennis&name[]=Don這樣的話接收者就可用name[]這個陣列/ 
		{
			alert("Error");
		}
}
//========================================================================================
//-----------------產品簡介----------------------
function SelectProductsContent(id,Table)
{
	try
		{
			//HideJquery('#Content');
			var time= new Date().getTime();		//因為ajax的時間戳讓每次的網址都不一樣，就會在讀一次xml檔。所以需url+time。
			var PostMain="id="+id+"&Table="+Table+"&time="+time;
			xmlHttp.open("POST","ajax/SelectProductsContent.php",true);											//將值傳進另一個網頁
			xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			xmlHttp.setRequestHeader("Content-length", PostMain.length);
			xmlHttp.setRequestHeader("Connection", "close");
			xmlHttp.onreadystatechange = ReturnSelectProductsAboutContent;						//將結果傳回來給function
			xmlHttp.send(PostMain);															//傳post的值需放進send(值)裡
			
		}																					//傳的值跟GET一樣。例：name=Dennis&content=good
		catch(e)																			//如要傳陣列的話。列：name[]=Dennis&name[]=Don這樣的話接收者就可用name[]這個陣列/ 
		{
			alert("Error");
		}
}
//========================================================================================
//-----------------產品配件簡介----------------------
function SelectProductsAccessoriesContent(id,Table)
{
	try
		{
			//HideJquery('#Content');
			var time= new Date().getTime();		//因為ajax的時間戳讓每次的網址都不一樣，就會在讀一次xml檔。所以需url+time。
			var PostMain="id="+id+"&Table="+Table+"&time="+time;
			xmlHttp.open("POST","ajax/SelectProductsAccessoriesContent.php",true);											//將值傳進另一個網頁
			xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			xmlHttp.setRequestHeader("Content-length", PostMain.length);
			xmlHttp.setRequestHeader("Connection", "close");
			xmlHttp.onreadystatechange = ReturnSelectProductsAboutContent;						//將結果傳回來給function
			xmlHttp.send(PostMain);															//傳post的值需放進send(值)裡
			
		}																					//傳的值跟GET一樣。例：name=Dennis&content=good
		catch(e)																			//如要傳陣列的話。列：name[]=Dennis&name[]=Don這樣的話接收者就可用name[]這個陣列/ 
		{
			alert("Error");
		}
}
//========================================================================================
function InsertContact()
{
	/*try
	{*/
		var FormName = document.Postform;
		
		/*if(FormName.ContactLastName.value=="")
		{alert("請輸入名稱：姓");return;}*/
		
		if(FormName.ContactName.value=="FirstName")
		{alert("Please enter FirstName");return;}
		
		if(FormName.ContactEmail.value=="")
		{alert("Please enter Email");return;}
		var Check_mail =CheckEmail(FormName.ContactEmail.value)   //驗証Email
		if(Check_mail==false)
		{alert("Your Email format does not!");return;}
		
		if(FormName.ContactProductsType.value=="")
		{alert("Please enter a product category");return;}
		
		if(FormName.ContactProductsFormat.value=="")
		{alert("Please enter a product specification");return;}
		
		if(FormName.ContactContent.value=="")
		{alert("Please enter the content");return;}
		
		var ContactLastName = escape(FormName.ContactLastName.value);　					//中文編碼　　　　接收方要解碼
		var ContactName = escape(FormName.ContactName.value);　					//中文編碼　　　　接收方要解碼
		var ContactCountry = escape(FormName.ContactCountry.value);　					//中文編碼　　　　接收方要解碼
		var ContactCity = escape(FormName.ContactCity.value);
		var ContactEmail = escape(FormName.ContactEmail.value);　					//中文編碼　　　　接收方要解碼
		var ContactProductsType = escape(FormName.ContactProductsType.value);
		var ContactProductsFormat = escape(FormName.ContactProductsFormat.value);　					//中文編碼　　　　接收方要解碼
		var ContactContent = escape(FormName.ContactContent.value);　					//中文編碼　　　　接收方要解碼
		//var VerificationCode = escape(FormName.userstring.value);
		var time= new Date().getTime();										//因為ajax的時間戳讓每次的網址都不一樣，就會在讀一次xml檔。所以需url+time。
		var PostMain = "ContactLastName="+ContactLastName+"&ContactName="+ContactName+"&ContactCountry="+ContactCountry+"&ContactCity="+ContactCity+"&ContactEmail="+ContactEmail+"&ContactProductsType="+ContactProductsType+"&ContactProductsFormat="+ContactProductsFormat+"&ContactContent="+ContactContent+"&date="+time;
		xmlHttp.open("POST","ajax/InsertContactXML.php",true);											//將值傳進另一個網頁
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", PostMain.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.onreadystatechange = ReturnInsertContact;								//將結果傳回來給function
		xmlHttp.send(PostMain);														//傳post的值需放進send(值)裡
		//FormName.ContactContent.value= PostMain;
		//document.getElementById("loading").style.display="block";
	/*}																					//傳的值跟GET一樣。例：name=Dennis&content=good
	catch(e)																			//如要傳陣列的話。列：name[]=Dennis&name[]=Don這樣的話接收者就可用name[]這個陣列/ 
	{
		alert("Error");
	}*/
}
function ReturnInsertContact()
{
	if(xmlHttp.readyState == 4)						//回傳回來必須這某寫~!??
	{
		if(xmlHttp.status == 200)					////回傳回來必須這某寫~!??
		{
			var XMLhtml = xmlHttp.responseXML;				//回傳的值必須這某寫~!??	將整個網頁放進變數裡
			var XMLAllTag = XMLhtml.documentElement;		//回傳的值必須這某寫~!??	將整個網頁內容放進變數裡
			var ConfirmTag = XMLAllTag.getElementsByTagName("confirm");						//將Tag<name>放進變數
			var ConfirmContent = ConfirmTag.item(0).firstChild.data;
			if(ConfirmContent==0)
			{
				alert("Thank you uery much for  your feedback and We will assit you in this matter very soon !");
				location.replace(location.href);
			}
			/*if(ConfirmContent!=1)
			{	
				if(ConfirmContent == '成功寄信!')
				{
					alert("很感謝你給的意見，我們近期將為你處理");
					var FormName = document.Postform;
					FormName.ContactCategory.options[0].selected=true;
					FormName.ContactName.value = "";
					FormName.ContactPhone.value = "";
					FormName.ContactMPhone.value = "";
					FormName.ContactEmail.value = "";
					FormName.ContactTime[0].checked=true;
					FormName.ContactContent.value = "";
					document.Postform.userstring.value = "";
					document.getElementById("verif").innerHTML="<img src=\"VerificationCode/imagebuilder.php\" border=\"1\">";
				}else
				{
					alert(ConfirmContent);
					document.getElementById("verif").innerHTML="<img src=\"VerificationCode/imagebuilder.php\" border=\"1\">";
					document.Postform.userstring.value = "";
				}
			}
			else
			{
				alert("驗証碼錯誤");
				document.getElementById("verif").innerHTML="<img src=\"VerificationCode/imagebuilder.php\" border=\"1\">";
				document.Postform.userstring.value = "";
			}
			document.getElementById("loading").style.display="none";*/
		}
		else
		{
			alert("There was a problem accessing the server:"+xmlHttp.statusText);
		}
	}
}
//===================================新增會員=============================================
//確認帳號是否有重覆
var account_cfm = 1;   //0=不重覆;1=重覆了
function AccountConfirm()
{
	try
		{
			var account = escape(document.Postform.Account.value);
			if(document.Postform.Account.value=="")
			{
				document.getElementById('AccountConfirm').innerHTML = '<img src="_img/cancel.png" width="16" height="16"><span class="font-style-03">請輸入帳號</span>';
				alert("Please enter the account number");
				return;
			}
			var time= new Date().getTime();		//因為ajax的時間戳讓每次的網址都不一樣，就會在讀一次xml檔。所以需url+time。
			var PostMain="account="+account+"&time="+time;
			xmlHttp.open("POST","ajax/accountConfirmXML.php",false);											//將值傳進另一個網頁
			xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			xmlHttp.setRequestHeader("Content-length", PostMain.length);
			xmlHttp.setRequestHeader("Connection", "close");
			xmlHttp.onreadystatechange = ReturnAccountConfirm;						//將結果傳回來給function
			xmlHttp.send(PostMain);															//傳post的值需放進send(值)裡
		}																					//傳的值跟GET一樣。例：name=Dennis&content=good
		catch(e)																			//如要傳陣列的話。列：name[]=Dennis&name[]=Don這樣的話接收者就可用name[]這個陣列/ 
		{
			alert("Error");
		}
}
function ReturnAccountConfirm()
{
	if(xmlHttp.readyState == 4)						//回傳回來必須這某寫~!??
	{
		if(xmlHttp.status == 200)					////回傳回來必須這某寫~!??
		{
			var XMLhtml = xmlHttp.responseXML;				//回傳的值必須這某寫~!??	將整個網頁放進變數裡
			var XMLAllTag = XMLhtml.documentElement;		//回傳的值必須這某寫~!??	將整個網頁內容放進變數裡
			var confirmTag = XMLAllTag.getElementsByTagName("confirm");						//將Tag<name>放進變數	
			if(confirmTag.item(0).firstChild.data=="Account has been repeated")
			{
				account_cfm = 1;
				document.getElementById('AccountConfirm').innerHTML = '<img src="_img/cancel.png" width="16" height="16"><span class="font-style-03">'+confirmTag.item(0).firstChild.data+'</span>';
			}
			else
			{
				account_cfm = 0;
				document.getElementById('AccountConfirm').innerHTML = '<img src="_img/ok.png" width="16" height="16">';
			}
		}
		else
		{
			alert("There was a problem accessing the server:"+xmlHttp.statusText);
		}
	}
}
//驗証密碼
function checkValidPasswd(str)
{
    /*var reg = /^[x00-x7f]+$/;
    if (! reg.test(str)){
     return '密碼中不可有<>?!@#$%^&*()..';
    }*/
    if (str.length < 6){
     return 'Password length must be greater than 6 characters!';
    }
    return 'OK';
}
//------------新增會員-----------
function InsertMember()
{
		try
		{
			var FormName = document.Postform;
			if(FormName.Account.value=="")
			{alert("Please enter the number");return;}
			
			AccountConfirm();					 //驗証帳號是否重覆
			if(account_cfm==1)
			{alert("This account is already in use");return;}
			
			if(FormName.Pasword.value=="")
			{alert("Please enter the password");return;}
			var password = FormName.Pasword.value;
			var CheckPassword =checkValidPasswd(password)
			if(CheckPassword!='OK')
			{alert(CheckPassword);return;}
			
			if(FormName.CheckPasword.value=="")
			{alert("Please enter the password to confirm");return;}
			var psssword2 = FormName.CheckPasword.value;
			
			if(password!=psssword2)
			{alert("Confirm the password and password information do not match");return;}

			if(FormName.Name.value=="")
			{alert("Please enter a name");return;}
			
			if(FormName.Sex.value=="")
			{alert("Please enter the sex");return;}
			
			if(FormName.Phone.value!="")
			{
				/*var check_ph =CheckPhone(FormName.Phone.value)
				if(check_ph==false)
				{alert("Right format for your phone");return;}*/
			}else
			{alert("Please enter the phone");return;}
			
			if(FormName.Company.value=="")
			{alert("Please enter a company name");return;}
			
			if(FormName.Country.value=="")
			{alert("Please enter the country");return;}
			
			if(FormName.Email.value!="")
			{
				var Check_mail =CheckEmail(FormName.Email.value)
				if(Check_mail==false)
				{alert("Your E-mail format does not");return;}
			}else
			{alert("Please enter E-mail");return;}

			if(FormName.userstring.value=="")
			{alert("Please enter the verification code");return;}
			
			var Account = escape(FormName.Account.value);
			var password = escape(password);
			var Name = escape(FormName.Name.value);
			var Sex = escape(FormName.Sex.value);
			var Phone = escape(FormName.Phone.value);
			var Fax = escape(FormName.Fax.value);
			var Company = escape(FormName.Company.value);
			var CompanyType = escape(FormName.CompanyType.value);
			var Responsible = escape(FormName.Responsible.value);
			var Liaison = escape(FormName.Liaison.value);
			var EmployeesNum = escape(FormName.EmployeesNum.value);
			var Country = escape(FormName.Country.value);
			var City = escape(FormName.City.value);
			var Email = escape(FormName.Email.value);
			var VerificationCode = escape(FormName.userstring.value);

			var time= new Date().getTime();										//因為ajax的時間戳讓每次的網址都不一樣，就會在讀一次xml檔。所以需url+time。
			var PostMain = "Account="+Account+"&password="+password+"&Name="+Name+
							"&Sex="+Sex+"&Phone="+Phone+"&Fax="+Fax+"&Company="+Company+
							"&CompanyType="+CompanyType+"&Responsible="+Responsible+"&Liaison="+Liaison+"&EmployeesNum="+EmployeesNum+
							"&Country="+Country+"&City="+City+"&Email="+Email+"&VerificationCode="+VerificationCode+"&date="+time;
			xmlHttp.open("POST","ajax/joinMemberXML.php",true);											//將值傳進另一個網頁
			xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			xmlHttp.setRequestHeader("Content-length", PostMain.length);
			xmlHttp.setRequestHeader("Connection", "close");
			xmlHttp.onreadystatechange = ReturnInsertMember;								//將結果傳回來給function
			xmlHttp.send(PostMain);												//傳post的值需放進send(值)裡
			document.getElementById("loading").style.display="block";
		}																					//傳的值跟GET一樣。例：name=Dennis&content=good
		catch(e)																			//如要傳陣列的話。列：name[]=Dennis&name[]=Don這樣的話接收者就可用name[]這個陣列/ 
		{
			alert("Error");
		}
}
function ReturnInsertMember()
{
	if(xmlHttp.readyState == 4)						//回傳回來必須這某寫~!??
	{
		if(xmlHttp.status == 200)					////回傳回來必須這某寫~!??
		{
			var XMLhtml = xmlHttp.responseXML;				//回傳的值必須這某寫~!??	將整個網頁放進變數裡
			var XMLAllTag = XMLhtml.documentElement;		//回傳的值必須這某寫~!??	將整個網頁內容放進變數裡
			var ConfirmTag = XMLAllTag.getElementsByTagName("confirm");						//將Tag<name>放進變數
			if(ConfirmTag.item(0).firstChild.data==0)
			{
				alert("Thank you for your registration !");
				location.replace('Complete.php');
			}
			else
			{
				alert("Verification code error");
				document.getElementById("verif").innerHTML="<img src=\"VerificationCode/imagebuilder.php\" border=\"1\">";
				document.Postform.Pasword.value = "";
				document.Postform.CheckPasword.value = "";
				document.Postform.userstring.value = "";
				document.getElementById("loading").style.display="none";
			}
			
		}
		else
		{
			alert("There was a problem accessing the server:"+xmlHttp.statusText);
		}
	}
}
//------------------------------------------------
//---------------------修改會員-------------------
function UpdateMember()
{
		try
		{
			var FormName = document.Postform;
			if(FormName.Name.value=="")
			{alert("Please enter a name");return;}
			
			if(FormName.Sex.value=="")
			{alert("Please enter the sex");return;}
			
			if(FormName.Phone.value!="")
			{
				var check_ph =CheckPhone(FormName.Phone.value)
				if(check_ph==false)
				{alert("Right format for your phone");return;}
			}else
			{alert("Please enter the phone");return;}
			
			if(FormName.Company.value=="")
			{alert("Please enter a Company Organization");return;}
			
			if(FormName.Country.value=="")
			{alert("Please enter the country");return;}
			
			if(FormName.Email.value!="")
			{
				var Check_mail =CheckEmail(FormName.Email.value)
				if(Check_mail==false)
				{alert("Your E-mail format does not!");return;}
			}else
			{alert("Please enter E-mail");return;}

			
			var Name = escape(FormName.Name.value);
			var Sex = escape(FormName.Sex.value);
			var Phone = escape(FormName.Phone.value);
			var Fax = escape(FormName.Fax.value);
			var Company = escape(FormName.Company.value);
			var CompanyType = escape(FormName.CompanyType.value);
			var Responsible = escape(FormName.Responsible.value);
			var Liaison = escape(FormName.Liaison.value);
			var EmployeesNum = escape(FormName.EmployeesNum.value);
			var Country = escape(FormName.Country.value);
			var City = escape(FormName.City.value);
			var Email = escape(FormName.Email.value);

			var time= new Date().getTime();										//因為ajax的時間戳讓每次的網址都不一樣，就會在讀一次xml檔。所以需url+time。
			var PostMain = "Name="+Name+
							"&Sex="+Sex+"&Phone="+Phone+"&Fax="+Fax+"&Company="+Company+
							"&CompanyType="+CompanyType+"&Responsible="+Responsible+"&Liaison="+Liaison+"&EmployeesNum="+EmployeesNum+
							"&Country="+Country+"&City="+City+"&Email="+Email+"&date="+time;
			xmlHttp.open("POST","ajax/UpdateMember.php",false);											//將值傳進另一個網頁
			xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			xmlHttp.setRequestHeader("Content-length", PostMain.length);
			xmlHttp.setRequestHeader("Connection", "close");
			xmlHttp.onreadystatechange = ReturnNothing;								//將結果傳回來給function
			xmlHttp.send(PostMain);												//傳post的值需放進send(值)裡
			location.replace(location.href);
		}																					//傳的值跟GET一樣。例：name=Dennis&content=good
		catch(e)																			//如要傳陣列的話。列：name[]=Dennis&name[]=Don這樣的話接收者就可用name[]這個陣列/ 
		{
			alert("Error");
		}
}
//-----------------修改密碼-----------------------
function UpdatePassword()
{
		try
		{
			var FormName = document.Postform;
			
			if(FormName.Pasword.value=="")
			{alert("Please enter Previous Password");return;}
			var old_password = FormName.Pasword.value;
			
			if(FormName.NewPasword.value=="")
			{alert("Please enter New Password");return;}
			var password = FormName.NewPasword.value;
			var CheckPassword =checkValidPasswd(password)
			if(CheckPassword!='OK')
			{alert(CheckPassword);return;}
			
			if(FormName.ChkPasword.value=="")
			{alert("Please enter Confirm Password");return;}
			var psssword2 = FormName.ChkPasword.value;
			
			if(password!=psssword2)
			{alert("New Password and Confirm New Password information does not match");return;}
			
			var time= new Date().getTime();		//因為ajax的時間戳讓每次的網址都不一樣，就會在讀一次xml檔。所以需url+time。
			//name,account,password,sex,born_date,phone,phone2,address,email,paper
			var PostMain="old_password="+old_password+"&password="+password+"&time="+time;
			//var name = escape(document.Postform.name.value);　					//中文編碼　　　　接收方要解碼
			xmlHttp.open("POST","ajax/updatepasXML.php",true);											//將值傳進另一個網頁
			xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			xmlHttp.setRequestHeader("Content-length", PostMain.length);
			xmlHttp.setRequestHeader("Connection", "close");
			xmlHttp.onreadystatechange = ReturnUpdatePassword;								//將結果傳回來給function
			xmlHttp.send(PostMain);		
																				//傳post的值需放進send(值)裡
		}																					//傳的值跟GET一樣。例：name=Dennis&content=good
		catch(e)																			//如要傳陣列的話。列：name[]=Dennis&name[]=Don這樣的話接收者就可用name[]這個陣列/ 
		{
			alert("Error");
		}
	
}
function ReturnUpdatePassword()
{
	if(xmlHttp.readyState == 4)						//回傳回來必須這某寫~!??
	{
		if(xmlHttp.status == 200)					////回傳回來必須這某寫~!??
		{
			var XMLhtml = xmlHttp.responseXML;				//回傳的值必須這某寫~!??	將整個網頁放進變數裡
			var XMLAllTag = XMLhtml.documentElement;		//回傳的值必須這某寫~!??	將整個網頁內容放進變數裡
			var confirmTag = XMLAllTag.getElementsByTagName("pas");
			if(confirmTag.item(0).firstChild.data=="Successfully modified")
			{
				alert(confirmTag.item(0).firstChild.data);
				window.location='account.php';
			}
			else
			{
				alert(confirmTag.item(0).firstChild.data);
				document.Postform.Pasword.value = "";
				document.Postform.NewPasword.value = "";
				document.Postform.ChkPasword.value = "";
			}
			
		}
		else
		{
			alert("There was a problem accessing the server:"+xmlHttp.statusText);
		}
	}
}
//------------------------------------------------
//-------------------登入帳密確認-----------------
function AccountPasswordConfirm()
{
	try
		{
			var ConfirmAcc=document.getElementById("LogInAccount").value;
			if(ConfirmAcc=="")
			{alert("Please enter the account");return;}
			var ConfirmPas=document.getElementById("LogInPasswrod").value;
			if(ConfirmPas=="")
			{alert("Please enter the password");return;}

			ConfirmAcc = escape(ConfirmAcc);　	
			ConfirmPas = escape(ConfirmPas);　
			var time= new Date().getTime();													//因為ajax的時間戳讓每次的網址都不一樣，就會在讀一次xml檔。所以需url+time。
			var PostMain="account="+ConfirmAcc+"&password="+ConfirmPas+"&time="+time;
			//alert(PostMain);
			xmlHttp.open("POST","ajax/loginXML.php",true);											//將值傳進另一個網頁
			xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			xmlHttp.setRequestHeader("Content-length", PostMain.length);
			xmlHttp.setRequestHeader("Connection", "close");
			xmlHttp.onreadystatechange = ReturnAccountPasswordConfirm;						//將結果傳回來給function
			xmlHttp.send(PostMain);															//傳post的值需放進send(值)裡
		}																					//傳的值跟GET一樣。例：name=Dennis&content=good
		catch(e)																			//如要傳陣列的話。列：name[]=Dennis&name[]=Don這樣的話接收者就可用name[]這個陣列/ 
		{
			alert("Error");
		}
}
function ReturnAccountPasswordConfirm()
{
	if(xmlHttp.readyState == 4)						//回傳回來必須這某寫~!??
	{
		if(xmlHttp.status == 200)					////回傳回來必須這某寫~!??
		{
			var XMLhtml = xmlHttp.responseXML;				//回傳的值必須這某寫~!??	將整個網頁放進變數裡
			var XMLAllTag = XMLhtml.documentElement;		//回傳的值必須這某寫~!??	將整個網頁內容放進變數裡
			var confirmTag = XMLAllTag.getElementsByTagName("confirm");						//將Tag<name>放進變數
			if(confirmTag.item(0).firstChild.data=='OK')
			{location.replace('account.php');}
			else
			{
				document.getElementById("login_content").innerHTML = '<span style="color: #F00;font-size:11px;"><strong>'+confirmTag.item(0).firstChild.data+'</strong></span>';
				document.getElementById("LogInPasswrod").value ="";
			}
		}
		else
		{
			//alert("There was a problem accessing the server:"+xmlHttp.statusText);
		}
	}
}
//-------------------登入帳密確認-----------------
function AccountPassword()
{
	try
		{
			var ConfirmAcc=document.getElementById("LogInAccount").value;
			if(ConfirmAcc=="")
			{alert("Please enter the account");return;}
			var ConfirmPas=document.getElementById("LogInPasswrod").value;
			if(ConfirmPas=="")
			{alert("Please enter the password");return;}

			ConfirmAcc = escape(ConfirmAcc);　	
			ConfirmPas = escape(ConfirmPas);　
			var time= new Date().getTime();													//因為ajax的時間戳讓每次的網址都不一樣，就會在讀一次xml檔。所以需url+time。
			var PostMain="account="+ConfirmAcc+"&password="+ConfirmPas+"&time="+time;
			//alert(PostMain);
			xmlHttp.open("POST","ajax/loginXML.php",true);											//將值傳進另一個網頁
			xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			xmlHttp.setRequestHeader("Content-length", PostMain.length);
			xmlHttp.setRequestHeader("Connection", "close");
			xmlHttp.onreadystatechange = ReturnAccountPassword;						//將結果傳回來給function
			xmlHttp.send(PostMain);															//傳post的值需放進send(值)裡
		}																					//傳的值跟GET一樣。例：name=Dennis&content=good
		catch(e)																			//如要傳陣列的話。列：name[]=Dennis&name[]=Don這樣的話接收者就可用name[]這個陣列/ 
		{
			alert("Error");
		}
}
function ReturnAccountPassword()
{
	if(xmlHttp.readyState == 4)						//回傳回來必須這某寫~!??
	{
		if(xmlHttp.status == 200)					////回傳回來必須這某寫~!??
		{
			var XMLhtml = xmlHttp.responseXML;				//回傳的值必須這某寫~!??	將整個網頁放進變數裡
			var XMLAllTag = XMLhtml.documentElement;		//回傳的值必須這某寫~!??	將整個網頁內容放進變數裡
			var confirmTag = XMLAllTag.getElementsByTagName("confirm");						//將Tag<name>放進變數
			if(confirmTag.item(0).firstChild.data=='OK')
			{location.replace(location.href);}
			else
			{
				alert(confirmTag.item(0).firstChild.data);
				document.getElementById("LogInPasswrod").value ="";
			}
		}
		else
		{
			//alert("There was a problem accessing the server:"+xmlHttp.statusText);
		}
	}
}
//-------------------登出-----------------
function logout()
{
	try
		{
			var PostMain = "logout=logout";
			xmlHttp.open("POST","ajax/loginXML.php",false);											//將值傳進另一個網頁
			xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			xmlHttp.setRequestHeader("Content-length", PostMain.length);
			xmlHttp.setRequestHeader("Connection", "close");
			xmlHttp.onreadystatechange = ReturnNothing;						//將結果傳回來給function
			xmlHttp.send(PostMain);															//傳post的值需放進send(值)裡
			location.replace(location.href);
		}																					//傳的值跟GET一樣。例：name=Dennis&content=good
		catch(e)																			//如要傳陣列的話。列：name[]=Dennis&name[]=Don這樣的話接收者就可用name[]這個陣列/ 
		{
			alert("Error");
		}
}
//-----------------最新消息列表----------------------
function SelectNewsList(Page)
{
	try
		{
			var NewYear = document.getElementById("NewsYear").value;
			var time= new Date().getTime();		//因為ajax的時間戳讓每次的網址都不一樣，就會在讀一次xml檔。所以需url+time。
			var PostMain="NewYear="+NewYear+"&Page="+Page+"&time="+time;
			xmlHttp.open("POST","ajax/SelectNewsList.php",false);											//將值傳進另一個網頁
			xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			xmlHttp.setRequestHeader("Content-length", PostMain.length);
			xmlHttp.setRequestHeader("Connection", "close");
			xmlHttp.onreadystatechange = ReturnSelectProductsList;						//將結果傳回來給function
			xmlHttp.send(PostMain);															//傳post的值需放進send(值)裡
			
		}																					//傳的值跟GET一樣。例：name=Dennis&content=good
		catch(e)																			//如要傳陣列的話。列：name[]=Dennis&name[]=Don這樣的話接收者就可用name[]這個陣列/ 
		{
			alert("Error");
		}
}
function ReturnSelectProductsList()
{
	if(xmlHttp.readyState == 4)						//回傳回來必須這某寫~!??
	{
		if(xmlHttp.status == 200)					////回傳回來必須這某寫~!??
		{
			var XMLhtml = xmlHttp.responseText;				//將整個網頁(xml)放進變數裡
			document.getElementById("NewsContent").innerHTML = XMLhtml;
		}
	}
}
//-----------------忘了密碼-----------------------
function ForgotPasswordEmail()
{
	try
		{
			
			if(document.Postform.Account.value=="")
			{alert("Please enter the account number");return;}
			if(document.Postform.Email.value=="")
			{alert("Please enter the Email");return;}
			var account = escape(document.Postform.Account.value);	
			var Email = escape(document.Postform.Email.value);				
			var time= new Date().getTime();
			var PostMain="account="+account+"&Email="+Email+"&time="+time;
			
			xmlHttp.open("POST","ajax/PasswordEmailXML.php",true);
			xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			xmlHttp.setRequestHeader("Content-length", PostMain.length);
			xmlHttp.setRequestHeader("Connection", "close");
			xmlHttp.onreadystatechange = ReturnForgotPasswordEmail;
			xmlHttp.send(PostMain);
			document.getElementById("loading").style.display="block";
		}
		catch(e)
		{
			alert("Error");
		}
}
function ReturnForgotPasswordEmail()
{
	if(xmlHttp.readyState == 4)						//回傳回來必須這某寫~!??
	{
		if(xmlHttp.status == 200)					////回傳回來必須這某寫~!??
		{
			var XMLhtml = xmlHttp.responseXML;				//回傳的值必須這某寫~!??	將整個網頁放進變數裡
			var XMLAllTag = XMLhtml.documentElement;		//回傳的值必須這某寫~!??	將整個網頁內容放進變數裡
			var confirmTag = XMLAllTag.getElementsByTagName("confirm");						//將Tag<name>放進變數
			if(confirmTag.item(0).firstChild.data=="OK")
			{
				alert('Go to your mailbox Request new password!');
				window.location='Login.php';
				
			}else
			{
				document.Postform.Account.value="";
				document.Postform.Email.value="";
				alert(confirmTag.item(0).firstChild.data);
			}
			document.getElementById("loading").style.display="none";
		}
		else
		{
			alert("There was a problem accessing the server:"+xmlHttp.statusText);
		}
	}
}
//------------------------------------------------
function SelectKeyWord()
{
	var KeyWord = document.getElementById("KeyWord").value;
	location.href='products.php?KeyWord='+KeyWord;
}
//---------------聯絡我們國家城市-----------------
function ChangeCountry(CountryID)
{
	try
	{	
		var time= new Date().getTime();
		
		var PostMain="CountryID="+CountryID+"&time="+time;
		xmlHttp.open("POST","ajax/ChangeCountryXML.php",true);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", PostMain.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.onreadystatechange = ReturnChangeCountry;
		xmlHttp.send(PostMain);
	}
	catch(e)
	{
		alert("Error");
	}
}
function ReturnChangeCountry()
{
	if(xmlHttp.readyState == 4)						//回傳回來必須這某寫~!??
	{
		if(xmlHttp.status == 200)					////回傳回來必須這某寫~!??
		{
			var XMLhtml = xmlHttp.responseXML;				//回傳的值必須這某寫~!??	將整個網頁放進變數裡
			var XMLAllTag = XMLhtml.documentElement;		//回傳的值必須這某寫~!??	將整個網頁內容放進變數裡
			var NumberTag = XMLAllTag.getElementsByTagName("Number");						//將Tag<name>放進變數	
			var Number = parseInt(NumberTag.item(0).firstChild.data);
			if(Number!=0)
			{
				var CityNameTag = XMLAllTag.getElementsByTagName("CityName");
				var selectpage = '<select name="ContactCity" id="ContactCity" style="width:110px" >';
				for(var i=0;i<Number;i++)
				{
					var CityName=CityNameTag.item(i).firstChild.data;
					selectpage += '<option value="'+CityName+'">'+CityName+'</option>';
				}
				document.getElementById("CityDiv").innerHTML = selectpage + '</select>';
			}else
			{
				var selectpage = '<select name="ContactCity" id="ContactCity" style="width:110px" >';
				document.getElementById("CityDiv").innerHTML = selectpage + '</select>';
			}
		}
		else
		{
			alert("There was a problem accessing the server:"+xmlHttp.statusText);
		}
	}
}
//---------------聯絡我們產品類別、規格-----------------
function ChangeCProducts(CProID)
{
	try
	{	
		var time= new Date().getTime();
		
		var PostMain="CProID="+CProID+"&time="+time;
		xmlHttp.open("POST","ajax/ChangeCProductsXML.php",true);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", PostMain.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.onreadystatechange = ReturnChangeCProducts;
		xmlHttp.send(PostMain);
	}
	catch(e)
	{
		alert("Error");
	}
}
function ReturnChangeCProducts()
{
	if(xmlHttp.readyState == 4)						//回傳回來必須這某寫~!??
	{
		if(xmlHttp.status == 200)					////回傳回來必須這某寫~!??
		{
			var XMLhtml = xmlHttp.responseXML;				//回傳的值必須這某寫~!??	將整個網頁放進變數裡
			var XMLAllTag = XMLhtml.documentElement;		//回傳的值必須這某寫~!??	將整個網頁內容放進變數裡
			var NumberTag = XMLAllTag.getElementsByTagName("Number");						//將Tag<name>放進變數	
			var Number = parseInt(NumberTag.item(0).firstChild.data);
			if(Number!=0)
			{
				var NameTag = XMLAllTag.getElementsByTagName("Name");
				var selectpage = '<select name="ContactProductsFormat" id="ContactProductsFormat" style="width:230px" >';
				for(var i=0;i<Number;i++)
				{
					var Name=NameTag.item(i).firstChild.data;
					selectpage += '<option value="'+Name+'">'+Name+'</option>';
				}
				document.getElementById("ProductsFormatDiv").innerHTML = selectpage + '</select>';
			}else
			{
				var selectpage = '<select name="ContactProductsFormat" id="ContactProductsFormat" style="width:230px" >';
				document.getElementById("ProductsFormatDiv").innerHTML = selectpage + '</select>';
			}
		}
		else
		{
			alert("There was a problem accessing the server:"+xmlHttp.statusText);
		}
	}
}
