var baseURL = window.location.protocol + "//" + window.location.host
var timerID=0;
var xmlhttpObj = "";
var xmlDoc = null;
var ajaxCount = 0;
function onLoadHandler(logonId,jobStatus,sortOrder,retainAfter,retainWithout)
{
	OnDataChange(logonId,jobStatus,sortOrder,retainAfter,retainWithout);
}
function refreshAjax(logonId,jobStatus,sortOrder,retainAfter,retainWithout)
{
	onLoadHandler(logonId,jobStatus,sortOrder,retainAfter,retainWithout);	 
}

function OnDataChange(logonId,jobStatus,sortOrder,retainAfter,retainWithout)
{
    if(timerID)
    {
    	clearTimeout(timerID);
    	timerID  = 0;
    }
         
    dataLoader(logonId,jobStatus,sortOrder,retainAfter,retainWithout);
    timerID = setTimeout("timedEvents('"+logonId+"','"+jobStatus+"','"+sortOrder+"',"+retainAfter+","+retainWithout+")", 15000);

}
function timedEvents(logonId,jobStatus,sortOrder,retainAfter,retainWithout)
{
     dataLoader(logonId,jobStatus,sortOrder,retainAfter,retainWithout);
     timerID = setTimeout("timedEvents('"+logonId+"','"+jobStatus+"','"+sortOrder+"',"+retainAfter+","+retainWithout+")", 15000);
}

function dataLoader(logonId,jobStatus,sortOrder,retainAfter,retainWithout)
{
window.status = "Loading  Data...";


// var actualURL = baseURL + "/eql2008/test.xml"
var actualURL = baseURL + "/eqlDownLoadListXML.cfm"
    actualURL = actualURL + "?id="  +  logonId
    actualURL = actualURL + "&job="  + jobStatus
    actualURL = actualURL + "&sort="  + sortOrder
    actualURL = actualURL + "&rf="  + retainAfter
    actualURL = actualURL + "&rw="  +retainWithout

xmlhttpObj = GetXMLHTTPConnection();  
xmlhttpObj.open("GET", actualURL+"&rand=" + Math.random(), true);
xmlhttpObj.onreadystatechange = loadData_Start;
xmlhttpObj.send(null);

}

function loadData_Start()
{
	
	// if xmlhttp shows "loaded"
	if (xmlhttpObj.readyState==4)
	{
		if (xmlhttpObj.status == 200) 
		{		
			var responseXML = xmlhttpObj.responseXML;                                                 
			if (responseXML != null )
			{  			 
			  xmlDoc = responseXML.documentElement;        
			}
		}
		
		updateTable();
	}
	window.status=""
}

//here is the actual update of table using ajax -- from server side xml
function updateTable()
{
ajaxCount = ajaxCount+1;
var rootElement=xmlDoc
if (xmlDoc == null) {return;}     
EqlList = rootElement.getElementsByTagName ("eqlList");
EqlListCount = rootElement.getElementsByTagName ("eqlListCount");

if (EqlList[0] == null) {document.getElementById("EqlInformation").innerHTML="<table/>";return;} 
var  ProgramTable = "";
var buttonTable = "";
var showPdfButton = "N";
var showButton = "N";


 //ProgramTable+='<div id="text_scroller">'

 ProgramTable+='<table class="smallText" border="0" cellpadding="3" cellspacing="0" width="212">'
 
 
	for (var i=0; i<EqlList.length; i++) 
	{
	    
       ProgramTable+='<tr >'
      topic = EqlList[i].getElementsByTagName('topic')[0].childNodes[0].nodeValue
      
      ProgramTable+='<td class="bGrey hThree" width="30">'+topic.substring(0,topic.indexOf("-"))+'</td>'
      if(EqlList[i].getElementsByTagName('status')[0].childNodes[0].nodeValue == 'C' || EqlList[i].getElementsByTagName('status')[0].childNodes[0].nodeValue == 'E') {            
      ProgramTable+='<td class="bGrey red" width="130">'+topic.substring(topic.indexOf("-")+1)+'</td>'
      }else{
      ProgramTable+='<td class="bGrey" width="130">'+topic.substring(topic.indexOf("-")+1)+'</td>'
      }
      
     if(EqlList[i].getElementsByTagName('status')[0].childNodes[0].nodeValue == 'C' || EqlList[i].getElementsByTagName('status')[0].childNodes[0].nodeValue == 'E') {      
      ProgramTable+='<td class="bGrey red" width="60">'+EqlList[i].getElementsByTagName('jobStatus')[0].childNodes[0].nodeValue+'</td>'
      }else{
      ProgramTable+='<td class="bGrey" width="60">'+EqlList[i].getElementsByTagName('jobStatus')[0].childNodes[0].nodeValue+'</td>'
      }
	     
	     ProgramTable+='</tr>'
    }
    
         	
         	
ProgramTable+='</table>'

//ProgramTable+='</div>'


document.getElementById("EqlInformation").innerHTML=ProgramTable;
//CSBfleXcroll('text_scroller');


}



function GetXMLHTTPConnection()
{
	var xmlhttp=false;
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
		 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
		 xmlhttp = false;
		}
	}
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		try {
			xmlhttp = new XMLHttpRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}
	if (!xmlhttp && window.createRequest) {
		try {
			xmlhttp = window.createRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}
return xmlhttp;
}