// JavaScript Document

// verify the email register form
function verify() {
    var themessage = "Please make sure you complete the following fields: ";
	if ((document.regform.EMAIL.value.indexOf('@', 0) == -1 || document.regform.EMAIL.value.indexOf('.', 0) == -1))
		themessage = themessage + "\n - Email address";
	 	
	 if (themessage == "Please make sure you complete the following fields: ")
		return true;
	else {
		alert(themessage);
		return false; 
	}
	
}

// verify the email quick quote form
function verify2() {
	var themessage = "Please make sure you complete the following fields: ";
	if ((document.qform.QNAME.value=="") || (document.qform.QNAME.value=="Enter your name..."))
		themessage = themessage + "\n - Name";
	 if ((document.qform.QEMAIL.value.indexOf('@', 0) == -1 || document.qform.QEMAIL.value.indexOf('.', 0) == -1) || (document.qform.QEMAIL.value=="") || (document.qform.QEMAIL.value=="Enter your email..."))
		themessage = themessage + "\n - Email";
	 if ((document.qform.QCOMMENTS.value=="") || (document.qform.QCOMMENTS.value=="Enter your enquiry..."))
		themessage = themessage + "\n - Enquiry";
	 if (themessage == "Please make sure you complete the following fields: ")
		return true;
	else {
		alert(themessage);
		return false; 
	}
	

}


// verify the booking form
function verifybooking() {
    var themessage = "Please make sure you complete the following fields: ";

	if (document.form1.name.value=="")
		themessage = themessage + "\n - Name";

	if (document.form1.dept.value=="")
		themessage = themessage + "\n - Departure date";


	if ((document.form1.email.value.indexOf('@', 0) == -1 || document.form1.email.value.indexOf('.', 0) == -1))
		themessage = themessage + "\n - Email address";
	 	
	if (document.form1.comments.value=="")
		themessage = themessage + "\n - Comments";



	 if (themessage == "Please make sure you complete the following fields: ")
		return true;
	else {
		alert(themessage);
		return false; 
	}
	
}


// verify the send to a friend form
function verifysendfriend() {
    var themessage = "Please make sure you complete the following fields: ";

	if (document.form1.name.value=="")
		themessage = themessage + "\n - Name";

	 

	if ((document.form1.email.value.indexOf('@', 0) == -1 || document.form1.email.value.indexOf('.', 0) == -1))
		themessage = themessage + "\n - Email address";
	 	
	if (document.form1.name2.value=="")
		themessage = themessage + "\n - Friend's name";

	 

	if ((document.form1.email2.value.indexOf('@', 0) == -1 || document.form1.email2.value.indexOf('.', 0) == -1))
		themessage = themessage + "\n - Friend's email address";


	if (document.form1.comments.value=="")
		themessage = themessage + "\n - Comments";



	 if (themessage == "Please make sure you complete the following fields: ")
		return true;
	else {
		alert(themessage);
		return false; 
	}
	
}


// clear form
function clearText(thefield){
if (thefield.defaultValue==thefield.value)
thefield.value = ""
}


// change/hide div
function changeDiv(the_div,the_change)
{
  var the_style = getStyleObject(the_div);
  if (the_style != false)
  {
    the_style.display = the_change;
  }
}

function getStyleObject(objectId) {
  if (document.getElementById && document.getElementById(objectId)) {
    return document.getElementById(objectId).style;
  } else if (document.all && document.all(objectId)) {
    return document.all(objectId).style;
  } else {
    return false;
  }
}

