﻿function checkIfGroupIsValid(group) {

    return Page_ClientValidate(group);


}

function MM_changeProp(objId, x, theProp, theValue) { //v9.0
    var obj = null; with (document) {
        if (getElementById)
            obj = getElementById(objId);
    }
    if (obj) {
        if (theValue == true || theValue == false)
            eval("obj.style." + theProp + "=" + theValue);
        else eval("obj.style." + theProp + "='" + theValue + "'");
    }
}

function onLoginEnter(evt, ctrl, groupname) {
    var keyCode = null;

    if (evt.which) {
        keyCode = evt.which;
    } else if (evt.keyCode) {
        keyCode = evt.keyCode;
    }
    if (13 == keyCode && checkIfGroupIsValid(groupname)) {
        document.getElementById(ctrl).click();
        return false;
    }
    return true;
}

function ValidateLogin(groupname) {
        if (checkIfGroupIsValid(groupname)) {
        return true;
    }
    return false;
}
/*
$(document).ready(function () {
    try {
        $("a.a_iframe_warenkorb").fancybox({
            'titleShow': false,
            'hideOnOverlayClick': true,
            'hideOnContentClick': false,
            'type': 'iframe',
            'scrolling': 'no',
            'width': 900,
            'onClosed': function () {
                __doPostBack();
            }
        });
    } catch (ex) { }
});
*/

function loadingAnim(load,el1, el2) {
    if (load == 1) {

        $("#"+el1).fadeTo(400, 0, function () {
            // Animation complete.
            $(this).css("visibility", "hidden");
        });
        $("#"+el2).css("display", "block");

    }
    else {
        $("#" +el2).css("display", "none");
        $("#" +el1).css("visibility", "visible");
        $("#"+el1).fadeTo(400, 1, function () {
            // Animation complete.
        });
    }
}

function loadingAnimWithParam(load, el1, el2,fadeToParam) {
    if (load == 1) {

        $("#" + el1).fadeTo(400, fadeToParam, function () {
            // Animation complete.
            //$(this).css("visibility", "hidden");
        });
        $("#" + el2).css("display", "block");

    }
    else {
        $("#" + el2).css("display", "none");
     //   $("#" + el1).css("visibility", "visible");
        $("#" + el1).fadeTo(400, 1, function () {
            // Animation complete.
        });
    }
}

jQuery.fn.center = function () {
    this.css("position", "fixed");
    this.css("top", ($(window).height() - this.height()) / 2 + $(window).scrollTop() + "px");
    this.css("left", ($(window).width() - this.width()) / 2 + $(window).scrollLeft() + "px");
    return this;
}

function clearRightPane() {
    try {
        var ucontainers = $("* > *[definition=ucontainer][class=DIV_content_Halfwidth]");

        for (p = 1; p <= $(ucontainers).length; p++) {
            var panes = $(ucontainers[p - 1]).find("*[class=module]");
            var length = $(panes).length;
            var done = 0;

            for (i = 1; i <= length; i++) {
                if (i % 2 == 0 && i < length) {
                    done = 1;
                    $($(panes)[i - 1]).after("<div class='cleaer'></div>");
                }
                else {
                    done = 0;
                }
            }
        }
    }
    catch (exc) {

    }
}




function loadingWKAnim(load, el1, el2) {
    if (load == 1) {

        $("#" + el1).fadeTo(400, 0, function () {
            // Animation complete.
            $(this).css("display", "none");
        });
        $("#" + el2).css("display", "block");

    }
    else {
        $("#" + el2).css("display", "none");

        $("#" + el1).css("display", "auto");
        $("#" + el1).fadeTo(400, 1, function () {
            // Animation complete.
        });
    }
}


function changeCnt(full, stud, kid) {
    var cnt;
    try {
        cnt = $("#" + full).attr("cnt");
        cnt = cnt - 0;
        if (cnt * 0 != 0) cnt = 10;

    } catch (Ex2) {
        cnt = 10;
    }

    var val_full = initTicketList(full);
    var val_stud = initTicketList(stud);
    var val_kid = initTicketList(kid);

    var sum = 0;

    var val_full_max = getMaxTicketCount(val_stud, val_kid, cnt);
    var val_stud_max = getMaxTicketCount(val_full, val_kid, cnt);
    var val_kid_max = getMaxTicketCount(val_full, val_stud, cnt);


    if (val_full != null) sum += val_full;
    if (val_stud != null) sum += val_stud;
    if (val_kid != null) sum += val_kid;

    for (var i = 1; i <= cnt; i++) {

        try {
            if (i <= val_full_max)
                $("#" + full).append($('<option> </option>').val(i).html(i));
        } catch (exx) { }
        try {
            if (i <= val_stud_max)
                $("#" + stud).append($('<option> </option>').val(i).html(i));
        } catch (exx) { }
        try {
            if (i <= val_kid_max)
                $("#" + kid).append($('<option> </option>').val(i).html(i));
        } catch (exx) { }

    }

    setOldTicketValue(full, val_full, val_full_max);
    setOldTicketValue(stud, val_stud, val_stud_max);
    setOldTicketValue(kid, val_kid, val_kid_max);


}

function setOldTicketValue(el, old, max) {
    try {
        if (max >= old)
            $("#" + el).val(old);
        else $("#" + el).val(max);
    } catch (tt) { }
}
function getMaxTicketCount(el1, el2, m) {
    var max = m;
    if (el1 != null) max -= el1;
    if (el2 != null) max -= el2;

    return max;
}



function initTicketList(list) {
    try {
        var selvals = $("#" + list).val();
        selvals = selvals - 0;
        if (selvals * 0 != 0) selvals = 0;
        $("#" + list + ">option").remove();

        $("#" + list).append($('<option> </option>').val(0).html('--'));

        return selvals;
    } catch (ex1) {
        return null;
    }
}
