var controlsource=null;
var controltarget=null;
var controltargets = null;
var response =null;
var xmlHttp; 

 
function getAjaxData(target,variable){

controltarget = target;
var j = controltarget.options.length;

for(i=1; i<j; i++){
 //controltarget.remove(i);
 controltarget.options[i]=null;
 controltarget.remove(i);
}

//addOption(controltarget,"-1","Select a LGA");
var url = "ajax.php" + variable;

xmlHttp = createXMLHttpRequest();


xmlHttp.open("GET", url, true);
xmlHttp.onreadystatechange = roleChange_CallBack;

xmlHttp.send(null);
//xmlHttp=null;
 }


function roleChange_CallBack(){
var j = controltarget.options.length;

for(i=1; i<=j; i++){
 //controltarget.remove(i);
 controltarget.options[i]=null;
 controltarget.remove(i);
}

if(xmlHttp.readyState == 4) {

if(xmlHttp.status == 200) {

response = xmlHttp.responseXML.getElementsByTagName("message")[0];


//addOption(controltarget,"-1","Select a LGA");

for ( x=0; x<response.childNodes.length; x++){

//Populate drop box

if (response.childNodes[x].childNodes[0].firstChild.nodeValue != null && response.childNodes[x].childNodes[1].firstChild.nodeValue != null) {
//alert(response.childNodes[x].childNodes[0].firstChild.nodeValue+" ,"+ response.childNodes[x].childNodes[1].firstChild.nodeValue);
addOption(controltarget, response.childNodes[x].childNodes[0].firstChild.nodeValue , response.childNodes[x].childNodes[1].firstChild.nodeValue);

}
}
}
}
}

 

function addOption(selectbox,value,text)
{
	
var optn = new Option(text, value, false, false);
var browserName=navigator.appName; 
 if (browserName=="Netscape")
	{ 
	selectbox.add(optn,null);
	}
else if (browserName=="Microsoft Internet Explorer")
	 {
	  selectbox.add(optn);
	 }
	 else
	 {
		selectbox.add(optn);
	  }
//selectbox.add(optn,null);
//alert('HERE1');
}

function createXMLHttpRequest() {  
 var http_request;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
	   try {
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
            http_request.overrideMimeType('text/xml');
         }
		  } catch (e) { http_request = false;}
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) { http_request = false;}
         }
      } 
 return http_request;  
 } 
 
    

/*********************************************
Date Compare function
**********************************************/


function CompareDates(str1,str2)
{
   var dt1   = parseInt(str1.substring(0,2),10);
   var mon1  = parseInt(str1.substring(3,5),10);
   var yr1   = parseInt(str1.substring(6,10),10);
   var dt2   = parseInt(str2.substring(0,2),10);
   var mon2  = parseInt(str2.substring(3,5),10);
   var yr2   = parseInt(str2.substring(6,10),10);
   var date1 = new Date(yr1, mon1, dt1);
   var date2 = new Date(yr2, mon2, dt2);

   if(date2 < date1)
   {
      //alert("To date cannot be greater than from date");
      return true;
   }
   else
   {
      return false;
   }
}
/*************************************************************************
section to handle single Text Response
**************************************************************************/

function getAjaxDataText(variable){
var url = "ajax.php"+ variable;

xmlHttp = createXMLHttpRequest();
if(xmlHttp){

xmlHttp.open("GET", url, false);
//xmlHttp.onreadystatechange = text_CallBack;
xmlHttp.send(null);
//alert(xmlHttp.responseText);
return  xmlHttp.responseText;
}
else
return false;
//xmlHttp=null;
 }


/*function text_CallBack(){

if(xmlHttp.readyState == 4) {
if(xmlHttp.status == 200) {
controltarget.value = xmlHttp.responseText;
}
}
//return response;
}
*/