
		var request;
		var response;				
		var xmlDoc; 
		var selectedID;
		var lstParent;
		var lstChild;
		var stEntity;
		var obToggleControl;
		var stAjaxURL;
		isEmpty = "true";
		   
		function fillDropDown(p_stSelectedValue,p_obParentDropDown,p_obChildDropDown,p_obToggleControl,p_stEntity,p_stAjaxURL)
		{	
			selectedID = p_stSelectedValue;	
			lstParent = p_obParentDropDown;	
			lstChild = p_obChildDropDown;
			obToggleControl = p_obToggleControl;
			stEntity = p_stEntity;
			stAjaxURL = p_stAjaxURL;
			
			if(selectedID == null)
			    selectedID = "";
		
			if(lstParent.options[lstParent.selectedIndex].value != '')
			{   //Check if the selectedItem is not "--Select--"					 
				return SendRequest(lstParent.options[lstParent.selectedIndex].value);				
			}
			else
			{	
				clearSelect(lstChild);//Clear the Child dropdown				
			}			
		}
		   
		function InitializeRequest()
		{			
				//Creating object of XMLHTTP in Mozilla and Safari
			    request = "" 
				if(!request && typeof XMLHttpRequest != "undefined") 
				{   
					request = new XMLHttpRequest();
				}
				else //Creating object of XMLHTTP in IE
				{
					try
					{
						request = new ActiveXObject("Msxml2.XMLHTTP");
					}
					catch(e)
					{
						try
						{
							request = new ActiveXObject("Microsoft.XMLHTTP");
						} 
						catch(oc)
						{
							request = null;
						}
					}
				}
		}
		   
		   
		function SendRequest(ID)
		{
			//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 = stAjaxURL + "?mode=" + stEntity + "&recordID="+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);						
					}
					else
					{							
						//Call clearSelect function						
						clearSelect(lstChild);
					}
				}
			}	
			    
			return true;//return
		}
		
		function populateList(response)
		{
			//Create the XMLDOM object
			var moz = (typeof document.implementation != 'undefined') && (typeof document.implementation.createDocument != 'undefined'); 
			var ie = (typeof window.ActiveXObject != 'undefined');
			
			if(ie)
			{
				xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
				xmlDoc.async  = false;
				while(xmlDoc.readyState!=4) {}
				xmlDoc.loadXML(response);			
			}
			else if(moz)
			{
				var Parser = new DOMParser
				xmlDoc = Parser.parseFromString(response,"text/xml")				
			}
					
					//alert(response)							
			//var sr = new XMLSerializer()
			//alert(sr.serializeToString(xmlDoc))			
							
           //Create the TABLE element
            var TableNameElement
            
            //Extract the table-name tag from the XML text depending upon the calling script 
            switch(stEntity)
            {
                case "state":
                    TableNameElement = xmlDoc.getElementsByTagName("Table");		
                case "active_state":
                    TableNameElement = xmlDoc.getElementsByTagName("Table");									 				                        
            }
		    		
			//Clear the dropdown before filling it with new values
			clearSelect(lstChild);            
           
			if(TableNameElement.length > 0)
			//If there are one or more table nodes
			{	
				for (var i = 0; i < TableNameElement.length; i++)
				//Loop through the XML Table nodes
				{	
					appendToSelect(lstChild, 
					xmlDoc.getElementsByTagName("OPTION_ID")[i].firstChild.nodeValue, xmlDoc.getElementsByTagName("OPTION_NAME")[i].firstChild.nodeValue);					
				}				
				
				//If the child drop down is State then toggle between State drop-down and State text-box
//				if(stEntity == "state" || stEntity == "active_state") 
//				{
//				    lstChild.style.display=""  
//				    if(obToggleControl != null) 
//				        obToggleControl.style.display="none"
//				}				
			}	
			else
			{   //if the child drop down is state then toggle between state drop down and state text box
			    if(stEntity == "state" || stEntity == "active_state") 
				{	
				   
				    if(obToggleControl != null) 
	                { 
	                   obToggleControl.value = selectedID
                    }			   		   
//				    if(obToggleControl != null) 
//				    {    lstChild.style.display="none"	
//                        obToggleControl.style.display=""
//                    }
				}                
			}					
		}
		
				   
		function appendToSelect(select, value, content)
		{		
				//Create an Element of type option
				var opt = document.createElement("option");
				
				//Set the option's value				
				opt.value = value;
				//Attach the text content to the option
				opt.appendChild(document.createTextNode(content));
				//Append the option to the referenced [Child] select box
				select.appendChild(opt);				
				
				var blIsSelected = "N"
			    for(i=0;i<lstChild.options.length;i++)
			    {	
				    if(lstChild[i].value == selectedID)
				    {	try
					    {   
					        if(obToggleControl != null) 
			                { 
			                   obToggleControl.value = ""
                            }
                            blIsSelected = "Y"
						    lstChild[i].selected = true;						    
						    break;
					    }
					    catch(e)
					    {	
					                
						    //document.frmPage.lstChild[0].selected = true;						
					    }
				    }
				   							     	
			    }// for(i=0;i<lstChild.options.length;i++)	
			    
			    
			    if( blIsSelected == "N")		
			    {
			         if(obToggleControl != null) 
			            { 
			               obToggleControl.value = selectedID
                        }
			    }
		}

		 
		function clearSelect(select)
		{	
				//Set the select box's length to 1 
				//so only "--Select--" is available in the selection on calling this function.			
				select.options.length = 1;				
		}

