// JavaScript Document

//window.onload=highlightSelector;

function emailEval(thisEmail){
	
	var badChars = " /,:;";
	
	for(var k = 0;k < badChars.length; k++){
		if(thisEmail.indexOf(badChars.charAt(k)) > -1){
            return true;
		}
	}
	
	var atPos = thisEmail.indexOf("@",1);
	if(atPos == -1){
		return true;
	}
	if(thisEmail.indexOf("@",atPos+1) > -1){
		return true;
	}
	
	var dotPos = thisEmail.indexOf(".",atPos);
	if(dotPos == -1){
		return true;
	}
	if(dotPos+3 > thisEmail.length){
		return true;
	}
	
	return false;
	}

function viewError(fields,banner_id){
	var parentDiv = document.getElementById(banner_id);
	
	   window.scroll(1000,0);
	   parentDiv.innerHTML = "<h3>FORM ERROR......</h3><p>Please complete the form by filling up the required fields: <font color=Red><b>"+fields+"</b></font>&nbsp;</p>";}

function addCommas(nStr){
		nStr += '';
		x = nStr.split('.');
		x1 = x[0];
		x2 = x.length > 1 ? '.' + x[1] : '';
		var rgx = /(\d+)(\d{3})/;
		while (rgx.test(x1)) {
			x1 = x1.replace(rgx, "$1" + "'" + "$2");
		}
		return x1 + x2;
	}

function highlightSelector(clickedHighlight,displayForm){
		var formTabs = document.getElementById('formTab').getElementsByTagName("LI"), formTabsCounter;
		var tabForm = document.getElementById('multiFormContainer').getElementsByTagName("FORM"), tabFormCounter;
		
		
		for(formTabsCounter = 0; formTabsCounter < formTabs.length; formTabsCounter++){
			
				formTabs[formTabsCounter].childNodes[0].className = '';
			
		} 
		
		for(tabFormCounter = 0; tabFormCounter < tabForm.length; tabFormCounter++){
				tabForm[tabFormCounter].style.display='none';
		}
		
		document.getElementById(displayForm).style.display = 'block';
		document.getElementById(clickedHighlight).className = 'active'; 
		
		
	}
	
function emailEval(thisEmail){
	
	var badChars = " /,:;";
	
	for(var k = 0;k < badChars.length; k++){
		if(thisEmail.indexOf(badChars.charAt(k)) > -1){
            return true;
		}
	}
	
	var atPos = thisEmail.indexOf("@",1);
	if(atPos == -1){
		return true;
	}
	if(thisEmail.indexOf("@",atPos+1) > -1){
		return true;
	}
	
	var dotPos = thisEmail.indexOf(".",atPos);
	if(dotPos == -1){
		return true;
	}
	if(dotPos+3 > thisEmail.length){
		return true;
	}
	
	return false;
	}
	
function contactUsFilters(){
	var airForms = document.forms['contactUsAir'].elements;
	var airFormsCounter, airFormsError = new Array();
	
	for(airFormsCounter = 0; airFormsCounter < airForms.length; airFormsCounter++){
		if(airForms[airFormsCounter].value == ""){
			switch(airFormsCounter){
				case 0: airFormsError.push("First Name"); break;
				case 1: airFormsError.push("Last Name"); break;
				case 2: airFormsError.push("Telephone Number"); break;
				case 3: airFormsError.push("Email Address"); break;
			}
		}
	}
	
	if(airForms[3].value != ""){
		if(emailEval(airForms[3].value)){
			airFormsError.push("Email Address");
		}
	}
	
	if(airFormsError.length > 0){
		window.scroll(1000,0);
		document.getElementById('head_banner').innerHTML="<h3>Form Error....</h3><p>Please make sure that <font color='red'>"+ airFormsError.join(", ") +"</font>&nbsp;fields have been filled out correctly.<br /><br /></p>";
		return false;
	}else{
		return true;
	}
	}

