


//on load code

window.onload = setonload;



function setonload() {

//    document.onkeypress = onKeyPress; //disabled ftb

//	set up email address for form

	try { 
	var kcdomain = "kingscare.org";
	document.kcform.recipient.value = "george@" + kcdomain;
	if (document.kcform.reference.value != "")
		{document.kcform.email.value = "care@" + kcdomain;}
	}catch(err) {}
		
	try {document.kcform.CP01_qty.focus();} catch(err) {}				//force 1st field to be selected
	try {document.kcform.realname.focus();} catch(err) {}				//force 1st field to be selected
	try {document.kcform.amount.focus();} catch(err) {}				//force 1st field to be selected

// updated date

	var d = document.lastModified;
	var dd;
	if (d.substring(2,3) == "/")					//Test for mm/dd/yyyy format
		{dd = d.substring(3,6) + d.substring(0,3) + d.substring(6,10);	//change to dd/mm/yyyy 
		}else
		{var l = d.length-12;						//remove time text
		dd = d.substring(l,0);
	}
	document.formup.date1.value = "Page updated "+dd;

//	get parameters and redo spaces

    var astring = window.location.search;
    astring = astring.substr(1);						//remove ?
    var x;
	for (x = 1; x <= 12; x++)
		{astring = astring.replace("%20"," ");
		 astring = astring.replace("%A3","£");
		 astring = astring.replace("&amp;","&");}

	var textarray = astring.split('&');
	var textno = textarray.length;
	
	for (x=0; x < textno; x++)
		{var pstring = textarray[x];

 		if (pstring.substr(0,5) == "fund=")			//	If fund= in the URL then use that fund 
    		{
    		var block = document.getElementById("presetfund");
    		block.style.display="block";
    		var block2 = document.getElementById("choosefund");
    		block2.style.display="none";
			
			var fund = pstring.substr(5);
    		document.kcform.descfund.value = fund;
			
			if(fund.substr(4,1) == ":")
				{
				var block3 = document.getElementById("chooseage");
    			block3.style.display="none";
				var block4 = document.getElementById("sphoto");
    			block4.style.display="block";
				var block5 = document.getElementById("sphoto2");
    			block5.src="../spi/"+fund.substr(0,4)+".jpg";
				}
			}
			
			
///		<p><img id="sphoto2" border="0" src="../spi/E071.jpg" width="100" height="99">

		if (pstring.substr(0,7) == "amount=") 		//	If amount= in the URL then put in form
    		{var amount = pstring.substr(7);
    		document.kcform.amount.value = amount;
			document.kcform.M_GA.focus();}					//  force 1st field to be selected


    		
		if (pstring.substr(0,5) == "send=") 		//	If send= in the URL then put in form
    		{var send = pstring.substr(5);
    		document.kcform.sendme.value = send;}
    	
    	}
  }

function GA(frm) {
  frm.cartId.value = (frm.M_GA.checked==true ? "Please treat all donations to Kingscare in the last six years as Gift Aid"
  : "Not Specifically Gift Aided (default)");
  frm.M_GAMsg.value = frm.cartId.value;
  return true;}
  
function GANO(frm) {
  frm.cartId.value = (frm.M_GANO.checked==true ? "Do NOT treat this donation as Gift Aid" : frm.cartId.value);
  frm.M_GAMsg.value = frm.cartId.value;
  return true;}
  

function getCSymbol(curr) {
  switch (curr) {
  case "GBP" : symbol = "£";break;
  case "EUR" : symbol = "€";break;
  default : symbol = "$";}
  return symbol;}
  
function chkAmount() {
	if (document.kcform.amount.value == 0)
  		{alert('A donation amount is needed');
  	 	document.kcform.amount.focus();
		document.kcform.amount.select();
  		return false;}
	else {
    	var block = document.getElementById("presetfund");
 	  	if	(block.style.display=="block")
			{document.kcform.desc.value=document.kcform.descfund.value;}
		else{
			document.kcform.desc.value=document.kcform.descselect.options[document.kcform.descselect.selectedIndex].text;
			}}
	return true;}
				
