<!-- // hide from non-js browsers

var aValidationFields = new Array();
var aFieldTypes = new Array();
var aValidationTypes = new Array();
var aMaxLengths = new Array();
var aMinLengths = new Array();
var aMaxValues = new Array();
var aMinValues = new Array();
var aFieldTexts = new Array();

var aFailedFields = new Array();
var aFailedFieldReasons = new Array();
var aFailedMaxLengths = new Array();
var aFailedMinLengths = new Array();
var aFailedMaxValues = new Array();
var aFailedMinValues = new Array();

//errorMessage = "This is a test";

function checkNumber(s)
{
    numbers = "0123456789";
    for (i = 0; i < s.length; i++) {
        if (numbers.indexOf(s.substr(i,1)) == -1) {
            return false;
        }
    }
    return true;
}


function fnModifyDayValidation(theForm, fieldStem, fieldText) {
	if (fieldStem == null || theForm == null ) { return false; }
	
	var FebLimit = 28;
	var DayLimit = 31;
	var DayMin = 1;
	
	objRefYear = "document." + theForm + "." + fieldStem + "_y";
	objYear = eval(objRefYear);
	objRefMonth = "document." + theForm + "." + fieldStem + "_m";
	objMonth = eval(objRefMonth);
	
	theYear = objYear.options[objYear.options.selectedIndex].value;
	theMonth = objMonth.options[objMonth.options.selectedIndex].value;
	
	if (theYear == "2000" || theYear == "2004" || theYear == "") { FebLimit = 29; }
	switch (theMonth)
	{
		case "":
			DayLimit = 999999;
			DayMin = 0;
			fieldText = "";
			break;
		case "2":
			DayLimit = FebLimit;
			break;
		case "4":
			DayLimit = 30;
			break;
		case "6":
			DayLimit = 30;
			break;
		case "9":
			DayLimit = 30;
			break;
		case "11":
			DayLimit = 30;
			break;
		default:
			DayLimit = 31;
	}
	fnRegisterField(fieldStem + '_d','text','max',0,DayLimit,DayMin,fieldText);
	fnRegisterField(fieldStem + '_d','text','min',0,DayLimit,DayMin,fieldText);
}

function fnRegisterField(theField, fieldType, validationType, maxLength, maxValue, minValue, fieldText) 
{
	//alert(theField);
	if (theField != null && fieldType != null && validationType != null && maxLength != null && maxValue != null && minValue != null && fieldText != null) {
		var thisFieldPosition = aValidationFields.length;
		// loop through existing registered fields - replace if theField already registered for this validationType, else append to array
		for (var i = 0; i < aValidationFields.length; i++) {
			if (aValidationFields[i] == theField && aValidationTypes[i] == validationType) { thisFieldPosition = i; }
		}
			
		// add to aValidationFields array
		aValidationFields[thisFieldPosition] = theField;
		
		// add to aFieldTypes
		aFieldTypes[thisFieldPosition] = fieldType;
		
		// add to aValidationTypes
		aValidationTypes[thisFieldPosition] = validationType;

		// add to aMaxLengths
		aMaxLengths[thisFieldPosition] = maxLength;
		
		// add to aMaxs
		aMaxValues[thisFieldPosition] = maxValue;
		
		// add to aMins
		aMinValues[thisFieldPosition] = minValue;
		
		// add to aFieldTexts
		aFieldTexts[thisFieldPosition] = fieldText;
	}
}

