function should_update_rss(response){
	if(jQuery.parseJSON(response))
		ajax_call(run_rss_update, "type=rss");
	else{
		run_delayed_ajax_call();
	}
}

function run_rss_update(response){
	response = Number(jQuery.parseJSON(response));
	if(!isNaN(response) && response > 0)
		ajax_call(load_db_update, "type=db&minid=" + maxid);
	else{
		run_delayed_ajax_call();
		}
}

function load_db_update(response){
	response = jQuery.parseJSON(response);
		for(notis in response){
			var headline = "headlinen";
			var markup = "<div class='notis'><a target='_blank' class='headline' href='" + response[notis].url + "'>" + response[notis].headline + "</a><p>" +response[notis].desc + "</p></div>";
			$("#notiser").prepend(markup);
		}
	run_delayed_ajax_call();
}

function run_delayed_ajax_call(){
	setTimeout('ajax_call(should_update_rss, "")', 180000);
}

function ajax_call(func, get){
	var xht = ('XMLHttpRequest' in window) ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
	function ready(xht){
		return (xht.readyState == 4 && xht.status == 200)
	}
	xht.onreadystatechange = function(){
		if(ready(xht))
			func(xht.responseText);
	}
	xht.open("GET", "update.php?" + get, true);
	xht.send();
}

function utf8_decode(input){
	return decodeURIComponent(escape(input));
}