// set input values for paypal form
//  	document.paypal.currency_code.value = document.kcform.currency.value;		
//  	document.paypal.item_name.value = "Donation: "+document.kcform.desc.value;
//  	document.paypal.custom.value = document.kcform.cartId.value;
//  	document.paypal.item_number.value = document.kcform.cartId.value;
//  	document.paypal.amount.value = document.kcform.amount.value;
  	

function chkgift() {
  if (parseInt(document.kcform.GTotal.value) == 0 )
	  {alert('At least 1 care package is required');
	  document.kcform.CP01_qty.focus();
	  document.kcform.CP01_qty.select();
	  return false;
  	  }
  else
	  {if (document.kcform.CP01_value.value == 0 )
	  			{document.kcform.CP01_value.value = "";
	  			document.kcform.CP01_price.value = "";}
	  if (document.kcform.CP02_value.value == 0 )
	  			{document.kcform.CP02_value.value = "";
	  			document.kcform.CP02_price.value = "";}
	  if (document.kcform.CP02_value.value == 0 )
	  			{document.kcform.CP02_value.value = "";
	  			document.kcform.CP02_price.value = "";}
	  if (document.kcform.CP03_value.value == 0 )
	  			{document.kcform.CP03_value.value = "";
	  			document.kcform.CP03_price.value = "";}
	  if (document.kcform.CP04_value.value == 0 )
	  			{document.kcform.CP04_value.value = "";
	  			document.kcform.CP04_price.value = "";}
	  if (document.kcform.CP05_value.value == 0 )
	  			{document.kcform.CP05_value.value = "";
	  			document.kcform.CP05_price.value = "";}
	  if (document.kcform.CP06_value.value == 0 )
	  			{document.kcform.CP06_value.value = "";
	  			document.kcform.CP06_price.value = "";}
	  if (document.kcform.CP07_value.value == 0 )
	  			{document.kcform.CP07_value.value = "";
	  			document.kcform.CP07_price.value = "";}
	  if (document.kcform.CP08_value.value == 0 )
	  			{document.kcform.CP08_value.value = "";
	  			document.kcform.CP08_price.value = "";}
	  if (document.kcform.CP09_value.value == 0 )
	  			{document.kcform.CP09_value.value = "";
	  			document.kcform.CP09_price.value = "";}
	  if (document.kcform.CP10_value.value == 0 )
	  			{document.kcform.CP10_value.value = "";
	  			document.kcform.CP10_price.value = "";}
	  if (document.kcform.CP12_value.value == 0 )
	  			{document.kcform.CP12_value.value = "";
	  			document.kcform.CP12_price.value = "";}
	  if (document.kcform.CP13_value.value == 0 )
	  			{document.kcform.CP13_value.value = "";
	  			document.kcform.CP13_price.value = "";}
	  if (document.kcform.CP14_value.value == 0 )
	  			{document.kcform.CP14_value.value = "";
	  			document.kcform.CP14_price.value = "";}
	  			
	  return true;}
}




