//this page is used to set up general functions used through out the search boxes and WCT pages. 

// Popup windows
var o_popurl = "#";
var o_popwindow = 0;
var b_popwindow = 1;
function checkpopUp(){
 b_popwindow = (o_popwindow) ? o_popwindow.closed : 1;
  if(b_popwindow) document.location = o_popurl;
  else o_popwindow.focus();
}

function popUp(s_url,s_name,s_attrib){
 o_popurl = s_url;
 o_popwindow = window.open(s_url,s_name,s_attrib);
 setTimeout("checkpopUp()",500);
}


//used to switch the class of elements on the fly.
function change(id, newClass) 
{	
	try
	{
		var obj = getElObj(id,'',searchType+"_frame");		
		if(typeof(obj) != "object")
			id = YAHOO.util.Dom.get(id);
		else
			id= obj;					
		var oldClassName = id.className;
		if(newClass.length == 0 )
		{
			YAHOO.util.Dom.removeClass(id,oldClassName);
		}
		else
		{
			YAHOO.util.Dom.replaceClass(id,oldClassName,newClass);
		}
	}
	catch(error){}
}

function hide(idLayer) { 
//	alert(idLayer);
//	alert(document.getElementById(idLayer));
	try {
		if(typeof(idLayer) != "object")
		{
			try
			{
				document.getElementById(idLayer).style.display='none'; 
			}
			catch(error){}
		}
		else
		{	
			idLayer.style.display='none'; 
		}
	}
	catch(e){};
}

// used to hide and show elements. 
function show(idLayer) {
	try{
		if(typeof(idLayer) != "object")
			document.getElementById(idLayer).style.display='block';  
		else
			idLayer.style.display='block';  
	}
	catch(e){};
}

function showInline(idLayer) { 
	try{
		if(typeof(idLayer) != "object")
			document.getElementById(idLayer).style.display='inline'; 
		else
			idLayer.style.display='inline'; 
	} 
	catch(e){};
}

function getChildrenBox()
{
	var re = new RegExp('(?:^|\\s+)' +'children_box' + '(?:\\s+|$)');
	var method = function(el) {return re.test(el["id"])};
	var childAgeContainer = YAHOO.util.Dom.getElementsBy(method,'',searchType+"_frame");
	if (childAgeContainer.length > 0)
		return childAgeContainer[0];
	else
		return false;
}

function getElObj(id,tag,root)
{
	var element;
	var re = new RegExp('(?:^|\\s+)' +id+ '(?:\\s+|$)');
	var method = function(el) {return re.test(el["id"])};
	var elementList = YAHOO.util.Dom.getElementsBy(method,tag,root);
	if (elementList.length > 0)
		element=elementList[0];
		
	return element;	
}
			   

function loadErrorTranslation(errmsgObj)
{
// checking to see if there are translated Error messages
if(typeof(errmsgObj) == "undefined"){
	// specifying defaults message if there is no translation
	var validateError = new Object();
	validateError = {cityError:'enter a city' , dateError:'enter dates'};
}
}

