function createRequestObject() {
	var ro;
	var browser = navigator.appName;
	if(browser == "Microsoft Internet Explorer"){
		ro = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		ro = new XMLHttpRequest();
	}
	return ro;
}
var http = createRequestObject();
var nextid;
var accessId;
function addOption(selectbox,text,value)
{
	var optn = document.createElement("option");
	optn.text = text;
	optn.value = value;
	selectbox.options.add(optn);
}
function getBlkAll(firstid,secondid) 
{
	nextid = secondid;
	var action=firstid.value;
	//alert(action)
	if(action == 'All')
	{
	  document.getElementById(nextid).value = 'All';
	  document.getElementById("idStateOffice").value = 'All';
	}
	else 
	{
	  http.open('get','ajax.php?blkId='+action+'&selDist=true');
	  http.onreadystatechange = handleResponseAll; //Function which handels the response.
	}
	http.send(null);
}
function getOffice(firstid,secondid) 
{
	nextid = secondid;
	var action=firstid.value;
	//alert(action)
	if(action == 'All')
	  document.getElementById("idStateOffice").value = 'All';
	else
	{
	  http.open('get','ajax.php?StateOfficeId='+action+'&selDist=true');
	  http.onreadystatechange = handleResponseAll; //Function which handels the response.
	}
	http.send(null);
}
function handleResponseAll() {
//if it is in ready state...
	if(http.readyState == 4)
	{
		var response = http.responseText;
		var update = new Array();		var abc=new Array();
		//alert(response)
		if(response.indexOf('|' != -1)) 
		{
//			data will come like this  cd#name | cd1#name1 | cd2#name....
			  update = response.split('|');
			  //alert(update);
			  for(var index=0; index < update.length;index++)
			  {
				  update1 =update[index].split(',');
				  if(update1[0] == '')
					  update1 = update;
				   abc[index]=update1[0].split('#');
			  }
			  //get another selection box element 
			  var next_selection =document.getElementById(nextid);
			  // remove all the previous items in the list box....
			  for ( ; next_selection.length > 0 ;  )
			  {
					next_selection.remove(next_selection.selectedIndex.value);
			  }
			  //First we should display Select.......
			  if(!response)
			 {
			     addOption(next_selection,'Select','');
			     addOption(next_selection,'All','All');
				 return;
			 }
			     addOption(next_selection,'Select','');
			     addOption(next_selection,'All','All');
			  for ( i=0; i<abc.length-1; i+=1)
			  {	
			  
				//add all options in the selection box which got from the database....
			      if(abc[i][1] != "")
				    addOption(next_selection,abc[i][1],abc[i][0]);
			  }
		  }
	}
}

