is_msie6=($.browser.msie && /6.0/.test(navigator.userAgent));
function msie6fix_init(){
    if (is_msie6){
        $('select:visible').each(function(i){
            var html;
            var obj=$(this);
            var obj_id=obj.attr('id');
            if (!obj_id){
                obj_id='msiefix_'+i;
                obj.attr('id', obj_id);
            }
            if (obj.attr('multiple')){
                html='<textarea class="msie-fix optional" rel="#'+obj_id+
                    '" style="display:none; width:'+obj.width()+'px; height:'+obj.height()+'px;"></textarea>';
            } else {
                html='<input class="msie-fix optional" type="text" rel="#'+obj_id+
                    '" value="" style="display:none; width:'+obj.width()+'px; height:'+obj.height()+'px;"/>';
            }
            obj.before(html);
        });
    }
}
function msie6fix_onOpen(){
    $('select:visible').hide();
    $('.msie-fix:input:not(:visible)').show();
}
function msie6fix_onClose(){
    $('.msie-fix:input:visible').each(function(){
        var obj=$(this);
        var sel=$(obj.attr('rel'));
        obj.hide();
        sel.show();
    });
}
function createDialog(selector, _width, _closeOnEscape, hasCloseBtn){
    if (hasCloseBtn)
        _buttons = {"Close": function(){ $(this).dialog("close"); }};
    else _buttons = {};
    $(selector).data('switch2', null).data('dlgText', null).data('onClose', null).dialog({
        autoOpen: false,
        closeOnEscape: _closeOnEscape,
        modal: true,
        resizable: false,
        width: _width,
        buttons: _buttons,
        close: function(event, ui){
            var obj=$(this);
            var switch2=obj.data('switch2');
            var onClose=obj.data('onClose');
            obj.data('switch2', null).data('onClose', null);
            if(onClose)
                onClose();
            if (!switch2){
                if (is_msie6)
                    msie6fix_onClose();
            } else switch2.dialog('open');
        },
        open: function(event, ui){
            var obj=$(this);
            var dlgText=obj.data('dlgText');
            obj.data('dlgText', null).children('.dlg_text').html(dlgText ? dlgText : '');
            if (is_msie6)
                msie6fix_onOpen();
        }
    });
}