//checks all of the search boxes for errors and displayes warnings
function checkForm(FormName, type) {

var childrenBox = getChildrenBox();
var form = document.getElementById(FormName);


var searchForm = form;
if( type=='hotel' || type=='saverate' || type=='attractions'){ 
	var cityVal =  form.city.value;
	if(type!='attractions')
	{
		var child 	=  form.num_children.selectedIndex;
	}
}
if(type=='airHotel' || type=='air'){ 
	var leavingFromVal;
	var goingToVal;

	if(type=='air')
	{
		leavingFromVal =  form.leavingFrom[0].value
		goingToVal =  form.goingTo[0].value
	}
	else
	{
		leavingFromVal =  form.leavingFrom.value
		goingToVal =  form.goingTo.value		
	}
	var child 	=  form.num_children.selectedIndex;
}

if(type=='car' || type=='car_fd'){
	var pucityVal =  form.pucity.value
	var docityVal =  form.docity.value
}

if(type=='lmd' || type=='lastminute'){
	var toDestination = form.in_destform_state;
	var destinationCity = form.in_location_key;
}
else if (type !='air')
{	
	var chk_inVal =  form.chk_in.value;
	var chk_outVal =  form.chk_out.value;	
}
var blnPass = true;

if(type=='hotel' || type=='saverate' || type=='attractions')
	{ 
		if (cityVal == "" || cityVal == validateError.cityError) 
			{
			change("city","formWarning");
			form.city.value=validateError.cityError;
			blnPass = false;
			}
		if(typeof(child) != "undefined" && child!=0 && type !='attractions')
		{	
			for (var i=1; i<=child; i++)
			{
				var selectBox = eval("form.minorsAge" +i);
				
				if(selectBox.selectedIndex == 0)
				{
				change('warn',"warning");
				childrenBox.style.display = "block";
				blnPass = false;
				}
			}
		}
	}

if(type=='airHotel' || type=='air')
	{ 
		if(type == "air")
		{
			var airSearchType;
			if(form.flightType.length)
			{
				for (var i=0; i < form.flightType.length; i++)
				{
					if(form.flightType[i].checked == true)
					{
						airSearchType = form.flightType[i].value;
					}
				}
			}
			
			if (airSearchType == "roundtrip" || airSearchType == "oneway")		
			{
				if (leavingFromVal == "" || leavingFromVal == validateError.cityError) 
					{
					change(form.leavingFrom[0],"formWarning");
					form.leavingFrom[0].value=validateError.cityError;
					blnPass = false;
					}
				if (goingToVal == "" || goingToVal == validateError.cityError) 
					{
					change(form.goingTo[0],"formWarning");
					form.goingTo[0].value=validateError.cityError;
					blnPass = false;
					}
			}
			else
			{	// multiple destinations
				for(i=1; i<=4; i++)
				{
					var flightNum = "flight" + i;
					var currFlight = document.getElementById(flightNum);
					var chk_in1 = eval("form.leavingDate" +i);
					if (currFlight.style.display == 'block')
					{
						var leavingFromVal=eval("form.leavingFrom" +i).value;
						var goingToVal = eval("form.goingTo" +i).value;
						
						if (leavingFromVal == "" || leavingFromVal == validateError.cityError) 
							{
							change(form.leavingFrom[i],"formWarning");
							form.leavingFrom[i].value=validateError.cityError;
							blnPass = false;
							}
						if (goingToVal == "" || goingToVal == validateError.cityError) 
							{
							change(form.goingTo[i],"formWarning");
							form.goingTo[i].value=validateError.cityError;
							blnPass = false;
							}
											
						if (chk_in1.value == "" || chk_in1.value == validateError.dateError || chk_in1.value == "mm/dd/yyyy" || chk_in1.value == "dd/mm/yyyy")
						{
							change(eval("form.leavingDate" +i),"formWarning");
							eval("form.leavingDate" +i).value = validateError.dateError;
							blnPass = false;
						}
	
					}
					else
					{
						chk_in1.value = "";
					}
				}				
			}


			var chk_inVal =  form.chk_in[0].value;
			var chk_outVal =  form.chk_out.value;
			
			if (airSearchType == "oneway")
			{
				if (chk_inVal == "" || chk_inVal == validateError.dateError || chk_inVal == "mm/dd/yyyy")			
				{
					change(form.chk_in[0],"formWarning");
					form.chk_in[0].value = 	validateError.dateError;
					blnPass = false;
				}
			}
			else if(airSearchType == "roundtrip")
			{
				if (chk_inVal == "" || chk_inVal == validateError.dateError || chk_inVal == "mm/dd/yyyy" || chk_outVal == "" || chk_outVal == validateError.dateError || chk_outVal == "mm/dd/yyyy")
				{
					change(form.chk_in[0],"formWarning");
					change(form.chk_out,"formWarning");
					form.chk_in[0].value=validateError.dateError;
					form.chk_out.value=validateError.dateError;
					blnPass = false;
				}
				
			}

		}
		else  // CT
		{
			if (leavingFromVal == "" || leavingFromVal == validateError.cityError) 
				{
				change(form.leavingFrom,"formWarning");
				form.leavingFrom.value=validateError.cityError;
				blnPass = false;
				}
			if (goingToVal == "" || goingToVal == validateError.cityError) 
				{
				change(form.goingTo,"formWarning");
				form.goingTo.value=validateError.cityError;
				blnPass = false;
				}
			if (leavingFromVal == "" || leavingFromVal == validateError.cityError) 
				{
				change(form.leavingFrom,"formWarning");
				form.leavingFrom.value=validateError.cityError;
				blnPass = false;
				}
			if (goingToVal == "" || goingToVal == validateError.cityError) 
				{
				change(form.goingTo,"formWarning");
				form.goingTo.value=validateError.cityError;
				blnPass = false;
				}
		}
			
		if(typeof(child) != "undefined" && child!=0)
		{
			if(type=='air')
			{
				for (var i=0; i<child; i++)
				{				
					var selectBox = eval("form.minorsAge" +i);
					if(selectBox.selectedIndex == 0)
					{
						change('warn',"warning");				
						childrenBox.style.display = "block";
						blnPass = false;
					}
				}
			}
			else
			{
				for (var i=1; i<=child; i++)
				{				
					var selectBox = eval("form.minorsAge" +i);
					if(selectBox.selectedIndex == 0)
					{
						change('warn',"warning");				
						childrenBox.style.display = "block";
						blnPass = false;
					}
				}				
			}
		}		
	}
	
if(type=='lmd' || type=='lastminute')
{	
	if (toDestination.selectedIndex == 0)
	{
		change('warn','warning');
		blnPass = false;		
	}
	
	if (destinationCity.selectedIndex == 0)
	{
		change('warn2','warning');
		blnPass = false;		
	}

}
else{
	if(type!="air")
	{
		if (chk_inVal == "" || chk_inVal == validateError.dateError || chk_inVal == "mm/dd/yyyy" || chk_outVal == "" || chk_outVal == validateError.dateError || chk_outVal == "mm/dd/yyyy")
		{
			change(form.chk_in,"formWarning");
			change(form.chk_out,"formWarning");
			form.chk_in.value=validateError.dateError;
			form.chk_out.value=validateError.dateError;
			blnPass = false;
		}
	}
}
		
if(type=='car' || type=='car_fd')
{ 
	// check to see if "same as pickup" checkbox is checked.  Populate dropoff city if check box is checked.
	if (pucityVal == "" || pucityVal == validateError.cityError) 
	{
	change("pucity","formWarning");
	form.pucity.value=validateError.cityError;
	blnPass = false;
	}

	if (searchForm.FillCity.checked)
	{
		if (searchForm.pucity.value != "" && searchForm.pucity.value != validateError.cityError) 
		{	
			searchForm.docity.value = searchForm.pucity.value;
		}
		else
		{
			searchForm.docity.value = "";
		}
	}
	else{
		if (docityVal == "" || docityVal == validateError.cityError) 
		{
		change("docity","formWarning");
		form.docity.value=validateError.cityError;
		blnPass = false;
		}
	}
}

return blnPass;

}

