
	function validate_options(thisform){
		with(thisform){
			//check each option 
			if(opt1.options[opt1.selectedIndex].value ==0){
				alert('You have not selected the relevance\nof the first option');
				opt1.focus();
				return false;
			}
			if(opt2.options[opt2.selectedIndex].value ==0){
				alert('You have not selected the relevance\nof the second option');
				opt2.focus();
				return false;
			}
			if(opt3.options[opt3.selectedIndex].value ==0){
				alert('You have not selected the relevance\nof the third option');
				opt3.focus();
				return false;
			}
			if(opt4.options[opt4.selectedIndex].value ==0){
				alert('You have not selected the relevance\nof the fourth option');
				opt4.focus();
				return false;
			}
			if(opt5.options[opt5.selectedIndex].value ==0){
				alert('You have not selected the relevance\nof the fifth option');
				opt5.focus();
				return false;
			}
			if(opt6.options[opt6.selectedIndex].value ==0){
				alert('You have not selected the relevance\nof the sixth option');
				opt6.focus();
				return false;
			}
			if(opt7.options[opt7.selectedIndex].value ==0){
				alert('You have not selected the relevance\nof the seventh option');
				opt7.focus();
				return false;
			}
			if(opt8.options[opt8.selectedIndex].value ==0){
				alert('You have not selected the relevance\nof the eighth option');
				opt8.focus();
				return false;
			}
			//check each relevance only appears once
			var arrRel = new Array(0,0,0,0,0,0,0,0);
			var relValue;
			
			relValue = opt1.options[opt1.selectedIndex].value
			if(arrRel[relValue-1] == 1){
				alert('Relevance ' + relValue + ' can only be used once');
				opt1.focus();
				return false;
			}else{
				arrRel[relValue-1] = 1;
			}
			relValue = opt2.options[opt2.selectedIndex].value
			if(arrRel[relValue-1] == 1){
				alert('Relevance ' + relValue + ' can only be used once');
				opt2.focus();
				return false;
			}else{
				arrRel[relValue-1] = 1;
			}
			relValue = opt3.options[opt3.selectedIndex].value
			if(arrRel[relValue-1] == 1){
				alert('Relevance ' + relValue + ' can only be used once');
				opt3.focus();
				return false;
			}else{
				arrRel[relValue-1] = 1;
			}
			relValue = opt4.options[opt4.selectedIndex].value
			if(arrRel[relValue-1] == 1){
				alert('Relevance ' + relValue + ' can only be used once');
				opt4.focus();
				return false;
			}else{
				arrRel[relValue-1] = 1;
			}
			relValue = opt5.options[opt5.selectedIndex].value
			if(arrRel[relValue-1] == 1){
				alert('Relevance ' + relValue + ' can only be used once');
				opt5.focus();
				return false;
			}else{
				arrRel[relValue-1] = 1;
			}
			relValue = opt6.options[opt6.selectedIndex].value
			if(arrRel[relValue-1] == 1){
				alert('Relevance ' + relValue + ' can only be used once');
				opt6.focus();
				return false;
			}else{
				arrRel[relValue-1] = 1;
			}
			relValue = opt7.options[opt7.selectedIndex].value
			if(arrRel[relValue-1] == 1){
				alert('Relevance ' + relValue + ' can only be used once');
				opt7.focus();
				return false;
			}else{
				arrRel[relValue-1] = 1;
			}
			relValue = opt8.options[opt8.selectedIndex].value
			if(arrRel[relValue-1] == 1){
				alert('Relevance ' + relValue + ' can only be used once');
				opt8.focus();
				return false;
			}else{
				arrRel[relValue-1] = 1;
			}
		submitted.value=1;	
		}
		return true;
	}
	
	
	
function validate_radio(thisform) {
	with(thisform){
			// validate FirstQuestion
			myOption = -1;
			for (i = FirstQuestion.length - 1; i > -1; i--) {
				if (FirstQuestion[i].checked) {
					myOption = i; 
					i = -1;
				}
			}
			if (myOption == -1) {
				alert("You must select an option");
				return false;
			}
			submitted.value =  FirstQuestion[myOption].value;
	}
	return true;
}

function validate_details_fran(thisform) {
	with(thisform){
		//validate the mandatory fields
		if(trim(DOB.value).length ==0){
			alert('You must enter a date of birth');
			DOB.focus();
			return false;
		}
		if(!validateDate(trim(DOB.value))){
			alert('Date of birth is in wrong format\nUse DD/MM/YY');
			DOB.focus();
			return false;
		}
		//validate sex
		if(!(sex[0].checked) && !(sex[1].checked)){
			alert('You must choose a sex');
			sex[0].focus();
			return false;	
		} 
		submitted.value=1;	
	}
	return true;
}


