/*var openedCardId=new Array()
openedCardId[0]=""

var engineTypes=new Array()
engineTypes[0]="packages";
engineTypes[1]="israel";
engineTypes[2]="flights";
engineTypes[3]="flyanddrive";
engineTypes[4]="regular";
engineTypes[5]="ski";
engineTypes[6]="link_card_1";
engineTypes[7]="link_card_2";
engineTypes[8]="link_card_3";*/




var _cityLoad=new Array();
var windowIsOpend = false;
var LOADING_STR=dic.LOADING_DATA;
var today="";
var CALENDAR_W=409;
var _site_path = path;
var COMPASS_SE_sLoadXMLFromURL = "/DATA/activeDestinationsByCountry.xml";
var cityXML = null;

var tmp_lang = "HE";
try
{
	if (!isnull(lang)) 
	{
		tmp_lang = lang;
		if (lang=="RU" || lang=="PL") tmp_lang = "EN";
	}
}
catch(e)
{
	tmp_lang = "HE";
}

if (tmp_lang=="EN") COMPASS_SE_sLoadXMLFromURL = "/DATA/activeDestinationsByCountry.EN.xml";

function GetActiveDestinations()
{
    if(!cityXML){
        cityXML = $.ajax({
	        type: "GET",
	        url: COMPASS_SE_sLoadXMLFromURL,
	        dataType: "xml",
	        contentType: "text/xml",
	        async: false
        }).responseXML;
    }
}



//************************************************************************************
//** SEARCH ENGINE *******************************************************************

var availableDepartureFlightsDates = {};
var availableReturnFlightsDates = {};
var availableDeparturePackagesDates = {};
var availableReturnPackagesDates = {};
var availableDepartureFlyAndDriveDates = {};
var availableReturnFlyAndDriveDates = {};

function openCardNewIfr(obj,ind){
    var actCard = $(obj)
    $('.se_ifr_main_tabs_content>div').css("display","none");
    $('.se_ifr_main_tabs_content #'+actCard.attr('cardId')).css("display","");
    actCard.parent().find('div.se_ifr_tab_on').attr("class","se_ifr_tab");
    actCard.attr("class","se_ifr_tab_on");

	
}
function openCardMainNew(obj,ind){
    var actCard = $(obj)
    $('.se_ifr_tabs_content>div').css("display","none");
    $('.se_ifr_tabs_content #'+actCard.attr('cardId')).css("display","");
    actCard.parent().find('div.se_ifr_tab_on').attr("class","se_ifr_tab");
    actCard.attr("class","se_ifr_tab_on");
}



function getDepartureSearchEngineDates(_data)
{
    var url = "/site/ajax/calendar/PackagesDepartureDates.asp?pi="+node_pi+"&lang="+lang;
    $.ajax({ 
        type: 'GET', 
        url: url, 
        dataType: 'json', 
        success: function(response) {  
          availableDeparturePackagesDates = response; 
        }, 
        data: _data, 
        async: false 
    }); 
}
function getReturnSearchEngineDates(_data)
{
    var url = "/site/ajax/calendar/PackagesDepartureDates.asp?pi="+node_pi+"&lang="+lang;
    $.ajax({ 
        type: 'GET', 
        url: url, 
        dataType: 'json', 
        success: function(response) {  
          availableReturnPackagesDates = response; 
        }, 
        data: _data, 
        async: false 
    }); 
}


//************************************************************************************
//** SEARCH ENGINE *******************************************************************
function openCardNew(obj){
    var actCard = $(obj)
    $('.se_tabs_content>div').css("display","none");
    $('.se_tabs_content #'+actCard.attr('cardId')).css("display","");
    actCard.parent().find('div.se_ifr_tab_on').attr("class","se_ifr_tab");
    actCard.attr("class","se_ifr_tab_on");
}
function openCardNewSE2(obj){
    var actCard = $(obj)
    $('.se2_tabs_content>div').css("display","none");
    $('.se2_tabs_content #'+actCard.attr('cardId')).css("display","");
    actCard.parent().find('div.se2_ifr_tab_on').attr("class","se2_ifr_tab");
    actCard.attr("class","se2_ifr_tab_on");
}
function SeByDateChangeType(id,act,query,eAct,typ)
{
    $('#query_date'+id).val(query);
    $('#searchFormByDate'+id).attr("action",act);
    $('#emptyAction'+id).val(eAct);
    $('#PackageType_date'+id).val(typ);
}
function SeSearchByDate(dateText, inst,ind)
{
    var emptyAction=$("#emptyAction"+ind).val()
    if(emptyAction=="ISRAEL"){
        $("input[set='Dest_FlightsDate"+ind+"']").val("");
        $("input[set='Dest_FlyanddriveDate"+ind+"']").val("");
    }
    else if(emptyAction=="NOFSHONIM"){
        $("input[set='Dest_FlightsDate"+ind+"']").val("");
        $("input[set='Dest_FlyanddriveDate"+ind+"']").val("");
    }
    else if(emptyAction=="FLIGHTS"){
        $("input[set='Dest_FlyanddriveDate"+ind+"']").val("");
        $("input[set='Dest_PackagesDate"+ind+"']").val("");
    }
    else if(emptyAction=="FLYANDDRIVE"){
        $("input[set='Dest_FlightsDate"+ind+"']").val("");
        $("input[set='Dest_PackagesDate"+ind+"']").val("");
    }
	$("#OutboundDate_Start_date"+ind).val(dateText);
	$("#OutboundDate_End_date"+ind).val(dateText);
	$("#searchFormByDate"+ind).submit();
	return;
}
function SeByPriceChangeType(id,act,query,eAct,typ)
{
    $('#query_price'+id).val(query);
    $('#searchFormByPriceRange'+id).attr("action",act);
    
    //$('#emptyAction'+id).val(eAct);
    $('#PackageType_price'+id).val(typ);
    
    if(eAct=="NOFSHONIM"){
        $('#flyanddriveByPrice'+id).css("display","none");
        $('#flightsByPrice'+id).css("display","none");
        $('#packagesByPrice'+id).css("display","block");
    }
    else if(eAct=="FLIGHTS"){
        $('#flyanddriveByPrice'+id).css("display","none");
        $('#flightsByPrice'+id).css("display","block");
        $('#packagesByPrice'+id).css("display","none");
    }
    else if(eAct=="FLYANDDRIVE"){
        $('#flyanddriveByPrice'+id).css("display","block");
        $('#flightsByPrice'+id).css("display","none");
        $('#packagesByPrice'+id).css("display","none");
    }
}
function SeByDestinationChangeType(id,act,query,eAct,typ)
{
    $('#query_dest'+id).val(query);
    $('#searchFormByDestination'+id).attr("action",act);
    
    //$('#emptyAction'+id).val(eAct);
    $('#PackageType_dest'+id).val(typ);
    
    if(eAct=="NOFSHONIM"){
        $('#flyanddriveByDestionation'+id).css("display","none");
        $('#flightsByDestionation'+id).css("display","none");
        $('#packagesByDestionation'+id).css("display","block");
    }
    else if(eAct=="FLIGHTS"){
        $('#flyanddriveByDestionation'+id).css("display","none");
        $('#flightsByDestionation'+id).css("display","block");
        $('#packagesByDestionation'+id).css("display","none");
    }
    else if(eAct=="FLYANDDRIVE"){
        $('#flyanddriveByDestionation'+id).css("display","block");
        $('#flightsByDestionation'+id).css("display","none");
        $('#packagesByDestionation'+id).css("display","none");
    }
}
function SeSearchByPrice(id,eAct,minprice,maxprice)
{
    if(eAct=="ISRAEL"){
        $("input[set='Dest_FlightsPrice"+id+"']").val("");
        $("input[set='Dest_FlyanddrivePrice"+id+"']").val("");
    }
    else if(eAct=="NOFSHONIM"){
        $("input[set='Dest_FlightsPrice"+id+"']").val("");
        $("input[set='Dest_FlyanddrivePrice"+id+"']").val("");
    }
    else if(eAct=="FLIGHTS"){
        $("input[set='Dest_FlyanddrivePrice"+id+"']").val("");
        $("input[set='Dest_PackagesPrice"+id+"']").val("");
    }
    else if(eAct=="FLYANDDRIVE"){
        $("input[set='Dest_FlightsPrice"+id+"']").val("");
        $("input[set='Dest_PackagesPrice"+id+"']").val("");
    }
	$("#MinFare"+id).val(minprice);
	$("#MaxFare"+id).val(maxprice);
	$("#searchFormByPriceRange"+id).submit();
	return;
}
function SeSearchByDestination(id,destCode)
{
    $("#DestCode_dest"+id).val(destCode);
	$("#searchFormByDestination"+id).submit();
	return;
}
function SeSearchByDestinationFromList(id,prefix)
{
    var destCode = document.getElementById(prefix+id).value;
    if(destCode!='')
    {
        $("#DestCode_dest"+id).val(destCode);
	    $("#searchFormByDestination"+id).submit();
	}
	return;
}
function SeAdvancedChangeType(id,act,query,eAct,typ)
{
     
    if(eAct=="NOFSHONIM"){
        $('#flyanddriveAdvancedSearchCont'+id).css("display","none");
        $('#flightsAdvancedSearchCont'+id).css("display","none");
        $('#packagesAdvancedSearchCont'+id).css("display","block");
    }
    else if(eAct=="FLIGHTS"){
        $('#flyanddriveAdvancedSearchCont'+id).css("display","none");
        $('#flightsAdvancedSearchCont'+id).css("display","block");
        $('#packagesAdvancedSearchCont'+id).css("display","none");
    }
    else if(eAct=="FLYANDDRIVE"){
        $('#flyanddriveAdvancedSearchCont'+id).css("display","block");
        $('#flightsAdvancedSearchCont'+id).css("display","none");
        $('#packagesAdvancedSearchCont'+id).css("display","none");
    }
}


function InitSearchEngineFlights(id)
{
    
    
    $(".se_adv_flights_outdate input").val("");
    $(".se_adv_flights_indate input").val("");
    
    FillFlightsCountriesList('countriesSelect_fse'+id,id);

}
function InitSearchEngineFlightsSE2(id)
{
    $(".se2_packages_outdate input").val("");
    $(".se2_packages_indate input").val("");
    
    FillFlightsCountriesList('countriesSelect_fse'+id,id);

}
function InitInnerSearchEngineFlights(id)
{
    $(".fse_adv_flights_outdate input").val("");
    $(".fse_adv_flights_indate input").val("");
    
    FillFlightsCountriesList('countriesSelect_fse'+id,id);
 
}
function InitSearchEnginePackages(id)
{
    $(".se_adv_packages_outdate input").val("");
    $(".se_adv_packages_indate input").val("");
    
    FillPackagesCountriesList('countriesSelect_pse'+id,id);
    
    
}
function InitSearchEngineSki(id)
{
    $(".se_adv_packages_outdate input").val("");
    $(".se_adv_packages_indate input").val("");
    
    FillSkiCountriesList('countriesSelect_pse'+id,id);
    
    
}
function InitSearchEngineIsrael(id)
{
    $(".se_adv_packages_outdate input").val("");
    $(".se_adv_packages_indate input").val("");
    
    FillIsraelCountriesList('countriesSelect_pse'+id,id);
    
    
}
function InitSearchEnginePackagesSE2(id)
{
    $(".se2_packages_indate input").val("");
    $(".se2_packages_outdate input").val("");
    
    FillPackagesCountriesList('countriesSelect_pse'+id,id);
    
    
}
function InitSearchEngineToursSE2(id)
{
    $(".se2_packages_indate input").val("");
    $(".se2_packages_outdate input").val("");
    
    FillPackagesCountriesListTours('countriesSelect_pse'+id,id);
    
    
}
function InitSearchEngineSkiSE2(id)
{
    $(".se2_packages_indate input").val("");
    $(".se2_packages_outdate input").val("");
    
    FillPackagesCountriesListSki('countriesSelect_pse'+id,id);
    
    
}
function InitSearchEngineTours(id)
{
    $(".pse_adv_flights_outdate input").val("");
    $(".pse_adv_flights_indate input").val("");
    
    FillPackagesCountriesListTours('countriesSelect_pse'+id,id);
    
    
}

