//Travel Search Functions
function hideSelectBox(){
	if (ie5){
		document.getElementById('travelersSelect').style.visibility = "hidden";
	}
}
function showSelectBox(){
	if (ie5){
		document.getElementById('travelersSelect').style.visibility = "visible";
	}
}

function goThere(which){
	document.HotelSearch.city.value = which.value;
	//document.HotelSearch.submit();
}
//Allow user to select the ages of the children
function selectChildAge(num){

	document.getElementById('hotdeals').style.display = "none";
	document.getElementById('childAge').style.display = "block";

	document.getElementById('child1').style.visibility = "hidden";
	document.getElementById('child2').style.visibility = "hidden";
	document.getElementById('child3').style.visibility = "hidden";

	if (num == ""){
		document.getElementById('hotdeals').style.display = "block";
		document.getElementById('childAge').style.display = "none";
		document.HotelSearch.childage1.value = "";
		document.HotelSearch.childage2.value = "";
		document.HotelSearch.childage3.value = "";
	}

	if (num == 1){
		document.getElementById('child1').style.visibility = "visible";
	}
	if (num == 2){
		document.getElementById('child1').style.visibility = "visible";
		document.getElementById('child2').style.visibility = "visible";
	}
	if (num == 3){
		document.getElementById('child1').style.visibility = "visible";
		document.getElementById('child2').style.visibility = "visible";
		document.getElementById('child3').style.visibility = "visible";
	}
}

//Errors
var ie5  = (document.all && document.getElementById);
var Gekco = (!document.all && document.getElementById);
//set opacity for ie and mozilla to 0
var opac = 0;
var mozopac = 0;

//Send focus after displaying an error
var sendfocusto;

//Error Messages
var error_messages = new Array();
error_messages["departcityerror"] = '<p class="error">Please enter an airport code or city, state.</p>';
error_messages["arrivecityerror"] = '<p class="error">Please enter an airport code or city, state.</p>';
error_messages["departdateerror"] = '<p class="error">Please select your departure date.</p>';
error_messages["returndateerror"] = '<p class="error">Please select your return date.</p>';
error_messages["cityerror"] = '<p class="error">Please enter destination airport code, city, or city, state.</p>';
error_messages["checkindateerror"] = '<p class="error">Please select your check in date.</p>';
error_messages["checkoutdateerror"] = '<p class="error">Please select your check out date.</p>';
error_messages["pickupcityerror"] = '<p class="error">Please enter a destination airport code, city, or city, state.</p>';
error_messages["zipcodeerror"] = '<p class="error">Please enter the zipcode from your Driver\'s License.</p>';
error_messages["pickupdateerror"] = '<p class="error">Please select your pick up date.</p>';
error_messages["dropoffdateerror"] = '<p class="error">Please select your drop off date.</p>';

function displayError(which, top, left, sendfocus){
	sendfocusto = sendfocus;
	removeError();
	document.getElementById('errorbubble').style.top = top+"px";
	document.getElementById('errorbubble').style.left = left+"px";
	document.getElementById('errormessage').innerHTML = error_messages[which];
	if(ie5){
		document.getElementById('errorbubble').filters.alpha.opacity = opac;
	}
	//if Gekco then change the opacity to 0
	if(Gekco){
		document.getElementById('errorbubble').style.MozOpacity = mozopac;
	}
	document.getElementById('errorbubble').style.display = "block";
	if (which == "returndateerror" && ie5 && document.getElementById('departTime')){
		document.getElementById('departTime').style.visibility = "hidden";
	}
	if (which == "cityerror" && ie5 && document.getElementById('hothoteldeals')){
		document.getElementById('hothoteldeals').style.visibility = "hidden";
	}
	if (which == "checkoutdateerror" && ie5 && document.getElementById('numadults')){
		document.getElementById('numadults').style.visibility = "hidden";
	}	
	if (which == "dropoffdateerror" && ie5 && document.getElementById('pickuptime')){
		document.getElementById('pickuptime').style.visibility = "hidden";
	}
	if (which == "zipcodeerror" && ie5 && document.getElementById('carclass')){
		document.getElementById('carclass').style.visibility = "hidden";
	}
	fade('errorbubble');
}

//Remove the error without any clipping or fading effects
function removeError(){
	document.getElementById('errorbubble').style.display = "none";
	//AIR
	if(document.getElementById('departTime'))
		document.getElementById('departTime').style.visibility = "visible";
	//HOTEL
	if(document.getElementById('hothoteldeals'))
		document.getElementById('hothoteldeals').style.visibility = "visible";
	if(document.getElementById('numadults'))	
		document.getElementById('numadults').style.visibility = "visible";
	//CAR
	if(document.getElementById('carclass'))
		document.getElementById('carclass').style.visibility = "visible";
	if(document.getElementById('pickuptime'))
		document.getElementById('pickuptime').style.visibility = "visible";
}

//Remove the error by clipping
function clipError(){
	if (document.getElementById('errorbubble').style.display == "block"){
		clip_hideError('errorbubble');
	}
}

