﻿var PageURL = 'http://www.sendamassage.co.nz';
var PageTitle = 'send a massage';
var Comment = 'send a massage';

	function CheckQty(myfield, e)
	{
		var key;
		var keychar;
		
		if (window.event)
		   key = window.event.keyCode;
		else if (e)
		   key = e.which;

		keychar = String.fromCharCode(key);
		if ((("0123456789").indexOf(keychar) > -1))
			myfield.value=keychar;
			
		CalcTotal();
		return false;
	};
	function AddMessage()
	{
		CalcTotal();
		return true;
	};
	function CalcTotal()
	{
		var ammounttotal=0;	
   		var ammount30 = document._qty.qty30.value;
   		var ammount45 = document._qty.qty45.value;
   		var ammount60 = document._qty.qty60.value;
   		var ammount90 = document._qty.qty90.value;
   		var ammounttea = document._qty.qtytea.value;

		if ((ammount30>0) && (ammount30<10))
			ammounttotal+=(ammount30*45);
		
		if ((ammount45>0) && (ammount45<10))
			ammounttotal+=(ammount45*60);
		
		if ((ammount60>0) && (ammount60<10))
			ammounttotal+=(ammount60*70);
		
		if ((ammount90>0) && (ammount90<10))
			ammounttotal+=(ammount90*120);
		
		if ((ammounttea>0) && (ammounttea<10))
			ammounttotal+=(ammounttea*12);
		
		if (document._messagecbx.qtymsg.checked == true)
   			ammounttotal+=3;
   		
		document._total.itemstotal.value =  "$"+ammounttotal+".00";
		document._total.shipping.value =  "$5.00";
		ammounttotal+=5;

		document._total.total.value =  "$"+ammounttotal+".00";

		return false;		
	};
	function CheckOut()
	{

		var dname = document._address.name.value;
		var daddress = document._address.address.value;
		var dsuburb = document._address.suburb.value;
		var dcity = document._address.city.value;
		var dpostcode = document._address.postcode.value;
		var dinstruct = document._address.instructions.value;

		if ((dname.length==0) || (daddress.length==0) || (dsuburb.length==0) || (dcity.length==0) || (dpostcode.length==0))
		{
			alert("Please enter all required fields of delivery address first");
			return false;
		}	


   		var msgdata = document._message.messag.value;
   		if ((msgdata.length>0) && (document._messagecbx.qtymsg.checked==false))
   		{
			alert("If you would like to include a greeting card, please check 'Select' box");
			return false;
   		}

		var ammounttotal=0;	
		var ammount30 = document._qty.qty30.value;
   		var ammount45 = document._qty.qty45.value;
   		var ammount60 = document._qty.qty60.value;
   		var ammount90 = document._qty.qty90.value;
   		var ammounttea = document._qty.qtytea.value;
		var prodtext="";

		if ((ammount30>0) && (ammount30<10))
		{
			ammounttotal+=(ammount30*45);
			prodtext+=ammount30+"x30Min;";
		}
		if ((ammount45>0) && (ammount45<10))
		{
			ammounttotal+=(ammount45*60);
			prodtext+=ammount45+"x45Min;";
		}
		if ((ammount60>0) && (ammount60<10))
		{
			ammounttotal+=(ammount60*70);
			prodtext+=ammount60+"x60Min;";
		}
		if ((ammount90>0) && (ammount90<10))
		{
			ammounttotal+=(ammount90*120);
			prodtext+=ammount90+"x90Min;";
		}
		if ((ammounttea>0) && (ammounttea<10))
		{
			ammounttotal+=(ammounttea*12);
			prodtext+=ammounttea+"xTea;";
		}
		if (document._messagecbx.qtymsg.checked == true)
		{
			ammounttotal+=3;
			prodtext+="Msg:"+msgdata+";";
		}
		if (ammounttotal==0)
		{
			alert("Please select items before checkout");
			return false;
		}

		ammounttotal+=5;
		
		var deltext="Delivery:"+dname+","+daddress+","+dsuburb+","+dcity+","+dpostcode+";"+dinstruct;

		var href="https://www.paymate.com/PayMate/ExpressPayment?mid=ease09";
		href+="&currency=NZD&popup=true&amt="+ammounttotal+".00&amt_editable=N";
		href+="&ref="+deltext;
		href+="&proditems="+prodtext;
		href+="&return=http://www.sendamassage.co.nz/ease_send_a_massage_thankyou.html";
		window.open(href, "", 'scrollbars=yes,width=760,height=655,top=40,left=90');

		return false;
	};
