
function load_new_forum_posts() {
	clearTimeout(live_forum_posts);
	$.getScript("http://img.kudika.ro/js/bula/latest_forum_posts_kudika.ro.js?r=" + Math.random(), function() {		
		live_forum_posts = setTimeout('load_new_forum_posts()', 60000);
	});
}

function close_forum_feed_popup() {
	$('#forum_feed_button').attr('src', IMG_URL + '/forum_feed_popup/off.gif');
	$('#feed_popup_container_forum').hide();	
	$.get('http://www.kudika.ro/ajax.php?act=forum_bula_status&r=close');
}

function show_forum_feed_popup() {
	$('#forum_feed_button').attr('src', IMG_URL + '/forum_feed_popup/off.gif');
	$('#feed_popup_container_forum').show();
}

function show_dialog(js_request,js_params) {
	var js_dialog = $('#dialog_window');
	var js_preloader = $('#dialog_preloader');
	
	if(js_dialog.length > 0) {
		if(js_params && js_params.width) {
			js_dialog.css('width', js_params.width);
			js_dialog.css('marginLeft', js_params.width/2);
		}
		
		if(js_params && js_params.height) js_dialog.css('height', js_params.height);
		
		fp_overlayer_show();
			
		var scrollInfo = new Array();
		scrollInfo[1] = 0;
		
		$('#overlay').css('zIndex', 11000)
		
		document.location.hash = '#';
		
		var min_zindex = $('#overlay').css('zIndex');
		
		js_preloader.css('top', (scrollInfo[1] + 200) + 'px').css('zIndex', min_zindex + 1);
		js_preloader.html('<img src="' + IMG_URL + '/ajax-loader.gif" />');
		js_preloader.show();
		
		js_dialog.css('top', (scrollInfo[1] + 200) + 'px')
				 .css('zIndex', min_zindex + 2)
				 .css('marginLeft', js_dialog.width()/2)
		
		$.post(
			SITE_URL + '/ajax.php?act=dialog&r=' + js_request,
			js_params,
			function(result) {			
				js_preloader.hide();
				js_dialog.html(result.html);				
				if(result.width) js_width = result.width; else js_width = js_dialog.width();
				
				js_dialog.css('width', js_width);
				js_dialog.css('marginLeft', '-' + (js_width/2) + 'px');
				
				if(result.height) {
					js_dialog.css('height', js_params.height);
				}
				
				js_dialog.fadeIn();
			},
			'json'
		);			
	}
}

function hide_dialog() {
	fp_overlayer_hide();
	var js_dialog = $('#dialog_window');
	js_dialog.hide();	
}

function function_exists( function_name ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Steve Clay
    // +   improved by: Legaev Andrey
    // *     example 1: function_exists('isFinite');
    // *     returns 1: true
 
 
    if (typeof function_name == 'string'){
        return (typeof window[function_name] == 'function');
    } else{
        return (function_name instanceof Function);
    }
}

function Set_Cookie( name, value, expires, path, domain, secure ) {
	// set time, it\'s in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = name + "=" +escape( value ) +
		( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +	
		( ( path ) ? ";path=" + path : "" ) +	
		( ( domain ) ? ";domain=" + domain : "" ) +	
		( ( secure ) ? ";secure" : "" );
}

function Get_Cookie( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

function fp_getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		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;
	
//	console.log(self.innerWidth);
//	console.log(document.documentElement.clientWidth);

	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			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;
	}

//	console.log("xScroll " + xScroll)
//	console.log("windowWidth " + windowWidth)

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

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


function fp_getPageScroll(){
	var xScroll, yScroll;

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

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

function fp_show(obj_id) {
        obj = document.getElementById(obj_id);
        if(obj) {
            obj.style.display = "block";
            obj.style.visibility = "visible";
            return true;
        }
        return false;
    }
    
function fp_hide(obj_id) {
	obj = document.getElementById(obj_id);
	if(obj) {
		obj.style.display = "none";
		if(obj_id != 'overlay') fp_hide('overlay');
		return true;
	}
	return false;
}

function fp_overlayer_show(){
	$('#overlay').bind('click', hide_dialog);
	o = document.getElementById('overlay');
	fp_show('overlay');
	scrollInfo = fp_getPageScroll();
	pageInfo   = fp_getPageSize();
	o.style.height = pageInfo[1] + 'px';
	o.style.width = pageInfo[0] + 'px';        
}

function fp_overlayer_hide(){
	fp_hide('overlay');
}
