<!-- 

/* 
 * Airfare Search Javascript
 */
 
var element;

function hide(obj) {
	document.getElementById(obj).style.display = 'none';
	currentOpac('banner', 100, 1000);
}

var ajax = new sack();

function getFromCountries(sel)
{
	obj_name = sel.id;
	element = "from_country";
	
	var from_airport_id = sel.options[sel.selectedIndex].value;
	document.getElementById(element).options.length = 0;	// Empty airport select box
	
	if(from_airport_id.length>0){
		ajax.requestFile = '/ajax/getFromCountries.php?from_airport_id='+from_airport_id;	// Specifying which file to get
		ajax.onLoading = showLoading;
		ajax.onCompletion = createOutput;	// Specify function that will be executed after file has been found
		ajax.runAJAX();		// Execute AJAX function
	}
	
}

function getCityList(sel)
{	
	
	obj_name = sel.id;
	
	if(obj_name == "from_country") {
		currentOpac('banner', 50, 1000);
		hide("to_popup");
		document.getElementById('from_popup').style.display = "";
		element = "from_city_id";
		element2 = "from_airport_id";
	} else if(obj_name == "to_country") {
		currentOpac('banner', 50, 1000);
		hide("from_popup");
		document.getElementById('to_popup').style.display = "";
		element = "to_city_id";
		element2 = "to_airport_id";
	}
	
	var country_id = sel.options[sel.selectedIndex].value;
	clearMenu(element, 0);
	clearMenu(element2, 1);
	if(country_id.length>0){
		ajax.requestFile = '/ajax/getCities.php?country_id='+country_id;	// Specifying which file to get
		ajax.onLoading = showLoading;
		ajax.onCompletion = createOutput;	// Specify function that will be executed after file has been found
		ajax.runAJAX();		// Execute AJAX function
	}
}

function getAirportList(sel)
{	
	
	obj_name = sel.id;
	
	if(obj_name == "from_city_id") {
		element = "from_airport_id";
	} else if(obj_name == "to_city_id") {
		element = "to_airport_id";
	}
	
	var city_id = sel.options[sel.selectedIndex].value;
	document.getElementById(element).options.length = 0;	// Empty airport select box
	if(city_id.length>0){
		ajax.requestFile = '/ajax/getAirports.php?city_id='+city_id;	// Specifying which file to get
		ajax.onLoading = showLoading;
		ajax.onCompletion = createOutput;	// Specify function that will be executed after file has been found
		ajax.runAJAX();		// Execute AJAX function
	}
}

function getToCountries(sel)
{
	obj_name = sel.id;
	element = "to_country";
	
	var to_airport_id = sel.options[sel.selectedIndex].value;
	document.getElementById(element).options.length = 0;	// Empty airport select box
	
	if(to_airport_id.length>0){
		ajax.requestFile = '/ajax/getToCountries.php?to_airport_id='+to_airport_id;	// Specifying which file to get
		ajax.onLoading = showLoading;
		ajax.onCompletion = createOutput;	// Specify function that will be executed after file has been found
		ajax.runAJAX();		// Execute AJAX function
	}
	
}

function getCityList2(sel)
{	
	
	obj_name = sel.id;
	from_airport_id = document.getElementById('from_airport_id').value;
	
	if(obj_name == "from_country") {
		currentOpac('banner', 50, 1000);
		// hide("to_popup");
		document.getElementById('from_popup').style.display = "";
		element = "from_city_id";
		element2 = "from_airport_id";
	} else if(obj_name == "to_country") {
		currentOpac('banner', 50, 1000);
		// hide("from_popup");
		document.getElementById('to_popup').style.display = "";
		element = "to_city_id";
		element2 = "to_airport_id";
	}
	
	var country_id = sel.options[sel.selectedIndex].value;
	clearMenu(element, 0);
	clearMenu(element2, 1);
	if(country_id.length>0){
		ajax.requestFile = '/ajax/getCities2.php?country_id='+country_id+'&from_airport_id='+from_airport_id;	// Specifying which file to get
		ajax.onLoading = showLoading;
		ajax.onCompletion = createOutput;	// Specify function that will be executed after file has been found
		ajax.runAJAX();		// Execute AJAX function
	}
}

