var postR = 0
var total = 0;
var tmpprice = 0;
var tmpprice2 = 0;
var tmppricez = 0;
var tmppricex = 0;
var postRange = 0;
var postRangex = 0;
var codeOk = 0;
var qtyS;
var qtyD;
var p1 = 10.95
var p2 = 9.95
var p3 = 7.90
var p4 = 5.90
var p5 = 4.80

function codeIt() { checkCode();  window.history.go(0);	}
function checkCode()
{
//alert("here");	 	
}
function changes(){	calcit();	window.history.go(0);	}
function calcit()
{
codeOk = document.formBasket.quantityI.value;
if(codeOk.length > 0) { checkCode(); } 	
if(!document.formBasket.quantityI.value)  { qtyS = 0; }
else { qtyS = document.formBasket.quantityI.value;	 }

if(!document.formBasket.quantityDB.value)  { qtyD = 0; }
else { qtyD = document.formBasket.quantityDB.value;	  }

if(qtyS == 0) { tmpprice = 0; postRange = 0; }
else if((qtyS > 0) && (qtyS < 6))  { tmpprice = p1*qtyS; postRange = 1; }
else if((qtyS > 5) && (qtyS < 11)) { tmpprice = (p1*5)+(p2*(qtyS-5)); postRange = 2; }
else if((qtyS > 10) && (qtyS < 21)) { tmpprice = (p1*5)+(p2*5)+(p3*(qtyS-10));  postRange = 3; }
else if((qtyS > 20) && (qtyS < 50)) { tmpprice = (p1*5)+(p2*5)+(p3*10)+(p4*(qtyS-20));  postRange = 4; }
else if(qtyS > 49) { tmpprice = (p1*5)+(p2*5)+(p3*10)+(p4*30)+(p5*(qtyS-50));  postRange = 5; }

if(qtyD == 0) { tmpprice2 = 0; postRangex = 0; }
else if((qtyD > 0) && (qtyD < 6)) { tmpprice2 = 61.00*qtyD; postRangex = 13; }
else if(qtyD > 5) { tmpprice2 = (61.00*5)+(50.00*(qtyD-5)); postRangex = 24; }
//alert(tmpprice);alert(tmpprice2);alert(tmppricez);		

//alert(""+qtyS+"\n"+qtyD+"\n"+postR+"\n"+tmpprice+"\n"+tmpprice2+"");
			var postx = getCookies("postx_");
//alert(""+tmppricez+"\n"+postx);			
//alert(""+postRange+"\n"+postRangex);			
		 	if(postRange + postRangex == 1)
			 {
				if(postx == 1) {	tmppricez = 0.0;	 }
				else if(postx == 2) {	tmppricez = 0.5;	 }
				else if(postx == 3) {	tmppricez = 1.0;	 }
				else  				{	tmppricez = 0.0;	 }
			 }
		 	else if(postRange + postRangex == 2)
			 {	
				if(postx == 1) {	tmppricez = 2.0;	 }
				else if(postx == 2) {	tmppricez = 2.5;	 }
				else if(postx == 3) {	tmppricez = 3.0;	 }
				else  				{	tmppricez = 0.0;	 }
			 }
		 	else if(postRange + postRangex == 3)
			 {	
				if(postx == 1) {	tmppricez = 3.5;	 }
				else if(postx == 2) {	tmppricez = 4.0;	 }
				else if(postx == 3) {	tmppricez = 6.5;	 }
				else  				{	tmppricez = 0.0;	 }
			 }
		 	else if(postRange + postRangex == 4)
			 {	
				if(postx == 1) {	tmppricez = 6.0;	 }
				else if(postx == 2) {	tmppricez = 8.0;	 }
				else if(postx == 3) {	tmppricez = 10.0;	 }
				else  				{	tmppricez = 0.0;	 }
			 }
		 	else if(postRange + postRangex == 5)
			 {	
				if(postx == 1) {	tmppricez = 10.0;	 }
				else if(postx == 2) {	tmppricez = 12.0;	 }
				else if(postx == 3) {	tmppricez = 15.0;	 }
				else  				{	tmppricez = 0.0;	 }
			 }
		 	else if(postRange + postRangex == 13)
			 {	
				if(postx == 1) {	tmppricez = 3.5;	 }
				else if(postx == 2) {	tmppricez = 4.0;	 }
				else if(postx == 3) {	tmppricez = 6.5;	 }
				else  				{	tmppricez = 0.0;	 }
			 }
		 	else if(postRange + postRangex == 14)
			 {	
				if(postx == 1) {	tmppricez = 3.5;	 }
				else if(postx == 2) {	tmppricez = 4.5;	 }
				else if(postx == 3) {	tmppricez = 7.50;	 }
				else  				{	tmppricez = 0.0;	 }
			 }
		 	else if(postRange + postRangex == 15)
			 {	
				if(postx == 1) {	tmppricez = 5.5;	 }
				else if(postx == 2) {	tmppricez = 6.5;	 }
				else if(postx == 3) {	tmppricez = 9.5;	 }
				else  				{	tmppricez = 0.0;	 }
			 }
		 	else if(postRange + postRangex == 16)
			 {	
				if(postx == 1) {	tmppricez = 7.0;	 }
				else if(postx == 2) {	tmppricez = 8.0;	 }
				else if(postx == 3) {	tmppricez = 13.0;	 }
				else  				{	tmppricez = 0.0;	 }
			 }
		 	else if(postRange + postRangex == 17)
			 {	
				if(postx == 1) {	tmppricez = 13.5;	 }
				else if(postx == 2) {	tmppricez = 16.0;	 }
				else if(postx == 3) {	tmppricez = 21.5;	 }
				else  				{	tmppricez = 0.0;	 }
			 }
		 	else if(postRange + postRangex == 24)
			 {	
				if(postx == 1) {	tmppricez = 10.0;	 }
				else if(postx == 2) {	tmppricez = 12.0;	 }
				else if(postx == 3) {	tmppricez = 15.0;	 }
				else  				{	tmppricez = 0.0;	 }
			 }
		 	else if(postRange + postRangex == 25)
			 {	
				if(postx == 1) {	tmppricez = 10.0;	 }
				else if(postx == 2) {	tmppricez = 12.5;	 }
				else if(postx == 3) {	tmppricez = 16.0;	 }
				else  				{	tmppricez = 0.0;	 }
			 }
		 	else if(postRange + postRangex == 26)
			 {	
				if(postx == 1) {	tmppricez = 12.0;	 }
				else if(postx == 2) {	tmppricez = 14.5;	 }
				else if(postx == 3) {	tmppricez = 18.0;	 }
				else  				{	tmppricez = 0.0;	 }
			 }
		 	else if(postRange + postRangex == 27)
			 {	
				if(postx == 1) {	tmppricez = 13.5;	 }
				else if(postx == 2) {	tmppricez = 16.0;	 }
				else if(postx == 3) {	tmppricez = 21.5;	 }
				else  				{	tmppricez = 0.0;	 }
			 }
		 	else if(postRange + postRangex == 28)
			 {	
				if(postx == 1) {	tmppricez = 20.0;	 }
				else if(postx == 2) {	tmppricez = 24.0;	 }
				else if(postx == 3) {	tmppricez = 30.0;	 }
				else  				{	tmppricez = 0.0;	 }
			 }
			else {	tmppricez = 0;	 }
	 
//alert(tmpprice);alert(tmpprice2);alert(tmppricez);		
tmppricex = tmpprice+tmpprice2+tmppricez;
setCookie_arr("qtyS_",""+tmpprice+"",expdate);
setCookie_arr("qtySq_",""+qtyS+"",expdate);
setCookie_arr("qtyD_",""+tmpprice2+"",expdate);
setCookie_arr("qtyDq_",""+qtyD+"",expdate);
setCookie_arr("total_",""+tmppricex+"",expdate);
//setCookie_arr("post_",""+postRange+"",expdate);
setCookie_arr("postP_",""+tmppricez+"",expdate);

var qtyX = getCookies("qtyS_");  if((qtyX == "undefned") || (qtyX == null)) {   alert("You are blocking Aquavis.co.uk cookies\nPlease allow cookies from www.aquavis.co.uk to continue");  }
}
function getInfo(name)
{
	var tmppricez = getCookies(name);
	if(name == "post_") {	var postx = getCookies("postx_"); document.forms['formBasket'].postr.selectedIndex=postx;	return; }
	
	if((tmppricez == null) || (tmppricez == "undefined")) { tmppricez = 0; } 
	var amount = formatCurrency(tmppricez);	document.write(amount); 
//alert(">"+tmppricez+"<"+name);
}
function getCookies(name) 
{
        var arg = name + "=";
        var alen = arg.length;
        var clen = document.cookie.length;
        var i = 0;
        while (i < clen) 
		{
        		var j = i + alen;
                if (document.cookie.substring(i, j) == arg) {  return getCookieVal (j); }
		        i = document.cookie.indexOf(" ", i) + 1;
                if (i == 0) break; 
        }
return null;
}
function getCookieVal (offset) {
        var endstr = document.cookie.indexOf (";", offset);
        if (endstr == -1) {  endstr = document.cookie.length; } 
        return unescape(document.cookie.substring(offset, endstr));
}
// -------------------------------------- set the cookie
function setCookie_arr (name, value, expires) 
{
    if (!expires) expires = new Date();
	document.cookie = name + "=" + escape (value) + 
	"; expires=" + expires.toGMTString() +  "; path=/";
}
//----------------------------------------------------------------------------------------------------
var expdate = new Date();
expdate.setTime (expdate.getTime() +  (24 * 60 * 60 * 1000 * 1));  
//----------------------------------------------------------------------------------------------------
function formvalidation()
{
			return(validateIt());
}
//-------------------------------------------------------------------------------------------------------------------------------
function validateIt()
{

var ok = document.forms['formBasket'].postr.selectedIndex;
	if(!ok)
     {
	 	alert("Please select your region");
		document.forms['formBasket'].postr.selectedIndex=0; 
//		document.forms['formBasket'].postr.select.focus();
		return false; 
	 }
	ok = document.forms['formBasket'].readIt.checked;	
	if(!ok) 
	 { 
	 	alert("Please read our terms of supply, and check the box to say that you have read and understand them in full");   
		return false; 
	}
	

}
//----------------------------------------------------------------------------------------------------
function formatCurrency(num) {
num = num.toString().replace(/\£|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
pence = num%100;
num = Math.floor(num/100).toString();
if(pence<10)
pence = "0" + pence;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + '£' + num + '.' + pence);
}
//----------------------------------------------------------------------------------------------------
function formatNumber(num) {
num = num.toString().replace(/\£|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
pence = num%100;
num = Math.floor(num/100).toString();
if(pence<10)
pence = "0" + pence;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + num + '.' + pence);
}
// ---------------------------------------------------------------------------------------------------
function goPaypal()
{	
document.write("<div align='center'>");
	document.write("<form onsubmit='return formvalidation()' name='paypalit' action='https://www.paypal.com/cgi-bin/webscr' method='post'>");
	document.write("<input type='hidden' name='cmd' 			value='_cart'>");
	document.write("<input type='hidden' name='upload' 			value='1'>");
	document.write("<input type='hidden' name='business'  		value='orders@aquavis.co.uk'>");
	document.write("<input type='hidden' name='currency_code'	value='GBP'>");
//	document.write("<input type='hidden' name='on0'				value='Telephone'>");
	document.write("<input.type='hidden' name='return' 			value='http://www.aquavis.co.uk/thankyou.htm'>");
	document.write("<input.type='hidden' name='image_url'  		value='http%3A//www.aquavis.co.uk/aquavis_logo.gif'>");
//  fill in the items--------------------------------------------------------------------------
	tmppricex = getCookies("qtyS_");
	tmpprice = formatNumber(tmppricex);
	tmppricex = getCookies("qtyD_");
	tmpprice2 = formatNumber(tmppricex);
	qtyS = getCookies("qtySq_");
	qtyD = getCookies("qtyDq_");
	tmppricex = getCookies("postP_");
	tmppricez = formatNumber(tmppricex);
//alert(""+qtyS+"-"+tmppricez+"\n"+qtyD+"-"+tmpprice2+"\n"+tmppricez+"-"+tmpprice+"");
	if(qtyS > 0)
     {	
	 	document.write("<input type='hidden' name='item_name_1' 	value='"+qtyS+"x Singles'>");
		document.write("<input type='hidden' name='amount_1' 		value='"+tmpprice+"'>");
//alert("<input type='hidden' name='item_name_1' 	value='"+qtyS+"x Singles'>");
//alert("<input type='hidden' name='amount_1' 		value='"+tmpprice+"'>");
		if(qtyD > 0)
    	 {	
		 	document.write("<input type='hidden' name='item_name_2' 	value='"+qtyD+"x Cartons'>");
			document.write("<input type='hidden' name='amount_2' 		value='"+tmpprice2+"'>");
//alert("<input type='hidden' name='item_name_2' 	value='"+qtyD+"x Cartons'>");
//alert("<input type='hidden' name='amount_2' 	value='"+qtyD+"'>");
		 }
	 }
	else if((qtyS == 0) && (qtyD > 0))
     {	
	 	document.write("<input type='hidden' name='item_name_1' 	value='"+qtyD+"x Cartons'>");
		document.write("<input type='hidden' name='amount_1' 		value='"+tmpprice2+"'>");
//alert("<input type='hidden' name='item_name_1' 	value='"+qtyD+"x Cartons'>");
//alert("<input type='hidden' name='amount_1' 	value='"+tmpprice2+"'>");
	 }
 	document.write("<input type='hidden' name='shipping_1'		value='"+tmppricez+"'>");
//alert("<input type='hidden' name='shipping_1' 		value='"+tmppricez+"'>");
// -----------------------------------------------------------	
	document.write("<input type='submit' align='bottom' value='-Checkout-'>");
	document.write("</form>");
    document.write("</div>");
}
//-----------------------------------------------------------------------------------------------------