﻿

var selectedTabId = "tab1";     // saves the selected tab id
var oLanguage;
// swaps img from "src" with "altsrc"
// showSelected receives "yes" or "no" - swap image of selected or not selected
function swapImgSrcIF(id, showSelected)
{
	with (document.getElementById(id))
	{
	    if (attributes["selected"].value == showSelected)
	    {
		    var saveSrc = src;
		    src = attributes["altsrc"].value;
		    attributes["altsrc"].value = saveSrc;
		}
	}
}

// shows relevant span and unselects other tabs
function tabClicked(id)
{
    var clickedTab = document.getElementById(id);
    
    if (clickedTab.attributes["selected"].value == "no") // not currently selected tab
    { 
        // show selected tab
        for (var i = 1; i <= 5; i++)
        {
            var span = document.getElementById("tabTr" + i);
            
            if (id.charAt(id.length - 1) == ("" + i))   // hide the tab only if not selected
                span.style.display = "";
            else
                span.style.display = "none";
        }
        
        // unselect other tabs
        swapImgSrcIF(selectedTabId, "yes");
        document.getElementById(selectedTabId).attributes["selected"].value = "no";
        clickedTab.attributes["selected"].value = "yes"
        selectedTabId = id;
     }
}

function arrivalsAndDeparturesClicked(reqType, regionChannel)
{
	// get the select value
	
	var tdSel = document.getElementById("tdSelect");
	var selObj = tdSel.getElementsByTagName("select")[0];
	if(selObj.selectedIndex==0)
		return;
	var selectedVal = selObj.options[selObj.selectedIndex].value;
	//alert(selectedVal);
	// get the radio button value
	/*
	var reqType;
	var rdbDepat = document.getElementById("rdOption1");
	if(rdbDepat.checked)
		reqType = 0;
	else
		reqType = 1;
	*/
	//alert(selectedVal);
	//alert(reqType);
	//alert(regionChannel);	
	window.open(appPath+"/Pages/CmsTemplates/ArrivalsAndDepartures.aspx?airport="+selectedVal+"&reqType="+reqType+"&regionChannel="+regionChannel, "adWindow", "scrollbars=1,resizable=yes,width=720,height=480,top=100,left=100");
	
}

function fillDDdlDest(allDestId,regionChannel)
{
	var AllDestinationSelect = document.getElementById(allDestId);//.getElementsByTagName("select");;
	var arrSelCont = document.getElementById("selContainer").getElementsByTagName("select");

	//var allDest = AllDestinationSelect;
	var selFrom = arrSelCont[0];//document.getElementById("selContainer").childNodes[1];
	var selTo = arrSelCont[1];//document.getElementById("To");
	removeOptionsOutOf1(selTo);
	var oOption,i;
	if (selFrom.options[selFrom.selectedIndex].value!="-1")
	{
	    if(selFrom.options[selFrom.selectedIndex].value == "TLV")
		{	// tel-aviv was select
		   for(i=0; i< AllDestinationSelect.options.length; i++)
			{
			    if(AllDestinationSelect.options[i].value!="TLV")
				{
					var sText = AllDestinationSelect.options[i].text;
                    var sValue = AllDestinationSelect.options[i].value;
					selTo.options[selTo.length] = new Option(sText,sValue);
				}
			}
			if (selTo.options.length > 1)
		    {
			    selTo.options.selectedIndex = 0;
		    }
		}
		else// tel-aviv was not selected
		{
			// add tel aviv
			var tlvStr = document.getElementById("tlvDestenation");
			
			var sText = tlvStr.value;
            var sValue = "TLV";
		    selTo.options[selTo.length] = new Option(sText,sValue);
			if (selTo.options.length > 1)
		    {
			    selTo.options.selectedIndex = 1;
		    }
			
			// los angeles was selected
			if(selFrom.options[selFrom.selectedIndex].value == "LAX")
			{
				// add toronto
				/*oOption = document.createElement("OPTION");
				selTo.options.add(oOption);
				if(regionChannel == "Hebrew")
					oOption.innerText = "טורונטו";
				else if(regionChannel == "English")
					oOption.innerText = "TORONTO";
				oOption.value = "YTO";*/
			}	
			
			 // toronto was selected
			else if(selFrom.options[selFrom.selectedIndex].value == "YTO")
			{
				// add los angeles
				/*oOption = document.createElement("OPTION");
				selTo.options.add(oOption);
				
				if(regionChannel == "Hebrew")
					oOption.innerText = "לוס אנג'לס";
				else if(regionChannel == "English")
					oOption.innerText = "LOS ANGELES";
				oOption.value = "LAX";*/
			}
		}
		/*if (selTo.options.length > 1)
		{
			selTo.options.selectedIndex = 0;
		}
		else
		{
            selTo.options.selectedIndex = 0;
		}*/
	}
	else
	{
	    selTo.options.selectedIndex = 0;
	}
}

