﻿var _totalQTY = 0
function PopUpCenter(u,n,w,h){
var wl=(screen.width-w)/2;var wt=(screen.height-h)/2;
wp='width='+w+',height='+h+',left='+wl+',top='+wt+',scrollbars=No'
Win=window.open(u,n,wp)
if(parseInt(navigator.appVersion)>=4){Win.window.focus()}
}
function postOrder(f,v){
if(confirm('是否確認送出本訂單？\n按下『確定』鍵送出訂單或『取消』鍵返回')){
	if(_totalQTY<3 && getid('qty_jpg').value<1 && getid('qty_classic').value<1){
		alert('很抱歉，訂購數量最少需要三箱');
		getid('qty_330').focus()
		return false
	}
	else{
		if(v){
			var a=new Array();
			a[a.length]=[f.membertype,'您的會員屬性'];
			a[a.length]=[f.name,'您的姓名'];
			a[a.length]=[f.email,'您的電郵',['email']];
			a[a.length]=[f.address,'送貨地址'];
			if(validateRequiredFields(f,a)){
				//PopUpCenter('../thanksForOrder.php','thanks','320','240');
				alert('感謝您訂購本公司的產品\n您的訂單我們會立即處理\n同時在我們送貨前,經銷商將先與您確認\n\n如果您有任何問題,\n請撥打消費者免付費服務專線:\n0800-300-808');
				return true
				}
			else{return false}
			}
			else{return true}
	}
}
}
function currency(n){n=''+n;
if(n.length>3){var mod=n.length%3;
var output=(mod>0?(n.substring(0,mod)):'');
for(crcy=0;crcy< Math.floor(n.length/3);crcy++){
if((mod==0)&&(crcy==0))
output+=n.substring(mod+3*crcy,mod+3*crcy+3);
else
output+=','+n.substring(mod+3*crcy,mod+3*crcy+3)}
return (output)}
else return n}
function setQty(f,v,u)
{
v=(v)?' disabled':'';
u=(u)?u:'箱'
sel='<select name=qty'+f+' id=qty_'+f+' onchange=updTotal()'+v+'>'
sel+='<option value=0>0 '+u
for(i=1;i<101;i++)
{sel+='<option value='+i+'>'+i+' '+u}
sel+='</select>'
return sel
}
thisMon=new Date().getMonth()+1;
thisDay=new Date().getDate();
function setDate(v,f)
{
switch(v){
case "y":
count=(f=='bday')?101:2;
init=(f=='bday')?thisyear-100:thisyear;
seled=(f=='bday')?thisyear-25:thisyear;
break;
case "m":count=12;init=1;seled=thisMon;break;
case "d":count=31;init=1;
seled=(f=='bday')?thisDay:thisDay+2;
break;
}
sel='<select id='+f+'_'+v+' onchange=updDate(\''+f+'\')>'
for(i=0;i<count;i++)
{
sel+='<option value="'+init+((init==seled)? '" selected':'"')+'>'+init
init++
}
sel+='</select>'
return sel
}
function updDate(f)
{
setdate=_rightback('00'+getid(f+'_m').value,2)+'/'+_rightback('00'+getid(f+'_d').value,2)+'/'+getid(f+'_y').value;
switch(f){
case "bday":getid('bday').value=setdate;break;
case "sday":getid('sday').value=setdate;break;
}
}
function updTotal()
{
_totalQTY = 0
_items=['330','500','1000','1500','750','jpg']
_total=0
for(i=0;i<_items.length;i++)
{
f=_items[i]
s=getid('qty_'+f).value
_totalQTY += eval(s)
subtotal=getid('price_'+f).innerHTML*s;
getid('total_'+f).innerHTML=currency(subtotal)
_total+=subtotal
}
getid('price_total').innerHTML=currency(_total)
getid('totalField').value=_total
}
function previewThis(o,v)
{pv=getid('preview_'+o);
if(v)
{
pv.style.filter=
'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'http://media.nicedepot.com/evian/order/Preview_'+o+'.png\',sizingMethod=\'crop\')';
pv.style.display='block'
}
else{
pv.style.filter="";
pv.style.display='none'
}
}
function makeForm()
{
var f='ordereditorprocessor';
df='document.forms[\''+f+'\']';
_fm='<div ID=orderEditor>'+
'<style>@import url(addon.css);</style>'+
'<form name="'+f+'" action="addon_makeorder.php" method="post" onsubmit="return postOrder(this,true)" enctype="multipart/form-data">'+
'<'+'script src=include_valid.php></'+'script>'+
'<input type=hidden name=total value=0 id=totalField>'+
'<input type=hidden id=bday name="birthday" value="'+_rightback('00'+thisMon,2)+'/'+_rightback('00'+thisDay,2)+'/'+(thisyear-25)+'">'+
'<input type=hidden id=sday name="shipdate" value="'+_rightback('00'+thisMon,2)+'/'+_rightback('00'+(thisDay+2),2)+'/'+thisyear+'">'+
'<table class=product><tr class=title><td class=item>容量ML/瓶</td><td class=rprice>零售價</td><td class=price>直送價</td><td class=qty>訂購數/箱</td><td class=total>金額</td></tr>'+
'<tr><td class=item onmouseover="previewThis(\'330\',1)" onmouseout="previewThis(\'330\',0)">330ML<div id=preview_330 class=preview></div><div class=note>(一箱24瓶)</div></td><td class=rprice><s>840.-</s></td><td class=price><span id=price_330>720</span>.-</td><td class=qty>'+setQty('330')+'</td><td class=total><span id=total_330>0</span>.-</td></tr>'+
'<tr><td class=item onmouseover="previewThis(\'500\',1)" onmouseout="previewThis(\'500\',0)">500ML<div id=preview_500 class=preview></div><div class=note>(一箱24瓶)</div></td><td class=rprice><s>960.-</s></td><td class=price><span id=price_500>840</span>.-</td><td class=qty>'+setQty('500')+'</td><td class=total><span id=total_500>0</span>.-</td></tr>'+
'<tr><td class=item onmouseover="previewThis(\'1000\',1)" onmouseout="previewThis(\'1000\',0)">1000ML<div id=preview_1000 class=preview></div><div class=note>(一箱12瓶)</div></td><td class=rprice><s>684.-</s></td><td class=price><span id=price_1000>620</span>.-</td><td class=qty>'+setQty('1000')+'</td><td class=total><span id=total_1000>0</span>.-</td></tr>'+
'<tr><td class=item onmouseover="previewThis(\'1500\',1)" onmouseout="previewThis(\'1500\',0)">1500ML<div id=preview_1500 class=preview></div><div class=note>(一箱12瓶)</div></td><td class=rprice><s>900.-</s></td><td class=price><span id=price_1500>760</span>.-</td><td class=qty>'+setQty('1500')+'</td><td class=total><span id=total_1500>0</span>.-</td></tr>'+
'<tr><td class=item colspan=2 onmouseover="previewThis(\'750\',1)" onmouseout="previewThis(\'750\',0)">750ML (缺貨中)<div id=preview_750 class=preview></div></td><td class=price><span id=price_750>708</span>.-</td><td class=qty>'+setQty('750',1)+'</td><td class=total><span id=total_750>0</span>.-</td></tr>'+
'<tr><td class=item colspan=2>2009 限量經典瓶<br>※請洽各經銷商</td><td class=price><span id=price_jpg><s>699</s></span>.-</td><td class=qty>'+setQty('jpg',1,'瓶')+'</td><td class=total><span id=total_jpg>0</span>.-</td></tr>'+
'<tr><td colspan=4 align=right>合計</td><td class=total><span id=price_total>0</span>.-</td></table>'+
'<div id=orderMemo>'+
((getid('shopnote'))?getid('shopnote').innerHTML:'※線上訂購至少需三箱，三箱以上可免運費<br>　低於三箱請撥打服務專線:<font color=red>0800-300-808</font>')+
'</div>'+
'<div class=title>訂戶基本資料</div>'+
'<div class=field><input type=radio name=membertype value=new id=m_new><label for=m_new>新會員</label> <input type=radio name=membertype value=old id=m_old><label for=m_old>續訂會員</label>&nbsp;,&nbsp;資訊來源 <input name="source" value="" class=field style="width:258px"></div>'+
'<div class=field>訂戶姓名 <input name="name" value="" class=field style="width:280px"> <input type=radio name="sex" value="f" id=sex_f><label for=sex_f>小姐</label> <input type=radio name="sex" value="m" id=sex_m><label for=sex_m>先生</label></div>'+
'<div class=field>公司名稱 <input name="company" value="" class=field></div>'+
'<div class=field>訂戶職業 <input name="jobs" value="" class=field></div>'+
'<div class=field>出生日期 &nbsp;'+setDate('y','bday')+' 年 '+setDate('m','bday')+' 月 '+setDate('d','bday')+' 日</div>'+
'<div class=field>最常飲用水 <input type=radio value=y name=isevian id=_isevian><label for=_isevian>evian</label> 年資 <input name="evianyear" value="" class=field style="width:80px"> 年 , <input type=radio value=n name=isevian id=_isother><label for=_isother>其他</label> <input name="brand" value="" class=field style="width:126px"> </div>'+
'<div class=field>電子郵件 <input name="email" value="" class=field></div>'+
'<div class=field>公司電話 <input name="phone" value="" class=field></div>'+
'<div class=field>住家電話 <input name="phone_h" value="" class=field></div>'+
'<div class=field>行動電話 <input name="phone_cell" value="" class=field></div>'+
'<div class=field>傳真號碼 <input name="fax" value="" class=field></div>'+
'<div class=field>送貨地址 <input type=radio name="addressas" value="h" id=add_h><label for=add_h>住家</label><input type=radio name="addressas" value="o" id=add_o><label for=add_o>公司</label><input name="address" value="" class=field style="width:324px"></div>'+
'<div class=field>發票種類 <input type=radio name="invoice" value="2" id=inv_2><label for=inv_2>二聯式</label><input type=radio name="invoice" value="3" id=inv_3><label for=inv_3>三聯式</label> , 統一編號 <input name="bizunid" value="" class=field style="width:218px"></div>'+
'<div class=field>發票抬頭 <input name="invoicetitle" value="" class=field></div>'+
'<div class=field>送貨日期 &nbsp;'+setDate('y','sday')+' 年 '+setDate('m','sday')+' 月 '+setDate('d','sday')+' 日 <input type=radio name="shiptime" value="a" id=sh_a><label for=sh_a>上午</label><input type=radio name="shiptime" value="p" id=sh_p><label for=sh_p>下午</label><input type=radio name="shiptime" value="n" id=sh_n><label for=sh_n>晚上</label></div>'+
'<div class=field>訂單備註<textarea name="memo" class=body></textarea></div><div class=field>'
_fm+=(!isie)?'<input type=submit style="margin-top:6px;padding-top:2px;width:auto;font:9pt verdana" onclick="if(getid(\'totalField\').value==0||getid(\'totalField\').value==\'\'){alert(\'您還沒有訂購任何的宅配商品喔\');getid(\'qty_330\').focus()}else{if(postOrder('+df+',true)){this.disabled=true;document.forms.'+f+'.submit()}else{return false}}" class=btn value="送出訂購單" />':'<button style="margin-top:6px;padding-top:2px" onclick="if(getid(\'totalField\').value==0||getid(\'totalField\').value==\'\'){alert(\'您還沒有訂購任何的宅配商品喔\');getid(\'qty_330\').focus()}else{if(postOrder('+df+',true)){this.disabled=true;'+df+'.submit()}}">送出訂購單</button>';
_fm+='</div>'
dw(_fm)
}
makeForm()