//Children selector.
function displayages(childobj)
{	
var	minorsAge = YAHOO.util.Dom.getElementsByClassName("minorsAge","select",searchType+"_frame");

var childAgeContainer = getChildrenBox();

if (childobj.options[0].selected){hide(childAgeContainer); hide(minorsAge[0]); hide(minorsAge[1]); hide(minorsAge[2]); hide(minorsAge[3]);}
if (childobj.options[1].selected){show(childAgeContainer); showInline(minorsAge[0]); hide(minorsAge[1]); hide(minorsAge[2]); hide(minorsAge[3]);}
if (childobj.options[2].selected){show(childAgeContainer); showInline(minorsAge[0]); showInline(minorsAge[1]); hide(minorsAge[2]); hide(minorsAge[3]);}
if (childobj.options[3].selected){show(childAgeContainer); showInline(minorsAge[0]); showInline(minorsAge[1]); showInline(minorsAge[2]); hide(minorsAge[3]);}
if (childobj.options[4].selected){ show(childAgeContainer); showInline(minorsAge[0]); showInline(minorsAge[1]); showInline(minorsAge[2]); showInline(minorsAge[3]);}
}

//cars "same as pick up city" function, fills in the drop off date when the radio button is clicked.
function fill_docity(){
//document.CarSearch.FillCity.checked= true;
//hide('FillCity');showInline('ClearCity');
if(document.getElementById("FillCity").checked)
{
	document.CarSearch.docity.disabled = true;
	document.CarSearch.docity.value = document.CarSearch.pucity.value;
}
else
{
	document.CarSearch.docity.disabled = false;
	document.CarSearch.docity.value="";
	document.CarSearch.docity.focus();
}

}
function clear_docity(){
document.CarSearch.docity.value = "";
showInline('FillCity');hide('ClearCity');

}



