//this page is used to set up general functions used through out the search boxes and WCT pages. 
  
// Popup windows 
var checkAir;
var blnForward = false;
var o_popurl = "#";
var o_popwindow = 0;
var b_popwindow = 1;
var Today = new Date();
var WeekDays = new Array('S','M','T','W','T','F','S');
var MonthDays = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
var MonthNames = new Array('January','February','March','April','May','June','July','August','September','October','November','December');
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);
}

function checkOptionValue(inputObj,paramToExternalFile,e)
	{
	if(inputObj.value.length <3){ 
	  if(document.getElementById("ajax_listOfOptions_iframe") !=null) {
	    ajax_options_hide() ;
	  } 
	   return;
	}
	else { ajax_list_currentLetters[inputObj.name]="";  
		ajax_showOptions(inputObj,paramToExternalFile,e);
		
	}
	}
//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=='air'){ 
	var leavingFromVal;
	var goingToVal;

	if(type=='air')
	{
		leavingFromVal =  form.leavingFrom[0].value
		goingToVal =  form.goingTo[0].value
	}	
	var child 	=  form.num_children.selectedIndex;
}



var blnPass = true;



if(type=='airHotel' || type=='air')
	{ 
	
		if(type == "air")
		{
			var airSearchType;
			if(form.TripType.length)
			{
				for (var i=0; i < form.TripType.length; i++)
				{
					if(form.TripType[i].checked == true)
					{
						airSearchType = form.TripType[i].value;
					}
				}
			}
			
			if (airSearchType == "rdbRoundTrip" || airSearchType == "rdbOneWay")		
			{
				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.txtDate1" +i);
					if (currFlight.style.display == 'block')
					{
						var leavingFromVal=eval("form.txtDepCity_" +i).value;
						var goingToVal = eval("form.txtArrCity_" +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.txtDate1" +i),"formWarning");
							eval("form.txtDate1" +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;
}

function setTheComponenetAuto()
{
document.getElementById("txtDepCity_1").setAttribute("autocomplete","off"); 
document.getElementById("txtArrCity_1").setAttribute("autocomplete","off"); 
document.getElementById("txtDepCity_2").setAttribute("autocomplete","off"); 
document.getElementById("txtArrCity_2").setAttribute("autocomplete","off"); 
document.getElementById("txtDepCity_3").setAttribute("autocomplete","off"); 
document.getElementById("txtArrCity_3").setAttribute("autocomplete","off");  
document.getElementById("txtDepFlight1").setAttribute("autocomplete","off"); 
document.getElementById("txtArrFlight1").setAttribute("autocomplete","off"); 
}

/**
 * Initializes popup code on load.	
 */
function initPopUp() {
	// Add the HTML to the body
	theBody = document.getElementsByTagName('form')['homeForm'];
	//theBody.txtDepCity_1.autocomplete="off";
	 setTheComponenetAuto();
	//alert(document.getElementById("txtDepCity_1").autocomplete);
	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.txtDepCity_1.value = "";
		change(form.txtDepCity_1,'');
		form.txtArrCity_1.value = '';
		change(form.txtArrCity_1,'');
		form.txtDate1.value='mm/dd/yyyy';		
		change(form.txtDate1,'');
		form.ddlTime1.options[form.ddlTime1.options.length-1].selected=true;
		//form.chkFlexSearch1.checked=true;
		
		// return		
		form.txtDate2.value = 'mm/dd/yyyy';
		change(form.txtDate2,'');
		
		form.ddlTime2.options[form.ddlTime2.options.length-1].selected=true;
		//form.chkFlexSearch2.checked=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.txtDate1.value='mm/dd/yyyy';		
		form.txtDate2.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.txtDepCity_" +i);
				var goingTo = eval("form.txtArrCity_" +i);
				leavingFrom.value = "";
				change(leavingFrom,'');
				goingTo.value = "";
				change(goingTo,'');
				//alert("form.txtDate1" +i);
				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.txtDepCity_1.value = "";
		change(form.txtDepCity_1,'');
		form.txtArrCity_1.value = '';
		change(form.txtArrCity_1,'');
		form.txtDate1.value='mm/dd/yyyy';		
		change(form.txtDate1,'');

		form.txtDate2.value = 'mm/dd/yyyy';
		//airDodCal.clear(); 
		change(form.txtDate2,'');
		//form.nearbyAirports.checked = false;
	}
}

function changeAirSearchType(searchType,form)
{
	var form = document.getElementById(form); 
	cFlightDisplayHide();
	document.homeForm.txtDepCity_1.value = "";
	document.homeForm.txtArrCity_1.value = ""; 
	if(searchType == "rt")  // round trip type
	{
		hide('multiCityForm');
		hide('multi_city_add');		
		show('round_way');
		show('search_options1')
		show("chk_out_lbl");
		show(form.txtDate2);
		show(form.ddlTime2);
		
		//#showagain#
		//show(form.chkFlexSearch2);
		show('labelchkSearch2');  	
			
		form.TripType[0].checked = true;
	}
	else if(searchType == "mc")  // multiple destinations
	{
		hide('round_way');
		show('multiCityForm');
		show('multi_city_add');
		
		//form.dateTypeSelect[0].checked = true;
		form.TripType[2].checked = true;	
	}
	else	// one way
	{
		hide('multiCityForm');
		hide('multi_city_add');
		show('round_way');
		hide('search_options1');
		hide("chk_out_lbl"); 
		hide('labelchkSearch2');
		hide(form.txtDate2);
		hide(form.ddlTime2);
		//hide(form.chkFlexSearch2);		
//		form.dateTypeSelect[0].checked = true;
		form.TripType[1].checked = true;		
	}		
	clearSearchForm(searchType,form);
	
	
}

function addFlight()
{
	for(i=1; i<=3; 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 == 3)
				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){}
}


function validateSearch(){
	alert_message = "";
	formObj = document.forms["homeForm"];
	var now = new Date();

	if(formObj.txtDepCity1.value == "" || formObj.txtDepCity1.value == formObj.txtDepCity1.getAttribute("defValue")) alert_message += " - Specify a Departure City for Flight 1\n";
	if(formObj.txtArrCity1.value == "" || formObj.txtArrCity1.value == formObj.txtArrCity1.getAttribute("defValue")) alert_message += " - Specify a Destination City for Flight 1\n";
	if(dateDiff('d', formObj.txtDate1.value, dateAdd('d',1,Today)) > 0) alert_message += " - Departure date for Flight 1 has to be atleast 1 day after today\n";

	if(formObj.TripType[0].checked || formObj.TripType[2].checked){
		if(formObj.txtDepCity2.value == "" || formObj.txtDepCity2.value == formObj.txtDepCity2.getAttribute("defValue")) alert_message += " - Specify a Departure City for Flight 2\n";
		if(formObj.txtArrCity2.value == "" || formObj.txtArrCity2.value == formObj.txtArrCity2.getAttribute("defValue")) alert_message += " - Specify a Destination City for Flight 2\n";
    	if(dateDiff('d', formObj.txtDate2.value, formObj.txtDate1.value) > 0) alert_message += " - Departure date for Flight 2 has to be on or after the date of Flight 1\n";
	}
	
	if(formObj.TripType[2].checked){
		if(formObj.txtDepCity3.value == "" || formObj.txtDepCity3.value == formObj.txtDepCity3.getAttribute("defValue")) alert_message += " - Specify a Departure City for Flight 3\n";
		if(formObj.txtArrCity3.value == "" || formObj.txtArrCity3.value == formObj.txtArrCity3.getAttribute("defValue")) alert_message += " - Specify a Destination City for Flight 3\n";
    	//if(dateDiff('d', formObj.txtDate3.value, formObj.txtDate2.value) > 0) alert_message += " - Departure date for Flight 3 has to be on or after the date of Flight 2\n";
	}

	if(alert_message!=""){
		//alert("Please fix the following problems: \n" + alert_message);
	//	return false;
	}
	return true;
}
function focusObj(obj){
	if(obj.value=="Airport or City")obj.value=""; 
}

function blurObj(obj){ 
	if(obj.value=="")obj.value = "Airport or City";
}

function copyTextbox(obj1, obj2){

    obj2.value = obj1.value;
   //alert(obj2.value+" ####  "+obj1.value);   
    
}



function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}


var xmlHttp;
m = new Array("01","02","03","04","05","06","07","08","09","10","11","12");
function SelectPlace(){ 
	
	var PreFlag;
	var url, todayDate;
	var one_day=1000*60*60*24;
	var todayDate = new Date();
	var tmpuserdate = new Array(); //alert("1d"+document.getElementById("txtDepCity_1_ID").value);
	
	if(document.homeForm.TripType[2].checked) { 
	if(document.homeForm.txtDepFlight1.value.length == 0) {
		 cFlightMulDisplay("Flight 1 leaving from left blank"); 
		   return ; 
	} else   {
			 if(document.homeForm.txtArrFlight1.value.length == 0)
			  {
			  cFlightMulDisplay("Flight 1 Going To left blank"); 
			   return ; 
			  } else {
			    if(document.homeForm.txtDepCity_2.value.length == 0)
			  { cFlightMulDisplay("Flight 2 leaving from left blank"); 
			   return ; 
			  } else if(document.homeForm.txtArrCity_2.value.length == 0) {
			  	cFlightMulDisplay("Flight 2 Going To left blank"); 
			   return ;   
			  }
			  }	
			  
		}	   
	
	} else {
	if(document.homeForm.txtDepCity_1.value.length == 0) 
		{
		 
		  cFlightDisplay("leaving from left blank"); 
		   return ; 
		} else   {
			 if(document.homeForm.txtArrCity_1.value.length == 0)
			  {
			  cFlightDisplay("Going To left blank"); 
			   return ; 
			  } else if(document.homeForm.txtDate1.value.length == 0)
			  
			  {
			   cFlightDisplay("Depart Date  left blank"); 
			    return ;
			  } else if(document.homeForm.txtDate2.value.length == 0) {
			    cFlightDisplay("Return Date  left blank");
			     return ;
			  } else {
		  cFlightDisplayHide(); }
		}
		
		}
		
			if(document.getElementById("txtDepCity_1_ID").value=="")
			{
			document.getElementById("txtDepCity_1_ID").value=document.getElementById("txtDepCity_1").value;
			}
			if(document.getElementById("txtDepCity_2_ID").value=="")
			{
			document.getElementById("txtDepCity_2_ID").value=document.getElementById("txtDepCity_2").value;
			}
			if(document.getElementById("txtArrCity_2_ID").value=="")
			{
			document.getElementById("txtArrCity_2_ID").value=document.getElementById("txtArrCity_2").value;
			}
			if(document.getElementById("txtDepCity_3_ID").value=="")
			{
			document.getElementById("txtDepCity_3_ID").value=document.getElementById("txtDepCity_3").value;
			}
			if(document.getElementById("txtArrCity_3_ID").value=="")
			{
			document.getElementById("txtArrCity_3_ID").value=document.getElementById("txtArrCity_3").value;
			}
			if(document.getElementById("txtArrCity_1_ID").value=="")
			{
			document.getElementById("txtArrCity_1_ID").value=document.getElementById("txtArrCity_1").value;
			}
			 
			
			document.getElementById("txtDepCity1").value=document.getElementById("txtDepCity_1_ID").value;
			document.getElementById("txtArrCity1").value=(document.getElementById("txtArrCity_1_ID").value);
			
			if(document.homeForm.TripType[2].checked) {
			 //alert(document.getElementById("txtDepFlight1_ID").value); 
			document.getElementById("txtDate1").value=document.getElementById("leavingDate1").value;
			if(document.getElementById("txtDepFlight1_ID").value == "")
			{
			document.getElementById("txtDepFlight1_ID").value=document.getElementById("txtDepFlight1").value;
			}
			document.getElementById("txtDepCity1").value = document.getElementById("txtDepFlight1_ID").value;
			if(document.getElementById("txtArrFlight1_ID").value == "")
			{
			document.getElementById("txtArrFlight1_ID").value=document.getElementById("txtArrFlight1").value;
			}
			document.getElementById("txtArrCity1").value = document.getElementById("txtArrFlight1_ID").value
			
			
			}
			
			document.getElementById("txtDepCity2").value=document.getElementById("txtDepCity_2_ID").value;
			document.getElementById("txtArrCity2").value=document.getElementById("txtArrCity_2_ID").value;
			if(document.homeForm.TripType[2].checked) { 
			document.getElementById("txtDate2").value=document.getElementById("leavingDate2").value;
			}
			
			
			document.getElementById("txtDepCity3").value=document.getElementById("txtDepCity_3_ID").value;
			document.getElementById("txtArrCity3").value=document.getElementById("txtArrCity_3_ID").value;
			if(document.homeForm.TripType[2].checked) { 
			document.getElementById("txtDate3").value=document.getElementById("leavingDate3").value;
			document.homeForm.flightType.value = "multicity" ;
			
			}
			//document.getElementById("cb_nba_input").value="off";
			//document.getElementById("cb_nba_input").checked=false;
			//document.homeForm.dateTypeSelect[0].checked = true; 
			if(document.homeForm.TripType[0].checked) { 
			
			 document.homeForm.flightType.value = "roundtrip" ;// alert(document.homeForm.flightType.value);
			 document.homeForm.flightType.checked = true;
			 document.homeForm.leavingFrom.value = document.homeForm.txtDepCity1.value; 
			 document.homeForm.goingTo.value     = document.homeForm.txtArrCity1.value;
			 document.homeForm.leavingDate.value= document.homeForm.txtDate1.value ;
			   document.homeForm.returningDate.value = document.homeForm.txtDate2.value;
			   document.homeForm.goingTo1.value = document.homeForm.txtDepCity2.value;
			   document.homeForm.leavingFrom1.value = document.homeForm.txtArrCity2.value;  
			   document.homeForm.leavingDate.value = document.homeForm.txtDate1.value;
   				document.homeForm.returningDate.value = document.homeForm.txtDate2.value;
   				
   				document.homeForm.dateLeavingTime.value = document.homeForm.ddlTime2.value; 
   				document.homeForm.dateReturningTime.value = document.homeForm.ddlTime1.value;
   				
   				if( document.homeForm.chkFlexSearch1.checked == true || document.homeForm.chkFlexSearch2.checked == true)
   				 {			
   				 			document.homeForm.dateTypeSelect.checked = true; 
   		  			        document.homeForm.dateTypeSelect.value="plusMinusDates"; 
   		 		}
   		 
   				 //document.homeForm.airlineSearchPref.value = document.homeForm.ddlAirline.value;
   				if(document.homeForm.ddlAirline == null) { 
		}else {
		document.homeForm.airlineSearchPref.value = document.homeForm.ddlAirline.value;
		}
   				 
   				 if(document.homeForm.ddlCabin == null){
			}
			else {
			 if(document.homeForm.ddlCabin.value == "Y"){ 
		    document.homeForm.classOfService.value = "Economy";}
		     if(document.homeForm.ddlCabin.value == "C"){
		      document.homeForm.classOfService.value = "Business";}
		       if(document.homeForm.ddlCabin.value == "F"){
		    document.homeForm.classOfService.value = "First";} 
		    }
					document.homeForm.adults.value = document.homeForm.ddlPaxADT.value;
     				document.homeForm.children.value = document.homeForm.ddlPaxCHD.value;
   					 document.homeForm.seniors.value = document.homeForm.ddlPaxINF.value; 
			}if(document.homeForm.TripType[1].checked) {   
			document.homeForm.flightType.value = "oneway" ;
			 document.homeForm.flightType.checked = true;
			 document.homeForm.leavingFrom.value = document.homeForm.txtDepCity1.value; 
			 document.homeForm.goingTo.value     = document.homeForm.txtArrCity1.value;
			 document.homeForm.leavingDate.value= document.homeForm.txtDate1.value ;
			   document.homeForm.returningDate.value = document.homeForm.txtDate2.value;
			   document.homeForm.goingTo1.value = document.homeForm.txtDepCity2.value;
			   document.homeForm.leavingFrom1.value = document.homeForm.txtArrCity2.value;  
			   document.homeForm.leavingDate.value = document.homeForm.txtDate1.value;
   				document.homeForm.returningDate.value = document.homeForm.txtDate2.value;
   				
   				document.homeForm.dateLeavingTime.value = document.homeForm.ddlTime2.value; 
   				document.homeForm.dateReturningTime.value = document.homeForm.ddlTime1.value;
   				 //document.homeForm.airlineSearchPref.value = document.homeForm.ddlAirline.value;
   				 
   				if(document.homeForm.ddlAirline == null) { 
		}else {
		document.homeForm.airlineSearchPref.value = document.homeForm.ddlAirline.value;
		}
   				 if(document.homeForm.ddlCabin == null){
			}
			else { 
			 if(document.homeForm.ddlCabin.value == "Y"){ 
		    document.homeForm.classOfService.value = "Economy";}
		     if(document.homeForm.ddlCabin.value == "c"){
		      document.homeForm.classOfService.value = "Business";}
		       if(document.homeForm.ddlCabin.value == "F"){
		    document.homeForm.classOfService.value = "First";} 
		    }
					document.homeForm.adults.value = document.homeForm.ddlPaxADT.value;
     				document.homeForm.children.value = document.homeForm.ddlPaxCHD.value;
   					 document.homeForm.seniors.value = document.homeForm.ddlPaxINF.value; 
			} if(document.homeForm.TripType[2].checked) {    
			 document.homeForm.flightType.value = "multicity" ;
			 document.homeForm.flightType.checked = true; 
			 
			 if(document.homeForm.mulFlexSearch1.checked == true) {
			 document.homeForm.chkFlexSearch1.checked=true;
			 document.homeForm.chkFlexSearch1.value=true;
			 }
			 if(document.homeForm.mulFlexSearch2.checked == true) {
			  document.homeForm.chkFlexSearch2.checked=true;
			 document.homeForm.chkFlexSearch2.value=true;
			 }
			 if(document.homeForm.mulFlexSearch3.checked == true) {
			  document.homeForm.chkFlexSearch3.checked=true;
			 document.homeForm.chkFlexSearch3.value=true;
			 }
			 
			 document.homeForm.leavingFrom1.value = document.homeForm.txtDepCity1.value; 
			 document.homeForm.goingTo1.value     = document.homeForm.txtArrCity1.value;
			 // document.homeForm.leavingDate1.value     = document.homeForm.leavingDate1.value;
			// document.homeForm.leavingTime1.value     = document.homeForm.leavingTime1.value;
			 
			 document.homeForm.leavingFrom2.value = document.homeForm.txtDepCity2.value; 
			 document.homeForm.goingTo2.value     = document.homeForm.txtArrCity2.value;
			// document.homeForm.leavingDate2.value     = document.homeForm.txtArrCity1.value;
			// document.homeForm.leavingTime2.value     = document.homeForm.txtArrCity1.value;
			 //alert(document.homeForm.leavingDate3.value);
			 document.homeForm.leavingFrom3.value = document.homeForm.txtDepCity3.value; 
			 document.homeForm.goingTo3.value     = document.homeForm.txtArrCity3.value;
			// document.homeForm.leavingDate3.value     = document.homeForm.txtArrCity1.value;
			// document.homeForm.leavingTime3.value     = document.homeForm.txtArrCity1.value;
			
			 if ((document.homeForm.leavingDate3.value) && (document.homeForm.goingTo3.value)){
				//document.getElementById("leavingDate3").value = getDate(document.getElementById("AIR_frommonth3").value, document.getElementById("AIR_fromdate3").value);
			} else {
				document.homeForm.leavingFrom3.value = "";
			}
			if(document.homeForm.leavingDate3.value == "mm/dd/yyyy") {
			  document.homeForm.leavingFrom3.value = ""; 
			  document.homeForm.goingTo3.value = "";
			  document.homeForm.leavingDate3.value = "";
			}
			 document.homeForm.leavingFrom4.value = document.homeForm.txtDepCity4.value; 
			 document.homeForm.goingTo4.value     = document.homeForm.txtArrCity4.value;
			 if ((document.homeForm.leavingDate4.value) && ( document.homeForm.goingTo4.value)){
				//document.getElementById("leavingDate4").value = getDate(document.getElementById("AIR_frommonth4").value, document.getElementById("AIR_fromdate4").value);
			} else { 
				 document.homeForm.leavingFrom4.value = "";  
			}
			
			if(document.homeForm.leavingDate4.value == "mm/dd/yyyy") {
			  document.homeForm.leavingFrom4.value = "";
			  document.homeForm.goingTo4.value = "";
			  document.homeForm.leavingDate4.value = ""; 
			}
			// document.homeForm.leavingDate4.value     = document.homeForm.txtArrCity1.value;
			/// document.homeForm.leavingTime4.value     = document.homeForm.txtArrCity1.value;
			
			 //document.homeForm.airlineSearchPref.value = document.homeForm.ddlAirline.value;
   				 
   				
				
					document.homeForm.adults.value = document.homeForm.ddlPaxADT.value;
     				document.homeForm.children.value = document.homeForm.ddlPaxCHD.value;
   					 document.homeForm.seniors.value = document.homeForm.ddlPaxINF.value; 
			 
			} 
			if(document.homeForm.ddlCabin == null){
			}
			else {
			 if(document.homeForm.ddlCabin.value == "Y"){ 
		    document.homeForm.classOfService.value = "Economy";}
		     if(document.homeForm.ddlCabin.value == "C"){
		      document.homeForm.classOfService.value = "Business";}
		       if(document.homeForm.ddlCabin.value == "F"){
		    document.homeForm.classOfService.value = "First";} 
		    }
			
		if(document.homeForm.TripType[0].checked) {
		  document.homeForm.txtDepCity2.value =document.homeForm.txtArrCity1.value;
		  document.homeForm.txtArrCity2.value = document.homeForm.txtDepCity1.value; 
		}
		if(document.homeForm.ddlAirline == null) { 
		}else {
		document.homeForm.airlineSearchPref.value = document.homeForm.ddlAirline.value;
		}
		//checkMulToRoundtrip(); 
		//document.homeForm.classOfService.value = document.homeForm.ddlCabin.value;
		//alert(document.homeForm.ddlAirline.value);
		//alert(document.homeForm.txtDepCity3.value);
		//alert(document.homeForm.txtArrCity3.value);
		
		// convert multipsearch to roundtrip
		
		//if(document.homeForm.TripType[2].checked  ) {
		//if(document.homeForm.txtDepCity3.value == "" && document.homeForm.txtArrCity3.value == "") {
		//  document.homeForm.TripType.value = "rdbRoundTrip"; 
		//  document.homeForm.TripType[0].checked = true; 
		//document.homeForm.flightType.value = "roundtrip" ;
	//	document.homeForm.flightType.checked = true;  
		
	//	 document.homeForm.leavingFrom.value = document.homeForm.txtDepCity1.value;  
	//	document.homeForm.goingTo.value     = document.homeForm.txtArrCity1.value;
	//	document.homeForm.leavingDate.value= document.homeForm.leavingDate1.value ;
	//	
	//	document.homeForm.goingTo1.value = document.homeForm.txtDepCity2.value;
	//	document.homeForm.leavingFrom1.value = document.homeForm.txtArrCity2.value;  
		
   //		document.homeForm.returningDate.value = document.homeForm.leavingDate2.value;
   	//	document.homeForm.dateLeavingTime.value = document.homeForm.leavingTime1.value; 
   	//	document.homeForm.dateReturningTime.value = document.homeForm.leavingTime2.value;
   	//			
	//	}
	//}
	
	// end of convert multipsearch to roundtrip
		
	if(validateSearch()){
		PreFlag = true;
		tmpuserdate = document.homeForm.txtDate1.value.split("/");
		
		var userdate = new Date(tmpuserdate[2], tmpuserdate[0], tmpuserdate[1]);
		
		if(userdate.getMonth()==11 && userdate.getDate()>30){
			todayDate.setFullYear(todayDate.getFullYear()+1);
		}
	
		var diff = Math.ceil((userdate.getTime() - todayDate.getTime())/(one_day)) - 31;
		
		if(diff <=0){
			PreFlag = true;
		}
		else{
			PreFlag = false;
		}
		
		if(PreFlag == true){
			PreFlag = false;
			
		}
		
		
		//alert(document.homeForm.txtDepCity1.value); 
		if(PreFlag == false){
			document.homeForm.action = "http://book.perfectibe.com/process.aspx";
			//document.homeForm.agentid.value = 130;  
			//document.homeForm.submit(); 
			//alert("aa"+document.homeForm.agentid.value);
			setForward(false);
			 //alert("fdfdf");
			checkAirFlight(document.homeForm.txtDepCity1.value);
			
			// while(getForward() == false)
			// {
			 	///checkAir = document.homeForm.agentid.value;
			// }
			//checkAir = document.homeForm.agentid.value;
			
			 
		
		}
	}
}
function cFlightDisplay(strMessage){ 
	document.getElementById("errorMessageId").innerHTML =strMessage;
}
function cFlightDisplayHide(){ 
	document.getElementById("errorMessageId").innerHTML ="";
}
function cFlightMulDisplay(strMessage){ 
	document.getElementById("errorMessageMulId").innerHTML =strMessage;
}
function cFlightMulDisplayHide(){ 
	document.getElementById("errorMessageMulId").innerHTML ="";
}
function setForward(bool)
{
	blnForward = bool;
}
function getForward()
{
	return blnForward;
}


function checkMulToRoundtrip() {
if(document.homeForm.TripType[2].checked  ) {

		if(document.homeForm.txtDepCity3.value == "" && document.homeForm.txtArrCity3.value == "") {
		  document.homeForm.TripType.value = "rdbRoundTrip"; 
		  document.homeForm.TripType[0].checked = true; 
		document.homeForm.flightType.value = "roundtrip" ;
		document.homeForm.flightType.checked = true;  
		
		 document.homeForm.leavingFrom.value = document.homeForm.txtDepCity1.value;  
		document.homeForm.goingTo.value     = document.homeForm.txtArrCity1.value;
		document.homeForm.leavingDate.value= document.homeForm.leavingDate1.value ;
		
		document.homeForm.goingTo1.value = document.homeForm.txtDepCity2.value;
		document.homeForm.leavingFrom1.value = document.homeForm.txtArrCity2.value;  
		
   		document.homeForm.returningDate.value = document.homeForm.leavingDate2.value;
   		document.homeForm.dateLeavingTime.value = document.homeForm.leavingTime1.value; 
   		document.homeForm.dateReturningTime.value = document.homeForm.leavingTime2.value;
   		
   				
		}
	}
}

function submitFlightCheck1()
	{ 		var newHidden;
			 document.getElementById("homeForm").action = "http://booking.etripinfo.com/nexres/start-pages/gateway.cgi";
	  		 newHidden = document.createElement("input");  
			 newHidden.setAttribute("type","hidden");
			 newHidden.setAttribute("id","action");
			 newHidden.setAttribute("name","action");
			 newHidden.setAttribute("value","search");  
			 
			 document.getElementById("homeForm").appendChild(newHidden);
			 document.getElementById("airTripType").disabled = true;
			 document.homeForm.submit(); 
			
	 //document.homeForm.action = "http://booking.etripinfo.com/nexres/start-pages/gateway.cgi";
	
	 //doSubmit('10012782',''); 
	 //eval("document."+formName).submit();    
	}
	var chkPrevValue = "";
 function checkAirFlight(airValue)
 {
       // setTimeout('',100000); 
 		//url = "http://www.etripinfo.com/includes/SelectPlace.jsp?PlaceValue="+airValue;
 		//url ="http://www.etripinfo.com/includes/SelectPlace.jsp?PlaceValue="+airValue;
 		url ="http://www.etripinfo.com/includes/SelectPlace.jsp?PlaceValue="+airValue;
 		
 		//alert(url);
 		
 		//document.homeForm.txtDepCity1.value; 
			//url ="http://www.etripinfo.com/includes/SelectPlace.jsp?PlaceValue="+document.homeForm.txtDepCity1.value;  
			
			
			xmlHttp=GetXmlHttpObject();  
		  if(xmlHttp==null){ 
				return false; 
			} 
			
			xmlHttp.onreadystatechange=stateChanged ;
			xmlHttp.open("GET",url,true);
			xmlHttp.send(null); 
 }
function stateChanged(){
	if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		var temp; 
		 
		temp = xmlHttp.responseText.replace(/\n|\r|\t|&#13;|&#10;/g,"");   
	 // alert("first "+temp)
	    chkPrevValue = temp;
	     if(temp == "OTHER")
	      {
	        cFlightDisplay("Leaving destination doesn't match"); 
			   return ;  
	      } 
		if(temp == "IN"){ checkAir = "123"; 
			document.homeForm.agentid.value = 123;  
			document.homeForm.action = "http://book.perfectibe.com/process.aspx";
			checkMulToRoundtrip();
			 document.homeForm.submit(); 
		}
		
		if(temp == "US"){  
		       checkAir = "130";  
		    	//alert("hi");   
			document.homeForm.agentid.value = 130;
			checkAirFlight1(document.homeForm.txtArrCity1.value); 
		} 
		if(temp == "DIFF"){  
		       checkAir = "130";  
		    	//alert("hi");   
			document.homeForm.agentid.value = 130;
			checkAirFlight1(document.homeForm.txtArrCity1.value); 
		}
		//alert("aa"+checkAir);  
		//if(checkAir == "130")
			// { 
			 	//alert("hi");
			// checkAirFlight1(document.homeForm.txtArrCity1.value);  
			 
			// } 
			// else if(checkAir == "123"){
			  //document.homeForm.agentid.value = 123;  
			 // document.homeForm.submit();
			// }
		//alert(blnForward);
		// setForward(true);
		 //alert(blnForward);
			//alert(document.homeForm.agentid.value
		 
		//document.homeForm.submit(); 
	}
}
function checkAirFlight1(airValue) 
 {
       // setTimeout('',100000); 
 		//url = "http://www.etripinfo.com/includes/SelectPlace.jsp?PlaceValue="+airValue;
 		//url ="http://www.etripinfo.com/includes/SelectPlace.jsp?PlaceValue="+airValue;
 		url ="http://www.etripinfo.com/includes/SelectPlace.jsp?PlaceValue="+airValue;
 		
 		//document.homeForm.txtDepCity1.value; 
			//url ="http://www.etripinfo.com/includes/SelectPlace.jsp?PlaceValue="+document.homeForm.txtDepCity1.value;  
			//alert(url);
			
			xmlHttp=GetXmlHttpObject();   
		  if(xmlHttp==null){ 
				return false;     
			} 
			
			xmlHttp.onreadystatechange=stateChanged1 ;
			xmlHttp.open("GET",url,true);
			xmlHttp.send(null);
 }
function stateChanged1(){
	if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		var temp; 
		
		temp = xmlHttp.responseText.replace(/\n|\r|\t|&#13;|&#10;/g,"");   
	   // alert("sec "+temp)
	     if(temp == "OTHER")
	      {
	        cFlightDisplay("Going destination doesn't match");  
			   return ;  
	      }
	      
	      	 if(temp == "US"){ 
	      	 	checkAir = "130";
			     submitFlightCheck1();	
				document.homeForm.agentid.value = 130;
				//document.homeForm.action = "http://book.perfectibe.com/process.aspx";
				
				document.homeForm.submit(); 
	      	 } else  if(temp == "DIFF"){ 
	      	 checkMulToRoundtrip();
	      	  document.homeForm.agentid.value = 130;     
			  document.homeForm.action = "http://book.perfectibe.com/process.aspx";
			//  checkMulToRoundtrip();
			  document.homeForm.submit(); 
	      	 } else if(temp == "IN"){
	      	 checkMulToRoundtrip();
	      	 document.homeForm.agentid.value = 130;    
			  document.homeForm.action = "http://book.perfectibe.com/process.aspx";
			//  checkMulToRoundtrip();
			  document.homeForm.submit(); 
	      }
	      
		//if(checkAir == "130") {   
			 // alert("other root");
			//  submitFlightCheck1();
			 // document.homeForm.agentid.value = 130;
			 // alert( document.homeForm.leavingDate.value);
			//  document.homeForm.submit(); 
			// } else  if(checkAir == "123") {  
			//  document.homeForm.agentid.value = 130;  
			 // document.homeForm.action = "http://book.perfectibe.com/process.aspx";
			 // document.homeForm.submit(); 
			 //}
	}
}
//--------------------------------------------------------------------
//create xmlhttpobject
//--------------------------------------------------------------------
function GetXmlHttpObject(){

	var objXMLHttp=null;
	if(window.XMLHttpRequest){
		objXMLHttp=new XMLHttpRequest();
	}
	else if(window.ActiveXObject){
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	return objXMLHttp;
	
	
}
function  toggleTime(dateType)
      {
           if (dateType == 'exact'){hide('departDateFlexibility');hide('returnDateFlexibility');showInline('dateLeavingTime');showInline('dateReturningTime');}
           if (dateType == 'plusMinus'){showInline('departDateFlexibility');showInline('returnDateFlexibility');hide('dateLeavingTime');hide('dateReturningTime');}
    }
    
    function changeAll() {change('tab_1','norm_tab');change('tab_2','norm_tab');change('tab_3','norm_tab');change('tab_4','norm_tab');change('tab_5','norm_tab');change('tab_6','norm_tab');}

// hide and show id's
/*function show(idLayer) { try{document.getElementById(idLayer).style.display='block';} catch(err){} }
function hide(idLayer) { try {document.getElementById(idLayer).style.display='none'; } catch(err){} }*/
function hideAll() {hide('hotel_frame');hide('air_frame');hide('airHotel_frame');hide('car_frame');hide('lmd_frame');hide('attractions_frame');}

// toggle search boxes and higlights tabs
function flip(idLayer){
	hideAll();
	if (idLayer=='1' || idLayer=='hotel' ){ searchType = "hotel";show('hotel_frame');changeAll();change('tab_1','active_tab');}
	if (idLayer=='2' || idLayer=='air'){ searchType = "air";show('air_frame');changeAll();change('tab_2','active_tab');}
	if (idLayer=='3' || idLayer=='customtrip'){searchType = "airHotel";show('airHotel_frame');changeAll();change('tab_3','active_tab');}
	if (idLayer=='4' || idLayer=='car'){searchType = "car";show('car_frame');changeAll();change('tab_4','active_tab');}
	if (idLayer=='5' || idLayer=='lmd'){searchType = "lmd";show('lmd_frame');changeAll();change('tab_5','active_tab');}
	if (idLayer=='6' || idLayer=='activities'){searchType = "attractions";show('attractions_frame');changeAll();change('tab_6','active_tab');}
}

// to redirect to 4hr car advanced search page
function go() {

       var destination = document.CarSearch.puwhere.value;

       var re = new RegExp('CarRequest');
       var m = re.exec(destination);
       if (m != null)
       {
			   //location.target = "_top";
               top.location.href = destination;
       } else {
               return false;
       }
}

