﻿
mainInitFunction = function() {
    $('#close').click(function() {
        $('#sendReviews').css({ 'display': 'none' });
    });


    $('#ibtnSendEmail').click(function() {
        var PageLink = "<%=PageLink%>";
        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('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();
});

function CheckStar(dep, course, checkid) {
    // alert("dep = " +dep + ', checkid = ' + checkid + ', course= ' + course);
    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('CheckinItems/CheckSR.aspx',
              {
                  checkid: checkid,
                  course: course,
                  action: action
              },
               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('CheckinItems/getCheckenItems.aspx', {},
                       function(data) {
                           $("#pnlSR_Checked").empty();
                           $("#pnlSR_Checked").append(data);
                       }
                    );
                $("#pnlSR").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();
                //  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('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 Destination_Change() {
    document.getElementById("DesCode").value = document.getElementById("DestinationID").value;
}
function showCalendarWin() {
    var CalUrl
    var chkSE = "flight";
    var Des = document.all.DestinationID.value;
    if (Des == "0") {
        alert("אנא בחר יעד לנסיעה \n יעד שדה חובה");
        return false;
    }
    CalUrl = "../lib/calendarNet/CalendarNetW.aspx?Des=" + Des + "&flddepDate=frmSE.tbFromDate&CurDate=&fldReturnDate=frmSE.tbReturnDate&ReturnDate=&Dep=" + chkSE;
    window.open(CalUrl, "CalWin", "width=540,height=360,resizable=yes,left=230,top=170");
}

function CheckData() {
    if ((document.getElementById("DestinationID").value == "") || (document.getElementById("DestinationID").value == "0")) {
        alert("אנא בחר יעד");
        document.getElementById("DestinationID").focus();
        return false;
    }
    var link = "http://www.netravel.co.il/wait.aspx?dep=flight&Des=" + document.getElementById("DestinationID").value + "&Country=" + document.getElementById("CountryID").value + "&depDate=" + document.getElementById("tbFromDate").value + "&ReturnDate=" + document.getElementById("tbReturnDate").value;
    SearchWin = window.open(link, '_self');
}
function GetDataViaAJAX() {
    $.post('CheckinItems/seFlightDes.aspx',
            {
                country: $('#CountryID').val() //country: document.getElementById("CountryID").value
            },
            function(data) {
                //alert("country : " + $('#CountryID').val() + " ! ansv = " + data);
                $('#DestinationID').empty();
                $('#DestinationID').append(data);
            });
}
