var xmlHttp
var onload=true;
function getnewsheading(action)
{ 
	
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 }
var url="fetch_news.php"
if(action!="")
{
	url=url+"?"+action
	url=url+"&sid="+Math.random()
}
else
{
	
	url=url+"?sid="+Math.random()
}	
xmlHttp.onreadystatechange=stateChanged 
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}

function stateChanged() 
{ 
if (xmlHttp.readyState==1 || xmlHttp.readyState=="complete")
 { 
 document.getElementById("status").innerHTML='<b>Loading..</b>'; 
 }
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 document.getElementById("newsheading").innerHTML=xmlHttp.responseText 
 document.getElementById("status").innerHTML=''; 
 } 
}

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

var xmlObj

function getnewsdeatils(action)
{ 
	
xmlObj=GetXmlObject()
if (xmlObj==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 }
var url="fetch_news.php"
if(action!="")
{
	url=url+"?"+action
	url=url+"&sid="+Math.random()
}
else
{
	
	url=url+"?sid="+Math.random()
}	
xmlObj.onreadystatechange=state
xmlObj.open("GET",url,true)
xmlObj.send(null)
}

function state() 
{ 
status
if (xmlObj.readyState==1 || xmlObj.readyState=="complete")
 { 
 document.getElementById("status").innerHTML='<b>Loading..</b>'; 
 }
if (xmlObj.readyState==4 || xmlObj.readyState=="complete")
 { 
 document.getElementById("newsdetails").innerHTML=xmlObj.responseText
 document.getElementById("status").innerHTML=''; 
 } 
}

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



function news_load(newsid,onload)
{ 
	 
	datefrom=document.getElementById("date_box_from1").value;
	dateto=document.getElementById("date_box_to1").value;
	catid=document.getElementById("cat_box").value;
	
   if(onload)
   {  	  
	   	getnewsheading('onload=showheading&newsid='+newsid);
	   if(newsid!=0)	
		getnewsdeatils('onload=shownews&newsid='+newsid);
	   else
	   	getnewsdeatils('onload=shownews');
		//onload=false;
   }
   else
   {	
   	
	getnewsheading('action=showheading&datefrom='+datefrom+'&dateto='+dateto+'&catid='+catid+'&newsid='+newsid);
	getnewsdeatils('action=shownews&newsid='+newsid+'&datefrom='+datefrom+'&dateto='+dateto+'&catid='+catid);
   }	
}