function fnRegisterConstraint(theField, fieldType, validationType, validationValue, fieldText) 
{
	//alert(theField + ", " fieldType + ", " + validationType + ", " + validationValue);
	if (theField != null && fieldType != null && validationType != null && validationValue != null && fieldText != null) {
		var thisFieldPosition = aValidationFields.length;
		// loop through existing registered fields - replace if theField already registered for this validationType, else append to array
		for (var i = 0; i < aValidationFields.length; i++) {
			if (aValidationFields[i] == theField && aValidationTypes[i] == validationType) { thisFieldPosition = i; }
		}
			
		// add to aValidationFields array
		aValidationFields[thisFieldPosition] = theField;
		
		// add to aFieldTypes
		aFieldTypes[thisFieldPosition] = fieldType;
		
		// add to aValidationTypes
		aValidationTypes[thisFieldPosition] = validationType;

        switch (validationType) {
            case "maxlength":
                // add to aMaxLengths
                aMaxLengths[thisFieldPosition] = validationValue;
                break;
            
            case "minlength":
                // add to aMinLengths
                aMinLengths[thisFieldPosition] = validationValue;
                break;
               
            case "max":
                // add to aMaxs
                aMaxValues[thisFieldPosition] = validationValue;
                break;
		
            case "min":
                // add to aMins
                aMinValues[thisFieldPosition] = validationValue;
                break;
        }
		
		// add to aFieldTexts
		aFieldTexts[thisFieldPosition] = fieldText;
	}
}