function InitInnerSearchEnginePackages(id,isIsrael)
{
    $(".pse_adv_flights_outdate input").val("");
    $(".pse_adv_flights_indate input").val("");
    
    var isFlyAndDrive = false;
    var obj = document.getElementById('PackageType_'+id)
    
    EmptyCitiesList("citiesSelect_pse"+id,id)
    
    if(isIsrael)
    {
        FillIsraelCountriesList('countriesSelect_pse'+id,id);
    }
    else
    {
        FillPackagesCountriesList('countriesSelect_pse'+id,id,(obj && obj.value=="FLY_AND_DRIVE"));
    }
    
    
}
function InitSearchEngineFlyAndDrive(id)
{
    $(".se_adv_flyanddrive_outdate input").val("");
    $(".se_adv_flyanddrive_indate input").val("");
    
    FillFlyAndDriveCountriesList('countriesSelect_pse'+id,id);
        
   
}
function InitSearchEngineFlyAndDriveSE2(id)
{
    $(".se2_packages_outdate input").val("");
    $(".se2_packages_indate input").val("");
    
    FillFlyAndDriveCountriesList('countriesSelect_pse'+id,id);
        
   
}

//************************************************************************************
//** DESTINATIONS *******************************************************************
function checkIfTypeInListOfTours(s)
{
    var toursstr= "ORG TOUR Schedule Flight|ORGANIZED TOUR|ORGANIZED TOUR Open Jaw";
    var arr = toursstr.split("|")
	
    var res = false;
    if(isnull(s) || arr.length==0) return res;
    
    for(var i =0 ; i < arr.length; i++)
    {
        if(s.indexOf("|"+arr[i]+"|")>-1)
        {
            res = true;
            break;
        }
    }    
    return res
}
function checkIfTypeInListOfSki(s)
{
    var skistr= "SKI|SKI FAMILY";
    var arr = skistr.split("|")
	
    var res = false;
    if(isnull(s) || arr.length==0) return res;
    
    for(var i =0 ; i < arr.length; i++)
    {
        if(s.indexOf("|"+arr[i]+"|")>-1)
        {
            res = true;
            break;
        }
    }    
    return res
}
function FillCitiesListTours(id,ind,xpath)
{
    GetActiveDestinations();
    if(cityXML)
    {
        var cityes = $(cityXML).find(xpath)
	    if(cityes)
	    {
	        var select = document.getElementById(id);
	        if(select)
	        {
	            var count=1
	            select.length=cityes.length+1;
	            select[0].selected=true;
	            for(var i=0;i<cityes.length;i++)
	            {
	                //alert("FillCitiesList : for : " + i);
	                if(checkIfTypeInListOfTours($(cityes[i]).attr("PackageType")))
	                {
		                select[count].text=$(cityes[i]).attr(tmp_lang)
		                select[count].value=$(cityes[i]).attr("Code")
		                count++;
		            }
	            }
		    }
	    }
    }
}
function FillCitiesListSki(id,ind,xpath)
{
    GetActiveDestinations();
    if(cityXML)
    {
        var cityes = $(cityXML).find(xpath)
	    if(cityes)
	    {
	        var select = document.getElementById(id);
	        if(select)
	        {
	            var count=1
	            select.length=cityes.length+1;
	            select[0].selected=true;
	            for(var i=0;i<cityes.length;i++)
	            {
	                //alert("FillCitiesList : for : " + i);
	                if(checkIfTypeInListOfSki($(cityes[i]).attr("PackageType")))
	                {
		                select[count].text=$(cityes[i]).attr(tmp_lang)
		                select[count].value=$(cityes[i]).attr("Code")
		                count++;
		            }
	            }
	            
	            select.length=count;
		    }
	    }
    }
}
function FillCountriesListTours(id,ind,xpath)
{
    
     
    GetActiveDestinations();
    if(cityXML)
    {
        var countries = $(cityXML).find(xpath)
	    if(countries)
	    {
	        var select = document.getElementById(id);
	        if(select)
	        {
	            var count=1
	            select.length=countries.length+1;
		        select[0].selected=true;
		        for(var i=0;i<countries.length;i++)
		        {
		            var cities = $(countries[i]).find("City[p='1']")
		            if(cities)
		            {
		                var _isTour = false;
		                for(var j = 0; j < cities.length; j++)
		                {
		                    if(checkIfTypeInListOfTours($(cities[j]).attr("PackageType"))){
			                    _isTour = true;
				                break;
			                }
		                }
		                
		                if(_isTour)
		                {
		                    select[count].text=$(countries[i]).attr(tmp_lang);
			                select[count].value=$(countries[i]).attr("EN");
			                count++;
		                }
		            }
		            
		        }
		    }
	    }
    }
}
function FillCountriesListSki(id,ind,xpath)
{
    
     
    GetActiveDestinations();
    if(cityXML)
    {
        var countries = $(cityXML).find(xpath)
	    if(countries)
	    {
	        var select = document.getElementById(id);
	        if(select)
	        {
	            var count=1
	            select.length=countries.length+1;
		        select[0].selected=true;
		        for(var i=0;i<countries.length;i++)
		        {
		            var cities = $(countries[i]).find("City[p='1']")
		            if(cities)
		            {
		                var _isSki = false;
		                for(var j = 0; j < cities.length; j++)
		                {
		                    if(checkIfTypeInListOfSki($(cities[j]).attr("PackageType"))){
			                    _isSki = true;
				                break;
			                }
		                }
		                
		                if(_isSki)
		                {
		                    select[count].text=$(countries[i]).attr(tmp_lang);
			                select[count].value=$(countries[i]).attr("EN");
			                count++;
		                }
		            }
		            
		        }
		        select.length=count;
		    }
	    }
    }
}
function FillPackagesCountriesListTours(id,ind)
{
    
    var xpath = "Country[EN!='ISRAEL']:has(City[p='1'])";
    FillCountriesListTours(id,ind,xpath);
}
function FillPackagesCountriesListSki(id,ind)
{
    
    var xpath = "Country[EN!='ISRAEL']:has(City[p='1'])";
    FillCountriesListSki(id,ind,xpath);
}
function FillSkiCountriesList(id,ind)
{
    
    var xpath = "Country[EN!='ISRAEL']:has(City[p='1'])";
    FillCountriesListSki(id,ind,xpath);
}

function FillPackagesCountriesList(id,ind,isFlyAndDrive)
{
    
    var xpath = "Country[EN!='ISRAEL']:has(City[p='1'])";
    if(isFlyAndDrive)
    {
        var xpath = "Country[EN!='ISRAEL']:has(City[p='1'][FlyAndDrive='1'])";
    }
    FillCountriesList(id,ind,xpath);
}
function FillIsraelCountriesList(id,ind)
{
    
    var xpath = "Country[EN='ISRAEL']:has(City[p='1'])";

    FillCountriesList(id,ind,xpath);
}
function FillFlightsCountriesList(id,ind)
{
    var xpath = "Country[EN!='ISRAEL']:has(City[f='1'])";
    FillCountriesList(id,ind,xpath);
}
function FillFlyAndDriveCountriesList(id,ind)
{
    var xpath = "Country[EN!='ISRAEL']:has(City[p='1'][FlyAndDrive='1'])";
    FillCountriesList(id,ind,xpath)
}
function FillCountriesList(id,ind,xpath)
{
    GetActiveDestinations();
    if(cityXML)
    {
        var countries = $(cityXML).find(xpath)
	    if(countries)
	    {
	        var select = document.getElementById(id);
	        if(select)
	        {
	            select.length=countries.length+1;
		        select[0].selected=true;
		        for(var i=0;i<countries.length;i++)
		        {
			        select[i+1].text=$(countries[i]).attr(tmp_lang);
			        select[i+1].value=$(countries[i]).attr("EN");
		        }
		    }
	    }
    }
}
function FillPackagesCitiesList(id,ind)
{
    $(".se_adv_packages_outdate input").val("");
    $(".se_adv_packages_indate input").val("");
    
    var countryCode = document.getElementById(id).value;
    
    if(countryCode!="")
    {
        var xpath = "Country[EN='"+countryCode+"'] > City[p='1']";
        FillCitiesList("citiesSelect_pse"+ind,ind,xpath);
    }
    else
    {
        EmptyCitiesList("citiesSelect_pse"+ind,ind)
    }
}
function FillSkiCitiesList(id,ind)
{
    $(".se_adv_packages_outdate input").val("");
    $(".se_adv_packages_indate input").val("");
    
    var countryCode = document.getElementById(id).value;
    
    if(countryCode!="")
    {
        var xpath = "Country[EN='"+countryCode+"'] > City[p='1']";
        FillCitiesListSki("citiesSelect_pse"+ind,ind,xpath);
    }
    else
    {
        EmptyCitiesList("citiesSelect_pse"+ind,ind)
    }
}
function FillPackagesCitiesListSE2(id,ind)
{
    $(".se2_packages_outdate input").val("");
    $(".se2_packages_indate input").val("");
    
    var countryCode = document.getElementById(id).value;
    
    if(countryCode!="")
    {
        var xpath = "Country[EN='"+countryCode+"'] > City[p='1']";
        FillCitiesList("citiesSelect_pse"+ind,ind,xpath);
    }
    else
    {
        EmptyCitiesList("citiesSelect_pse"+ind,ind)
    }
}

