﻿// JScript File
browserCode = GetCurrentBrowserCode(); //alert("your browser is: " + browserCode);
var xmlDocCountries = null;

//hadle onclick for destination part. open destination logic dialog window		
//--<FOR CALENDAR> --------------------------------------------------------------    
    var tmpDate = new Date()
    var maxAvailableDays = 320; 
    var CalS = parseInt(tmpDate.getMonth() + 1).toString() + "/" + tmpDate.getDate() + "/" + tmpDate.getFullYear(); // '12/25/2006'; 
    tmpDate = new Date(tmpDate.setDate(maxAvailableDays))
    var CalE = parseInt(tmpDate.getMonth() + 1).toString() + "/" + tmpDate.getDate() + "/" + tmpDate.getFullYear(); // '01/16/2007';
//--</FOR CALENDAR> --------------------------------

function OpenTripCalendar(obj){
	SC(document.getElementById(obj));
}

function initControl(_baseurl)
{
    var continent = document.getElementById(trips_search_engine + "ddlContinent").value;
    
    if (browserCode == "IE"){
        xmlDocCountries=new ActiveXObject("Microsoft.XMLDOM");
        xmlDocCountries.async="false";
        xmlDocCountries.load(_baseurl + "resources/data/trips/countries.xml");
        LoadCountriesIE(continent);
    }    
    else if (browserCode == "FF"){
        xmlDocCountries = GetStrFromXml(_baseurl + "resources/data/trips/countries.xml");
        LoadCountriesFF(continent);
    }
    
    if (document.getElementById(trips_search_engine + "hiddenCountry").value!='') {
        document.getElementById("ddlCountry").value = document.getElementById(trips_search_engine + "hiddenCountry").value;}
}

function selectedContinentChanged(_baseurl) {
    ClearSelectControl("ddlCountry");
    var continent = document.getElementById(trips_search_engine + "ddlContinent").value;
    if (browserCode == "IE"){
        LoadCountriesIE(continent);
    }    
    else if (browserCode == "FF"){
        if (xmlDocCountries.length == 0) { xmlDocCountries = GetStrFromXml(_baseurl + "resources/data/trips/countries.xml"); }
        LoadCountriesFF(continent);
    }
}

function SetCountry() {
    document.getElementById(trips_search_engine + "hiddenCountry").value = document.getElementById("ddlCountry").value;
}

function LoadCountriesIE(continent){
    InsertOptionsToSelectControlIE("ddlCountry", "", "0", "- הכל -");

	nodeList = xmlDocCountries.selectNodes("/countries/country[continent='"+ continent +"' or " + continent + "='0']");
    if ( nodeList.length > 0){
        for (var i=0 ; i< nodeList.length ; i++ )
            InsertOptionsToSelectControlIE("ddlCountry", "", nodeList[i].selectSingleNode("./code").text, nodeList[i].selectSingleNode("./name").text)
    }
}

function LoadCountriesFF(continent){
    InsertOptionsToSelectControlFF("ddlCountry", "", "0", "- הכל -");
    for(var i=0; i<xmlDocCountries.length; i++){
        if (xmlDocCountries[i].childNodes.length > 0){
          if (xmlDocCountries[i].childNodes[5].childNodes.length > 0) {
            if (xmlDocCountries[i].childNodes[5].firstChild.nodeValue == continent || continent =='0'){
                InsertOptionsToSelectControlFF("ddlCountry", "", xmlDocCountries[i].childNodes[3].firstChild.nodeValue, xmlDocCountries[i].childNodes[1].firstChild.nodeValue);
            }
          }
        }
    }    
}
