function MM_swapImgRestore() { var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;}
function MM_preloadImages() { var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array(); var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++) if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}}
function MM_findObj(n, d) { var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) { d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);} if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n]; for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;}
function MM_swapImage() { var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3) if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}}


function StartUp() {
//Get form corrected
document.cart['handling'].value = handling;
document.cart['administration'].value = administration;
//Load images
MM_preloadImages('pics/topknop_over.gif','pics/orderformknop_over.gif','pics/order_over.jpg','pics/vignetkl_over.gif','pouch','#pouch');
MM_preloadImages('pics/knop_prodinfo_over.gif','pics/knop_proddesi_over.gif','pics/backknop_dn.gif')
}

function GetGuilder() {
	var qstr = document.location.href;	v=0; x=0;
	for (v=0;v<qstr.length;v++)
		{
		if (qstr.charAt(v)=='?') x = v;
		} 
	qstr = qstr.substring(x+1,qstr.length);
	if (qstr=='') qstr=dollar;
	return qstr;
}
	
function roundit(what)
{
	what=what.toString();
	var xx = what.indexOf('.')
	if (xx==-1) {what=what+'.00'; var xx = what.indexOf('.')}
	var l = what.length
	var zstr = '0000000000000000000000'
	var theInt = ''
	var theFrac = ''
	var theNo = ''
	rfac = ''
	rfacx = 0
	whatx = 0
	var rfacx = parseFloat('.005')
	if (xx == 0)		{	theInt = '0'
							whatx = 0 + parseFloat(what) + parseFloat(rfacx) 
							what = whatx + zstr
							theFrac = '' + what.substring(1, what.length) }
	else				{	theInt = what.substring(0,xx)
							whatx = parseFloat(what) + rfacx
							what = '' + whatx + zstr
							theFrac = '' + what.substring(xx+1,xx + 3) }
 theFrac = theFrac.substring(0,2)
 theNo = theInt + '.' + theFrac
 return theNo
}


function ValidateForm() {
if (document.cart['name'].value == '') {document.location.hash='orderform2'; alert('Please enter your name.'); return false;}
if (document.cart['company'].value == '') {document.location.hash='orderform2'; alert('Please enter the company name.'); return false;}
if (document.cart['address'].value == '') {document.location.hash='orderform2'; alert('Please enter your address.'); return false;}
if (document.cart['zipcode'].value == '') {document.location.hash='orderform2'; alert('Please enter your zip code.'); return false;}
if (document.cart['city'].value == '') {document.location.hash='orderform2'; alert('Please enter your city.'); return false;}
if (document.cart['country'].value == '') {document.location.hash='orderform2'; alert('Please enter country. '); return false;}
if (document.cart['email'].value == '') {document.location.hash='orderform2'; alert('Please enter your e-mail address.'); return false;}

//if (document.cart['mailservice'].value == '') {document.location.hash='orderform'; //alert('Please choose a shipment.'); return false;}
if (document.cart['payement'].value == '') {document.location.hash='orderform1'; alert('Please choose a way of paying.'); return false;}
return true;
}


function StartAt(Object) {for (i=0; i<A.length; i++) if (A[i].charAt(0)=='@' && A[i].substring(2,A[i].length)==Object) return i+1;}


function BuildCell(cLASS,cOLOR,iNPUT,pOSITION) {return('<TD ALIGN="center" HEIGHT="19" BGCOLOR="'+cOLOR+'" NOWRAP CLASS="'+cLASS+'">'+iNPUT+'</TD>');} 