function FillPackagesCitiesListToursSE2(id,ind)
{
    $(".se2_packages_outdate input").val("");
    $(".se2_packages_indate input").val("");
    
    var countryCode = document.getElementById(id).value;
    
    if(countryCode!="")
    {
        var xpath = "Country[EN='"+countryCode+"'] > City[p='1']";
        FillCitiesListTours("citiesSelect_pse"+ind,ind,xpath);
    }
    else
    {
        EmptyCitiesList("citiesSelect_pse"+ind,ind)
    }
}
function FillPackagesCitiesListSkiSE2(id,ind)
{
    $(".se2_packages_outdate input").val("");
    $(".se2_packages_indate input").val("");
    
    var countryCode = document.getElementById(id).value;
    
    if(countryCode!="")
    {
        var xpath = "Country[EN='"+countryCode+"'] > City[p='1']";
        FillCitiesListSki("citiesSelect_pse"+ind,ind,xpath);
    }
    else
    {
        EmptyCitiesList("citiesSelect_pse"+ind,ind)
    }
}
function FillPackagesCitiesListTours(id,ind)
{
    $(".pse_adv_flights_outdate input").val("");
    $(".pse_adv_flights_indate input").val("");
    
    var countryCode = document.getElementById(id).value;
    
    if(countryCode!="")
    {
        var xpath = "Country[EN='"+countryCode+"'] > City[p='1']";
        FillCitiesListTours("citiesSelect_pse"+ind,ind,xpath);
    }
    else
    {
        EmptyCitiesList("citiesSelect_pse"+ind,ind)
    }
}
function FillInnerPackagesCitiesList(id,ind)
{
    $(".pse_adv_flights_outdate input").val("");
    $(".pse_adv_flights_indate input").val("");
    
    var countryCode = document.getElementById(id).value;
    
    if(countryCode!="")
    {
        var xpath = "Country[EN='"+countryCode+"'] > City[p='1']";
        
        var isFlyAndDrive = false;
        var obj = document.getElementById('PackageType_'+id)
        if(obj && obj.value=="FLY_AND_DRIVE")
        {
            var xpath = "Country[EN='"+countryCode+"'] > City[p='1'][FlyAndDrive='1']";
        }
       
        
        FillCitiesList("citiesSelect_pse"+ind,ind,xpath);
    }
    else
    {
        EmptyCitiesList("citiesSelect_pse"+ind,ind)
    }
}
function FillFlightsCitiesList(id,ind)
{
    $(".se_adv_flights_outdate input").val("");
    $(".se_adv_flights_indate input").val("");
    
    var countryCode = document.getElementById(id).value;
    if(countryCode!="")
    {
        var xpath = "Country[EN='"+countryCode+"'] > City[f='1']";
        FillCitiesList("citiesSelect_fse"+ind,ind,xpath);
    }
    else
    {
        EmptyCitiesList("citiesSelect_fse"+ind,ind)
    }
}
function FillFlightsCitiesListSE2(id,ind)
{
    $(".se2_packages_outdate input").val("");
    $(".se2_packages_indate input").val("");
    
    var countryCode = document.getElementById(id).value;
    if(countryCode!="")
    {
        var xpath = "Country[EN='"+countryCode+"'] > City[f='1']";
        FillCitiesList("citiesSelect_fse"+ind,ind,xpath);
    }
    else
    {
        EmptyCitiesList("citiesSelect_fse"+ind,ind)
    }
}
function FillInnerFlightsCitiesList(id,ind)
{
    $(".fse_adv_flights_outdate input").val("");
    $(".fse_adv_flights_indate input").val("");
    
    var countryCode = document.getElementById(id).value;
    if(countryCode!="")
    {
        var xpath = "Country[EN='"+countryCode+"'] > City[f='1']";
        FillCitiesList("citiesSelect_fse"+ind,ind,xpath);
    }
    else
    {
        EmptyCitiesList("citiesSelect_fse"+ind,ind)
    }
}
function FillFlyAndDriveCitiesList(id,ind)
{
    $(".se_adv_flyanddrive_outdate input").val("");
    $(".se_adv_flyanddrive_indate input").val("");
    
    var countryCode = document.getElementById(id).value;
    if(countryCode!="")
    {
        var xpath = "Country[EN='"+countryCode+"'] > City[p='1'][FlyAndDrive='1']";
        FillCitiesList("citiesSelect_pse"+ind,ind,xpath);
    }
    else
    {
        EmptyCitiesList("citiesSelect_pse"+ind,ind)
    }
}
function FillFlyAndDriveCitiesListSE2(id,ind)
{
    $(".se2_packages_outdate input").val("");
    $(".se2_packages_indate input").val("");
    
    var countryCode = document.getElementById(id).value;
    if(countryCode!="")
    {
        var xpath = "Country[EN='"+countryCode+"'] > City[p='1'][FlyAndDrive='1']";
        FillCitiesList("citiesSelect_pse"+ind,ind,xpath);
    }
    else
    {
        EmptyCitiesList("citiesSelect_pse"+ind,ind)
    }
}
function FillCitiesList(id,ind,xpath)
{
    GetActiveDestinations();
    if(cityXML)
    {
        var cityes = $(cityXML).find(xpath)
	    if(cityes)
	    {
	        var select = document.getElementById(id);
	        if(select)
	        {
	            select.length=cityes.length+1;
	            select[0].selected=true;
	            for(var i=0;i<cityes.length;i++)
	            {
	                //alert("FillCitiesList : for : " + i);
		            select[i+1].text=$(cityes[i]).attr(tmp_lang)
		            select[i+1].value=$(cityes[i]).attr("Code")
	            }
		    }
	    }
    }
}
function EmptyCitiesList(id,ind)
{
    var select = document.getElementById(id);
    if(select)
    {
        select.length=1;
        select[0].selected=true;
        
    }
}

function FillPackagesOutDates(id,ind)
{
    var cityCode = document.getElementById("citiesSelect_pse"+ind).value;
    $(".se_adv_packages_outdate input").val("");
    $(".se_adv_packages_indate input").val("");
}
function FillSkiOutDates(id,ind)
{
    var cityCode = document.getElementById("citiesSelect_pse"+ind).value;
    $(".se_adv_packages_outdate input").val("");
    $(".se_adv_packages_indate input").val("");
}
function FillInnerPackagesOutDates(id,ind)
{
    var cityCode = document.getElementById("citiesSelect_pse"+ind).value;
    $(".pse_adv_flights_outdate input").val("");
    $(".pse_adv_flights_indate input").val("");
}
function FillFlightsOutDates(id,ind)
{
    var cityCode = document.getElementById("citiesSelect_fse"+ind).value;
    $(".se_adv_flights_outdate input").val("");
    $(".se_adv_flights_indate input").val("");
}
function FillInnerFlightsOutDates(id,ind)
{
    var cityCode = document.getElementById("citiesSelect_fse"+ind).value;
    $(".fse_adv_flights_outdate input").val("");
    $(".fse_adv_flights_indate input").val("");
}
function FillFlyAndDriveOutDates(id,ind)
{
    var cityCode = document.getElementById("citiesSelect_pse"+ind).value;
    $(".se_adv_flyanddrive_outdate input").val("");
    $(".se_adv_flyanddrive_indate input").val("");
}


function FillPackagesInDates(id,ind)
{
    $(".se_adv_packages_indate input").val("");
}
function FillFlightsInDates(id,ind)
{
    $(".se_adv_flights_indate input").val("");
}
function FillFlyAndDriveInDates(id,ind)
{
    $(".se_adv_flyanddrive_indate input").val("");
}




function countProperties(obj) {
  var prop;
  var propCount = 0;
  
  for (prop in obj) {
    propCount++;
  }
  return propCount;
}
function firstProperty(obj) {
  var prop;
  var firstProp = "";
  
  for (prop in obj) {
    if(firstProp=="") firstProp = prop;
    break;
  }
  return firstProp;
}




var FlightOutboundDate = {}
var FlightOutboundDateID = ""
var FlightInboundDate = {}
var FlightInboundDateID = ""

var PackageOutboundDate = {}
var PackageOutboundDateID = ""
var PackageInboundDate = {}
var PackageInboundDateID = ""

function GetFlightOutboundDate(id,citiesid,outdateid,indateid)
{
    //alert("GetFlightOutboundDate")
    var oCity = document.getElementById(citiesid);
    var oInDate = document.getElementById(indateid);
    if(oCity && oCity.value == "")
    {
        alert(dic.NOT_DESTINATION)
        return;
    }
    
    FlightOutboundDate = {};
    FlightOutboundDateID = outdateid;
    if(oInDate)
    {
        oInDate.value="";
    }
    
    $(".calendar_se_calendar").datepicker("destroy");
    $(".calendar_se_calendar").html("");
    $(".calendar_se_popup").dialog("destroy");
    $(".calendar_se_popup").dialog({
        autoOpen: true,
        modal: true,
        title: dic.CHOOSE_EXIT_DATE,
        width: 530,
        height: 350,
        resizable: false,
        draggable: false,
        onClose: function(){
            $(".calendar_se_loading").css("display","none");
        }
    });
    $(".calendar_se_loading").css("display","block");
    
    var data = {};
    $('#form_fse' + id + ' input').each(function(){
        var n = $(this).attr("name");
        if(!isnull(n))
        {
            data[n] = $(this).val()
        }
    });
    data["DestCode"] = oCity.value
    //alert(data.length)
    var postData=[]
	for(var x in data){
	    postData.push(x+"="+data[x]);
	}
    
    $.ajax({
		type: "GET",
		url: "/Site/Ajax/Calendar/FlightsDepartureDates.asp?pi=" + node_pi + "&id="+id + "&",// + "&r=" + Math.random(),
		cache: true,
		data: postData.join("&"),
		dataType: 'json', 
        timeout: 20000,
		error: function(XMLHttpRequest, textStatus, errorThrown){
		    $(".calendar_se_loading").css("display","none");
		    $(".calendar_se_calendar").datepicker("destroy");
            $(".calendar_se_calendar").html(dic['LOADING_DATA_ERROR']);
            FlightOutboundDate = {}
			//alert('error : ' + textStatus + " : " + errorThrown);
		},
		success: function(data, textStatus){
		    //alert(countProperties(data))
		    //alert($.datepicker.formatDate('yy-mm-dd', firstProperty(data)))
		    if(countProperties(data)==0)
		    {
		        $(".calendar_se_loading").css("display","none");
		        $(".calendar_se_calendar").datepicker("destroy");
                $(".calendar_se_calendar").html(dic['LOADING_DATA_ERROR']);
		    }
		    else
		    {
		        FlightOutboundDate = data
		        $(".calendar_se_loading").css("display","none");
		        $(".calendar_se_calendar").datepicker("destroy");
		        $('.calendar_se_calendar').datepicker({
	                minDate: $.datepicker.parseDate('yy-mm-dd', firstProperty(data)),
                    maxDate: '+12m',
                    numberOfMonths: 2,
                    onSelect: function(dateText, inst){
                        $('#'+FlightOutboundDateID).val(dateText);
                        $(".calendar_se_popup").dialog("close");
                    },
                    beforeShowDay: function(date) { 
                        //show only available dates
                        try{
                            if (FlightOutboundDate[$.datepicker.formatDate('yy-mm-dd', date)]) { 
                                return [true]; 
                            } else { 
                                return [false]; 
                            } 
                        }
                        catch(e){}
                        
                        return [false];
                        
                    }
	            });
	         }
	        //alert("data : " + data);
		    
		    
		    
		}
	})
    
    
    
}
function GetFlightInboundDate(id,citiesid,outdateid,indateid)
{
    var oCity = document.getElementById(citiesid);
    var oOutDate = document.getElementById(outdateid);
    if(oCity && oCity.value == "")
    {
        alert(dic.NOT_DESTINATION)
        return;
    }
    else if(oOutDate && oOutDate.value == "")
    {
        alert(dic.CHOOSE_EXIT_DATE)
        return;
    }
    
    FlightInboundDate = {};
    FlightInboundDateID = indateid;
    
    
    $(".calendar_se_calendar").datepicker("destroy");
    $(".calendar_se_calendar").html("");
    $(".calendar_se_popup").dialog("destroy");
    $(".calendar_se_popup").dialog({
        autoOpen: true,
        modal: true,
        title: dic.CHOOSE_RETURN_DATE,
        width: 530,
        height: 350,
        resizable: false,
        draggable: false,
        onClose: function(){
            $(".calendar_se_loading").css("display","none");
        }
    });
    $(".calendar_se_loading").css("display","block");
    
    var data = {};
    $('#form_fse' + id + ' input').each(function(){
        var n = $(this).attr("name");
        if(!isnull(n))
        {
            data[n] = $(this).val()
        }
    });
    data["DestCode"] = oCity.value
    data["OutboundDate"] = oOutDate.value
    //alert(data.length)
    var postData=[]
	for(var x in data){
	    postData.push(x+"="+data[x]);
	}
    
    $.ajax({
		type: "GET",
		url: "/Site/Ajax/Calendar/FlightsReturnDates.asp?pi=" + node_pi + "&id="+id + "&",// + "&r=" + Math.random(),
		cache: true,
		data: postData.join("&"),
		dataType: 'json', 
        timeout: 20000,
		error: function(XMLHttpRequest, textStatus, errorThrown){
		    $(".calendar_se_loading").css("display","none");
		    $(".calendar_se_calendar").datepicker("destroy");
            $(".calendar_se_calendar").html(dic['LOADING_DATA_ERROR']);
            FlightInboundDate = {}
			//alert('error : ' + textStatus + " : " + errorThrown);
		},
		success: function(data, textStatus){
		    if(countProperties(data)==0)
		    {
		        $(".calendar_se_loading").css("display","none");
		        $(".calendar_se_calendar").datepicker("destroy");
                $(".calendar_se_calendar").html(dic['LOADING_DATA_ERROR']);
		    }
		    else
		    {
		        FlightInboundDate = data
		        $(".calendar_se_loading").css("display","none");
		        $(".calendar_se_calendar").datepicker("destroy");
		        $('.calendar_se_calendar').datepicker({
	                minDate: $.datepicker.parseDate('yy-mm-dd', firstProperty(data)),
                    maxDate: '+12m',
                    numberOfMonths: 2,
                    onSelect: function(dateText, inst){
                        $('#'+FlightInboundDateID).val(dateText);
                        $(".calendar_se_popup").dialog("close");
                    },
                    beforeShowDay: function(date) { 
                        //show only available dates
                        try{
                            if (FlightInboundDate[$.datepicker.formatDate('yy-mm-dd', date)]) { 
                                return [true]; 
                            } else { 
                                return [false]; 
                            } 
                        }
                        catch(e){}
                        
                        return [false];
                        
                    }
	            });
	        }
	        //alert("data : " + data);
		    
		    
		    
		}
	})
}

