<!-- Hide from old browsers

function isValidEmail(strEmail){
	// This function returns true if the email is valid and false if not
	validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;

   // Search email text for regular expression matches
    if (strEmail.search(validRegExp) == -1) {return false;} 
    return true; 
}

function validate_required(field,alerttxt){
	with (field){
		if (value==null||value==""){
			alert(alerttxt);return false
		}
		else {
			return true
		}
	}
}

// Date validation script for dd/mm/yyyy from www.smartwebby.com/dhtml/
//These functions are used by the isDate function below which in turn is used by the CheckDate function


// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=2000;
var maxYear=2100;

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 isDate(dtStr){
	var daysInMonth = DaysArray(12)
	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
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : dd/mm/yyyy\nFor example the 3rd December 2008 would be 03/12/2008")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}

// End of date validation script for dd/mm/yyyy from www.smartwebby.com/dhtml/

function CheckDate(strInputDateControl,strOutputDateControl)
{
	//Input a value from a form control. Check its format is dd/mm/yyyy. Then convert format to "dd mmm yyyy" eg "03 Dec 1969". And output the result to a form control. The input and output form controls can be the same. Returns true if successful and false if Not.
	
	strMyDate=document.getElementById(strInputDateControl).value;
	
	//Check the date has a valid format of dd/mm/yyyy	
	if (isDate(strMyDate)==false){return false;}
	
	if (strMyDate.length != 10) {
		alert("The date format should be : dd/mm/yyyy\nFor example the 3rd December 2008 would be 03/12/2008\nHave you missed out a leading zero?")
		return false;
	}

	strDay=strMyDate.substr(0,2);
	strMonth=strMyDate.substr(3,2);
	strYear=strMyDate.substr(6,4);

	switch (strMonth)
	{
	case "01":
	  strMonth="Jan"
	  break
	case "02":
	  strMonth="Feb"
	  break
	case "03":
	  strMonth="Mar"
	  break
	case "04":
	  strMonth="Apr"
	  break
	case "05":
	  strMonth="May"
	  break
	case "06":
	  strMonth="Jun"
	  break
	case "07":
	  strMonth="Jul"
	  break
	case "08":
	  strMonth="Aug"
	  break
	case "09":
	  strMonth="Sep"
	  break
	case "10":
	  strMonth="Oct"
	  break
	case "11":
	  strMonth="Nov"
	  break
	case "12":
	  strMonth="Dec"
	  break
	default:
	  alert("Invalid date format. The month has been recorded as "+strMonth);
	  return false;
	}

	strMyDate=document.getElementById(strOutputDateControl).value = strDay+" "+strMonth+" "+strYear;
	return true;
}

function validate_form(thisform){
	with (thisform){		

		if (validate_required(forename,"Please provide your forename or at least an initial. Thanks.")==false){
			forename.focus();return false
		}

		if (validate_required(surname,"Please provide your surname.")==false){
			surname.focus();return false
		}

		if (validate_required(phone,"Please provide a day-time phone number in case we need to discuss any aspect of the fault or repair with you.")==false){
			phone.focus();return false
		}

		//Validate e-mail if user has requested product updates OR if an e-mail has been entered
		if (requestproductupdates.checked){	
			if (validate_required(submittedemail,"You've asked to be updated with Latronics product innovations. Please provide an e-mail address to receive the updates.")==false){
				submittedemail.focus();return false
			}
		}

		if ((requestproductupdates.checked)||(submittedemail.value!="")){	
				if (!isValidEmail(submittedemail.value)){
					alert("Sorry but the e-mail address provided isn't valid.\n\nPlease check it and try again.");
					submittedemail.focus();return false;
				}

				if (submittedemail.value!=email2.value){alert("Sorry but the e-mail confirmation doesn't match the first one given.\n\nPlease check it and try again.");
					email2.focus();return false;
				}
		}

		if (validate_required(deliveryaddress,"Please provide your delivery address.")==false){
			deliveryaddress.focus();return false
		}

		if (validate_required(postaladdress,"Please provide your postal address.")==false){
			postaladdress.focus();return false
		}

		if (validate_required(serialno,"Please provide the serial number for your Latronics product.")==false){
			serialno.focus();return false
		}

		if (!isInteger(serialno.value)){// Check Serial No contains only numbers - string will already have been trimmed
			alert("Please check that the serial number contains only numbers and no other characters.");
			serialno.focus();return false
		}

		if (serialno.value.length!=9){// Check Serial No is 9 digits
			alert("Latronics serial numbers contain 9 digits - please check your Serial number and try again. Thanks.");
			serialno.focus();return false
		}

		if (validate_required(dateofpurchase,"Please provide the date on your sales receipt for this product in the format (dd/mm/yyyy).\n\nFor example the 3rd December 2008 would be 03/12/2008")==false){
			dateofpurchase.focus();return false
		}
		
		//Check Date format and also populate the control dateofpurchase2 with the correct format if date check is successful
		if (CheckDate("dateofpurchase","dateofpurchase2")==false)
			{dateofpurchase.focus();return false}
	}
}

function clearForm(){
  var r=confirm("Are you sure you want to remove all information from this form?\n\nClick 'OK' for yes or 'Cancel' for no.")
  if (r==true){
	document.forms[0].reset()
  }
  else{
    alert("You've chosen not to clear the form so please continue\nand click 'Submit' when ready.")
  }
}

// end script hide from old browsers -->