﻿function floatingDiv(w, h, u, m, d, aj) {
    if (!m) m = "GET";
    if (!d) d = "";
    if (!aj) aj = "ajax";
    $("#lightbox-overlay").show()
    l = ($(window).width() - w) / 2 + $(window).scrollLeft()
    t = ($(window).height() - h) / 2 + $(window).scrollTop() - 50
    $("#floating").css("width", w + "px");
    $("#floating").css("height", h + "px");
    $("#floating").css("left", l + "px")
    $("#floating").css("top", "70px")
    $("#floating").css("display", "block")
    $("#floating").html("<img src='img/cross.png' style='float:right' onclick='javascript:closeOperator()'><div style='text-align:center'>Načítání...</div>")
    $('#floating').click(function (event) {
        event.stopPropagation();
    });

    ts = new Date().getTime();
    $.ajax({
        type: m,
        url: "/ajax/" + aj + ".aspx?action=" + u + "&ts=" + ts,
        data: d,
        success: function (msg) {
            showOperator(msg)
        }
    });
}

function sendJQAjax() {

}


function transferNewsSelected() {
    if ($("#incsel").attr("checked")) {
        c = getCookie()
        $("#fromselection").attr("value", c)
    } else {
        $("#fromselection").attr("value", "")
    }
}

function showSpecialOffer(t, p) {
    //if (t == "floating") {
    kuki = ""
    nameEQ = "specialoffer"
    var ca = decodeURIComponent(document.cookie).split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) kuki = c.substring(nameEQ.length + 1, c.length);
    }

    if (kuki == "" || p == "preview") {
        $("#lightbox-overlay").show()
        l = ($(window).width() - 800) / 2 + $(window).scrollLeft()

        $("#floating2").css("width", "800px")
        $("#floating2").css("left", l + "px")
        $("#floating2").css("top", "100px")
        $("#floating2").css("display", "block")
        $("#floating2").html("<img src='img/cross.png' style='float:right' onclick='javascript:closeOperator()'><div style='text-align:center'>Načítání...</div>")
        $('#floating2').click(function (event) {
            event.stopPropagation();
        });
    }

    if (p == "preview") {
        showOperator(CKEDITOR.instances.specialoffer.getData())
    } else {
        document.cookie = "specialoffer=" + encodeURIComponent("Yes; path=/");
        ts = new Date().getTime();
        $.ajax({
            type: "GET",
            url: "/ajax/ajax.aspx?action=showSpecialOffer" + "&ts=" + ts,
            success: function (msg) {
                msg = "<img src='img/cross.png' style='float:right; cursor:pointer' onclick='javascript:closeOperator()'>" + msg;
                $("#floating2").html(msg);
            }
        });
    }
    //} else {
    //    var left = (screen.width/2)-(800/2);
    //    var top = (screen.height/2)-(400/2);
    //    var targetWin = window.open ("Default.aspx", "", 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=800, height=400, top='+top+', left='+left); 
    //}
}




function copyWH(obj) {
    if (obj.checked == true) {
        flds = $(obj).attr("value").split("-")
        $("#awh" + flds[1]).attr("value", $("#awh" + flds[0]).attr("value"))
    }
}



var lastGHPfromDate = ""
var lastGHPtoDate = ""
var lastGHPstrava = ""
var lastGHPdoprava = ""
var lastGHPmisto = ""
var lastGHPlm = ""
var lastGHPfm = ""

function getHotelsPrices(hotelID, page, fromDate, toDate, doprava, misto, strava, lm, fm, userContext) {
    $("#priceCalc" + hotelID).html('Načítání...')

    if (fromDate) lastGHPfromDate = fromDate
    if (doprava) lastGHPdoprava = doprava
    if (misto) lastGHPmisto = misto
    if (strava) lastGHPstrava = strava
    if (toDate) lastGHPtoDate = toDate
    if (lm) lastGHPlm = lm
    if (fm) lastGHPfm = fm

    ts = new Date().getTime();
    $.ajax({
        type: "POST",
        url: "/ajax/ajax.aspx?action=getHotelsPrices" + "&ts=" + ts,
        data: "hotelID=" + hotelID + "&fromDate=" + lastGHPfromDate + "&toDate=" + lastGHPtoDate + "&doprava=" + lastGHPdoprava + "&misto=" + lastGHPmisto + "&strava=" + lastGHPstrava + "&lm=" + lastGHPlm + "&fm=" + lastGHPfm + "&start=" + page,
        success: function (msg) {
            $("#priceCalc" + hotelID).html(msg)
        }
    });
}

function createCookie(name, value) {
    document.cookie = name + "=" + encodeURIComponent(value + "; path=/");
}

function getCookie() {
    kuki = ""
    nameEQ = "checkedhotels"
    var ca = decodeURIComponent(document.cookie).split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) kuki = c.substring(nameEQ.length + 1, c.length);
    }
    return kuki
}

function removeSelected() {
    document.cookie = "checkedhotels=" + encodeURIComponent("; path=/");
    var checkboxes = document.getElementsByName('tabshotels[]');
    var cboxLength = checkboxes.length;

    IDs = ""
    for (i = 0; i < cboxLength; i++) {
        checkboxes[i].checked = false
    }
}

function selectAllFromPage(v) {
    var checkboxes = document.getElementsByName('tabshotels[]');
    var cboxLength = checkboxes.length;

    kuki = getCookie()

    IDs = ""
    for (i = 0; i < cboxLength; i++) {
        ex = "," + checkboxes[i].value + ","
        kuki = kuki.replace(ex, "")
        if (v == 1) {
            checkboxes[i].checked = true
            kuki += ex
        } else {
            checkboxes[i].checked = false
        }
    }
    document.cookie = "checkedhotels=" + encodeURIComponent(kuki + "; path=/");
}

//createCookie("checkedhotels", "", -1);
function addNewHotelToCheckList(obj) {
    kuki = ""
    kuki = getCookie()

    ex = "," + obj.value + ","
    if (obj.checked == true) {
        kuki += ex
    } else {
        ex = ""
        kuki = kuki.replace("," + obj.value + ",", "")
    }

    document.cookie = "checkedhotels=" + encodeURIComponent(kuki + "; path=/");

    //newurl = "#!/" + newurl + "&checked=" + IDs
    //reload = false
    //$.historyLoad(newurl);
}

var to
function showActions(obj) {
    clearTimeout(to)
    oo = $(obj).parent().position()
    ox = oo.left - 174
    oy = oo.top + 24
    $("#viber").css("margin-top", "5px")
    $("#viber").css("margin-left", "-170px")
    $("#viber").css("display", "block");
}

