function checkRequest()
{
  var f = document.frmTwinGrant;
  
  //Changed 24/07/03 OH
  var checkNoEmpty;
  checkNoEmpty = checkFields_onsubmit(document.frmTwinGrant);
  
  if (checkNoEmpty == false){return false}
  
  if (checkNoEmpty == true)
  {
	if(f.txtNumParty.value == "")
	{
	 		alert("Please enter the number of participants on your visit.");
			f.txtNumParty.focus();
			return true;
			//return false;
	}

    if(f.txtCostVisit.value != "" && f.txtOwnFinance.value != "" && f.txtOtherGrants.value != "" && f.txtGrantRequest.value != "" && f.txtNumParty.value != "")
	{//Check value is entered for all relevant fields
	
	  		 if (isValidMoney(f.txtCostVisit) && isValidMoney(f.txtOwnFinance) && isValidMoney(f.txtOtherGrants) && isValidMoney(f.txtGrantRequest)) 
	  		 {//Check relevant fields are valid money then need to convert to number
			  //by multiplying by 100 to lose the decimal place
	  	  	  	var totalCost = f.txtCostVisit.value * 100;
	  	  		var ownFinance = f.txtOwnFinance.value * 100;
	  	  		var otherGrants = f.txtOtherGrants.value * 100;
	  	  		var grantRequest = f.txtGrantRequest.value * 100;				
				
				totalCost = totalCost/100;
				ownFinance = ownFinance/100;
				otherGrants = otherGrants/100;
				grantRequest = grantRequest/100;
				
	  	  		var numPeople = f.txtNumParty.value;
		  		var costPP = totalCost/numPeople;
				var otherResources = ownFinance + otherGrants;
				var costRemaining = totalCost - otherResources; 
				var costRemainingPP = costRemaining/numPeople;
	  		    var grantRequestPP = grantRequest/numPeople;
				
		  			if (otherResources > totalCost)
					{
					   	   alert("Money from other resources cannot be greater\n" +
						   		 "than the total cost of the visit.");
						   f.txtCostVisit.select();
						   return false;
					}
					
					if (grantRequestPP > 30)
					{
					   	   alert("Grant request is limited to £30 per person.");
						   f.txtGrantRequest.select();
						   return false;
					}
					
					if (grantRequest > costRemaining)
					{
					   	   alert("Grant requested is more than the total cost of\n" +
						   		 "the visit minus the money from other resources.");
						   f.txtGrantRequest.select();
						   return false;
					}			    
	  		 }
			 else
			 {
				 return false;
			 }
    }
	else
	{
	 	return true;
	}
  }
}

function checkTelNum(areaCode_txtbox, phoneNum_txtbox)
{
 	  var telNum = phoneNum_txtbox.value;
	  var areaCode = areaCode_txtbox.value;

 	  if (telNum != "" && isNaN(telNum))
	  {
	   	 	  alert ("Please enter a valid phone number");
		  	  phoneNum_txtbox.select();
		  	  return false;
	  }
	  else if (telNum != "")
	  {
	   	  	  if (areaCode == "")
	  		  {
	   		   	   alert("Please enter your area code.");
				   areaCode_txtbox.select();
				   return false;
	   		  }
			  else if(isNaN(areaCode))
			  {
			   	   alert("Please enter a valid area code.");
				   areaCode_txtbox.select();
				   return false;
			  }
	  }
	  else if (areaCode != "" && telNum == "")
	  {
			  phoneNum_txtbox.focus();
			  return false;
	  }
	  	  
	  return true;
}

function completeAddress(cboTownHost)
{
 		 var f = document.frmTwinGrant;

 		 if (cboTownHost.value == "Macon")
		 {
		  		f.txtRegionHost.value = "Bourgogne"
				f.txtCountryHost.value = "France"
				f.txtPostCodeHost.focus();
				return true;
		 }
		 else if (cboTownHost.value == "Bischofsheim")
		 {
		  	  	f.txtRegionHost.value = "Hessen"
				f.txtCountryHost.value = "Germany"
				f.txtPostCodeHost.focus();
				return true;
		 }
		 else 
		 {
		  	  f.txtRegionHost.value = ""
			  f.txtCountryHost.value = ""
		  	  return false;
		 }
}

function checkPurpose()
{
		 var f = document.frmTwinGrant;

		 var textBoxvalue = f.txtPurpose.value;
 		 
		 if (f.cboPurpose.value != "Other")
		 {
		  	   f.txtPurpose.cmt = "optional";
			   f.txtPurpose.value = "";
			   f.txtAccomm.focus();
			   return true;
		 }
		 else
		 {
		  	   f.txtPurpose.cmt = "the purpose of your visit";
			   f.txtPurpose.focus();
			   return true;
		 }	 
		 
		 if (textBoxvalue != "")
		 {
		  	 //textBox has value so set drop down menu to "Other"
			 f.cboPurpose.value = "Other";
			 return true;
		 }
		 
}

function checkNum(obj)
{
 		 if (obj.value != "")
 		 {
		  	if (isNaN(obj.value))
		 	{
		  	   alert ("You must enter a number for " + obj.cmt);
			   obj.focus();
			   return false;
		 	}
		 	else return true;
		 }
		 else return false;
}