//attractions check boxes
// Go through a list of input fields and only work on checkboxes.
function uncheck(){

	var actFormInputList = document.getElementById('AttractionsSearch').getElementsByTagName("input");
	
	for (var i=0; i<actFormInputList.length; i++)
	{
		var currentInput = actFormInputList[i];
		if(currentInput.type == "checkbox")
		{
			if(currentInput.name != "ACTTYPE_all")
			{
				currentInput.checked=false;
			}
			else
			{
				currentInput.checked=true;
			}			
		}
	}
}


function uncheckAll(boxtype){
document.getElementById('AttractionsSearch').ACTTYPE_all.checked=false;
}



/**
 * COMMON DHTML FUNCTIONS
 * These are handy functions I use all the time.
 *
 * By Seth Banks (webmaster at subimage dot com)
 * http://www.subimage.com/
 *
 * Up to date code can be found at http://www.subimage.com/dhtml/
 *
 * This code is free for you to use anywhere, just keep this comment block.
 */

/**
 * X-browser event handler attachment and detachment
 * TH: Switched first true to false per http://www.onlinetools.org/articles/unobtrusivejavascript/chapter4.html
 *
 * @argument obj - the object to attach event to
 * @argument evType - name of the event - DONT ADD "on", pass only "mouseover", etc
 * @argument fn - function to call
 */
function addEvent(obj, evType, fn){
 if (obj.addEventListener){
    obj.addEventListener(evType, fn, false);
    return true;
 } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    return r;
 } else {
    return false;
 }
}
function removeEvent(obj, evType, fn, useCapture){
  if (obj.removeEventListener){
    obj.removeEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.detachEvent){
    var r = obj.detachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Handler could not be removed");
  }
}

/**
 * Code below taken from - http://www.evolt.org/article/document_body_doctype_switching_and_more/17/30655/
 *
 * Modified 4/22/04 to work with Opera/Moz (by webmaster at subimage dot com)
 *
 * Gets the full width/height because it's different for most browsers.
 */
function getViewportHeight() {
	if (window.innerHeight!=window.undefined) return window.innerHeight;
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientHeight;
	if (document.body) return document.body.clientHeight; 
	return window.undefined; 
}
function getViewportWidth() {
	if (window.innerWidth!=window.undefined) return window.innerWidth; 
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientWidth; 
	if (document.body) return document.body.clientWidth; 
	return window.undefined; 
}




/**
 * POPUP WINDOW CODE v1.3
 * Used for displaying DHTML only popups instead of using buggy modal windows.
 *
 * By Seth Banks (webmaster at subimage dot com)
 * http://www.subimage.com/
 *
 * Contributions by:
 * 	Eric Angel - tab index code
 * 	Scott - hiding/showing selects for IE users
 *	Todd Huss - inserting modal dynamically and anchor classes
 *
 * Up to date code can be found at http://www.subimage.com/dhtml/subModal
 * 
 *
 * This code is free for you to use anywhere, just keep this comment block.
 */

// Popup code
var gPopupMask = null;
var gPopupContainer = null;
var gPopFrame = null;
var gReturnFunc;
var gPopupIsShown = false;

var gHideSelects = false;


