function doPopUp(theurl,width,height,winname)
	{
	document.form1.action=theurl;
	document.form1.target="Declaration";
	//form1.method="GET";
	var leftpos = (screen.width / 2) - (width /2);
	var toppos = (screen.height / 2) - (height /2);
	MailMerger = open("","Declaration","width="+width+",height="+height+",left="+leftpos+",top="+toppos+",align=center,valign=centre,scrollbars=no,status=yes,menubar=no"); 
	document.form1.submit();
	}
	
function selectAll(pointer)
	{
	pointer.focus();
	pointer.select();
	}

function TESTcalculateIt(submitThis)
	{
//	window.gift_4_display.innerText = "Hello MOOMIN";
//	document.getElementById("gift1display").innerText = "Hello";
//	document.getElementById('gift1display').innerText = "NEW METHOD WORKED YEAH!";	
	}	
	
function calculateIt(submitThis)
	{
	var totalPrice;
	totalPrice = 0;

	document.form1.orderinfo.value = "";
	if (!isNaN(document.form1.gift_1.value) && !isNaN(document.form1.gift_2.value) && !isNaN(document.form1.gift_3.value) && !isNaN(document.form1.gift_4.value) && !isNaN(document.form1.gift_5.value) && !isNaN(document.form1.gift_6.value) && !isNaN(document.form1.gift_7.value) && !isNaN(document.form1.gift_8.value) && !isNaN(document.form1.gift_9.value) && !isNaN(document.form1.gift_10.value) &&
!isNaN(document.form1.gift_11.value) &&
!isNaN(document.form1.gift_12.value) &&
!isNaN(document.form1.gift_13.value) && !isNaN(document.form1.gift_14.value) && !isNaN(document.form1.gift_15.value) && !isNaN(document.form1.gift_20_value.value))
		{
		if (document.form1.gift_1.value != "" && document.form1.gift_2.value != "" && document.form1.gift_3.value!= "" && document.form1.gift_4.value != "" && document.form1.gift_5.value != "" && document.form1.gift_6.value != "" && document.form1.gift_7.value != "" && document.form1.gift_8.value != "" && document.form1.gift_9.value != "" && document.form1.gift_10.value != "" && document.form1.gift_11.value != "" && document.form1.gift_12.value != "" &&  document.form1.gift_13.value != "" && document.form1.gift_14.value != "" && document.form1.gift_15.value != "" && document.form1.gift_20_value.value != "")
			{
			document.form1.gift_1_value.value = cent(parseInt(document.form1.gift_1.value) * document.form1.gift_1_amount.value);
			document.form1.gift_1.value = parseInt(document.form1.gift_1.value);
			document.getElementById("gift_1_display").innerHTML = document.form1.gift_1_value.value;
			if (document.form1.gift_1.value > 0 )
				{
				document.form1.orderinfo.value = document.form1.orderinfo.value + "Bible portion for a seeker @ 7.50. QTY = " + parseInt(document.form1.gift_1.value) + ",\n ";
				}
			document.form1.gift_2_value.value = cent(parseInt(document.form1.gift_2.value) * document.form1.gift_2_amount.value);
			document.form1.gift_2.value = parseInt(document.form1.gift_2.value);
			document.getElementById("gift_2_display").innerHTML = document.form1.gift_2_value.value;
			if (document.form1.gift_2.value > 0 )
				{
				document.form1.orderinfo.value = document.form1.orderinfo.value + "SMedia pack for an Arab seeker living in France @ 6. QTY = " + parseInt(document.form1.gift_2.value) + ",\n ";
				}
			document.form1.gift_3_value.value = cent(document.form1.gift_3.value * document.form1.gift_3_amount.value);
			document.form1.gift_3.value = parseInt(document.form1.gift_3.value);
			document.getElementById("gift_3_display").innerHTML = document.form1.gift_3_value.value;
			if (document.form1.gift_3.value > 0 )
				{
				document.form1.orderinfo.value = document.form1.orderinfo.value + "TBible Correspondence Course for an enquirer @ 7.50. QTY = " + parseInt(document.form1.gift_3.value) + ",\n ";
				}
			
			document.form1.gift_4_value.value = cent(document.form1.gift_4.value * document.form1.gift_4_amount.value);
			document.form1.gift_4.value = parseInt(document.form1.gift_4.value);
			document.getElementById("gift_4_display").innerHTML = document.form1.gift_4_value.value;
			if (document.form1.gift_4.value > 0 )
				{
				document.form1.orderinfo.value = document.form1.orderinfo.value + "Hold an Arabic conversation with a seeker about God @ 10. QTY = " + parseInt(document.form1.gift_4.value) + ",\n ";
				}
				
			document.form1.gift_5_value.value = cent(document.form1.gift_5.value * document.form1.gift_5_amount.value);
			document.form1.gift_5.value = parseInt(document.form1.gift_5.value);
			document.getElementById("gift_5_display").innerHTML = document.form1.gift_5_value.value;
			if (document.form1.gift_5.value > 0 )
				{
				document.form1.orderinfo.value = document.form1.orderinfo.value + "French/Arabic Bible @ 12.50. QTY = " + parseInt(document.form1.gift_5.value) + ",\n ";
				}
			
			totalPrice += (document.form1.gift_1.value * document.form1.gift_1_amount.value);
			totalPrice += (document.form1.gift_2.value * document.form1.gift_2_amount.value);
			totalPrice += (document.form1.gift_3.value * document.form1.gift_3_amount.value);
			totalPrice += (document.form1.gift_4.value * document.form1.gift_4_amount.value);
			totalPrice += (document.form1.gift_5.value * document.form1.gift_5_amount.value);
			
			document.form1.gift_6_value.value = cent(document.form1.gift_6.value * document.form1.gift_6_amount.value);
			document.form1.gift_6.value = parseInt(document.form1.gift_6.value);
			document.getElementById("gift_6_display").innerHTML = document.form1.gift_6_value.value;
			if (document.form1.gift_6.value > 0 )
				{
				document.form1.orderinfo.value = document.form1.orderinfo.value + "Starter pack for a Moroccan child beginning school @ 15. QTY = " + parseInt(document.form1.gift_6.value) + ",\n ";
				}
				
			document.form1.gift_7_value.value = cent(document.form1.gift_7.value * document.form1.gift_7_amount.value);
			document.form1.gift_7.value = parseInt(document.form1.gift_7.value);
			document.getElementById("gift_7_display").innerHTML = document.form1.gift_7_value.value;
			if (document.form1.gift_7.value > 0 )
				{
				document.form1.orderinfo.value = document.form1.orderinfo.value + "Adult education teaching pack for Mauritanian women @ 20. QTY = " + parseInt(document.form1.gift_7.value) + ",\n ";
				}
			
			document.form1.gift_8_value.value = cent(document.form1.gift_8.value * document.form1.gift_8_amount.value);
			document.form1.gift_8.value = parseInt(document.form1.gift_8.value);
			document.getElementById("gift_8_display").innerHTML = document.form1.gift_8_value.value;
			if (document.form1.gift_8.value > 0 )
				{
				document.form1.orderinfo.value = document.form1.orderinfo.value + "Emergency food for a poor Moroccan family @ 25. QTY = " + parseInt(document.form1.gift_8.value) + ",\n ";
				}
				
			document.form1.gift_9_value.value = cent(document.form1.gift_9.value * document.form1.gift_9_amount.value);
			document.form1.gift_9.value = parseInt(document.form1.gift_9.value);
			document.getElementById("gift_9_display").innerHTML = document.form1.gift_9_value.value;
			if (document.form1.gift_9.value > 0 )
				{
				document.form1.orderinfo.value = document.form1.orderinfo.value + "Support a missionary @ 25. QTY = " + parseInt(document.form1.gift_9.value) + ",\n ";
				}
			
			document.form1.gift_10_value.value = cent(document.form1.gift_10.value * document.form1.gift_10_amount.value);
			document.form1.gift_10.value = parseInt(document.form1.gift_10.value);
			document.getElementById("gift_10_display").innerHTML = document.form1.gift_10_value.value;
			if (document.form1.gift_10.value > 0 )
				{
				document.form1.orderinfo.value = document.form1.orderinfo.value + "Medical needs of an Iraqi refugee for one month @ 30. QTY = " + parseInt(document.form1.gift_10.value) + ",\n ";
				}
				
document.form1.gift_11_value.value = cent(document.form1.gift_11.value * document.form1.gift_11_amount.value);
			document.form1.gift_11.value = parseInt(document.form1.gift_11.value);
			document.getElementById("gift_11_display").innerHTML = document.form1.gift_11_value.value;
			if (document.form1.gift_11.value > 0 )
				{
				document.form1.orderinfo.value = document.form1.orderinfo.value + "Refurbish a wheelchair in Morocco @ 55. QTY = " + parseInt(document.form1.gift_11.value) + ",\n ";
				}
				
document.form1.gift_12_value.value = cent(document.form1.gift_12.value * document.form1.gift_12_amount.value);
			document.form1.gift_12.value = parseInt(document.form1.gift_12.value);
			document.getElementById("gift_12_display").innerHTML = document.form1.gift_12_value.value;
			if (document.form1.gift_12.value > 0 )
				{
				document.form1.orderinfo.value = document.form1.orderinfo.value + "Help a persecuted Muslim convert who is living in the UK @ 100. QTY = " + parseInt(document.form1.gift_12.value) + ",\n ";
				}
				
document.form1.gift_13_value.value = cent(document.form1.gift_13.value * document.form1.gift_13_amount.value);
			document.form1.gift_13.value = parseInt(document.form1.gift_13.value);
			document.getElementById("gift_13_display").innerHTML = document.form1.gift_13_value.value;
			if (document.form1.gift_13.value > 0 )
				{
				document.form1.orderinfo.value = document.form1.orderinfo.value + "Assist a retired missionary @ 200. QTY = " + parseInt(document.form1.gift_13.value) + ",\n ";
				}
				
document.form1.gift_14_value.value = cent(document.form1.gift_14.value * document.form1.gift_14_amount.value);
			document.form1.gift_14.value = parseInt(document.form1.gift_14.value);
			document.getElementById("gift_14_display").innerHTML = document.form1.gift_14_value.value;
			if (document.form1.gift_14.value > 0 )
				{
				document.form1.orderinfo.value = document.form1.orderinfo.value + "Train a North African believer to lead the emerging church @ 300. QTY = " + parseInt(document.form1.gift_14.value) + ",\n ";
				}
				
document.form1.gift_15_value.value = cent(document.form1.gift_15.value * document.form1.gift_15_amount.value);
			document.form1.gift_15.value = parseInt(document.form1.gift_15.value);
			document.getElementById("gift_15_display").innerHTML = document.form1.gift_15_value.value;
			if (document.form1.gift_15.value > 0 )
				{
				document.form1.orderinfo.value = document.form1.orderinfo.value + "Create an Arabic web page @ 500. QTY = " + parseInt(document.form1.gift_15.value) + ",\n ";
				}
				
			totalPrice += (document.form1.gift_6.value * document.form1.gift_6_amount.value);
			totalPrice += (document.form1.gift_7.value * document.form1.gift_7_amount.value);
			totalPrice += (document.form1.gift_8.value * document.form1.gift_8_amount.value);
			totalPrice += (document.form1.gift_9.value * document.form1.gift_9_amount.value);
			totalPrice += (document.form1.gift_10.value * document.form1.gift_10_amount.value);
			totalPrice += (document.form1.gift_11.value * document.form1.gift_11_amount.value);
			totalPrice += (document.form1.gift_12.value * document.form1.gift_12_amount.value);
			totalPrice += (document.form1.gift_13.value * document.form1.gift_13_amount.value);
			totalPrice += (document.form1.gift_14.value * document.form1.gift_14_amount.value);
			totalPrice += (document.form1.gift_15.value * document.form1.gift_15_amount.value);
		
			var bob = document.form1.gift_20_value.value;
			totalPrice += bob.valueOf() * 1;
			if (document.form1.gift_20_value.value > 0 )
				{
				document.form1.orderinfo.value = document.form1.orderinfo.value + "My extra gift to help where most needed. Amount = " + cent(document.form1.gift_20_value.value) + ",\n ";
				}
			
			if (document.form1.declaration.checked)
				{
				document.form1.orderinfo.value = document.form1.orderinfo.value + "Declaration Sent";
				}
				
			if (document.form1.supporter[0].checked)
				{			
				document.form1.orderinfo.value = document.form1.orderinfo.value + "Yes, I am an existing supporter.\n\n";	
				document.form1.existingsupporter.value = 'Yes';
				}
			else
				{
				document.form1.orderinfo.value = document.form1.orderinfo.value + "\No, I am not an existing supporter.\n\n";	
				document.form1.existingsupporter.value = 'No';
				}
		//if (document.form1.giveoutyourdetails_check.checked)
		//{			
		//document.form1.orderinfo.value = document.form1.orderinfo.value + "Please do NOT distribute my details to third parties.\n\n";	
		//}
			document.form1.total_price.value = cent(totalPrice);		
			var amountArray = (document.form1.total_price.value * 100).toString().split(".");
			document.form1.amount.value = amountArray[0];
			if (submitThis == 'Y')
				{
				document.form1.action = "https://securetrading.net/authorize/form.cgi";
				document.form1.target="Donation";
				//form1.method="GET";
				var width = 700;
				var height = 550;
				var leftpos = (screen.width / 2) - (width /2);
				var toppos = (screen.height / 2) - (height /2);
				MailMerger = open("","Donation","width="+width+",height="+height+",left="+leftpos+",top="+toppos+",align=center,valign=centre,resizable=yes,scrollbars=yes,status=yes,menubar=no"); 
				
				var stringVar = document.form1.url.value;
				var listArray = stringVar.split("/");
				document.form1.url.value= "";
				
				for (var i=0;i+1< listArray.length;i++)
					{
					document.form1.url.value = document.form1.url.value + listArray[i] + "/";
					}
				document.form1.url.value = document.form1.url.value + "form_closer.php";	
				document.form1.dob.value = document.form1.Dob_Day.value + "/" + document.form1.Dob_Month.value + "/" + document.form1.Dob_Year.value;
				document.form1.name.value = document.form1.forename.value + " " + document.form1.surname.value;
				document.form1.address.value = document.form1.address1.value;
				if (document.form1.address2.value != "")
					{
					document.form1.address.value = document.form1.address.value +  ",\n" + document.form1.address2.value;
					}
								
				if (document.form1.forename.value == "")
					{
					alert("Please fill in the 'Forename(s)' box");
					}
				
				if (document.form1.surname.value == "")
					{
					alert("Please fill in the 'Surname' box");
					}
				else if (document.form1.address1.value == "")
					{
					alert("Please fill in the 'Address' box");
					}
				else if (document.form1.town.value == "")
					{
					alert("Please fill in the 'Town/City' box");
					}
				else if (document.form1.county.value == "")
					{
					alert("Please fill in the 'County' box");
					}
				else if (document.form1.postcode.value == "")
					{
					alert("Please fill in the 'Postcode' box");
					}
				else if (document.form1.country.value == "")
					{
					alert("Please fill in the 'Country' box");
					}
				else if (document.form1.email.value == "")
					{
					alert("Please fill in the 'Email' box");
					}
				else if (document.form1.total_price.value < 0.01 )
					{
					alert("After filling in your preferred 'QTY' field(s), click the 'Calculate' button");
					}
				else	
					//DIV SWITCH - if greater than 7.50 turn optionone off. 
					{
					if (document.form1.total_price.value > 7.50)
					{
					switchMenu('optionone');
					}
					//END DIV SWITCH
					document.form1.submit();
					}
				}
			}
		else
			{
			alert("Please ensure that you only use numbers in the donation boxes");
			}		
		}
	else
		{
		alert("Please ensure that you only use  numbers in the donation boxes");
		}	
	}

function cent(amount) 
	{
	// returns the amount in the .99 format
    amount -= 0;
    return (amount == Math.floor(amount)) ? amount + '.00' : (  (amount*10 == Math.floor(amount*10)) ? amount + '0' : amount);
	}

//DIV SWAP
function switchMenu(obj) {
	var el = document.getElementById(obj);
	if ( el.style.display != "none" ) {
		el.style.display = 'none';
	}
	else {
		el.style.display = '';
	}
}