function Calc() {
// calculate values and total
	document.kcform.CP01_value.value = document.kcform.CP01_qty.value * document.kcform.CP01_price.value;
	document.kcform.CP02_value.value = document.kcform.CP02_qty.value * document.kcform.CP02_price.value;
	document.kcform.CP03_value.value = document.kcform.CP03_qty.value * document.kcform.CP03_price.value;
	document.kcform.CP04_value.value = document.kcform.CP04_qty.value * document.kcform.CP04_price.value;
	document.kcform.CP05_value.value = document.kcform.CP05_qty.value * document.kcform.CP05_price.value;
	document.kcform.CP06_value.value = document.kcform.CP06_qty.value * document.kcform.CP06_price.value;
	document.kcform.CP07_value.value = document.kcform.CP07_qty.value * document.kcform.CP07_price.value;
	document.kcform.CP08_value.value = document.kcform.CP08_qty.value * document.kcform.CP08_price.value;
	document.kcform.CP09_value.value = document.kcform.CP09_qty.value * document.kcform.CP09_price.value;
	document.kcform.CP10_value.value = document.kcform.CP10_qty.value * document.kcform.CP10_price.value;
	document.kcform.CP12_value.value = document.kcform.CP12_qty.value * document.kcform.CP12_price.value;
	document.kcform.CP13_value.value = document.kcform.CP13_qty.value * document.kcform.CP13_price.value;
	document.kcform.CP14_value.value = document.kcform.CP14_qty.value * document.kcform.CP14_price.value;
//
	document.kcform.GTotal.value = parseInt(document.kcform.Donation.value)
	+ parseInt(document.kcform.CP01_value.value)
	+ parseInt(document.kcform.CP02_value.value)
	+ parseInt(document.kcform.CP03_value.value)
	+ parseInt(document.kcform.CP04_value.value)
	+ parseInt(document.kcform.CP05_value.value)
	+ parseInt(document.kcform.CP06_value.value)
	+ parseInt(document.kcform.CP07_value.value)
	+ parseInt(document.kcform.CP08_value.value)
	+ parseInt(document.kcform.CP09_value.value)
	+ parseInt(document.kcform.CP10_value.value)
	+ parseInt(document.kcform.CP12_value.value)
	+ parseInt(document.kcform.CP13_value.value)
	+ parseInt(document.kcform.CP14_value.value);

 	var ref = Math.random()
 	ref += 0.1112 ;
 	ref *= 8999 ;
 	document.kcform.reference.value = Math.floor(ref);

	var pstring = "http://www.kingscare.org/Donate/index.html?fund=Payment for Care Package "
	    + Math.floor(ref)
	 	+ " &amount="
  		+ document.kcform.GTotal.value;
 		document.kcform.redirect.value = pstring;
 	}
 
// trap return on forms disabled ?? ftb
   
function onKeyPress () {
		var keycode; 
   		if (window.event)
   			keycode = window.event.keyCode; 
   		else if (e)
   			keycode = e.which;
    	else return true;
    	if (keycode == 13)
			{alert("Please use the Submit button rather than hitting return");
			return false; }
		return true;
	} 
	
function chkSpon() {
	var spaction1 = "http://www.kingscare.org";
	var spaction2 = "";
	var country = ", " + document.kcform.sponselect.options[document.kcform.sponselect.selectedIndex].text ;
	var gender = ", " + document.kcform.sponselectg.options[document.kcform.sponselectg.selectedIndex].text ;
	var age = ", " + document.kcform.sponselectage.options[document.kcform.sponselectage.selectedIndex].text ;
	var amount = "";
	var amount2 = "";	
	var ind;
	
	for (ind = 0; ind < document.kcform.sponamount.length; ind++)
		{if (document.kcform.sponamount[ind].checked == true)
			{amount = document.kcform.sponamount[ind].value;
			 break;}}
	
	
	if (document.kcform.sponoption.selectedIndex == 0)
		{spaction2 = "/Donate?fund=First Months Sponsorship";
		 amount2 = "&amount=" +  amount ;}
	else {spaction2 = "/sponreserve?send=Sponsorship Reservation";
		amount2 = ", £" +  amount ;}
	
	if (document.kcform.descfund.value != "**")
		{country = ", "+document.kcform.descfund.value;}
	else {if (document.kcform.sponselect.selectedIndex == 0)
		{country = "";}}
		
	if (document.kcform.sponselectg.selectedIndex == 0)
		{gender = "";}
	if (document.kcform.sponselectage.selectedIndex == 0)
		{age = "";}


	document.kcform.action=spaction1+spaction2+country+gender+age+amount2;
	
	return true;   }
  
//


