// JavaScript Document

URL = '/';

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 unBlur(element)
{
    if ( element.blur ) element.blur();
}

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 tryShow (id)
{
    if ( form = getElement(id) )
    {
        form.style.display = 'block';
        return false;
    }
    else return true;
}

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';
        }
        //return true;
	}
	//return false;
}

function toggleBox(box, element)
{
    if ( (b = getElement(box)) && element )
    {
        if ( b.style.display == '' || b.style.display == 'block' )
        {
            b.style.display =  'none';
            element.innerHTML = '::';
        }
        else
        {
            b.style.display =  'block';
            element.innerHTML = ':.';
        }
    }
}

function foc()
{
    if (f = getElement('focusThis'))
    {
        f.focus();
    }
}

function onLoad()
{
}

function popUp(type, id)
{
    switch (type)
    {
        case 'psychosearch':
            nw = window.open(URL+'popup_psychosearch.php','Foto','width=700, height=200, toolbar=0, scrollbars=yes, resizable');
            break;
        case 'editorHTML':
            nw = window.open(URL+'popup_editorhtml.php?eid='+id,'Foto','width=1024, height=768, toolbar=0, scrollbars=yes, resizable');
            break;
    }
    if ( typeof(nw) != 'undefined' )
        nw.focus();
    return false
}

function requestHL2Status()
{
    var ip = getElement('requestParms').ip.value;
    var port = getElement('requestParms').port.value;
    if ( ip.match(/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/) && port.match(/^[0-9]{1,5}$/) )
    {
    
        getElement('serverInfo').innerHTML = '<div class="working">loading...</div>';
        var status = new Ajax();
        status.doGet('/serverStatus?ip='+ip+'&port='+port+'&full',serverStatusHandler,'xml');
    }
}

function handleMultiBlockInput (blockId)
{
    if ( vstup = getElement(blockId) )
    {
        var newCopy = vstup.childNodes[0].cloneNode(true);
        fList = newCopy.getElementsByTagName('INPUT');
        for (var i = 0; i < fList.length; i++)
            if ( fList[i].type == 'text' || fList[i].type == 'password' || fList[i].type == 'file' )
                if ( fList[i].parentNode )
                    fList[i].value = '';
        fList = newCopy.getElementsByTagName('TEXTAREA');
        for (var i = 0; i < fList.length; i++)
            if ( fList[i].parentNode )
                fList[i].value = '';
    }
    else return false;
    if ( typeof(newCopy) == 'undefined' )
        return false;
    for (var x = 0; vstup.childNodes[x]; x++)
    {
        if (vstup.childNodes[x].tagName=='DIV')
        {
            if (vstup.childNodes[x].childNodes[0].value == '')
            {
                vstup.removeChild(vstup.childNodes[x]);
                x--;
            }
        }
    }
    vstup.appendChild(newCopy.cloneNode(true));
}



