var errColour= "#FF0000";
var standardColour = "#A27A33";


	var textFieldLabels = new Array("Name","Surname","Email","Comments"); 
    var textFieldErrors = new Array(4);
    
    var emailFieldLabels = new Array("Email");
    var emailFieldErrors = new Array(1);
    
    var emptyFieldsExist = false;
    var emailErrors = false;


function sendReservation(){

	var submitRes = true;
	var frmName = "Form";
	emptyFieldsExist = false;
    emailErrors = false;

	checkCompulsoryTextFields(frmName);

    checkCompulsorySelectFields("reservation");    
  	if (emptyFieldsExist){
		errorMsg = "Please fill-in all fields marked red before you can proceed."; 
		alert(errorMsg);
		submitRes = false;
		return;
	}  
            
	checkEmailFields(frmName);
                
	if (emailErrors){
	   errorMsg = "Please correct the email address given before you can proceed (the values entered is not a valid email address).";
	   alert(errorMsg);
	   submitRes = false;
	   return;
	}
           
	

	



	if (!checkAlphabetic("reservation","firstname","lastname","city","First Name","Last Name","City")) {	
		submitRes = false;	
		return;
	}


	if (!checkAlphanumericPlusOther("reservation","-&,. ","address1","address2","Address Line 1", "Address Line 2")) {
		submitRes = false;
		return;
	}


	if (!checkAlphanumeric("reservation","postcode","ZIP/Postal Code")) {
		submitRes = false;
		return;
	}


	if (!checkNumericPlusOther("reservation"," +-","homePhone","businessPhone","mobilePhone","fax","Home Telephone","Business Telephone","Mobile Telephone","Fax Number")) {

		submitRes = false;
		return;
	}



	if (submitRes) {
		document.forms["reservation"].submit();
	}

}








function checkDates(formName){

	
	var checkInDate = document.forms[formName].elements["checkInDate"].value;
	var checkOutDate = document.forms[formName].elements["checkOutDate"].value;
	
	if (checkInDate == "dd/mm/yyyy" || checkInDate == "" || checkInDate == null){
        emptyFieldsExist  = true;
        textFieldErrors[7] = true;
        changeTextColour(textFieldLabels[7],errorColour);
    }
    else {
        textFieldErrors[7] = false;
        changeTextColour(textFieldLabels[7],okColour);
    }

    
    if (checkOutDate == "dd/mm/yyyy" || checkOutDate == "" || checkOutDate == null){
       	emptyFieldsExist  = true;
        textFieldErrors[8] = true;
        changeTextColour(textFieldLabels[8],errorColour);
    }
     else {
        textFieldErrors[8] = false;
        changeTextColour(textFieldLabels[8],okColour);
    }




}






function checkAlphabetic(formName){
//This function checks if alphabetic fields were  filled in correclty, i.e. with 
//capital or lower case arguments only. If some of the alphabetic fields were not it gives an
// error message and returns false otherwise it returns true.  The first argument is the form name
// on the document and the rest  of the arguments are alphabetic fields' names.  
//At least one alphabetic field should exist (otherwise there is no point to call this function).

//The n (n odd, so that n-1 is even) arguments to be passed are as follows:
//argument 0: form name
//arguments 1 to (n-1)/2: field names
//arguments (n-1)/2 + 1 to n-1: field labels

var errorFields = "";
var noFields  = (arguments.length  - 1)/2;



	for (var curFieldIndex = 1; curFieldIndex <= noFields;curFieldIndex++) {
		
		if (!isAlphabetic(document.forms[formName].elements[arguments[curFieldIndex]].value,true)) {
			changeTextColour(arguments[curFieldIndex],errColour);
			errorFields=errorFields + "\n   _ " + arguments[curFieldIndex + noFields];
		}
		else {
			changeTextColour(arguments[curFieldIndex],standardColour );
		}
	}


	if (errorFields != "") {
		alert("The following fields should only contain alphabetic characters, i.e. not numerical digits or other characters, but they do so:" +errorFields + ".\n\nPlease correct before submitting your reservation.");
		return false;
	}
	else {
		return true;
	}


}


