function calculate_buy() 
{
	var q1=document.getElementById("quantity1").options[document.getElementById('quantity1').selectedIndex].value;
	var q2=document.getElementById("quantity2").options[document.getElementById('quantity2').selectedIndex].value;
	var q3=document.getElementById("quantity3").options[document.getElementById('quantity3').selectedIndex].value;
	var q4=document.getElementById("quantity4").options[document.getElementById('quantity4').selectedIndex].value;
	var q5=document.getElementById("quantity5").options[document.getElementById('quantity5').selectedIndex].value;
	var q6=document.getElementById("quantity6").options[document.getElementById('quantity6').selectedIndex].value;	
	var q10=document.getElementById("quantity10").options[document.getElementById('quantity10').selectedIndex].value;
	var q9=document.getElementById("quantity9").options[document.getElementById('quantity9').selectedIndex].value;	
	
	
	var str1 = q1.split("-");
	var str2 = q2.split("-");
	var str3 = q3.split("-");
	var str4 = q4.split("-");
	var str5 = q5.split("-");
	var str6 = q6.split("-");
	var str10 = q10.split("-");
	var str9 = q9.split("-");
	
	q1=parseInt(str1[0]);
	q2=parseInt(str2[0]);	
	q3=parseInt(str3[0]);
	q4=parseInt(str4[0]);
	q5=parseInt(str5[0]);	
	q6=parseInt(str6[0]);
	q10=parseInt(str10[0]);	
	q9=parseInt(str9[0]);
	
	
	var DeliveryCost1 = parseFloat(str1[1]); 
	var DeliveryCost2 = parseFloat(str2[1]); 
	var DeliveryCost3 = parseFloat(str3[1]); 
	var DeliveryCost4 = parseFloat(str4[1]); 
	var DeliveryCost5 = parseFloat(str5[1]); 
	var DeliveryCost6 = parseFloat(str6[1]); 
	
	var DeliveryCost10 = parseFloat(str10[1]); 
	var DeliveryCost9 = parseFloat(str9[1]); 	



	
	if(q2==6)
	{
		alert("Thanks for your interest in Orbana! It seems that you're interested in a large order, so we'd like to suggest some different delivery options for you. Please contact us on +44 (0)20 7581 8972 or at info@orbana.com, and we'll sort you out immediately. Many thanks, the Orbana"+ document.buy_form.trade.value + " team." );
		document.buy_form.quantity2.options[5].selected="selected";
		q2=5;
		DeliveryCost2=12.61;		
	}
	else if(q1==7)
	{
		alert("Thanks for your interest in Orbana! It seems that you're interested in a large order, so we'd like to suggest some different delivery options for you. Please contact us on +44 (0)20 7581 8972 or at info@orbana.com, and we'll sort you out immediately. Many thanks, the Orbana"+ document.buy_form.trade.value + " team." );
		document.buy_form.quantity1.options[6].selected="selected";
		q1=6;
		DeliveryCost1=7.06;
	}
	else if(q3==6)
	{
		alert("Thanks for your interest in Orbana! It seems that you're interested in a large order, so we'd like to suggest some different delivery options for you. Please contact us on +44 (0)20 7581 8972 or at info@orbana.com, and we'll sort you out immediately. Many thanks, the Orbana"+ document.buy_form.trade.value + " team." );
		document.buy_form.quantity3.options[5].selected="selected";
		q3=5;
		DeliveryCost3=9.58;		
	}
	else if(q4==6)
	{
		alert("Thanks for your interest in Orbana! It seems that you're interested in a large order, so we'd like to suggest some different delivery options for you. Please contact us on +44 (0)20 7581 8972 or at info@orbana.com, and we'll sort you out immediately. Many thanks, the Orbana"+ document.buy_form.trade.value + " team." );
		document.buy_form.quantity4.options[5].selected="selected";
		q4=5;
		DeliveryCost4=0.00;		
	}
	else if(q5==6)
	{
		alert("Thanks for your interest in Orbana! It seems that you're interested in a large order, so we'd like to suggest some different delivery options for you. Please contact us on +44 (0)20 7581 8972 or at info@orbana.com, and we'll sort you out immediately. Many thanks, the Orbana"+ document.buy_form.trade.value + " team." );
		document.buy_form.quantity5.options[5].selected="selected";
		q5=5;
		DeliveryCost5=0.00;		
	}
	else if(q6==6)
	{
		alert("Thanks for your interest in Orbana! It seems that you're interested in a large order, so we'd like to suggest some different delivery options for you. Please contact us on +44 (0)20 7581 8972 or at info@orbana.com, and we'll sort you out immediately. Many thanks, the Orbana"+ document.buy_form.trade.value + " team." );
		document.buy_form.quantity6.options[5].selected="selected";
		q6=5;
		DeliveryCost6=0.00;		
	}	
	else if(q9==7)
	{
		alert("Thanks for your interest in Orbana! It seems that you're interested in a large order, so we'd like to suggest some different delivery options for you. Please contact us on +44 (0)20 7581 8972 or at info@orbana.com, and we'll sort you out immediately. Many thanks, the Orbana"+ document.buy_form.trade.value + " team." );
		document.buy_form.quantity9.options[6].selected="selected";
		q9=6;
		DeliveryCost5=0.00;		
	}
	else if(q10==7)
	{
		alert("Thanks for your interest in Orbana! It seems that you're interested in a large order, so we'd like to suggest some different delivery options for you. Please contact us on +44 (0)20 7581 8972 or at info@orbana.com, and we'll sort you out immediately. Many thanks, the Orbana"+ document.buy_form.trade.value + " team." );
		document.buy_form.quantity10.options[6].selected="selected";
		q10=6;
		DeliveryCost6=0.00;		
	}	
		
	
	
	// Define Prices
	
	var price1=8.00; //4 pack
	var price2=45.00; //cases
	var price3=29.00; //tubs	
	
	var price4=15.99; //Sigg Bottle
	var price5=5.99; //Sigg Pouch
	var price6=9.99; //Cap
	
	var price9=10.80; //sachet
	var price10=28.80; //sachet box

	
	
	
	var promocode=document.buy_form.p.value;
	
	//alert("hi");
	//alert(promocode);
	//	alert("hi2");
	var testcode=md5(promocode);
	
	
	
//	if (testcode=="224b520c0339a636d110023f4dcffa69"){
	if ( (testcode=="06ccdc9ffff75843c9b5a8a110509778") || (testcode=="b919c9669a5a5521d89764382c3ad9cf") ){ //bme upper and lower
	
		// take 10% off cases and tubs
		// as per 5/11/2010 this is now 10% of everything
		
	//	var cases_and_tubs=q2*price2 + q3*price3;
	//	cases_and_tubs=cases_and_tubs-(cases_and_tubs*.1);
	//	var items=q1*price1 + cases_and_tubs;
		
		var all=q1*price1 + q2*price2 + q3*price3 + q4*price4 + q5*price5 + q6*price6 + q9*price9 + q10*price10;
		// sub 10%
		all=all-(all*.1);
		
		//need to add other products
		//all=all+(q4*price4 + q5*price5 + q6*price6);
		
		//need to add other products
		//all=all+(q9*price9 + q10*price10);
		
		var items=all;
	}else if( (testcode=="b1133a295600378986c54ee6c7de5d90") || (testcode=="eafc6711a319812daa4796ee1ecab311") ){   //B11 upper and lower
		/*  Sachet 6Pack = £6.60
			Sachet 16 Pack =£17.60
			Tub (800g) = £17.40
			Bottle 4Pack = £5
			Bottle 24Pack = £28.10 */
					
			//New price
			var price1=5.00; //4 pack
	var price2=28.10; //cases
	var price3=17.40; //tubs	
	var price9=6.60; //sachet 6pack
	var price10=17.60; //sachet box 16pack
			
			var all=q1*price1 + q2*price2 + q3*price3 + q4*price4 + q5*price5 + q6*price6 + q9*price9 + q10*price10;
			
			DeliveryCost1=0;
			var items=all;

	/*
	}else if( (testcode=="4e1b34e1a5991fc5e0d07d903d0ab64b") || (testcode=="7c99ea37fad4e4291d0a25e4d703c481") ){   //B4 upper and lower
		// Discount for this code: £5.00 for a four pack (37.5% Discount + free delivery)
			// item 1 = 4 pack
			
			// as per 5/11/2010 this is now 40% of everything
					
			//var tempPrice1 = 5;
			var all=q1*price1 + q2*price2 + q3*price3 + q4*price4 + q5*price5 + q6*price6 + q9*price9 + q10*price10;
			all=all-(all*.4);
			DeliveryCost1=0;
			var items=all;
		
	}else if( (testcode=="db7919b9c48ca8995c69fed60277e298") ||  (testcode=="e9b02e2c111be3695c7927335aa66aa2") ||  (testcode=="7992cb4d88a873a7b7609b01c200adaa") ){  //Btb  upper and lower and combined
		// Discount for this code: £17.40 for a tub (40% Discount + free delivery)	
		// tub is 3
			var tempPrice3 = 17.40;
			var items=q1*price1 + q2*price2 + q3*tempPrice3 + q4*price4 + q5*price5 + q6*price6 + q9*price9 + q10*price10;
			//DeliveryCost3=0; #not free del as per email 04/02/2010
*/
	}else{
		var items=q1*price1 + q2*price2 + q3*price3 + q4*price4 + q5*price5 + q6*price6 + q9*price9 + q10*price10;
	}


	//q1=4 pack
	//q2=24 pack
	//q3= tubby
	//q4=
	//q5=
	//q6=
	
	
	//special delivery combinations 
	if ((q3==1) && (q1==1) && (q2==0)){ //1 Tub + 1 four pack = £5.20
		delivery=0.00;	
	}else if ( (q3==1) && ( (q1>1) && (q1<7) ) && (q2==0) ){
		delivery=0.00;
	}else if ( ( (q3>1) && (q3<6) ) && ((q1>0) || (q2>0)) ){
		delivery=0.00;
	}else if ( (q2>0) && ( (q1>0) || (q3>0) ) ){
		delivery=0.00;
	}else{
		var delivery= DeliveryCost1 +  DeliveryCost2 +  DeliveryCost3;
	}

	var subtotal= items+delivery;
	var VAT = 0;
	var total = subtotal+VAT;
	
// Display Prices
	
	var totalQty = q1+q2+q3+q4+q5+q6+q9+q10;	

	document.getElementById("items").innerHTML='&pound;'+items.toFixed(2);
	document.getElementById("delivery").innerHTML='&pound;'+delivery.toFixed(2);
	document.getElementById("subtotal").innerHTML='&pound;'+subtotal.toFixed(2);
	document.getElementById("total").innerHTML='&pound;'+total.toFixed(2);
	
	/* Set the order summary and save in the document's hidden field */
	var summary="";
	if(q1>0)
	{ summary="* 4 X 40g bottles - "+q1+" four pack(s)| "; }
	if(q2>0)
	{ summary+="* 24 X 40g bottles - "+q2+" case(s)| "; }
	if(q3>0)
	{ summary+="* 800g tub - "+q3+" tub(s)|"; }
	if(q4>0)
	{ summary+="* Sigg Bottles - "+q4+" pack(s)|"; }
	if(q5>0)
	{ summary+="* Sigg Pouch - "+q5+" pack(s)|"; }	
	if(q6>0)
	{ summary+="* Cap - "+q6+" cap(s)|"; }	
	if(q9>0)
	{ summary+="* sachet - "+q9+" pack(s)|"; }	
	if(q10>0)
	{ summary+="* sachet box - "+q10+" cap(s)|"; }	
	document.buy_form.summary.value=summary;
	document.buy_form.grandtotal.value=items;
	document.buy_form.carriage.value=delivery;	
	
}