function fnCheckForm(theForm, submitOpt)
{
	//alert(theForm);
	if (submitOpt == null) { submitOpt = true; }
	aFailedFields = null;
	aFailedFields = new Array();
	aFailedFieldReasons = null;
	aFailedFieldReasons = new Array();
	aFailedMaxLengths = null;
	aFailedMaxLengths = new Array();
    aFailedMinLengths = null;
    aFailedMinLengths = new Array();
	aFailedMaxValues = null;
	aFailedMaxValues = new Array();
	aFailedMinValues = null;
	aFailedMinValues = new Array();
	
	//Make sure at least one checkbox is selected:
	if(theForm == "brochureRequest"){
		if (
		(eval("document." + theForm + ".check1.checked") == false) &&
		(eval("document." + theForm + ".check2.checked") == false) &&
		(eval("document." + theForm + ".check4.checked") == false) ) //&& (eval("document." + theForm + ".check4.checked") == false)
		
		{
			alert ("Please select at least one Brochure.");
			return false;
		}
	} 
	// End checkbox validation
	
	//Check that at least 1 Passenger is selected in the Early Booking Form:
	if(theForm == "earlyBooking"){
		if (
		(eval("document." + theForm + ".compAdults.options[0].selected")) &&
		(eval("document." + theForm + ".compChilds.options[0].selected")) &&
		(eval("document." + theForm + ".compInfs.options[0].selected"))) 
		{
			alert ("Please select at least one Passenger.");
			return false;
		}
	} 
	// End checkbox validation
	
	
	if (theForm != null && eval("document." + theForm)) {
		var i = 0;
		var theField, ValidationType, FieldType, MaxLength, MinLength, MaxValue, MinValue, FieldText;
		// loop through theField registered in aValidationFields
		for (i=0; i < aValidationFields.length; i++) {
			theField = aValidationFields[i];
			ValidationType = aValidationTypes[i];
			FieldType = aFieldTypes[i];
			MaxLength = aMaxLengths[i];
            MinLength = aMinLengths[i];
			MaxValue = aMaxValues[i];
			MinValue = aMinValues[i];
			FieldText = aFieldTexts[i];
			
			switch (ValidationType)
			{
				case "required" :
				// if theField has a ValidationType of "required", then get its FieldType
					switch (FieldType)
					{
						case "text" :
						// if the FieldType is "text" then check that its value is not empty
							if (eval("document." + theForm + "." + theField + ".value") == "") { 
								if (FieldText) { fnFailField('required',FieldText,0); }
							}
							break;
						
						case "textarea" :
						// if the FieldType is "textarea" then check that its value is not empty
							if (eval("document." + theForm + "." + theField + ".value") == "") { 
								if (FieldText) { fnFailField('required',FieldText,0); }
							}
							break;
						
						case "select" :
						// if the FieldType is "select", then check that the value of the selectedIndex is not empty
							if (eval("document." + theForm + "." + theField + ".options.selectedIndex") < 0 ||
                                                            eval("document." + theForm + "." + theField + ".options[document." + theForm + "." + theField + ".options.selectedIndex].value") == "") { 
								if (FieldText) { fnFailField('required',FieldText,0); }
							}
							break;
						
						case "radio" :
						// if the FieldType is "radio" then loop through the options array and check than one of them is 'checked'
							var optionsLength = eval("document." + theForm + "." + theField + ".length");
							var radioIsChecked = false;
							for (var j=0; j < optionsLength; j++) {
								if (eval("document." + theForm + "." + theField + "[" + j + "].checked") == true) {
									radioIsChecked = true;
								}
							}
							if (radioIsChecked == false) { if (FieldText) { fnFailField('required',FieldText,0); } }
							break;
						
						case "checkbox" :
						// if the FieldType is "checkbox" then check that the field is 'checked'
							if (eval("document." + theForm + "." + theField + ".checked") == false) { 
								if (FieldText) { fnFailField('required',FieldText,0); }
							}
							break;	
						
					}
					break;
				
				case "oneof-required" :
				// if theField has a ValidationType of "oneof-required", then get its FieldType
					switch (FieldType)
					{			
						case "checkbox" :
							// if the FieldType is "checkbox" then iterate over k and check for existence of a field called {theField + k} - 
							var checkboxIsChecked = false;
							var numberedFields = false;
							for (var k = 1; k <= 100; k++) {
								// if {theField + k} exists, see if it checked
								objRef = "document." + theForm + "." + theField + k;
								if ( (obj=eval(objRef)) != null ) {
									numberedFields = true;
									if (obj.checked == true) { checkboxIsChecked = true; }
								} else {
									k = 100;
								}
							}

							// if fields not numbered 1..x then look for an array of form elements with this name
							if (!numberedFields) {
								for (var k = 1; k <= 100; k++) {
									// if {theField[k]} exists, see if it checked
									objRef = "document." + theForm + "." + theField + "[" + k + "]";
									if ( (obj=eval(objRef)) != null ) {
										if (obj.checked == true) { checkboxIsChecked = true; }
									} else {
										k = 100;
									}
								}
							}

							// check that at least one of the fields iterated over was checked
							if (checkboxIsChecked == false ) { if (FieldText) { fnFailField('required',FieldText,0); } }
												
						// oneof-required is meaningless for other field types, so do nothing
						
					}
					break;
				
				case "email" :
				// if theField has a ValidationType of "email", then get its FieldType
					switch (FieldType)
					{			
						case "text" :
						// if the FieldType is "text" then check that its value has a valid email structure
							objRef = "document." + theForm + "." + theField + ".value";
							obj = eval(objRef);
							if (obj.indexOf('@') < 0 || obj.indexOf('.') < 0 || 
								obj.indexOf('@') > obj.lastIndexOf('.') - 2 || 
								obj.length < 5 || obj.indexOf('@') < obj.lastIndexOf('@') || 
								obj.lastIndexOf('.') > obj.length - 3 ) {
								if (FieldText) { fnFailField('email',FieldText,0); }
							}
							
							//confirm Email
							
							email = eval("document." + theForm + "." + theField + ".value");
							confirmEmail = eval("document." + theForm + "." + "confirmEmail.value");
							
							
							if (email != confirmEmail){
								if (FieldText) { fnFailField('confirmEmailAddress',FieldText,0); }
							}
							
							break;
						
						// email is meaningless for other field types, so do nothing
					}
					break;
				
				case "maxlength" :
				// if theField has a ValidationType of "maxlength", then get its FieldType and MaxLength
					switch (FieldType)
					{			
						case "text" :
						// if the FieldType is "text" then check that its value.length is not greater than MaxLength
							if (eval("document." + theForm + "." + theField + ".value.length") > MaxLength) { 
								if (FieldText) { fnFailField('maxlength',FieldText,MaxLength); }
							}
							break;
						
						case "textarea" :
						// if the FieldType is "textarea" then check that its value.length is not greater than MaxLength
							if (eval("document." + theForm + "." + theField + ".value.length") > MaxLength) { 
								if (FieldText) { fnFailField('maxlength',FieldText,MaxLength); }
							}
							break;
						
						// maxlength is meaningless for other field types, so do nothing
					}
					break;
				
				case "minlength" :
                                // if theField has a ValidationType of "minlength", then get its FieldType and MinLength
					switch (FieldType)
					{			
						case "text" :
                                                        // if the FieldType is "text" then check that its value.length is not less than MinLength
							if (eval("document." + theForm + "." + theField + ".value.length") < MinLength) { 
								if (FieldText) { fnFailField('minlength',FieldText,MinLength); }
							}
							break;
						
						case "textarea" :
                                                        // if the FieldType is "textarea" then check that its value.length is not less than MaxLength
							if (eval("document." + theForm + "." + theField + ".value.length") < MinLength) { 
								if (FieldText) { fnFailField('minlength',FieldText,MinLength); }
							}
							break;
						
						// minlength is meaningless for other field types, so do nothing
					}
					break;
				
				case "max" :
				// if theField has a ValidationType of "max", then get its FieldType
					switch (FieldType)
					{			
						case "text" :
						// if the FieldType is "text" then check that its value is not greater than MaxValue
							if (parseInt(eval("document." + theForm + "." + theField + ".value")) > MaxValue) {
								if (FieldText) { fnFailField('max',FieldText,MaxValue); }
							}
							break;
												
						// max is meaningless for other field types, so do nothing
					}
					break;
				
				case "min" :
				// if theField has a ValidationType of "max", then get its FieldType
					switch (FieldType)
					{			
						case "text" :
						// if the FieldType is "text" then check that its value is not less than MinValue
							if (eval("document." + theForm + "." + theField + ".value") == "" || isNaN(parseInt(eval("document." + theForm + "." + theField + ".value"))) || parseInt(eval("document." + theForm + "." + theField + ".value")) < MinValue) { 
								if (FieldText) { fnFailField('min',FieldText,MinValue); }
							}
							break;
												
						// min is meaningless for other field types, so do nothing
					}
					break;
			} // end of switch
		} // end of loop
	
		if (aFailedFields.length > 0) {
			fnReportFailures();

			return false;
		} else {
			if (submitOpt == true) {
				var objRef = "document." + theForm;
				var obj = eval(objRef);
				obj.submit();
			}
				//hacked in by lpb 19/03/04 & 20/07/04
				//submits registration for email on submission of form
				if(theForm == "brochureRequest"){
				if (eval("document." + theForm + ".check4.checked") == true) {
				var lpbfirstname = eval("document." + theForm + ".initials.value");
				var lpblastname = eval("document." + theForm + ".lastName.value");
				var lpbemailaddress = eval("document." + theForm + ".email.value");
				var emailurl = window.open('http://meontravel.ecircle-ag.com/public/remotebox_welcome.jsp?action=register&gid=40006178&firstName='+lpbfirstname+'&lastName='+lpblastname+'&uemail='+lpbemailaddress+'&action_type=subscribe', 'emailsubs', 'height=450,width=450,scrollbars=1,resizable=0,menubar=0,toolbar=0,status=0,location=0,directories=0,left=100,top=100');
				}
				}
			return true;
		}
		
	} // end of if form exists
	
	
}