var gTabIndexes = new Array();
// Pre-defined list of tags we want to disable/enable tabbing into
var gTabbableTags = new Array("A","BUTTON","TEXTAREA","INPUT");	

// If using Mozilla or Firefox, use Tab-key trap.
if (!document.all) {
	document.onkeypress = keyDownHandler;
}



/**
 * Initializes popup code on load.	
 */
function initPopUp() {
	// Add the HTML to the body
	theBody = document.getElementsByTagName('form')['AirSearch'];
	popmask = document.createElement('div');
	popmask.id = 'popupMask';
	popcont = document.createElement('div');
	popcont.id = 'popupContainer';
	popcont.innerHTML = '' +
		'<div id="popupInner">' +
			'<div id="popupTitleBar">' +
				'<div id="popupTitle"></div>' +
				'<div id="popupControls" ></div>' +
			'</div>' +
			'<div id="popupFrame" name="popupFrame"></div>' +
//			'<iframe src="loading.html" style="width:100%;height:100%;background-color:transparent;" scrolling="auto" frameborder="0" allowtransparency="true" id="popupFrame" name="popupFrame" width="100%" height="100%"></iframe>' +
		'</div>';
	theBody.appendChild(popmask);
	theBody.appendChild(popcont);
	
	gPopupMask = document.getElementById("popupMask");
	gPopupContainer = document.getElementById("popupContainer");
	gPopFrame = document.getElementById("popupFrame");	
	gPopControl = document.getElementById("popupControls");
	
	// check to see if this is IE version 6 or lower. hide select boxes if so
	// maybe they'll fix this in version 7?
	var brsVersion = parseInt(window.navigator.appVersion.charAt(0), 10);
	if (brsVersion <= 6 && window.navigator.userAgent.indexOf("MSIE") > -1) {
		gHideSelects = true;
	}
	
	// Add onclick handlers to 'a' elements of class submodal or submodal-width-height-div
	var elms = document.getElementsByTagName('a');
	for (i = 0; i < elms.length; i++) {
		if (elms[i].className.indexOf("submodal") == 0) { 
			// var onclick = 'function (){showPopWin(\''+elms[i].href+'\','+width+', '+height+', null);return false;};';
			// elms[i].onclick = eval(onclick);
			elms[i].onclick = function(){
				// default width and height
				var width = 400;
				var height = 200;
				var popupDiv;
				// Parse out optional width and height from className
				params = this.className.split('-');
				if (params.length == 3) {
					width = parseInt(params[1]);
					height = parseInt(params[2]);
				}
				if (params.length == 4) {
					width = parseInt(params[1]);
					height = parseInt(params[2]);
					popupDiv = document.getElementById(params[3]);
				}
				
				showPopWin(popupDiv,width,height,null); return false;
			}
		}
	}
}

/*addEvent(window, "load", initPopUp);*/

 /**
	* @argument width - int in pixels
	* @argument height - int in pixels
	* @argument url - url to display
	* @argument returnFunc - function to call when returning true from the window.
	*/

function showPopWin(divContainer, width, height, returnFunc) {
	if (typeof (divContainer) != "object")
	{
		divContainer = document.getElementById(divContainer);
	}
	
	gPopupIsShown = true;
	disableTabIndexes();
	gPopupMask.style.display = "block";
	gPopupContainer.style.display = "block";	
	setPopTitle();
	// calculate where to place the window on screen

	var titleBarHeight = parseInt(document.getElementById("popupTitleBar").offsetHeight, 10);
	var popupControls =  15;
	setMaskSize();
	
	gPopupContainer.style.width = (width +5+popupControls) +"px"; 
	gPopupContainer.style.height = (titleBarHeight+height)+"px"; 

	centerPopWin((width +5+popupControls), height);
	// need to set the width of the iframe to the title bar width because of the dropshadow
	// some oddness was occuring and causing the frame to poke outside the border in IE6

	gPopFrame.style.width = parseInt(document.getElementById("popupTitleBar").offsetWidth, 10) + "px";
	gPopFrame.style.height = (height) + "px";
	
	gReturnFunc = returnFunc;
	// for IE
	
	if (gHideSelects == true) {
		hideSelectBoxes();
	}
		// set the url
	if(gPopFrame.innerHTML == "")
	{
		gPopFrame.innerHTML = divContainer.innerHTML;
	}
	gPopControl.innerHTML = document.getElementById("close-frame").innerHTML;

	
		//window.setTimeout("setPopTitle();", 600);
}

