// <![CDATA[
			
function valMakeAClaimForm(form){
	if(form.intTitleID.value == -1){alert('Please select your title');form.intTitleID.focus();return false;}
	if(!form.strFirstName.value){alert('Please enter your first name');form.strFirstName.focus();return false;}
	if(!form.strSurname.value){alert('Please enter your surname');form.strSurname.focus();return false;}
	if(!isDate(form.dtDOB.value, 'Date of Birth')){form.dtDOB.focus();return false;}
		
	/* Check email addr */
	if(!form.strEmail.value){
			alert('Please enter your email address');
			form.strEmail.focus();
			return false;
		}
	else{
			if(!checkEmail(form.strEmail.value))
			{
				alert('Please enter a valid email address');
				form.strEmail.focus();
				return false;
			}
		}
	
	if(!form.strTel.value){alert('Please enter your telephone number');form.strTel.focus();return false;}
	if(!form.strAddr1.value){alert('Please enter the first line of your address');form.strAddr1.focus();return false;}
	if(!form.strCity.value){alert('Please enter the town\/city of your residence');form.strCity.focus();return false;}
	if(!form.strPostcode.value){alert('Please enter the postcode of your residence');form.strPostcode.focus();return false;}
	/* Format Postcode - add space and make uppercase */
	form.strPostcode.value = formatPostcode(form.strPostcode.value);
	if(!isValidPostcode(form.strPostcode.value)){alert('Please enter a valid postcode for your residence');form.strPostcode.focus();return false;}
	if(form.intPreferredTimeID.value == -1){alert('Please indicate the Preferred Time of Contact');form.intPreferredTimeID.focus();return false;}
	if(!isDate(form.dtAccident.value, 'Date of Accident')){form.dtAccident.focus();return false;}
	if(!form.strCircumstances.value){alert('Please enter the circumstances of the accident');form.strCircumstances.focus();return false;}
	if(!form.strInjury.value){alert('Please enter the details of your injury');form.strInjury.focus();return false;}
	
	return true;	
}


function valContactUsForm(form){
	if(form.intTitleID.value == -1){alert('Please select your title');form.intTitleID.focus();return false;}
	if(!form.strFirstName.value){alert('Please enter your first name');form.strFirstName.focus();return false;}
	if(!form.strSurname.value){alert('Please enter your surname');form.strSurname.focus();return false;}
		
	/* Check email addr */
	if(!form.strEmail.value){
			alert('Please enter your email address');
			form.strEmail.focus();
			return false;
		}
	else{
			if(!checkEmail(form.strEmail.value))
			{
				alert('Please enter a valid email address');
				form.strEmail.focus();
				return false;
			}
		}
	
	if(!form.strTel.value){alert('Please enter your telephone number');form.strTel.focus();return false;}
	if(!form.strComment.value){alert('Please enter your comment');form.strComment.focus();return false;}
	
	return true;	
}


function valCallMeBackForm(form){
	if(form.intPnlTitleID.value == -1){alert('Please select your title');form.intPnlTitleID.focus();return false;}
	if(!form.strPnlFirstName.value){alert('Please enter your first name');form.strPnlFirstName.focus();return false;}
	if(!form.strPnlSurname.value){alert('Please enter your surname');form.strPnlSurname.focus();return false;}
		
	/* Check email addr */
	if(!form.strPnlEmail.value){
			alert('Please enter your email address');
			form.strPnlEmail.focus();
			return false;
		}
	else{
			if(!checkEmail(form.strPnlEmail.value))
			{
				alert('Please enter a valid email address');
				form.strPnlEmail.focus();
				return false;
			}
		}
	
	if(!form.strPnlTel.value){alert('Please enter your telephone number');form.strPnlTel.focus();return false;}
	if(form.intPnlPreferredTimeID.value == -1){alert('Please indicate the Preferred Time of Contact');form.intPnlPreferredTimeID.focus();return false;}
	
	return true;	
}


// Tests to see if string is in correct UK style postcode: AL1 1AB, BM1 5YZ etc. //
function isValidPostcode(p) {
	var postcodeRegEx = /[A-Z]{1,2}[0-9]{1,2} ?[0-9][A-Z]{2}/i;
	return postcodeRegEx.test(p);
}


// Formats a VALID postcode: AB120XY -> AB1 0XY //
function formatPostcode(p) {
	p = p.toUpperCase();
	if (isValidPostcode(p)) {
		var postcodeRegEx = /(^[A-Z]{1,2}[0-9]{1,2})([0-9][A-Z]{2}$)/i;
		return p.replace(postcodeRegEx,"$1 $2");
	} else {
		return p;
	}
}


// Tests to see if string is in correct date format of mm/dd/yyyy. //
// Tests to ensure date has correct number of days for the month and leap year. //
function isDate(strDate, strType) {

	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
	var matchArray = strDate.match(datePat); // is the format ok?
	
	if (matchArray == null) {
	alert(strType + ": Please enter date as either dd/mm/yyyy or dd-mm-yyyy.");
	return false;
	}
	
	month = matchArray[3]; // p@rse date into variables
	day = matchArray[1];
	year = matchArray[5];
	
	if (month < 1 || month > 12) { // check month range
	alert(strType + ": Month must be between 1 and 12.");
	return false;
	}
	
	if (day < 1 || day > 31) {
	alert(strType + ": Day must be between 1 and 31.");
	return false;
	}
	
	if ((month==4 || month==6 || month==9 || month==11) && day==31) {
	alert(strType + ": Month "+month+" doesn`t have 31 days.")
	return false;
	}
	
	if (month == 2) { // check for february 29th
	var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
	if (day > 29 || (day==29 && !isleap)) {
	alert(strType + ": February " + year + " doesn`t have " + day + " days.");
	return false;
	}
	}
	return true; // date is valid
}

// Tests to see if string is in correct format for email addresses //
function checkEmail(inputvalue){	
    var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
    if(pattern.test(inputvalue)){         
		return true;   
    }else{   
		return false; 
    }
}

// Tests strength of password //			
/*function passwordChanged(inputElement, strength) {
	
	var strength = $(strength);
	var strongRegex = new RegExp("^(?=.{6,})(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*\\W).*$", "g");
	var mediumRegex = new RegExp("^(?=.{6,})(((?=.*[A-Z])(?=.*[a-z]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[0-9]))).*$", "g");
	var enoughRegex = new RegExp("(?=.{6,}).*", "g");
	var pwd = inputElement;
	if (pwd.value.length==0) {
		//alert('None');
		strength.innerHTML = '<span style="color: red;">Enter Password</span>';
	} else if (false == enoughRegex.test(pwd.value)) {
		//alert('More');
		strength.innerHTML = '<span style="color: red;">More Characters</span>';		
	} else if (strongRegex.test(pwd.value)) {
		//alert('Strong');
		strength.innerHTML = '<span style="color: green;">Strong</span>';		
	} else if (mediumRegex.test(pwd.value)) {
		//alert('Medium');
		strength.innerHTML = '<span style="color: orange;">Medium</span>';		
	} else {
		//alert('Weak');
		strength.innerHTML = '<span style="color: red;">Weak</span>';		
	}
}
*/

// ]]>
