﻿
function parseRepsonse(result, context)
{
    //result format: data_type:prop0,prop1,prop2|prop0,prop1,...
    var resultData = result.split(":");
    
    if (resultData[0] == "citydata")
    {
    	$get(ctrlId + "CityDropDown").disabled = false;
    	$get(ctrlId + "SubmitLocationButton").disabled = false;
    	try {
    	    $get(ctrlId + "SubmitScanAvailableButton").disabled = false;
    	    $get(ctrlId + "SubmitMapButton").disabled = false;
    	}
    	catch (Error) {

    	}
    	
	    var citiesArray = resultData[1].split("|");     
        for (var i=0; i < citiesArray.length; i++)
        {
 		    var opt = document.createElement("option");
 		    var cityDataArray = citiesArray[i].split(",");
    		
    		opt.text = (cityDataArray[2] != "" ? (cityDataArray[2] + ", ") : "") + cityDataArray[0] + " " + cityDataArray[4];
		    opt.value = cityDataArray[1];   
		    $get(ctrlId + "CityDropDown").options.add(opt);       
        }
    } 
    else if (resultData[0] == "countrydata")
    {   
	    var countryArray = resultData[1].split("|");        
        for (var i=0; i < countryArray.length; i++)
        {
            var countryData = countryArray[i].split(",");
 		    
 		    var opt = document.createElement("option");
		    opt.text = countryData[0] + " " + countryData[2];
    		opt.value = countryData[1];       
		    $get(ctrlId + "CountryDropDown").options.add(opt);       
        }       
    }
}
function categorySelected(categoryid)
{
    $get(ctrlId + "CountryDropDown").options.length = 0;
    $get(ctrlId + "CityDropDown").options.length = 0;
    $get(ctrlId + "CityDropDown").disabled = true;
    $get(ctrlId + "SubmitLocationButton").disabled = true;
    try {   
        $get(ctrlId + "SubmitScanAvailableButton").disabled = true;
        $get(ctrlId + "SubmitMapButton").disabled = true;
    }
    catch (Error) {

    } 
    $get(ctrlId + "SelectedCategoryField").value = $get(ctrlId + "ListingCategory").options[$get(ctrlId + "ListingCategory").selectedIndex].value;
    $get(ctrlId + "SelectedLocationField").value = '';
    
    callback("categoryselected:" + categoryid, "");
}
function countrySelected(countryId)
{
    $get(ctrlId + "CityDropDown").options.length = 0;
	$get(ctrlId + "SelectedLocationField").value = countryId;
    $get(ctrlId + "SelectedCategoryField").value = $get(ctrlId + "ListingCategory").options[$get(ctrlId + "ListingCategory").selectedIndex].value;
    callback("countryselected:" + countryId + "," + $get(ctrlId + "ListingCategory").options[$get(ctrlId + "ListingCategory").selectedIndex].value, "");
}
function citySelected()
{
    var cityid = $get(ctrlId + "CityDropDown").options[$get(ctrlId + "CityDropDown").selectedIndex].value;
    $get(ctrlId + "SelectedCategoryField").value = $get(ctrlId + "ListingCategory").options[$get(ctrlId + "ListingCategory").selectedIndex].value;
        
    if (cityid != 0)
	    $get(ctrlId + "SelectedLocationField").value = cityid;
	else
	     $get(ctrlId + "SelectedLocationField").value = $get(ctrlId + "CountryDropDown").options[$get(ctrlId + "CountryDropDown").selectedIndex].value;    
}

