// JavaScript Document
dirImages = '/reklama.bzcompany.cz/images/';

function getElement(name)
{
    if (document.getElementById)
    return document.getElementById(name)
    else if (document.all)
    return document.all.name
    return false;
}

function trySubmit (id)
{
    if ( form = getElement(id) ) form.submit();
}

function wMail(login, domain, link, name)
{
    if (link)
        document.write('<a href="mailto:'+login+'@'+domain+'">'+((name)?name:login+'@'+domain)+'</a>');
    else
        document.write(login+'@'+domain);
} 

function unBlur(element)
{
    if ( element.blur ) element.blur();
}

function preloadImage()
{
    images = new Array();
	for ( var i=0; i < arguments.length; i++ )
    {
        images[i] = new Image(25, 25);
        images[i].src = dirImages + arguments[i];
        images[i].onerror = onerror;
	}
}

function onerror()
{
    alert('err image loading');
}

function toggle()
{
	for ( var i=0; i < arguments.length; i++ )
    {
        if ( e = getElement(arguments[i]) )
        {
            e.style.display = ((e.style.display == 'none') || ((e.style.display=='') && (e.offsetWidth==0))) ? 'block' : 'none';
        }
	}
}

function onLoad()
{
    if ( e = getElement('inputLogin') )
    {
        if ( e.value == '' )
            e.value = 'přihlašovací jméno';
        e.onfocus = inputLoginEventOnFocus;
        e.onblur = inputLoginEventOnBlur;
    }
    if ( e = getElement('inputPassword') )
    {
        if ( e.value == '' )
            e.value = 'heslo';
        e.onfocus = inputPasswordEventOnFocus;
        e.onblur = inputPasswordEventOnBlur;
    }
    unBlurAllLinks();
}

    function unBlurAllLinks()
    {
        rList = document.getElementsByTagName('A');
        for (var i = 0; i < rList.length; i++)
        {
            rList[i].onfocus = new Function('if (this.blur) this.blur();');
        }
    }

function inputLoginEventOnFocus()
{
    if ( e = getElement('inputLogin') )
    {
        if ( e.value == 'přihlašovací jméno' )
            e.value = '';
        else
            e.oldvalue = e.value;
    }
}

function inputLoginEventOnBlur()
{
    if ( e = getElement('inputLogin') )
    {
        if ( e.value == '' )
            if ( typeof(e.oldvalue) != 'undefined' )
                e.value = e.oldvalue;
            else
                e.value = 'přihlašovací jméno';
    }
}

function inputPasswordEventOnFocus()
{
    if ( e = getElement('inputPassword') )
    {
        if ( e.value == 'heslo' )
            e.value = '';
        else
            e.oldvalue = e.value;
    }
}

function inputPasswordEventOnBlur()
{
    if ( e = getElement('inputPassword') )
    {
        if ( e.value == '' )
            if ( typeof(e.oldvalue) != 'undefined' )
                e.value = e.oldvalue;
            else
                e.value = 'heslo';
    }
}

function foc()
{
    if (f = getElement('focusThis'))
    {
        f.focus();
    }
}

function popUp(type, id, x, y)
{
    switch (type)
    {
        case 'banner':
            if (!x)
                x=640;
            if (!y)
                x=480;
            nw = window.open(dirImages+'../file.php?s=banner&id='+id+'&o=html','Foto','width='+x+', height='+y+', toolbar=0, scrollbars=yes, resizable');
            break;
    }
    if ( typeof(nw) != 'undefined' )
        nw.focus();
}

function popupText(url)
{
    nw = window.open(url,'PopUp','width=700, height=200, toolbar=0, scrollbars=yes, resizable');
    if ( typeof(nw) != 'undefined' )
    {
        //nw.document.getElementsByTagName('body')[0].innerHTML = '1';
        nw.focus();
    }
}

    function selectItems(id, checked, expr)
    {
        if (!expr)
            expr = /itemId.*/;
        if (e=getElement(id))
        {
            rList = e.getElementsByTagName('INPUT');
            for (var i = 0; i < rList.length; i++)
            {
                if ( rList[i].type == 'checkbox' && rList[i].name.match(expr) )
                    if ( rList[i].parentNode )
                        rList[i].checked = (checked==2) ? (rList[i].checked ? false : true) : checked;
            }
        }
    }

    function selectItem(id, value, expr)
    {
        if (!expr)
            expr = /itemId.*/;
        if (e=getElement(id))
        {
            rList = e.getElementsByTagName('INPUT');
            for (var i = 0; i < rList.length; i++)
            {
                if ( rList[i].type == 'checkbox' && rList[i].name.match(expr) && rList[i].value==value )
                    if ( rList[i].parentNode )
                        rList[i].checked = true;
            }
            //if (submit && typeof(e.submit)=='function')
                //e.submit();
        }
    }
    
function submitList (id, q)
{
    if ((e=getElement(id)) && typeof(e.submit)!='undefined')
    {
        if (q)
            e.action.value=q;
        e.submit();
    }
}


window.onload = onLoad;

