﻿
function buildDDL(HandleType, ActionDDL, WorkDDL, targetItem, targetValue){
    var CityId = $('#ddlCity').val(); 
    if(WorkDDL=='ddlCity'){
        CityId = targetValue;
    }else{
        CityId = $('#ddlCity').val();
    }
    
    var AreaId = $('#ddlArea').val(); 
    if(WorkDDL=='ddlArea'){
        AreaId = targetValue;
    }else{
        AreaId = $('#ddlArea').val();
    }
    
    var CountryId = $('#ddlCountry').val(); 
    if(WorkDDL=='ddlCountry'){
        CountryId = targetValue;
    }else{
        CountryId = $('#ddlCountry').val();
    }
    
    var ContinentId = ""; 
    if(WorkDDL=='ddlContinent'){
        ContinentId = targetValue;
        
    }else{
        ContinentId = $('#ddlContinent').val();
    }
    
    if(HandleType == 'onchange'){
        if(ActionDDL=='ddlCity'){CityId = "";}
        if(ActionDDL=='ddlArea'){
            CityId = "";
        }
        if(ActionDDL=='ddlCountry'){
            AreaId = "";
            CityId = "";
        }
        if(ActionDDL=="ddlContinent"){
            CountryId = "";
            AreaId = "";
            CityId = "";
        }
    }
    
    var url = "HandleAction.aspx?HandleType=" + HandleType + "&WorkDDL=" + WorkDDL + "&ContinentId=" + ContinentId + "&CountryId=" + CountryId + "&AreaId=" + AreaId + "&CityId="+ CityId + "&TF=" + new Date().getTime();
	$('#'+targetItem).html('<select><option>查詢中...</option></select>');

	$.ajax({
		type: "GET",
		url: url,
		success: function(msg) {
			$('#'+targetItem).html(msg);
			$('#'+targetItem).fadeIn();
            $('#ddlContinent').attr("style","width: 70px;");
		},
		error: function(xhr, ajaxOptions, thrownError) {
			alert(xhr.status);
			alert(thrownError);
			$('#'+targetItem).html(url);
		}
	});
}
