
function e(elem)
{
    return document.getElementById(elem) || false;
}

function showForm()
{
	fixMargin();
    e('blockform').style.display = '';
	e('shadow').style.display = '';
    if (e('banner')) e('banner').style.display = 'none';
    return false;
}

function showFormLogin()
{
    fixMargin();
    e('blockformlogin').style.display = '';
	e('shadow').style.display = '';
    if (e('banner')) e('banner').style.display = 'none';
    return false;
}

function showFormRestore()
{
    fixMargin();
    e('blockformrestore').style.display = '';
	e('shadow').style.display = '';
    if (e('banner')) e('banner').style.display = 'none';
    return false;
}

function closeFormLogin()
{
	e('blockformlogin').style.display = 'none';
	e('shadow').style.display = 'none';
    if (e('banner')) e('banner').style.display = '';
}

function closeFormRestore()
{
	e('blockformrestore').style.display = 'none';
	e('shadow').style.display = 'none';
    if (e('banner')) e('banner').style.display = '';
}

function showForm2()
{
	fixMargin();
    e('blockform2').style.display = '';
	e('shadow').style.display = '';
    if (e('banner')) e('banner').style.display = 'none';
    return false;
}

function closeForm()
{
	e('blockform').style.display = 'none';
	e('shadow').style.display = 'none';
    if (e('banner')) e('banner').style.display = '';
}
function closeForm2()
{
	e('blockform2').style.display = 'none';
	e('shadow').style.display = 'none';
    if (e('banner')) e('banner').style.display = '';
}


function change(from, to)
{
	e(from).style.display = 'none';	
	e(to).style.display = '';	
}

function fixMargin()
{
    if (parseInt(document.documentElement.clientWidth) < 1100)
    {
        e('order').className += ' order2';
        e('order2').className += ' order2';
        e('loginBlock').className += ' login2';
    }        
    else
    {
        e('order').className = e('order').className.replace('order2', '');
        e('order2').className = e('order2').className.replace('order2', '');
        e('loginBlock').className = e('loginBlock').className.replace('login2', '');
    }
}

function addFile(elem)
{
    var id = parseInt(elem.id.replace('morefiles', ''));
    var newElem = document.createElement('INPUT');
    newElem.type = 'file';
    newElem.className = 'file';
    newElem.name = 'docp'+id;
    elem.parentNode.insertBefore(newElem, elem);
    id++;
    if (id == 5)
    {
        elem.parentNode.removeChild(elem);
    }
    else
    {
        elem.id = 'morefiles' + id;
        elem.onclick = function() {addFile(this);}
    }
}

function init()
{
    if (e('linkClose') && e('linkClose2') && e('linkOpen') && e('ustniy') && e('pismenniy'))
    {
        e('linkClose').onclick = closeForm;
        e('linkClose2').onclick = closeForm2;
        e('linkOpen').onclick = function() {showForm(); return false;};
        e('ustniy').onclick = function () {change('blockform', 'blockform2'); };
        e('pismenniy').onclick = function () {change('blockform2', 'blockform'); };
        if (e('error1')) showForm();
        if (e('error2')) showForm2();
        if (e('sended1')) showForm();
        if (e('sended2')) showForm2();
        fixMargin();
        window.onresize = fixMargin;
    }
    if (e('linkCloseLogin') && e('linkCloseRestore') && e('restore') && e('alogin') && e('linkLogin'))    
    {		
        e('linkCloseLogin').onclick = closeFormLogin;
		e('linkCloseRestore').onclick = closeFormRestore;
		e('linkLogin').onclick = function() {showFormLogin(); return false;};
		e('restore').onclick = function () {change('blockformlogin', 'blockformrestore'); };
		e('alogin').onclick = function () {change('blockformrestore', 'blockformlogin'); };
        if (e('error3')) showFormLogin();
        if (e('error4')) showFormRestore();
        if (e('sended3')) showFormLogin();
        if (e('sended4')) showFormRestore();        
    }
    
    if (e('morefiles1'))
    {
        e('morefiles1').onclick = function() {addFile(this);};
    }
}
window.onload = init;
