function getHTTPObject() {
  var xmlhttp;
 
  if(window.XMLHttpRequest){
    xmlhttp = new XMLHttpRequest();
  }
  else if (window.ActiveXObject){
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    if (!xmlhttp){
        xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
    
}
  return xmlhttp;

  
}
var http = getHTTPObject(); // We create the HTTP Object

/*
	Funtion Name=requestInfo 
	Param = url >> Url to call : id = Passing div id for multiple use ~ as a seprator for eg. div1~div2 :
	redirectPage >> if you like to redirect to other page once the event success then 
	the response text = 1 and the redirectPage not left empty
*/

function requestInfo(url, id, redirectPage, func) {      
	if(func==null){
		func = '';
	}
	
	var temp=new Array();
	temp = id.split("~"); // To display on multiple div 
	for(i=0;i<temp.length;i++){
		document.getElementById(temp[i]).innerHTML = '<img src="/images/loading.gif" width="16" height="16" align="absmiddle" />loading...';
	}
	
	var exctime = new Date();
	url += "&exctime="+exctime.getTime();
	
	http.open("GET", url, true);
	http.onreadystatechange = function() {
		if (http.readyState == 4) {
		  if(http.status==200) {
			var results=http.responseText;
			if(redirectPage=="" || results!="1") {
				var r=results.split("~"); // To display multiple data into the div 
				for(i=0;i<temp.length;i++) {	 
					document.getElementById(temp[i]).innerHTML=r[i];
					if(func!=''){
						func;
					}
				}
			} else { 
				window.location.href=redirectPage;
			}
		  } 
		}
	};
	http.send(null);
}

function showList(pageid, prm) {
	var search_cond = document.getElementById("search_key").value!="" ? "&search_key="+encodeURIComponent(document.getElementById("search_key").value) : ""; 
	requestInfo('showList.php?pageid='+pageid+prm+search_cond, 'showList', '');
}

function reqGeneral(altpage, prm, target){
	requestInfo(altpage+prm, target, '');
}
