//######################## MAIN FORM VALIDATION FUNCTION ######################
function validate() {

	var msg = '';

	if (document.frmComp.slctTitle.selectedIndex == 0){
		msg+="\nTitle";
	}	
	
	if (document.frmComp.txtFirstName.value == "") {
		msg+="\nFirst Name";
	} 

	if (document.frmComp.txtSurname.value == "") {
		msg+="\nLast Name";
	}			

	if (document.frmComp.slctCountry.value == 0) {
		msg+="\nCountry";
	}								

	if (document.frmComp.txtEmail.value == "") {
		msg+="\nEmail Address";
	}
	
	if (document.frmComp.txtEmail2.value == "") {
		msg+="\nConfirm Email";
	}
	
	if ( document.frmComp.txtEmail.value != document.frmComp.txtEmail2.value ) {
		msg+="\nEmail addresses do not match.";
	}
	
	if (!document.frmComp.agree.checked) {
		msg+='\nYou must agree to the Privacy Policy and/or Terms and Conditions.';
	}

	if (msg != "") {
		alert("Please complete the following field(s)\n" + msg);
		return false;
	}

	if (!isEmail(document.frmComp.txtEmail.value)) {
		alert("Please enter a valid email address");
		return false;	
	}

}

//###################################
function isMobile( str ) {
	var r1 = new RegExp("[a-z]|[A-Z]");
	return (!r1.test(str));
}

//#############################
function checkCountry() {
	if (document.all){
		if(frmComp.slctCountry.value == "GBR"){
			frmComp.txtzipcode.value = "";
			frmComp.txtzipcode.disabled = true;
			frmComp.txtPostcode1.disabled = false;
			frmComp.txtPostcode3.disabled = false;
		} else {
			frmComp.txtPostcode1.value = "";
			frmComp.txtPostcode3.value = "";
			frmComp.txtzipcode.disabled = false;
			frmComp.txtPostcode1.disabled = true;
			frmComp.txtPostcode3.disabled = true;
		}
	}	
}

//#######################################################
function isDOB(dd,mm,yyyy) {

	monthdays = new Array(12);
	monthdays[0]=31;
	monthdays[1]=28;
	monthdays[2]=31;
	monthdays[3]=30;
	monthdays[4]=31;
	monthdays[5]=30;
	monthdays[6]=31;
	monthdays[7]=31;
	monthdays[8]=30;
	monthdays[9]=31;
	monthdays[10]=30;
	monthdays[11]=31;
	
	todayDate=new Date();
	thisyear=todayDate.getFullYear();

	if (isNaN(dd) || isNaN(mm) || isNaN(yyyy)) {
		alert('Please ensure you have entered numbers for the Date of Birth');
		return false;
	}

	if (((yyyy % 4 == 0) && !(yyyy % 100 == 0)) ||(yyyy % 400 == 0)) monthdays[1]++;
	
	if ((yyyy < 1900) || (yyyy >= (thisyear+1900))) {
		alert('Please check the year for the Date of Birth');
		return false;
	}
	
	if ((mm > 12) || (mm < 1)) {
		alert('Please check the month for the Date of Birth');
		return false;
	}
	
	if ((dd > monthdays[mm - 1]) || (dd < 1)) {
		alert('Please check the day for the Date of Birth');
		return false;
	}
	
	return true;

}

//#################################
function isEmail(str) {
	// are regular expressions supported?
	var supported = 0;
	if (window.RegExp) {
		var tempStr = "a";
		var tempReg = new RegExp(tempStr);
		if (tempReg.test(tempStr)) supported = 1;
	}
	if (!supported) 
		return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
	var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
	return (!r1.test(str) && r2.test(str));
}

function doGender() {
	f = document.forms[0];
	
	if( (f.slctTitle.selectedIndex == 1) || (f.slctTitle.selectedIndex == 5) ) {
		f.slctSex.selectedIndex = 1;
	} else {
		f.slctSex.selectedIndex = 2;
	}
}
