﻿function RowDeal_Click(link) {
    SearchWin = window.open(link, '_self');
    SearchWin.focus();
}

function Getbgcolor(trbgcol, row) {
    if (document.all) {
        var thestyle = eval('document.all.' + row + '.style');
        thestyle.backgroundColor = trbgcol;
    }
}

function GetDialogMsg(strTitle, strRemark, intSugMsg) {
    var param = new Array();
    param[0] = strTitle;
    param[1] = strRemark;
    param[2] = intSugMsg;
    var val = window.showModalDialog("../lib/msgDialog/addItemDialog.htm", param, "dialogWidth:300px;dialogHeight:170px;help:no;resizable:no;status:no;scroll:no;");
}

function showCalendarWin() {
    var CalUrl
    var chkSE = "flight";
    var Des = document.all.DestinationID.value;
    if (Des != "") {
        //document.frmSE.submit();
    } else {
        var par1 = "נא בחר יעד לנסיעה"
        var par2 = "יעד שדה חובה"
        GetDialogMsg(par1, par2, 1);
        return false;
    }
    CalUrl = "../lib/calendarNet/setParam.asp?Des=" + Des + "&flddepDate=frmSE.tbFromDate&CurDate=&fldReturnDate=frmSE.tbReturnDate&ReturnDate=&Dep=" + chkSE;
    window.open(CalUrl, "CalWin", "width=550,height=470,resizable=yes,left=200,top=0");

}

function sendRequest() {
    //    if (document.getElementById("CountryID").value == "") {
    //        alert("נא בחר מדינה");
    //        document.getElementById("CountryID").focus();
    //        return false;
    //    }
    alert("go");
}
function Search_Click() {
    //document.frmSE.submit();
    var err = 0;
    if (document.getElementById("CountryID").value == "0") {
        alert("נא בחר מדינה");
        document.getElementById("CountryID").focus();
        err = 1;
    }
    else {
        if (document.getElementById("DestinationID").value == "0") {
            alert("נא בחר יעד");
            document.getElementById("DestinationID").focus();
            err = 1;
        }
    }

    if (err == 0) {
        var Country = document.getElementById("CountryID").value;
        var des = document.getElementById("DestinationID").value;
        var depDate = document.getElementById("tbFromDate").value;
        var ReturnDate = document.getElementById("tbReturnDate").value;
        var link = "http://www.ypaymore.co.il/flight/Flights-search.aspx?DES=" + des + "&Country=" + Country + "&Dep=package&depDate=" + depDate + "&ReturnDate=" + ReturnDate;
        SearchWin = window.open(link, '_self');
        SearchWin.focus();
    }

}



//------------------------------------------------------------------------//
//          AJAX Search
var desHe, desEn;
var ddlDestination = document.getElementById("DestinationID");
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");


function GetDataViaAJAX() {
    try {
        obj = new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch (e) {
        try {
            obj = new ActiveXObject("Msxml2.XMLHTTP.3.0");
        }
        catch (e1) {
            obj = null;
        }
    }
    if (obj != null) {
        obj.onreadystatechange = ProcessResponseXML;
        obj.open("POST", "http://www.ypaymore.co.il/NetServices/seFlightDesXML.aspx", false);
        obj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        obj.send("country=" + document.getElementById("CountryID").value);
    }
    return false;
}

function ProcessResponseXML() {
    //process xml returned from AJAX request
    if (obj.readyState == 4) {
        if (obj.status == 200) {
            //alert(obj.responseText);
            initTraverse(obj.responseText);
        }
        else {
            alert("Error retrieving data!");
        }
    }
}


function loadXML(xmlFile) {
    xmlDoc.async = "false";
    xmlDoc.onreadystatechange = verify;
    xmlDoc.loadXML(xmlFile);
}

function verify() {
    if (xmlDoc.readyState != 4)
        return false;
}

function traverse(tree) {
    if (tree.hasChildNodes()) {
        var nodes = tree.childNodes.length;
        for (var i = 0; i < tree.childNodes.length; i++)
            traverse(tree.childNodes(i));
        if (tree.tagName == "DesEn") { desEn = tree.text; }
        if (tree.tagName == "DesHe") {

            var listItem;
            desHe = tree.text;
            listItem = new Option(desHe, desEn, false, false);
            document.all["DestinationID"].add(listItem)
        }
    }
}

function initTraverse(file) {
    loadXML(file);
    var doc = xmlDoc.documentElement;
    var ddlDestination = document.getElementById("DestinationID");
    for (var count = ddlDestination.options.length - 1; count > -1; count--) {
        ddlDestination.options[count] = null;
    }

    var listItem;
    listItem = new Option("כל היעדים למדינה", "0", false, false);
    document.all["DestinationID"].add(listItem);

    traverse(doc);
}