function loadLocations(currentId,targetId){
	var oElement = document.getElementById(currentId);
	var Xposition, Yposition,anchorTagsCounter; 
	var airLocations = document.getElementById('locations').style;
	var locationCloser = document.getElementById('locationCloser');
	var anchorTags = document.getElementById('locations').getElementsByTagName('a');

	
	airLocations.display='block';
	locationCloser.style.display='block';
	
	if(typeof(oElement.offsetParent) != 'undefined'){
		for(var posX = 0, posY = 0; oElement; oElement = oElement.offsetParent){
			posX += oElement.offsetLeft
			posY += oElement.offsetTop;
		}
		
		Xposition = posX;
		Yposition = posY;
		
	}else{
		
		Xposition = oElement.x;
		Yposition = oElement.y;
		
	}
	
	Xposition += document.getElementById(currentId).offsetWidth;
	
	
	airLocations.left = Xposition+5+"px";
	airLocations.top = Yposition+"px";
	
	Yposition += document.getElementById('locations').offsetHeight;
	
	locationCloser.style.left = Xposition+5+"px";
	locationCloser.style.top = Yposition+"px";
	locationCloser.style.width = document.getElementById('locations').offsetWidth+"px";
	
	for(anchorTagsCounter = 0; anchorTagsCounter < anchorTags.length; anchorTagsCounter++){
		
		   
			anchorTags[anchorTagsCounter].onclick=function(){
                
            	document.getElementById(targetId).value=this.title;
                unloadLocations();
				return false;
            
		}
		
	}
	
	
	}

function unloadLocations(){
	document.getElementById('locations').style.display='none'; 
	document.getElementById('locationCloser').style.display='none';
	return false;}

function carFilters(){
	
	var carForm = document.getElementById('carForm').elements
	var carFormCounter;
	var carFormErrors = new Array();
	
	for(carFormCounter = 0; carFormCounter < carForm.length; carFormCounter++){
		if(carForm[carFormCounter].tagName=='SELECT' && carForm[carFormCounter].selectedIndex == 0){
			switch(carFormCounter){
					case 0:carFormErrors.push("Pick Up Location"); break;
					case 2:carFormErrors.push("Drop Off Location"); break;
					case 4:carFormErrors.push("Car Type"); break;
			}
		}
		
		if(carForm[carFormCounter].tagName=='INPUT' && carForm[carFormCounter].type=='text' && carForm[carFormCounter].value==""){
			switch(carFormCounter){
				case 1:carFormErrors.push("Pick Up Date"); break;
				case 3:carFormErrors.push("Drop Off Date"); break;
			}
		}
	}
	
	if(carFormErrors.length > 0){
		document.getElementById('bodyContainer').style.display='block';
		document.getElementById('bodyContainer').innerHTML="<h5>Please make sure that <font color='red'>"+ carFormErrors.join(" ,") +"</font> fields have been filled out correctly</h5> ";
		return false;
	}
		return true;
	
	}

function sectionShow(appear,hide){
	document.getElementById(appear).style.display='block';
	document.getElementById(hide).style.display='none';
	return false;}

function propetyFilter(){
		var propertyForm = document.getElementById('propertyForm').elements;
		var propertyFormCounter;
		var propertyFormError = new Array();
		
		for(propertyFormCounter = 0; propertyFormCounter < propertyForm.length; propertyFormCounter++){
			if(propertyForm[propertyFormCounter].tagName == "INPUT" && propertyForm[propertyFormCounter].type=="text" && propertyForm[propertyFormCounter].value==""){
				switch(propertyFormCounter){
					case 0:propertyFormError.push("Arrival Date"); break;
					case 1:propertyFormError.push("Departure Date"); break;
					case 2:propertyFormError.push("Approximate Budget"); break;
				}
			}
			
			if(propertyForm[propertyFormCounter].tagName == "SELECT" && propertyForm[propertyFormCounter].selectedIndex == 0){
				propertyFormError.push("Location");
			}
		}
		
		
		if(propertyFormError.length > 0){
			document.getElementById('bodyContainer').style.display='block';
			document.getElementById('bodyContainer').innerHTML="<h5>Please make sure that <font color='red'>"+ propertyFormError.join(" ,") +"</font> fields have been filled out correctly</h5> ";
			return false;
		}
		
		return true;
		
	}
	
