function load_new_forum_posts() {
	clearTimeout(live_forum_posts);
	$.getScript("http://img.grace.ro/js/bula/latest_forum_posts_grace.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.grace.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);
			
		document.location.hash = '#';
		
		if(function_exists('block_interface'))
			block_interface();
			
		var scrollInfo = new Array();
		scrollInfo[1] = 0;
		
		document.location.hash = '#';
		
		var min_zindex = $('#overlay').css('zIndex');
		
		js_preloader.css('top', (scrollInfo[1] + 100) + '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] + 100) + '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() {
	if(function_exists('unblock_interface'))
		unblock_interface();
	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 ) );
}
