

			var request;
			var response;

			var Territory;// =document.getElementById("ddTerritory");
			var status;// = document.getElementById("lblStatus");
			var objCourses;
			var objCentres;
			var objStates;
			var  objCity;
			var xmlDoc=null;
			
			var CourseStartText;
			var StateStartText;
			var CityStartText;
			
			
			function populateCourses(ddlQualifications,ddlCourses,PagePath)
			{
			
		
			   objCourses=ddlCourses;
			   
			   //alert(ddlCourses.options[ddlCourses.selectedIndex].value);
			   if(ddlQualifications.options[ddlQualifications.selectedIndex].value != 'undefined')
				{
					return SendRequestCourses(ddlQualifications.options[ddlQualifications.selectedIndex].value,PagePath);
				}
				else
				{
					clearSelect(objStates);
				}
			}

			function populateCentres(ddlStates,ddlCentres,CourseName,PagePath)
			{

			    objCentres=ddlCentres;
			
				if(ddlStates.options[ddlStates.selectedIndex].value !=0)
				//Check if the selectedItem as not "--Select--"
				{
					return SendCentreRequest(ddlStates.options[ddlStates.selectedIndex].value,CourseName,PagePath);
				}
				else
				{
					clearSelect(objCentres);
				}
			}
			
			
			function populateStates(ddlCourses,ddlStates,PagePath)
			{
			//debugger
		
			   objStates=ddlStates;
			   
			   //alert(ddlCourses.options[ddlCourses.selectedIndex].value);
			   if(ddlCourses.options[ddlCourses.selectedIndex].value != 'undefined')
				{
					return SendRequestStates(ddlCourses.options[ddlCourses.selectedIndex].value,PagePath);
				}
				else
				{
					clearSelect(objStates);
				}
			}
			
			
			function populateCity(ddl_state,ddl_city,PagePath)
			{
			
		
			   objCity=ddl_city;
			   
			   //alert(ddl_state.options[ddl_state.selectedIndex].value);
			   if(ddl_state.options[ddl_state.selectedIndex].value != 'undefined')
				{
					return SendRequestCity(ddl_state.options[ddl_state.selectedIndex].value,PagePath);
				}
				else
				{
					clearSelect(objCity);
				}
			}
			
			function InitializeRequest()
			{
				try
				{
					request = new ActiveXObject("Microsoft.XMLHTTP");//Try creating an XMLHTTP Object
				}
				catch(Ex)
				{
					try
					{
				
						request = new ActiveXObject("Microsoft.XMLHTTP");//First failure, try again creating an XMLHTTP Object
					}
					catch(Ex)
					{
			
						request = null;//Else assign null to request
					}
				}

				if(!request&&typeof XMLHttpRequest != 'undefined')
				{
					request = new XMLHttpRequest();
				}
			}
			
			function SendRequestCourses(ID,PagePath)
			{
				//status.innerText = "Loading.....";//Set the status to "Loading....."
				InitializeRequest();//Call InitializeRequest to set request object
				
				var url = PagePath + "?Qualification="+ID.replace(/&/g,"/nbsp;");//Create the url to send the request to
				//alert(url);
				CourseStartText=objCourses.options[0].text;
				
				request.onreadystatechange = ProcessCourseRequest;//Delegate ProcessRequest to onreadystatechange property so it gets called for every change in readyState value
				request.open("GET", url, true);//Open a GET request to the URL
				request.send(null);//Send the request with a null body.
			}

			function SendRequestStates(ID,PagePath)
			{
				
		
				InitializeRequest();//Call InitializeRequest to set request object
				var url = PagePath + "?CourseName="+ID.replace(/&/g,"/nbsp;");//Create the url to send the request to
			//	alert(url);
			    
			    StateStartText=objStates.options[0].text;
			   
				request.onreadystatechange = ProcessStateRequest;//Delegate ProcessRequest to onreadystatechange property so it gets called for every change in readyState value
				request.open("GET", url, true);//Open a GET request to the URL
				request.send(null);//Send the request with a null body.
			}

			function SendCentreRequest(ID,CourseName,PagePath)
			{
				//status.innerText = "Loading.....";//Set the status to "Loading....."
				InitializeRequest();//Call InitializeRequest to set request object
				var url = PagePath + "?StateName="+ID.replace(/&/g,"/nbsp;")+"&CourseName="+CourseName.replace(/&/g,"/nbsp;");//Create the url to send the request to
			//	alert(url);
			    CityStartText=objCentres.options[0].text;
				request.onreadystatechange = ProcessCentreRequest;//Delegate ProcessRequest to onreadystatechange property so it gets called for every change in readyState value
				request.open("GET", url, true);//Open a GET request to the URL
				request.send(null);//Send the request with a null body.
			}
			
			
			function SendRequestCity(ID,PagePath)
			{
				//status.innerText = "Loading.....";//Set the status to "Loading....."
				InitializeRequest();//Call InitializeRequest to set request object
				var url = PagePath +"?StateName="+ID.replace(/&/g,"/nbsp;");//Create the url to send the request to
			//	alert(url);
				request.onreadystatechange = ProcessCityRequest;//Delegate ProcessRequest to onreadystatechange property so it gets called for every change in readyState value
				request.open("GET", url, true);//Open a GET request to the URL
				request.send(null);//Send the request with a null body.
				
			}
			
			function ProcessCourseRequest()
			{
				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
						{
							
							populateCourseList(request.responseText);//Call the populateList fucntion
							//status.innerText = "Territories Loaded";//Set the status to "Territories Loaded"
						}
						else
						{
							//status.innerText = "None Found";//Set the status to "None Found"
							clearSelect(objCourses);//Call clearSelect function
						}
					}
				}
				else
				{
				   ShowLoading(objCourses);
				}
				return true;//return
			}

			function ProcessStateRequest()
			{
				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
						{
							
							populateStateList(request.responseText);//Call the populateList fucntion
							//status.innerText = "Territories Loaded";//Set the status to "Territories Loaded"
						}
						else
						{
							//status.innerText = "None Found";//Set the status to "None Found"
							clearSelect(objStates);//Call clearSelect function
						}
					}
				}
				else
				{
				   ShowLoading(objStates);
				}
				return true;//return
			}
			
			function ProcessCentreRequest()
			{
				if(request.readyState == 4)
				{
					if(request.status == 200)
					{
						if(request.responseText != "")
						{
							
							populateCentreList(request.responseText);//Call the populateList fucntion
							
						}
						else
						{
							
							clearSelect(objCentres);
						}
					}
				}
				else
				{
				   ShowLoading(objCentres);
				}
				return true;//return
			}
			
			function ProcessCityRequest()
			{
				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
						{
							//alert(request.responseText);
							
							populateCityList(request.responseText);//Call the populateList fucntion
							//status.innerText = "Territories Loaded";//Set the status to "Territories Loaded"
						}
						else
						{
							//alert(request.responseText);
							//status.innerText = "None Found";//Set the status to "None Found"
							clearSelect(objCity);//Call clearSelect function
						}
					}
				}
				return true;//return
			}
			
			function populateCourseList(response)
			{
			
				
				try //Internet Explorer
				{
					xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
					xmlDoc.async=false;
					response=response.substring(0,response.indexOf("<!DOCTYPE"));
 	                xmlDoc.loadXML(response);
 	                FillCourses();
				}
				catch(e)
				{
				try //Firefox, Mozilla, Opera, etc.
				{
					parser=new DOMParser();
					response=response.substring(0,response.indexOf("<!DOCTYPE"));
					xmlDoc=parser.parseFromString(response,"text/xml");
					FillCourses();
				}
				catch(e) {alert(e.message)}
				}
				
			
			}

			function populateStateList(response)
			{
			
				
				try //Internet Explorer
				{
					xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
					xmlDoc.async=false;
					response=response.substring(0,response.indexOf("<!DOCTYPE"));
 	                xmlDoc.loadXML(response);
 	                FillStates();
				}
				catch(e)
				{
				try //Firefox, Mozilla, Opera, etc.
				{
					parser=new DOMParser();
					response=response.substring(0,response.indexOf("<!DOCTYPE"));
					xmlDoc=parser.parseFromString(response,"text/xml");
					FillStates();
				}
				catch(e) {alert(e.message)}
				}
				
			
			}

			function populateCentreList(response)
			{
		
				try //Internet Explorer
				{
					xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
					xmlDoc.async=false;
					response=response.substring(0,response.indexOf("<!DOCTYPE"));
 	                xmlDoc.loadXML(response);
 	                FillCentres();
				}
				catch(e)
				{
				try //Firefox, Mozilla, Opera, etc.
				{
					parser=new DOMParser();
					response=response.substring(0,response.indexOf("<!DOCTYPE"));
					xmlDoc=parser.parseFromString(response,"text/xml");
					FillCentres();
				}
				catch(e) {alert(e.message)}
				}
				
			}
			
			function populateCityList(response)
			{
			
				//debugger
				try //Internet Explorer
				{
					xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
					xmlDoc.async=false;
					response=response.substring(0,response.indexOf("<!DOCTYPE"));
 	                xmlDoc.loadXML(response);
 	                //alert(response)
 	                FillCity();
				}
				catch(e)
				{
				try //Firefox, Mozilla, Opera, etc.
				{
					parser=new DOMParser();
					response=response.substring(0,response.indexOf("<!DOCTYPE"));
					xmlDoc=parser.parseFromString(response,"text/xml");
					//alert(xmlDoc);
					FillCity();
				}
				catch(e) {alert(e.message)}
				}
				
			
			}
			
			
			
			function appendToSelect(select, value, content)
			{
				var opt;
				opt = document.createElement("option");//Create an Element of type option
				opt.value = value;//Set the option's value
				opt.appendChild(content);//Attach the text content to the option
				select.appendChild(opt);//Append the option to the referenced [Territory] select box
			}

			function clearSelect(select)
			{
				select.options.length = 1;//Set the select box's length to 1 so only "--Select--" is availale in the selection on calling this function.
										  //You may want to write your own clearSelect logic
			}
			
			function ShowLoading(select)
			{
			    select.options.length = 1;
				select.options[0].text = "loading....";//Set the select box's length to 1 so only "--Select--" is availale in the selection on calling this function.
										  //You may want to write your own clearSelect logic
			}
			
			
			
			function FillCourses()
			{
		
				if(xmlDoc!=null)
				{
					var opt;
					var TerritoriesElem = xmlDoc.getElementsByTagName("root");
					var TerritoryElem = TerritoriesElem[0].getElementsByTagName("COURSE");
					
					objCourses.options[0].text=CourseStartText;
					objCourses.options[0].value='';
					
					clearSelect(objCourses);
					if(TerritoriesElem.length > 0)
					{
						for (var i = 0; i < TerritoryElem.length; i++)
						{
							var textNode = document.createTextNode(TerritoryElem[i].getAttribute("DESC"));
							appendToSelect(objCourses, TerritoryElem[i].getAttribute("DESC"), textNode);//Call appendToSelect to append the text elements to the Territory dropdown
						}
					} 
				}
				else
				   clearSelect(objCourses);  
				
			}
			
			
			function FillStates()
			{
		
				if(xmlDoc!=null)
				{
					var opt;
					var TerritoriesElem = xmlDoc.getElementsByTagName("root");
					var TerritoryElem = TerritoriesElem[0].getElementsByTagName("STATE");
					
					objStates.options[0].text=StateStartText;
					objStates.options[0].value='';
					
					clearSelect(objStates);
					if(TerritoriesElem.length > 0)
					{
						for (var i = 0; i < TerritoryElem.length; i++)
						{
							var textNode = document.createTextNode(TerritoryElem[i].getAttribute("DESC"));
							appendToSelect(objStates, TerritoryElem[i].getAttribute("DESC"), textNode);//Call appendToSelect to append the text elements to the Territory dropdown
						}
					} 
				}
				else
				   clearSelect(objStates);  
				
			}
			
			
			function FillCentres()
			{
			   if(xmlDoc!=null)
				{
					var opt;
					var TerritoriesElem = xmlDoc.getElementsByTagName("root");//Create the EmployeeTerritories element
					//alert(TerritoriesElem[0]);
					var TerritoryElem = TerritoriesElem[0].getElementsByTagName("CITY");//Create the TERRITORIES element
				    
				    objCentres.options[0].text=CityStartText;
					objCentres.options[0].value='';
				
				
					clearSelect(objCentres);//Clear the dropdown before filling it with new values
					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
						{
							var textNode = document.createTextNode(TerritoryElem[i].getAttribute("DESC"));
							appendToSelect(objCentres, TerritoryElem[i].getAttribute("VALUE"), textNode);//Call appendToSelect to append the text elements to the Territory dropdown
						}
					}
				}
				else
				 clearSelect(objCentres);
			}
			
			function FillCity()
			{
		//debugger
				if(xmlDoc!=null)
				{
					
					var opt;
					
					var TerritoriesElem = xmlDoc.getElementsByTagName("root");
					var TerritoryElem = TerritoriesElem[0].getElementsByTagName("citymaster");
					
					
					clearSelect(objCity);
					//alert(TerritoriesElem.length);
					if(TerritoriesElem.length > 0)
					{
						for (var i = 0; i < TerritoryElem.length; i++)
						{
							var textNode = document.createTextNode(TerritoryElem[i].getAttribute("varCityName"));
							appendToSelect(objCity, TerritoryElem[i].getAttribute("intCityId"), textNode);//Call appendToSelect to append the text elements to the Territory dropdown
							
							
						}
						objCity.options[i+1] = new Option("Others","Others");
					} 
					
				}
				else
				   clearSelect(objCity);  
				
			}


// Form Tracker
			function InsertFormsData(brand,PagePath)
			{
				//status.innerText = "Loading.....";//Set the status to "Loading....."
				InitializeRequest();//Call InitializeRequest to set request object
				var url = PagePath;//Create the url to send the request to
			//	alert(url);
				request.onreadystatechange = ProcessFormRequest;//Delegate ProcessRequest to onreadystatechange property so it gets called for every change in readyState value
				request.open("GET", url, true);//Open a GET request to the URL
				request.send(null);//Send the request with a null body.
				
			}
			
			
			function ProcessFormRequest()
			{
			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
						{
							//alert(request.responseText);
							
							//populateCityList(request.responseText);//Call the populateList fucntion
							//status.innerText = "Territories Loaded";//Set the status to "Territories Loaded"
						}
					}
				}
				return true;//return
			}						