function propertyEnquiryFilter(){
		var propertyEnquiryForm = document.getElementById('propertyEnquiry').elements;
		var propertyFormFrame = window.form_behind.document.forms[0].elements;
		var propertyEnquiryFormCounter, propertyFormFrameCounter,lastElement;
		var propertyEnquiryFormError = new Array();
		
		for(propertyEnquiryFormCounter = 0; propertyEnquiryFormCounter < propertyEnquiryForm.length; propertyEnquiryFormCounter++){
			if(propertyEnquiryForm[propertyEnquiryFormCounter].tagName == 'INPUT' && propertyEnquiryForm[propertyEnquiryFormCounter].type == 'text' && propertyEnquiryForm[propertyEnquiryFormCounter].value == ""){
				switch(propertyEnquiryFormCounter){
					case 0:propertyEnquiryFormError.push("First Name"); break;
					case 1:propertyEnquiryFormError.push("Last Name"); break;
					case 3:propertyEnquiryFormError.push("Email Address"); break;
					case 4:propertyEnquiryFormError.push("Street"); break;
					case 5:propertyEnquiryFormError.push("City"); break;
				}
			}
			
			if(propertyEnquiryForm[propertyEnquiryFormCounter].tagName == 'SELECT' && propertyEnquiryForm[propertyEnquiryFormCounter].selectedIndex == 0){
				propertyEnquiryFormError.push("Country");
			}
		}
		
		if(propertyEnquiryFormError.length > 0){
			viewError(propertyEnquiryFormError.join(", "),"banner");
			return false;
		}else{
			if(propertyEnquiryForm[3].value != "" && emailEval(propertyEnquiryForm[3].value)){
				document.getElementById('banner').innerHTML="<h3>FORM ERROR......</h3><p>You have inputed an invalid email. Please check the inputed email address and try again</p>";
				return false;
			}else{
				
				for(propertyFormFrameCounter = 0; propertyFormFrameCounter < propertyFormFrame.length - 1; propertyFormFrameCounter++){
					if(propertyFormFrameCounter == 7){
						propertyFormFrame[propertyFormFrameCounter].value = propertyEnquiryForm[propertyFormFrameCounter].options[propertyEnquiryForm[propertyFormFrameCounter].selectedIndex].value;
					}else{
						propertyFormFrame[propertyFormFrameCounter].value = propertyEnquiryForm[propertyFormFrameCounter].value;
					}
				}
				
				lastElement = propertyFormFrame.length - 1;
				
				propertyFormFrame[lastElement].value='insert query';
				window.form_behind.document.forms[0].submit();
				return false;
				
			}
		}
		
	}

function generalFilters(){
		var planeForm = document.forms[0].elements;
		var planeFormCounter, planeFormError = new Array();
		
		for(planeFormCounter = 0; planeFormCounter < planeForm.length; planeFormCounter++){
			if(planeForm[planeFormCounter].tagName == 'INPUT' && planeForm[planeFormCounter].type == 'text' && planeForm[planeFormCounter].value==""){
				switch(planeFormCounter){
					case 0: planeFormError.push("First Name"); break;
					case 1: planeFormError.push("Last Name"); break;
					case 2: planeFormError.push("Telephone Number"); break;
					case 3: planeFormError.push("Email Address"); break;
					case 4: planeFormError.push("Street"); break;
					case 5: planeFormError.push("City"); break;
					case 6: planeFormError.push("ZIP"); break;
				}
			}
			
			if(planeForm[planeFormCounter].tagName == 'SELECT' && planeForm[planeFormCounter].selectedIndex == 0 ){
				planeFormError.push("Country");
			}
		}
		
		if(planeFormError.length > 0){
			
			viewError(planeFormError.join(", "),"banner");
			return false;
			
		}else{
			
			if(planeForm[3].value != ""){
				if(emailEval(planeForm[3].value)){
					document.getElementById('banner').innerHTML="<h3>FORM ERROR......</h3><p>You have inputed an invalid email. Please check the inputed email address and try again</p>";
					return false;
				}
			}
			
		}
		
		return true;
	}