function fillScheduleDDdlDest(id)
{
	var arrSelCont = document.getElementById(id).getElementsByTagName("select");
	var selFrom = arrSelCont[0];
	var selTo = arrSelCont[1];
	removeOptionsOutOf1(selTo);
	var oOption,i;

	if (selFrom != null && selTo != null )
	removeOptionsOutOf1(selTo);
	var oOption,i;
	if (selFrom.options[selFrom.selectedIndex].value!="-1")
	{
		if(selFrom.options[selFrom.selectedIndex].value == "TLV")
		{	// tel-aviv was select
			for(i=1; i<selFrom.options.length; i++)
			{
				if(selFrom.options[i].value!="TLV")
				{
                    var sText = selFrom.options[i].text;
                    var sValue = selFrom.options[i].value;
					selTo.options[selTo.length] = new Option(sText,sValue);
				}
			}
		}
		else// tel-aviv was not selected
		{
			// add tel aviv
			var tlvStr = document.getElementById("tlvDestenation");
			var sText = tlvStr.value;
            var sValue = "TLV";
		    selTo.options[selTo.length] = new Option(sText,sValue);
			
			// los angeles was selected
			if(selFrom.options[selFrom.selectedIndex].value == "LAX")
			{
				// add toronto
				var sText = "TORONTO";
                var sValue = "YTO";
		        selTo.options[selTo.length] = new Option(sText,sValue);
			}	
			
			 // toronto was selected
			else if(selFrom.options[selFrom.selectedIndex].value == "YTO")
			{
				// add los angeles
				var sText = "LOS ANGELES";
                var sValue = "LAX";
		        selTo.options[selTo.length] = new Option(sText,sValue);
			}
		}
		if (selTo.options.length > 1)
		{
			selTo.options.selectedIndex = 1;
		}
		else
		{
            selTo.options.selectedIndex = 0;
		}
	}
	else
	{
	    selTo.options.selectedIndex = 0;
	}
}

function removeOptionsOutOf1(sel)
{
	sel.options.length=1;
}	

function changeDivDisplay(div)
{
    if (div && div.style)
    {
        if (div.style.display == "none")
            div.style.display = "";
        else
            div.style.display = "none";
    }
}	

//mouse over the Tabs - change the look
function highlightTab(imgTab)
{
    //set all tabs to Off
    imgTab1 = document.getElementById(oTab1);
    imgTab2 = document.getElementById(oTab2);
    imgTab3 = document.getElementById(oTab3);
    
    if (oLanguage == oHebLang)
    {
        imgTab1.src = imgTab1.src.replace("_hover","");
        imgTab2.src = imgTab2.src.replace("_hover","");
        imgTab3.src = imgTab3.src.replace("_hover","");
        imgTab.src = imgTab.src.replace(".jpg","_hover.jpg");
    }
    else
    {
        imgTab1.src = imgTab1.src.replace("_on","");
        imgTab2.src = imgTab2.src.replace("_on","");
        imgTab3.src = imgTab3.src.replace("_on","");
        imgTab.src = imgTab.src.replace(".jpg","_on.jpg");
    }
}

// when we leave the regions of the SecondTab and ThirdTab we
// we will automaticaly select the first tab
function TabMouseOut()
{
    oFirstTab=document.getElementById(oTab1);
    highlightTab(oFirstTab);
}
