
<!-- Helper functions for ajax  

function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	{
	  		// Firefox, Opera 8.0+, Safari
	  xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
	      // Internet Explorer
	  try
	  {
	    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	  }
	  catch (e)
	  {
	        try
		    {
		      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		    }
		    catch (e)
		    {
		    }
	   }
	}
	return xmlHttp;
}

function getAreas(selected_country, selected_city)
{
  xmlHttp=GetXmlHttpObject();
  if (xmlHttp==null)
  {
	  alert ("Your browser does not support Java Script/AJAX!");
	  return;
  } 
  xmlHttp.onreadystatechange=function()
  {
    if(xmlHttp.readyState==4)
    {
      res =  xmlHttp.responseText;
	  areaNames=res.split(",");   
	  
       if ((areaNames.length == 1) && (areaNames[0] == "[ Area ]")){
            document.Form0.area_name.options[0] = new Option("[ No Area ]", 0);
            document.Form0.area_name.disabled = 1;
       }
       else{
			for(i = 0; i < areaNames.length; i++){
	                  document.Form0.area_name.options[i]	= new Option(areaNames[i], i);
			}
			document.Form0.area_name.disabled = 0;
	   }
      document.Form0.area_name.options[0].selected = true;
      
      
    }
  }
  document.Form0.area_name.options[0]	= new Option("Loading ...", 0);
  xmlHttp.open("GET","/pub?service=external/AjaxGetAreas&sp=S" + selected_country + "&sp=S" + selected_city,true);
  xmlHttp.send(null);
}

function OnChangeCity(){


        sel_country_index = document.Form0.country_name.selectedIndex;
		sel_country_value = document.Form0.country_name.options[sel_country_index].text;

		sel_city_index = document.Form0.city_name.selectedIndex;
		sel_city_value = document.Form0.city_name.options[sel_city_index].text;

		

        document.Form0.area_name.options[0]	= new Option("[ Area ]", 0);
                   // make current area options null  except first one [ Area ]
		for(i = document.Form0.area_name.length - 1; i > 0; i--)
			document.Form0.area_name.options[i]	= null;
			
		
		if (sel_city_value == "[ City ]" || sel_city_value == "--------------"){
		   return;
		}



		 getAreas(sel_country_value, sel_city_value);
	    


	}

function getCities(selected_country)
{
  xmlHttp=GetXmlHttpObject();
  if (xmlHttp==null)
  {
	  alert ("Your browser does not support Java Script/AJAX!");
	  return;
  } 
  xmlHttp.onreadystatechange=function()
  {
    if(xmlHttp.readyState==4)
    {
      res =  xmlHttp.responseText;
      
	  cityNames=res.split(",");
	
			for(i = 0; i < cityNames.length; i++){
	                  document.Form0.city_name.options[i]	= new Option(cityNames[i], i);
			}
      document.Form0.city_name.options[0].selected = true;
      
      
    }
  }
  document.Form0.city_name.options[0]	= new Option("Loading ...", 0);
  xmlHttp.open("GET","/pub?service=external/AjaxGetCities&sp=S" + selected_country ,true);
  xmlHttp.send(null);
}

	function OnChangeCountry(){



		sel_country_index = document.Form0.country_name.selectedIndex;

		sel_country_value = document.Form0.country_name.options[sel_country_index].text;

		

         document.Form0.city_name.options[0]	= new Option("[ City ]", 0);
         
                   // make current city options null  except first one [ City ]
		for(i = document.Form0.city_name.length - 1; i > 0; i--)
			document.Form0.city_name.options[i]	= null;
			
		document.Form0.area_name.options[0]	= new Option("[ Area ]", 0);
	    		           // make current area options null  except first one [ Area ]
		for(i = document.Form0.area_name.length - 1; i > 0; i--)
				document.Form0.area_name.options[i]	= null;
			
		
		if (sel_country_value == "[ Country ]"){
		     return;
		}



		 getCities(sel_country_value)
	    


	}
	
	
	
	
  //  end  -->

