﻿function Getbgcolor(trbgcol, row) {
    if (document.all) {
        var thestyle = eval('document.all.' + row + '.style');
        thestyle.backgroundColor = trbgcol;
    }
}
function showCalendarWin() {
    var chkSE = "package";
    var Des = document.getElementById("Destination").value;
    if (Des == "") { alert("נא הקלד יעד לנסיעה \n יעד שדה חובה"); return false; }
    $("#calendarPopup").css("display", "inline");
    var CalUrl = "http://www.netravel.co.il/lib/calendarNet/Calendar.aspx?Des=" + Des + "&flddepDate=frmSE.tbFromDate&CurDate=&fldReturnDate=frmSE.tbReturnDate&ReturnDate=&Dep=" + chkSE;
    var ifr = "<iframe id='ifrmCalendar' name='ifrmCalendar' src='" + CalUrl + "' width='500' height='260' frameborder='0' />"
    $("#frmCalendarPopup").append(ifr);

}
function closeCalendar() {
    $("#calendarPopup").css("display", "none");
    $("#frmCalendarPopup").empty();
}
function btnSubmit() {
    document.getElementById("tbFromDate").value = $("#ifrmCalendar").contents().find("#lblDepartureDate").text();
    document.getElementById("tbReturnDate").value = $("#ifrmCalendar").contents().find("#lblReturnDate").text();
    if (document.getElementById("Destination").value == "") {
        alert("נה בחר יעד"); document.getElementById("Destination").focus(); return false;
    }
    var link = "http://www.netravel.co.il/wait.aspx?dep=package&Des=" + document.getElementById("Destination").value + "&Country=" + document.getElementById("Country").value + "&depDate=" + document.getElementById("tbFromDate").value + "&ReturnDate=" + document.getElementById("tbReturnDate").value;
    SearchWin = window.open(link, '_self');
}

function CheckData() {
    if ((document.getElementById("Destination").value == "") || (document.getElementById("Destination").value == "0")) {
        alert("נא בחר יעד");
        //document.getElementById("Destination").focus();
        return false;
    }
    //  var Dep = ""    //document.getElementById("DepartmentID").value;
    //  if(Dep=="0"){Dep="";}
    //  var link ="../../package/?Des=" + document.getElementById("Destination").value + "&Country=" + document.getElementById("Country").value + "&DepID=" + Dep
    //  link = link + "&depDate=" + document.getElementById("tbFromDate").value + "&ReturnDate=" + document.getElementById("tbReturnDate").value;
    //	SearchWin = window.open(link,"_self");

    var link = "http://www.netravel.co.il/wait.aspx?dep=package&Des=" + document.getElementById("Destination").value + "&Country=" + document.getElementById("Country").value + "&depDate=" + document.getElementById("tbFromDate").value + "&ReturnDate=" + document.getElementById("tbReturnDate").value;
    SearchWin = window.open(link, '_self');
}
//  AJAX CODE   *************************************************************************** //
var obj = null;
function GetDataViaAJAX() {
    if (window.XMLHttpRequest) {
        // code for IE7+, Firefox, Chrome, Opera, Safari
        obj = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) {
        // code for IE6, IE5
        obj = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else {
        alert("Your browser does not support XMLHTTP!");
    }
    if (obj != null) {
        var url = "http://www.netravel.co.il/NetServices/sePacckageDes.aspx?country=" + document.getElementById("Country").value;
        obj.onreadystatechange = ProcessResponseXML;
        obj.open("POST", url, true);
        obj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        obj.send(null);
    }
    return false;
}

function ProcessResponseXML() {
    //process xml returned from AJAX request
    if (obj.readyState == 4) {
        if (obj.status == 200) {
            //alert("obj.responseText = " + obj.responseText);
            document.getElementById("divDestination").innerHTML = obj.responseText; //html;           
        }
        else {alert("Error retrieving data!");}
    }
}
function showSearchPopup() {
    document.getElementById("searchPopup").style.display = "inline";
    var point = document.getElementById("SearchPoint");
    var top = point.style.top;
    document.getElementById("searchPopup").style.top = 245;
    document.getElementById("searchPopup").style.left = point.style.left;
    document.getElementById("searchPopup").style.display = "inline";
    document.getElementById("CountryPopup").focus();
    //            var p = $("#serch");
    //            var position = p.position();
    //            $('#searchPopup').css("left: " + position.left + ", top: " + position.top);
    //            $('#searchPopup').css({ 'display': 'inline' });

    //            var pos = $("#serch").offset();
    //            var width = $("#serch").width();
    //            //show the menu directly over the placeholder
    //            $("#searchPopup").css({ "left": (pos.left + width) + "px", "top": pos.top + "px" });
    //            $("#searchPopup").show();

    //$('#searchPopup').css({ 'top': '" + point.style.top +"' });
    //$('#searchPopup').css({ 'display': 'inline' });
}
function popupSelectDes(country, des, DesHe) {
    //   $('#searchPopup').css({ 'display': 'none' });
    document.getElementById("searchPopup").style.display = "none";
    document.getElementById("Country").value = country;
    document.getElementById("Destination").value = des;
    document.getElementById("DestinationHeb").value = DesHe;
}
function closeSEPopup() {
    document.getElementById("searchPopup").style.display = "none";
    document.getElementById("tbFromDate").focus();
}
function chkSE_change() {
    document.getElementById("Country").value = "";
    document.getElementById("Destination").value = "";
    document.getElementById("DestinationHeb").value = "";
    $.post('../../NetServices/GetDestinationsForDepartment.aspx',
            {
                Dep: 'package'
            },
            function (data) {
                $("#popupDes").html(data);
            }
            );
    $.post('../../NetServices/GetCountrysForDepartment.aspx',
            {
                Dep: 'package'
            },
            function (data) {
                $("#divCountryPopup").html(data);
            }
            );
    $("#divDestinationPopup").html("<select ID='DestinationPopup' name='DestinationPopup' class='field' style='Width:130px;Height:20px;' dir='rtl' />");
}
function CountryPopup_change() {
    document.getElementById("DestinationHeb").value = "";
    document.getElementById("Destination").value = "";
    document.getElementById("Country").value = $("#CountryPopup").val();
    $.post('../../NetServices/GetDestinationCmb.aspx',
            {
                Dep: 'package',
                Country: $("#CountryPopup").val()
            },
            function (data) {
                $("#divDestinationPopup").html(data);
            }
            );

}
function DestinationPopup_change() {
    document.getElementById("Destination").value = $("#DestinationPopup").val();
    var variable = $("#DestinationPopup");
    var actualText = variable.find(":selected").text();
    document.getElementById("DestinationHeb").value = actualText;
    document.getElementById("searchPopup").style.display = "none";
    document.getElementById("tbFromDate").focus();
}
function selectDesPopup() {
    if (document.getElementById("DestinationPopup").value == "") {
        alert("נא בחר יעד \n יעד - שדה חובה");
        document.getElementById("DestinationPopup").focus();
        return false;
    }
    DestinationPopup_change();
}
