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;
}

function change_caphca_image (id)
{
	
	setTimeout("capcha('" + id + "')", 100);
}

function capcha(id)
{
	document.getElementById(id).src = 'https://quickreg.4game.ru/imagecode.html?'+phpsession+'&rnd='+Math.random();	
}
function show_hide_layer (id, action)
{
    if (action == "show")
    {
        document.getElementById(id).style.display = 'block';
        document.getElementById(id).style.visibility = 'visible';
    }
    else if (action == "hide")
    {
        document.getElementById(id).style.display = 'none';
        document.getElementById(id).style.visibility = 'hidden';
    }
    else if( document.getElementById(id).style.display == 'none')
    {
    	document.getElementById(id).style.display = 'block';
    }
    else if( document.getElementById(id).style.display == 'block')
    {
    	document.getElementById(id).style.display = 'none';
    }
}

function registration_validate( service_name, field, value )
{
	getContent( service_name + '/validate', 'field=' + field + '&value=' + ( value ? value : '' ), false, false, 'registration_validate_result', 'load_' + field );
}

function registration_validate_result( result )
{
	if ( result !== '' )
	{
		var parent_node = document.getElementById( 'infoblock_text' );
		var string = eval( '('+result+')' );
		
		for ( i in string )
		{
			if ( string[i] !== true )
			{
				document.getElementById('infoblock').style.display = 'block';

				if ( !document.getElementById( 'reg_field_err_' + i ) )
				{
					var myDocument = document;
					var pElement = myDocument.createElement( "div" );
					var text = myDocument.createTextNode( string[i] );
					pElement.appendChild( text );
					pElement.setAttribute( "id", "reg_field_err_" + i );
					parent_node.appendChild( pElement );
					pElement.className = 'red';
				}
				else
				{
					document.getElementById( 'reg_field_err_' + i ).innerHTML = string[i];
				}
			}
			else
			{
				if ( document.getElementById( 'reg_field_err_' + i ) )
				{
					parent_node.removeChild( document.getElementById( 'reg_field_err_' + i ) );
				}
			}
		}

		if ( document.getElementById('infoblock_text').innerHTML == '' )
		{
			document.getElementById('infoblock').style.display = 'none';
		}
	}
}

function verifyForm( 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 += '&' + field_name + '=' + dat;
		else str = field_name + '=' + dat;
    }

	getContent ( action, false, str, false, ( fn_callback ? fn_callback : false ) );
}

function registrationResult( result )
{
	if ( result !== '' )
	{
		var string = eval( '('+result+')' );

		for ( i in string )
		{
			if ( i == 'registration' && string[i] == '1' )
			{
				var registration = true;
				var string = (document.location.href.indexOf('?')!=-1) ? document.location.href.substring(0,document.location.href.indexOf('?')) : document.location.href;
				document.location.href = string.substring(string.length-1, string.length) == '/' ? string+'complete.html' : string.substring(0,string.length-5)+'/complete.html';
			}
		}

		if ( !registration )
		{
			registration_validate_result( result );
		}
	}
}


