function T_Auth_Login(i_login,i_pass,i_saveauth)
{
    this.h_login.value = this.h_pass.value = '';
    this.h_login.value = document.getElementById(i_login).value;
    this.h_pass.value = document.getElementById(i_pass).value;
    this.h_pass.value = this.h_pass.value.replace(/ $/, "");
    this.h_pass.value = hex_md5(hex_md5(this.h_pass.value) + this.key);
    this.h_saveauth.value = 1;
    document.getElementById(i_login).disabled = document.getElementById(i_pass).disabled = true; 
     
//    document.getElementById('auth_sess2').value = (document.getElementById(i_pass).value);
    this.form.action = "";
    this.form.submit();
}
function T_Auth(name, key)
{
    this.name    = name;
    this.key = key;
    this.form = document.getElementById(name+'_form');
    this.h_login = document.getElementById(name + '_login');
    this.h_pass  = document.getElementById(name + '_pass');
    this.h_saveauth = document.getElementById(name + '_saveauth');

    this.login    = T_Auth_Login; 
}


function T_Errors_Add(str,field)
{
    if (!field) field = '';
    this.array.push(str);
    this.fields.push(field);
    busy = false;
}
function T_Errors_Print()
{
    busy = false;
    var i,j;
    var tempArr = new Array();
    var str = '';
    if (this.array.length == 0)
    {
        this.body.style.display = 'none';
        this.body.innerHTML = '';
        return true;
    }
    else
        this.body.style.display = 'block';

    for (i = 0; i < this.fieldsUnset.length; i++)
    {
    
        tempArr = this.fieldsUnset[i].split(",");
        for (j = 0; j < tempArr.length; j++)
            if (tempArr[j] != '') document.getElementById(tempArr[j]).className = 'normal';
    }

    for (i = 0; i < this.array.length; i++)
    {
        tempArr = this.fields[i].split(",");
        for (j = 0; j < tempArr.length; j++)
            if (tempArr[j] != '') document.getElementById(tempArr[j]).className = 'wrong';
        
        str +=''+this.array[i]+'<br />';
        
    }
    this.body.innerHTML = str + '';
    this.fieldsUnset    = this.fields; 
    this.array            = new Array();
    this.fields            = new Array();
}
function T_Errors(name,color)
{
    this.name       = name;
    this.body        = document.getElementById(name + '_errors');
    this.add        = T_Errors_Add;
    this.array        = new Array();
    this.fields        = new Array();
    this.fieldsUnset= new Array();
    this.print        = T_Errors_Print;
    this.body.style.display = 'none';
    this.body.className = 'errorBlock';

    if (color)
        this.body.style.borderColor = color;
    
}

function checkMaxLength(obj, maxCnt)
{
    if (obj.value.length >= maxCnt)
        obj.value = obj.value.substring(0, maxCnt);
}
