﻿var userplace ={
stateID:1001,
cityID:10001,
domID:'',
isAll:0,
init:function(domID, cityID, isAll){
this.domID = '#'+domID;
if(!isAll)
    this.isAll = 0;
else
    this.isAll = isAll;

var h='<select id="selState" onchange="$(\'#selCity\').load(\'/FAjax/Place/placelist.dhtml?id=\'+userplace.getStateValue() + \'&isAll=\' + userplace.isAll);"><option value="0">请选择...</option></select>';
 h+='<select id="selCity"><option value="0">请选择...</option></select>';
 $(this.domID).html(h);
 
if(!cityID) cityID = -1;
if(cityID>0)
{
    this.cityID = cityID;
    $.get('/FAjax/Place/index.dhtml?id=' + this.cityID,function(result){
        eval("var cityData =" + result);
        userplace.stateID = cityData.ParentID;
        userplace.loadState(); 
    });
 }
 else
    userplace.loadState();
},
loadState:function(){
$.get('/FAjax/Place/placelist.dhtml?id=1&isAll='+this.isAll,function(result){
    $('#selState').html(result);
    var stateID = userplace.stateID;
    if(1==userplace.isAll)
        stateID = -1;
     setTimeout("$('#selState').val("+stateID+");userplace.loadCity();",10);
});
},
loadCity:function()
{
 $.get('/FAjax/Place/placelist.dhtml?id=' + userplace.getStateValue() + '&isAll=' + this.isAll, function(result){
        $('#selCity').html(result);
        if(1==userplace.isAll)
            setTimeout("$('#selCity').val(userplace.cityID);",10);
    });
},
getStateValue:function(){
    return $('#selState').val();
},
getCityValue:function(){
    return $('#selCity').val();
},
getState:function(){
    return $('select[id=selState]').find('option[selected]').text();
},
getCity:function(){
    return $('select[id=selCity]').find('option[selected]').text();
}
};
