﻿// AceWidget Version 1.0

// below is a lst of products.  These names are tied to the div names
var products = new Array ("air", "hotel", "airHotel");

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.target=winName;
/*
        //document.frmAceWidget.action=getElemById("hidPageName").value;  //send request to here
        //document.frmAceWidget.method="post";  
        //{ ' ', ',', ';', '!', '-', '/', '\'', '"', '<', '>', '=', '&', '{', '(', ')', '}', '%' };
        //invalidChar[0] = ' ';
        invalidChar[1] = ',';
        invalidChar[2] = ';';
        invalidChar[3] = '!';
        invalidChar[4] = '-';
        invalidChar[5] = '/';
        invalidChar[6] = '\\';
        invalidChar[7] = '"';
        invalidChar[8] = '<';
        invalidChar[9] = '>';
        invalidChar[10] = '=';
        invalidChar[11] = '&';
        invalidChar[12] = '{';
        invalidChar[13] = '(';
        invalidChar[14] = ')';
        invalidChar[15] = '}';
        invalidChar[16] = '%';                

        for(i=0;i < document.frmAceWidget.length;i++) 
            {
                if (document.frmAceWidget[i].name != null)
                    if (document.frmAceWidget[i].name.indexOf('txt') > -1 && document.frmAceWidget[i].value != null)
                        if (document.frmAceWidget[i].value.length > 0 )                    
                            for(j=0;j < invalidChar.length;j++) {
                                var loc = document.frmAceWidget[i].value.indexOf(invalidChar[j]);
                                var value1 = document.frmAceWidget[i].value;
                                if (loc > -1)
                                    for (k=loc;k < value1.length; k++)
                                        if (value1.substring(k,k+1).indexOf(invalidChar[j]) > -1)
                                            document.frmAceWidget[i].value = document.frmAceWidget[i].value.replace(invalidChar[j],empty_string);
           }
         }    
*/
        document.frmAceWidget.submit();  //submit the request
        //returning false will stop the .net button from posting back
        return false;
    }
}

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;            
        }   
}


    

