﻿// AceWidget Version 1.0

var tabTitles = new Array("flights", "cars", "hotels", "cruises","vacations", "directions" );
var tabDefaultProduct = new Array ("air", "car", "hotel", "cruise", "vacation", "direction" );
// below is a lst of products.  These names are tied to the div names
var products = new Array ("air", "car", "hotel", "airHotel", "cruise", "vacation", "direction");

var productPointer;     //points to current product
var tabPointer;         //points to current tab
var debugging;          //a flag from a hidden form field for diagnostic messages (see web.config)
var widgetPrefix;       //a hidden field that contains the name of the .net User Control.  Needed to prefix elements in 'getelementbyname/id)

var navID = 'navBox';
var windowCntr = 0;



/** Main Functions **/

//replaces the body onload event.  Can't be called by some browsers
function initializeWidget()
{
	if(document.all)
	{
		if(document.readyState == "complete")
		{
			doInitWork();
		}
		else
			window.setTimeout(initializeWidget, 100); 
	}
	else
	{
		doInitWork();
	}	
}

function doInitWork()
{
    initTabJS();
    widgetPrefix = getWidgetID();
    debugging = getElemById("hidDebugFlag").value; 
    tabPointer=tabTitles[0];    
    productPointer = products[0];
	SwitchWidgetTab(tabPointer);
}

function SwitchWidgetTab(tabname)
{ 
	
	AW_highlightTab(tabname);

    hideButtonRows();
    exposeButtonRow(tabname)

	hideAllProducts(); 
	showDefaultProduct(tabname);
	tabPointer = tabname;
}

function hideButtonRows()
{
    for (var i=0; i<tabTitles.length; i++)
    {
        try
        {
        	getElemById(tabTitles[i]+"Buttons").style.display="none";
        }
    	//not all tabs have buttons
    	catch(e) {}
    }
}

function exposeButtonRow(tabname)
{
	//not all tabs have buttons
    try
	{
		getElemById(tabname + "Buttons").style.display = "inline";
		getElemByName(tabname + "Radio")[0].checked = "true";
	}
	catch(e)
	{ var x ; x = 1;
	}
}

function hideAllProducts()
{
    for (var i=0; i<products.length; i++)
    {
        getElemById(products[i]+"Product").style.display = "none";
    }
}


function changeProduct(product) 
{
	hideAllProducts(); 
    //not all tabs have products
    try
	{
        getElemById(product+"Product").style.display = "inline";
	}
	catch(e){}
}

function showDefaultProduct(tabname)
{
    for (var i=0; i<tabTitles.length; i++)
    {
        if (tabTitles[i] == tabname)
        {
            changeProduct(tabDefaultProduct[i]);
	    }
    }
}

function checkforblanks(frm)
{
	if(frm.city && !frm.city.value) 
	{
		alert("Please enter a city"); 
		frm.city.focus(); 
		return true; 
	}
	else if (frm.depCity)
	{
		if(!frm.depCity.value)
		{
			alert("Please enter a departure city"); 
			frm.depCity.focus(); 
			return true; 
		}
		if(!frm.arrCity.value)
		{
			alert("Please enter an arrival city"); 
			frm.arrCity.focus(); 
			return true; 
		}
	}
	return false; 
}
 
function enableChildAgeFields(controlPrefix, product)
{
    //first hide the div that contains the controls
     getElemById(product + "_Children").style.display = "none";

    //next disable all of them - unlimited number, do forever
    for (var i=1; ; i++)
    {
        try
        {
            getElemById(controlPrefix + "Child" + i).disabled=true;
        }
        catch(e)
        {
            //end of the line
            break;
        }
    }
    //now enable some of them --  and if any then show the div
    var children = parseInt(getElemById(controlPrefix + "Children").options[getElemById(controlPrefix + "Children").selectedIndex].text);
    for (var k=1; k < children+1; k++)
    {
	    getElemById(controlPrefix + "Child" + k).disabled=false;
        getElemById(product + "_Children").style.display = "inline";
    }
}

function getElemById(ID)
{
    var el;
	el = document.getElementById(ID);
	if (!el) 
	{
	    	el = document.getElementById(widgetPrefix +"_" + ID);
        	if(!el && debugging == "true") window.status = "getElemById : Element " + ID + " was not found"; 
	}
	return el;
 }

function getElemByName(theName)
{
    var el;
	el = document.getElementsByName(theName);
	if (!el)
	{
	    el = document.getElementsByName(widgetPrefix + "$" + theName);
	    if(!el && debugging == "true") window.status = "getElemByName : Element " + theName + " was not found"; 
	}
	return el;
 }