function checkit()
{
	//alert('hi');
	var product1=document.buy_form.quantity1.selectedIndex;
//	alert(product1);
	var product2=document.buy_form.quantity2.selectedIndex;
	var product3=document.buy_form.quantity3.selectedIndex;
	var product4=document.buy_form.quantity4.selectedIndex;
	var product5=document.buy_form.quantity5.selectedIndex;
	var product6=document.buy_form.quantity6.selectedIndex;
	var product9=document.buy_form.quantity9.selectedIndex;
	var product10=document.buy_form.quantity10.selectedIndex;
	
	//alter('hi2');
	
	if(product1==0 && product2==0 && product3==0 && product4==0 && product5==0 && product6==0 && product9==0 && product10==0)
	{
		alert('Please select product quantity. ');
		return false;
	} 
	
	

	 
	if ( (document.buy_form.f.value=="") && (document.buy_form.p.value != "") ){
		alert('Please enter where you got your promotion code');
		return false;
 
		
	}
return true;
}


function echeck(str) {

		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID");
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID");
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID");
		    return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID");
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID");
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID");
		    return false;
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID");
		    return false;
		 }

 		 return true;					
	}


function ValidateForm()
{
	var fieldFilter=/^ *$/;
	var emailFilter=/^[a-zA-Z\-0-9_'\.]+\@[a-zA-Z0-9\-.]+$/;
	var phoneFilter=/^[0-9 ]+$/;
	var postcodeFilter=/^[A-Za-z]{1,2}[0-9]{1,2}[a-zA-Z]? [0-9]{1,2}[a-zA-Z]{2}$/;
	var passwordFilter=/^[^ ]{4,}$/;
	
	if(fieldFilter.test(document.detail_form.firstname.value)==true)
	{
		alert('Please enter a valid first name!');
		document.detail_form.firstname.focus();
		return false;
	}
	else if(fieldFilter.test(document.detail_form.lastname.value)==true)
	{
		alert('Please enter a valid last name!');
		document.detail_form.lastname.focus();
		return false;
	}
	else if(emailFilter.test(document.detail_form.email.value)==false)
	{
		alert('Please enter a valid email address!');
		document.detail_form.email.focus();
		return false;
	}
	else if(passwordFilter.test(document.detail_form.password.value)==false)
	{
		alert('Please enter a valid password with at least 4 characters!');
		document.detail_form.password.focus();
		return false;
	}
	else if(passwordFilter.test(document.detail_form.confirm_password.value)==false || document.detail_form.confirm_password.value!=document.detail_form.password.value)
	{
		alert('The characters entered in \'Confirm Password\' field should be the same as the \'Password\' field!');
		document.detail_form.confirm_password.focus();
		return false;
	}
	else if(fieldFilter.test(document.detail_form.address.value)==true)
	{
		alert('Please enter a valid address!');
		document.detail_form.address.focus();
		return false;
	}
	else if(fieldFilter.test(document.detail_form.city.value)==true)
	{
		alert('Please enter your city!');
		document.detail_form.city.focus();
		return false;
	}
	else if(fieldFilter.test(document.detail_form.county.value)==true)
	{
		alert('Please enter your county!');
		document.detail_form.county.focus();
		return false;
	}
	else if(postcodeFilter.test(document.detail_form.postcode.value)==false)
	{
		alert('Please enter a valid post code!\n For e.g. \'SW1 5UZ\'');
		document.detail_form.postcode.focus();
		return false;
	}
	else if(fieldFilter.test(document.detail_form.telephone.value)==true)
	{
		alert('Please enter a valid phone number!');
		document.detail_form.telephone.focus();
		return false;
	}
	else
		return true;	
	
 }
 
 
 function ValidateUpdateForm()
{
	var fieldFilter=/^ *$/;
	var phoneFilter=/^[0-9 ]+$/;
	var postcodeFilter=/^[A-Za-z]{1,2}[0-9]{1,2}[a-zA-Z]? [0-9]{1,2}[a-zA-Z]{2}$/;
	var passwordFilter=/^[^ ]{4,}$/;
	
	if(fieldFilter.test(document.detail_form.firstname.value)==true)
	{
		alert('Please enter a valid first name!');
		document.detail_form.firstname.focus();
		return false;
	}
	else if(fieldFilter.test(document.detail_form.lastname.value)==true)
	{
		alert('Please enter a valid last name!');
		document.detail_form.lastname.focus();
		return false;
	}
	else if(passwordFilter.test(document.detail_form.password.value)==false)
	{
		alert('Please enter a valid password with at least 4 characters!');
		document.detail_form.password.focus();
		return false;
	}
	else if(passwordFilter.test(document.detail_form.confirm_password.value)==false || document.detail_form.confirm_password.value!=document.detail_form.password.value)
	{
		alert('The characters entered in \'Confirm Password\' field should be the same as the \'Password\' field!');
		document.detail_form.confirm_password.focus();
		return false;
	}
	else if(fieldFilter.test(document.detail_form.address.value)==true)
	{
		alert('Please enter a valid address!');
		document.detail_form.address.focus();
		return false;
	}
	else if(fieldFilter.test(document.detail_form.city.value)==true)
	{
		alert('Please enter your city!');
		document.detail_form.city.focus();
		return false;
	}
	else if(fieldFilter.test(document.detail_form.county.value)==true)
	{
		alert('Please enter your county!');
		document.detail_form.county.focus();
		return false;
	}
	else if(postcodeFilter.test(document.detail_form.postcode.value)==false)
	{
		alert('Please enter a valid post code!\n For e.g. \'SW1 5UZ\'');
		document.detail_form.postcode.focus();
		return false;
	}
	else if(fieldFilter.test(document.detail_form.telephone.value)==true)
	{
		alert('Please enter a valid phone number!');
		document.detail_form.telephone.focus();
		return false;
	}
	else
		return true;	
	
 }

function ValidateLogin()
{
	var passwordFilter=/^[^ ]{4,}$/;
	var emailFilter=/^[a-zA-Z\-0-9_'\.]+\@[a-zA-Z0-9\-.]+$/;
	
	
	if(emailFilter.test(document.frm_login.email.value)==false)
	{
		alert('Please enter a valid email address!');
		document.frm_login.email.focus();
		return false;
	}
	else if(passwordFilter.test(document.frm_login.passkey.value)==false)
	{
		alert('Please enter a valid password !');
		document.frm_login.passkey.focus();
		return false;
	}
	else
	{
		return true;
	}

}