//
var gi = 0;
function centerPopWin(width, height) {
	if (gPopupIsShown == true) {
		if (width == null || isNaN(width)) {
			width = gPopupContainer.offsetWidth;
		}
		if (height == null) {
			height = gPopupContainer.offsetHeight;
		}
		
		//var theBody = document.documentElement;
		var theBody = document.getElementsByTagName("BODY")[0];
		theBody.style.overflow = "hidden";
		
		var scTop = parseInt(theBody.scrollTop,10);
		var scLeft = parseInt(theBody.scrollLeft,10);
		
		gPopupMask.style.top = scTop + "px";
		gPopupMask.style.left = scLeft + "px";
	
		setMaskSize();
		
		//window.status = gPopupMask.style.top + " " + gPopupMask.style.left + " " + gi++;
		
		var titleBarHeight = parseInt(document.getElementById("popupTitleBar").offsetHeight, 10);
		
		var fullHeight = getViewportHeight();
		var fullWidth = getViewportWidth();
		
		gPopupContainer.style.top = (scTop + ((fullHeight - (height+titleBarHeight)) / 2)) + "px";
		gPopupContainer.style.left =  (scLeft + ((fullWidth - width) / 2)) + "px";
		//alert(fullWidth + " " + width + " " + gPopupContainer.style.left);
	}
}
addEvent(window, "resize", centerPopWin);
//addEvent(window, "scroll", centerPopWin);
window.onscroll = centerPopWin;

/**
 *
 *
 */
function setMaskSize() {
	var theBody = document.getElementsByTagName("BODY")[0];
			
	var fullHeight = getViewportHeight();
	var fullWidth = getViewportWidth();
	
	// Determine what's bigger, scrollHeight or fullHeight / width
	if (fullHeight > theBody.scrollHeight) {
		popHeight = fullHeight;
	} else {
		popHeight = theBody.scrollHeight
	}
	
	gPopupMask.style.height = popHeight + "px";
	gPopupMask.style.width = theBody.scrollWidth + "px";
}

/**
 * @argument callReturnFunc - bool - determines if we call the return function specified
 * @argument returnVal - anything - return value 
 */
function hidePopWin(callReturnFunc) {
	gPopupIsShown = false;
	var theBody = document.getElementsByTagName("BODY")[0];
	theBody.style.overflow = "";
	restoreTabIndexes();
	if (gPopupMask == null) {
		return;
	}
	gPopupMask.style.display = "none";
	gPopupContainer.style.display = "none";
	if (callReturnFunc == true && gReturnFunc != null) {
//		gReturnFunc(window.frames["popupFrame"].returnVal);
		gReturnFunc();
	}

//	gPopFrame.innerHTML = "";  // comment out to retain prev content selection

	// display all select boxes
	if (gHideSelects == true) {
		displaySelectBoxes();
	}
}

/**
 * Sets the popup title based on the title of the html document it contains.
 * Uses a timeout to keep checking until the title is valid.
 */
function setPopTitle() {
	if (document.getElementById("title") == null) {
		return null;
	} else {
		document.getElementById("popupTitle").innerHTML = document.getElementById("title").innerHTML;
	}
}

// Tab key trap. iff popup is shown and key was [TAB], suppress it.
// @argument e - event - keyboard event that caused this function to be called.
function keyDownHandler(e) {
    if (gPopupIsShown && e.keyCode == 9)  return false;
}

// For IE.  Go through predefined tags and disable tabbing into them.
function disableTabIndexes() {
	if (document.all) {
		var i = 0;
		for (var j = 0; j < gTabbableTags.length; j++) {
			var tagElements = document.getElementsByTagName(gTabbableTags[j]);
			for (var k = 0 ; k < tagElements.length; k++) {
				gTabIndexes[i] = tagElements[k].tabIndex;
				tagElements[k].tabIndex="-1";
				i++;
			}
		}
	}
}