function getAirportList2(sel)
{	
	
	obj_name = sel.id;
	from_airport_id = document.getElementById('from_airport_id').value;
	element = "to_airport_id";
	
	var city_id = sel.options[sel.selectedIndex].value;
	document.getElementById(element).options.length = 0;	// Empty airport select box
	if(city_id.length>0){
		ajax.requestFile = '/ajax/getAirports2.php?city_id='+city_id+'&from_airport_id='+from_airport_id;	// Specifying which file to get
		ajax.onLoading = showLoading;
		ajax.onCompletion = createOutput;	// Specify function that will be executed after file has been found
		ajax.runAJAX();		// Execute AJAX function
	}
}

function clearMenu(element, clear) {
	var obj = document.getElementById(element);
	obj.options.length = 0;
	
	if(clear == 1) {
		obj.options[obj.options.length] = new Option('PLEASE SELECT','N/A');
	} 
}

function showLoading()
{	
	var obj = document.getElementById(element);
	obj.options[obj.options.length] = new Option('LOADING...','N/A');
}

function createOutput()
{
	document.getElementById(element).options.length = 0;	// Empty city select box
	var obj = document.getElementById(element);
	obj.options[obj.options.length] = new Option('PLEASE SELECT','N/A');
	eval(ajax.response);	// Executing the response from Ajax as Javascript code	
}

/* 
 * Form Javascripts
 */

function checkForm(form) 
{
	
	from_airport_id = document.getElementById('from_airport_id').value;
	to_airport_id = document.getElementById('to_airport_id').value;
	
	search_return_Day = document.getElementById('search_return_Day').value;
	search_return_Month = document.getElementById('search_return_Month').value;
	search_return_Year = document.getElementById('search_return_Year').value;
	var return_date = new Date();
	return_date.setFullYear(search_return_Year, (search_return_Month-1), search_return_Day);
	
	search_departure_Day = document.getElementById('search_departure_Day').value;
	search_departure_Month = document.getElementById('search_departure_Month').value;
	search_departure_Year = document.getElementById('search_departure_Year').value;
	var departure_date = new Date();
	departure_date.setFullYear(search_departure_Year, (search_departure_Month-1), search_departure_Day);
	
	if(isNaN(from_airport_id)) {
		alert("Please select Departure Airport");
	} else if(isNaN(to_airport_id)) {
		alert("Please select Destination Airport");
	} else if(return_date < departure_date) {
		alert("Please make sure Date of Return is valid");
	} else {
		form.submit();
	}
	
}

function flipRows(this_element, element_prefix, start, end) {
	
	for(i=start; i<=end; i++) {
		
		obj = document.getElementById(element_prefix + i);
		
		if(this_element.checked == true) {
			obj.style.display = '';
		} else {
			obj.style.display = 'none';
		}
		
	}
	
}

function disable(element, value) {
	
	element = document.getElementById(element);
	
	if(value == 'Yes') {
		element.value = '';
		element.disabled = false;
	} else {
		element.disabled = true;
	}
		
}

function changeBG(element, color) {
		
	// element = document.getElementById(element);
	element.style.backgroundColor = color;
		
}

function statusField(this_element, target_element) {
	
	
	if(this_element.value == 'Student' || this_element.value == 'Teacher') {
		document.getElementById(target_element).disabled = false;
		document.getElementById(target_element).style.backgroundColor = "#FFFFFF";
	} else {
		document.getElementById(target_element).disabled = true;
		document.getElementById(target_element).style.backgroundColor = "#ECECEC";
	}
	
}

var cheap_flights_checked = 0;
var travel_insurance_checked = 0;
var hotel_accomodation_checked = 0;

