<!--


var dtCh= "/";
var minYear=1900;
var maxYear=2100;
var ap;

/*dd = document.testform.day.value;
mm = document.testform.month.value;
yy = document.testform.year.value;*/


function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDateday(strDay,strMonth,strYear){
	var daysInMonth = DaysArray(12)
	if (strDay.length<1 || strDay<1 || strDay>31 || (strMonth==2 && strDay>daysInFebruary(strYear)) || strDay > daysInMonth[strMonth]){
		alert("Please enter a valid day for you Date Of Birth")
		return false
	}
return true
}


function isDatemonth(strDay,strMonth,strYear){
	var daysInMonth = DaysArray(12)
	if (strMonth.length<1 || strMonth<1 || strMonth>12){
		alert("Please enter a valid month for you Date Of Birth")
		return false
	}
return true
}



function isDateyear(strDay,strMonth,strYear){
	var daysInMonth = DaysArray(12)
	if (strYear.length != 4 || strYear==0 || strYear<minYear || strYear>maxYear){
		alert("Please enter a valid 4 digit year")
		return false
	}
return true
}






function checkForm(testform){


test = document.testform.postcode.value; size = test.length
 test = test.toUpperCase(); //Change to uppercase
 while (test.slice(0,1) == " ") //Strip leading spaces
  {test = test.substr(1,size-1);size = test.length
  }
 while(test.slice(size-1,size)== " ") //Strip trailing spaces
  {test = test.substr(0,size-1);size = test.length
  }
 document.testform.postcode.value = test; //write back to form field
 count1 = test.indexOf(" ");count2 = test.lastIndexOf(" ");

var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/	
var emailFilter=/^.+@.+\..{2,3}$/;
var phonestripped = document.testform.telephone.value.replace(/[\(\)\.\-\ ]/g, '');

var valid = "0123456789-";
var hyphencount = 0;

		/* the minumum age you want to allow in */
var day=document.testform.day
	var month=document.testform.month
	var year=document.testform.year
	var min_age = 18;
	
	var dtStr = day.value +"/"+ month.value + "/" + year.value
	
	
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	
	strYr=strYear
	
	month2=parseInt(strMonth)
	day2=parseInt(strDay)
	year2=parseInt(strYr)
	
var theirDate = new Date((year2 + min_age), month2, day2);
var today = new Date;



	
	if (isDateday(day.value,month.value,year.value)==false){
		day.focus()
		return false
	} 

	
	else if (isDatemonth(day.value,month.value,year.value)==false){
		month.focus()
		return false
	}
	
	else if (isDateyear(day.value,month.value,year.value)==false){
		year.focus()
		return false
	}

	
	

/*else if ((today.getTime() - theirDate.getTime()) < 0) {
alert("You are too young to enter this area");
return false;
}*/
	
 else if (document.testform.b_country.value=="0") {

  		alert("You must supply your COUNTRY and complete all required fields");
  		document.testform.b_country.focus();
  		return false;

  	} else if (document.testform.first_name.value=="") {

    	alert("You must supply your FIRST NAME and complete all required fields");
    	document.testform.first_name.focus();
		return false;

  	}  else  if (document.testform.surname.value=="") {

  		alert("You must supply your SURNAME and complete all required fields");
  		document.testform.surname.focus();
  		return false;

  	} else  if (document.testform.street_address.value=="") {
  
  		alert("You must supply your FIRST LINE OF ADDRESS and complete all required fields");
  		document.testform.street_address.focus();
  		return false;

  	} else  if (document.testform.city.value=="") {

	  	alert("You must supply your CITY  and complete all required fields");
 		document.testform.city.focus();
 		return false;

  	} else  if (document.testform.postcode.value=="") {

  		alert("You must supply your POSTCODE/ZIP and complete all required fields");
  		document.testform.postcode.focus();
 		return false;

  	} 

	else if (document.testform.b_state.value=="0") {

    	alert("You must select the County/State you live in");
		return false;
		
		

	}
	
	
	

else if ((size !=5 && document.testform.b_country.value== "United_States") && (size != 10 && document.testform.b_country.value == "United_States")){ //Code length rule
  alert(test + " is not a valid postcode/Zip - Please enter your 5 digit or 5 digit+4 zip code including the hyphen.");
  document.testform.postcode.focus();
  return false;
  }
	
 

else if ((size < 5 && document.testform.b_country.value== "United_Kingdom") || (size > 8 && document.testform.b_country.value == "United_Kingdom")){ //Code length rule
  alert(test + " is not a valid postcode - wrong length");
  document.testform.postcode.focus();
  return false;
  }
else if (!(isNaN(test.charAt(0))) && document.testform.b_country.value == "United_Kingdom"){ //leftmost character must be alpha character rule
   alert(test + " is not a valid postcode - cannot start with a number");
   document.testform.postcode.focus();
   return false;
  }
 else if (isNaN(test.charAt(size-3)) && document.testform.b_country.value == "United_Kingdom"){ //first character of inward code must be numeric rule
   alert(test + " is not a valid postcode - alpha character in wrong position");
   document.testform.postcode.focus();
   return false;
  }
 else if (!(isNaN(test.charAt(size-2))) && document.testform.b_country.value == "United_Kingdom"){ //second character of inward code must be alpha rule
   alert(test + " is not a valid postcode - number in wrong position");
   document.testform.postcode.focus();
   return false;
  }
 else if (!(isNaN(test.charAt(size-1))) && document.testform.b_country.value == "United_Kingdom"){ //third character of inward code must be alpha rule
   alert(test + " is not a valid postcode - number in wrong position");
   document.testform.postcode.focus();
   return false;
  }
 /*else if (!(test.charAt(size-4) == " ") && document.testform.b_country.value == "United_Kingdom"){//space in position length-3 rule
   alert(test + " is not a valid postcode - no space or space in wrong position");
   document.testform.postcode.focus();
   return false;
   }*/

 else if ((count1 != count2) && document.testform.b_country.value == "United_Kingdom"){//only one space rule
   alert(test + " is not a valid postcode - only one space allowed");
   document.testform.postcode.focus();
   return false;
  }

  
		
		
		

    else  if (document.testform.race.value=="0") {

  		alert("You must supply your RACE and complete all required fields");
  		document.testform.race.focus();
  		return false;

  	} else  if (document.testform.sex.value=="0") {

  		alert("You must supply your sex");
  		document.testform.sex.focus();
  		return false;

	} else  if (document.testform.telephone.value=="" && document.testform.mobile.value=="") {

  		alert("You must supply at least one method of phone contact");
		document.testform.telephone.focus();
  		return false;
  	} 
	else if (document.testform.n5.value=="0") {

    	alert("You must select how you rate your blood pressure");
   		document.testform.n5.focus();
		return false;

	}
	
		else if (document.testform.time_suffered_asthma.value=="0") {

  		alert("You must supply how long you have suffered from asthma");
  		document.testform.time_suffered_asthma.focus();
  		return false;

  	}
	
	
	else if (document.testform.n27.value=="") {

  		alert("You must supply your BMI Value and complete all required fields");
		MM_openBrWindow('bmi2.php','bmi','width=380,height=500');
  		document.testform.n27.focus();
  		return false;

  	}
	
	else if (document.testform.many_cigarettes.value=="0") {

    	alert("You must select the NUMBER OF CIGARETTES smoked each day");
   		document.testform.many_cigarettes.focus();
		return false;

	}else if (document.testform.n9[0].checked && document.testform.units_week.value=="") {

    	alert("As you have answered YES to drinking alcohol you must enter the NUMBER OF UNITS OF ALCOHOL consumed per week and complete all required fields");
    	document.testform.units_week.focus();
		return false;

	} else if (document.testform.units_week.value!="" && isNaN(document.testform.units_week.value)) {

   	 	alert("The answer you have given to the number of units of alcohol consumed per week is NOT A NUMBER! Please use numerical characters to enter the NUMBER of units per week");
    	document.testform.units_week.focus();
		return false;

	}
	
	
	else if (document.testform.social_drug_status.value=="0") {

    	alert("You must select your social drug status");
   		document.testform.social_drug_status.focus();
		return false;

	}
	else if (document.testform.menopausal.value=="0") {

    	alert("You must select when you are available");
   		document.testform.menopausal.focus();
		return false;

	}
	else  if (document.testform.code.value=="") {

  		alert("You must enter the code displaid in the white box");
		document.testform.code.focus();
  		return false;
  	}
	

	

	
	
	 else {

  		return true;

  	} 
 }

// -->