function preHideActions() {
    to = setTimeout("hideActions()", 400)
}

function hideActions() {
    $("#viber").css("display", "none");
}


function openTabs() {
    var checkboxes = document.getElementsByName('tabshotels[]');
    var cboxLength = checkboxes.length;

    IDs = getCookie()
    IDs = kuki.replace(/,,/g, ",")
    if (IDs != "") {
        window.location.href = 'Default.aspx?link=hotels&hotelID=' + IDs
    } else {
        alert("Musíte vybrat alespoň jeden hotel!")
    }
}

function setPDFMenu() {
    $("#vibranelink").mouseover(function () {
        showActions($(this))
    }).mouseout(function () {
        preHideActions()
    });
    $("#viber").mouseenter(function () {
        clearTimeout(to)
    }).mouseleave(function () {
        preHideActions()
    });
}

function pdfList(tt) {
    IDs = getCookie()
    IDs = kuki.replace(/,,/g, ",")
    if (IDs != "") {
        document.pdfform.action = "Default.aspx?link=hotels&pdf=" + tt;
        document.pdfform.hotelID.value = IDs;
        document.pdfform.firstpage.value = firstpage;
        document.pdfform.target = "_blank";
        document.pdfform.submit()
        //window.location.href='Default.aspx?link=hotels&pdf=' + tt + '&hotelID=' + IDs + '&firstpage=' + firstpage
    } else {
        alert("Musíte vybrat alespoň jeden hotel!")
    }
}


function emailpdfList(tt) {
    IDs = getCookie()
    IDs = kuki.replace(/,,/g, ",")

    if (IDs != "") {
        floatingDiv(400, 300, "emailpdfList", "POST", "tt="+tt)
    } else {
        alert("Musíte vybrat alespoň jeden hotel!")
    }
}

var pdf_mail = ""
var pdf_sub = ""
var pdf_bdy = ""

function sendPDF2Email(tt) {
    em = $("#emailtopdf").attr("value")
    sub = $("#emailtopdfsubject").attr("value")
    bdy = $("#emailtopdfbody").attr("value")
    if (!validateemail(em)) {
        alert("E-mailová adresa není správná!")
        return false
    } else {
        IDs = getCookie()
        IDs = kuki.replace(/,,/g, ",")

        pdf_mail = em
        pdf_sub = sub
        pdf_bdy = bdy
        $("#pdfodeslat").attr("value", "kontrola...")
        $("#pdfodeslat").attr("disabled", "disabled")

        ts = new Date().getTime();
        $.ajax({
            type: "POST",
            url: "/ajax/ajax.aspx?action=sendPDF2Email" + "&ts=" + ts,
            data: "tt=" + tt + "&em=" + em + "&IDs=" + IDs + "&firstpage=" + firstpage + "&sub=" + sub + "&bdy=" + bdy,
            success: function (msg) {
                confirmSendPDF(msg)
            }
        });
    }
}

function confirmSendPDF(result) {
    fns = result.split(";")
    conf = 0
    if (fns[1] > 1024000) {
        mb = (fns[1] / 1024) / 1024
        if (confirm("Opravdu chcete odeslat email s přílohou o velikosti " + mb.toFixed(2) + " Mb?")) {
            conf = 1
        } else {
            $("#pdfodeslat").attr("value", "Odeslat")
            $("#pdfodeslat").attr("disabled", "")
        }
    } else {
        conf = 1
    }
    if (conf == 1) {
        ts = new Date().getTime();
        $("#floating").html("<div style='text-align:center; padding:20px'>odesílání emailu...</div>")
        $.ajax({
            type: "POST",
            url: "/ajax/ajax.aspx?action=confirmSendPDF" + "&ts=" + ts,
            data: "fn=" + fns[0] + "&pdf_mail=" + pdf_mail + "&pdf_sub=" + pdf_sub + "&pdf_bdy=" + pdf_bdy,
            success: function (msg) {
                showOperator(msg)
            }
        });
    }
}

var lasttc = ""
var firsttc = ""
function switchHotel(ID) {
    if ($("#hoteltab" + ID).length > 0) {
        $("#hoteltab" + lasttc).css("display", "none")
        $("#hoteltab" + ID).css("display", "block")

        $("#htab" + lasttc).removeClass("active")
        $("#htab" + ID).addClass("active")

        lasttc = ID
    }
}

function removeHotel(ID, obj) {
    o = $(obj).parent()
    $(o).remove()
    $("#hoteltab" + ID).remove()
    $("#htab" + ID).remove()
    $(".htab:first").addClass("active")
    $(".hoteltab:first").css("display", "block")
    lasttc = $(".htab:first").attr("ID").replace("htab", "")
    if ($(".closehotels").length == 1) {
        $(".closehotels").remove()
    }
}

function showZarizeni(ID) {
    $(".zarizeni").hide()
    $("#zarizeni" + ID).toggle();
    $("#zarizeni" + ID).click(function (event) {
        event.stopPropagation();
    });
}

function showHotelsPrices(result, userContext, methodName) {
    $("#priceCalc").html(result)
    //window.location.href = "#priceCalc"
}