function GetPackageOutboundDate(id,citiesid,outdateid,indateid)
{
    //alert("GetFlightOutboundDate")
    var oCity = document.getElementById(citiesid);
    var oInDate = document.getElementById(indateid);
    if(oCity && oCity.value == "")
    {
        alert(dic.NOT_DESTINATION)
        return;
    }
    
    PackageOutboundDate = {};
    PackageOutboundDateID = outdateid;
    if(oInDate)
    {
        oInDate.value="";
    }
    
    $(".calendar_se_calendar").datepicker("destroy");
    $(".calendar_se_calendar").html("");
    $(".calendar_se_popup").dialog("destroy");
    $(".calendar_se_popup").dialog({
        autoOpen: true,
        modal: true,
        title: dic.CHOOSE_EXIT_DATE,
        width: 530,
        height: 350,
        resizable: false,
        draggable: false,
        onClose: function(){
            $(".calendar_se_loading").css("display","none");
        }
    });
    $(".calendar_se_loading").css("display","block");
    
    var data = {};
    $('#form_pse' + id + ' input').each(function(){
        var n = $(this).attr("name");
        if(!isnull(n))
        {
            data[n] = $(this).val()
        }
    });
    data["DestCode"] = oCity.value
    var oPackageType = document.getElementById("PackageType_"+id)
    if(oPackageType && oPackageType.value != "")
    {
        data["PackageType"] = oPackageType.value
    }
    //alert(data.length)
    var postData=[]
	for(var x in data){
	    postData.push(x+"="+data[x]);
	}
    
    $.ajax({
		type: "GET",
		url: "/Site/Ajax/Calendar/PackagesDepartureDates.asp?pi=" + node_pi + "&id="+id + "&",// + "&r=" + Math.random(),
		cache: true,
		data: postData.join("&"),
		dataType: 'json', 
        	timeout: 20000,
		error: function(XMLHttpRequest, textStatus, errorThrown){
//alert("error : " + textStatus)
			$(".calendar_se_loading").css("display","none");
			$(".calendar_se_calendar").datepicker("destroy");
			$(".calendar_se_calendar").html(dic['LOADING_DATA_ERROR']);
			PackageOutboundDate = {}
			//alert('error : ' + textStatus + " : " + errorThrown);
		},
		success: function(data, textStatus){
		    if(countProperties(data)==0)
		    {
		        $(".calendar_se_loading").css("display","none");
		        $(".calendar_se_calendar").datepicker("destroy");
                        $(".calendar_se_calendar").html(dic['LOADING_DATA_ERROR']);
		    }
		    else
		    {
		        PackageOutboundDate = data
		        $(".calendar_se_loading").css("display","none");
		        $(".calendar_se_calendar").datepicker("destroy");
		        $('.calendar_se_calendar').datepicker({
	                minDate: $.datepicker.parseDate('yy-mm-dd', firstProperty(data)),
                    maxDate: '+12m',
                    numberOfMonths: 2,
                    onSelect: function(dateText, inst){
                        $('#'+PackageOutboundDateID).val(dateText);
                        $(".calendar_se_popup").dialog("close");
                    },
                    beforeShowDay: function(date) { 
                        //show only available dates
                        try{
                            if (PackageOutboundDate[$.datepicker.formatDate('yy-mm-dd', date)]) { 
                                return [true]; 
                            } else { 
                                return [false]; 
                            } 
                        }
                        catch(e){}
                        
                        return [false];
                        
                    }
	            });
	        }
	        //alert("data : " + data);
		    
		    
		    
		}
	})
    
}
function GetPackageInboundDate(id,citiesid,outdateid,indateid)
{
    var oCity = document.getElementById(citiesid);
    var oOutDate = document.getElementById(outdateid);
    if(oCity && oCity.value == "")
    {
        alert(dic.NOT_DESTINATION)
        return;
    }
    else if(oOutDate && oOutDate.value == "")
    {
        alert(dic.CHOOSE_EXIT_DATE)
        return;
    }
    
    PackageInboundDate = {};
    PackageInboundDateID = indateid;
    
    
    $(".calendar_se_calendar").datepicker("destroy");
    $(".calendar_se_calendar").html("");
    $(".calendar_se_popup").dialog("destroy");
    $(".calendar_se_popup").dialog({
        autoOpen: true,
        modal: true,
        title: dic.CHOOSE_RETURN_DATE,
        width: 530,
        height: 350,
        resizable: false,
        draggable: false,
        onClose: function(){
            $(".calendar_se_loading").css("display","none");
        }
    });
    $(".calendar_se_loading").css("display","block");
    
    var data = {};
    $('#form_pse' + id + ' input').each(function(){
        var n = $(this).attr("name");
        if(!isnull(n))
        {
            data[n] = $(this).val()
        }
    });
    data["DestCode"] = oCity.value
    data["OutboundDate"] = oOutDate.value
    var oPackageType = document.getElementById("PackageType_"+id)
    if(oPackageType && oPackageType.value != "")
    {
        data["PackageType"] = oPackageType.value
    }
    //alert(data.length)
    var postData=[]
	for(var x in data){
	    postData.push(x+"="+data[x]);
	}
    
    $.ajax({
		type: "GET",
		url: "/Site/Ajax/Calendar/PackagesReturnDates.asp?pi=" + node_pi + "&id="+id + "&",// + "&r=" + Math.random(),
		cache: true,
		data: postData.join("&"),
		dataType: 'json', 
        timeout: 20000,
		error: function(XMLHttpRequest, textStatus, errorThrown){
		    $(".calendar_se_loading").css("display","none");
		    $(".calendar_se_calendar").datepicker("destroy");
            $(".calendar_se_calendar").html(dic['LOADING_DATA_ERROR']);
            PackageInboundDate = {}
			//alert('error : ' + textStatus + " : " + errorThrown);
		},
		success: function(data, textStatus){
		    if(countProperties(data)==0)
		    {
		        $(".calendar_se_loading").css("display","none");
		        $(".calendar_se_calendar").datepicker("destroy");
                $(".calendar_se_calendar").html(dic['LOADING_DATA_ERROR']);
		    }
		    else
		    {
		        PackageInboundDate = data
		        $(".calendar_se_loading").css("display","none");
		        $(".calendar_se_calendar").datepicker("destroy");
		        $('.calendar_se_calendar').datepicker({
	                minDate: $.datepicker.parseDate('yy-mm-dd', firstProperty(data)),
                    maxDate: '+12m',
                    numberOfMonths: 2,
                    onSelect: function(dateText, inst){
                        $('#'+PackageInboundDateID).val(dateText);
                        $(".calendar_se_popup").dialog("close");
                    },
                    beforeShowDay: function(date) { 
                        //show only available dates
                        try{
                            if (PackageInboundDate[$.datepicker.formatDate('yy-mm-dd', date)]) { 
                                return [true]; 
                            } else { 
                                return [false]; 
                            } 
                        }
                        catch(e){}
                        
                        return [false];
                        
                    }
	            });
	        }
	        //alert("data : " + data);
		    
		    
		    
		}
	})
}






/****************************************/







function emptyList(id){
	var coll=document.getElementById(id)
	if(!coll || coll.length==0) return
	for(var i=0;i<coll.length;i++){
		coll[i].value=""
		coll[i].name=""
	}
}

function goToFlightPriceTemplate(id,module){ goToPriceTemplate(id,false,module);}

function goToPackagePriceTemplate(id,module){ goToPriceTemplate(id,true,module);}

