var selectedCity = "";  	
    
function selectProvince(provinceSelect, citySelect)
{
	new Ajax.Request('/ajax/getCities.php',   
	{     
		method:'get', 
		parameters: $(provinceSelect).serialize(true),  
		onSuccess: function(transport){       
			var response = transport.responseText; 
			if (response == null) alert('Could not load city list, if error persists please contact us...');
			else
			{
				$(citySelect).options.length = 1;
				
  				var cities = response.evalJSON();  
   				populateCitySelect(citySelect, cities);  
   				selectCity(citySelect, selectedCity); 
			} 
   		},     
    	onFailure: function(){ 
    		alert('Could not load city list, if error persists please contact us...');
    	}   
    });
}
    	
function populateCitySelect(citySelect, cities)
{
	var citySelect = $(citySelect);    
    //citySelect.options.length = 1;
	    
    // add an 'all cities' option with a blank value
		    
    var optionNum = 1;
    //var option = new Option("");
    //citySelect.options[0] = option;
		    
    // add cities received from ajax 
		    
    for (var i = 0, length = cities.length; i < length; ++i) 
    {
    	var option = new Option(cities[i]);
        citySelect.options[optionNum] = option;
        optionNum++;
	}
}
    	
function selectCity(citySelect)
{
	var citySelect = $(citySelect);
	
    if (selectedCity)
    {
        for (i=0; i < citySelect.options.length; i++)
        {
            if (citySelect.options[i].text == selectedCity)
                citySelect.options[i].selected = true;
            else
                citySelect.options[i].selected = false;
        }
    }
 
    selectedCity = "";
}