// js_javascript.js # ADW # Oct 1998 # Revised May 2010 # V9.38;
// 10% off over £25 + PayPal
//See js_javascript.htm for Working Notes;

	var i=0; 
	note="SECURITY NOTE\n\nPersonal data, such as Credit Card information, may not be secure during internet transmission. This should cause no problems, but if you prefer, you can send your details by letter post, or telephone.\n\nYour details will be retained for any future orders. (Any such information will not be passed on to any third party.)\n\nIf you have previously supplied your Credit Card details, you need only enter the last 4 digits, plus the Expiry date."


	function cpns(middle,bottom){
		parent.R_mid.location.href=middle;
		parent.R_bot.location.href=bottom;
		}


	function pod(num){
		num+="";
		idx=(num).indexOf(".");
		if(idx==-1){return padn=num+".00"};
		if(idx==num.length-2){return padn=num+"0"};
		{return padn=num};
		}


	function sB(de,ea,sx,fr){
		i=parent.si;
		for (ix=0; ix<i; ix++)
			if(de==parent.selection[ix]){
// alert("Item "+ix+" already selected "+de+" Reload flag: "+parent.rg[ix]+" Item Desc: "+parent.special[ix]);
				if(parent.rg[ix]==1){
					parent.rg[ix]=0
					return};				 
				parent.qty[ix]=0;
				parent.selection[ix]="["+parent.selection[ix]+"]";
				parent.cost[ix]=0;
				parent.each[ix]=0;
				parent.special[ix]="*UNTICKED*";
				parent.fr[ix]="DEL";
				totup(i-1);
				rts();
				return};
		parent.selection[i]=de;
		parent.each[i]=ea;
		parent.special[i]=sx;
		parent.fr[i]=fr; 
		parent.qty[i]=1; parent.ufg[i]=0; parent.cost[i]=ea;
		totup(i);
		rts();
		parent.si++;
		}


	function rk(fr){
		end=parent.si;
		count=0;
		while(count<end){
			if(parent.fr[count]==fr){
				parent.rg[count]=1
				document.adw.elements[parent.selection[count]].click()
				}
			count++
			}
		}


	function rut(){
		parent.R_bot.document.selectForm.total.value=pod(parent.fdt);
		} 

		
	function rts(){
		parent.R_bot.document.selectForm.total.value=pod(parent.totsing/100);
		} 


	var k,nq,ea; //Index, New Quantity
	function newTotal(kname,newQty){
		k=parseInt(kname.substring(4,8))-1000;
		nq=parseInt(newQty);
		if((nq!=newQty)||(nq<0))
			{nq=prompt("QUANTITY ERROR!    Only figures of 0 or greater are accepted.\n\nPlease enter the new Quantity here:","");
			if ((nq==null)||(parseInt(nq)!=nq))
				{nq="0"};
			document.orderHC.elements[k*3].value=nq};
		parent.qty[k]=nq;
		if(nq==0){
			parent.special[k]="*CANCELLED*";
			parent.selection[k]="00";
			parent.each[k]=0;
			parent.fr[k]="DEL";
			document.orderHC.elements[k*3+1].value="*CANCEL*";
			};
		document.orderHC.elements[k*3+2].value=parent.special[k];
		parent.cost[k]=pod(nq*(parent.each[k]*100)/100);
		totup(parent.si-1);
		ft();
		if(parent.pix>0){
			tf(parent.xp)
			}
// alert("Qty changed to: "+parent.qty[k]+", of Item: "+parent.selection[k]+", Item Desc: "+parent.special[k]);
		}


	function specIns(kname,newTxt){
		k=parseInt(kname.substring(2,6))-1000;
		parent.special[k]=newTxt;
		}


	function mu(kname,newUfg){
		k=parseInt(kname.substring(1,5))-1000;
		parent.ufg[k]=newUfg;
		}


	function details(){
		for(j=0;j<end;j++){
			var desc=parent.selection[j]+" @ "+parent.each[j];
			}
		}


	function addOther(lv){
		parent.other=0;
		if(lv==""){lv="0"};
		sstr=lv.substring(0,1);
		lv=lv-0;
		sv=""+lv;
		sstrlh=sv.substring(0,3);
		if(sstrlh=="NaN"){alert("PRICE FORMAT INCORRECT\nPlease enter total as Pounds-dot-Pence.\n(For example: 13.75)");
			lv=0;
			document.orderHC.xr_Extras_Cost_ct.focus()};
		if(sstr=="."){lv="0"+lv};
		pv=parseInt(100*lv);
		document.orderHC.xr_Extras_Cost_ct.value=pod(lv);
		parent.other=pv;
		totup(parent.si-1);
		ft();
	}

	function textwrite(){
	document.open();
	document.write("<H3><font color=brown>This is the complete text of your order.</font></H3><PRE><P>Please supply the following:<p></PRE>");
	i=0; j=0;
	while(i<end){
			document.write(parent.qty[i]+" x ");
			document.write(parent.selection[i]+" @ "+parent.each[i]+" ");
			document.write(parent.special[i]+"<br>");
			j++
		i++
		};
	if(parent.otherTxt>""){
	document.write("<p>Also<br>"+parent.otherTxt)};
	if(parent.other>0){
	   document.write(" (total: "+pod(parent.other/100)+")")
	};
	document.write("<p>Total of All Items: "+pod(parent.totall/100));
	document.write("<br>Less Discount: "+pod(parent.dc));
	document.write("<br>Makes: "+parent.fdt);
	document.write("<br>Plus Postage: "+pod(parent.xp/100));
	document.write("<br>Total Due: £"+pod(parent.due));
		if (parent.pyx==1){word="Cheque"};
		if (parent.pyx==2){word="Other Method: please specify!"};
		if (parent.pyx<1){word="PayPal"};
	document.write("<br>Payment by: "+word);
	
//	document.write("<p><font color=red size=+1>Holiday Time again!");
//	document.write("<br>You can send in your order at any time, but it cannot be processed before April 20th 2010.</font>");
	
	document.write("<p>To place your order, copy this page (Select All, Copy, then Paste data) into an ordinary email and send by your usual system to:<p>");
	document.write('<A HREF="MAILTO: hc@machin-stamp.co.uk">hc@machin-stamp.co.uk</A>');
	document.write("<p>Your order will be confirmed as soon as possible.");
	document.write("<font color=brown><H3>Please remember to add your personal details!</H3></font>");
	document.write("<p>Name:");
	document.write("<p>Address:");
	document.write("<p>Email:");
	document.write("<p><p><p>Thank you.");
	document.close();
	};

	function formwrite(){
	document.write("<H3>These are your selections:</H3><PRE><P></PRE>");
	document.write("<TABLE BGCOLOR=FFFFE0 width=82% border=0>");
	document.write("<TR><TD WIDTH=7><FONT COLOR=navy><PRE> <U>QTY</U></TD><TD WIDTH=8><FONT COLOR=navy><PRE>  <U>ITEM</U>  <U>&amp;</U></TD><TD WIDTH=9><FONT COLOR=navy><PRE> <U>PRICE</U></TD><TD><FONT COLOR=navy><PRE>  <U>DETAILS (Add comments)</U></TD></TR>");
	end=parent.si;
	if(parent.fdt==0){
	    document.write("<TR><TD colspan=4 align=center><FONT COLOR='NAVY'><PRE><I><B>** NOTHING SELECTED, SO FAR. **</B></I></TD></TR>");
		};
	i=0; j=0;
	while(i<end){
			document.write("<TR><TD colspan=4 NOWRAP><input name='xrc_"+(j+1000)+"q' size=3 value=0 onChange='newTotal(this.name,this.value)'>&nbsp;");
			document.orderHC.elements[j*3].value=parent.qty[i];
			document.write("<INPUT TYPE='TEXT' NAME='c_"+(j+1000)+"s' TYPE='text' SIZE=20 onFocus='blur()'>&nbsp;");
			document.orderHC.elements[j*3+1].value=parent.selection[i]+" @ "+parent.each[i];
			document.write("<INPUT NAME='c_"+(j+1000)+"x' TYPE='text' value='' SIZE=29 onChange='specIns(this.name,this.value)'></TD></TR>");
			document.orderHC.elements[j*3+2].value=parent.special[i];
			j++
		i++
		};
	document.write("<TR><TD colspan=2 valign=parent><FONT COLOR='NAVY'><CENTER><PRE><B>Extra Items: </B>\n\n\n\nPlease enter \nthe  <B>Total   \nprice</B> of any \n<B>Extra  items </B>\nbelow.       </CENTER></FONT></TD><TD colspan=2><TextArea name='xr_Extras_ct' rows=7 cols=37 onChange='parent.otherTxt=this.value'></textarea></TD></TR>");
	document.write("<TR><TD COLSPAN=2 align=right><FONT COLOR='NAVY'><PRE><B>Extras Total: </B>&#163;</TD><TD><INPUT NAME='xr_Extras_Cost_ct' TYPE='text' SIZE=9 onChange='addOther(this.value)'></TD><TD><FONT COLOR='NAVY'><PRE> Please add, if applicable.</FONT></TD></TR>");
	document.write("<TR><TD COLSPAN=2 align=right><FONT COLOR='NAVY'><PRE>+ Selections= &#163;</TD><TD ><INPUT NAME='xr_Items_Total_ct' TYPE='text' SIZE=9 value='0' onFocus='blur()'></TD></TR>");
	document.write("<TR><TD COLSPAN=2 align=right><FONT COLOR='NAVY'><PRE>- Discount: &#163;</TD><TD><INPUT NAME='xr_Discount_ct' TYPE='text' SIZE=8 value='0' onFocus='blur()'></TD><TD><FONT COLOR='NAVY'><PRE>(Where applicable).</FONT></TD></TR>");
	document.write("<TR><TD COLSPAN=2 align=right><FONT COLOR='NAVY'><PRE>Making: &#163;</TD><TD><INPUT NAME='xr_Makes_ct' TYPE='text' SIZE=9 value='0' onFocus='blur()'></TD><TD><FONT COLOR='NAVY'><PRE> Postage is extra, see below.</FONT></TD></TR>");
	ft();
	details();
	if(parent.otherTxt>""){
		document.orderHC.xr_Extras_ct.value=parent.otherTxt};
	if(parent.other>0){
		document.orderHC.xr_Extras_Cost_ct.value=pod(parent.other/100)};
	document.write('<TR><TD colspan=2 align=right><FONT COLOR="NAVY"><PRE><B>* Postage:</B> </TD><TD COLSPAN=3><PRE><select name="xr_Post_ct" size=1 onChange="psb(this.selectedIndex);"><option value="0_blank">Please select a postage method<option value="41_UK Ord">UK Ordinary (41p)<option value="0_UK Free">FREE (UK only, orders over &#163;15)<option value="505_UK Spec">UK Special Delivery (&pound;5.05)<option value="114_Europe">EUROPE Airmail [own risk] (&pound;1.14)<option value="789_EU Sig">EUROPE Signed for Airmail (&pound;7.89)<option value="182_WW Ord">WORLDWIDE Airmail [own risk](&pound;1.82)<option value="857_WW Sig">WORLDWIDE Signed for Airmail (&pound;8.57)</select></TD></TR>');
	document.write("<TR><TD colspan=2 align=right><FONT COLOR='NAVY'><PRE>Final Total: &#163; </TD><TD COLSPAN=1><INPUT NAME='xr_Final_Total_ct' TYPE='text' SIZE=9> </FONT></TD><TD> </TD></TR>");
	document.write('<TR><TD colspan=2 align=right><FONT COLOR="NAVY"><PRE><B>* Payment:</B> </TD><TD COLSPAN=2><PRE><select name="xr_Pay_By_ct" size=1 onChange="pyb(this.selectedIndex);"><option value="PayPal">PayPal&nbsp;<option value="chq">Sterling Cheque<option value="Other">Other Method</select></TD></TR>');
//	document.write('<TR><TD colspan=2 align=right><FONT COLOR="NAVY"><PRE><B>* Name:</B> </TD><TD colspan=2><input name="xr_Name_ct" size=36 value=""></FONT></TD></TR>');
//	document.write('<TR><TD colspan=2 align=right><FONT COLOR="NAVY"><PRE>Customer No: </TD><TD><input name="xr_Customer_No_ct" size=6></TD><TD><FONT COLOR="NAVY"><PRE> (if known)</TD></TR>');
//	document.write('<TR><TD colspan=2 align=right valign=parent><FONT COLOR="NAVY"><PRE><B>* Address:</B> </TD><TD colspan=2><TextArea name="xr_Address_ct" rows=7 cols=37></textarea></FONT></TD></TR>');
//	document.write('<TR><TD colspan=2 align=right><FONT COLOR="NAVY"><PRE><B>* E-mail:</B> </TD><TD colspan=2><input name="xr_E_mail_ct" size=36></FONT></TD></TR>');
//	document.write('<TR><TD colspan=2 align=right><FONT COLOR="NAVY"><PRE>Telephone: </TD><TD colspan=2><input name="xr_Phone_ct" size=36></FONT></TD></TR>');
	document.write("<TR><TD colspan=4><PRE> </TD></TR>");
	document.write('<TR><td> </td><td> </td><td><input type="button" value="List Items Selected to enable Ordering" onClick="textwrite()"></td><TD>&nbsp;&nbsp;</td><TD>&nbsp;&nbsp;<input type="reset" value="Clear All Items" onClick="clearall()"></TD></TR>');
	document.write("<TR><TD colspan=4><PRE> </TD></TR>");
	document.write("</TABLE>");
	if (end==0){
		document.orderHC.reset();
		};
	}


	function ft(){
			document.orderHC.xr_Items_Total_ct.value=pod(parent.totall/100);
			if (parent.totall>=1){
				document.orderHC.xr_Discount_ct.value=parent.dc;
				document.orderHC.xr_Makes_ct.value=parent.fdt;
							}
			else{
		 		 document.orderHC.xr_Discount_ct.value=0;
		 		 document.orderHC.xr_Makes_ct.value=pod(parent.totall/100);
				 		 	};
			}


		var tup=0;
	function totup(nd){
		tup=0;
		for(j=0;j<nd+1;j++){
			tup+=parseInt(eval(parent.cost[j]*100))
			};
		parent.totsing=tup;
		parent.totall=eval(tup+parent.other);
		if (parent.totall>=2500){
		    ta10=parent.totall*10;
			d10=Math.round(ta10/100)*10;
			m10=ta10-d10;
			parent.dc=pod(d10/1000);
			parent.fdt=pod(m10/1000);
			parent.due=parent.fdt;
			
			}
		else{
			parent.dc=0; //Discount;
			parent.fdt=pod(parent.totall/100);
			}
		}


	var po=0;
	function psb(ix){
		po=document.orderHC.xr_Post_ct.options[ix].value;
		px=parseInt(po);
		tf(px);
		parent.pix=ix;
		parent.xp=px;
		htp();
	}


	function pyb(ix){
		parent.pyx=ix;
		htp();
	}


	 function tf(px){
		mkn=Math.round(document.orderHC.xr_Makes_ct.value*100+px)/100;
		document.orderHC.xr_Final_Total_ct.value=pod(mkn);
		parent.due=mkn;
	}


	  function htp(){
		document.orderHC.xr_Pay_By_ct.focus();
	}


	function clearall(){
		parent.si=0;parent.totsing=0;parent.other=0;parent.otherTxt="";
		parent.totall=0;parent.dc=0;parent.fdt=0;parent.pix=0;parent.xp=0;
		}		


	function validate(){
		if(document.orderHC.xr_E_mail_ct.value==""){
			alert("Error: Form is still incomplete. Please enter at least your E-Mail Address!");}
		else {document.orderHC.submit();}
	}
