var formSubmit = true;  
		
function validateForm() { //v4.0
    var errors='';
    var emailFilter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    var phoneFilter = /^\d{3}-\d{3}-\d{4}$/;    
    
    if (document.forms[0].location.value == ''
        || document.forms[0].location.value == 'Postal Code') {
        errors += '- Postal code is required\n';
    }

    /*else {
        returnresult = postit(document.forms[0].location.value);
        if(returnresult != '') {
            errors += '- ' + returnresult + '\n';
        }
    }*/

    if (errors)
        alert('The following error(s) occurred:\n'+errors);
    
    document.MM_returnValue = (errors == '');
}

function formatPhoneNumber(textField) {
	var tempString = textField.value;
	tempString = tempString.replace(/[^0-9]/gi, "");
	tempString = tempString.toUpperCase();
	if (tempString.length>9) {
		if (tempString.length==11 && tempString.substring(0,1)=="1")
			tempString = tempString.substring(1);
		tempString = tempString.substring(0,3)+"-"+tempString.substring(3,6)+"-"+tempString.substring(6,10);
	}
	textField.value = tempString;
}

function numbersOnly(evt) {
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : 
        ((evt.which) ? evt.which : 0));
    if (charCode > 31 && (charCode < 48 || charCode > 57)) {       
        return false;
	  
    }
    return true;
}


function lettersOnly(evt) {
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : 
        ((evt.which) ? evt.which : 0));
    if (charCode > 31 && (charCode!= 45) && (charCode!= 32) &&(charCode < 65 || charCode > 90) && 
        (charCode < 97 || (charCode > 122))) {       
        return false;
    }
    return true;
}

//<!-- This script and many more are available free online at -->
//<!-- The JavaScript Source!! http://javascript.internet.com -->
//<!-- Original code by Peter Haydon -->
//<!-- peter_haydon@lineone.net -->

function postit(test){ //check postcode format is valid
    // test = document.details.pcode.value;
    size = test.length
    test = test.toUpperCase(); //Change to uppercase
    result = '';
    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.details.pcode.value = test; //write back to form field
    if (size < 6 || size > 8) { //Code length rule
        result = test + " is not a valid postcode - wrong length";
        //document.details.pcode.focus();
        return result;
    }

    if (!(isNaN(test.charAt(0)))) { //leftmost character must be alpha character rule
        result = test + " is not a valid postcode - cannot start with a number";
        //document.details.pcode.focus();
        return result;
    }

    if (isNaN(test.charAt(size-3))) { //first character of inward code must be numeric rule
       result = test + " is not a valid postcode - alpha character in wrong position";
       //document.details.pcode.focus();
       return result;
    }

    if (!(isNaN(test.charAt(size-2)))){ //second character of inward code must be alpha rule
       result = test + " is not a valid postcode - number in wrong position";
       //document.details.pcode.focus();
       return result;
    }

    if (!(isNaN(test.charAt(size-1)))){ //third character of inward code must be alpha rule
        result = test + " is not a valid postcode - number in wrong position";
        //document.details.pcode.focus();
        return result;
    }

    if (!(test.charAt(size-4) == " ")){//space in position length-3 rule
        result = test + " is not a valid postcode - no space or space in wrong position";
        //document.details.pcode.focus();
        return result;
    }

    count1 = test.indexOf(" ");
    count2 = test.lastIndexOf(" ");

    if (count1 != count2){//only one space rule
        result = test + " is not a valid postcode - only one space allowed";
        //document.details.pcode.focus();
        return result;
    }

    //alert("Postcode Format OK");
    return result;
}