//Show the error by fading in
function fade(which){
	//if IE5+ then change the opacity to 0
	if(ie5){
		document.getElementById(which).filters.alpha.opacity = opac;
	}
	//if Gekco then change the opacity to 0
	if(Gekco){
		//document.getElementById('image').style.MozOpacity = mozopac;
		document.getElementById(which).style.MozOpacity = mozopac;
	}
	//Show the error but it has 0 opacity at this point
	document.getElementById(which).style.display = "block";
	//fade in the image of the model (white)
	changeOpacity(which);
}
//Fade the error until it is completely visible
function changeOpacity(which){
	if (opac < 99){
		opac = opac + 9;
		mozopac = opac/100;
		if(ie5){
			document.getElementById(which).filters.alpha.opacity = opac;
		}
		if(Gekco){
			document.getElementById(which).style.MozOpacity = mozopac;
		}
		//call the changeOpacity function again after 20 ms
		setTimeout("changeOpacity('"+which+"')",20);
	}
	else{
		//reset the opacity so that we can use it again
		opac = 0;
		mozopac = 0;
	}
}

//set the top value of clipping to 0 so that nothing shows at the begining
var topVal=0;
var imageHeight=140;
var imageWidth=250;
//Clip the error bubble
function clip_hideError(which){
	//set the clipping of the image to 0 and then call the showImage function to unveil the image
	document.getElementById(which).style.clip = "rect(0px "+imageWidth+"px "+imageHeight+"px 0px)";

	//unveil the image of the model (color)		
	clipDiv(which);
}

//Clip the error bubble
function clipDiv(which)
{
	//keep clipping as long as the image has some height
	if(topVal < imageHeight){
		//remove an additional 10pixels
		topVal+=10;
		//display the model (color)
		document.getElementById(which).style.clip="rect("+topVal+"px "+imageWidth+"px "+imageHeight+"px 0px)";
		//call the hideImage function again after 50 ms
		setTimeout("clipDiv('"+which+"')",15);
	}
	//reset the top values so that we can use it again
	else {
		topVal = 0;
		document.getElementById(which).style.display = "none";
		document.getElementById(which).style.clip = "rect(0px "+imageWidth+"px "+imageHeight+"px 0px)";
			//AIR
	if(document.getElementById('departTime'))
		document.getElementById('departTime').style.visibility = "visible";
	//HOTEL
	if(document.getElementById('hothoteldeals'))
		document.getElementById('hothoteldeals').style.visibility = "visible";
	if(document.getElementById('numadults'))	
		document.getElementById('numadults').style.visibility = "visible";
	//CAR
	if(document.getElementById('carclass'))
		document.getElementById('carclass').style.visibility = "visible";
	if(document.getElementById('pickuptime'))
		document.getElementById('pickuptime').style.visibility = "visible";

		sendfocusto.focus();
	}		
}

//Functions to Change the Quick Fare Finder
function changeSearch(which, div_lf, div_rt, focushere){
	if (loadcomplete){
		removeError();
		changeTab(which, div_lf, div_rt);
		changeForm(which);
		changeBanner(which);
		document.getElementById(focushere).focus();
	}
}

//Change which search form is being displayed
function changeForm(which){
	//Hide all forms
	document.getElementById('flightsearch').style.display = "none";
	document.getElementById('hotelsearch').style.display = "none";
	document.getElementById('carsearch').style.display = "none";
	document.getElementById('vacationsearch').style.display = "none";
	document.getElementById('cruisesearch').style.display = "none";
	//Display the selected form
	searchform = which+"search";
	document.getElementById(searchform).style.display = "block";
}

//Change the tabs to reflect the current search
function changeTab(which, div_lf, div_rt){
	//Hide all ON tabs
	document.getElementById('flight').src = "/bookingbox/images/blank.gif";
	document.getElementById('hotel').src = "/bookingbox/images/blank.gif";
	document.getElementById('car').src = "/bookingbox/images/blank.gif";
	document.getElementById('vacation').src = "/bookingbox/images/blank.gif";
	document.getElementById('cruise').src = "/bookingbox/images/blank.gif";
	//Turn the selected tab ON
	tab = "tab_"+which+"s";
	document.getElementById(which).src = "/bookingbox/images/"+tab+"_on.gif";
	document.getElementById(which).blur();
}

//Change top banner
var flightbanner = '<img src="resources/travelsearch/images/banners/flight.jpg" width="432" height="129">';
var hotelbanner = '<img src="resources/travelsearch/images/banners/hotel.jpg" width="432" height="129">';
var carbanner = '<img src="resources/travelsearch/images/banners/car.jpg" width="432" height="129">';
var vacationbanner = '<img src="resources/travelsearch/images/banners/vacation.jpg" width="432" height="129">';
var cruisebanner = '<img src="resources/travelsearch/images/banners/cruise.jpg" width="432" height="129">';
function changeBanner(which){
	//Display the select banner
	//document.getElementById("topbanner").innerHTML = eval(which+"banner");	
}