﻿mainInitFunction = function () {
    $('#close').click(function () {
        $('#sendReviews').css({ 'display': 'none' });
    });

    $('#ibtnSendEmail').click(function () {
        var PageLink = $("#myPageLink").val();
        if ($("#Email").val() == "") { alert("נא מלא כתובת מייל"); $("#Email").focus(); return false; }
        //     alert("send to " + $("#Email").val() + " | Fullname + " + $("#FullName").val());
        //     $('#sendReviews .inTopWnd').append('<img class="loading" src="images/ajax-loader2.gif" alt="">');
        //     $('#sendReviews .submit input').attr({ 'disabled': 'disabled' });
        $.post('../lib/CheckinItems/sendItemsEmail.aspx',
              {
                  FullName: $("#FullName").val(),
                  Email: $("#Email").val(),
                  PageLink: PageLink
              }//,
        // function(data) {
        //     alert(data);
        //alert("מייל נשלח בהצלחה");
        // }
            );
        $('#sendReviews').css({ 'display': 'none' });
        alert("מייל נשלח בהצלחה");
        return false;
    });
}

//  jQuery.noConflict();
$(document).ready(function () {
    $('#pnlSR_Checked').hide("slow");
    //$('#sendReviews').css({ 'visibility': 'hidden' });
    $('#sendReviews').css({ 'display': 'none' });
    mainInitFunction();
    testBtnSendEmail();
 //   GetLoader();
    chkSE_change();
});

function GetLoader() {
    //$("#pnlSR_Loader").append($("#waiting"));
    $('#pnlSR').css({ 'display': 'none' });
    $('#pnlSR_Loader').css({ 'display': 'none' });
 //   $('#waiting').css({ 'display': 'inline' });
    $.post('CheckinItems/loaderSR.aspx',
    {
        country: $("#Country").val(),
        Destination: $("#Destination").val(),
        DateFrom: $("#tbFromDate").val(),
        DateTo: $("#tbReturnDate").val(),
        department: "flight"

    },
    function (data) {
        $('#waiting').css({ 'display': 'none' });
        $("#pnlSR_Loader").empty();
        $("#pnlSR_Loader").append(data);
        $("#pnlSR_Loader").animate({ height: "show" }, 300);
        $('#pnlSR').css({ 'display': 'inline' });
    }
);
}

function CheckStar(dep, course, checkid, id) {
    var action = "";
    var tot = 0;
    if ($("#totSelectItems").val() != "") { tot = parseInt($("#totSelectItems").val()); }
    if (document.getElementById('star_' + checkid)) {
        splitadd = document.getElementById('star_' + checkid).src;
        if (splitadd == "http://www.netravel.co.il/images/star_off.gif") {
            document.getElementById('star_' + checkid).src = "http://www.netravel.co.il/images/star_on.gif";
            action = "on";
            tot = tot + 1;
        } else {
            document.getElementById('star_' + checkid).src = "http://www.netravel.co.il/images/star_off.gif";
            action = "off";
            tot = tot - 1;
        }

        $.post('../lib/CheckinItems/CheckSR.aspx',
              {
                  checkid: checkid,
                  course: course,
                  action: action,
                  id: id,
                  department: "flight"
              },
               function (data) {
                   $("#ansv").empty();
                   $("#ansv").append(data);
                   $("#ansv").animate({ height: "show" }, 300);
               }
            );
        //    $("#lbltotalSelectedItems").text(parseInt($("#oldtotalSelectedItems").val()) + tot);
        var num
        num = parseInt($("#oldtotalSelectedItems").val()) + tot;
        $("#ibtnShowCheckedSR").text(" עיסקאות מסומנות (" + tot + ")");
        document.getElementById("totSelectItems").value = tot;
        testBtnSendEmail();
    }
}

function showHand(row) {
    // var thestyle = eval('document.getElementById("result").style');
    // thestyle.cursor = "hand";
    //  alert(" thestyle.cursor =" + thestyle.cursor);
    //  document.getElementById("result").classname = "showHand";
    document.getElementById(row).style.cursor = "hand";
    //var thestyle = eval('document.getElementById("' + row + '").class');
    //thestyle = "showHand";
}