// verify the email search form
function verifysearch() {
    var themessage = "Please make sure you complete the following fields: ";
	 
	 if ((document.searchform.DEST.selectedIndex == 0 ) && (document.searchform.COUNTRY.selectedIndex == 0 ) &&
	 ( document.searchform.S[0].checked == false ))
		themessage = themessage + "\n - Please select your preferred continent or country";
	 if ((document.searchform.ACT.selectedIndex == 0 ) &&
	 ( document.searchform.S[0].checked == true ))
		themessage = themessage + "\n - Please select your preferred activity";
	if (( document.searchform.S[0].checked == false ) && ( document.searchform.S[1].checked == false ) && ( document.searchform.S[2].checked == false ))	 
	themessage = themessage + "\n - Please select a destination or activity";

	if (( document.searchform.S[2].checked == true ) && (document.searchform.DEST.selectedIndex == 0 ) && (document.searchform.COUNTRY.selectedIndex == 0 ))	 
	themessage = themessage + "\n - Please select a destination";

		if (( document.searchform.S[2].checked == true ) && (document.searchform.ACT.selectedIndex == 0 ))	 
	themessage = themessage + "\n - Please select an activity";


	 if (themessage == "Please make sure you complete the following fields: ")
		return true;
	else {
		alert(themessage);
		return false; 
	}
	
}


function verifysearchform() {
    var themessage = "Please make sure you complete the following fields: ";
	 
	 if ((document.searchform.DEST.selectedIndex == 0 ) && (document.searchform.COUNTRY.selectedIndex == 0 ) &&
	 (document.searchform.ACT.selectedIndex == 0 ) )
		themessage = themessage + "\n - Please select your preferred region, activity or country";
	 if (themessage == "Please make sure you complete the following fields: ")
		return true;
	else {
		alert(themessage);
		return false; 
	}
	
}

// country/destination dynamic select
function dynamicSelect(DEST,COUNTRY) {
	// Feature test to see if there is enough W3C DOM support
	if (document.getElementById && document.getElementsByTagName) {
		// Obtain references to both select boxes
		var sel1 = document.getElementById(DEST);
		var sel2 = document.getElementById(COUNTRY);
		// Clone the dynamic select box
		var clone = sel2.cloneNode(true);
		// Obtain references to all cloned options 
		var clonedOptions = clone.getElementsByTagName("option");
		// Onload init: call a generic function to display the related options in the dynamic select box
		refreshDynamicSelectOptions(sel1, sel2, clonedOptions);
		// Onchange of the main select box: call a generic function to display the related options in the dynamic select box
		sel1.onchange = function() {
			refreshDynamicSelectOptions(sel1, sel2, clonedOptions);
		};
	}
}


function refreshDynamicSelectOptions(sel1, sel2, clonedOptions) {
	// Delete all options of the dynamic select box
	while (sel2.options.length) {

		sel2.remove(0);
	}
	// Create regular expression objects for "select" and the value of the selected option of the main select box as class names
	var pattern1 = /( |^)(select)( |$)/;
	var pattern2 = new RegExp("( |^)(" + sel1.options[sel1.selectedIndex].value + ")( |$)");
	// Iterate through all cloned options
	for (var i = 0; i < clonedOptions.length; i++) {
		// If the classname of a cloned option either equals "select" or equals the value of the selected option of the main select box
		if (clonedOptions[i].className.match(pattern1) || clonedOptions[i].className.match(pattern2)) {
			// Clone the option from the hidden option pool and append it to the dynamic select box
			sel2.appendChild(clonedOptions[i].cloneNode(true));
		}
	}
}

// clear dynamic select
function clearselect()
{
var searchform = document.searchform.DEST;
document.searchform.DEST.selectedIndex = 0;

var searchform = document.searchform.COUNTRY;
document.searchform.COUNTRY.selectedIndex = 0;

var searchform = document.searchform.ACT;
document.searchform.ACT.selectedIndex = 0;


}

// verify the continent
function verifycontinent() {
    var themessage = "Please select a continent first";
	 
	 if (document.searchform.DEST.selectedIndex == 0 )
		themessage = themessage + "\n";

	 if (themessage == "Please select a continent first")
		return true;
	else {
		alert(themessage);
		return false; 
	}
	
}