// For IE. Restore tab-indexes.
function restoreTabIndexes() {
	if (document.all) {
		var i = 0;
		for (var j = 0; j < gTabbableTags.length; j++) {
			var tagElements = document.getElementsByTagName(gTabbableTags[j]);
			for (var k = 0 ; k < tagElements.length; k++) {
				tagElements[k].tabIndex = gTabIndexes[i];
				tagElements[k].tabEnabled = true;
				i++;
			}
		}
	}
}


/**
* Hides all drop down form select boxes on the screen so they do not appear above the mask layer.
* IE has a problem with wanted select form tags to always be the topmost z-index or layer
*
* Thanks for the code Scott!
*/

			// Hide any selects which intersect
			var selects = document.getElementsByTagName("select");
			for (var i = 0; i < selects.length; i++)
			{
				if (r.intersect(YAHOO.util.Dom.getRegion(selects[i])))
				{
					selects[i].style.visibility = "hidden";
					this.hiddenSelects.push(selects[i]);
				}
			}
function hideSelectBoxes() {
	for(var i = 0; i < document.forms.length; i++) {
		for(var e = 0; e < document.forms[i].length; e++){
			if(document.forms[i].elements[e].tagName == "SELECT") {
				// don't hide select box that are in popup
				if(document.forms[i].elements[e].name != "airlineSearchPref" &&
				   document.forms[i].elements[e].name != "classOfService" &&
				   document.forms[i].elements[e].name != "fareType")
				{					
					document.forms[i].elements[e].style.visibility="hidden";
				}
			}
		}
	}
}

/**
* Makes all drop down form select boxes on the screen visible so they do not reappear after the dialog is closed.
* IE has a problem with wanted select form tags to always be the topmost z-index or layer
*/
function displaySelectBoxes() {
	for(var i = 0; i < document.forms.length; i++) {
		for(var e = 0; e < document.forms[i].length; e++){
			if(document.forms[i].elements[e].tagName == "SELECT") {
//				alert(document.forms[i].elements[e].name);
			document.forms[i].elements[e].style.visibility="visible";
			}
		}
	}
}

function clearSearchForm(type,form)
{
	if(type == "rt") // clear out round trip and one way 
	{
		form.nearbyAirports.checked = false;
		form.leavingFrom[0].value = "";
		change(form.leavingFrom[0],'');
		form.goingTo[0].value = '';
		change(form.goingTo[0],'');
		form.leavingDate.value='mm/dd/yyyy';		
		change(form.leavingDate,'');
		form.dateLeavingTime.options[form.dateLeavingTime.options.length-1].selected=true;
		form.departDateFlexibility.options[0].selected=true;
		
		// return		
		form.returningDate.value = 'mm/dd/yyyy';
		change(form.returningDate,'');
		
		form.dateReturningTime.options[form.dateReturningTime.options.length-1].selected=true;
		form.returnDateFlexibility.options[form.returnDateFlexibility.options.length-1].selected=true;		
		// clear calendar internal select dates
		for(var i=0; i <=airCalArray.length-1; i++)
		{	
			airCalArray[i].clear();
			change(airCalArray[i],'');
		}
	}
	if(type == "mc")	
	{ // clear out multi-destination
		form.leavingDate.value='mm/dd/yyyy';		
		form.returningDate.value = 'mm/dd/yyyy';
		for(i=1; i<=4; i++)
		{
			var flightNum = "flight" + i;
			var currFlight = document.getElementById(flightNum);
		    if (currFlight.style.display == 'block')
		    {
				var leavingFrom=eval("form.leavingFrom" +i);
				var goingTo = eval("form.goingTo" +i);
				leavingFrom.value = "";
				change(leavingFrom,'');
				goingTo.value = "";
				change(goingTo,'');
				var leavingDate = eval("form.leavingDate" +i);
				leavingDate.value = "mm/dd/yyyy";
				change(leavingDate,'');
				var leavingTime = eval("form.leavingTime" +i);
				leavingTime.options[leavingTime.options.length-1].selected = true;
				if(multiCalArray[i])
	 				multiCalArray[i].clear();
		    }
		}
	}
	
	if(type== "ow")
	{
		form.leavingFrom[0].value = "";
		change(form.leavingFrom[0],'');
		form.goingTo[0].value = '';
		change(form.goingTo[0],'');
		form.leavingDate.value='mm/dd/yyyy';		
		change(form.leavingDate,'');

		form.returningDate.value = 'mm/dd/yyyy';
		airDodCal.clear();
		change(form.returningDate,'');
		form.nearbyAirports.checked = false;
	}
}