function goToPriceTemplate(id,bPackages,module){
	var viewIn = ""
	if(document.getElementById('view_in_'+id)) viewIn = document.getElementById('view_in_'+id).value;
	
	var oInFlightID=document.getElementById('InFlightID_'+id)
	if(isnull(oInFlightID.value)){
		alert(dic.CHOOSE_RETURN_DATE)
		return
	}
	with(document){
		switch(module){
			case "FLIGHTS":
				isnull(viewIn)?tempAction=flights_action:tempAction=(pagePath+"?pi="+viewIn);	
				getElementById('detailsForm_'+id).action=tempAction;
				break;
			case "ISRAEL":
				isnull(viewIn)?tempAction=israel_action:tempAction=(pagePath+"?pi="+viewIn);	
				getElementById('detailsForm_'+id).action=tempAction;
				break;
			case "PACKAGES":
				isnull(viewIn)?tempAction=packages_action:tempAction=(pagePath+"?pi="+viewIn);	
				getElementById('detailsForm_'+id).action=tempAction;
				break;	
			default:
				getElementById('detailsForm_'+id).action=''
		}
		getElementById('queryName_'+id).value=(bPackages?'PackageDealDetailsRequest':'FlightDealDetailsRequest');
		getElementById('detailsForm_'+id).submit();
	}
}
function goToPriceTemplateOfFlyAndDrive(id){
	var oInFlightID=document.getElementById('InFlightID_'+id)
	if(isnull(oInFlightID.value)){
		alert(dic.CHOOSE_RETURN_DATE)
		return
	}
	with(document){
		getElementById('detailsForm_'+id).action = ""
		getElementById('queryName_'+id).value='PackageDealDetailsRequest';
		getElementById('detailsForm_'+id).submit();
	}
}
function goToFlightPassengersDetailes(){
	if(document.getElementById('num_of_passengers0').value==""){
		alert(dic.CHOOSE_PASSENGERS_NUMBER)
		return
	}
	with(document){
		getElementById('step').value='_passengers_detailes';
		getElementById('query').value='FlightPriceTemplateRequest';
		getElementById('passengers_detailes').submit();
	}
}
function submitPromotionByCacheID(id,sCacheID,sMode){
	var viewIn = ""
	if(document.getElementById('view_in_'+id) && document.getElementById('view_in_'+id).value!="DEAL") viewIn = document.getElementById('view_in_'+id).value;
		
	var seatsNum=document.getElementById('seatsNum_'+id)
	if(seatsNum && seatsNum.innerText=='0') return
	var oForm=document.getElementById('detailsForm_'+id)
	switch(sMode){
		case "FLIGHTS":
			isnull(viewIn)?tempAction=flights_action:tempAction=(pagePath+"?pi="+viewIn);
			oForm.action=tempAction;
			document.getElementById('query_'+id).value="FlightDealDetailsRequest"
			break;
		case "ISRAEL":
			isnull(viewIn)?tempAction=israel_action:tempAction=(pagePath+"?pi="+viewIn);
			oForm.action=tempAction;
			document.getElementById('query_'+id).value="PackageDealDetailsRequest"
			break
		default:
			isnull(viewIn)?tempAction=packages_action:tempAction=(pagePath+"?pi="+viewIn);
			oForm.action=tempAction;
			document.getElementById('query_'+id).value="PackageDealDetailsRequest"
	}
	
	document.getElementById('step_'+id).value="_passengers_number"
	oForm.submit()
}
function submitPromotion(id,ShowOutCalendar){
	var viewIn = ""
	if(document.getElementById('view_in_'+id) && document.getElementById('view_in_'+id).value!="DEAL") viewIn = document.getElementById('view_in_'+id).value;
	
	if(isnull(ShowOutCalendar)) ShowOutCalendar='0'
	ShowOutCalendar=String(ShowOutCalendar)
	if(ShowOutCalendar=='1'){
	    
		document.getElementById('step_'+id).value='_search_results'
		try{
			var fareVal=document.getElementById('Fare_'+id).value
			document.getElementById('MinFare_'+id).value=fareVal
			document.getElementById('MaxFare_'+id).value=fareVal
		}catch(e){}
		switch(document.getElementById('mode_'+id).value){
			case "FLIGHTS":
				document.getElementById('query_'+id).value="FlightDealsRequestEx";
				isnull(viewIn)?tempAction=flights_action:tempAction=(pagePath+"?pi="+viewIn);
				document.getElementById('detailsForm_'+id).action = tempAction;
				break;
			case "ISRAEL":
				document.getElementById('query_'+id).value="PackageDealsRequestEx";
				isnull(viewIn)?tempAction=israel_action:tempAction=(pagePath+"?pi="+viewIn);
				document.getElementById('detailsForm_'+id).action = tempAction;
				break;
			default:
				document.getElementById('query_'+id).value="PackageDealsRequestEx";
				isnull(viewIn)?tempAction=packages_action:tempAction=(pagePath+"?pi="+viewIn);
				document.getElementById('detailsForm_'+id).action = tempAction;
		}
		document.getElementById('detailsForm_'+id).submit()
		return
	}
	// submit by cacheID
	var oCacheID=document.getElementById('CacheID_'+id)
	var oModeField=document.getElementById('mode_'+id)
	if(oCacheID && !isnull(oCacheID.value) && oCacheID.value != "0"){
		submitPromotionByCacheID(id,oCacheID.value,oModeField.value)
		return
	}
	var seatsNum=document.getElementById('seatsNum_'+id)
	if(seatsNum && seatsNum.innerText=='0') return
	var oForm=document.getElementById('detailsForm_'+id)
	var oStepField=document.getElementById('step_'+id)
	var oInFlightID=document.getElementById('InFlightID_'+id)	
	if(oModeField.value=="FLIGHTS"){
		if(!isnull(oInFlightID.value)){
			isnull(viewIn)?tempAction=flights_action:tempAction=(pagePath+"?pi="+viewIn);
			oForm.action=tempAction;
			oStepField.value="_passengers_number"
			document.getElementById('query_'+id).value="FlightDealDetailsRequest"
		} else {
		    //alert("Not implemented yet (return flights calendar)");
	        //return;
			document.getElementById('query_'+id).value="FlightReturnDatesRequestEx"
			openCalendar({'mode':'RETURN'},id)
			return
		}
	}
	else{	
		if(oModeField.value=="ISRAEL"){
			if(!isnull(oInFlightID.value)){
				isnull(viewIn)?tempAction=israel_action:tempAction=(pagePath+"?pi="+viewIn);
				oForm.action=tempAction;
				oStepField.value="_passengers_number"
				document.getElementById('query_'+id).value="PackageDealDetailsRequest"
			}
			else{
				document.getElementById('query_'+id).value="PackageReturnDatesRequestEx"
				//alert("Not implemented yet (return flights calendar)");
	            //return;
			    openCalendar({'mode':'RETURN'},id)
				return
			}
		}
		else{
			if(!isnull(oInFlightID.value)){
				isnull(viewIn)?tempAction=packages_action:tempAction=(pagePath+"?pi="+viewIn);
				oForm.action=tempAction;
				oStepField.value="_passengers_number"
				document.getElementById('query_'+id).value="PackageDealDetailsRequest"
			}
			else{
				document.getElementById('query_'+id).value="PackageReturnDatesRequestEx"
				//alert("Not implemented yet (return flights calendar)");
	            //return;
			    openCalendar({'mode':'RETURN'},id)
				return
			}
		}
	}

	oForm.submit()
	oForm.target="_parent"
}
function submitPromotionWithoutCheck(id){
	var viewIn = ""
	if(document.getElementById('view_in_'+id) && document.getElementById('view_in_'+id).value!="DEAL") viewIn = document.getElementById('view_in_'+id).value;
	
	var oForm=document.getElementById('detailsForm_'+id)
	var oStepField=document.getElementById('step_'+id)
	var oModeField=document.getElementById('mode_'+id)
	oStepField.value="_passengers_number"
	if(oModeField.value=="FLIGHTS"){
		document.getElementById('query_'+id).value="FlightDealDetailsRequest"
		isnull(viewIn)?tempAction=flights_action:tempAction=(pagePath+"?pi="+viewIn);
		oForm.action=tempAction;
	}
	if(oModeField.value=="PACKAGES"){
		document.getElementById('query_'+id).value="PackageDealDetailsRequest"
		isnull(viewIn)?tempAction=packages_action:tempAction=(pagePath+"?pi="+viewIn);
		oForm.action=tempAction;
	}
	if(oModeField.value=="ISRAEL"){
		document.getElementById('query_'+id).value="PackageDealDetailsRequest"
		isnull(viewIn)?tempAction=israel_action:tempAction=(pagePath+"?pi="+viewIn);
		oForm.action=tempAction;
	}
	

	oForm.submit()
    oForm.target="_parent"
}

