﻿mainInitFunction = function () {
    $('#close').click(function () {
        $('#sendReviews').css({ 'display': 'none' });
    });

    $('#ibtnSendEmail').click(function () {
        var PageLink = $("#myPageLink").val();  // "PageLink % >";
        if ($("#Email").val() == "") { alert("נא מלא כתובת מייל"); $("#Email").focus(); return false; }
        $.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;
    });
}

$(document).ready(function () {
    chkSE_change();
    $('#pnlSR_Checked').hide("slow");
    $('#sendReviews').css({ 'display': 'none' });
    mainInitFunction();
    testBtnSendEmail();
});

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;
        }
        //                if (tot > 0) {$("#menuShowSR").animate({ height: "show" }, 300);
        //                } else {$("#menuShowSR").animate({ height: "toggle" }, 300);}
        // alert(" menuShowSR display = " + document.getElementById("menuShowSR").style.display);
        $.post('../lib/CheckinItems/CheckSR.aspx',
              {
                  checkid: checkid,
                  course: course,
                  action: action,
                  id: id,
                  department: "package"
              },
               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) {
    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_Checked").show();
                break;
            case "ShowAll":
                document.getElementById("tabShowAll").className = "selectButton";
                document.getElementById("ibtnShowAllSR").className = "selectFont";
                $("#pnlSR_Checked").hide();
                $("#pnlSR").show();
                break;
        }
    }
}

function delete_CheckingItem(id) {
    var item = "#lsP_" + id;
    var tot = 0;
    if ($("#totSelectItems").val() != "") {
        tot = parseInt($("#totSelectItems").val()) - 1;
        document.getElementById("totSelectItems").value = tot;
    }
    document.getElementById("ibtnShowCheckedSR").innerHTML = "עיסקאות מסומנות(" + tot + ")";
    $.post('CheckinItems/getCheckenItems.aspx',
        {
            deleteItem: id
        },
           function (data) {
               $("#pnlSR_Checked").empty();
               $("#pnlSR_Checked").append(data);
           }
        );
    testBtnSendEmail();
}
function sendEmail() {
    $('#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: '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();
}
function showCalendarWin() {
    closeCalendar();
    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() {
    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=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 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);
        }
    );
}