function changeCurrency2(radioValue){
		var priceHeader = document.getElementById('priceTable').rows;
		var pricesData = document.getElementsByName('pricesData'), pricesDataCounter;
		var genericCurrency = radioValue;
		var priceHeaderCounter, storePriceCounter = 0, actualPrice;
		var storePrice = new Array();
		
		for(pricesDataCounter = 0; pricesDataCounter < pricesData.length; pricesDataCounter++){
			storePrice.push(parseFloat(pricesData[pricesDataCounter].value));
		}
		
		
		if(genericCurrency == 'CHF'){
			for(priceHeaderCounter = 1; priceHeaderCounter < priceHeader.length; priceHeaderCounter++){
				if(priceHeader[priceHeaderCounter].cells.length > 1){
					actualPrice = storePrice[storePriceCounter];
					priceHeader[priceHeaderCounter].cells[1].innerHTML= addCommas(actualPrice.toFixed(2));
					storePriceCounter++;
				}
			}
		}else{
			for(priceHeaderCounter = 1; priceHeaderCounter < priceHeader.length; priceHeaderCounter++){
				if(priceHeader[priceHeaderCounter].cells.length > 1){
					actualPrice = storePrice[storePriceCounter] / 1.51611;
					priceHeader[priceHeaderCounter].cells[1].innerHTML= addCommas(actualPrice.toFixed(2));
					storePriceCounter++;
				}
			}
		}
	
	}

function planeEnquiryFilters(){
		var planeEnquiryForm = document.getElementById('planeForm').elements;
		var planeEnquiryCounter;
		var planeEnquiryError = new Array();
		
		
		for(planeEnquiryCounter = 0; planeEnquiryCounter < planeEnquiryForm.length; planeEnquiryCounter++){
			if(planeEnquiryForm[planeEnquiryCounter].type=='text' && planeEnquiryForm[planeEnquiryCounter].tagName == 'INPUT' && planeEnquiryForm[planeEnquiryCounter].value==""){
				switch(planeEnquiryCounter){
					case 0: planeEnquiryError.push("First Name"); break;
					case 1: planeEnquiryError.push("Last Name"); break;
					case 3: planeEnquiryError.push("Email Address"); break;
					case 4: planeEnquiryError.push("Street"); break;
					case 5: planeEnquiryError.push("City"); break;
					case 7: planeEnquiryError.push("Country"); break;
					case 11: planeEnquiryError.push("Number of Passengers"); break;
					case 12: planeEnquiryError.push("Departure City / Town"); break;
					case 13: planeEnquiryError.push("Arrival City / Town"); break;
					case 14: planeEnquiryError.push("From"); break;
					case 15: planeEnquiryError.push("To"); break;
					case 16: planeEnquiryError.push("Departure Date"); break;
				}
			}
			
			if(planeEnquiryForm[planeEnquiryCounter].tagName == 'SELECT' && planeEnquiryForm[planeEnquiryCounter].selectedIndex==0){
				planeEnquiryError.push("Country");
			}
		}
		
		if(planeEnquiryForm[9].checked == true && planeEnquiryForm[17].value==""){
				planeEnquiryError.push("Return Date");
		}
		
		
		
		if(planeEnquiryError.length > 0){
			viewError(planeEnquiryError.join(", "),"banner");
			return false;
		}else{
			if(planeEnquiryForm[3].value != "" && emailEval(planeEnquiryForm[3].value)){
					window.scroll(1000,0);
					document.getElementById('banner').innerHTML="<h3>FORM ERROR......</h3><p>Your inputed email is invalid. <br/> Please check your inputed email and try again. </p>"
					return false;
			}
		}
		
		
	}

