﻿/*
	http://www.binlin.com.tw
*/

// protect
var accepted_domains = new Array();
var this_domains = document.location.href;
var accepted_ok = false;

accepted_domains[0] = 'binlin.idv.tw';
accepted_domains[1] = 'sv.idv.tw';
accepted_domains[2] = 'onlyorz.com';

if (this_domains.indexOf('http') != -1)
{
	for (i0=0; i0<accepted_domains.length; i0++)
	{
		if (this_domains.indexOf(accepted_domains[i0]) != -1)
		{
			accepted_ok = true;
			break;
		}
	}

	if (!accepted_ok)
	{
		alert('JAVA Script Error.');
		history.back(-1);
	}
}

// OnMouse table change background Color
function OMOver(OMO){OMO.style.backgroundColor='#FFCC00';}
function OMOut(OMO){OMO.style.backgroundColor='';}

// Jump page
function SystemLog_JP()
{
	var theForm = document.systemlog_form;
	theForm.submit();
}

// Jump page
function OrderList_JP()
{
	var theForm = document.orderlist_form;
	theForm.submit();
}

// Jump page
function ArticleList_JP()
{
	var theForm = document.aList_form;
	theForm.submit();
}

// cookie
function setCookie(c_name, value)
{
	var savetime = new Date();
	savetime.setTime(savetime.getTime() + 1000 * 60 * 60 * 24 * 365);
	document.cookie = c_name + '=' + escape(value) + ';expires=' + savetime;
}

function tr_focus(thisI)
{
	var inptCount = document.getElementsByName('inputCount[]');
	inptCount[thisI].focus();
}

// 統計金額
function order_count_change()
{
	var theForm = document.order_form;
	var anum = document.getElementsByName('anum[]');
	var inptCount = document.getElementsByName('inputCount[]');
	var price = document.getElementsByName('price[]');
	var freight = document.getElementsByName('freight[]');
	var carrytype = document.getElementsByName('carrytype[]');
	var subtotal = document.getElementsByName('subtotal[]');
	var alltotal = 0;
	
	// 檢查最小量
	for (i1=0; i1<anum.length; i1++)
	{
		if (anum[i1].value == 'V00101')
		{
			if (inptCount[i1].value.length > 0 && inptCount[i1].value < 10)
			{
				alert('非常抱歉！\n產品編號：V00101 最小訂購數量需為 10 喔。');
				inptCount[i1].value = '';
				break;
			}
		}
	}
	
	// 計算
	for (i1=0; i1<inptCount.length; i1++)
	{
		if (parseInt(inptCount[i1].value) > 0)
		{
			// Rule - 郵局出貨禁用六日到貨( check )
			if (carrytype[i1].value == 3)
				theForm.gettime_disable.value = 1;
			
			subtotal[i1].value = parseInt(price[i1].value) + parseInt(freight[i1].value);
			subtotal[i1].value = parseInt(subtotal[i1].value) * parseInt(inptCount[i1].value);
			alltotal += parseInt(subtotal[i1].value);
		}
	}
	
	// 顯示
	theForm.DisplayTotal.value = alltotal;
}

// 貨到付款選擇鈕
function paymethod_select()
{
	var theForm = document.order_form;
	var freight = document.getElementsByName('freight[]');
	var freight_set = theForm.freight_set.value;
	
	if (theForm.paymethod[1].checked)
	{
		for (i1=0; i1<freight.length; i1++)
			freight[i1].value = parseInt(freight_set);
	}
	else
	{
		for (i1=0; i1<freight.length; i1++)
			freight[i1].value = 0;
	}
	
	// 統計金額
	order_count_change();
}

// 訂單送出檢查
function order_form_chk()
{
	var theForm = document.order_form;
	var DisplayTotal = theForm.DisplayTotal.value;
	var msg = '';
	
	if (DisplayTotal == 0)
	{
		alert('您尚未選擇任何商品唷！');
		return false;
	}
	
	if (theForm.name.value.length == 0)
		msg += '請輸入訂購人或收件人姓名。\n';
	if (theForm.tel.value.length == 0)
		msg += '請輸入聯絡電話。\n';
	if (theForm.tel2.value.length == 0)
		msg += '請輸入行動電話。\n';
	if (theForm.zip.value.length == 0)
		msg += '請輸入郵遞區號。\n';
	if (theForm.address.value.length == 0)
		msg += '請輸入送件地址。\n';
	if (theForm.email.value.indexOf("@") == -1)
		msg += '請輸入電子信箱。\n';
	
	if (msg != '')
	{
		alert(msg);
		theForm.DisplayMSG.value = '請輸入正確資料，謝謝您！';
		return false;
	}
	else
	{
		// Rule - 郵局出貨禁用六日到貨
		if (theForm.gettime_disable.value == 1 && theForm.gettime[1].checked)
		{
			alert('非常抱歉！\n您選購了以郵局出貨的商品，故到貨時間無法選擇週六、日。\n不便之處請多多包函。\n');
			theForm.gettime[0].checked = true;
			return false;
		}
		
		msg = '感謝您的訂購！\n\n';
		msg += '您所選擇的付款方式為：';
		msg += (theForm.paymethod[1].checked) ? '貨到付款' : '轉帳匯款';
		msg += '，共 ' + DisplayTotal + '元。\n\n';
		msg += '按下確定後，系統將送出此訂單；\n';
		msg += '並且在十分鐘內送出一封確認信到您的電子信箱裡。';
		
		if (confirm(msg))
		{
			theForm.disbtm.disabled = true;
			theForm.disbtm2.disabled = true;
			theForm.DisplayMSG.value = '訂單送出中，請稍候；謝謝您！';
			return true;
		}
		else
			return false;
	}
}

// 出貨確認
function opcheck_form_chk()
{
	var theForm = document.opcheck_form;
	var order_id = document.getElementsByName('order_id[]');
	var waybill_count = theForm.waybill_count.value;
	var msg = '';
	
	checkbox_chk = 0;
	for (i1=0; i1<order_id.length; i1++)
		if (order_id[i1].checked) checkbox_chk = 1;
	
	if (checkbox_chk != 1)
		msg = '未選取任何訂單。\n';
	
	if (msg != '')
	{
		alert(msg);
		return false;
	}
	else
	{
		if (waybill_count != 0)
		{
			msg = '系統留有此商品前次出貨單，將會被覆蓋！\n是否繼續？';
			if (confirm(msg))
			{
				theForm.disbtm.disabled = true;
				return true;
			}
			else
				return false;
		}
		
		theForm.disbtm.disabled = true;
		return true;
	}
}

// 更改管理密碼
function chgpwd_form_chk()
{
	var theForm = document.chgpwd_form;
	var p1 = theForm.p1.value;
	var p2 = theForm.p2.value;
	var p3 = theForm.p3.value;
	var msg = '';
	
	if (p1 == '') msg += '請輸入目前的密碼。\n';
	if (p2 == '') msg += '請輸入新的密碼。\n';
	if (p3 == '') msg += '請再次輸入新的密碼。\n';
	if (p1 == p2) msg += '新密碼不得與原始密碼相同。\n';
	
	if (p2.length < 4 || p2.length > 20)
		msg += '密碼請使用 4~20 個英文或數字。\n(英文有區分大小寫)\n';
	
	if (p2 != p3)
	{
		msg += '密碼確認失敗，請重新輸入。\n';
		theForm.p2.value = '';
		theForm.p3.value = '';
		theForm.p2.focus();
	}
	
	if (msg == '')
	{
		theForm.disbtm.disabled = true;
		return true;
	}
	
	alert(msg);
	return false;
}












