$(document).ready(function(){
    group = $("#sgroup");
    section = $("#ssection");
    son = $("#sson");    
    group.change(function(){
        BindSection(s[group.val()]);        
    })    
    section.change(function(){
        BindSectionSon(s[group.val()][section[0].selectedIndex][2]);
    })
})

function BindSection(result){
    disabled();    
    if (result == '' || result == null) {
        return;
    }
	section.empty();    
    for (i = 0; i < result.length; i++) {    
        section[0].options[i] = new Option(result[i][1], result[i][0]);
    }    
    BindSectionSon(result[section[0].selectedIndex][2]);
}

function BindSectionSon(result){
    if (result == '' || typeof result != "object") {
		son.empty();
		son.hide();
        enabled();
        return;
    }
    else {
        son.show();
    }   
    //读取上次选中的二级分类的数据
    var tempLength = son[0].options.length;
    var selectedValue = son[0].selectedIndex;
    son.empty();
    for (i = 0; i < result.length; i++) {
        son[0].options[i] = new Option(result[i][1], result[i][0]);
    }    
    //设定上次选中的二级分类
    if (tempLength == result.length && selectedValue > 0) {
        son[0].selectedIndex = selectedValue;
    }
    enabled();
}

function disabled(){
    section[0].disabled = true;
    son[0].disabled = true;
}

function enabled(){
    section[0].disabled = false;
    son[0].disabled = false;
}