function chopperEnquiryFilters(){
		var chopperEnquiryForm = document.getElementById('helicopterForm').elements;
		var chopperEnquiryCounter;
		var chopperEnquiryError = new Array();
		
		
		for(chopperEnquiryCounter = 0; chopperEnquiryCounter < chopperEnquiryForm.length; chopperEnquiryCounter++){
			if(chopperEnquiryForm[chopperEnquiryCounter].type=='text' && chopperEnquiryForm[chopperEnquiryCounter].tagName == 'INPUT' && chopperEnquiryForm[chopperEnquiryCounter].value == ""){
				switch(chopperEnquiryCounter){
					case 0: chopperEnquiryError.push("First Name"); break
					case 1: chopperEnquiryError.push("Last Name"); break;
					case 3: chopperEnquiryError.push("Email"); break;
					case 4: chopperEnquiryError.push("Street"); break;
					case 5: chopperEnquiryError.push("City"); break;
					case 11: chopperEnquiryError.push("Number of Passengers");break;
					case 15: chopperEnquiryError.push("Departure Date");break;
					case 17: chopperEnquiryError.push("Departure Town / City");break;
					case 18: chopperEnquiryError.push("Arrival Town / City");break;
				}
			}
			
			if(chopperEnquiryForm[chopperEnquiryCounter].tagName == 'SELECT' && chopperEnquiryForm[chopperEnquiryCounter].selectedIndex == 0){
				chopperEnquiryError.push("Country")
			}
		}
		
		if(chopperEnquiryForm[9].checked == true && chopperEnquiryForm[16].value == ""){
			chopperEnquiryError.push("Return Date");
		}
		
		if(chopperEnquiryError.length > 0){
			viewError(chopperEnquiryError.join(", "),"banner");
			return false;
		}else{
			if(chopperEnquiryForm[3].value != "" && emailEval(chopperEnquiryForm[3].value)){
					window.scroll(1000,0);
					document.getElementById('banner').innerHTML="<h3>FORM ERROR......</h3><p>Your inputed email is invalid. <br/> Please check your inputed email and try again. </p>"
					return false;
			}
		}
		
		return true; 
	}

function contactUsFilters(){
	var contactUsForms = document.getElementById('contactUs').elements;
	var contactUsCounter;
	var contactUsErrors = new Array();
	var contactUsInterest = document.getElementsByName('contactInterest[]');
	var contactUsInterestCounter, contactUsCheck=0;
	
	for(contactUsCounter = 0; contactUsCounter < contactUsForms.length; contactUsCounter++){
		if(contactUsForms[contactUsCounter].type=='text' && contactUsForms[contactUsCounter].tagName == 'INPUT' && contactUsForms[contactUsCounter].value==""){
			switch(contactUsCounter){
				case 0: contactUsErrors.push("First Name"); break;
				case 1: contactUsErrors.push("Last Name"); break;
				case 3: contactUsErrors.push("Email Address"); break;
				case 4: contactUsErrors.push("Street"); break;
				case 5: contactUsErrors.push("City"); break;
			}
		}
		
		if(contactUsForms[contactUsCounter].tagName == 'select' && contactUsForms[contactUsCounter].selectedIndex == 0){
			contactUsErrors.push("Country");
		}
	}
	
	for(contactUsInterestCounter = 0 ; contactUsInterestCounter < contactUsInterest.length; contactUsInterestCounter++){
		if(contactUsInterest[contactUsInterestCounter].checked == true){
			contactUsCheck++;
		}
	}
	
	if(contactUsCheck == 0){
		contactUsErrors.push("Interest");
	}
	
	if(contactUsErrors.length > 0){
		viewError(contactUsErrors.join(", "),"banner");
		return false;
	}else{
		if(contactUsForms[3].value != "" && emailEval(contactUsForms[3].value)){
			window.scroll(1000,0);
			document.getElementById('banner').innerHTML="<h3>FORM ERROR......</h3><p>Your inputed email is invalid. <br/> Please check your inputed email and try again. </p>"
			return false;
		}
	}
	}