function submitFlightOrPackageMainSearch(id,bPackage){
	var _yes=false
	var pr=(bPackage?'p':'f')

	if(document.getElementById('citiesSelect_'+pr+'se'+id).value=="")
	{
		alert(dic.NOT_DESTINATION)
		try{
		    document.getElementById('countriesSelect_'+pr+'se'+id).focus()
		}
		catch(e){}
		return
	}
	var ot = document.getElementById("Template"+id)
	if(ot && ot.getAttribute("is_requeried") == "1" && ot.value == "")
	{
		alert(ot.getAttribute("requeried_msg"))
		ot.focus()
		return
	}
	if(!isnull(document.getElementById('departureDate_'+pr+'se'+id).value)){
		document.getElementById('OutboundDate_Start_'+pr+'se'+id).value=document.getElementById('departureDate_'+pr+'se'+id).value
		document.getElementById('OutboundDate_End_'+pr+'se'+id).value=document.getElementById('departureDate_'+pr+'se'+id).value
		document.getElementById('BestPrice_'+pr+'se'+id).value='0'
		_yes=true
	}
	if(!isnull(document.getElementById('arrivalDate_'+pr+'se'+id).value)){
		document.getElementById('InboundDate_Start_'+pr+'se'+id).value=document.getElementById('arrivalDate_'+pr+'se'+id).value
		document.getElementById('InboundDate_End_'+pr+'se'+id).value=document.getElementById('arrivalDate_'+pr+'se'+id).value
	}
    
    try
    {
        var opt = document.getElementById('PackageType'+id)
        if(opt && opt.value == "SKI|SKI FAMILY") _yes = true
    }
    catch(e){}
    
	if(!_yes) document.getElementById('OutboundDate_End_'+pr+'se'+id).value=EndRangeDateByDestRange	
	document.getElementById('query_'+pr+'se'+id).value=(bPackage?'PackageDealsRequestEx':'FlightDealsRequestEx')
	var fObj=$('#form_'+pr+'se'+id);
	fObj.attr("target","_parent");
	fObj.attr("action",(!isnull(fObj.attr("realaction"))?fObj.attr("realaction"):(bPackage?packages_action:flights_action)));
	//fObj.method="GET"
	fObj.submit()
}
function submitTypesMainSearch(id){
	var _yes=false
	var pr='p'

	if(document.getElementById('citiesSelect_'+pr+'se'+id).value=="")
	{
		alert(dic.NOT_DESTINATION)
		try{
		    document.getElementById('countriesSelect_'+pr+'se'+id).focus()
		}
		catch(e){}
		return
	}
	var ot = document.getElementById("Template"+id)
	if(ot && ot.getAttribute("is_requeried") == "1" && ot.value == "")
	{
		alert(ot.getAttribute("requeried_msg"))
		ot.focus()
		return
	}
	if(!isnull(document.getElementById('departureDate_'+pr+'se'+id).value)){
		document.getElementById('OutboundDate_Start_'+pr+'se'+id).value=document.getElementById('departureDate_'+pr+'se'+id).value
		document.getElementById('OutboundDate_End_'+pr+'se'+id).value=document.getElementById('departureDate_'+pr+'se'+id).value
		document.getElementById('BestPrice_'+pr+'se'+id).value='0'
		_yes=true
	}
	if(!isnull(document.getElementById('arrivalDate_'+pr+'se'+id).value)){
		document.getElementById('InboundDate_Start_'+pr+'se'+id).value=document.getElementById('arrivalDate_'+pr+'se'+id).value
		document.getElementById('InboundDate_End_'+pr+'se'+id).value=document.getElementById('arrivalDate_'+pr+'se'+id).value
	}

	if(!_yes) document.getElementById('OutboundDate_End_'+pr+'se'+id).value=EndRangeDate_Types
	document.getElementById('query_'+pr+'se'+id).value='PackageDealsRequestEx'
	var fObj=$('#form_'+pr+'se'+id);
	fObj.attr("target","_parent");
	fObj.attr("action",(!isnull(fObj.attr("realaction"))?fObj.attr("realaction"):packages_action));
	//fObj.method="GET"
	fObj.submit()
}
function submitFlightMainSearch(id){
	submitFlightOrPackageMainSearch(id,false)
}
function submitPackageMainSearch(id){
	submitFlightOrPackageMainSearch(id,true)
}
function submitSkiMainSearch(id){
	var _yes=false
	var pr='p';

	if(document.getElementById('citiesSelect_'+pr+'se'+id).value=="")
	{
		alert(dic.NOT_DESTINATION)
		try{
		    document.getElementById('countriesSelect_'+pr+'se'+id).focus()
		}
		catch(e){}
		return
	}
	if(!isnull(document.getElementById('departureDate_'+pr+'se'+id).value)){
		document.getElementById('OutboundDate_Start_'+pr+'se'+id).value=document.getElementById('departureDate_'+pr+'se'+id).value
		document.getElementById('OutboundDate_End_'+pr+'se'+id).value=document.getElementById('departureDate_'+pr+'se'+id).value
		document.getElementById('BestPrice_'+pr+'se'+id).value='0'
		_yes=true
	}
	if(!isnull(document.getElementById('arrivalDate_'+pr+'se'+id).value)){
		document.getElementById('InboundDate_Start_'+pr+'se'+id).value=document.getElementById('arrivalDate_'+pr+'se'+id).value
		document.getElementById('InboundDate_End_'+pr+'se'+id).value=document.getElementById('arrivalDate_'+pr+'se'+id).value
	}

	document.getElementById('query_'+pr+'se'+id).value='PackageDealsRequestEx'
	var fObj=$('#form_'+pr+'se'+id);
	fObj.attr("target","_parent");
	fObj.attr("action",(!isnull(fObj.attr("realaction"))?fObj.attr("realaction"):packages_action));
	//fObj.method="GET"
	fObj.submit()
}
/*function submitIsraelMainSearch(id){
	var _yes=false
	var pr='p'
	if(document.all['citiesSelect_'+pr+'se'+id].value==""){
		alert(dic.NOT_DESTINATION)
		document.all['countriesSelect_'+pr+'se'+id].focus()
		return
	}
	if(!isnull(document.all['departureDate_'+pr+'se'+id].value)){
		document.all['OutboundDate_Start_'+pr+'se'+id].value=document.all['departureDate_'+pr+'se'+id].value
		document.all['OutboundDate_End_'+pr+'se'+id].value=document.all['departureDate_'+pr+'se'+id].value
		document.all['BestPrice_'+pr+'se'+id].value='0'
		_yes=true
	}
	if(!isnull(document.all['arrivalDate_'+pr+'se'+id].value)){
		document.all['InboundDate_Start_'+pr+'se'+id].value=document.all['arrivalDate_'+pr+'se'+id].value
		document.all['InboundDate_End_'+pr+'se'+id].value=document.all['arrivalDate_'+pr+'se'+id].value
	}

	if(!_yes) document.all['OutboundDate_End_'+pr+'se'+id].value=EndRangeDateByDestRange	
	document.all['query_'+pr+'se'+id].value='PackageDealsRequestEx'
	var fObj=document.all['form_'+pr+'se'+id]
	fObj.target="_parent"
	fObj.action=(!isnull(fObj.realaction)?fObj.realaction:israel_action)
	fObj.submit()
}
function submitSkiMainSearch(id){
	var _yes=false
	var pr='p'
	if(document.all['citiesSelect_'+pr+'se'+id].value==""){
		alert(dic.NOT_DESTINATION)
		document.all['countriesSelect_'+pr+'se'+id].focus()
		return
	}
	if(!isnull(document.all['departureDate_'+pr+'se'+id].value)){
		document.all['OutboundDate_Start_'+pr+'se'+id].value=document.all['departureDate_'+pr+'se'+id].value
		document.all['OutboundDate_End_'+pr+'se'+id].value=document.all['departureDate_'+pr+'se'+id].value
		document.all['BestPrice_'+pr+'se'+id].value='0'
		_yes=true
	}
	if(!isnull(document.all['arrivalDate_'+pr+'se'+id].value)){
		document.all['InboundDate_Start_'+pr+'se'+id].value=document.all['arrivalDate_'+pr+'se'+id].value
		document.all['InboundDate_End_'+pr+'se'+id].value=document.all['arrivalDate_'+pr+'se'+id].value
	}

	if(!_yes) document.all['OutboundDate_End_'+pr+'se'+id].value=EndRangeDateBySkiDestRange	
	document.all['query_'+pr+'se'+id].value='PackageDealsRequestEx'
	var fObj=document.all['form_'+pr+'se'+id]
	fObj.target="_parent"
	fObj.action=(!isnull(fObj.realaction)?fObj.realaction:packages_action)
	fObj.submit()
}

function setArrivalAndDepartureLabels(id){
	var opt=document.all['citiesSelect_fse'+id].options
	for(var i=0;i<opt.length;i++){
		if(opt[i].selected){
			document.all['ArrivalCityDesc_fse'+id].value=opt[i].text
			break
		}
	}
	var opt=document.all['departureCitySelect_fse'+id].options
	for(var i=0;i<opt.length;i++){
		if(opt[i].selected){
			document.all['DepartureCityDesc_fse'+id].value=opt[i].text
			break
		}
	}
}
function setArrivalAndDepartureLabels_Package(id){
	var opt=document.all['citiesSelect_pse'+id].options
	for(var i=0;i<opt.length;i++){
		if(opt[i].selected){
			document.all['ArrivalCityDesc_pse'+id].value=opt[i].text
			break
		}
	}
}
function getDepartureDateFlightPackageMainSearch(id,bPackage)
{
	var pr=(bPackage?'p':'f')
	if(document.all['citiesSelect_'+pr+'se'+id].value==""){
		alert(dic.NOT_DESTINATION)
		try{
		document.all['countriesSelect_'+pr+'se'+id].focus()
		}
		catch(e){}
		return
	}
	if(bPackage)
		setArrivalAndDepartureLabels_Package(id)
	else
		setArrivalAndDepartureLabels(id)
	document.all['departureDate_'+pr+'se'+id].value=""
	document.all['arrivalDate_'+pr+'se'+id].value=""
	var CALENDAR_H=300;
	var top=window.screen.availHeight/2-CALENDAR_H/2
	var left=window.screen.availWidth/2-CALENDAR_W/2
	var calendarWinFeatures = "height="+CALENDAR_H+"px,width="+CALENDAR_W+"px,top="+top+",left="+left+",center=no,status=no,scrollbars=yes,resizable=no"
	var calendarWin=window.open('about:blank','calendarWin',calendarWinFeatures)
	calendarWin.document.write(LOADING_STR)
	calendarWin.document.body.style.cursor='wait'
	document.all['query_'+pr+'se'+id].value=(bPackage?'PackageDepartureDatesByDestRequest':'FlightDepartureDatesByDestRequest')
	var formObj=document.all['form_'+pr+'se'+id]
	formObj.action=windows_path+"FLIGHTS_SEARCH_CALENDAR/flights_search_calendar.asp?pi="+node_pi+"&sitePath="+_site_path+"&id="+id+"&mode=exit&dealType="+(bPackage?"PACKAGE":"FLIGHT")
	//formObj.action=windows_path+"FLIGHTS_SEARCH_CALENDAR/flights_search_calendar.asp?pi="+node_pi+"&id="+id+"&mode=exit&dealType="+(bPackage?"PACKAGE":"FLIGHT")
	formObj.target="calendarWin"
	formObj.submit()
	calendarWin.focus()
}
function getDepartureDateFlightMainSearch(id){
	getDepartureDateFlightPackageMainSearch(id,false)
}
function getDepartureDatePackageMainSearch(id){
	getDepartureDateFlightPackageMainSearch(id,true)

}
function getArrivalDateFlightPackageMainSearch(id,bPackage)
{	

	var pr=(bPackage?'p':'f')
	if(document.all['citiesSelect_'+pr+'se'+id].value==""){
		alert(dic.NOT_DESTINATION)
		try{
		document.all['countriesSelect_'+pr+'se'+id].focus()
		}
		catch(e){}
		return
	}
	if(document.all['departureDate_'+pr+'se'+id].value==""){
		alert(dic.CHOOSE_EXIT_DATE)
		return
	}
	if(bPackage)
		setArrivalAndDepartureLabels_Package(id)
	else
		setArrivalAndDepartureLabels(id)
	document.all['arrivalDate_'+pr+'se'+id].value=""
	var CALENDAR_H=300;
	var top=window.screen.availHeight/2-CALENDAR_H/2
	var left=window.screen.availWidth/2-CALENDAR_W/2	
	var calendarWinFeatures = "height="+CALENDAR_H+"px,width="+CALENDAR_W+"px,top="+top+",left="+left+",center=no,status=no,scrollbars=yes,resizable=no"	
	var calendarWin=window.open('about:blank','calendarWin',calendarWinFeatures)
	calendarWin.document.write(LOADING_STR)
	calendarWin.document.body.style.cursor='wait'
	document.all['query_'+pr+'se'+id].value=(bPackage?'PackageReturnDatesByDestRequest':'FlightReturnDatesByDestRequest')
	var formObj=document.all['form_'+pr+'se'+id]
	formObj.action=windows_path+"FLIGHTS_SEARCH_CALENDAR/flights_search_calendar.asp?pi="+node_pi+"&sitePath="+_site_path+"&id="+id+"&mode=return&dealType="+(bPackage?"PACKAGE":"FLIGHT")
	formObj.target="calendarWin"
	formObj.submit()
	calendarWin.focus()
}
function getArrivalDateFlightMainSearch(id){
	getArrivalDateFlightPackageMainSearch(id,false)
}
function getArrivalDatePackageMainSearch(id){
	getArrivalDateFlightPackageMainSearch(id,true)

}
function updateNightsNumber(id){
	var obj=document.all['nightsNumber_pse'+id]
	if(!obj) return
	var str=obj.innerHTML;
	var date1=document.all['departureDate_pse'+id].value
	var date2=document.all['arrivalDate_pse'+id].value
	obj.innerHTML=str.replace(/\d/g,'');
	if(isnull(date2) || isnull(date1)){
		
		obj.style.visibility='hidden'
		return
	}	
	date1=new Date(date1.replace(/-/g,'/'))
	date2=new Date(date2.replace(/-/g,'/'))
	obj.innerHTML+=String(Math.round((date2-date1)/(1000*60*60*24)))
	obj.style.visibility='visible'
}
*/
function isIn(list,arg,delim){
	if (isnull(list) || isnull(arg)) return false;
	delim = (isnull(delim)?",":delim)
	return ((delim + list + delim).search(delim + arg + delim) >= 0);
}
function isnull(arg) {
	arg = arg+'';
	return (arg == '' || arg == 'null' || arg == 'undefined');
}
String.prototype.toFirstLetterCase=function(){
	return (this.substring(0,1).toUpperCase()+this.substring(1,this.length).toLowerCase())
}
function clear_fse(id){
	
}
function clear_pse(id){
	
}


