var alertDivs = new Array();
var curDiv = null;

function checkPass()
{
	main.real_pass.value = MD5(MD5(main.pass.value) + main.session_id.value);
}
	
function hideIcon()
{
    helpIcon = window.parent.navmenu.document.all['help_icon'];
    if (!helpIcon)
    {
        setTimeout("hideIcon()", 50);
        return;
    }
    helpIcon.style.display = 'none';
}


function showIcon()
{
    helpIcon = window.parent.navmenu.document.all['help_icon'];
    if (!helpIcon)
    {
        setTimeout("showIcon()", 50);
        return;
    }
    helpIcon.style.display = '';
}
function showAlert()
{
    oDivs = document.body.getElementsByTagName('DIV');
    for (i = 0; i < oDivs.length; i++)
    if (oDivs[i].className == 'alert')
        alertDivs.push(oDivs[i]);

    if (alertDivs.length > 0)
    {
        curDiv = alertDivs.pop();
        curDiv.style.width = 500;
        curDiv.style.left = (document.body.clientWidth - 500) / 2;
        curDiv.filters[0].apply();
        curDiv.style.display = '';
        curDiv.filters[0].play();
        setTimeout('hideAlert(false);', 5000);
    }   
}
function hideAlert(remove)
{
    if (!remove)
    {
        curDiv.filters[0].apply();
        curDiv.style.visibility = 'hidden';
        curDiv.filters[0].play();
        if (alertDivs.length > 0)
        {
            curDiv = alertDivs.pop();
            curDiv.style.width = 500;
            curDiv.style.left = (document.body.clientWidth - 500) / 2;
            curDiv.filters[0].apply();
            curDiv.style.display = '';
            curDiv.filters[0].play();
            setTimeout('hideAlert(false);', 5000);
        }
    }
    else
    {
        curDiv.removeNode(true);
        if (alertDivs.length > 0)
        {
            curDiv = alertDivs.pop();
            curDiv.style.width = 500;
            curDiv.style.left = (document.body.clientWidth - 500) / 2;
            curDiv.filters[0].apply();
            curDiv.style.display = '';
            curDiv.filters[0].play();
            setTimeout('hideAlert(false);', 5000);
        }
    }
}
function noReturn()
{
    event.cancelBubble = true;
    event.returnValue = false;
}

function binnStoreCaret(textEl) 
{
    if (textEl.createTextRange)
    { 
        textEl.caretPos = document.selection.createRange().duplicate();
    }
}

function binnInsertAtCaret(textEl, text) 
{
    if (textEl.createTextRange && textEl.caretPos) 
    {
        var caretPos = textEl.caretPos;
        caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
    }
    else
    {
        textEl.value = text;
    }
}

function addTabProc()
{
    var oTextAreas = document.getElementsByTagName('TEXTAREA');
    if (oTextAreas)
    {
        for (i = 0; i < oTextAreas.length; i++)
            oTextAreas[i].attachEvent('onkeydown', tabProc);
    }
}
function tabProc()
{
    if (event.keyCode == 9)
    {
        var el = event.srcElement;
        if (!el)
        {
            return;
        }
        el.focus();
        binnStoreCaret(el);
        binnInsertAtCaret(el, '    ');
        noReturn();
    }
}
     
var div_el_old_width;
var div_el_old_height;
     
function binn_enlargeArea(btn, el_id)
{
    div_el = document.getElementById(el_id);
    if (div_el.style.position != 'absolute')
    {
        var main_tbl = document.forms[0].all.tags('TABLE')[0];
        main_tbl.style.visibility = 'hidden';

        div_el.style.position = 'absolute';
        document.body.scroll = 'no';
        div_el.style.top = document.body.scrollTop+10;
        div_el.style.left = 10;
        var area = div_el.all.tags('TEXTAREA');
        div_el_old_width = area[0].style.width;
        div_el_old_height = area[0].style.height;
        binn_areaResize();
        btn.value = '-';
        window.attachEvent('onresize', binn_areaResize);
        div_el.style.visibility = 'visible';
    }
    else
    {
        var main_tbl = document.forms[0].all.tags('TABLE')[0];
        div_el.style.position = 'static';
        div_el.style.visibility = '';
        div_el.style.top = '';
        div_el.style.left = '';
        div_el.style.width = '';
        var area = div_el.all.tags('TEXTAREA');
        area[0].style.width = div_el_old_width;
        area[0].style.height = div_el_old_height;
        document.body.scroll = 'yes';
        btn.value = '+';
        window.detachEvent('onresize', binn_areaResize);
        main_tbl.style.visibility = 'visible';
    }
}
function binn_areaResize()
{
    div_el.style.width = document.body.clientWidth-20;
    var area = div_el.all.tags('TEXTAREA');
    area[0].style.width = document.body.clientWidth-20;
    area[0].style.height = document.body.clientHeight-60;
}
document.attachEvent('oncontextmenu', noReturn);
window.attachEvent('onload', addTabProc);