﻿///<reference path="jquery-1.2.6-vsdoc.js">




var datas;
var select1;
var select2;
var select3;
var select4;
var subxmldata;

$().ready(function() {
    select1 = $('#bb').get(0);
    select2 = $('#nj').get(0);
    select3 = $('#dy').get(0);
    select4 = $('#kc').get(0);

    $(select1).change(function() {
        select2.options.length = 0;
        select2.options.add(new Option("年级", -1));
        select3.options.length = 0;
        select3.options.add(new Option("单元", -1));
        select4.options.length = 0;
        select4.options.add(new Option("课程名", -1));
        dyselect(select1, select2, "version", "grade");
    });
    $(select2).change(function() {
        select3.options.length = 0;
        select3.options.add(new Option("单元", -1));
        select4.options.length = 0;
        select4.options.add(new Option("课程名", -1));
        dyselect(select2, select3, "grade", "unit");
    });
    $(select3).change(function() {
        select4.options.length = 0;
        select4.options.add(new Option("课程名", -1));
        subselect(select3, select4);
    })
    $(select4).change(function() {

    // alert(select4.value);
    if (select4.value != -1) {
        window.location = "search_sucai.aspx?type=1&kcid=" + select4.value;
        }
        
    })
    select_init();
})
function getData() {
    $.ajaxSetup({ async: false });
    $.get("config/kcPorConfig.xml", function(xml) { datas = xml; }, "XML");
}
function select_init() {
    getData();
    $(datas).find('version').each(function() {
        var p = $(this).attr("name");
        var pvalue = $(this).attr("uid");
        option = new Option(p, pvalue);
        select1.options.add(option);
    }
                )
}


function dyselect(obj1, obj2, parent, chirld) {
    var svalue = obj1.value;
    if (svalue != -1) {
        str_xpath = parent + "[@uid=" + svalue + "]";
        var nodes = $(datas).find(str_xpath);
        $(nodes).find(chirld).each(function() {
            var p = $(this).attr("name");
            var pvalue = $(this).attr("uid");
            option = new Option(p, pvalue);
            obj2.options.add(option);

        })
    }
}

function subselect(obj1, obj2) {
    var svalue = obj1.value;

    if (svalue != -1) {

   
        
            $.get("admin/kcOutXml.aspx?uid="+svalue, function(xml) { subxmldata = xml; }, "XML");

        
    }

    if (typeof (subxmldata) != "undefined") {
   $(subxmldata).find('sub').each(function() {
        var p = $(this).find('kcName').get(0).text;
        var pvalue = $(this).find('kcid').get(0).text;
        option = new Option(p, pvalue);
        obj2.options.add(option);
    })
}

   
}