// newsletter_action:	1 = subscribe
//						0 = unsubscribe
function newsletter_subscribe(action) {
	/*var email = document.getElementById('newsletter_email').value;
	var oXML=new ActiveXObject("Msxml2.DOMDocument");
	oXML.async=false;
	var obj = {};
	obj.exist = oXML.load("/SITE/UTILS/XX/newsletterSubsribtion.hx.asp?newsletter_action="+action+"&newsletter_email="+email);
	if(!obj.exist) alert(oXML.parseError.reason);
	alert(oXML.xml);*/
}


function printDeal(){
    window.print()
    /*
	var printDIV = document.getElementById("print_deal");
	if (printDIV != null) {
			var content = printDIV.innerHTML;
	} else {
		//alert("Could not find the printDIV section in the HTML");
		return;
	}	
	var printWin = window.open("/SITE/MODULES/PURCHASE/print_win.asp?pi="+node_pi,"printWin");
	//printWin.document.open();
	//alert(printWin.document.all('print_container'));	
	//printWin.document.write(content);
	//printWin.document.close();
	//printWin.print();
	*/
}

function validInput(obj){
	var str = obj.value.toUpperCase() 
	var strOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZ _-.@0123456789"
	for(var i=0 ; i < str.length ; i++){
		if(strOK.indexOf(str.substring(i,i+1)) == -1){
			alert(dic.ENGLISH_CHAR_ONLY)
			obj.focus()
			return false;
		}
	}
}







function ShowUrlTrip(url)
{
	/*var CALENDAR_H=500;
	var CALENDAR_W=750;
	var top=window.screen.availHeight/2-CALENDAR_H/2
	var left=window.screen.availWidth/2-CALENDAR_W/2	
	var calendarWinFeatures = "height="+CALENDAR_H+"px,width="+CALENDAR_W+"px,top="+top+",left="+left+",center=no,status=yes,scrollbars=no,resizable=yes"	
	var UrlTrip=window.open('/site/UrlTrip.asp?sUrl='+escape(url),'UrlTrip',calendarWinFeatures)*/
	window.open(url)
	return;
	
}



/////////////////////////////////////////////////////////////////////////////////////////

function checkIfAffiliate(affiliatecode,doaffildiscount){
    try{
        var oDate = new Date();
        var url = "/SITE/INCLUDES/getHeaderBanners.hx.asp?affiliatecode="+affiliatecode+"&doaffildiscount="+doaffildiscount+"&pi="+home_pi+"&rn="+oDate.getMilliseconds();
        var bannersXML = $.ajax({
	            type: "GET",
	            url: url,
	            dataType: "xml",
	            contentType: "text/xml",
	            async: false
            }).responseXML;
        	var doaffildiscountElem = $(bannersXML).find("doaffildiscount")
	    var affiliatecodeElem = $(bannersXML).find("affiliatecode")
    	
	    var doaffildiscount_serv = "";
	    var affiliatecode_serv = "";
    	
	    if(doaffildiscountElem) doaffildiscount_serv = doaffildiscountElem.text()
	    if(affiliatecodeElem) affiliatecode_serv = affiliatecodeElem.text()
    	
	    //alert(doaffildiscount_serv + " : " + affiliatecode_serv)
    	
	    if(!isnull(affiliatecode_serv) && isnull(affiliatecode)){
		    var s = window.location.href
		    if(s.indexOf("?") > -1) s = s + "&affiliatecode=" + affiliatecode_serv
		    else  s = s + "?affiliatecode=" + affiliatecode_serv
		    if(!isnull(doaffildiscount_serv))  s + "&doaffildiscount=" + doaffildiscount_serv
		    else   s + "&doaffildiscount=0"

		    window.location.href = s
	    }
	}
	catch(e){
	    //alert("checkIfAffiliate : error : " + e.description);
	}
	
	
}

function getHeaderBanners(affiliatecode,doaffildiscount){

    try{
        var oDate = new Date();
        var url = "/SITE/INCLUDES/getHeaderBanners.hx.asp?affiliatecode="+affiliatecode+"&doaffildiscount="+doaffildiscount+"&pi="+home_pi+"&rn="+oDate.getMilliseconds();
        var bannersXML = $.ajax({
	            type: "GET",
	            url: url,
	            dataType: "xml",
	            contentType: "text/xml",
	            async: false
            }).responseXML;
        var headerPartDivElem = $(bannersXML).find("header_part_div")
	    
	    var header_part_div = "";
	    
	    if(headerPartDivElem) header_part_div = headerPartDivElem.text()
	    
	    //alert(doaffildiscount_serv + " : " + affiliatecode_serv)
    	
	    if(!isnull(header_part_div))
	    {
			$('#header_part').html(header_part_div);
		}
	}
	catch(e){
	    //alert("getHeaderBanners : error : " + e.description);
	}


}
var affElemCode = "";
function updateAffiliateLinks(affiliatecode,doaffildiscount){
	
	try{



	var oDate = new Date();
	var url = "/SITE/INCLUDES/checkAffiliateCode.hx.asp?affiliatecode="+affiliatecode+"&doaffildiscount="+doaffildiscount+"&pi="+home_pi+"&rn="+oDate.getMilliseconds();
        var affXML = $.ajax({
	            type: "GET",
	            url: url,
	            dataType: "xml",
	            contentType: "text/xml",
	            async: false
            }).responseXML;
	var affElem = $(affXML).find("isaffiliate")
	//var affElemCode = "";
	    
	if(affElem) affElemCode = affElem.text()

	//alert("affElemCode : "+affElemCode);

	//if(!isnull(affElemCode)) $("#contText628").attr("href","http://pnim.ophirtours.co.il/"+affElemCode)	
			
	}
	catch(e){
		//alert("updateaffiliatelinks : " + e.description)
	}
}
var returnFlightsDates = {}
var returnFlightsObj = {}
var returnFlightsID = {}
function openCalendar(obj,id)
{
    returnFlightsDates = {};
    returnFlightsObj = obj;
    returnFlightsID = id;
    
    var data = {}//detailsForm_
    //alert('#detailsForm_' + id + ' input')
    //alert($('#detailsForm_' + id + ' input').length)
    //return
    $('#detailsForm_' + id + ' input').each(function(){
        var n = $(this).attr("name");
        if(!isnull(n))
        {
            data[n] = $(this).val()
        }
    });
    var postData=[]
	for(var x in data){
	    //alert(x+"="+data[x])
	    postData.push(x+"="+data[x]);
	}
    
    //load("/ajax/hotelDetails/hotelDetails.asp?pi="+node_pi).
    $(".return_flights_result").html("");
    $(".return_flights_calendar").datepicker("destroy");
    $(".return_flights_calendar").html("");
    $(".return_flights_popup").dialog("destroy");
    $(".return_flights_popup").dialog({
        autoOpen: true,
        modal: true,
        title: (isnull(data["ArrivalCityDesc"]) ? "" : data["ArrivalCityDesc"]) + "-" + (isnull(data["DepartureCityDesc"]) ? dic['TEL_AVIV'] : data["DepartureCityDesc"]),
        width: 530,
        height: 600,
        resizable: false,
        draggable: false,
        onClose: function(){
            $(".return_flights_loading").css("display","none");
        }
    });
    $(".return_flights_loading").css("display","block");
    
    $('.return_flights_calendar').datepicker({
	    minDate: '+1d',
        maxDate: '+12m',
        numberOfMonths: 2
	});
    
    
    //alert(postData.join("&"))
    $.ajax({
		type: "GET",
		url: "/Site/Ajax/ReturnDatesCalendar/ReturnDates.asp?pi=" + node_pi + "&id="+id + "&",// + "&r=" + Math.random(),
		cache: true,
		data: postData.join("&"),
		dataType: 'json', 
        timeout: 20000,
		error: function(XMLHttpRequest, textStatus, errorThrown){
		    $(".return_flights_loading").css("display","none");
		    $(".return_flights_result").html("");
		    $(".return_flights_calendar").datepicker("destroy");
            $(".return_flights_calendar").html(dic['LOADING_DATA_ERROR']);
            returnFlightsDates = {}
			//alert('error : ' + textStatus + " : " + errorThrown);
		},
		success: function(data, textStatus){
		    returnFlightsDates = data
		    $(".return_flights_loading").css("display","none");
		    $(".return_flights_result").html("");
		    $(".return_flights_calendar").datepicker("destroy");
		    $('.return_flights_calendar').datepicker({
	            minDate: '+1d',
                maxDate: '+12m',
                numberOfMonths: 2,
                onSelect: function(dateText, inst){
                    getReturnFlights(dateText);
                },
                beforeShowDay: function(date) { 
                    //show only available dates
                    try{
                        if (returnFlightsDates[$.datepicker.formatDate('yy-mm-dd', date)]) { 
                            return [true]; 
                        } else { 
                            return [false]; 
                        } 
                    }
                    catch(e){}
                    
                    return [false];
                    
                }
	        });
	        //alert("data : " + data);
		    
		    
		    
		}
	})
	
    

	
}
function getReturnFlights(date)
{
    $(".return_flights_result").html("");
    $(".return_flights_loading").css("display","block");
    
    var data = {}
    $('#detailsForm_' + returnFlightsID + ' input').each(function(){
        var n = $(this).attr("name");
        if(!isnull(n))
        {
            data[n] = $(this).val()
        }
     });
    data["InboundDate_Start"] = date;
    data["InboundDate_End"] = date;
    if(data["query"]=="PackageReturnDatesRequestEx")
    {
        data["query"]="PackageDealsReturnFlightRequest"
    }
    else
    {
        data["query"]="ReturnFlightDetailsRequestEx";
    }
    var postData=[]
	for(var x in data){
	    //alert(x+"="+data[x])
	    postData.push(x+"="+data[x]);
	}
	
	
	$.ajax({
		type: "GET",
		url: "/Site/Ajax/ReturnDatesCalendar/ReturnFlights.asp?pi=" + node_pi + "&id="+returnFlightsID + "&",// + "&r=" + Math.random(),
		cache: true,
		data: postData.join("&"),
		timeout: 20000,
		error: function(XMLHttpRequest, textStatus, errorThrown){
		    $(".return_flights_loading").css("display","none");
		    $(".return_flights_result").html(dic['LOADING_DATA_ERROR']);
		    //alert('error : ' + textStatus + " : " + errorThrown);
		},
		success: function(data, textStatus){
		    $(".return_flights_loading").css("display","none");
		    if(data.length > 0 && data.indexOf("ERROR")==-1)
		    {
		        $(".return_flights_result").html(data);
		    }
		    else
		    {
		        $(".return_flights_result").html(dic['LOADING_DATA_ERROR']);
		    }
		    
		    
		}
	})
}



