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) {      
	var exctime = new Date();
	url += "&exctime="+exctime.getTime();
	
	var temp=new Array();
	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 temp=id.split("~"); // To display on multiple div 
				//alert(temp.length);
				var r=results.split("~"); // To display multiple data into the div 
				//alert(temp.length);
				if(temp.length>1) {
					for(i=0;i<temp.length;i++) {	
						//alert(temp[i]);
						document.getElementById(temp[i]).innerHTML=r[i];
					}
				} else {
					document.getElementById(id).innerHTML = results;
				}	
			} else {
				//alert(results);
				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) : "";
	//var prm = encodeURIComponent(prm);
	//alert('showList.php?pageid='+pageid+prm);
	requestInfo('showList.php?pageid='+pageid+prm+search_cond, 'showList', '');
}

function showOfficer(prm) {
	//var search_key = encodeURIComponent(search_key);
	var search_key = encodeURIComponent(document.getElementById("search_key").value);
	var pstype_id = document.getElementById("pstype_id").value;
	var branch_id = document.getElementById("branch_id").value;
	if(document.getElementById("branch_id").style.display=='block'){
		requestInfo('showOfficer.php?search_key='+search_key+'&pstype_id='+pstype_id+'&branch_id='+branch_id+prm, 'showOfficer', '');
	}else{
		requestInfo('showOfficer.php?search_key='+search_key+'&pstype_id='+pstype_id+prm, 'showOfficer', '');
	}	
}

function showActivity(act_date) {
	requestInfo('showActivity.php?act_date='+act_date, 'showList', '');
}
function showResult(altpage, prm){
	var pyear = document.getElementById("pyear").value;
	var dist_id = document.getElementById("dist_id").value;
	requestInfo(altpage+"?pyear="+pyear+"&dist_id="+dist_id, 'showResult', '');
}

function reqGeneral(altpage, prm, target){
	requestInfo(altpage+prm, target, '');
}