function getWidgetID()
{
    var widgetName;
	el = document.getElementsByTagName("input");
	try 
	{
	    for (var i = 0; i < el.length; i++)
	    {
	        if (el[i].type == "hidden")
	        {
    	        if (el[i].name.indexOf("hidWidgetName") > 0)
	            {
	                widgetName = el[i].value;
	                break;
	            }
	        }
	    }
	}
	catch(e)
	{
	    widgetName = "AceWidget1";
	}
	return widgetName;
 }


/** UI FUNCTIONS **/

/* Function:    initTabJS()
 *              Initializes all tabs and assigns their respective event handlers
 * Params:      none
 * Modified:    Fernan - Feb.5,2007
 *
 */
 
function initTabJS() {
    var ul;     //parent UL/LI element
    var li;
    var tab;    // current tab

    if(document.getElementById && document.getElementsByTagName ) {
        ul = document.getElementById(navID);
        li = ul.getElementsByTagName( 'li' );
        
        for(var i=0; i<li.length; i++) {
            
            tab = li[i].getElementsByTagName( 'a' );
            
            // onFocus
            tab[0].onfocus = function() {
                //AW_highlightTab( this.className );
                SwitchWidgetTab(this.className);
            };
            
            // onClick
            tab[0].onclick = function() {
                SwitchWidgetTab(this.className);
            };   
        }
    }
}

/* Function:    AW_highlightTab(tabID)
 *              Highlights the selected tab.  
 *
 * params:      tabID - ID of the current tab element
 * dependency:  AW_initTabJS(), SwitchWidgetTab()
 * Modified:    Fernan - Feb.5,2007
 *
 */

function AW_highlightTab(tabID) {
    var el;
    
    if( document.getElementById && document.getElementsByTagName ) {

        el = document.getElementById('navBox'); // containers are too deep.

        if( el != null && tabID != '' ) {
            el.className = tabID;
        }          
    }
} 

// utility
function getTabnameFromId( tabID ) {
    return tabID.substring(0, tabID.indexOf('T'));
}

function searchButtonClick(product) {
    getElemById("hidSearchButtonClick").value = product;
    if (getElemById("hidDoPopup").value == "no") {
        //returning true will allow the .net button to continue its postback work
        return true;
    }
    else {
        windowCntr += 1;
        winParams  = "menubar=1,";
        winParams += "toolbar=1,";
        winParams += "location=1,";
        winParams += "status=1,";
        winParams += "scrollbars=1,";
        winParams += "resizable=1,";
        winParams += "top=50,";
        winParams += "left=50,";
        winParams += "height=600,";
        winParams += "width=800";
        winName    = "AAA_Travel" + windowCntr;
        window.open('', winName, winParams);  //pop a new window
        document.frmAceWidget.target = winName; //send the server's response to the new window
        //document.frmAceWidget.action=getElemById("hidPageName").value;  //send request to here
        //document.frmAceWidget.method="post";  
        document.frmAceWidget.submit();  //submit the request
        //returning false will stop the .net button from posting back
        return false;
    }
}

function air_showExact() {
    getElemById("airDepFlex").style.display = "none";
    getElemById("airDepExact").style.display="inline";
    getElemById("airRetFlex").style.display = "none";
    getElemById("airRetExact").style.display="inline";
    // show fare type drop down for flexible travel dates
    getElemById("Air_Class").style.visibility="visible";
}


function air_showFlex() {
    getElemById("airDepFlex").style.display = "inline";
    getElemById("airDepExact").style.display="none";
    getElemById("airRetFlex").style.display = "inline";
    getElemById("airRetExact").style.display="none";
    // hide fare type drop down for flexible travel dates
    getElemById("Air_Class").style.visibility="hidden";

}

/*
    function AW_ChangeDropOffCity( dropOffCB ) {
        
        var DropOffLoc = getElemById('txtCarReturn');
        var PickUpLoc = getElemById('txtCarDepart').value;
        
        if( dropOffCB.checked ) {
            DropOffLoc.value = PickUpLoc;
            DropOffLoc.disabled = true;
        } else {
            DropOffLoc.value = '';
            DropOffLoc.disabled = false;            
        }   
}
*/

// this function toggles the visibility of the different Pickup Options div
function AW_ChangePickUpCar() {
                
        var PickUpCar = getElemById('ddlCarAirport').value;
        
        if (PickUpCar == null) return;
        
        if (PickUpCar == 'airport') {
            getElemById("carAirport").style.display = "inline";
            getElemById("carAddress").style.display="none";
            getElemById("carPOI").style.display="none";
        }
        else if (PickUpCar == 'address')
	    {   getElemById("carAirport").style.display = "none";
            getElemById("carAddress").style.display="inline";
            getElemById("carPOI").style.display="none";
        }
        else if (PickUpCar == 'poi')
	    {   getElemById("carAirport").style.display = "none";
            getElemById("carAddress").style.display="none";
            getElemById("carPOI").style.display="inline";
        }                
}

