
function inputsValid()
{
	if (!checkLength(document.form1.name.value))
	{
 		alert("Please enter your name")
		document.form1.name.focus()
		return false	
	}

	if (!checkLength(document.form1.postcode.value))
	{
 		alert("Please enter Postcode/ Zip Code")
		document.form1.postcode.focus()
		return false	
	}
	
	if (!checkLength(document.form1.telephone.value))
	{
 		alert("Please enter your telphone number")
		document.form1.telephone.focus()
		return false	
	}

	if (!checkEmail(document.form1.client_email.value))
	{
		alert("Email address not valid!")
		document.form1.client_email.focus()
		return false
	}

	
	calculateAmount(document.form1)
	
	return true

} /*inputsValid*/


function checkLength(data)
{
	return (data.length > 0)
}

function checkEmail(email)
{
	invalidChars = "/:,;";
		
	if (email.length == 0)
		return false;
	
	for (i=0; i<invalidChars.length; i++)
	{
		badChar = invalidChars.charAt(i);
		if (email.indexOf(badChar,0) != -1)
		{
			return false
		}
	}

	counter = 0;
	for (i=0; i<email.length; i++)
	{
		character = email.charAt(i)
		if (character == "@")
			counter++;
	}
	if (counter != 1)
		return false

	if (email.indexOf(".",0) == -1)
		return false

	return true;
	
}/*checkEmail*/	

function setPaymentAmount()
{
	if (document.form1.PayOption[0].checked)
		document.form1.amount.value = "2580.00";
	if (document.form1.PayOption[1].checked)
		document.form1.amount.value = "280.00";
	if (document.form1.PayOption[2].checked)
		document.form1.amount.value = "0.00";

}

function calculateAmount(formular)
{
	description = new String("")
	identification = new String("")
	
	identification = identification+formular.name.value+"-"+formular.client_email.value // counting the instruments checked and constructing the description string for worldPay;d
	
	description = "Fee Payment from FXMoneyMap.co.uk";
	
	amount = document.form1.amount.value;
	amount = amount * 100;
	document.form2.amount.value = amount;

	// setting hidden variable for worldpay
	document.form2.orderref.value = identification;
	document.form2.orderinfo.value = description;

	document.form2.email.value = document.form1.client_email.value;
	document.form2.name.value =  document.form1.name.value;	
	document.form2.address.value = document.form1.address1.value + "&#10;"+document.form1.address2.value + "&#10;";
	document.form2.postcode.value = document.form1.postcode.value;	
	document.form2.town.value = document.form1.city.value;
	document.form2.county.value = document.form1.county.value;
	document.form2.telephone.value = document.form1.ttelephone.value;
	document.form2.country.value = document.form1.country.options[document.form1.country.selectedIndex].value;
	


}/*calculateAmount*/

function round(number,X) 
{
	X = (!X ? 2 : X);
	result = Math.round(number*Math.pow(10,X))/Math.pow(10,X);
	result = new String(result)
	if (result.indexOf(".") == -1)
	{
		result = result + ".00"	
	}
	if (result.indexOf(".") == (result.length -2))
	{
		result = result + "0"	
	}
	return result
}