/*Spike 2007.10.09 修改:
	1.InquireCheck(): email驗證及內容驗證之語法及相容性修正
*/
//驗證付款方式是否選取
function PaymentCheck()
{
	var selected = false
	var len = payment_form.payment.length
	for (var i=0 ; i < len ; i++)
	{
		if(document.payment_form.payment[i].checked){
			selected = true
		}
	}
	if(selected == false)
	{
		alert("請選擇付款方式！");
		return false
	}
}

//驗證簡易會員註冊
function SimpleRegister()
{
	if(document.SimpleReg.name.value=="")
	{
		alert("請輸入您的姓名！");
		document.SimpleReg.name.focus();
		return false;
	}
	if(document.SimpleReg.NickName.value=="")
	{
		alert("請輸入您的暱稱！");
		document.SimpleReg.NickName.focus();
		return false;
	}
	if(document.SimpleReg.email.value=="")//電子郵件
    {
		alert("請輸入您的的電子郵件信箱！");
		document.SimpleReg.email.focus();
		return false;
	}
	if(document.SimpleReg.email.value!=="")
	{

		if(!checkmail(document.SimpleReg.email))
			{
			document.SimpleReg.email.focus();
			return false;
			} 
			
			function checkmail(myEmail) {
			if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(myEmail.value)){
			return (true)
			}
			alert("抱歉，您的的E-mail格式不正確!")
			return (false)
			}
	}
	if(document.SimpleReg.passwd.value=="")
	{
		alert("請輸入會員的密碼！");
		document.SimpleReg.passwd.focus();
		return false;
	}
	if(document.SimpleReg.passwd.value!=document.SimpleReg.passwd2.value)
	{
		alert("密碼前後輸入有誤！");
		document.SimpleReg.passwd2.focus();
		return false;
	}
}

function OrderInfoCheck()
{
	
	//訂購人表單欄位驗證
	if(document.OrderInfo.customer_name.value=="")
	{
		alert("請填寫訂購人『姓名』！");
		document.OrderInfo.customer_name.focus();
		return false;
	}
	var customer_selected = false
	var len = OrderInfo.customer_gender.length
	for (var i=0 ; i < len ; i++)
	{
		if(document.OrderInfo.customer_gender[i].checked){
			customer_selected = true
		}
	}
	if(customer_selected == false)
	{
		alert("請選擇訂購人『性別』！");
		return false
	}
	if(document.OrderInfo.customer_tel.value=="")
	{
		alert("請填寫訂購人『聯絡電話』！");
		document.OrderInfo.customer_tel.focus();
		return false;
	}
	if(document.OrderInfo.customer_tel.value.length < 7)
	{
		alert("『聯絡電話』輸入有誤！");
		document.OrderInfo.customer_tel.focus();
		return false;
	}
	if(document.OrderInfo.customer_postcode.value=="")
	{
		alert("請填寫訂購人『郵遞區號』！");
		document.OrderInfo.customer_postcode.focus();
		return false;
	}
	if(document.OrderInfo.customer_postcode.value.length <3)
	{
		alert("訂購人『郵遞區號』至少要有3碼！");
		document.OrderInfo.customer_postcode.focus();
		return false;
	}
	if(document.OrderInfo.customer_city.value=="")
	{
		alert("請填寫訂購人『居住城市』！");
		document.OrderInfo.customer_city.focus();
		return false;
	}
	if(document.OrderInfo.customer_address.value=="")
	{
		alert("請填寫訂購人『地址』！");
		document.OrderInfo.customer_address.focus();
		return false;
	}
	if(document.OrderInfo.customer_email.value=="")
	{
		alert("請輸入訂購人『電子郵件信箱』！");
		document.OrderInfo.customer_email.focus();
		return false;
	}
	if(document.OrderInfo.customer_email.value!=="")
	{

		if(!checkmail(document.OrderInfo.customer_email))
			{
			document.OrderInfo.customer_email.focus();
			return false;
			} 
			
			function checkmail(myEmail) {
			if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(myEmail.value)){
			return (true)
			}
			alert("抱歉，您的E-mail格式不正確!")
			return (false)
		}
	}
	
	//收件人表單欄位驗證
	if(document.OrderInfo.delivery_name.value=="")
	{
		alert("請填寫收件人『姓名』！");
		document.OrderInfo.delivery_name.focus();
		return false;
	}
	var delivery_selected = false
	var len = OrderInfo.delivery_gender.length
	for (var i=0 ; i < len ; i++)
	{
		if(document.OrderInfo.delivery_gender[i].checked){
			delivery_selected = true
		}
	}
	if(delivery_selected == false)
	{
		alert("請選擇收件人『性別』！");
		return false
	}
	if(document.OrderInfo.delivery_tel.value=="")
	{
		alert("請填寫收件人『聯絡電話』！");
		document.OrderInfo.delivery_tel.focus();
		return false;
	}
	if(document.OrderInfo.delivery_tel.value.length <7)
	{
		alert("『聯絡電話』輸入有誤！");
		document.OrderInfo.delivery_tel.focus();
		return false;
	}
	if(document.OrderInfo.delivery_postcode.value=="")
	{
		alert("請填寫收件人『郵遞區號』！");
		document.OrderInfo.delivery_postcode.focus();
		return false;
	}
	if(document.OrderInfo.delivery_postcode.value.length <3)
	{
		alert("收件人『郵遞區號』至少要有3碼！");
		document.OrderInfo.delivery_postcode.focus();
		return false;
	}
	if(document.OrderInfo.delivery_city.value=="")
	{
		alert("請填寫收件人『居住城市』！");
		document.OrderInfo.delivery_city.focus();
		return false;
	}
	if(document.OrderInfo.delivery_address.value=="")
	{
		alert("請填寫收件人『地址』！");
		document.OrderInfo.delivery_address.focus();
		return false;
	}
	return confirm('請確認所有資料是否正確無誤！');
}

function RecInfo(){
	var OrderInfo = document.OrderInfo;
	OrderInfo.delivery_name.value = OrderInfo.customer_name.value;
	//OrderInfo.delivery_id="delivery_gender";
	OrderInfo.delivery_tel.value = OrderInfo.customer_tel.value;
	OrderInfo.delivery_postcode.value = OrderInfo.customer_postcode.value;
	OrderInfo.delivery_city.value = OrderInfo.customer_city.value;
	OrderInfo.delivery_address.value = OrderInfo.customer_address.value;
} 

function InquireCheck()
{
	if(document.form.name.value=="")
	{
		alert("請填寫您的姓名！");
		document.form.name.focus();
		return false;
	}
	if(document.form.tel.value=="")
	{
		alert("請填寫您的聯絡電話！");
		document.form.tel.focus();
		return false;
	}
	if(document.form.email.value == "")
	{
		alert("請填寫您的E-mail！");
		document.form.email.focus();
		return false;
	}
	else
	{
		function checkmail(myEmail)
		{
			if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(myEmail.value))
				return (true);
			alert("抱歉，您的E-mail格式不正確！");
			return false;
		}
		if(!checkmail(document.form.email))
		{
			document.form.email.focus();
			return false;
		} 
	}
	if(document.form.inquire_content.value=="")
	{
		alert("請填寫您的洽詢內容！");
		document.form.content.focus();
		return false;
	}
}