function fnFailField(failType, fieldText, limitValue)
{
    //alert("fnFailField: " + failType + ", " + fieldText + ", " + limitValue);
	if (failType != null && fieldText != null) {
		var thisFailedField = aFailedFields.length;
		aFailedFields[thisFailedField] = fieldText;
		aFailedFieldReasons[thisFailedField] = failType;
		if (failType == "maxlength" && String(limitValue) != "" && limitValue != null && limitValue != 0) {
			aFailedMaxLengths[thisFailedField] = limitValue;
		}
		if (failType == "minlength" && String(limitValue) != "" && limitValue != null && limitValue != 0) {
			aFailedMinLengths[thisFailedField] = limitValue;
		}
		if (failType == "max" && String(limitValue) != "" && limitValue != null && limitValue != 0) {
			aFailedMaxValues[thisFailedField] = limitValue;
		}
		if (failType == "min" && String(limitValue) != "" && limitValue != null) {
			aFailedMinValues[thisFailedField] = limitValue;
		}
	}
}

function fnReportFailures()
{
	var sFailureMessage1 = "";
	var sFailureMessage2 = "";
	var sFailureMessage3 = "";
	var errorMessage = ""
	
	
	// first loop checks for any 'required' fields failed
	for (var i=0; i < aFailedFields.length; i++) {
		if (aFailedFieldReasons[i] == "required") {sFailureMessage1 = "Please make sure that you\nhave correctly completed\nthe following field(s):\n\n"; }
	}
	// second loop lists these 'required' fields
	for (var i=0; i < aFailedFields.length; i++) {
		if (aFailedFieldReasons[i] == "required") {sFailureMessage1 = sFailureMessage1 + "'" + aFailedFields[i].substr(0, 60) + "' \n"; }
	}

	// first loop checks for any 'email' fields failed
	for (var i=0; i < aFailedFields.length; i++) {
		if (aFailedFieldReasons[i] == "email") {sFailureMessage2 = "Please confirm that you have\nentered a valid Email address\nin the following field(s):\n\n"; }
	}
	// second loop lists these email fields
	for (var i=0; i < aFailedFields.length; i++) {
		if (aFailedFieldReasons[i] == "email") {sFailureMessage2 = sFailureMessage2 + "'" + aFailedFields[i].substr(0, 60) + "' \n"; }
	}

	// loop lists 'maxlength' fields and their maximum lengths
	for (var i=0; i < aFailedFields.length; i++) {
		if (aFailedFieldReasons[i] == "maxlength") {sFailureMessage3 = sFailureMessage3 + "'" + aFailedFields[i].substr(0, 60) + "' - max length is " + aFailedMaxLengths[i] + " characters\n"; }
	}

	// loop lists 'minlength' fields and their minimum lengths
	for (var i=0; i < aFailedFields.length; i++) {
		if (aFailedFieldReasons[i] == "minlength") {sFailureMessage3 = sFailureMessage3 + "'" + aFailedFields[i].substr(0, 60) + "...' - min length is " + aFailedMinLengths[i] + " characters\n"; }
	}
	
	// loop lists 'maxValue' fields and their maximum values
	for (var i=0; i < aFailedFields.length; i++) {
		if (aFailedFieldReasons[i] == "max") {sFailureMessage3 = sFailureMessage3 + "'" + aFailedFields[i].substr(0, 60) + "...' - maximum value is " + String(aFailedMaxValues[i]) + "\n"; }
	}
	
	// loop lists 'minValue' fields and their maximum values
	for (var i=0; i < aFailedFields.length; i++) {
		if (aFailedFieldReasons[i] == "min") {sFailureMessage3 = sFailureMessage3 + "'" + aFailedFields[i].substr(0, 60) + "...' - minumum value is " + aFailedMinValues[i] + "\n"; }
	}
	
	for (var i=0; i < aFailedFields.length; i++) {
		if (aFailedFieldReasons[i] == "confirmEmailAddress") {sFailureMessage2 = "The two Email Addresses that\nyou entered don't appear\nto be the same.\nPlease confirm this."; }
	}
	
	
	if (sFailureMessage1 != "" || sFailureMessage2 != "" || sFailureMessage3 != "") {
		errorMessage = (sFailureMessage1 + (sFailureMessage1 != ""?"\n\n":"") + sFailureMessage2 +  (sFailureMessage2 != ""?"\n\n":"") + sFailureMessage3);
		alert(errorMessage);
	}
}

// -->
