var div = document.getElementById('static_mail');
var gdash=0;

var handleSuccess = function(o){
	if(o.responseText !== undefined){
		var text = o.responseText.split('|');
		create_notifi(text[0]);
		if (text.length > 1)
			var text = trim(text[1]);
		else 
			var text='';

		if (text.length > 1) {
			openAlertwin('url',text)
		}
	setTimeout('makeRequest();',60000);
	}
}

var handleFailure = function(o){
	if(o.responseText !== undefined){
	setTimeout('makeRequest();',5000);
	}
}

var sUrl = "http://avatar-bg.org/static/static.php";

function makeRequest(){
	var request = YAHOO.util.Connect.asyncRequest('GET', sUrl,
            {
                success: handleSuccess,
                failure: handleFailure,
		  cache:false 
            }
        );
}

function show_notifi() {
	var dispp = document.getElementById("notifications");

	if (dispp.style.display == 'none') {
		Effect.toggle('notifications', 'slide'); 
		makeRequestNotifi('');
	} else {
		Effect.toggle('notifications', 'slide'); 
	}
}


var divnotifi = document.getElementById('noti_content');
var dash_view=0;

function makeRequestNotifi(p,dd){
dash_view=dd;
gdash=p;
 var p='save='+p;
		divnotifi.innerHTML = '<div style="width:100%; text-align:center;"><img src="http://avatar-bg.org/images/loading2.gif" ></div>';

	var req = YAHOO.util.Connect.asyncRequest('GET', 'static/notifi.php?'+p,
            {
                success: handleSuccessNotifi,
                failure: handleFailureNotifi,
		  cache:false 
            }
        );
}

var handleSuccessNotifi = function(o){
	if(o.responseText !== undefined && o.responseText!='saved' ){
		divnotifi.innerHTML = o.responseText;
	} else if (o.responseText=='saved') {
		Effect.toggle('notifications', 'slide');
		var rnd=Math.floor(Math.random()*999999); 
//		window.location="index.php?page=dashboard#"+gdash+"&rnd="+rnd;
		window.location="index.php?page=dashboard&do=view_dash&did="+dash_view;
	}
}
var handleFailureNotifi = function(o){
	if(o.responseText !== undefined){
	setTimeout('makeRequestNotifi();',5000);
	}
}

function create_notifi(text) {
		var child = document.getElementById('static_mail');
		var parent=child.parentNode;
		var prevtr = '<div id="static_mail" >'+text+'</div>';
		parent.innerHTML = prevtr; //replace table
}

makeRequest();

