/*
 * NOTE:	This file should only be included by the transTasmanPorts.inc file
 *			If you wish to use this file, please include the transTasmanPorts.
 *			inc file instead.
 *
 */
/* global variable denotes whether previous selection was Trans Tasman or not.*/
TTSet="";

/********************************************************************************
*
* Name:		setFareList
*
* Args:		region   - region to base the fares on ie "au"
*				from		- (from city) point of origin for flight
*             to		    - flight destination *
*				fareList	- fare list drop down selection box
*
* Returns:		void
*
* Description:	function is used to swap the drop down fare list when a Trans
*				Tasman flight has been selected.
*
*				si = selected index for the farelist drop down
*
*				TTSet - global variable stores a value denoting whether the
*						 previous selection was Trans Tasman or not.
*
*				TTfareList - trans-Tasman fare dropdown list
*
*				NonTTfareList - non trans-Tasman fare dropdown list
*
*			possible values for TTSet.
*				TTSet == "Y" User has previously chosen a Trans-Tasman Flight
*				TTSet == "N" User has not chosen a Trans-Tasman Flight
*				TTSet == ""  User just arrived at this page (or hit back button)
*
*******************************************************************************/
function setFareList(region,from,to,fareList){
	if("au"==region.toLowerCase()||"sp"==region.toLowerCase()){
		if(isTransTasmanTrip(region,from,to)){
			if(TTSet=="N" || TTSet==""){
				setFL(TTfareList,fareList);
				if(TTSet=="N"){
					fareList.options.selectedIndex=0;
				}
				TTSet='Y';
			}
		}else{
			if(TTSet=="Y" || TTSet==""){
				setFL(NonTTfareList,fareList);
				if(TTSet=="Y"){
					fareList.options.selectedIndex=0;
				}
				TTSet="N";
			}
		}
	}
}

/********************************************************************************
 *
 * Name:		isTransTasmanTrip 
 *
 * Args:		region	- region to base the fares on ie "au"
 *				from		- (from city) point of origin for flight
 *             to			- flight destination
 *
 * Returns:		true - if this is a Trans Tasman Flight, else False
 *
 * Description:	Function is used to verify that a given city pair form a Trans Tasman flight.
 *
 *            Variable acronyms - (to keep things short)
 *              rg1 = region 1 (ie AU or NZ)                                         
 *              rg2 = region 2 (ie AU or NZ)                                         
 *              NZc = String containing all NZ Trans Tasman 3 letter city codes      
 *              AUc = String containing all AU Trans Tasman 3 letter city codes      
 *
 *******************************************************************************/

function isTransTasmanTrip(region,from,to){
	var rg1=AUc;rg2=NZc;
	if(from=="" || to==""){return false;}
	else{
		return((rg1.indexOf(from) != -1) && (rg2.indexOf(to) !=-1) || (rg1.indexOf(to) != -1) && (rg2.indexOf(from) !=-1));
	}
}

/********************************************************************************
 *
 * Name:		setFareListCheckT_Tasmin
 *
 * Args:		region   - region to base the fares on ie "au"
 *					from		- (from city) point of origin for flight
 *          to		    - flight destination *
 *					fareList	- fare list drop down selection box
 *
 * Returns:		void
 *
 * Description:	function is used to swap the drop down fare list when a Trans
 *							Tasman flight has been selected.  It also checks if the route is
 *							trans tasmin, and shows/hides the appropriate DIV...
 *
 *				si = selected index for the farelist drop down
 *				
 *				TTSet - global variable stores a value denoting whether the
 *						 previous selection was Trans Tasman or not.
 *
 *			possible values for TTSet.
 *				TTSet == "Y" User has previously chosen a Trans-Tasman Flight 
 *				TTSet == "N" User has not chosen a Trans-Tasman Flight
 *				TTSet == ""  User just arrived at this page (or hit back button)
 *	
 *******************************************************************************/