function checkAlphabeticPlusOther(formName,otherValidChars){
//Works similar to checkAlphabetic with the addition of one argument

var errorFields = "";
var noFields  = (arguments.length  - 2)/2;



	for (var curFieldIndex = 2; curFieldIndex <= noFields+1;curFieldIndex++) {
		if (!isAlphabeticPlusOther(document.forms[formName].elements[arguments[curFieldIndex]].value,otherValidChars,true)) {
			changeTextColour(arguments[curFieldIndex],errColour);
			errorFields=errorFields + "\n   _ " + arguments[curFieldIndex + noFields];
		}
		else {
			changeTextColour(arguments[curFieldIndex],standardColour );
		}

	}


	if (errorFields != "") {
		alert("The following fields can only contain alphanumeric characters, comma (,), dot (.), dash (-), space ( ) and the And sign (&):" +errorFields + ".\n\nPlease correct before submitting your reservation.");
		return false;
	}
	else {
		return true;
	}


}

function checkAlphanumericPlusOther(formName,otherValidChars){
//Works similar to checkAlphabetic with the addition of one argument

var errorFields = "";
var noFields  = (arguments.length  - 2)/2;



	for (var curFieldIndex = 2; curFieldIndex <= noFields+1;curFieldIndex++) {
		if (!isAlphaNumericPlusOther(document.forms[formName].elements[arguments[curFieldIndex]].value,otherValidChars,true)) {
			changeTextColour(arguments[curFieldIndex],errColour);
			errorFields=errorFields + "\n   _ " + arguments[curFieldIndex + noFields];
		}
		else {
			changeTextColour(arguments[curFieldIndex],standardColour );
		}

	}


	if (errorFields != "") {
		alert("The following fields can only contain alphanumeric characters, comma (,), dot (.), dash (-), space ( ) and the And sign (&):" +errorFields + ".\n\nPlease correct before submitting your reservation.");
		return false;
	}
	else {
		return true;
	}


}


function checkNumericPlusOther(formName,otherValidChars){
//Works similar to checkAlphabetic with the addition of one argument

var errorFields = "";
var noFields  = (arguments.length  - 2)/2;


	for (var curFieldIndex = 2; curFieldIndex <= noFields+1;curFieldIndex++) {
		if (!isNumericPlusOther(document.forms[formName].elements[arguments[curFieldIndex]].value,otherValidChars,true)) {
			changeTextColour(arguments[curFieldIndex],errColour);
			errorFields=errorFields + "\n   _ " + arguments[curFieldIndex + noFields];
		}
		else {
			changeTextColour(arguments[curFieldIndex],standardColour );
		}

	}


	if (errorFields != "") {
		alert("The following fields can only contain numeric characters, the Plus sign (+) and dash (-):" +errorFields + ".\n\nPlease correct before submitting your reservation.");
		return false;
	}
	else {
		return true;
	}


}

function checkAlphanumeric(formName){
//Works similar to checkAlphabetic

var errorFields = "";
var noFields  = (arguments.length  - 1)/2;



	for (var curFieldIndex = 1; curFieldIndex <= noFields;curFieldIndex++) {
		if (!isAlphanumeric(document.forms[formName].elements[arguments[curFieldIndex]].value,true)) {
			changeTextColour(arguments[curFieldIndex],errColour);
			errorFields=errorFields + "\n   _ " + arguments[curFieldIndex + noFields];
		}
		else {
			changeTextColour(arguments[curFieldIndex],standardColour );
		}

	}


	if (errorFields != "") {
		alert("The following fields can only contain alphanumeric characters:" +errorFields + ".\n\nPlease correct before submitting your reservation.");
		return false;
	}
	else {
		return true;
	}


}


