function show_hide_layer ( id )
{
	if ( document.getElementById( id ) )
	{
		if ( document.getElementById( id ).style.display == "block" || document.getElementById( id ).style.display == '' )
		{
			document.getElementById( id ).style.display = 'none';
		}
		else if ( document.getElementById( id ).style.display == "none" )
		{
			document.getElementById( id ).style.display = 'block';
		}
	}
}


function hideContainer( id )
{
	if ( document.getElementById( id ) )
	{
		document.getElementById( id ).style.display = 'none';
	}
}

function form_verify( form, action, fn_callback )
{
    var str = '';
    var dat = '';

    for ( var i=0; i < form.elements.length; i++ )
	{
        field_name = form.elements[i].name;
        field_value = form.elements[i].value;
        
        dat = field_value ? field_value.toString() : '';
        dat = dat.replace(/\+/g, '&#43;');
        //dat = escape(dat);

		if ( ( form.elements[i].type == 'radio' || form.elements[i].type == 'checkbox' ) && form.elements[i].checked === false )
		{
			continue;
		}

        if ( i != '0' )
		{
            str = str + '&data[' + field_name + ']=' + dat;
        }
		else
		{
            str = 'data[' + field_name + ']=' + dat;
        }
    }

	getContent ( action, false, str, false, ( fn_callback ? fn_callback : false ) );
}

function verify_field( field, value ) 
{
	if( field )
	{
		getContent( 'registration', 'reg_field='+ field + '&value=' + ( !value ? '' : value ), false, false, 'showVerifyResult' );
	}
}


function sendAmnesia()
{
	var login = document.getElementById( 'login' ) ? document.getElementById( 'login' ).value : '';
	var email = document.getElementById( 'email' ) ? document.getElementById( 'email' ).value : '';
	var imagecode = document.getElementById( 'imagecode_text' ) ? document.getElementById( 'imagecode_text' ).value : '';

	if ( imagecode == '' )
		alert( 'Не введен код защиты' );
	else if ( login == '' && email == '' )
		alert( 'Укажите логин или e-mail' );
	else
		getContent( 'registration', 'amnesia&login='+ login + '&email=' + email + '&imagecode=' + imagecode, false, false, 'showVerifyResult' );
}


function showVerifyResult( result )
{
	if ( document.getElementById( 'verify_result' ) )
	{
		if ( result == '1' )
		{
		}
		else if ( result !== '' )
		{
			document.getElementById( 'verify_result' ).style.marginTop = getBodyScrollTop() + 200 + 'px';
			document.getElementById( 'verify_result' ).innerHTML = result;
			document.getElementById( 'verify_result' ).style.display = 'block';

			setTimeout( "hideContainer('verify_result')", 3000 );
		}
	}
}

function form_submit ( result )
{
	if ( result == "success" )
	{
		document.location.href = "/success.html";
	}
	else 
	{
		alert( result );
	}
}



function blog_comment_delete( comment_id )
{
	if ( document.getElementById( 'comment' + comment_id ) && comment_id !== '' )
	{
		document.getElementById( 'comment' + comment_id ).innerHTML = '';
	}
}

function sendContactForm()
{
	var name = document.getElementById( 'name' ) ? document.getElementById( 'name' ).value : '';
	var email = document.getElementById( 'email' ) ? document.getElementById( 'email' ).value : '';
	var text = document.getElementById( 'text' ) ? document.getElementById( 'text' ).value : '';
	var imagecode = document.getElementById( 'imagecode_text' ) ? document.getElementById( 'imagecode_text' ).value : '';

	if ( name !== '' && email !== '' && text !== '' )
	{
		getContent( 'company', 'send_contact_form&name=' + name + '&email=' + email + '&text=' + text + '&imagecode=' + imagecode, false, 'send_result' );
	}
	else
	{
		alert( 'Все поля обязательны для заполнения' );
	}
}

function changePassword()
{
	var password = document.getElementById( 'password' ) ? document.getElementById( 'password' ).value : '';
	var password_repeat = document.getElementById( 'password_repeat' ) ? document.getElementById( 'password_repeat' ).value : '';

	if ( password_repeat == '' || password_repeat == '' )
		alert( 'Введите пароль и его подтверждение' );
	else
		getContent( 'registration', 'change_password&password='+ password + '&password_repeat=' + password_repeat, false, false, 'showVerifyResult' );
}

function getDocumentHeight(){
    return (document.body.scrollHeight > document.body.offsetHeight)?document.body.scrollHeight:document.body.offsetHeight;
}	

function getDocumentWidth(){
    return (document.body.scrollWidth > document.body.offsetWidth)?document.body.scrollWidth:document.body.offsetWidth;
}

function getBodyScrollTop(){
    return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
}
function getClientWidth()
{
    return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
}