var assignedkeys = 0
hcou = "-1"
hsta = "-1"
hcit = "-1"
hchecked = ""
var thisdoprava = ""
iseditpage = false
function load(num) {
    if (reload == true) {
        //$("#mainlist").html("")
        nums = num.split(/&/g)
        hasstars = false
        hasdoprava = false
        hasstrava = false
        hasvb = false

        var checkboxes = document.getElementsByName('hclient[]');
        var cboxLength = checkboxes.length;
        for (j = 0; j < cboxLength; j++) {
            checkboxes[j].checked = false
        }

        for (i = 0; i < nums.length; i++) {
            if (nums[i].indexOf("dfrom") > -1) document.searchform.fromDate.value = nums[i].replace("dfrom=", "")
            if (nums[i].indexOf("dto") > -1) document.searchform.toDate.value = nums[i].replace("dto=", "")
            if (nums[i].indexOf("hn") > -1) document.searchform.hotelname.value = nums[i].replace("hn=", "")
            if (nums[i].indexOf("stars") > -1) {
                hasstars = true
                $("#advancedsearch").show()
                document.searchform.stars.value = nums[i].replace("stars=", "")
            }
            if (nums[i].indexOf("doprava") > -1) {
                $("#advancedsearch").show()
                hasdoprava = true
                thisdoprava = nums[i].replace("doprava=", "")
                lastdoprava = thisdoprava;
                document.searchform.doprava.value = nums[i].replace("doprava=", "")
            }
            if (nums[i].indexOf("strava") > -1) {
                $("#advancedsearch").show()
                hasstrava = true
                document.searchform.strava.value = nums[i].replace("strava=", "")
            }
            if (nums[i].indexOf("vlastnibusselect") > -1) {
                $("#advancedsearch").show()
                hasvb = true
                document.searchform.vlastnibusselect.value = nums[i].replace("vlastnibusselect=", "")
            }
            if (nums[i].indexOf("cena") > -1) document.searchform.cena.value = nums[i].replace("cena=", "")

            if (nums[i].indexOf("lm") > -1) {
                $("#advancedsearch").show()
                tlm = nums[i].replace("lm=", "")
                if (tlm == "Yes") {
                    document.searchform.lm.checked = true
                } else {
                    document.searchform.lm.checked = false
                }
            }

            if (nums[i].indexOf("misto") > -1 && thisdoprava == "Letecky") {
                $("#mistoselect").show()
                ubits = nums[i].replace("misto=", "").split(/,/g)

                var checkboxes = document.getElementsByName('hmisto[]');
                var cboxLength = checkboxes.length;

                uc = 0
                for (j = 0; j < cboxLength; j++) {
                    if (jQuery.inArray(checkboxes[j].value, ubits) > -1) {
                        checkboxes[j].checked = true
                        uc++
                    } else {
                        checkboxes[j].checked = false
                    }
                }
                m = ""
                if (uc == 1) {
                    $("div[id='smisto-div']").prev('INPUT.multiSelect').val($("#smisto-div input:checked").parent().text());
                } else if (uc > 0) {
                    m = '% vybráno'
                    $("div[id='smisto-div']").prev('INPUT.multiSelect').val(m.replace('%', uc));
                } else {
                    $("div[id='smisto-div']").prev('INPUT.multiSelect').val(m.replace('%', uc));
                }
            }

            if (nums[i].indexOf("country") > -1) hcou = nums[i].replace("country=", "")
            if (nums[i].indexOf("state") > -1) hsta = nums[i].replace("state=", "")
            if (nums[i].indexOf("city") > -1) hcit = nums[i].replace("city=", "")
            if (nums[i].indexOf("checked") > -1) hchecked = nums[i].replace("checked=", "")

            if (nums[i].indexOf("client") > -1) {
                ubits = nums[i].replace("client=", "").split(/,/g)

                checkboxes = document.getElementsByName('hclient[]');
                cboxLength = checkboxes.length;

                uc = 0
                for (j = 0; j < cboxLength; j++) {
                    if (jQuery.inArray(checkboxes[j].value, ubits) > -1) {
                        checkboxes[j].checked = true
                        uc++
                    } else {
                        checkboxes[j].checked = false
                    }
                }
                m = ""
                if (uc == 1) {
                    $("div[id='sclient-div']").prev('INPUT.multiSelect').val($("#sclient-div input:checked").parent().text());
                } else if (uc > 0) {
                    m = '% vybráno'
                    $("div[id='sclient-div']").prev('INPUT.multiSelect').val(m.replace('%', uc));
                } else {
                    $("div[id='sclient-div']").prev('INPUT.multiSelect').val(m.replace('%', uc));
                }
            }
            if (nums[i].indexOf("ubytovani") > -1) {
                ubits = nums[i].replace("ubytovani=", "").split(/,/g)

                checkboxes = document.getElementsByName('hubytovani[]');
                cboxLength = checkboxes.length;

                uc = 0
                for (j = 0; j < cboxLength; j++) {
                    if (jQuery.inArray(checkboxes[j].value, ubits) > -1) {
                        checkboxes[j].checked = true
                        uc++
                    } else {
                        checkboxes[j].checked = false
                    }
                }
                m = ""
                if (uc == 1) {
                    $("div[id='subytovani-div']").prev('INPUT.multiSelect').val($("#subytovani-div input:checked").parent().text());
                } else if (uc > 0) {
                    m = '% vybráno'
                    $("div[id='subytovani-div']").prev('INPUT.multiSelect').val(m.replace('%', uc));
                } else {
                    $("div[id='subytovani-div']").prev('INPUT.multiSelect').val(m.replace('%', uc));
                }
            }
        }

        if (hasdoprava == false) $("#doprava option")[0]['selected'] = true;
        if (hasstars == false) $("#stars option")[0]['selected'] = true;
        if (hasstrava == false) $("#strava option")[0]['selected'] = true;
        if (hasvb == false) $("#vlastnibusselect option")[0]['selected'] = true;

        setClients()
    }
}

function setLoading(obj) {
    var offset = $(obj).offset();
    ox = offset.left + $(obj).width() / 2 - 110
    oy = offset.top + $(obj).height() / 3

    $("#loadinggif").css("top", oy + "px")
    $("#loadinggif").css("left", ox + "px")
    $("#loadinggif").css("display", "block")
}

function stopLoading() {
    $("#loadinggif").css("display", "none")
}

var reload = true
ajaxweb = 1;
loadbook = false
loaddestinations = false
firstpage = false

