﻿/*****************************/
//  MENU
/*****************************/

var i, t, ddid;

function showmenu(id) {
    clear_t();
    i = 1;
    while (document.getElementById('smenu' + i)) {
        document.getElementById('smenu' + i).style.display = 'none';
        i++;
    }
    doc = document.getElementById(id);
    if (doc)
        doc.style.display = 'block';
}

function hidemenu(id) {
    clear_t();
    ddid = id;
    t = window.setTimeout("document.getElementById(ddid).style.display='none'", 300);
}


function hidepodmenu(id) {
    document.getElementById(id).style.display = 'none';
}

function clear_t() {
    clearTimeout(t);
}

/*****************************/
//  FORUM
/*****************************/

function ConfDel(delUrl, lang) {
    switch (lang) {
        case 'cs':
            if (confirm("Opravdu chcete smazat příspěvek?"))
                document.location = delUrl;
            break;
        case 'en':
            if (confirm("Are you sure you want to delete this post?"))
                document.location = delUrl;
            break;
    }
}

function Smile(what, where) {
    $("#forumText").focus();
    $("#forumText").val($("#forumText").val() + what);
    
    /*document.forms.comment.S1.focus();
    document.forms.comment.S1.value =
    document.forms.comment.S1.value + what;*/
}

/*****************************/
//  Zbytek
/*****************************/

function HideTable(id) {
    SetVisibility(document.getElementById(id), false, true);
}

function Remove(Id) {
    SetVisibility(document.getElementById(Id), false, false);
}

function Show(Id) {
    SetVisibility(document.getElementById(Id), true);
}


function SetVisibility(element, showItSwitch, keepPlacementSwitch) {
    if (showItSwitch) {
        element.style.display = "inline";
        element.style.visibility = "visible";
    }
    else {
        if (keepPlacementSwitch) {
            element.style.display = "inline";
            element.style.visibility = "hidden";
        }
        else {
            element.style.display = "none";
        }
    }
}

function blick(id, all) 
{
    for (var i = 0; i < all.length; i++) 
    {
        if (id != all[i])
            $("#" + all[i]).fadeOut(0);
    }
    $("#" + id).fadeIn(200);
}

function articleInit(all) 
{
    for (var i = 0; i < all.length; i++)
        $("#" + all[i]).fadeOut(0);

    $("#" + all[0]).fadeIn(0);
}

function hiding(id) 
{
    if ($("#" + id).is(":visible")) 
    {
        $("#" + id).fadeOut(200);
    }
    else
        $("#" + id).fadeIn(200);
}

/*****************************/
//  CLASS FORM
/*****************************/

function Log(message) 
{
    if (!$("#message").is(":visible")) 
    {
        $("#message").html(message);
        $("#message").fadeIn(300);
        setInterval(function () 
        {
            $("#message").fadeOut(300);
        }, 2000);
    }
}

$(document).ready(function () 
{
    $('#__editForm').submit(function () 
    {
        submit = true;
        var i = 0;
        var inputs = new Array(30);
        $('.__dbFormRequired').each(function () 
        {
            if ($(this).val() == '') 
            {
                inputs[i] = $(this).attr('name');
                if ($('#err' + inputs[i]).length == 0) 
                {
                    $(this).parent().append(
                        '<div id="err' + inputs[i] +
                        '"><span class="error">Toto Pole je povinne!</span></div>');
                }
                else $('#err' + inputs[i]).fadeIn("fast");

                $(this).focus(function () 
                {
                    for (j = 0; j < inputs.length; j++)
                    {
                        if ($('#err' + inputs[j]).length != 0 && inputs[j] == $(this).attr('name')) 
                        {
                           $('#err' + inputs[j]).fadeOut("fast");
                        }
                    }
                });
                submit = false;
            }
            i++;
        });
        return submit;
    });
});

    /*****************************/
    //  CLASS DBTable
    /*****************************/

function DbTableInit(id, wrapperId) 
{
    //alert('#' + wrapperId + ' > .ajaxload');
    $('#' + wrapperId + ' .ajaxload').click(function () 
    {
        $('#' + wrapperId).html(
            '<div style="position: absolute; '
             + 'height: '+ $('#' + id).height() + ';'
             + 'width: ' + $('#' + id).width()  + ';'
             + 'text-align: center;">' + 
            '<img style="position: relative; top: 40%;" src="/js/loading.gif" alt="">' +
            '</div>' + $('#' + wrapperId).html());

        $('#' + wrapperId).fadeTo("fast", 0.33).load($(this).attr('href') + ' #' + id, function () 
        {
            DbTableInit(id, wrapperId);
            $('#' + wrapperId).fadeTo("fast", 1);
        });
        return false;
    });
}


function AjaxPanelInit(id, wrapperId) 
{
    height = $('#' + id).css('height');
    $('#' + wrapperId + ' a').click(function () 
    {
        if ($(this).attr('class') != "noAjax")
        {
            $('#' + wrapperId + ' a').click(function()
            { return false; });

            $('#' + wrapperId).append(
                '<div style="position: absolute; '
                 + 'height: '+ $('#' + id).height() + ';'
                 + 'width: ' + $('#' + id).width()  + ';'
                 + 'text-align: center;">' + 
                '<img style="position: relative; top: 40%;" src="/js/loading.gif" alt="">' +
                '</div>');

                // + $('#' + wrapperId).html()

            $('#' + id).fadeTo("fast", 0.33);
            $('#' + id).css('height', height);
            $('#' + wrapperId).load($(this).attr('href') + ' #' + id, function () 
            {
                AjaxPanelInit(id, wrapperId);
                $('#' + id).fadeTo("fast", 1);
            });
            return false;
        }
    });
}