function validate_details(thisform) {
	with(thisform){
		//validate the mandatory fields
		if(trim(title.value).length ==0){
			alert('You must enter a title');
			title.focus();
			return false;
		}
		if(trim(first_name.value).length ==0){
			alert('You must enter a first name');
			first_name.focus();
			return false;
		}
		if(trim(surname.value).length ==0){
			alert('You must enter a surname');
			surname.focus();
			return false;
		} //
		if(trim(DOB.value).length ==0){
			alert('You must enter a date of birth');
			DOB.focus();
			return false;
		}
		if(!validateDate(trim(DOB.value))){
			alert('Date of birth is in wrong format\nUse DD/MM/YY');
			DOB.focus();
			return false;
		}
		//validate sex
		if(!(sex[0].checked) && !(sex[1].checked)){
			alert('You must choose a sex');
			sex[0].focus();
			return false;	
		} 
		//validate in business
		if(!(in_business[0].checked) && !(in_business[1].checked)){
			alert('You must indicate if you have started in business');
			in_business[0].focus();
			return false;	
		}
		if(in_business[0].checked){ //if in business validate years and months
			//business_years
			if(trim(business_years.value).length ==0){
				alert('You must enter the number of years in business');
				business_years.focus();
				return false;
			}
			//business_months
			if(trim(business_months.value).length ==0){
				alert('You must enter the number of months in business');
				business_months.focus();
				return false;
			}
		} 
		if(!terms.checked){
			alert('To proceed you must agree to the Terms and Conditions');
			terms.focus();
			return false;
		}
	   //mandatory fields filled check formatting
	   if(!validateInteger(business_years.value)){
			alert('Number of years in business must be a number');
			business_years.focus();
			return false;
	   }
	   if(!validateInteger(business_months.value)){
			alert('Number of months in business must be a number');
			business_months.focus();
			return false;
	   }
	   if(!validateInteger(retire_age.value)){
			alert('Retirement age must be a number');
			retire_age.focus();
			return false;
	   }
	   if(!validateMoney(business_capital.value)){
			alert('Business capital must be a number');
			business_capital.focus();
			return false;
	   }
	   if(!validatePostCode(postcode.value)){
			alert('Post Code is not a valid format');
			postcode.focus();
			return false;
	   }
		
		if((business_start.value.length > 0) && !validateDate(trim(business_start.value))){
			alert('Business start date is in wrong format\nUse DD/MM/YY');
			business_start.focus();
			return false;
		}	
		submitted.value=1;	
	}
	return true;
}
function validate_email(thisform) {
	with(thisform){
		//Disable submit 
		click_once.disabled = true;
		//validate the mandatory fields
		if(trim(email.value).length ==0){
			alert('You must enter an email');
			email.focus();
			click_once.disabled = false;
			return false;
		}
		if(trim(confirmemail.value).length ==0){
			alert('You must confirm your email');
			confirmemail.focus();
			click_once.disabled = false;
			return false;
		}
		//Check the fields match
		if(email.value.toLowerCase() != confirmemail.value.toLowerCase()){
			alert('Emails do not match');
			click_once.disabled = false;
			return false;
		}
		//check format
		if(!validateEmail(email.value)){
			alert('Email format invalid');
			click_once.disabled = false;
			return false;
		}
		submitted.value=1;
		//click_once.disabled = false;
	}
	return true;
}

function validate_franchisee(thisform) {
	with(thisform){
		//Disable submit 
		click_once.disabled = true;
		//validate the mandatory fields
		if(trim(email.value).length ==0){
			alert('You must enter an email');
			email.focus();
			click_once.disabled = false;
			return false;
		}
		if(trim(confirmemail.value).length ==0){
			alert('You must confirm your email');
			confirmemail.focus();
			click_once.disabled = false;
			return false;
		}
		//Check the fields match
		if(email.value.toLowerCase() != confirmemail.value.toLowerCase()){
			alert('Emails do not match');
			click_once.disabled = false;
			return false;
		}
		//check format
		if(!validateEmail(email.value)){
			alert('Email format invalid');
			click_once.disabled = false;
			return false;
		}
		if(trim(franchisee_name.value).length ==0){
			alert('You must enter a Franchisee Name');
			franchisee_name.focus();
			click_once.disabled = false;
			return false;
		} //
		if(trim(franchise.value).length ==0){
			alert('You must enter a Franchise');
			franchise.focus();
			click_once.disabled = false;
			return false;
		} //
		
		
		submitted.value=1;
		//click_once.disabled = false;
	}
	return true;
}


function trim (str){
	return(str.replace(/^\s+|\s+$/g,''));
}

function validateInteger( strValue ) {
/************************************************
DESCRIPTION: Validates that a string contains only
    valid integer number.

PARAMETERS:
   strValue - String to be tested for validity

RETURNS:
   True if valid, otherwise false.
**************************************************/
  if(trim(strValue).length==0){
	return true;
  }
  
  var objRegExp  = /(^\d\d*$)/;
  //check for integer characters
  return objRegExp.test(strValue);
}