function Build(object) {
var builder = new Array('<TR>','</TR>');
var row=StartAt(object), i;
var size=0;

	//BuildTop
	document.write('<TABLE border="0" cellpadding="0" cellspacing="0" width="70%">'+builder[0]);
	while (A[row+size].charAt(0)=='@') {document.write(BuildCell('LineTop','#B3C5E5','&nbsp;&nbsp;&nbsp;'+A[row+size].substring(2,A[row+size].length), size)); size++; }
	document.write(BuildCell('LineTop','#FFFFFF','&nbsp;',size+1)+BuildCell('LineTop','#B3C5E5','Order',size+2)+builder[1]);
	row+=size;

while (row+size <= A.length)
	{
	if (A[row].charAt(0)=='@') break;
	document.write(builder[0]);
	//Blauwe regel schrijven als -
	if (A[row]=='-') { 
		for (i=0; i<size; i++) document.write(BuildCell('LineRegular','#BFEFFF','&nbsp;',i));
		document.write(BuildCell('LineRegular','#FFFFFF','&nbsp;',size+1)+BuildCell('LineRegular','#BFEFFF','&nbsp;',size+2)+builder[1]);
		row++; }
	//Normale regel schrijven
	for (i=0; i<size; i++) document.write(BuildCell('LineRegular','#FFFFFF',A[row+i],i));
	document.write(BuildCell('LineRegular','#FFFFFF','&nbsp;',size+1)+BuildCell('LineRegular','#FFFFFF','<A href="Javascript:AddProduct('+row+')" onMouseOut=MM_swapImgRestore() onMouseOver=MM_swapImage("p'+row+'","","pics/order_over.jpg",1)><img name="p'+row+'" border=0 src="pics/order.jpg" width=25 height=24></A>',size+2)+builder[1]);
	row+=size+2;
	}	
	document.write('</TABLE>');
}


function BuildCart() {
var i;
var browser = navigator.appName;

for (i=0;i<10;i++)
	{
	document.write(	'<TR><TD><input type=hidden name=code'+i+' value=0><input type=text name=article'+i+' value="" size=20 onFocus="blur()"></TD>',
			'<TD><input type=text name=packaging'+i+' value="" size="20" onfocus="blur()"></TD>',
			'<TD><input type="text" name=quantity'+i+' size="4" value="" onKeyUp="CheckOnNumber('+i+')">&nbsp;x&nbsp;</TD>');

	if (browser == "Microsoft Internet Explorer")
		document.write(	'<TD><input type=text name=price'+i+' size=7 onFocus="blur()" value="0" STYLE="text-align: right">&nbsp;=&nbsp;</TD>',
				'<TD><input type="text" name=totalprice'+i+' size="10" onFocus="blur()" STYLE="text-align: right"></TD>');
	else	document.write(	'<TD><input type=text name=price'+i+' size=7 onFocus="blur()" value="0">&nbsp;=&nbsp;</TD>',
				'<TD><input type="text" name=totalprice'+i+' size="10" onFocus="blur()"></TD>');

	document.write(	'<TD ALIGN=center><input type=button value="cor." onClick=DelProduct("'+i+'")><input type=hidden name=weight'+i+' value=0></TD></TR>');
	}
}


function CheckOnNumber(w) {	//check on stupidy
var i;
for (i=0; i<document.cart['quantity'+w].value.length; i++)
	if (document.cart['quantity'+w].value.charAt(i) >= 0 && document.cart['quantity'+w].value.charAt(i) <= 9); else
	{alert('You can only multiply by numbers,\nplease try again.'); return;}
CalculateCart(); 
}

function CalculateTransport() {
var total=0;
extra = new Array(0,0);

//Calculate weight
for (i=0; i<10; i++) if (document.cart['code'+i].value != 0) total+=eval(document.cart['weight'+i].value * document.cart['quantity'+i].value);

//Categorize
if (total > 0 && total <= 500)		total=0;	if (total > 500 && total <= 1000)	total=1;
if (total > 1000 && total <= 1500)	total=2;	if (total > 1500 && total <= 2000)	total=3;
if (total > 2000 && total <= 2500)	total=4;	if (total > 2500 && total <= 3000)	total=5;
if (total > 3000 && total <= 3500)	total=6;	if (total > 3500 && total <= 4000)	total=7;
if (total > 4000 && total <= 6000)	total=8;	if (total > 6000 && total <= 8000)	total=9;
if (total > 8000 && total <= 10000)	total=10;

//Als er boven de 10kg is gekozen
if (total > 10000) {
	extra[0] = total-10000;
	if (extra[0] >= 10000) extra[0]=20; else extra[0]=extra[0]/500;
	if (total <= 20000) total=10;
	}

//Als er boven de 20kg is gekozen	
if (total > 20000) {
	extra[1] = total-20000;
	if (extra[1] > 20000) alert('Weight limit exceeded.\nPlease contact us for further information.'); else extra[1]=extra[1]/500;
	total=10;
	}

if (document.cart['mailzone'].options[document.cart['mailzone'].selectedIndex].value == 'A') total=eval(W[total*3]) + eval(W[11*3]*extra[0]) + eval(W[12*3]*extra[1]);
if (document.cart['mailzone'].options[document.cart['mailzone'].selectedIndex].value == 'B') total=eval(W[total*3+1]) + eval(W[11*3+1]*extra[0]) + eval(W[12*3+1]*extra[1]);
if (document.cart['mailzone'].options[document.cart['mailzone'].selectedIndex].value == 'C') total=eval(W[total*3+2]) + eval(W[11*3+2]*extra[0]) + eval(W[12*3+2]*extra[1]);
return total;
}

