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 heartBeat()
{ 
	var diffY;
	if (document.documentElement && document.documentElement.scrollTop)
		diffY = document.documentElement.scrollTop;
	else if (document.body)
		diffY = document.body.scrollTop
	else
		{	
			//Netscape stuff
		}
		
	//alert(diffY);
	var percent=1*(diffY-lastScrollY); 
	if(percent>0)percent=Math.ceil(percent); 
	else percent=Math.floor(percent); 
	document.getElementById("RightCar").style.top=parseInt(document.getElementById("RightCar").style.top)+percent+"px";
	lastScrollY=lastScrollY+percent; 
	//alert(lastScrollY);
}
//-------------------確認數字鍵-----------------
function fild_valid(number)
{
	var re = /^\d+$/;
　	if (number!="" && !re.test(number)) 
	{
　　	return false;
　	}else 
	{
　　	return true;
　	}
}
//=============檢查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======
function ReturnNothing()
{
	if(xmlHttp.readyState == 4)						//回傳回來必須這某寫~!??
	{
		if(xmlHttp.status == 200)					////回傳回來必須這某寫~!??
		{
			//為了把下面錯誤用不見
		}
		else
		{
			alert("There was a problem accessing the server:"+xmlHttp.statusText);
		}
	}
}
//-------------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);
}
//===================================聯絡我們=============================================
function InsertContact()
{
		try
		{
			var FormName = document.Postform;
			if(FormName.ContactName.value=="")
			{alert("請輸入姓名");return;}
			if(FormName.ContactEmail.value!="")
			{
				var Check_mail =CheckEmail(FormName.ContactEmail.value)   //驗証Email
				if(Check_mail==false)
				{alert("您的E-mail格式不對");return;}
			}else
			{alert("請輸入E-mail");return;}
		
			if(FormName.ContactContent.value=="")
			{alert("請輸入內容");return;}
		
			if(	FormName.userstring.value=="")
			{alert("請輸入驗証碼");return;}
			
			
			var name = escape(FormName.ContactName.value);
			var email = escape(FormName.ContactEmail.value);
			var content = escape(FormName.ContactContent.value);
			var VerificationCode = escape(FormName.userstring.value);
			var time= new Date().getTime();										//因為ajax的時間戳讓每次的網址都不一樣，就會在讀一次xml檔。所以需url+time。
			var PostMain = "name="+name+"&email="+email+"&content="+content+"&VerificationCode="+VerificationCode+"&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(值)裡
		}																					//傳的值跟GET一樣。例：name=Dennis&content=good
		catch(e)																			//如要傳陣列的話。列：name[]=Dennis&name[]=Don這樣的話接收者就可用name[]這個陣列/ 
		{
			alert("錯誤喔");
		}
}
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>放進變數
			if(ConfirmTag.item(0).firstChild.data==0)
			{	
				alert("很感謝你給的意見，我們近期將為你處理");
				location.replace(location.href);
			}
			else
			{
				alert("驗証碼錯誤");
				document.getElementById("verif").innerHTML="<img src=\"VerificationCode/imagebuilder.php\" border=\"1\">";
				document.Postform.userstring.value = "";
			}
		
		}
		else
		{
			alert("There was a problem accessing the server:"+xmlHttp.statusText);
		}
	}
}
//------------------------------------------------
//-------------------登入帳密確認-----------------
function AccountPasswordConfirm()
{
	try
		{
			var ConfirmAcc=document.getElementById("login_account").value;
			if(ConfirmAcc=="")
			{alert("請輸入帳號");return;}
			var ConfirmPas=document.getElementById("login_password").value;
			if(ConfirmPas=="")
			{alert("請輸入密碼");return;}
			
			ConfirmAcc = escape(ConfirmAcc);　	
			ConfirmPas = escape(ConfirmPas);　	
			var time= new Date().getTime();													//因為ajax的時間戳讓每次的網址都不一樣，就會在讀一次xml檔。所以需url+time。
			var PostMain="account="+ConfirmAcc+"&password="+ConfirmPas+"&time="+time;
			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("錯誤喔");
		}
}
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=="confirm")
			{location.replace(location.href);}
			else
			{document.getElementById("login_content").innerHTML = '<span style="color: #53E1E3;"><strong>帳號密碼錯誤喔!!</strong></span>'};
		}
		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("錯誤喔");
		}
}
//===================================新增會員=============================================
//確認帳號是否有重覆
var account_cfm = 1;   //0=不重覆;1=重覆了
function AccountConfirm()
{
	try
		{
			var account = escape(document.Postform.MemberAccount.value);　	
			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("錯誤喔");
		}
}
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_cfm = 1;
			}
			else
			{
				account_cfm = 0;
			}
		}
		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 '密碼不可小於6碼';
    }
    return 'OK';
}
//------------新增會員-----------
function InsertMember()
{
		try
		{
			var FormName = document.Postform;
			if(FormName.MemberName.value=="")
			{alert("請輸入會員名稱/公司名稱");return;}
			
			if(FormName.MemberAccount.value=="")
			{alert("請輸入帳號");return;}
			
			AccountConfirm();					 //驗証帳號是否重覆
			if(account_cfm==1)
			{alert("此帳號已有人使用");return;}
			
			if(FormName.MemberPassword.value=="")
			{alert("請輸入密碼");return;}
			var password = FormName.MemberPassword.value;
			var CheckPassword =checkValidPasswd(password)
			if(CheckPassword!='OK')
			{alert(CheckPassword);return;}
			
			if(FormName.MemberPassword2.value=="")
			{alert("請輸入確認密碼");return;}
			var psssword2 = FormName.MemberPassword2.value;
			
			if(password!=psssword2)
			{alert("確認密碼和密碼資料不符");return;}
			
			
			if(FormName.MemberEmail.value!="")
			{
				var Check_mail =CheckEmail(FormName.MemberEmail.value)
				if(Check_mail==false)
				{alert("您的E-mail格式不對");return;}
			}else
			{alert("請輸入E-mail");return;}
			
			if(FormName.MemberPhone.value!="")
			{
				var check_ph =CheckPhone(FormName.MemberPhone.value)
				if(check_ph==false)
				{alert("您的連絡電話格式不對");return;}
			}else
			{alert("請輸入連絡電話");return;}
			
			if(FormName.MemberMPhone2.value!="")
			{
				var check_ph =CheckPhone(FormName.MemberMPhone2.value)
				if(check_ph==false)
				{alert("您的手機格式不對");return;}
			}else
			{alert("請輸入手機");return;}
			
			if(FormName.MemberAddress.value=="")
			{alert("請輸入地址");return;}
		
			if(FormName.userstring.value=="")
			{alert("請輸入驗証碼");return;}
			
			
			var MemberName = escape(FormName.MemberName.value);
			var MemberAccount = escape(FormName.MemberAccount.value);
			var MemberPassword = escape(FormName.MemberPassword.value);
			var MemberEmail = escape(FormName.MemberEmail.value);
			var MemberPhone = escape(FormName.MemberPhone.value);
			var MemberMPhone2 = escape(FormName.MemberMPhone2.value);
			var MemberAddress = escape(FormName.MemberAddress.value);
			var MemberSex = escape(FormName.MemberSex.value);
			var VerificationCode = escape(FormName.userstring.value);
			var time= new Date().getTime();										//因為ajax的時間戳讓每次的網址都不一樣，就會在讀一次xml檔。所以需url+time。
			var PostMain = "MemberName="+MemberName+"&MemberAccount="+MemberAccount+"&MemberPassword="+MemberPassword+
							"&MemberEmail="+MemberEmail+"&MemberPhone="+MemberPhone+
							"&MemberMPhone2="+MemberMPhone2+"&MemberAddress="+MemberAddress+
							"&MemberSex="+MemberSex+"&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(值)裡
		}																					//傳的值跟GET一樣。例：name=Dennis&content=good
		catch(e)																			//如要傳陣列的話。列：name[]=Dennis&name[]=Don這樣的話接收者就可用name[]這個陣列/ 
		{
			alert("錯誤喔");
		}
}
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("很感謝你加入會員");
				location.replace('Member_Information.php');
			}
			else
			{
				alert("驗証碼錯誤");
				document.getElementById("verif").innerHTML="<img src=\"VerificationCode/imagebuilder.php\" border=\"1\">";
				document.Postform.userstring.value = "";
			}
			
		}
		else
		{
			alert("There was a problem accessing the server:"+xmlHttp.statusText);
		}
	}
}
//------------------------------------------------
function UpdateMember()
{
		try
		{
			var FormName = document.Postform;
			if(FormName.MemberName.value=="")
			{alert("請輸入會員名稱");return;}
			
			
			if(FormName.MemberEmail.value!="")
			{
				var Check_mail =CheckEmail(FormName.MemberEmail.value)
				if(Check_mail==false)
				{alert("您的E-mail格式不對");return;}
			}else
			{alert("請輸入E-mail");return;}
			
			if(FormName.MemberPhone.value!="")
			{
				var check_ph =CheckPhone(FormName.MemberPhone.value)
				if(check_ph==false)
				{alert("您的連絡電話格式不對");return;}
			}else
			{alert("請輸入連絡電話");return;}
			
			if(FormName.MemberMPhone2.value!="")
			{
				var check_ph =CheckPhone(FormName.MemberMPhone2.value)
				if(check_ph==false)
				{alert("您的手機格式不對");return;}
			}else
			{alert("請輸入手機");return;}
			
			if(FormName.MemberAddress.value=="")
			{alert("請輸入地址");return;}
			
			var MemberName = escape(FormName.MemberName.value);
			var MemberEmail = escape(FormName.MemberEmail.value);
			var MemberPhone = escape(FormName.MemberPhone.value);
			var MemberMPhone2 = escape(FormName.MemberMPhone2.value);
			var MemberAddress = escape(FormName.MemberAddress.value);
			var MemberSex = escape(FormName.MemberSex.value);
			var time= new Date().getTime();										//因為ajax的時間戳讓每次的網址都不一樣，就會在讀一次xml檔。所以需url+time。
			var PostMain = "MemberName="+MemberName+"&MemberEmail="+MemberEmail+"&MemberPhone="+MemberPhone+
							"&MemberMPhone2="+MemberMPhone2+"&MemberAddress="+MemberAddress+
							"&MemberSex="+MemberSex+"&date="+time;
			xmlHttp.open("POST","ajax/UpdateMemberXML.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("錯誤喔");
		}
}
//-----------------修改密碼-----------------------
function UpdatePassword()
{
		try
		{
			var FormName = document.Postform;
			
			if(FormName.MemberPassword.value=="")
			{alert("請輸入密碼");return;}
			var old_password = FormName.MemberPassword.value;
			
			if(FormName.MemberNewPassword.value=="")
			{alert("請輸入新密碼");return;}
			var password = FormName.MemberNewPassword.value;
	
			if(FormName.MemberNewPassword2.value=="")
			{alert("請輸入確認新密碼");return;}
			var psssword2 = FormName.MemberNewPassword2.value;
			
			if(password!=psssword2)
			{alert("新密碼和確認新密碼資料不符");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("錯誤喔");
		}
	
}
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=="修改成功")
			{
				alert(confirmTag.item(0).firstChild.data);
				window.location='Member_Information.php';
			}
			else
			{
				alert(confirmTag.item(0).firstChild.data);
				document.Postform.MemberPassword.value = "";
				document.Postform.MemberNewPassword.value = "";
				document.Postform.MemberNewPassword2.value = "";
			}
			
		}
		else
		{
			alert("There was a problem accessing the server:"+xmlHttp.statusText);
		}
	}
}
//------------------------------------------------
//=======用會員頁登入的=====
function MemberLoginConfirm()
{
	try
		{
			var ConfirmAcc=document.Postform.MemberAccount.value;
			if(ConfirmAcc=="")
			{alert("請輸入帳號");return;}
			var ConfirmPas=document.Postform.MemberPassword.value;
			if(ConfirmPas=="")
			{alert("請輸入密碼");return;}
			
			ConfirmAcc = escape(ConfirmAcc);　	
			ConfirmPas = escape(ConfirmPas);　	
			var time= new Date().getTime();													//因為ajax的時間戳讓每次的網址都不一樣，就會在讀一次xml檔。所以需url+time。
			var PostMain="account="+ConfirmAcc+"&password="+ConfirmPas+"&time="+time;
			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 = ReturnMemberLoginConfirm;						//將結果傳回來給function
			xmlHttp.send(PostMain);															//傳post的值需放進send(值)裡
		}																					//傳的值跟GET一樣。例：name=Dennis&content=good
		catch(e)																			//如要傳陣列的話。列：name[]=Dennis&name[]=Don這樣的話接收者就可用name[]這個陣列/ 
		{
			alert("錯誤喔");
		}
}
function ReturnMemberLoginConfirm()
{
	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=="confirm")
			{
				location.replace(location.href);
			}
			else
			{
				document.Postform.MemberAccount.value='';
				document.Postform.MemberPassword.value='';
				document.getElementById("user_div").innerHTML = '<strong>帳號密碼錯誤喔!!</strong>';
			}
		}
		else
		{
			alert("There was a problem accessing the server:"+xmlHttp.statusText);
		}
	}
}
//------------------------------------------------
//===================================線上叫修=============================================
function InsertRepair()
{
		try
		{
			var FormName = document.Postform;
			if(FormName.RepairName.value=="")
			{alert("請輸入申請人");return;}
			
			if(FormName.RepairPhone.value!="")
			{
				var check_ph =CheckPhone(FormName.RepairPhone.value)
				if(check_ph==false)
				{alert("您的連絡電話格式不對");return;}
			}else
			{alert("請輸入連絡電話");return;}
			
			if(FormName.RepairPhone2.value!="")
			{
				var check_ph =CheckPhone(FormName.RepairPhone2.value)
				if(check_ph==false)
				{alert("您的手機格式不對");return;}
			}else
			{alert("請輸入手機");return;}
			
			if(FormName.RepairAddress.value=="")
			{alert("請輸入地址");return;}
			
			if(FormName.RepairEmail.value!="")
			{
				var Check_mail =CheckEmail(FormName.RepairEmail.value)   //驗証Email
				if(Check_mail==false)
				{alert("您的E-mail格式不對");return;}
			}else
			{alert("請輸入E-mail");return;}
			
			
			if(FormName.RepairModel.value=="")
			{alert("請輸入維修物品機型");return;}
		
			if(FormName.RepairCauses.value=="")
			{alert("請輸入送修原因");return;}
		
			var Name = escape(FormName.RepairName.value);
			var Phone = escape(FormName.RepairPhone.value);
			var Phone2 = escape(FormName.RepairPhone2.value);
			var Address = escape(FormName.RepairAddress.value);
			var Email = escape(FormName.RepairEmail.value);
			var Type = escape(FormName.RepairType.value);
			var Model = escape(FormName.RepairModel.value);
			var Code = escape(FormName.RepairCode.value);
			var Causes = escape(FormName.RepairCauses.value);
			var Remarks = escape(FormName.RepairRemarks.value);
			var time= new Date().getTime();										//因為ajax的時間戳讓每次的網址都不一樣，就會在讀一次xml檔。所以需url+time。
			var PostMain = "Name="+Name+"&Phone="+Phone+"&Phone2="+Phone2+"&Address="+Address+
							"&Email="+Email+"&Type="+Type+"&Model="+Model+
							"&Code="+Code+"&Causes="+Causes+"&Remarks="+Remarks+"&date="+time;
			xmlHttp.open("POST","ajax/InsertRepairXML.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(值)裡
			alert("我們會儘快跟您聯絡");
			location.replace(location.href);
		}																					//傳的值跟GET一樣。例：name=Dennis&content=good
		catch(e)																			//如要傳陣列的話。列：name[]=Dennis&name[]=Don這樣的話接收者就可用name[]這個陣列/ 
		{
			alert("錯誤喔");
		}
}
//------------------------------------------------
//===================================載入會員資料=============================================
function LoadMembers()
{
	try
		{
			var time= new Date().getTime();		//因為ajax的時間戳讓每次的網址都不一樣，就會在讀一次xml檔。所以需url+time。
			var PostMain="time="+time;
			xmlHttp.open("POST","ajax/LoadMembersXML.php",true);											//將值傳進另一個網頁
			xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			xmlHttp.setRequestHeader("Content-length", PostMain.length);
			xmlHttp.setRequestHeader("Connection", "close");
			xmlHttp.onreadystatechange = ReturnLoadMembers;						//將結果傳回來給function
			xmlHttp.send(PostMain);															//傳post的值需放進send(值)裡
		}																					//傳的值跟GET一樣。例：name=Dennis&content=good
		catch(e)																			//如要傳陣列的話。列：name[]=Dennis&name[]=Don這樣的話接收者就可用name[]這個陣列/ 
		{
			alert("錯誤喔");
		}
}
function ReturnLoadMembers()
{
	if(xmlHttp.readyState == 4)
	{
		if(xmlHttp.status == 200)
		{
			var XMLhtml = xmlHttp.responseXML;				
			var XMLAllTag = XMLhtml.documentElement;		
			var nameTag = XMLAllTag.getElementsByTagName("name");
			var name = nameTag.item(0).firstChild.data;
			if(name=="無")
			{var name='';}
			var emailTag = XMLAllTag.getElementsByTagName("email");
			var email = emailTag.item(0).firstChild.data;
			if(email=="無")
			{var email='';}
			var phoneTag = XMLAllTag.getElementsByTagName("phone");
			var phone = phoneTag.item(0).firstChild.data;
			if(phone=="無")
			{var phone='';}
			var mphoneTag = XMLAllTag.getElementsByTagName("mphone");
			var mphone = mphoneTag.item(0).firstChild.data;
			if(mphone=="無")
			{var mphone='';}
			var addressTag = XMLAllTag.getElementsByTagName("address");
			var address = addressTag.item(0).firstChild.data;
			if(address=="無")
			{var address='';}
			var FormName = document.Postform;
			FormName.RepairName.value = name;
			FormName.RepairPhone.value = phone;
			FormName.RepairPhone2.value = mphone;
			FormName.RepairAddress.value = address;
			FormName.RepairEmail.value = email;
		}
		else
		{
			alert("There was a problem accessing the server:"+xmlHttp.statusText);
		}
	}
}
//========================================================================================
//-----------------產品列表----------------------
function ChangeDisplay(Display)
{
	document.getElementById("NowDispaly").value = Display;
	SelectProductsList('',0);
}
function SelectProductsList(Type,Page)
{
	try
		{
			if(Type=='')
			{
				Type = document.getElementById("NowType").value;
			}
			document.getElementById("NowType").value = Type;
			var Display = document.getElementById("NowDispaly").value;
			if(Display==0)
			{
				var AjaxUrl = 'ajax/SelectProductslist.php';
			}else
			{
				var AjaxUrl = 'ajax/SelectProductslist1.php';
			}
			var time= new Date().getTime();		//因為ajax的時間戳讓每次的網址都不一樣，就會在讀一次xml檔。所以需url+time。
			var PostMain="Type="+Type+"&Page="+Page+"&time="+time;
			xmlHttp.open("POST",AjaxUrl,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("錯誤喔");
		}
}
function ReturnSelectProductsList()
{
	if(xmlHttp.readyState == 4)						//回傳回來必須這某寫~!??
	{
		if(xmlHttp.status == 200)					////回傳回來必須這某寫~!??
		{
			var XMLhtml = xmlHttp.responseText;				//將整個網頁(xml)放進變數裡
			document.getElementById("ProductsContent").innerHTML = XMLhtml;
		}
	}
}
//-------------------加入訂購-----------------
function JoinOrder(who)
{
	try
		{
			var time= new Date().getTime();		//因為ajax的時間戳讓每次的網址都不一樣，就會在讀一次xml檔。所以需url+time。
			var PostMain="who="+who+"&time="+time;
			//alert(PostMain);
			xmlHttp.open("POST","OrderJoinXML.php",true);											//將值傳進另一個網頁
			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(值)裡
			alert('已幫你加入購物車');
		}																					//傳的值跟GET一樣。例：name=Dennis&content=good
		catch(e)																			//如要傳陣列的話。列：name[]=Dennis&name[]=Don這樣的話接收者就可用name[]這個陣列/ 
		{
			alert("錯誤喔");
		}
}
//-------------------刪除訂單-----------------
function DeleteOrder(who)
{
	try
		{
			if(!confirm('是否刪除?'))
			{return;}
			var time= new Date().getTime();		//因為ajax的時間戳讓每次的網址都不一樣，就會在讀一次xml檔。所以需url+time。
			var PostMain="who="+who+"&time="+time;
			//alert(PostMain);
			xmlHttp.open("POST","OrderDeleteXML.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("錯誤喔");
		}
}
//改變數量
function ChangeQuantity(who)
{
	var Price = parseInt(document.getElementById("Price"+who).value);
	var Quantity = parseInt(document.getElementById("Quantity"+who).value);
	document.getElementById("Subtotal"+who).innerHTML = (Price*Quantity);
	SumHowMich();
}
//小計加總
function SumHowMich()
{
	var OrderNum = parseInt(document.getElementById("OrderNum").value)
	var HowMich = 0;
	for(var i=0;i<OrderNum;i++)
	{
		HowMich += parseInt(document.getElementById("Subtotal"+i).innerHTML);
	}
	document.getElementById("HowMich").innerHTML = HowMich;
	var NowFreightID=document.getElementById("NowFreightID").value;
	SumAllOrder(NowFreightID);
}
//金額加總
function SumAllOrder(FreightID)
{
	//改變運費
	var HowMich = parseInt(document.getElementById("HowMich").innerHTML);
	var FreeFreight = parseInt(document.getElementById("FreeFreight").value);
	if(HowMich>=FreeFreight)
	{
		document.getElementById("Freight").innerHTML = 0;
	}else
	{
		document.getElementById("Freight").innerHTML = document.getElementById("OrderFreight").value;
	}
	document.getElementById("NowFreightID").value = FreightID;
	//金額加總
	var HowMich = parseInt(document.getElementById("HowMich").innerHTML);
	var Freight = parseInt(document.getElementById("Freight").innerHTML)
	document.getElementById("cope").innerHTML = HowMich+Freight;
}
//-------------------儲存訂單-----------------
function SaveOrder()
{
	try
	{
		var HowMich = parseInt(document.getElementById("HowMich").innerHTML);
		var Freight = parseInt(document.getElementById("Freight").innerHTML);
		var Cope = parseInt(document.getElementById("cope").innerHTML);
		var NowFreightID=document.getElementById("NowFreightID").value;
		var time= new Date().getTime();		//因為ajax的時間戳讓每次的網址都不一樣，就會在讀一次xml檔。所以需url+time。
		var PostMain="&time="+time+"&HowMich="+HowMich+"&Freight="+Freight+"&Cope="+Cope+"&NowFreightID="+NowFreightID;
		var OrderNum = parseInt(document.getElementById("OrderNum").value);
		for(var i =0;i<OrderNum;i++)
		{
			var Quantity = "Quantity"+i;
			PostMain += "&Quantity[]="+document.getElementById(Quantity).value;
		}

		xmlHttp.open("POST","OrderSaveXML.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.href='queryConfirm.php';
	}																					//傳的值跟GET一樣。例：name=Dennis&content=good
	catch(e)																			//如要傳陣列的話。列：name[]=Dennis&name[]=Don這樣的話接收者就可用name[]這個陣列/ 
	{
		alert("錯誤喔");
	}
}
//===================================載入會員資料=============================================
function OrderLoadMembers()
{
	try
		{
			var time= new Date().getTime();		//因為ajax的時間戳讓每次的網址都不一樣，就會在讀一次xml檔。所以需url+time。
			var PostMain="time="+time;
			xmlHttp.open("POST","ajax/LoadMembersXML.php",true);											//將值傳進另一個網頁
			xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			xmlHttp.setRequestHeader("Content-length", PostMain.length);
			xmlHttp.setRequestHeader("Connection", "close");
			xmlHttp.onreadystatechange = ReturnOrderLoadMembers;						//將結果傳回來給function
			xmlHttp.send(PostMain);															//傳post的值需放進send(值)裡
		}																					//傳的值跟GET一樣。例：name=Dennis&content=good
		catch(e)																			//如要傳陣列的話。列：name[]=Dennis&name[]=Don這樣的話接收者就可用name[]這個陣列/ 
		{
			alert("錯誤喔");
		}
}
function ReturnOrderLoadMembers()
{
	if(xmlHttp.readyState == 4)
	{
		if(xmlHttp.status == 200)
		{
			var XMLhtml = xmlHttp.responseXML;				
			var XMLAllTag = XMLhtml.documentElement;		
			var nameTag = XMLAllTag.getElementsByTagName("name");
			var name = nameTag.item(0).firstChild.data;
			if(name=="無")
			{var name='';}
			var emailTag = XMLAllTag.getElementsByTagName("email");
			var email = emailTag.item(0).firstChild.data;
			if(email=="無")
			{var email='';}
			var phoneTag = XMLAllTag.getElementsByTagName("phone");
			var phone = phoneTag.item(0).firstChild.data;
			if(phone=="無")
			{var phone='';}
			var mphoneTag = XMLAllTag.getElementsByTagName("mphone");
			var mphone = mphoneTag.item(0).firstChild.data;
			if(mphone=="無")
			{var mphone='';}
			var addressTag = XMLAllTag.getElementsByTagName("address");
			var address = addressTag.item(0).firstChild.data;
			if(address=="無")
			{var address='';}
			var FormName = document.Postform;
			FormName.RemName.value = name;
			FormName.RemPhone.value = phone;
			FormName.RemPhone2.value = mphone;
			FormName.RemAddress.value = address;
			FormName.RemEmail.value = email;
		}
		else
		{
			alert("There was a problem accessing the server:"+xmlHttp.statusText);
		}
	}
}
//========================================================================================
//-------------------產生訂單(選擇付款方式)-----------------
function RemittanceSelect()
{
		var Remittance = document.getElementById("Remittance").value;
		if(Remittance!='')
		{
			var FormName = document.Postform;
			if(FormName.RemName.value=='')
			{alert('請輸入接收人');return;}
			
			if(!CheckPhone(FormName.RemPhone.value)&&FormName.RemPhone.value!='')
			{alert('電話格式不對');return;}
			if(FormName.RemPhone2.value=='')
			{alert('請輸入手機');return;}
			if(!CheckPhone(FormName.RemPhone2.value))
			{alert('手機格式不對');return;}
			if(FormName.RemEmail.value=='')
			{alert('請輸入E-mail');return;}
			if(!CheckEmail(FormName.RemEmail.value))
			{alert('您的Email格式不對');return;}
			if(FormName.RemAddress.value=='')
			{alert('請輸入地址');return;}
			
			var RemName = escape(FormName.RemName.value);
			var RemPhone = escape(FormName.RemPhone.value);
			var RemPhone2 = escape(FormName.RemPhone2.value);
			var RemEmail = escape(FormName.RemEmail.value);
			var RemAddress = escape(FormName.RemAddress.value);
			var RemRemarks = escape(FormName.RemRemarks.value);
			
			var HowMich = parseInt(FormName.HowMich.value);
			var Freight = parseInt(FormName.Freight.value);
			var Cope = parseInt(FormName.Cope.value);
			var FreightID = parseInt(FormName.FreightID.value);
			
			
			var time= new Date().getTime();		//因為ajax的時間戳讓每次的網址都不一樣，就會在讀一次xml檔。所以需url+time。
			var PostMain='RemName='+RemName+'&Remittance='+Remittance+'&RemPhone='+RemPhone+'&RemPhone2='+RemPhone2+'&RemEmail='+RemEmail+
						'&RemAddress='+RemAddress+'&RemRemarks='+RemRemarks+'&HowMich='+HowMich+'&Freight='+Freight+"&Cope="+Cope+"&FreightID="+FreightID+'&time='+time+'&Confirm=HonJet';
			//alert(PostMain);
			//FormName.RemRemarks.value = PostMain;
			xmlHttp.open("POST","OrderConfirmXML.php",true);											//將值傳進另一個網頁
			xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			xmlHttp.setRequestHeader("Content-length", PostMain.length);
			xmlHttp.setRequestHeader("Connection", "close");
			xmlHttp.onreadystatechange = ReturnRemittanceSelect;						//將結果傳回來給function
			xmlHttp.send(PostMain);														//傳post的值需放進send(值)裡
			document.getElementById("loading").style.display="block";
			//window.location='queryconfirm.php';
		}else
		{
			alert('請選擇匯款方式');
		}
}
function ReturnRemittanceSelect()
{
	if(xmlHttp.readyState == 4)						//回傳回來必須這某寫~!??
	{
		if(xmlHttp.status == 200)					////回傳回來必須這某寫~!??
		{
			var XMLhtml = xmlHttp.responseXML;				//回傳的值必須這某寫~!??	將整個網頁放進變數裡
			var XMLAllTag = XMLhtml.documentElement;		//回傳的值必須這某寫~!??	將整個網頁內容放進變數裡
			window.location='queryOrder.php';
		}
		else
		{
			alert("There was a problem accessing the server:"+xmlHttp.statusText);
		}
	}
}
//-------------------收到商品-----------------
function Finish(who)
{
	try
	{
		if(!confirm('是否收到商品?'))
		{return;}
		var time= new Date().getTime();		//因為ajax的時間戳讓每次的網址都不一樣，就會在讀一次xml檔。所以需url+time。
		var PostMain="Who="+who+"&time="+time;
		xmlHttp.open("POST","ajax/FinishOrderXML.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("錯誤喔");
	}
}
//-------------------匯款完成通知信-----------------
function RemittanceRegister(who)
{
	try
	{
		var FormName = document.Postform;
		var RemDate = FormName.RemDate.value;
		if(!fild_valid(FormName.RemAmount.value))
		{alert("匯款金額格式錯誤!");return;}
		var RemAmount = FormName.RemAmount.value;
		var RemFiveYards = FormName.RemFiveYards.value;
		var time= new Date().getTime();		//因為ajax的時間戳讓每次的網址都不一樣，就會在讀一次xml檔。所以需url+time。
		var PostMain="Who="+who+"&RemDate="+RemDate+"&RemAmount="+RemAmount+"&RemFiveYards="+RemFiveYards+"&time="+time;
		//alert(PostMain);
		xmlHttp.open("POST","ajax/RemittanceOrderXML.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(值)裡
		window.location='queryOrder.php';
	}																					//傳的值跟GET一樣。例：name=Dennis&content=good
	catch(e)																			//如要傳陣列的話。列：name[]=Dennis&name[]=Don這樣的話接收者就可用name[]這個陣列/ 
	{
		alert("錯誤喔");
	}
}
//------------------非會員查詢------------------
function CheckSelectOrder()
{
	/*try
	{*/
		var FormName = document.Postform;
		if(FormName.SelectName.value=="")
		{alert("請輸入姓名");return;}
		if(FormName.SelectEmail.value=="")
		{alert("請輸入Email");return;}
		var SelectName = escape(FormName.SelectName.value);
		var SelectEmail = escape(FormName.SelectEmail.value);
		var time= new Date().getTime();		//因為ajax的時間戳讓每次的網址都不一樣，就會在讀一次xml檔。所以需url+time。
		var PostMain="SelectName="+SelectName+"&SelectEmail="+SelectEmail+"&time="+time;
		//alert(PostMain);
		xmlHttp.open("POST","ajax/SelectOrder.php",true);											//將值傳進另一個網頁
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", PostMain.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.onreadystatechange = ReturnCheckSelectOrder;						//將結果傳回來給function
		xmlHttp.send(PostMain);															//傳post的值需放進send(值)裡
	/*}																					//傳的值跟GET一樣。例：name=Dennis&content=good
	catch(e)																			//如要傳陣列的話。列：name[]=Dennis&name[]=Don這樣的話接收者就可用name[]這個陣列/ 
	{
		alert("錯誤喔");
	}*/
}
function ReturnCheckSelectOrder ()
{
	if(xmlHttp.readyState == 4)
	{
		if(xmlHttp.status == 200)
		{
			var XMLhtml = xmlHttp.responseXML;				
			var XMLAllTag = XMLhtml.documentElement;		
			var confirmTag = XMLAllTag.getElementsByTagName("confirm");
			var Con = confirmTag.item(0).firstChild.data;
			if(Con=='noconfirm')
			{
				alert('查無訂單');
				location.replace(location.href);
			}else
			{
				 document.Postform.submit();
			}
		}
		else
		{
			alert("There was a problem accessing the server:"+xmlHttp.statusText);
		}
	}
}
//--------------------------------------------------