function add_template(this_element, item_name, target_element) {
	
	temp = document.getElementById(target_element).value + "\n" ;
	obj = item_name + "_checked";
	
	if(item_name == "cheap_flights") {
		new_text = "Cheap Flights: \n ----------------- \n From: \n Destination: \n Date of Travel: \n One way or Return: \n\n";
	} else if(item_name == "travel_insurance") {
		new_text = "Travel Insurace: \n -------------------- \n Duration of travel: \n\n";
	} else if(item_name == "hotel_accomodation") {
		new_text = "Hotel Accomodation: \n ------------------------- \n Preference: Budget, Intermediate or Five Star \n\n";
	}
	
	if(this_element.checked == true && eval(obj) == 0) {
		document.getElementById(target_element).value = temp + new_text;
		eval(obj + " = 1");
	}
	
}

function processForm(form_name) {
	
	process = document.getElementById('process');
	form = document.getElementById(form_name);
	
	if(form_name == 'mailinglist') {
		
		/* 
		 * ORIGINAL
		 *
		first_name = document.getElementById('first_name');
		last_name = document.getElementById('last_name');
		email_address = document.getElementById('email_address');
		
		if(first_name.value.length == 0) {
			alert("First Name is a required field.");
			first_name.focus();
		} else if(last_name.value.length == 0) {
			alert("Last Name is a required field.");
			last_name.focus();
		} else if(emailCheck(email_address.value) != true) {
			alert(emailCheck(email_address.value));
			email_address.focus();
		} else {
			process.value = 'Y';
			form.submit();
		}
		 */
		
		full_name = document.getElementById('full_name');
		company_name = document.getElementById('company_name');
		contact_number = document.getElementById('contact_number');
		email_address = document.getElementById('email_address');
		
		if(full_name.value.length == 0) {
			alert("Full Name is a required field.");
			full_name.focus();
		} else if(company_name.value.length == 0) {
			alert("Company Name is a required field.");
			company_name.focus();
		} else if(contact_number.value.length == 0) {
			alert("Contact Name is a required field.");
			contact_number.focus();
		} else if(emailCheck(email_address.value) != true) {
			alert(emailCheck(email_address.value));
			email_address.focus();
		} else {
			process.value = 'Y';
			form.submit();
		}
		
	} else if(form_name == 'enquiry') {
		
		first_name = document.getElementById('first_name');
		last_name = document.getElementById('last_name');
		email_address = document.getElementById('email_address');
		status = document.getElementById('status');
		name_of_school = document.getElementById('name_of_school');
		additional_information = document.getElementById('additional_information');
		
		if(first_name.value.length == 0) {
			alert("First Name is a required field.");
			first_name.focus();
		} else if(last_name.value.length == 0) {
			alert("Last Name is a required field.");
			last_name.focus();
		} else if(emailCheck(email_address.value) != true) {
			alert(emailCheck(email_address.value));
			email_address.focus();
		} else if(status.value == 'N/A') {
			alert("Please select your Status.");
			status.focus();
		} else if(name_of_school.disabled == false && name_of_school.value.length == 0) {
			alert("Name of School is a required field.");
			name_of_school.focus();
		} else if(additional_information.value.length == 0) {
			alert("Additional Information is a required field.");
			additional_information.focus();
		} else {
			process.value = 'Y';
			form.submit();
		}
		
	} else if(form_name == 'booking') {
		
		first_name = document.getElementById('first_name');
		last_name = document.getElementById('last_name');
		email_address = document.getElementById('email_address');
		status = document.getElementById('status');
		name_of_school = document.getElementById('name_of_school');
		
		if(first_name.value.length == 0) {
			alert("First Name is a required field.");
			first_name.focus();
		} else if(last_name.value.length == 0) {
			alert("Last Name is a required field.");
			last_name.focus();
		} else if(emailCheck(email_address.value) != true) {
			alert(emailCheck(email_address.value));
			email_address.focus();
		} else if(status.value == 'N/A') {
			alert("Please select your Status.");
			status.focus();
		} else if(name_of_school.disabled == false && name_of_school.value.length == 0) {
			alert("Name of School is a required field.");
			name_of_school.focus();
		} else {
			process.value = 'Y';
			form.submit();
		}
		
	}
	
}

