var auto_refresh = "off";

if(readCookie('sa7afa_hp_autorefresh') != null)
{
auto_refresh = readCookie('sa7afa_hp_autorefresh');
}


function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}



function auto_refresh_switch()
{

if(auto_refresh=='on')
{
document.getElementById("auto_refresh").style.background="white";
document.getElementById("auto_refresh").style.color="blue";
auto_refresh = 'off';
createCookie('sa7afa_hp_autorefresh','off',10);
}
else
{
document.getElementById("auto_refresh").style.background="green";
document.getElementById("auto_refresh").style.color="white";
auto_refresh = 'on';
createCookie('sa7afa_hp_autorefresh','on',10);
}


}

/////////////////////////////////////////////////////////

var time = 1000*60*15;
function begin_auto_refresh(){

setTimeout("auto_refresh_forward()",time);

}

function auto_refresh_forward(){
if(auto_refresh == "on")
{
auto_refresh_process();
}
begin_auto_refresh();
}

begin_auto_refresh();//it start the auto refresh

/////////////////////////////auto refresh ajax////////////////////////

var xmlHttp_auto_refresh_process

function auto_refresh_process()
{
xmlHttp_auto_refresh_process=GetXmlHttpObject_auto_refresh_process()
//if (xmlHttp_auto_refresh_process==null)
//{
//alert ("Browser does not support HTTP Request")
//return
//}

document.getElementById("newscontrols_loading").innerHTML=' | جارى تحديث الاخبار'; 
var url="auto_refresh.php"
url=url+"?sid="+Math.random()
xmlHttp_auto_refresh_process.onreadystatechange=stateChanged_auto_refresh_process
xmlHttp_auto_refresh_process.open("GET",url,true)
xmlHttp_auto_refresh_process.send(null)


}

function stateChanged_auto_refresh_process() 
{ 
if (xmlHttp_auto_refresh_process.readyState==4 || xmlHttp_auto_refresh_process.readyState==0)
{
document.getElementById("newscol").innerHTML=xmlHttp_auto_refresh_process.responseText
document.getElementById("newscontrols_loading").innerHTML='';
} 
}

function GetXmlHttpObject_auto_refresh_process()
{
var xmlHttp_auto_refresh_process=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp_auto_refresh_process=new XMLHttpRequest();
}
catch (e)
{
//Internet Explorer
try
{
xmlHttp_auto_refresh_process=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp_auto_refresh_process=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp_auto_refresh_process;
}
