var inFlight = new Array();
var actionQueue = new Array();
var filterTimer = false;

function fixemail( a )
{
    a.href = a.href.replace( /facethis./g, "" );
    return true;
}
    
function drawstatus( a, b )
{
    if ( b )
    {
	a.href = a.href.replace( /facethis./g, "" );
    }
    else
    {
	a.href = a.href.replace( /.com/g, ".facethis.com" );
    }
}

function pf( a ) {
	if ( console )
	{
	    console.log( a );
	}
	else
	{
	    window.status = a +' '+ window.status;
	}
}

function Is()
{
    //browser leválogatás
    agent = navigator.userAgent.toLowerCase();
    this.agent = navigator.userAgent.toLowerCase();
    this.major = parseInt(navigator.appVersion);
    this.minor = parseFloat(navigator.appVersion);
    this.ns = ( ( agent.indexOf( 'mozilla' ) != -1 ) && ( ( agent.indexOf( 'spoofer' ) == -1 ) && ( agent.indexOf( 'compatible' ) == -1 ) ) );
    this.ns4 = ( this.ns && ( this.major <= 4 ) && ( this.minor < 5 ) );
    this.ns6 = ( this.ns && ( this.major >= 5 ) );
    this.opera = ( agent.indexOf( 'opera' ) != -1 );
    this.opera6 = ( this.major >= 6 );
    this.ie = ( agent.indexOf( "msie" ) != -1 );
    this.ie4 = ( this.ie && ( this.major == 4 ) && ( agent.indexOf( "msie 5.0" ) == -1 ) );
    this.ie5 = ( this.ie && ( this.major == 4 ) && ( agent.indexOf( "msie 5" ) != -1 ) );
    this.ie6 = ( this.ie && ( this.major == 4 ) && ( agent.indexOf( "msie 6" ) != -1 ) );
    this.ie7 = ( this.ie && ( this.major == 4 ) && ( agent.indexOf( "msie 7" ) != -1 ) );
    this.iframe = ( this.ie || this.ns6 || this.opera6 );
    this.popup = ( this.ie || this.ns6 || this.opera6 );
    this.layer = ( this.ie || this.ns6 );
}

var is = new Is();

function ajaxRelogin( alias_user_id ) {
	var parameters = new Array();
	parameters.push( 'alias_user_id='+ alias_user_id );

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

function contentUpdater( elementId, url, parameters, callback ) {
	if ( inFlight[elementId] ) {
		return false;
	}

	inFlight[elementId] = true;
	if( callback == null ) var oncomp = function() { contentUpdated( elementId ) };
	else var oncomp = function( obj, json ) { contentUpdated( elementId ); callback( obj, json ) };
	if ( parameters == '' )
	{
	    var req = new Ajax.Updater (
	    	elementId,
	    	url, {
				method: 'get',
				onComplete: oncomp,
				asynchronous: true,
				evalScripts: true
	    	}
	    );
	}
	else
	{
	    var req = new Ajax.Updater (
	    	elementId,
	    	url, {
				method: 'post',
				parameters: parameters,
				onComplete: oncomp,
				asynchronous: true,
				evalScripts: true
	    	}
	    );
	}

    flipProgress();

    return false;
}

function contentUpdated( elementId )
{
	inFlight[elementId] = false;
	flipProgress();
	if ( $('logo') )
	{
		window.scrollTo( 0, 0 );
	}
}

function flipProgress() {
	if ( $('progress') )
	{
		if ( $('progress').style.display == '' )
		{
			new Effect.Fade(
				'progress',
				{
					afterFinish: function()
					{
						writeProgress( messages['Loading...'] );
					}
				}
			);
		}
		else
		{
			var arrayPageSize = getPageSize();
			var arrayPageScroll = getPageScroll();
			$('progress').style.top = arrayPageScroll[1] +'px';

		    $('progress').style.display = '';
		}
	}
}

function writeProgress( message )
{
	$("progressText").innerHTML = ( message ) ? message : messages['Loading...'];
}

function getPageSize() {

	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}

function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll)
	return arrayPageScroll;
}

function millitimestamp()
{
    var date = new Date();
    var millitimestamp =  date.getTime();

    return millitimestamp;
}

function banner( ade_lc, bhely_id, width, height, margin_top, margin_bottom, co )
{
    document.domain = 'blog.hu';
    var indexadengineui = Math.round( Math.random() * 10000000 );
    if ( co == undefined ) { co = 1; }
    if ( is.iframe )
    {
        rnd = "uniq" + Math.round( Math.random() * 10000000 );
        document.write( '<div style="margin-top: ' + margin_top + 'px; margin-bottom: ' + margin_bottom + 'px;" id="' + rnd + '">' );
        document.write( '<iframe name="indexadengineframe' + same + '" src="http://rehs.blog.hu/ad?lc=' + ade_lc + '&amp;ui=' + indexadengineui + '&amp;co=' + co + '&amp;cn=1&amp;do=' + document.domain + '&amp;ho=' + width + '&amp;ve=' + height + '" width="' + width + '" vspace="0" hspace="0" marginheight="0" marginwidth="0" height="' + height + '" frameborder="0" scrolling="no"></iframe>' );
        document.write( '<scr'+'ipt type="text/javascript">cont = document.getElementById( "' + rnd + '" ).parentNode.parentNode; if ( cont.id == "microsite" ) { cont.style.width = "' + width + 'px"; cont.style.marginLeft = "' + ( 220 - width / 2 ) + 'px"; }</scr'+'ipt>' );
        document.write( '</div>' );
    } else {
        document.write( '<div style="margin-top: ' + margin_top + 'px; margin-bottom: ' + margin_bottom + 'px;">' );
        document.write( '<a target="_top" href="http://rehs.blog.hu/rd?lc=' + ade_lc + '&ui=' + indexadengineui + '"><img src="http://rehs.index.hu/ad?lc=' + ade_lc + '&amp;ui=' + indexadengineui + '" border="0" height="' + height + '" width="' + width + '"></a>' );
        document.write( '</div>' );
    }
}

function change_comment_user()
{
	document.getElementById( 'cuch_comment' ).value = document.getElementById( 'com_textarea' ).value;
	document.getElementById( 'cuch_hash' ).value = document.getElementById( 'com_hash' ).value;
	document.getElementById( 'cuch_realuser' ).value = document.getElementById( 'com_realuser' ).options[document.getElementById( 'com_realuser' ).selectedIndex].value;
	document.getElementById( 'cuch_form' ).submit();
}

function toggleShareToolBox( postId )
{
    var toolBox = $('shareToolBox'+ postId);
    var options = { duration: 0.5 };
    if ( toolBox.style.display == 'none' )
    {
	new Effect.SlideDown( toolBox, options );
    }
    else
    {
	new Effect.SlideUp( toolBox, options );
    }    
}