function getBookings(p, userContext) {
    hcou = "-1"
    hsta = "-1"
    hcit = "-1"
    otherpage = false

    //if ($("#pagebody").length > 0) {
    //    $("#pagebody").attr("id", "mainlist")
    //    otherpage = true
    //}

    //if ($("#hotelsdetails").length > 0) {
    //    $("#hotelsdetails").attr("id", "mainlist")
    //    $("#mainlist").css("width", "756px")
    //    otherpage = true
    //}
    //if ($("#bookingcont").length > 0) {
    //    $("#bookingcont").attr("id", "mainlist")
    //    otherpage = true
    //}

    if (otherpage) {
        $("#mainlist").css("float", "left")
        $("#mainlist").html("<div class=mainheader>NABÍDKA ZÁJEZDŮ</div><div class=mainlistbody><table width=100% style='position:relative'><tr><td style='padding:40px'>&nbsp;</td></tr></table></div><div id=main_footer></div>")
        $(".navigator").remove()
    }

    $("#submitsearch").attr("value", "Hledám...")
    $("#mainlist .mainlistbody table").addClass("transp50")
    setLoading($("#mainlist .mainlistbody table"))
    //$("#submitsearch").attr("disabled", "disabled")
    //obj = $("#tabcontents")
    //obj.addClass("transp50")

    var checkboxes = document.getElementsByName('hcountry[]');
    var cboxLength = checkboxes.length;

    country = ""
    for (i = 0; i < cboxLength; i++) {
        if (checkboxes[i].checked) {
            if (country != "") country += ","
            country += checkboxes[i].value
        }
    }

    checkboxes = document.getElementsByName('hstate[]');
    cboxLength = checkboxes.length;

    state = ""
    for (i = 0; i < cboxLength; i++) {
        if (checkboxes[i].checked) {
            if (state != "") state += ","
            state += checkboxes[i].value
        }
    }

    checkboxes = document.getElementsByName('hcity[]');
    cboxLength = checkboxes.length;

    city = ""
    for (i = 0; i < cboxLength; i++) {
        if (checkboxes[i].checked) {
            if (city != "") city += ","
            city += checkboxes[i].value
        }
    }

    checkboxes = document.getElementsByName('hclient[]');
    cboxLength = checkboxes.length;

    client = ""
    for (i = 0; i < cboxLength; i++) {
        if (checkboxes[i].checked) {
            if (client != "") client += ","
            client += checkboxes[i].value
        }
    }
    dfrom = document.searchform.fromDate.value
    dto = document.searchform.toDate.value
    //cfrom = document.searchform.cenaod.value
    cfrom = ""
    cto = ""
    //cto = document.searchform.cenado.value
    cena = document.searchform.cena.value
    hn = document.searchform.hotelname.value
    lm = document.searchform.lm.checked ? "Yes" : "No"
    fm = document.searchform.fm.checked ? "Yes" : "No"

    nights = document.searchform.nights.value
    strava = document.searchform.strava.value

    //var checkboxes = document.getElementsByName('hubytovani[]');
    //var cboxLength = checkboxes.length;

    ubytovani = ""
    //for (i = 0; i < cboxLength; i++) {
    //    if (checkboxes[i].checked) {
    //        if (ubytovani != "") ubytovani += ","
    //        ubytovani += checkboxes[i].value
    //    }
    //}

    doprava = document.searchform.doprava.value
    vbselect = document.searchform.vlastnibusselect.value
    stars = document.searchform.stars.value

    checkboxes = document.getElementsByName('hmisto[]');
    cboxLength = checkboxes.length;

    misto = ""
    if (doprava != "") {
        for (i = 0; i < cboxLength; i++) {
            if (checkboxes[i].checked) {
                if (misto != "") misto += ","
                misto += checkboxes[i].value
            }
        }
    }

    checkboxes = document.getElementsByName('htype[]');
    cboxLength = checkboxes.length;

    stype = ""
    for (i = 0; i < cboxLength; i++) {
        if (checkboxes[i].checked) {
            if (stype != "") stype += ","
            stype += checkboxes[i].value
        }
    }

    sort = document.searchform.sort.value
    sortdir = document.searchform.sortdir.value

    reload = false
    nurl = "#!/"
    if (country != "") nurl += "country=" + country + "&"
    if (state != "") nurl += "state=" + state + "&"
    if (city != "") nurl += "city=" + city + "&"
    if (client != "") nurl += "client=" + client + "&"
    if (dfrom != "") nurl += "dfrom=" + dfrom + "&"
    if (dto != "") nurl += "dto=" + dto + "&"
    if (cena != "") nurl += "cena=" + cena + "&"
    if (hn != "") nurl += "hn=" + hn + "&"
    if (lm != "") nurl += "lm=" + lm + "&"
    if (fm != "") nurl += "fm=" + fm + "&"
    if (strava != "") nurl += "strava=" + strava + "&"
    if (misto != "") nurl += "misto=" + misto + "&"
    if (stars != "") nurl += "stars=" + stars + "&"
    if (vbselect != "") nurl += "vlastnibusselect=" + vbselect
    hchecked = getCookie()
    if (hchecked != "") nurl += "&checked=" + hchecked

    //window.location.href=nurl
    if (ajaxweb == 1) {
        //$.historyLoad(nurl);
    }
    lbokvars = [p, stype, country, state, city, client, dfrom, dto, cena, hn, lm, fm, nights, strava, ubytovani, doprava, misto, stars, vbselect, hchecked, firstpage, sort, sortdir, "Yes", lastbaseurl]

    ts = new Date().getTime();
    $.ajax({
        type: "POST",
        url: "/ajax/ajax.aspx?action=getBookings" + "&ts=" + ts,
        data: "p=" + p + "&stype=" + stype + "&country=" + country + "&state=" + state + "&city=" + city + "&client=" + client + "&dfrom=" + dfrom + "&dto=" + dto + "&cena=" + cena + "&hn=" + hn + "&lm=" + lm + "&fm=" + fm + "&nights=" + nights + "&strava=" + strava + "&ubytovani=" + ubytovani + "&doprava=" + doprava + "&misto=" + misto + "&stars=" + stars + "&vbselect=" + vbselect + "&hchecked=" + hchecked + "&firstpage=" + firstpage + "&sort=" + sort + "&sortdir=" + sortdir + "&updatecookies=Yes&baseurl=&session_hash=" + session_hash,
        success: function (msg) {
            listtab(msg)
        }
    });
}
var lbokvars = new Array()
var lastbaseurl = ""

function openHotel(ID) {
    window.location.href = "Default.aspx?link=hotels&hotelID=" + ID
}

function sortBy(w, f) {
    if (document.searchform.sort.value == w) {
        if (document.searchform.sortdir.value == "ASC") {
            document.searchform.sortdir.value = "DESC"
        } else {
            document.searchform.sortdir.value = "ASC"
        }
    } else {
        document.searchform.sortdir.value = "ASC"
    }
    document.searchform.sort.value = w
    eval(f)
}

function reloadBooking() {
    ts = new Date().getTime();
    $.ajax({
        type: "POST",
        url: "/ajax/ajax.aspx?action=getBookings" + "&ts=" + ts,
        data: "p=" + lbokvars[0] + "&stype=" + lbokvars[1] + "&country=" + lbokvars[2] + "&state=" + lbokvars[3] + "&city=" + lbokvars[4] + "&client=" + lbokvars[5] + "&dfrom=" + lbokvars[6] + "&dto=" + lbokvars[7] + "&cena=" + lbokvars[8] + "&hn=" + lbokvars[9] + "&lm=" + lbokvars[10] + "&fm=" + lbokvars[11] + "&nights=" + lbokvars[12] + "&strava=" + lbokvars[13] + "&ubytovani=" + lbokvars[14] + "&doprava=" + lbokvars[15] + "&misto=" + lbokvars[16] + "&stars=" + lbokvars[17] + "&vbselect=" + lbokvars[18] + "&hchecked=" + lbokvars[19] + "&firstpage=" + lbokvars[20] + "&sort=" + lbokvars[21] + "&sortdir=" + lbokvars[22] + "&updatecookies=" + lbokvars[23] + "&baseurl=" + lbokvars[24] + "&session_hash=" + session_hash,
        success: function (msg) {
            listtab(msg)
        }
    });
}