function validateMoney(strValue){
//allow commas to be stripped latter
	if(trim(strValue).length==0){
	return true;
  }
   var objRegExp  = /(^[0-9,]*$)/;
  //check for integer characters
  return objRegExp.test(strValue);
}

function validatePostCode(strValue){
	if(trim(strValue).length==0){
		return true;
	}
	var objRegExp =/^([Gg][Ii][Rr] 0[Aa]{2})|((([A-Za-z][0-9]{1,2})|(([A-Za-z][A-Ha-hJ-Yj-y][0-9]{1,2})|(([A-Za-z][0-9][A-Za-z])|([A-Za-z][A-Ha-hJ-Yj-y][0-9]?[A-Za-z])))) {0,1}[0-9][A-Za-z]{2})$/;
	return objRegExp.test(strValue);
}
function validateDate( strValue ) {
/************************************************
DESCRIPTION: Validates that a string contains only
    valid dates with 2 digit month, 2 digit day,
    4 digit year. Date separator can be ., -, or /.
    Uses combination of regular expressions and
    string parsing to validate date.
    Ex. mm/dd/yyyy or mm-dd-yyyy or mm.dd.yyyy

PARAMETERS:
   strValue - String to be tested for validity

RETURNS:
   True if valid, otherwise false.

REMARKS:
   Avoids some of the limitations of the Date.parse()
   method such as the date separator character.
*************************************************/
  //var objRegExp = /^\[0-3][0-9]\/[01][0-9]\/\d{2}$/
 var objRegExp = /^[0-3][0-9](\/)[01][0-9](\/)\d{2}$/
 
  //check to see if in correct format
  if(!objRegExp.test(strValue)){
      return false; //doesn't match pattern, bad date
  }
  else{
    var strSeparator = '/';
    //convert to american date format 
    strValue = strValue.substring(3,6) +  strValue.substring(0,3) + strValue.substring(6,8);
    var arrayDate = strValue.split(strSeparator); 
    //create a lookup for months not equal to Feb.
    var arrayLookup = { '01' : 31,'03' : 31, 
                        '04' : 30,'05' : 31,
                        '06' : 30,'07' : 31,
                        '08' : 31,'09' : 30,
                        '10' : 31,'11' : 30,'12' : 31}
    var intDay = parseInt(arrayDate[1],10); 

    //check if month value and day value agree
    if(arrayLookup[arrayDate[0]] != null) {
      if(intDay <= arrayLookup[arrayDate[0]] && intDay != 0)
        return true; //found in lookup table, good date
    }
    
    //check for February (bugfix 20050322)
    //bugfix  for parseInt kevin
    //bugfix  biss year  O.Jp Voutat
    var intMonth = parseInt(arrayDate[0],10);
    if (intMonth == 2) { 
       var intYear = parseInt(arrayDate[2]);
       if (intYear < 15){
			intYear = 2000 + intYear;
       }else{
			intYear = 1900 + intYear;
       }
       if (intDay > 0 && intDay < 29) {
           return true;
       }
       else if (intDay == 29) {
         if ((intYear % 4 == 0) && (intYear % 100 != 0) || 
             (intYear % 400 == 0)) {
              // year div by 4 and ((not div by 100) or div by 400) -&gt;ok
             return true;
         }   
       }
    }
  }  
  return false; //any other values, bad date
}

function validateEmail( strValue) {
/************************************************
DESCRIPTION: Validates that a string contains a
  valid email pattern.

 PARAMETERS:
   strValue - String to be tested for validity

RETURNS:
   True if valid, otherwise false.


*************************************************/
var objRegExp  =/^.+@[^\.].*\.[a-z]{2,}$/

  //check for valid email
  return objRegExp.test(strValue);
}
function validate_login(thisform){
	with(thisform){
		if(trim(user.value).length ==0){
			alert('You must enter a UserID');
			user.focus();
			return false;
		}
		if(trim(secret.value).length ==0){
			alert('You must enter a password');
			secret.focus();
			return false;
		}
		submitted.value=1;
	}
	return true;
}

function validate_report(thisform){
with(thisform){
		
		if(trim(date_from.value).length ==0){
			alert('You must enter a date from');
			date_from.focus();
			return false;
		}
		if(trim(date_to.value).length ==0){
			alert('You must enter a date to');
			date_to.focus();
			return false;
		}
		if(!validateDate(trim(date_from.value))){
			alert('Date from is in wrong format\nUse DD/MM/YY');
			date_from.focus();
			return false;
		}
		if(!validateDate(trim(date_to.value))){
			alert('Date to is in wrong format\nUse DD/MM/YY');
			date_to.focus();
			return false;
		}
		submitted.value=1;
	}
	return true;
}