function HiddenHand(row) {
    //   alert("row = " + row);
    var thestyle = eval('document.getElementById("result").style');
    thestyle.cursor = "default";
}
function chekOption(item) {
    if (item != "") {
        //                $('#ibtnShowCheckedSR').removeClass('notSelectFont selectFont');
        //                $('#ibtnShowAllSR').removeClass('notSelectFont selectFont');
        //                $('#tabShowChecked').removeClass('notSelectButton selectButton');
        //                $('#tabShowAll').removeClass('notSelectButton selectButton');

        document.getElementById("ibtnShowCheckedSR").className = "notSelectFont";
        document.getElementById("ibtnShowAllSR").className = "notSelectFont";
        document.getElementById("tabShowChecked").className = "notSelectButton";
        document.getElementById("tabShowAll").className = "notSelectButton";

        switch (item) {
            case "ShowChecked":
                //    $('#tabShowChecked').addClass('selectButton'); $('#ibtnShowCheckedSR').addClass('selectFont');
                document.getElementById("tabShowChecked").className = "selectButton";
                document.getElementById("ibtnShowCheckedSR").className = "selectFont";
                $.post('../lib/CheckinItems/getCheckenItems.aspx', {},
                       function (data) {
                           $("#pnlSR_Checked").empty();
                           $("#pnlSR_Checked").append(data);
                       }
                    );
                $("#pnlSR").hide();
                $("#pnlSR_Loader").hide();
                $("#pnlSR_Checked").show();
                //   alert("ShowChecked");                      
                break;

            case "ShowAll":
                //  $('#tabShowAll').addClass('selectButton'); $('#ibtnShowAllSR').addClass('selectFont');
                document.getElementById("tabShowAll").className = "selectButton";
                document.getElementById("ibtnShowAllSR").className = "selectFont";
                $("#pnlSR_Checked").hide();
                $("#pnlSR").show();
                $("#pnlSR_Loader").show();
                //  alert("ShowAll");
                break;
        }
    }
}

function delete_CheckingItem(id) {
    var item = "#lsP_" + id;
    // alert("item to delete = " + item);
    var tot = 0;
    //   alert(" totSelectItems = " + $("#totSelectItems").val());
    if ($("#totSelectItems").val() != "") {
        tot = parseInt($("#totSelectItems").val()) - 1;
        //$("#totSelectItems").val() = tot;
        document.getElementById("totSelectItems").value = tot;
    }
    document.getElementById("ibtnShowCheckedSR").innerHTML = "עיסקאות מסומנות(" + tot + ")";
    $.post('../lib/CheckinItems/getCheckenItems.aspx',
    {
        deleteItem: id
    },
        function (data) {
            $("#pnlSR_Checked").empty();
            $("#pnlSR_Checked").append(data);
        }
    );
    testBtnSendEmail();
}

function sendEmail() {
    //$('#sendReviews').css({ 'visibility': 'visible' });
    $('#sendReviews').css({ 'display': 'inline' });
    $('#FullName').focus();
}
function testBtnSendEmail() {
    var tot = parseInt($("#totSelectItems").val());
    if (tot > 0) {
        $("#lbtnSendEmail").css({ 'display': 'inline' });
    }
    else {
        $("#lbtnSendEmail").css({ 'display': 'none' });
    }
}

//-----------------
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();
}

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: 'flight'
    },
    function (data) {
        $("#popupDes").html(data);
    }
    );
    $.post('../NetServices/GetCountrysForDepartment.aspx',
    {
        Dep: 'flight'
    },
    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: 'flight',
        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();
}
function showCalendarWin() {
    closeCalendar();
    var chkSE = "flight";
    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() {
    if ($("#ifrmCalendar").contents().find("#lblDepartureDate").text() != "") {
        document.getElementById("tbFromDate").value = $("#ifrmCalendar").contents().find("#lblDepartureDate").text();
        document.getElementById("tbReturnDate").value = $("#ifrmCalendar").contents().find("#lblReturnDate").text();
    }
    if (document.getElementById("Destination").value == "") { alert("נא בחר יעד"); return false; }
    var link = "http://www.netravel.co.il/wait.aspx?dep=flight&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 loadNextItems(CarrentPage, LoadRows, Dep) {
    var div = "#page_" + Dep;
    var pageLink = "#pagelink_" + Dep + "_" + CarrentPage;
    var pagelist = "#pagelist_" + Dep + " a";
    $(pagelist).removeClass("navPagelinkSelect").addClass("navPagelink"); //.toggleClass("Pagelink");
    $(pageLink).removeClass("navPagelink").addClass("navPagelinkSelect");
    $.get('CheckinItems/GetSRItems.aspx',
        {
            CarrentPage: CarrentPage,
            LoadRows: LoadRows,
            Dep: Dep
        },
        function (data) {
            $(div).empty();
            $(div).append(data);
            $(div).animate({ height: "show" }, 300);
        }
    );
}