function listtab(result, userContext, methodName) {
    if (result.indexOf("loadagain") > -1) {
        d = result.split(";")
        setTimeout("reloadBooking()", 500)
    } else {
        stopLoading()
        //reload=true
        $("#submitsearch").attr("value", "Hledat")
        $("#submitsearch").removeAttr("disabled")

        obj = $("#mainlist")
        obj.removeClass("transp50")
        obj.html(result)
        setUpTRBg();
    }
}

function setUpTRBg() {
    $("#mainlist table tr").not("#viber table tr").mouseenter(function () {
        lbg = $(this).css("background-color")
        $(this).css("background-color", "#ffffb0");
        $(this).attr("lastbg", lbg);
    }).mouseleave(function () {
        lbg = $(this).attr("lastbg")
        $(this).css("background-color", lbg);
    }).css("z-index", "100");
    setPDFMenu();

    //    $("#viber table tr").mouseenter(function() {
    //$(this).css("background-color", "#ffffff");
    //  }).mouseleave(function() {
    //$(this).css("background-color", "#ffffff");
    //});
}

lastprefix = "s"
lastprefix2 = "h"
function getStates(prefix, userContext) {
    hfunc = "";
    if (!prefix || prefix == "s") {
        prefix = "s"
        prefix2 = "h"
    } else {
        prefix = "b2b"
        prefix2 = "b2b"
    }
    lastprefix = prefix
    lastprefix2 = prefix2
    $("div[id='" + prefix + "state-div'] label:not(.selectAll):not(.apply)").remove();
    $("div[id='" + prefix + "city-div'] label:not(.selectAll):not(.apply)").remove();
    $("div[id='" + prefix + "state-div'] label .selectAll").removeAttr("checked");
    $("div[id='" + prefix + "city-div'] label .selectAll").removeAttr("checked");

    $("div[id='" + prefix + "state-div']").prev('INPUT.multiSelect').val("Načítání...");
    $("div[id='" + prefix + "state-div']").prev('INPUT.multiSelect').attr("disabled", "disabled");
    $("div[id='" + prefix + "city-div']").prev('INPUT.multiSelect').val("");
    $("div[id='" + prefix + "city-div']").prev('INPUT.multiSelect').attr("disabled", "disabled");

    $("div[id='" + prefix + "country-div']").hide();
    $("div[id='" + prefix + "country-div']").prev("input").removeClass('active');

    var selectedGroups = new Array();
    selectedAll = "No"
    if ($("div[id='" + prefix + "country-div'] input[class=selectAll]").is(':checked')) selectedAll = "Yes"
    $("div[id='" + prefix + "country-div'] input[@name='" + prefix2 + "country[]']:checked").each(function () {
        selectedGroups.push($(this).val());
    });

    var selectedClients = new Array();
    selectedAllClients = "No"
    if ($("div[id='" + prefix + "client-div'] input[class=selectAll]").is(':checked')) selectedAll = "Yes"
    $("div[id='" + prefix + "client-div'] input[@name='" + prefix2 + "client[]']:checked").each(function () {
        selectedClients.push($(this).val());
    });

    var stype = new Array();
    $("div[id='" + prefix + "type-div'] input[@name='" + prefix2 + "type[]']:checked").each(function () {
        stype.push($(this).val());
    });

    ts = new Date().getTime();
    $.ajax({
        type: "POST",
        url: "/ajax/ajax.aspx?action=getStates" + "&ts=" + ts,
        data: "selectedGroups=" + selectedGroups + "&selectedAll=" + selectedAll + "&selectedClients=" + selectedClients + "&selectedAllClients=" + selectedAllClients + "&stype=" + stype,
        success: function (msg) {
            returnStates(msg)
        }
    });
}

function returnStates(result, userContext, methodName) {
    $("div[id='" + lastprefix + "state-div']").prev('INPUT.multiSelect').val("");
    $("div[id='" + lastprefix + "city-div']").prev('INPUT.multiSelect').removeAttr("disabled");
    $("div[id='" + lastprefix + "state-div']").prev('INPUT.multiSelect').removeAttr("disabled");
    var res = new Array()

    res = result.split("|")
    //$("div[id='sstate-div']").append('<label class="apply" onclick="javascript:getCities()">Apply</label>')
    totalselected = 0
    for (j = 0; j < res.length - 1; j++) {
        ln = res[j].split(";")
        ID = ln[0]
        title = ln[1]
        if (ID != "country") {
            sel = ""
            if (ln[2] == "selected") {
                sel = "checked"
                totalselected++
            }
            $("div[id='" + lastprefix + "state-div'] .multilist").append("<label><input type=checkbox name='" + lastprefix2 + "state[]' onclick='javascript:inclicked(this)' value='" + ID + "' " + sel + ">" + title + "</label>");
        } else {
            $("div[id='" + lastprefix + "state-div'] .multilist").append("<label class=cb></label><label class=cc>" + title + "</label><label class=cb></label>");
        }
    }
    if (totalselected == 0) {
        $("div[id='" + lastprefix + "state-div']").prev('INPUT.multiSelect').val("");
    } else if (totalselected==1) {
        $("div[id='" + lastprefix + "state-div']").prev('INPUT.multiSelect').val($("#" + lastprefix + "state-div input:checked").parent().text());
    } else {
        m = '% vybráno'
        $("div[id='" + lastprefix + "state-div']").prev('INPUT.multiSelect').val(m.replace('%', totalselected));
    }

    if (hsta != "-1" || iseditpage == true) {
        ubits = hsta.split(/,/g)

        var checkboxes = document.getElementsByName(lastprefix2 + 'state[]');
        var cboxLength = checkboxes.length;

        uc = 0
        for (j = 0; j < cboxLength; j++) {
            if (jQuery.inArray(checkboxes[j].value, ubits) > -1) {
                checkboxes[j].checked = true
                uc++
            } else {
                checkboxes[j].checked = false
            }
        }

        m = ""
        if (uc == 1) {
            $("div[id='" + lastprefix + "state-div']").prev('INPUT.multiSelect').val($("#" + lastprefix + "state-div input:checked").parent().text());
        } else if (uc > 0) {
            m = '% vybráno'
            $("div[id='" + lastprefix + "state-div']").prev('INPUT.multiSelect').val(m.replace('%', uc));
        } else {
            $("div[id='" + lastprefix + "state-div']").prev('INPUT.multiSelect').val(m.replace('%', uc));
        }
    }

    getCities(lastprefix)
}

