//prototype 20081207
var ChkCtl;
//area number
var GetAreaInfo;

document.observe('dom:loaded',function(){
    ChkCtl = new CtlCheckBox('check_row','lightyellow');
    ChkCtl.load();

    GetAreaInfo = new GetAreaInformation('check_area');
    GetAreaInfo.load();
    //GetAreaInfo.getAreaData();
    GetAreaInfo.checkSession();

});

var GetAreaInformation = Class.create({
    initialize: function(wrap_class) {
        this.wrap_class = wrap_class; 
        this.wrap_styles = $H({});
    },
    load: function(){
        var h = $H({}); 
        this.wrapElements = $$('.' + this.wrap_class);
        this.wrapElements.each(function(e) {
            var chkbox = e.down('input[type="checkbox"]');
            if(chkbox) {
                h.set(chkbox.identify(), e.identify());
            }
        }.bind(this));
        this.checkbox2wrap = h;
    },
    getValue: function() {
        var ret_arr = [];
        this.checkbox2wrap.each(function(h) {
            var chk = $(h.key);
            ret_arr.push(chk.value);
        });
        return ret_arr;
    },
    getAreaData: function() {
        var ajax = new Ajax.Request('/sanei/lease/getAreaData/' ,{method: 'load',evanScripts:true, asynchronous:true, onComplete: this.setCheckBox });
    },
    setCheckBox: function(request) {
        var json;
        var html_mapping = new Array ("高崎市・多野郡吉井町","前橋市・勢多群富士見村","伊勢崎市","太田市","桐生市","館林市","渋川市","安中市","藤岡市","みどり市","北群馬郡吉岡町","北群馬郡榛東村","佐波郡玉村町","邑楽郡大泉町","上里町地区");
        json = eval("json="+request.responseText);
        html_mapping.each(function( value, index) {
                Element.update('location' + (index + 1),value + ' (' + json["area" + (index + 1)]  + ')'); 
        });
    },
    checkSession: function() {
        var ajax = new Ajax.Request('/sanei/lease/getSessionData/' ,{method: 'load',evanScripts:true, asynchronous:true, onComplete: this.setCheck });
    },
    setCheck: function(request) {
        var json;
        json = eval("json="+request.responseText);
        $(json.key).checked = true;
    }

});
