Control.CycExamQelWin = Class.create(Control.CycQelWin,{

    getQelItems: function(){
        if (this.isOpen) {
            this.myField.focus();
            return;
        }
        if(this.myField.value == ""){

            var box = this.options.get('modalbox');

             box.show('<ul class="list01"><li>検索対象とする文字(よみ)を入力してから検索ボタンをクリックしてください</li></ul>',
                      {title:'「よみ」の未入力', nextCtrl:this.myFieldName});

            return;
        }
        this.getResponseListener = this.getResponse.bindAsEventListener(this);
        var data = "name_furi="+ this.myField.value;
        var options = {
            method:'post',
            onSuccess:this.getResponseListener,
            parameters:data
        };
        new Ajax.Request(this.options.get('ajaxUrl'), options);

    },
    getResponse : function (httpObject){
        var res = httpObject.responseJSON;
        var box = this.options.get('modalbox');
        switch(res.mode){
                case 'notFound':
                    var d_value = this.myField.value.escapeHTML();
                    box.show('<ul class="list01"><li>検索しましたが「ふりがな」に「' + d_value + '」の含まれる個人情報はありません。</li></ul>',
                          {title:'個人情報なし', nextCtrl:this.myFieldName});
                    break;
                case 'tooMany':
                    box.show('<ul class="list01"><li>該当件数が多すぎるため検索を中止しました。</li></ul>',
                          {title:'検索文字数を増やしてください', nextCtrl:this.myFieldName});
                    break;
                case  'succsess':
                    this.responses = res.items.toArray();
                    if(this.responses.length == 1){
                            var my = this.options.get('myWin');
                            my.$('exam_code').value = this.responses[0]['exam_code'];
                            my.codeCallClick();
                    }
                    else{
                        this.open();
                    }
                    break;
        }

    },
    makeHTML : function(){
        this.liItems.clear();

        var html = '<table class="CycPoptable" id="'+this.myFieldName + '_tblItem" >';

        var f = true;
        var idVal;
        var other = this;
        var s;

        this.responses.each(function(ele){

            idVal = other.myFieldName + '-' + ele['exam_code'];
            if(f){
                html += '<tr class="activerow" ';
                f = false;
            }
            else{
                html += '<tr ';
            }
            html += 'id="' + idVal + '" title="' + ele['exam_code'] + '" >';
            html += '<td>' + ele['name'] + '</td>'
                  + '<td>' + ele['tel']  + '</td>'
                  + '<td>' + ele['addr_1'] + ele['addr_2'] + '</td></tr>';


            other.liItems.push(idVal);
        });
        html += '</table>';
        return html;

/*
        var maxItemLength = [];
        maxItemLength['name'] = 0;
        maxItemLength['tel'] = 0;

        maxItemLength['name'] = this.responses.max(function(ele){
            return jstrlen(ele['name']);
        });
        maxItemLength['tel'] = this.responses.max(function(ele){
            return jstrlen(ele['tel']);
        });
        var html = '<ul class="cycMainUl" id="'+this.myFieldName + '_ulItem" >';
        var f = true;
        var idVal;
        var other = this;
        var s;
        this.responses.each(function(ele){

            idVal = other.myFieldName + '-' + ele['exam_code'];
            if(f){
                html += '<li class="activeli" ';
                f = false;
            }
            else{
                html += '<li ';
            }
            html += 'id="' + idVal + '" value="' + ele['exam_code'] + '" >';
            s = strAddSpc(ele['name'], maxItemLength['name'] + 1);
            html += s;
            s = strAddSpc(ele['tel'], maxItemLength['tel'] + 1)
            html += s;
            html += ele['addr_1'] + ele['addr_2'] + '</li>';
            other.liItems.push(idVal);
        });
        html += '</ul>';
        return html;
*/
    },
    popupPosSet :function () {
        var pos = Position.cumulativeOffset(this.myField);
        pos[1] = pos[1] + this.myField.getHeight();
        pos[0] = pos[0] + (this.myField.getWidth() / 2) - (this.control.popUp.getWidth() / 2);
        if(pos[0] < 10)
            pos[0] = 10;
        this.control.popUp.style.left = (pos[0]) + "px";
        this.control.popUp.style.top = (pos[1]) + "px";
    },
    setItems : function(ele){
        this.close();
        var my = this.options.get('myWin');


        my.$('exam_code').value = ele.title;
        my.codeCallClick();
    }

});