var lastdoprava = "";
function getCities(prefix, userContext) {
    hfunc = "";
    if (!prefix || prefix == "s") {
        prefix = "s"
        prefix2 = "h"
    } else {
        prefix = "b2b"
        prefix2 = "b2b"
    }
    lastprefix = prefix
    lastprefix2 = prefix2
    $("div[id='" + prefix + "city-div'] label:not(.selectAll):not(.apply)").remove();
    //lastdoprava = $("#doprava").attr("value")
    $("#doprava option").remove();
    $("#doprava").append("<option value=''></option>");
    $("div[id='" + prefix + "city-div'] label .selectAll").removeAttr("checked");
    $("div[id='" + prefix + "city-div']").prev('INPUT.multiSelect').attr("value", "Načítání...");
    $("div[id='" + prefix + "city-div']").prev('INPUT.multiSelect').attr("disabled", "disabled");
    $("div[id='" + prefix + "state-div']").hide();
    $("div[id='" + prefix + "state-div']").prev("input").removeClass('active');

    var states = new Array();
    selectedAll = "No"
    ima = 0
    //if ($("div[id='sstate-div'] input[class=selectAll]").is(':checked')) selectedAll = "Yes"
    $("div[id='" + prefix + "state-div'] input[@name='" + prefix2 + "state[]']:checked").each(function () {
        if ($(this).val() != "on") states.push($(this).val());
        ima = 1
    });

    if (ima == 0) {
        $("div[id='" + prefix + "country-div'] input[@name='" + prefix2 + "country[]']:checked").each(function () {
            ima = 1
        });
        if (ima == 1) {
            $("div[id='" + prefix + "state-div'] input").each(function () {
                states.push($(this).val());
            });
        }
    }

    var selectedClients = new Array();
    selectedAllClients = "No"
    //if ($("div[id='sclient-div'] input[class=selectAll]").is(':checked')) selectedAll = "Yes"
    $("div[id='" + prefix + "client-div'] input[@name='" + prefix2 + "client[]']:checked").each(function () {
        selectedClients.push($(this).val());
    });
    var stype = new Array();
    $("div[id='" + prefix + "type-div'] input[@name='" + prefix2 + "type[]']:checked").each(function () {
        stype.push($(this).val());
    });

    ts = new Date().getTime();
    $.ajax({
        type: "POST",
        url: "/ajax/ajax.aspx?action=getCities" + "&ts=" + ts,
        data: "states=" + states + "&selectedAll=" + selectedAll + "&selectedClients=" + selectedClients + "&selectedAllClients=" + selectedAllClients + "&stype=" + stype + "&lastdoprava=" + lastdoprava,
        success: function (msg) {
            returnCities(msg)
        }
    });
}

var started = 0
function returnCities(result, userContext, methodName) {
    $("#submitsearch").attr("disabled", "")
    $("div[id='" + lastprefix + "city-div']").prev('INPUT.multiSelect').attr("value", "");
    $("div[id='" + lastprefix + "city-div']").prev('INPUT.multiSelect').removeAttr("disabled");
    var res = new Array()
    res = result.split("|")
    totalselected = 0
    dopravaselected = 0;
    for (j = 0; j < res.length - 1; j++) {
        ln = res[j].split(";")
        ID = ln[0]
        title = ln[1]
        if (ID == "country") {
            lastcountry = title
        } else if (ID == "state") {
            $("div[id='" + lastprefix + "city-div'] .multilist").append("<label class=cb></label><label class=cc>" + lastcountry + " - " + title + "</label><label class=cb></label>");
        } else if (ID == "transport") {
            sel = ""
            if (lastdoprava != "") {
                if (lastdoprava == title) sel = "selected"
            } else if (ln[2] == "selected") {
                sel = "selected"
            }
            $("#doprava").append("<option value='" + title + "' " + sel + ">" + title + "</option>");
        } else {
            sel = ""
            if (ln[2] == "selected") {
                totalselected++
                sel = "checked"
            }
            $("div[id='" + lastprefix + "city-div'] .multilist").append("<label><input type=checkbox name='" + lastprefix2 + "city[]' onclick='javascript:inclicked(this)' value='" + ID + "' " + sel + ">" + title + "</label>");
        }
    }

    if (totalselected == 0) {
        $("div[id='" + lastprefix + "city-div']").prev('INPUT.multiSelect').val("");
    } else if (totalselected == 1) {
        $("div[id='" + lastprefix + "city-div']").prev('INPUT.multiSelect').val($("#" + lastprefix + "city-div input:checked").parent().text());
    } else {
        m = '% vybráno'
        $("div[id='" + lastprefix + "city-div']").prev('INPUT.multiSelect').val(m.replace('%', totalselected));
    }

    if (started == 0) {
        if (window.location.href.indexOf("link") == -1 || window.location.href.indexOf("link=hotels&countryID") > -1) {
            if ($("#loginf").length > 0) {

            } else if (loadbook == true) {
                loadbook = false
                getBookings(1)
            }
        }
        started = 1
    }

    if (hcit != "-1" || iseditpage == true) {
        ubits = hcit.split(/,/g)

        var checkboxes = document.getElementsByName(lastprefix2 + 'city[]');
        var cboxLength = checkboxes.length;

        uc = 0
        for (j = 0; j < cboxLength; j++) {
            if (jQuery.inArray(checkboxes[j].value, ubits) > -1) {
                checkboxes[j].checked = true
                uc++
            } else {
                checkboxes[j].checked = false
            }
        }

        m = ""
        if (uc == 1) {
            $("div[id='" + lastprefix + "city-div']").prev('INPUT.multiSelect').val($("#" + lastprefix + "city-div input:checked").parent().text());
        } else if (uc > 0) {
            m = '% vybráno'
            $("div[id='" + lastprefix + "city-div']").prev('INPUT.multiSelect').val(m.replace('%', uc));
        } else {
            $("div[id='" + lastprefix + "city-div']").prev('INPUT.multiSelect').val(m.replace('%', uc));
        }
        //getBookings(1)
    }
    if (loadbook == true) {
        loadbook = false
        getBookings(1)
    }
}