// this function toggles the visibility of the different Pickup Options div
function AW_DifferentPickup() {
                
        var DiffPickUpCar = getElemById('chkCarDifferentDepart').checked;        
        var dPickUpCar = getElemById('dddlCarAirport').value;
                
        if (DiffPickUpCar == true) {            
            getElemById("dcarChoiceDropDown").style.display = "inline";
                                    
            if (dPickUpCar == 'doairport') {
                getElemById("dcarAirport").style.display = "inline";
                getElemById("dcarAddress").style.display="none";
                getElemById("dcarPOI").style.display="none";
            }
            else if (dPickUpCar == 'doaddress')
	        {   getElemById("dcarAirport").style.display = "none";
                getElemById("dcarAddress").style.display="inline";
                getElemById("dcarPOI").style.display="none";
            }
            else if (dPickUpCar == 'dopoi')
	        {   getElemById("dcarAirport").style.display = "none";
                getElemById("dcarAddress").style.display="none";
                getElemById("dcarPOI").style.display="inline";
            }
        } else {            
            getElemById("dcarChoiceDropDown").style.display = "none";
            getElemById("dcarAirport").style.display = "none";
            getElemById("dcarAddress").style.display= "none";
            getElemById("dcarPOI").style.display= "none";
            }                       
}

// this function toggles the visibility of the different DropOff Options div
function AW_ChangedPickUpCar() {
                
        var dPickUpCar = getElemById('dddlCarAirport').value;
        
        if (dPickUpCar == null) return;
        
        if (dPickUpCar == 'doairport') {
            getElemById("dcarAirport").style.display = "inline";
            getElemById("dcarAddress").style.display="none";
            getElemById("dcarPOI").style.display="none";
        }
        else if (dPickUpCar == 'doaddress')
	    {   getElemById("dcarAirport").style.display = "none";
            getElemById("dcarAddress").style.display="inline";
            getElemById("dcarPOI").style.display="none";
        }
        else if (dPickUpCar == 'dopoi')
	    {   getElemById("dcarAirport").style.display = "none";
            getElemById("dcarAddress").style.display="none";
            getElemById("dcarPOI").style.display="inline";
        }                
}

// this function toggles the visibility of the "More Search Options" div
// located at the bottom of each tab's pages 
function Toggle_MoreSearchOptions( moreOptionsLabel, moreOptionsID ) {
        var moreOptionsDiv;
        var moreOptionsLabel;
        var isVisible;
        
        if( ! (document.getElementById && document.getElementsByTagName )) 
            return false;
            
        moreOptionsDiv = document.getElementById( moreOptionsID );    
        moreOptionsLabel = document.getElementById( moreOptionsLabel );
        if(moreOptionsDiv != null) {
        
            isVisible = (moreOptionsDiv.style.display != 'none') ? true : false; 
            //alert(isVisible);

            /*
            if(isVisible) {
                moreOptionsDiv.style.display = 'none';
                moreOptionsLabel.innerHTML = 'Show More Search Options';                
            } 
            else {
            */
                moreOptionsDiv.style.display = 'block';
                moreOptionsLabel.innerHTML = '<label>More Search Options</label><br /><br/>';
                
            //}
        }
}
    
function air_showRound() {
    getElemById("airNormal").style.display = "inline";
    getElemById("airMulti").style.display = "none";
//    getElemById("airCompareZone").style.visibility="visible";
    getElemById("airReturnZone").style.visibility="visible";
    getElemById("airExactZone").style.display="inline";
    getElemById("airCompareZone").style.display = "inline";
    getElemById("airReturnZone").style.display = "inline";
}

function air_showOneWay() {
    getElemById("airNormal").style.display = "inline";
    getElemById("airMulti").style.display = "none";
    air_showExact();
	getElemById("radAirExact").checked = "true";
//    getElemById("airCompareZone").style.visibility="hidden";
//    getElemById("airReturnZone").style.visibility="hidden";
    getElemById("airExactZone").style.display = "none";
    getElemById("airCompareZone").style.display = "none";
    getElemById("airReturnZone").style.visibility = "hidden";
}

function air_showMulti() {
    getElemById("airNormal").style.display = "none";
    getElemById("airMulti").style.display = "";
}