function changeAirSearchType(searchType,form)
{
	var form = document.getElementById(form);
	if(searchType == "rt")  // round trip type
	{
		hide('multiCityForm');
		hide('multi_city_add');		
		show('round_way');
		show('search_options1')
		show("chk_out_lbl");
		show(form.returningDate);
		show(form.dateReturningTime);
		form.flightType[0].checked = true;
	}
	else if(searchType == "mc")  // multiple destinations
	{
		hide('round_way');
		show('multiCityForm');
		show('multi_city_add');
		form.dateTypeSelect[0].checked = true;
		form.flightType[2].checked = true;	
	}
	else	// one way
	{
		hide('multiCityForm');
		hide('multi_city_add');
		show('round_way');
		hide('search_options1');
		hide("chk_out_lbl");
		hide(form.returningDate);
		hide(form.dateReturningTime);
		hide(form.returnDateFlexibility);		
		form.dateTypeSelect[0].checked = true;
		form.flightType[1].checked = true;		
	}		
	clearSearchForm(searchType,form);
}

function addFlight()
{
	for(i=1; i<=4; i++)
	{
		var flightNum = "flight" + i;
		var currFlight = document.getElementById(flightNum);
		var mainDiv = document.getElementById('multiCityForm');
		if (currFlight.style.display == 'none')
		{
			currFlight.style.display = 'block';
			currFlightHeight = currFlight.offsetHeight;	
			if(i == 4)
				hide('multi_city_add');
				
			mainDiv.scrollTop += currFlightHeight;
			break;
		}		
	}	
}
				  
/*function resetAdvanceOption()
{	// resetting content selection by copying the template div
	gPopFrame.innerHTML = "";
}*/

var bodyHeight=0;
function resizeIframe(frameid){
	if(typeof(frameid) != "Object")
	{
		if(!frameid.match(/_frame/))
		{
			if (frameid=='hotel') frameid='hotel_frame';
			if (frameid=='air')frameid='air_frame';
			if (frameid=='customtrip') frameid='airHotel_frame';
			if (frameid=='car')frameid='car_frame';
			if (frameid=='lmd')frameid='lmd_frame';
			if (frameid=='activities')frameid='attractions_frame';
		}
		var currentfr = document.all? document.all[frameid] : document.getElementById(frameid);		
	}
	
	var parentContainer = document.all? document.all['multi_searchbox'] : document.getElementById('multi_searchbox');
	
	if (currentfr && parentContainer){
		currentfr.style.display="block";
		if (currentfr.contentDocument && parentContainer.offsetWidth&&currentfr.parentNode.offsetHeight) //ns6 syntax
		{
			if(bodyHeight == 0)
				bodyHeight = currentfr.parentNode.offsetHeight;
				
			currentfr.width = parentContainer.offsetWidth;
			currentfr.height = bodyHeight;
		}
		else if (currentfr.Document && parentContainer.scrollWidth && currentfr.parentNode.scrollHeight) //ie5+ syntax
		{
			if(bodyHeight == 0)
				bodyHeight = currentfr.parentNode.scrollHeight;
				
			currentfr.width = parentContainer.scrollWidth;
			currentfr.height = bodyHeight;
		}
	}
}

function clearStateCountry()
{
	try
	{
		document.getElementById('state').value="";	
		document.getElementById('country').value="";	
	}
	catch(e){}
}
