var request;
		var response;
		var Territory;
		
		var Employee ;
	///onchange="return populateTerritory(drpmaincat1,drpsubcat1);"

     ///two parametes are passed dropdownmain and dropdownsub
     //
   function populateTerritory(drpname,drpname1)
   { 
     

	Employee=drpname;//assigning dropname to employee variable
	
	Territory=drpname1  //assigning dropsub to territory varibale
    
   
    if(Employee.options[Employee.selectedIndex].value != '')
    {   
     return SendRequest(Employee.options[Employee.selectedIndex].value);
    }
    else
    {
     clearSelect(Territory);//Clear the Territory dropdown
     status.innerText = "";//Blank the status text label
    }
   }

   function InitializeRequest()
   {
    try
    {
     request = new ActiveXObject("Microsoft.XMLHTTP");
     //Try creating an XMLHTTP Object
    }
    catch(Ex)
    {
     try
     {
      //First failure, try again creating an XMLHTTP Object
      request = new ActiveXObject("Microsoft.XMLHTTP");
     }
     catch(Ex)
     {
        //Else assign null to request

    request = null;
     }
    }
    if(!request&&typeof XMLHttpRequest != 'undefined')
    {
     request = new XMLHttpRequest();
    }
   }

   function SendRequest(ID)///MAIN DROPS PARAMETER IS PASSED AS INDEX VALUE
   {
    ///////////status.innerText = "Loading.....";//Set the status to "Loading....."
    InitializeRequest();//Call InitializeRequest to set request object    
    //Create the url to send the request to
    var url = "EmployeeTerritoryAjaxServer.aspx?EmployeeID="+ID;
    //Delegate ProcessRequest to onreadystatechange property so 
    //it gets called for every change in readyState value
    request.onreadystatechange = ProcessRequest;
    request.open("GET", url, true);//Open a GET request to the URL
    request.send(null);//Send the request with a null body.
   }

   function ProcessRequest()
   {  
    if(request.readyState == 4)
    //If the readyState is in the "Ready" state
    {
     if(request.status == 200)
     //If the returned status code was 200. 
     //Everything was OK.
     {
      if(request.responseText != "")
      //If responseText is not blank
      {   

       //Call the populateList fucntion      
       populateList(request.responseText);
       //Set the status to "Territories Loaded"
       ////////status.innerText = "Territories Loaded";
      }
      else
      {
       //Set the status to "None Found"
      /////////////// status.innerText = "None Found";
       //Call clearSelect function
     
       clearSelect(Territory);
      }
     }
    }
    return true;//return
   }

   function populateList(response)
   {
    //Create the XMLDOM object
    ////var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
	var xmlDoc=null;
    if ((typeof document.implementation != 'undefined') && (typeof document.implementation.createDocument != 'undefined'))
     {
      //create the DOM Document the standards way
      
      xmlDoc = document.implementation.createDocument("","EmployeeTerritories", null);     
      xmlDoc.load(request.responseXML);
      xmlDoc.onload=request.responseXML;
      var TerritoriesElem = request.responseXML.getElementsByTagName("EmployeeTerritories"); 
      var TerritoryElem=request.responseXML.getElementsByTagName("tbl_itemsubcategory");   
	  clearSelect(Territory);  
	 
	if(TerritoriesElem.length > 0)    
		{          
		for (var i = 0; i < TerritoryElem.length; i++)   
		{   
		var textNode = document.createTextNode(
			TerritoryElem[i].getAttribute("itemsubcattitle"));
			
		appendToSelect1(Territory, 
		TerritoryElem[i].getAttribute("itemsubcatid"),textNode);
		}
		}
   }  
     
 else if (navigator.appName.indexOf("Microsoft Internet Explorer")>(-1))
  {
		//create the DOM Document the IE way
		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async = false;
		//Load the responseText into the XMLDOM document
		xmlDoc.loadXML(response); 
	       
      
		//Create the EmployeeTerritories element  
			var TerritoriesElem = xmlDoc.getElementsByTagName("EmployeeTerritories"); 
			var TerritoryElem = TerritoriesElem[0].getElementsByTagName("tbl_itemsubcategory"); 
			clearSelect(Territory);
			if(TerritoriesElem.length > 0)
    //If there are one or more TERRITORIES nodes
		{          
		for (var i = 0; i < TerritoryElem.length; i++)
		//Loop through the XML TERRITORIES nodes
		{ 
	      
		appendToSelect(Territory, 
		TerritoryElem[i].getAttribute("itemsubcatid"),TerritoryElem[i].getAttribute("itemsubcattitle"));
		}
		} 
	 }   
   }

   function appendToSelect(select, value, content)
   {    
             
    var st;
    var soption = "";   
	st = new Option(content,value);
	Territory.add(st);
	////document.all["ddTerritory"].add(st)
   }
   function appendToSelect1(select, value, content)
   {   
    var opt;
    //Create an Element of type option
    opt = document.createElement("option");
    //Set the option's value
    opt.value =value;
    //Attach the text content to the option
    opt.appendChild(content);
    //Append the option to the referenced [Territory] select box
  Territory.appendChild(opt);
   }

   function clearSelect(select)
   {
    //Set the select box's length to 1 
    //so only "--Select--" is available in the selection on calling this function.
     Territory.length=1;
      /*if ((typeof document.implementation != 'undefined') && (typeof document.implementation.createDocument != 'undefined'))
     {
     	var textNode = document.createTextNode("All");
			
		var opt;
		//Create an Element of type option
		opt = document.createElement("option");
		//Set the option's value
		opt.value =500;
		//Attach the text content to the option
		opt.appendChild(textNode);
		//Append the option to the referenced [Territory] select box
		Territory.appendChild(opt);
     }
     else
     {     
		var st;
		var soption = "";   
		st = new Option("All",500);
		Territory.add(st);		
     }*/
     
     
	///////document.all["ddTerritory"].length=1;
    //You may want to write your own clearSelect logic
   }