function setCities(userContext) {
    $("#submitsearch").attr("disabled", "")
    hfunc = "";
    $("div[id='scity-div']").hide();
    $("div[id='scity-div']").prev("input").removeClass('active');
}

function setAirports(prefix, userContext) {
    $("#submitsearch").attr("disabled", "")
    hfunc = "";
    if (!prefix || prefix == "s") {
        prefix = "s"
        prefix2 = "h"
    } else {
        prefix = "b2b"
        prefix2 = "b2b"
    }
    lastprefix = prefix
    lastprefix2 = prefix2
    $("div[id='smisto-div']").hide();
    $("div[id='smisto-div']").prev("input").removeClass('active');

    var selectedClients = new Array();
    $("div[id='" + prefix + "client-div'] input[@name='" + prefix2 + "client[]']:checked").each(function () {
        selectedClients.push($(this).val());
    });

    var selectedCities = new Array();
    $("div[id='" + prefix + "city-div'] input[@name='" + prefix2 + "city[]']:checked").each(function () {
        selectedCities.push($(this).val());
    });

    var stype = new Array();
    $("div[id='" + prefix + "type-div'] input[@name='" + prefix2 + "type[]']:checked").each(function () {
        stype.push($(this).val());
    });

    var states = new Array();
    selectedAll = "No"
    ima = 0
    //if ($("div[id='sstate-div'] input[class=selectAll]").is(':checked')) selectedAll = "Yes"
    $("div[id='" + prefix + "state-div'] input[@name='" + prefix2 + "state[]']:checked").each(function () {
        if ($(this).val() != "on") states.push($(this).val());
        ima = 1
    });

    if (ima == 0) {
        $("div[id='" + prefix + "country-div'] input[@name='" + prefix2 + "country[]']:checked").each(function () {
            ima = 1
        });
        if (ima == 1) {
            $("div[id='" + prefix + "state-div'] input").each(function () {
                states.push($(this).val());
            });
        }
    }

    ts = new Date().getTime();
    $.ajax({
        type: "POST",
        url: "/ajax/ajax.aspx?action=getTransport" + "&ts=" + ts,
        data: "states=" + states + "&selectedClients=" + selectedClients + "&selectedCities=" + selectedCities + "&stype=" + stype,
        success: function (msg) {
            returnTransport(msg)
        }
    });
}

function returnTransport(result, userContext, methodName) {
    if (result != "") {
        $("#doprava option").remove();
        $("#doprava").append("<option value=''></option>");

        var res = new Array()
        res = result.split("|")
        for (j = 0; j < res.length - 1; j++) {
            title = res[j]
            sel = ""
            if (lastdoprava == title) sel = "selected"
            $("#doprava").append("<option value='" + title + "' " + sel + ">" + title + "</option>");
        }
    }
}


function setUbitovany(userContext) {
    $("div[id='ubytovani-div']").hide();
    $("div[id='ubytovani-div']").prev("input").removeClass('active');
}

function setStype() {
    stype = document.searchform.stype.value

    ts = new Date().getTime();
    $.ajax({
        type: "POST",
        url: "/ajax/ajax.aspx?action=getCountries" + "&ts=" + ts,
        data: "selectedGroups=" + selectedGroups + "&selectedAll=" + selectedAll + "&stype=" + stype,
        success: function (msg) {
            returnCountries(msg)
        }
    });
}

function setClients(prefix, userContext) {
    hfunc = "";
    if (!prefix || prefix == "s") {
        prefix = "s"
        prefix2 = "h"
    } else {
        prefix = "b2b"
        prefix2 = "b2b"
    }
    lastprefix = prefix
    lastprefix2 = prefix2
    $("div[id='" + prefix + "country-div'] label:not(.selectAll):not(.apply)").remove();
    $("div[id='" + prefix + "state-div'] label:not(.selectAll):not(.apply)").remove();
    $("div[id='" + prefix + "city-div'] label:not(.selectAll):not(.apply)").remove();
    $("div[id='" + prefix + "country-div'] label .selectAll").removeAttr("checked");
    $("div[id='" + prefix + "state-div'] label .selectAll").removeAttr("checked");
    $("div[id='" + prefix + "city-div'] label .selectAll").removeAttr("checked");

    $("div[id='" + prefix + "country-div']").prev('INPUT.multiSelect').val("Načítání...");
    $("div[id='" + prefix + "country-div']").prev('INPUT.multiSelect').attr("disabled", "disabled");
    $("div[id='" + prefix + "state-div']").prev('INPUT.multiSelect').val("");
    $("div[id='" + prefix + "state-div']").prev('INPUT.multiSelect').attr("disabled", "disabled");
    $("div[id='" + prefix + "city-div']").prev('INPUT.multiSelect').val("");
    $("div[id='" + prefix + "city-div']").prev('INPUT.multiSelect').attr("disabled", "disabled");

    $("div[id='" + prefix + "client-div']").hide();
    $("div[id='" + prefix + "client-div']").prev("input").removeClass('active');

    var selectedGroups = new Array();
    selectedAll = "No"
    if ($("div[id='" + prefix + "client-div'] input[class=selectAll]").is(':checked')) selectedAll = "Yes"
    $("div[id='" + prefix + "client-div'] input[@name='" + prefix2 + "client[]']:checked").each(function () {
        selectedGroups.push($(this).val());
    });

    $("div[id='" + prefix + "type-div']").hide();
    $("div[id='" + prefix + "type-div']").prev("input").removeClass('active');

    var stype = new Array();
    $("div[id='" + prefix + "type-div'] input[@name='" + prefix2 + "type[]']:checked").each(function () {
        stype.push($(this).val());
    });
    $("div[id='" + prefix + "type-div'] label:not(.selectAll):not(.apply)").remove();
    $("div[id='" + prefix + "type-div']").prev('INPUT.multiSelect').val("");

    ts = new Date().getTime();
    $.ajax({
        type: "POST",
        url: "/ajax/ajax.aspx?action=getCountries" + "&ts=" + ts,
        data: "selectedGroups=" + selectedGroups + "&selectedAll=" + selectedAll + "&stype=" + stype,
        success: function (msg) {
            returnCountries(msg)
        }
    });
}