function emailCheck (emailStr) {
	
	/* The following variable tells the rest of the function whether or not
	to verify that the address ends in a two-letter country or well-known
	TLD.  1 means check it, 0 means don't. */
	
	var checkTLD=1;
	
	/* The following is the list of known TLDs that an e-mail address must end with. */
	
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	
	/* The following pattern is used to check if the entered e-mail address
	fits the user@domain format.  It also is used to separate the username
	from the domain. */
	
	var emailPat=/^(.+)@(.+)$/;
	
	/* The following string represents the pattern for matching all special
	characters.  We don't want to allow special characters in the address. 
	These characters include ( ) < > @ , ; : \ " . [ ] */
	
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	
	/* The following string represents the range of characters allowed in a 
	username or domainname.  It really states which chars aren't allowed.*/
	
	var validChars="\[^\\s" + specialChars + "\]";
	
	/* The following pattern applies if the "user" is a quoted string (in
	which case, there are no rules about which characters are allowed
	and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
	is a legal e-mail address. */
	
	var quotedUser="(\"[^\"]*\")";
	
	/* The following pattern applies for domains that are IP addresses,
	rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
	e-mail address. NOTE: The square brackets are required. */
	
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	
	/* The following string represents an atom (basically a series of non-special characters.) */
	
	var atom=validChars + '+';
	
	/* The following string represents one word in the typical username.
	For example, in john.doe@somewhere.com, john and doe are words.
	Basically, a word is either an atom or quoted string. */
	
	var word="(" + atom + "|" + quotedUser + ")";
	
	// The following pattern describes the structure of the user
	
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	
	/* The following pattern describes the structure of a normal symbolic
	domain, as opposed to ipDomainPat, shown above. */
	
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	
	/* Finally, let's start trying to figure out if the supplied address is valid. */
	
	/* Begin with the coarse pattern to simply break up user@domain into
	different pieces that are easy to analyze. */
	
	var matchArray=emailStr.match(emailPat);
	
	if (matchArray==null) {
	
	/* Too many/few @'s or something; basically, this address doesn't
	even fit the general mould of a valid e-mail address. */
	
	return ("Email address seems incorrect (check @ and .'s)");
	// return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];
	
	// Start by checking that only basic ASCII characters are in the strings (0-127).
	
	for (i=0; i<user.length; i++) {
	if (user.charCodeAt(i)>127) {
	return("Ths username contains invalid characters.");
	// return false;
	   }
	}
	for (i=0; i<domain.length; i++) {
	if (domain.charCodeAt(i)>127) {
	return("Ths domain name contains invalid characters.");
	// return false;
	   }
	}
	
	// See if "user" is valid 
	
	if (user.match(userPat)==null) {
	
	// user is not valid
	
	return("The username doesn't seem to be valid.");
	// return false;
	}
	
	/* if the e-mail address is at an IP address (as opposed to a symbolic
	host name) make sure the IP address is valid. */
	
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {
	
	// this is an IP address
	
	for (var i=1;i<=4;i++) {
	if (IPArray[i]>255) {
	return("Destination IP address is invalid!");
	//return false;
	   }
	}
	return true;
	}
	
	// Domain is symbolic name.  Check if it's valid.
	 
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) {
	if (domArr[i].search(atomPat)==-1) {
	return("The domain name does not seem to be valid.");
	//return false;
	   }
	}
	
	/* domain name seems valid, but now make sure that it ends in a
	known top-level domain (like com, edu, gov) or a two-letter word,
	representing country (uk, nl), and that there's a hostname preceding 
	the domain or country. */
	
	if (checkTLD && domArr[domArr.length-1].length!=2 && 
	domArr[domArr.length-1].search(knownDomsPat)==-1) {
	return("The address must end in a well-known domain or two letter " + "country.");
	//return false;
	}
	
	// Make sure there's a host name preceding the domain.
	
	if (len<2) {
	return("This address is missing a hostname!");
	// return false;
	}
	
	// If we've gotten this far, everything's valid!
	return true;
}

-->