function setFareListCheckT_Tasman(region,from,to,fareList){
    var divDefault      = "default";
    var divNFSDefault   = "transTasmanPostThrottleDate";
    var divTravelClass  = "divTravelClass";
    var divSortBy       = "divSortBy";
    var divNFSGo        = "divNFSGo";
    var divMultiDest	= "multiDest";
	
	if(from==null || from.length==0) from="selectacity";
	if(to==null || to.length==0) to="selectacity";

    if (region.indexOf("as")!=-1)
    {
             if(document.getElementById(divTravelClass)!=null) document.getElementById(divTravelClass).style.display="block";
             if(document.getElementById(divDefault)!=null) document.getElementById(divDefault).style.display="none";
             if(document.getElementById(divNFSDefault)!=null) document.getElementById(divNFSDefault).style.display="block";
             isShowTimeDropdown(false);
    } else if (region.indexOf("am")!=-1) {
             if(document.getElementById(divTravelClass)!=null) document.getElementById(divTravelClass).style.display="block";
             if(document.getElementById(divDefault)!=null) document.getElementById(divDefault).style.display="none";
             if(document.getElementById(divNFSDefault)!=null) document.getElementById(divNFSDefault).style.display="block";
             if(document.getElementById(divMultiDest)!=null) document.getElementById(divMultiDest).style.display="";
             isShowTimeDropdown(false);
    } else if((region.indexOf("au")!=-1) || (region.indexOf("sp")!=-1)) {
		this.setFareList(region,from,to,fareList);
        if(!isTransTasmanTrip(region,from,to))
        {
            if((region.indexOf("au")!=-1))
            {
                if(document.getElementById(divTravelClass)!=null) document.getElementById(divTravelClass).style.display="block";
                if(document.getElementById(divDefault)!=null) document.getElementById(divDefault).style.display="none";
			    if(document.getElementById(divNFSDefault)!=null) document.getElementById(divNFSDefault).style.display="block";
                isShowTimeDropdown(false);
            }
            else
            {
	                if(document.getElementById(divTravelClass)!=null) document.getElementById(divTravelClass).style.display="block";
	                if(document.getElementById(divDefault)!=null) document.getElementById(divDefault).style.display="none";
				    if(document.getElementById(divNFSDefault)!=null) document.getElementById(divNFSDefault).style.display="block";
	                isShowTimeDropdown(false);
            }
            if(document.getElementById(divSortBy)!=null) document.getElementById(divSortBy).style.display="none";
            if(document.getElementById(divNFSGo)!=null) document.getElementById(divNFSGo).style.display="block";
		} else if (isTransTasmanTrip(region,from,to)) {
            if (document.getElementById('intTripTypeOneWay').checked) {
                if(document.getElementById(divDefault)!=null)document.getElementById(divDefault).style.display="none";
			    if(document.getElementById(divNFSDefault)!=null)document.getElementById(divNFSDefault).style.display="block";
                if(document.getElementById(divTravelClass)!=null)document.getElementById(divTravelClass).style.display="none";
                isShowTimeDropdown(false);
                if(document.getElementById(divSortBy)!=null)document.getElementById(divSortBy).style.display="block";
                if(document.getElementById(divNFSGo)!=null) document.getElementById(divNFSGo).style.display="none";
            } else if (document.getElementById('intTripTypeReturn').checked) {
				if(document.getElementById(divDefault)!=null)document.getElementById(divDefault).style.display="none";
				if(document.getElementById(divNFSDefault)!=null)document.getElementById(divNFSDefault).style.display="block";
				if(document.getElementById(divTravelClass)!=null)document.getElementById(divTravelClass).style.display="none";
				isShowTimeDropdown(false);
				if(document.getElementById(divSortBy)!=null)document.getElementById(divSortBy).style.display="block";
				if(document.getElementById(divNFSGo)!=null) document.getElementById(divNFSGo).style.display="none";
            } else {
                if(document.getElementById(divDefault)!=null)document.getElementById(divDefault).style.display="block";
			    if(document.getElementById(divNFSDefault)!=null)document.getElementById(divNFSDefault).style.display="none";
                if((region.indexOf("au")!=-1))
                {
                    if(document.getElementById(divTravelClass)!=null) document.getElementById(divTravelClass).style.display="none";
                    isShowTimeDropdown(false);
                }
                else
                {
						if(document.getElementById(divTravelClass)!=null) document.getElementById(divTravelClass).style.display="none";
						isShowTimeDropdown(false);
                }
                if(document.getElementById(divSortBy)!=null) document.getElementById(divSortBy).style.display="none";
                if(document.getElementById(divNFSGo)!=null) document.getElementById(divNFSGo).style.display="none";
			}
		} else
        {
            if((region.indexOf("au")!=-1))
            {
                if(document.getElementById(divDefault)!=null)document.getElementById(divDefault).style.display="none";
			    if(document.getElementById(divNFSDefault)!=null)document.getElementById(divNFSDefault).style.display="block";
                if(document.getElementById(divTravelClass)!=null) document.getElementById(divTravelClass).style.display="block";
                isShowTimeDropdown(false);
            }
            else
            {
                if(document.getElementById(divDefault)!=null)document.getElementById(divDefault).style.display="block";
			    if(document.getElementById(divNFSDefault)!=null)document.getElementById(divNFSDefault).style.display="none";
			    if(document.getElementById(divTravelClass)!=null) document.getElementById(divTravelClass).style.display="none";
                isShowTimeDropdown(true);
            }
			
            if(document.getElementById(divSortBy)!=null) document.getElementById(divSortBy).style.display="none";
            if(document.getElementById(divNFSGo)!=null) document.getElementById(divNFSGo).style.display="block";
		}
	} else   if (region.indexOf("eu")!=-1)
    {
             if(document.getElementById(divTravelClass)!=null) document.getElementById(divTravelClass).style.display="block";
             if(document.getElementById(divDefault)!=null) document.getElementById(divDefault).style.display="none";
             if(document.getElementById(divNFSDefault)!=null) document.getElementById(divNFSDefault).style.display="block";
             isShowTimeDropdown(false);
    }
}