function returnCountries(result, userContext, methodName) {
    $("div[id='" + lastprefix + "country-div']").prev('INPUT.multiSelect').val("");
    $("div[id='" + lastprefix + "state-div']").prev('INPUT.multiSelect').val("");
    $("div[id='" + lastprefix + "city-div']").prev('INPUT.multiSelect').val("");
    $("div[id='" + lastprefix + "country-div']").prev('INPUT.multiSelect').removeAttr("disabled");
    var res = new Array()
    res = result.split("|")
    totalselected = 0
    for (j = 0; j < res.length - 1; j++) {
        ln = res[j].split(";")
        ID = ln[0]
        title = ln[1]

        if (ID == "TYPES") {
            for (gg = 1; gg < ln.length; gg += 2) {
                ID = ln[gg];
                nextgg = gg + 1
                sel = ""
                if (ln[nextgg] == "selected") {
                    sel = "checked"
                    totalselected++
                }
                title = tourtypes[ID]

                $("div[id='" + lastprefix + "type-div']  .multilist").append("<label><input type=checkbox name='" + lastprefix2 + "type[]' onclick='javascript:inclicked(this)' value='" + ID + "' " + sel + ">" + title + "</label>");
            }
            if (totalselected == 0) {
                $("div[id='" + lastprefix + "type-div']").prev('INPUT.multiSelect').val("");
            } else if (totalselected == 1) {
                $("div[id='" + lastprefix + "type-div']").prev('INPUT.multiSelect').val($("#" + lastprefix + "type-div input:checked").parent().text());
            } else {
                m = '% vybráno'
                $("div[id='" + lastprefix + "type-div']").prev('INPUT.multiSelect').val(m.replace('%', totalselected));
            }
            totalselected = 0;
        } else {
            sel = ""
            if (ln[2] == "selected") {
                sel = "checked"
                totalselected++
            }

            $("div[id='" + lastprefix + "country-div']  .multilist").append("<label><input type=checkbox name='" + lastprefix2 + "country[]' onclick='javascript:inclicked(this)' value='" + ID + "' " + sel + ">" + title + "</label>");
        }
    }

    if (totalselected == 0) {
        $("div[id='" + lastprefix + "country-div']").prev('INPUT.multiSelect').val("");
    } else if (totalselected == 1) {
        $("div[id='" + lastprefix + "country-div']").prev('INPUT.multiSelect').val($("#" + lastprefix + "country-div input:checked").parent().text());
    } else {
        m = '% vybráno'
        $("div[id='" + lastprefix + "country-div']").prev('INPUT.multiSelect').val(m.replace('%', totalselected));
    }

    if (hcou != "-1" || iseditpage == true) {
        ubits = hcou.split(/,/g)

        var checkboxes = document.getElementsByName(lastprefix2 + "country[]");
        var cboxLength = checkboxes.length;

        uc = 0
        for (j = 0; j < cboxLength; j++) {
            if (jQuery.inArray(checkboxes[j].value, ubits) > -1) {
                checkboxes[j].checked = true
                uc++
            } else {
                checkboxes[j].checked = false
            }
        }

        m = ""
        if (uc == 1) {
            $("div[id='" + lastprefix + "country-div']").prev('INPUT.multiSelect').val($("#" + lastprefix + "country-div input:checked").parent().text());
        } else if (uc > 0) {
            m = '% vybráno'
            $("div[id='" + lastprefix + "country-div']").prev('INPUT.multiSelect').val(m.replace('%', uc));
        } else {
            $("div[id='" + lastprefix + "country-div']").prev('INPUT.multiSelect').val(m.replace('%', uc));
        }
        getStates()
    } else {
        getStates(lastprefix)
    }
}


if (typeof (Sys) !== "undefined") Sys.Application.notifyScriptLoaded();

function inclicked(obj) {
    var i = 0, s = '';
    o = obj.name
    o = o.replace("[]", "-div")
    if (o.indexOf("b2b") == -1) {
        o = "s" + o.substring(1, o.length)
    }

    $("div[id='" + o + "']").find('INPUT:checkbox:checked').not('.selectAll').each(function () {
        i++;
    })
    if (i == 0) {
        $("div[id='" + o + "']").prev('INPUT.multiSelect').val("");
    } else if (i==1) {
        $("div[id='" + o + "']").prev('INPUT.multiSelect').val($("#" + o + " input:checked").parent().text());
    } else {
        m = '% vybráno'
        $("div[id='" + o + "']").prev('INPUT.multiSelect').val(m.replace('%', i));
    }
}

function allclicked(obj) {
    var i = 0, s = '';
    //o = obj.name
    //o = o.replace("[]", "-div")
    //o = "s" + o.substring(1, o.length)

    o = $(obj).attr("id")

    $("div[id='" + o + "']").find('INPUT:checkbox:checked').not('.selectAll').each(function () {
        i++;
    })
    if (i == 0) {
        $("div[id='" + o + "']").prev('INPUT.multiSelect').val("");
    } else if (i == 1) {
        $("div[id='" + o + "']").prev('INPUT.multiSelect').val($("#" + o + " input:checked").parent().text());
    } else {
        m = '% vybráno'
        $("div[id='" + o + "']").prev('INPUT.multiSelect').val(m.replace('%', i));
    }
}

function closeOperator() {
    $("#container").removeClass("transp50");
    $("#lightbox-overlay").hide();
    $("#floating").css("display", "none");
    $("#floating2").css("display", "none");
}

function showOperator(result, userContext, methodName) {
    result = "<img src='img/cross.png' style='float:right; cursor:pointer' onclick='javascript:closeOperator()'>" + result
    $("#floating").html(result)
}



function showCalc(ID) {
    $("#lightbox-overlay").show()
    l = ($(window).width() - 600) / 2 + $(window).scrollLeft() - 50
    h = parseInt($(window).height() - 100)
    t = 40 + $(window).scrollTop()
    $("#floating").css("width", "600px")
    $("#floating").css("height", h + "px")
    $("#floating").css("left", l + "px")
    $("#floating").css("top", "50px")
    $("#floating").css("display", "block")
    $("#floating").html("<img src='img/cross.png' style='float:right' onclick='javascript:closeOperator()'><div style='text-align:center'>Načítání...</div>")
    $('#floating').click(function (event) {
        event.stopPropagation();
    });

    ts = new Date().getTime();
    $.ajax({
        type: "POST",
        url: "/ajax/ajax.aspx?action=showCalc" + "&ts=" + ts,
        data: "ID=" + ID,
        success: function (msg) {
            showOperator(msg)
        }
    });
}


function calculate(obj) {
    var tot = 0
    var thisval = 0
    c = $(obj).attr("class")
    $("." + c).each(function () {
        thisval = $(this).next().attr("value") * $(this).attr("value")
        tot += thisval
        $(this).parent().next().html(thisval + " Kč")
    });

    $("#" + c + "total").html(tot + " Kč")
}