function CalculateCart() {
var i;

document.cart['subtotal'].value = '0';
document.cart['total'].value = '0';

for (i=0; i<10; i++)
	{
	if (document.cart['code'+i].value != 0)
		{
		document.cart['totalprice'+i].value = roundit(eval(document.cart['quantity'+i].value * document.cart['price'+i].value));
		document.cart['subtotal'].value = roundit(eval(document.cart['totalprice'+i].value)+eval(document.cart['subtotal'].value));
		}	 
	}
//if (document.cart['mailservice'].value == '1') document.cart['transport'].value = //roundit(CalculateTransport()); else document.cart['transport'].value = 0;
//document.cart['total'].value = roundit(eval(document.cart['transport'].value) + //eval(document.cart['subtotal'].value) + eval(handling) + eval(administration));
//}
if (document.cart['mailservice'].value == '1') document.cart['transport'].value = 0;
else document.cart['transport'].value = 0;
document.cart['total'].value = roundit(eval(document.cart['transport'].value) + eval(document.cart['subtotal'].value) + eval(handling) + eval(administration));
}


function DelProduct(rOW) {
var i;
rOW=eval(rOW);

//Empty
document.cart['code'+rOW].value=0;

//Organize
for (i=rOW; i<9; i++)
	{	document.cart['code'+i].value		= document.cart['code'+eval(i+1)].value;
		document.cart['article'+i].value	= document.cart['article'+eval(i+1)].value;
		document.cart['packaging'+i].value	= document.cart['packaging'+eval(i+1)].value;
		document.cart['quantity'+i].value	= document.cart['quantity'+eval(i+1)].value;
		document.cart['price'+i].value		= document.cart['price'+eval(i+1)].value;
		document.cart['totalprice'+i].value	= document.cart['totalprice'+eval(i+1)].value; 	}
document.cart['code'+9].value=0;
document.cart['article'+9].value='';
document.cart['packaging'+9].value='';
document.cart['quantity'+9].value='';
document.cart['price'+9].value='0';
document.cart['totalprice'+9].value='';
CalculateCart();
}


function AddProduct(pRODUCT) {
var size=0, i=pRODUCT;
var REF, Packaging, Price;
 
//Find Categories and size
while (i >= 0)	{	if (A[i].charAt(0)=='@') 
						{size++;
						//Put current values for REF
						if (A[i].substring(2,5)=='REF') REF=size;
						}
					if (A[i].charAt(0)!='@' && size>0) {size--; break;}
					Packaging=i;
					i--; }
//Reverse values
REF=size-REF;  Price=size+1;

//Check articles and increase amount or add article
for (i=0; i<10; i++)
	{
	if (document.cart['code'+i].value==pRODUCT) {alert('This product has already been added.\nYou can change the quantity later on.'); break;}
	if (document.cart['code'+i].value==0) {
		document.cart['code'+i].value=parseInt(pRODUCT);
		document.cart['article'+i].value=A[pRODUCT+REF];
		document.cart['packaging'+i].value = A[Packaging].substring(2,A[Packaging].length);
		document.cart['quantity'+i].value='1';
		document.cart['price'+i].value= A[pRODUCT+Price];
		document.cart['weight'+i].value=A[pRODUCT+Price-1];
		alert('This product has been added to the shopping cart.\nYou can change the quantity later on.'); break;}
	if (i==9) alert('You can only add up to 10 products at a time.\nPlease send us an e-mail for more information.');
	}
CalculateCart();
}