/********************************************************************************
 * Name:		isShowTimeDropdown
 *
 * Returns:		void
 *
 * Description:	Function used to show or hide the time dropdowns for departure and destinations
 *
 *******************************************************************************/
function isShowTimeDropdown(value) {
	if(value)
	{
		if(document.getElementById('intDepHour')!=null)document.getElementById('intDepHour').style.visibility="visible";
		if(document.getElementById('intRetHour')!=null)document.getElementById('intRetHour').style.visibility="visible";
	}
	else
	{
		if(document.getElementById('intDepHour')!=null)document.getElementById('intDepHour').style.visibility="hidden";
		if(document.getElementById('intRetHour')!=null)document.getElementById('intRetHour').style.visibility="hidden";
	}
}


/********************************************************************************
 * Name:		isFromToSet
 *
 * Returns:		boolean
 *
 * Description:	Function used to determine if the departue or destination
 *							city has been set.		
 *
 *******************************************************************************/
function isFromToSet(from,to){
	if(from==null||from.length==0||from.indexOf("selectacity")!=-1)return false;
	if(to==null||to.length==0||to.indexOf("selectacity")!=-1)return false;
	return true;
}



/********************************************************************************
* Name:		setFL (set fares list)
*
* Args:		c 	= The fare list values
*				fl 	= The fare list to populate
*
* Returns:		void
*
* Description:	Function is used to set the drop down list box for Trans Tasman flights.
*
*            Variable acronyms - (to keep things short)
*              setFL  = set fare list
*
*				An associative multi dimensional array is used to store the fare list values.
*				The associative array allows us to directly access the fare list values without
*				using an if/else statement. After the list has been created/populated, we
*				reset the selected index to its previous value (current selected index - csi)
*
*
*******************************************************************************/
function setFL(c,fl){
	populateOptions(fl.name,c,'');
}

/**
 * Returns true if the sortby drop down is shown and false otherwise
 */
function hasSortBy(from, to) {
    if ((region == "au" || region == "sp") && isTransTasmanTrip(region, from, to)) {
        if (document.getElementById('intTripTypeOneWay').checked) {
			return true;
        } else if (document.getElementById('intTripTypeReturn').checked) {
			return true;
		}
    }
    return false;
}

/**
 * Opens a help popup depending on the region, and itinerary
 */
function popupHelpLink(from, to) {
	if (isFromToSet(from, to) && isTransTasmanTrip(region, from, to) ) {
		window.open('/info/bookings/help/transTasman/index','Help','width=666,height=550,status=yes,scrollbars=yes,resizable=yes');	
	} else if   (region == "au" ||
                (region=="as" ) ||
                (region=="am" ) ||
                (region=="sp" ) ||
                (region=="eu") ) {
		window.open('/info/bookings/helpInternationalNFS','Help','width=666,height=550,status=yes,scrollbars=yes,resizable=yes');
    } else {
		window.open('/info/bookings/helpInternational','Help','width=666,height=550,status=yes,scrollbars=yes,resizable=yes');
	}
}

