

function getrfr(){
	
	// call by  onload="getrfr();"
// if there is a rfr querystring then set the cookie
		var args = parseQueryString ();
		for (var arg in args) {
			if (arg == "rfr") {
			//alert("rfr returned");
			setCookie('rfr',args[arg],1);
			}
		}
// if there is no cookie, set to default
		if (getCookie('rfr') == "" ) setCookie('rfr','TCV',1);

//set value of rfr hidden field to cookie
		document.form1.rfr.value = getCookie('rfr') ;
		
}

function checkform(){ 

NumAdults = 0;


document.form1.NumAdults.value = parseInt(document.form1.NumAdults69.value) + parseInt(document.form1.NumAdults65.value)+ parseInt(document.form1.NumAdults.value) + parseInt(document.form1.NumAdults45.value);

if ((document.form1.PolicyType.value == "Annual Multitrip")||(document.form1.PolicyType.value == "Annual Multitrip with Wintersports")||(document.form1.PolicyType.value == "Business")||(document.form1.PolicyType.value == "Motorcycle Multitrip")) {
	
    if ( ( document.form1.GroupType[0].checked == false )
    && ( document.form1.GroupType[1].checked == false ) )
    {
        alert ( "Please select if the policy is for one person or a couple" );
        return false;
    }
	
	if (document.form1.AdultAge.value > 65 ){
   alert("We are unable to cover anyone over 65 on this policy");
	document.form1.AdultAge.focus();
	document.form1.AdultAge.select();
   return false;
} 

}
if (document.form1.NumAdults.value == "" ) document.form1.NumAdults.value = 0;
if (document.form1.NumChildren.value == "" ) document.form1.NumChildren.value = 0;


NumAdults = parseInt(document.form1.NumAdults.value);
NumChildren = parseInt(document.form1.NumChildren.value);
AdultAge = parseInt(document.form1.AdultAge.value);

  if (isNum(NumAdults) == false){
   alert("I dont recognise the Number of Adults as a number");
   return false;
 } 
  if (isNum(NumChildren) == false){
   alert("I dont recognise the Number of Children as a number");
	document.form1.NumChildren.focus();
	document.form1.NumChildren.select();
   return false;
 } 
 
 if (isNum(AdultAge) == false){
   alert("I dont recognise the Age of the eldest person as a number");
	document.form1.AdultAge.focus();
	document.form1.AdultAge.select();
   return false;
 } 
 
 TotalAdults = NumAdults;
 TotalChildren = NumChildren;
 TotalInsured = TotalAdults + TotalChildren;
 
  if (TotalInsured == 0 ) {
   alert("Please enter at least one person");
   return false;
  }
  
  if (TotalInsured > 20 ) {
   alert("There is a limit of 20 insured");
   return false;
  }



if (document.form1.multitrip.value == "1"){
	if (document.form1.DateFrom.value == ""){
   alert("Please enter a date you want the policy to start");
	document.form1.DateFrom.focus();
	document.form1.DateFrom.select();
   return false;
} 

}

if (document.form1.multitrip.value == "0"){
	if (document.form1.DateFrom.value == ""){
   alert("Please enter a departure date");
	document.form1.DateFrom.focus();
	document.form1.DateFrom.select();
   return false;
} 
	if (document.form1.DateTo.value == ""){
	   alert("Please enter a return date");
		document.form1.DateTo.focus();
		document.form1.DateTo.select();
	   return false;
	} 
}


if (document.form1.AdultAge.value == ""){
   alert("Please enter the age of the oldest person on the policy");
	document.form1.AdultAge.focus();
	document.form1.AdultAge.select();
   return false;
} 

if (document.form1.NumAdults.value == 0 && document.form1.AdultAge.value > 17 ){
   alert("You have indicated that there are no persons over 18 on this policy - Check the age you entered.");
	document.form1.AdultAge.focus();
	document.form1.AdultAge.select();
   return false;
} 

if (document.form1.NumChildren.value == 0 && document.form1.AdultAge.value < 18 ){
   alert("You have indicated that there are no persons under 18 on this policy - Check the age you entered.");
	document.form1.AdultAge.focus();
	document.form1.AdultAge.select();
   return false;
} 

if (document.form1.NumAdults69.value > 0 && document.form1.AdultAge.value > 69 ){
   alert("We are unable to cover anyone over 69 on this policy");
	document.form1.AdultAge.focus();
	document.form1.AdultAge.select();
   return false;
} 
if (document.form1.NumAdults65.value > 0 && document.form1.AdultAge.value > 65 ){
   alert("We are unable to cover anyone over 65 on this policy");
	document.form1.AdultAge.focus();
	document.form1.AdultAge.select();
   return false;
} 

if (document.form1.NumAdults45.value > 0 && document.form1.AdultAge.value > 45 ){
   alert("We are unable to cover anyone over 45 on this policy");
	document.form1.AdultAge.focus();
	document.form1.AdultAge.select();
   return false;
} 

   
  return true; 
  // Submit Point
}


// ***  Form Checking routines for quote.asp *** \\

// onFocus="this.blur()" 
//Disables editing of a field

function sendIt(){
window.open('','newWin','toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=no,resizable=no,width=500,height=300');
document.form1.submit();
}


function ignoreSpaces(string) {
var temp = "";
string = '' + string;
splitstring = string.split(" ");
for(i = 0; i < splitstring.length; i++)
temp += splitstring[i];
return temp;
}

function ignoreDashes(string) {
var temp = "";
string = '' + string;
splitstring = string.split("-");
for(i = 0; i < splitstring.length; i++)
temp += splitstring[i];
return temp;
}

// Checks for card number inc. spaces:
//  General purpose check for numbers called by onBlur="validnumber(this)" :
function validnumber(field) {
var valid = "0123456789"
var ok = "yes";
var temp;
for (var i=0; i<field.value.length; i++) {
temp = "" + field.value.substring(i, i+1);
if (valid.indexOf(temp) == "-1") ok = "no";
}
if (ok == "no") {
alert("Invalid entry!  Please Enter Numbers Only");
field.focus();
field.select();
   }
}

function isNum(argvalue) {
argvalue = argvalue.toString();
if (argvalue.length == 0)
return false;

for (var n = 0; n < argvalue.length; n++)
if (argvalue.substring(n, n+1) < "0" || argvalue.substring(n, n+1) > "9")
return false;

return true;
}