/* Count textbox length and display lenght of textbox in label */			
function _testText(obj, tstLength) {
			
		var lblName = obj.id;
			
		if ((obj.value.length) > tstLength) 
		{ 
			obj.value = obj.value.substring(0, tstLength); 
		} 
				
	lblName = lblName + '1';
	lblName = lblName.replace('txt','lbl');
	document.getElementById(lblName).innerText = '(' + obj.value.length + ' of ' + tstLength + ' Max)';
			
}
		
/* Display lenght of textbox in label */	
function _testText1(obj, tstLength) {
			
	var lblName = obj.id;
			
	lblName = lblName + '1';
	lblName = lblName.replace('txt','lbl');
	document.getElementById(lblName).innerText = '(' + obj.value.length + ' of ' + tstLength + ' Max)';
			
}

function SearchLoadCities(drplstStates) 
{

  var citiesList = document.getElementById("ucSiteSearch1$drplstCitys");
  //if we couldn't find the states drop down
  if (citiesList == null)
  {
    return; //couldn't find the states dropdown...
  }
  
  citiesList.disabled = true;
  citiesList.options.length = 0;  
  citiesList.options[citiesList.options.length] = new Option("loading...", "loading...");
  
  var stateid = drplstStates.options[drplstStates.selectedIndex].value;
  Daycare.Site_Search.GetCities(stateid, SearchLoadCities_CallBack); 
}

function SearchLoadCities_CallBack(response) 
{

  //if the server side code threw an exception
  if (response.error != null)
  {    
    alert(response.error); //we should probably do better than this
    return;
  }  
  
  var cities = response.value; 
  //if the response wasn't what we expected  
  if (cities == null || typeof(cities) != "object")
  {
    return;  
  }
  
  var citiesList = document.getElementById("ucSiteSearch1$drplstCitys");
  //if we couldn't find the states drop down
  if (citiesList == null)
  {
    return; //couldn't find the states dropdown...
  }
  citiesList.options.length = 0;  
  citiesList.options[citiesList.options.length] = new Option("Select City", "Select City");
  //note that this is JavaScript casing and the L in length is lowercase for arrays
  for (var i = 0; i < cities.Rows.length; ++i)
  {
	citiesList.disabled = false;
	citiesList.options[citiesList.options.length] = new Option(cities.Rows[i].City, cities.Rows[i].City);       
  }  
  
}

function ProviderLoadCities(drplstState) 
{

  var citiesList = document.getElementById("ucProviderLocation1$drplstCity");
  //if we couldn't find the states drop down
  if (citiesList == null)
  {
    return; //couldn't find the states dropdown...
  }

  citiesList.disabled = true;
  citiesList.options.length = 0;  
  citiesList.options[citiesList.options.length] = new Option("loading...", "loading...");
  
  var zipsList = document.getElementById("ucProviderLocation1$drplstZip");
  //if we couldn't find the states drop down
  if (zipsList == null)
  {
    return; //couldn't find the states dropdown...
  }
  
  zipsList.disabled = true;
  zipsList.options.length = 0;  
  zipsList.options[zipsList.options.length] = new Option("Select Zip", "Select Zip");
  
  var stateid = drplstState.options[drplstState.selectedIndex].value;
  Daycare.Provider_Profile.GetCities(stateid, ProviderLoadCities_CallBack); 
}

function ProviderLoadCities_CallBack(response) 
{

  //if the server side code threw an exception
  if (response.error != null)
  {    
    alert(response.error); //we should probably do better than this
    return;
  }  

  var cities = response.value; 
  //if the response wasn't what we expected  
  if (cities == null || typeof(cities) != "object")
  {
    return;  
  }

  var citiesList = document.getElementById("ucProviderLocation1$drplstCity");
  //if we couldn't find the states drop down
  if (citiesList == null)
  {
    return; //couldn't find the states dropdown...
  }
  citiesList.options.length = 0;  
  citiesList.options[citiesList.options.length] = new Option("Select City", "Select City");
  //note that this is JavaScript casing and the L in length is lowercase for arrays
  for (var i = 0; i < cities.Rows.length; ++i)
  {
	citiesList.disabled = false;
	citiesList.options[citiesList.options.length] = new Option(cities.Rows[i].CITY, cities.Rows[i].CITY);       
  }  
  
}

function ProviderLoadZips(drplstCitys) 
{

  var zipsList = document.getElementById("ucProviderLocation1$drplstZip");
  //if we couldn't find the states drop down
  if (zipsList == null)
  {
    return; //couldn't find the states dropdown...
  }

  zipsList.disabled = true;
  zipsList.options.length = 0;  
  zipsList.options[zipsList.options.length] = new Option("loading...", "loading...");

  var statesList = document.getElementById("ucProviderLocation1$drplstState");
  //if we couldn't find the states drop down
  if (statesList == null)
  {
    return; //couldn't find the states dropdown...
  }

  var stateid = statesList.options[statesList.selectedIndex].value;

  var cityid = drplstCitys.options[drplstCitys.selectedIndex].value;
  Daycare.Provider_Profile.GetZips(stateid, cityid, ProviderLoadZips_CallBack); 

}

function ProviderLoadZips_CallBack(response) 
{

  //if the server side code threw an exception
  if (response.error != null)
  {    
    alert(response.error); //we should probably do better than this
    return;
  }  
  
  var zips = response.value; 
  //if the response wasn't what we expected  
  if (zips == null || typeof(zips) != "object")
  {
    return;  
  }
  
  var zipsList = document.getElementById("ucProviderLocation1$drplstZip");
  //if we couldn't find the states drop down
  if (zipsList == null)
  {
    return; //couldn't find the states dropdown...
  }
  zipsList.options.length = 0;  
  zipsList.options[zipsList.options.length] = new Option("Select Zip", "Select Zip");
  //note that this is JavaScript casing and the L in length is lowercase for arrays
  for (var i = 0; i < zips.Rows.length; ++i)
  {
	zipsList.disabled = false;
	zipsList.options[zipsList.options.length] = new Option(zips.Rows[i].ZIPCODE, zips.Rows[i].ZIPCODE);       
  }  
  
}