function continueToSearchResults(){
    var val = "";
    var arr = []
	try{
	    val = $('div.rf_data_radio input:radio:checked').val()
		if(isnull(val))
		{
		    alert(dic.CHOOSE_OTHER_DATE)
		    return true;
		}
	}catch(e){
		alert(dic.CHOOSE_OTHER_DATE)
		return true;
	}
	//alert(val);
	//return;
	
	var InFlightID=val.split("=")[0]
	var InTakeoffdate=val.split("=")[1]
	var InTakeoffdate=new Date((InTakeoffdate.split(" ")[0]).replace(/-/g,'\/'))
	InTakeoffdate=InTakeoffdate.getDate()+"/"+(Number(InTakeoffdate.getMonth())+1)+"/"+InTakeoffdate.getYear()
	var InTakeofftime=val.split("=")[2]
	InTakeofftime=InTakeofftime.substring(0,5)
	try{
		$('#InFlightID_'+returnFlightsID).val(InFlightID);
		$('#InTakeofftime_'+returnFlightsID).val(InTakeofftime.substring(0,5));
	}catch(e){
		
	}
	try{
		var CacheId = val.split("=")[3]
		if(CacheId != "" && CacheId !="0")
		{
		    $('#CacheId_'+returnFlightsID).val(CacheId);
		}
	}catch(e){}
	
	$('#detailsForm_'+returnFlightsID).attr("target","");
	try{
	    $('#returnDateText_'+returnFlightsID).html("<strong>"+InTakeoffdate+"<br/>"+InTakeofftime+"</strong>");
	}catch(e){
		
	}
	try{
		submitPromotionWithoutCheck(returnFlightsID)
	}catch(e){}
	
	$(".return_flights_result").html("");
    $(".return_flights_calendar").datepicker("destroy");
    $(".return_flights_calendar").html("");
    $(".return_flights_popup").dialog("destroy");
}

function resetContactUsForm(id)
{
    $('#contact_us_form_'+id + ' input[type="text"]').each(function(){
        $(this).val("");
    });
    $('#contact_us_form_'+id + ' textarea').each(function(){
        $(this).val("");
    });
}
function sendContactUsForm(id){
    if(validateContactUsForm(id))
    {
        $(".contact_us_result").html("");
        $(".contact_us_popup").dialog("destroy");
        $(".contact_us_popup").dialog({
            autoOpen: true,
            modal: true,
            title: dic['MAIL_PROCCESED'],
            width: 520,
            height: 350,
            resizable: false,
            draggable: false,
            onClose: function(){
                $(".contact_us_loading").css("display","none");
                $(".contact_us_buttons").css("display","none");
                
            }
        });
        $(".contact_us_loading").css("display","block");
        
        
        var postData=createContactUsData(id);
//alert(postData.join("&"))
        
        if(postData.length > 0)
        {
        
            $.ajax({
		        type: "POST",
		        url: "/Site/Ajax/SendEmail/SendEmail.asp?pi=" + node_pi,
		        cache: true,
		        data: postData.join("&").replace(/ /g,'___'),
		        timeout: 20000,
		        error: function(XMLHttpRequest, textStatus, errorThrown){
				$(".contact_us_popup").dialog( "option", "title", dic["CLOSE"] );
		            $(".contact_us_loading").css("display","none");
		            $(".contact_us_result").html(dic['MAIL_ERROR']);
			        //alert('error : ' + textStatus + " : " + errorThrown);
		        },
		        success: function(data, textStatus){
		            $(".contact_us_loading").css("display","none");
				$(".contact_us_popup").dialog( "option", "title", dic["CLOSE"] );
		            if(data=="1")
		            {
		                $(".contact_us_result").html($('#confirmation_text_'+id).html()+"<iframe src='/Site/Ajax/SendEmail/SendEmailEvent.asp?pi=" + node_pi+"&lang="+lang+"&sitepath="+path+"' style='width:1px;height:1px;visibility:hidden;' frameborder='0'></iframe>");  
		                $(".contact_us_buttons").css("display","none");
		            }
		            else
		            {
		                $(".contact_us_result").html(dic['MAIL_ERROR']);
		            }
		        }
	        });
	    }
	    else
	    {
	        $(".contact_us_loading").css("display","none");
		    $(".contact_us_result").html(dic['MAIL_ERROR']);
	    }
	    
	    
	    
    }
    
    return;
}
function createContactUsData(id)
{
    var postData=[]
    try{
        var data = {}
        //$('#detailsForm_' + id + ' input').each(function(){
        //    data[$(this).attr("name")] = $(this).val()
        //});

        var bAddMember = $('input.contact_us_add_member').is(":checked")
	
	//alert(bAddMember)

        data["FROM_ADDRESS"] = $('#email_'+id).val()
        data["FROM_NAME"] = $('#fname_'+id).val()+" "+$('#lname_'+id).val()
        data["TO_ADDRESS"] = $('#email_address_'+id).val()
        data["SUBJECT"] = (!isnull($('#subject_'+id).val())?(dic.CONTACT_US_SUBJECT + ":" + $('#subject_'+id).val()):dic.CONTACT_US_SUBJECT);
        data["TO_ADDRESS"] = $('#email_address_'+id).val()
        
        data["FNAME"] = $('#fname_'+id).val()
        data["FNAME_LABEL"] = $('#fname_'+id).attr("email_label")
        data["LNAME"] = $('#lname_'+id).val()
        data["LNAME_LABEL"] = $('#lname_'+id).attr("email_label")
        data["CONTACT_PHONE"] = $('#prephone_'+id).val()+" "+$('#phone_'+id).val()
        data["CONTACT_PHONE_LABEL"] = $('#phone_'+id).attr("email_label")
        data["EMAIL"] = $('#email_'+id).val()
        data["EMAIL_LABEL"] = $('#email_'+id).attr("email_label")
        data["INTERESTED"] = $('#interested_'+id).val()
        data["INTERESTED_LABEL"] = $('#interested_'+id).attr("email_label")
        data["LANG"] = lang
        data["LANG_LABEL"] = dic.MAIL_LANG
        data["CATEGORY"] = MEMBERS_CLUB_CATEGORY
        data["CATEGORY_LABEL"] = dic.MAIL_CATEGORY
        data["ADD_MEMBER"] = bAddMember?"1":"0"
        data["ADD_MEMBER_LABEL"] = dic.MAIL_MEMBER
        
       
        
        /*
        var SendingMailArgs={}
		    SendingMailArgs.errorMsg=document.all['error_msg_'+id].value
		    SendingMailArgs.confirmMsg=document.all['confirmation_text_container_'+id].innerHTML
		    SendingMailArgs.loadingMsg=dic.MAIL_PROCCESED
		    SendingMailArgs.closeMsg=dic.CLOSE_WINDOW
		    SendingMailArgs.URL=SEND_MAIL_URL
		    SendingMailArgs.msg=oXML
    		
		    var SendResult=showModalDialog("/site/windows/dialogs/SendingMail.asp",SendingMailArgs,"status:no;dialogWidth:300px;dialogHeight:200px;");
	    */	
    		
    		
	    
	    for(var x in data){
	        postData.push(x+"="+data[x]);
	    }
	}
	catch(e){
	    postData=[]
	}
	
	return postData;
}
function validateContactUsForm(id){
	//alert("Not implemented yet (sendContactUsForm function)")
	
	var form=$('#contact_us_form_'+id)
	
	
	if($('#fname_'+id).val()=="")
	{
	    alert($('#fname_'+id).attr("email_label")+" : "+dic.REQUIRED_FIELD);
		$('#fname_'+id).focus();
		return false;
	}
	if($('#lname_'+id).val()=="")
	{
	    alert($('#lname_'+id).attr("email_label")+" : "+dic.REQUIRED_FIELD);
		$('#lname_'+id).focus();
		return false;
	}
	if($('#email_'+id).val()=="")
	{
	    alert($('#email_'+id).attr("email_label")+" : "+dic.REQUIRED_FIELD);
		$('#email_'+id).focus();
		return false;
	}
	if($('#phone_'+id).val()=="")
	{
	    alert($('#phone_'+id).attr("email_label")+" : "+dic.REQUIRED_FIELD);
		$('#phone_'+id).focus();
		return false;
	}
	if($('#prephone_'+id).val()=="")
	{
	    alert($('#prephone_'+id).attr("email_label")+" : "+dic.REQUIRED_FIELD);
		$('#prephone_'+id).focus();
		return false;
	}
	var re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
	if(!re.test($('#email_'+id).val()))
	{
	    alert(dic.BAD_MAIL);
		$('#email_'+id).focus();
		return false;
	}
	var re = /^\d+$/;
	if($('#phone_'+id).val()!="" && !re.test($('#phone_'+id).val()))
	{
	    alert(dic.NUMBERS_ONLY);
		$('#phone_'+id).focus();
		return false;
	}
	var re = /^\d+$/;
	if($('#prephone_'+id).val()!="" && !re.test($('#prephone_'+id).val()))
	{
	    alert(dic.NUMBERS_ONLY);
		$('#prephone_'+id).focus();
		return false;
	}
	
	return true;
	
	
	
}
function fillAgentsLookup(id,agents_pi){
    alert("Not implemented yet (fillAgentsLookup function)")
	/*
	var regionsSelect=document.all['region_'+id]
	var agentsSelect=document.all['email_address_'+id]
	if(fillAgentsLookup.first){
		if(isnull(agents_pi)) return
		var AGENTS_LIST_URL="/site/utils/xx/getAgentsList.hx.asp?lang="+lang+"&agents_pi="+agents_pi
		fillAgentsLookup.oXML=new ActiveXObject("Microsoft.XMLDOM")
		fillAgentsLookup.oXML.async=false;
		if(!fillAgentsLookup.oXML.load(AGENTS_LIST_URL)) return

		var zones=fillAgentsLookup.oXML.documentElement.selectNodes("ZONES/ZONE")
		regionsSelect.length=zones.length+1
		regionsSelect[0].selected=true
		for(var i=1;i<zones.length+1;i++){
			var e = zones.nextNode();
			regionsSelect[i].text=e.getAttribute("label")
			regionsSelect[i].value=e.getAttribute("code")
		}
		fillAgentsLookup.first=false
	}
	else{
		var agents=fillAgentsLookup.oXML.documentElement.selectNodes("ROW[AGENT_ZONE/text()='"+regionsSelect.value+"']")
		agentsSelect.length=agents.length+1
		agentsSelect[0].selected=true
		for(var i=1;i<agents.length+1;i++){
			var e = agents.nextNode();
			agentsSelect[i].text=e.selectSingleNode("AGENT_NAME").text
			agentsSelect[i].value=e.selectSingleNode("EMAIL").text
		}
	}
	*/
}
fillAgentsLookup.first=true

function GetToursByCountry(obj, id, doc_id, destinations, country)
{
    $("#ContinentDocID"+id).val(doc_id);
    
    $("#CountryCode"+id).val(country);
    
    $("#DestCode"+id).val(destinations.replace(/,$/,''));
    
    document.getElementById("continentForm"+id).submit();
}

