
var hotelValues = new Array();

function checkHotel(){
	
	var destination = document.getElementById("DESTINATION");
	var selectedIndex = destination.selectedIndex;
	
	if(selectedIndex != 0 && selectedIndex != 1) {
	
		var optionName= destination.options[selectedIndex].value;
		
		if(optionName == "Hotel"){
			enableHotelElement("HOTEL NAME");
			enableHotelElement("HOTEL ADDRESS");
		} else {
			disableHotelElement("HOTEL NAME");
			disableHotelElement("HOTEL ADDRESS");
		}
	
	} else {
			disableHotelElement("HOTEL NAME");
			disableHotelElement("HOTEL ADDRESS");	
	}
}


function enableHotelElement (id) {
	
	var element = document.getElementById(id);
	
	// Change appearance
	
	element.style.backgroundColor = "#ffffff";
	element.style.color = "#000000";
	
	// Restore the value
	
	element.value = hotelValues[id];
	
}

function disableHotelElement (id) {
	
	var element = document.getElementById(id);
	
	// Change the appearance
	
	element.style.backgroundColor = "#dddddd";
	element.style.color = "#aaaaaa";
	
	// Save the value, and wipe it over
	
	hotelValues[id] = element.value;
	element.value = "N/A";
	
}



function checkblank(pFieldName,pLabel){

	var fieldname = theform[pFieldName];

	if(fieldname.value == ""){
		errorfield(fieldname,pLabel);
		return false;
	} else {
		fieldname.className = "type1";
		return true;
	}

}

function checkform(pFormId){

	theform = document.getElementById(pFormId);

    var tickettype = theform["1way_return"];
    var ticket_result = "";
 
    for( var i=0; i < tickettype.length; i++)
        if(tickettype[i].checked)
            ticket_result = tickettype[i].value;
 
    if(ticket_result == ""){
        alert("Please select a ticket type (one way or return)");
        return false;
    }


	var fields = new Array(["NAME","Full Name"], ["ADDRESS","Address"], ["PHONE NO. /MOBILE NO","Phone number"], ["EMAIL","Email address"], ["ARRIVAL DATE","Arrival date"], ["ARRIVAL FLIGHT NO. /  ARRIVAL TIME", "Arrival flight number and time"], ["HOTEL NAME","Hotel name"], ["HOTEL ADDRESS","Hotel address"], ["DEPARTURE DATE","Departure date"], ["DEPARTURE FLT NO / DEPARTURE TIME","Departure flight number and time"]);

	for(var i=0; i <= 3; i++){ // first four fields
		if (!checkblank(fields[i][0],fields[i][1])){
			return false;
		}
	}

	// Check Destination

	var destination = theform.DESTINATION;
	if(destination.selectedIndex < 2){
		alert("Please select a destination");
		destination.className = "type2"; destination.focus();
		return false;
	} else {
		destination.className = "type1";
	}

    // process the arrival if necessary
 
    var skipfields = ticket_result == "one way" ? 6 : 4 ;
	for(var i=skipfields; i < fields.length ; i++){ // remaining fields 
		if (!checkblank(fields[i][0],fields[i][1])){
			return false;
		}
	}


	if(!theform["NO CREDIT CARD"].checked){

		// Check Credit card details

		var fields = new Array( ["CREDIT CARD NO.","Credit Card Number"], ["NAME ON CARD","Credit Card Name"], ["EXPIRY DATE","Credit Card Expiry Date"]);

		for(var i=0; i < fields.length ; i++){ 
			if (!checkblank(fields[i][0],fields[i][1])){
				return false;
			}
		}

		var cctype = theform["CREDIT CARD TYPE"];
		if(cctype.selectedIndex < 1){
			alert("Please select a Credit Card Type");
			cctype.className = "type2"; cctype.focus();
			return false;
		} else {
			cctype.className = "type1";
		}
	} else {
		alert("You will be contacted by telephone to complete your booking");
	}

	//alert("Returning True!");
	return true; // disabled
}

function errorfield(pField,pPrintName){
	alert(pPrintName + " must not be blank");
	pField.className = "type2";
	pField.focus();
}

