var bigRandom = Math.round( Math.random() * 10000000 );

function reloginDone() {

}

function regEmailCheck() {
    if ( inFlight['regchk'] )
    {
		return;
    }

    if ( $('email').value.length == 0 ) {
	    showStatus( 'Please enter an e-mail address.', true, true );
	    $('email').focus();
	    return;
    }

    if ( $('pass1').value.length < 5 ) {
	    showStatus( 'The mimimum password length is %d characters.', true, true );
	    $('pass1').focus();
    	return;
    }

    if ( $('pass1').value != $('pass2').value ) {
	    showStatus( 'You typed two different passwords.', true, true );
	    $('pass1').value = '';
	    $('pass2').value = '';
	   	$('pass1').focus();
    	return;
    }

    if ( $('nickname').value.length == 0 ) {
	    showStatus( 'Please enter a nickname.', true, true );
	    $('nickname').focus();
	    return;
    }


    if ( $('captcha').value.length == 0 ) {
	    showStatus( 'Please fill this field too.', true, true );
	   	$('captcha').focus();
	    return;
    }

    if ( $('email').disabled )
    {
		showStatus( 'That\'s all right.', true, false );
    }
    else
    {
	    var parameters = new Array();

	    parameters.push( 'email='+ $('email').value );

	    var req = new Ajax.Request( '/'+ htsrv_subdir +'ajax_regcheck.php', {
			method: "post",
			// Prototype does NOT encode form params for us
			parameters : parameters,
			onComplete : regEmailCheckDone,
			asynchronous: true
	    });

	    showStatus( 'Checking...', 0, false );
    }
}

function regEmailCheckDone( transport )
{
    inFlight['regchk'] = false;
    eval( transport.responseText );
    showStatus( message, true, isError );
    if ( isError ) {
		$('email').select();
    }
}

function regTermsCheck()
{
    if( $( 'termsagreed' ).checked != true )
    {
    	showStatus( 'You have to accept terms and conditions.', true, true );
    	return false;
    }
    return true;
}


function showStatus( msg, hideSpinner, isError ) {
	if ( ajax_messages[msg] ) {
		msg = ajax_messages[msg];
	}
    $("progress").style.display = "";
    $("progressText").innerHTML = (msg) ? msg : "loading...";
    if ( isError ) {
    	$('progressText').style.color = '#d00';
    } else {
    	$('progressText').style.color = '#000';
    }
    $("spinner").style.display = (hideSpinner) ? "none" : "";
}

function webaudit( ucm, uct, where, name, auditid )
{
    document.write( '<img' + ( ( auditid != undefined ) ? ' id="' + auditid + '"' : '' ) + ' class="pixel" src="http://audit.median.hu/cgi-bin/track.cgi?uc=' + ucm + '&amp;dc=' + ( ( where == 'top' ) ? 1 : 2 ) + '&amp;ui=' + bigRandom + '" alt="" />' );
//  document.write( '<img class="pixel" src="http://audit.median.hu/cgi-bin/track.cgi?uc=' + ucm + '&amp;dc=' + ( ( where == 'top' ) ? 1 : 2 ) + '&amp;ui=' + bigRandom + '" alt="" /><img class="pixel" src="http://traffic.index.hu/cgi-bin/audit/track.cgi?uc=' + uct + '&amp;dc=' + ( ( where == 'top' ) ? 1 : 2 ) + '&amp;ui=' + bigRandom + '" alt="" />' );
}
