    // ***************************************************************************************
    // 
    // ***************************************************************************************
//<div>
//    размер пиктограммы
//    <div id='tn' class='ui-slider-1' style="margin:10px;">
//        <div class='ui-slider-handle' ></div>	
//    </div>
//    <input type="text" name="tn_width" id="tn_width" size="4" maxlength="4" use="1" filter="">x
//    <input type="text" name="tn_height" id="tn_height" size="4" maxlength="4" use="1" filter="">  
//</div>

    function bsGUIMakeImgSizer( sFieldId, aSizes, iLen ){
         if( !aSizes ) {            
             var aSizes = { 
                0: [32,32],
                1: [48,48],
                2: [64,64],
                3: [85,85],
                4: [100,100],
                5: [128,128],
                6: [150,150],
                7: [192,192]  
            };
        }

        if( !iLen ) {
            var iLen = 8;
        }

        var sSliderId   = "#" + sFieldId;
        var sWidthId    = sSliderId + "_width";
        var sHeightId   = sSliderId + "_height";
        
        $(sSliderId).slider({ 
            animate: true,
            steps: iLen,
            min: 0,
            max: (iLen-1),
            slide: function(e,ui) {                
                var val = $(sSliderId).slider('value');                 
                $(sWidthId).attr('value', aSizes[val][0]);
                $(sHeightId).attr('value',aSizes[val][1]);
            }
        });
        $(sWidthId).attr('value', aSizes[0][0]);
        $(sHeightId).attr('value',aSizes[0][1]);

    }

    function bsGUIMakeSlider( sFieldId, aSizes, iLen ){
         if( !aSizes ) {            
             var aSizes = { 
                0: [32],
                1: [48],
                2: [64],
                3: [85],
                4: [100],
                5: [128],
                6: [150],
                7: [192]  
            };
        }

        if( !iLen ) {
            var iLen = 8;
        }

        var sSliderId   = "#" + sFieldId;
        var sWidthId    = sSliderId + "_width";
        
        $(sSliderId).slider({ 
            animate: true,
            steps: iLen,
            min: 0,
            max: (iLen-1),
            slide: function(e,ui) {                
                var val = $(sSliderId).slider('value');                 
                $(sWidthId).attr('value', aSizes[val][0]);
            }
        });
        $(sWidthId).attr('value', aSizes[0][0]);

    }



    function bsGUIExtender( handlerid, containerid ){
        /* handlerid must be checkbox, container -- else */
        $(document).ready(function(){ 
            
            if( $(handlerid).attr("checked") ) {
                $(containerid).show();           
            }else{
                $(containerid).hide();
            }

            $(handlerid).bind("click", function(e){
                if( $(handlerid).attr("checked") ) {
                    $(containerid).show();            
                }else{
                    $(containerid).hide();
                }
            });

            $(handlerid).bind("change", function(e){
                if( $(handlerid).attr("checked") ) {
                    $(containerid).show();            
                }else{
                    $(containerid).hide();
                }
            });

        });
       
    }


    function bsGUIXExtender( handlerid, containerid ){
        /* handlerid must be checkbox, container -- else */
        $(document).ready(function(){ 
            
            if( $(handlerid).attr("checked") ) {
                $(containerid).hide();            
            }else{
                $(containerid).show();
            }

            $(handlerid).bind("click", function(e){
                if( $(handlerid).attr("checked") ) {
                    $(containerid).hide();            
                }else{
                    $(containerid).show();
                }
            });

            $(handlerid).bind("change", function(e){
                if( $(handlerid).attr("checked") ) {
                    $(containerid).hide();            
                }else{
                    $(containerid).show();
                }
            });

        });
       
    }


    function bsGUIAlert(msg){
        alert(msg);
    }

    function bsGUIConfirm(msg){
        var r = confirm(msg);
        return r;
    }

    function bsGUIWillBeClosed(msg){
        alert(msg);
        window.close();
    }

    function bsGUIModal( blockid, openid, closeid ){
        $(document).ready(function(){
            $('#'+blockid).jqm();
            
           
            $('#'+openid).bind('click', function(e){
                $('#'+blockid).jqmShow();
                
            }); 

            
            $('#'+closeid).bind('click', function(e){
                $('#'+blockid).jqmHide();
                
            }); 

        });

    }

    function bsGUIFallMsg( id, msg, timeout){
        $('#'+id).text(msg);
        if( timeout > 0 && timeout < 100000 ) {        
            window.setTimeout(function(){
                $('#'+id).text('');
            }, timeout);
        }
    }

    function bsGUIFallBlock( id, msg, timeout){
        $('#'+id).empty();
        var t = $('<span>'+msg+'</span>');
        t.appendTo('#'+id);
        $('#'+id).fadeTo(300, 0.99);


        if( timeout > 0 && timeout < 100000 ) {        
            window.setTimeout(function(){
                $('#'+id).fadeTo(300, 0.00);
                $('#'+id).empty();
            }, timeout);
        }
    }


    
    function bsGUIMakeImgBox( id, containerfield, prov, node ){
                var container = $('#'+containerfield);        

                var field2 = $("<img>");
                    field2.attr("name", id+'_i');
                    field2.attr("id", id+'_i');
                    field2.attr("width", "100");
                    field2.attr("height", "100");
                    field2.appendTo(container);
                    
                var field3 = $("<input type=\"file\">");
                    field3.attr("name", id+'_f');
                    field3.attr("id", id+'_f');
                    field3.attr("size", "1");
                    /*field3.attr("style", "width:5px;");*/
                    field3.appendTo(container);
                  
                var field4 = $("<input type=\"button\">");
                    field4.attr("name", id+'_b');
                    field4.attr("id", id+'_b');
                    field4.attr("value", "загрузить");
                    field4.appendTo(container);                    
                
                    field4.bind("click", function(e){
                       JsHttpRequest.query(
                            '/?part=file', 
                            {
                                'req':'uploadTempFile',
                                'upl':document.getElementById(id + '_f'),
                                'provid':prov,
                                'nodeid':node
                            },
                            
                            function(result, errors) {
                                if (result) {
                                    if (result['errcode']=='complete') {
                                        var aResource = eval( "(" + result['data2']['resource'] + ")");
                                        $('#'+id+'_i').attr("src", aResource['src']);
                                        $('input[name="'+id+'"]').attr("value", aResource['src']);
                                    }else{
                                    
                                    }
                                }
                            },
                            true 
                        ); 
                    });

    }

     function bsGUIMakeFileBox( id, containerfield, prov, node ){
                var container = $('#'+containerfield);        

                var field2 = $("<input type=\"text\">");
                    field2.attr("name", id+'_i');
                    field2.attr("id", id+'_i');
                    field2.attr("size", "50");
/*                    field2.attr("height", "100");*/
                    field2.appendTo(container);
                    
                var field3 = $("<input type=\"file\">");
                    field3.attr("name", id+'_f');
                    field3.attr("id", id+'_f');
                    field3.attr("size", "1");
                    /*field3.attr("style", "width:5px;");*/
                    field3.appendTo(container);
                  
                var field4 = $("<input type=\"button\">");
                    field4.attr("name", id+'_b');
                    field4.attr("id", id+'_b');
                    field4.attr("value", "загрузить");
                    field4.appendTo(container);                    
                
                    field4.bind("click", function(e){
                       JsHttpRequest.query(
                            '/?part=file', 
                            {
                                'req':'uploadTempFile',
                                'upl':document.getElementById(id + '_f'),
                                'provid':prov,
                                'nodeid':node
                            },
                            
                            function(result, errors) {
                                if (result) {
                                    if (result['errcode']=='complete') {
                                        var aResource = eval( "(" + result['data2']['resource'] + ")");
                                        $('#'+id+'_i').attr("value", aResource['src']);
                                        $('input[name="'+id+'"]').attr("value", aResource['src']);
                                    }else{
                                    
                                    }
                                }
                            },
                            true 
                        ); 
                    });

    }

    
    function bsGUIMakeImgBox2( id, containerfield, prov, node, w, h ){

                if( h < 120 ) {
                    var h2=120;
                }else{
                    h2=h;
                }
                
                $('#'+id).hide();

                var container = $('#'+containerfield);        

                
                var box1 = $('<div id="'+id+'_box1" style="width: 100%; height: '+h2+'px;" > </div>');

                var img = $('<img name="'+id+'_img" id="'+id+'_img" width="'+w+'" height="'+h+'" border="0" class="f_null" />');
                img.appendTo(box1);

                var bln = $('<input type="button" name="'+id+'_bln" id="'+id+'_bln" value="изменить" />');                    
                bln.appendTo(box1); 

                
                var box2 = $('<div id="'+id+'_box2" style="width: 100%;  height: '+h2+'px;" > </div>');

                var uf = $('<input type="file" name="'+id+'_uf" id="'+id+'_uf" class="f_medium" size="40" /><br>');                    
                uf.appendTo(box2);

                var su = $('<span>выберите файл и нажмите </span>');         
                var bu = $('<input type="button" name="'+id+'_bu" id="'+id+'_bu" value="загрузить"/>');                    
                bu.appendTo(su);
                su.appendTo(box2);

                var stat = $('<div id="'+id+'_stat"></div>');
                stat.appendTo(box2);


                box1.appendTo(container);
                box2.appendTo(container);

                box2.hide();


                bln.bind("click", function(e){
                    box1.hide();
                    box2.show();

                });



                bu.bind("click", function(e){
                    
                    document.body.style.cursor="wait";
                    bsGUIFallBlock(id + '_stat', '<img src="/images/system/loaderh.gif" alt="" border="0" align="absmiddle"/> загрузка ', 0);

                    JsHttpRequest.query(
                        '/?part=file', 
                        {
                            'req':'uploadTempFile',
                            'upl':document.getElementById(id + '_uf'),
                            'provid':prov,
                            'nodeid':node
                        },
                        
                        function(result, errors) {
                            if (result) {
                                if (result['errcode']=='complete') {
                                    var aResource = eval( "(" + result['data2']['resource'] + ")");
                                    
                                    var v=aResource['src'];
                                    var f=bsStrCropBefore(v, '.');
                                    var e=bsStrCropAfter(v, '.');
                                    v=f+'&asp&x=mn&w=100&h=100&m=c&r=0&bsp&.'+e;

                                    
                                    $('#'+id+'_img').attr("src", v);
                                    $('input[name="'+id+'"]').attr("value", aResource['src']);

                                    bsGUIFallBlock(id + '_stat', '', 0);
                                    
                                }else{
                                    bsGUIAlert(result['errcode']);                                
                                }
                                box2.hide();
                                    box1.show();
                                    document.body.style.cursor="default";
                            }
                        },
                        true 
                    ); 
                });
    }

    function bsGUIChangeImgBox2( id, containerfield, prov, node, w, h ){
        $('#'+id).hide();
        var v=$('input[name="'+id+'"]').attr("value");
        
        if( v!=null ) {       
        
            var f=bsStrCropBefore(v, '.');
            var e=bsStrCropAfter(v, '.');
            v=f+'&asp&x=mn&w=100&h=100&m=c&r=0&bsp&.'+e;
            $('#'+id+'_img').attr("src", v);
        
        }else{
            $('#'+id+'_img').attr("src", '');
      
        }
    }


        function bsGUIMakeFileBox2( id, containerfield, prov, node, w, h ){

                if( h < 120 ) {
                    var h2=120;
                }else{
                    h2=h;
                }
                
                $('#'+id).hide();

                var container = $('#'+containerfield);        

                
                var box1 = $('<div id="'+id+'_box1" style="width: 100%; height: '+h2+'px;" > </div>');

                var img = $('<input type="text" name="'+id+'_img" id="'+id+'_img" class="f_medium" disabled/>');
                img.appendTo(box1);

                var bln = $('<input type="button" name="'+id+'_bln" id="'+id+'_bln" value="изменить" />');                    
                bln.appendTo(box1); 

                
                var box2 = $('<div id="'+id+'_box2" style="width: 100%;  height: '+h2+'px;" > </div>');

                var uf = $('<input type="file" name="'+id+'_uf" id="'+id+'_uf" class="f_medium" size="40" /><br>');                    
                uf.appendTo(box2);

                var su = $('<span>выберите файл и нажмите </span>');         
                var bu = $('<input type="button" name="'+id+'_bu" id="'+id+'_bu" value="загрузить"/>');                    
                bu.appendTo(su);
                su.appendTo(box2);

                var stat = $('<div id="'+id+'_stat"></div>');
                stat.appendTo(box2);


                box1.appendTo(container);
                box2.appendTo(container);

                box2.hide();


                bln.bind("click", function(e){
                    box1.hide();
                    box2.show();

                });



                bu.bind("click", function(e){
                    
                    document.body.style.cursor="wait";
                    bsGUIFallBlock(id + '_stat', '<img src="/images/system/loaderh.gif" alt="" border="0" align="absmiddle"/> загрузка ', 0);

                    JsHttpRequest.query(
                        '/?part=file', 
                        {
                            'req':'uploadTempFile',
                            'upl':document.getElementById(id + '_uf'),
                            'provid':prov,
                            'nodeid':node
                        },
                        
                        function(result, errors) {
                            if (result) {
                                if (result['errcode']=='complete') {
                                    var aResource = eval( "(" + result['data2']['resource'] + ")");
                                    
                                    
                                    $('#'+id+'_img').attr("value", aResource['src']);
                                    $('input[name="'+id+'"]').attr("value", aResource['src']);

                                    bsGUIFallBlock(id + '_stat', '', 0);
     
                                }else{
                                    bsGUIAlert(result['errcode']);
                                }
                                box2.hide();
                                    box1.show();
                                    document.body.style.cursor="default";
                            }
                        },
                        true 
                    ); 
                });
    }

    function bsGUIChangeFileBox2( id, containerfield, prov, node, w, h ){
        $('#'+id).hide();
        var v=$('input[name="'+id+'"]').attr("value");
        
        if( v!=null ) {               
            
            $('#'+id+'_img').attr("value", v);
        
        }else{
            $('#'+id+'_img').attr("value", '');
      
        }
    }





 function bsGUIMakeImgBox3( id, containerfield, prov, node, w, h, imgid, fl ){

                if( h < 120 ) {
                    var h2=120;
                }else{
                    h2=h;
                }

                if( !fl && fl!=0 ) {
                    fl=1;
                }

                
                /*$('#'+id).hide();*/

                var container = $('#'+containerfield);        

                
                var box1 = $('<div id="'+id+'_box1" style="width: 100%; height: '+h2+'px;" > </div>');

                var img = $('<img name="'+imgid+'" id="'+imgid+'" width="'+w+'" height="'+h+'" border="0" class="f_null" />');
                /*var img = $('<img name="'+id+'_img" id="'+id+'_img" width="'+w+'" height="'+h+'" border="0" class="f_null" />');*/
                /*img.appendTo(box1);*/

                var bln = $('<input type="button" name="'+id+'_bln" id="'+id+'_bln" value="выбрать" />');                    
                bln.appendTo(box1); 

                
                var box2 = $('<div id="'+id+'_box2" style="width: 100%;  height: '+h2+'px;" > </div>');

                var uf = $('<input type="file" name="'+id+'_uf" id="'+id+'_uf" class="f_long" /><br>');                    
                uf.appendTo(box2);

                var su = $('<span>выберите файл и нажмите </span>');         
                var bu = $('<input type="button" name="'+id+'_bu" id="'+id+'_bu" value="загрузить"/>');                    
                bu.appendTo(su);
                su.appendTo(box2);

                var stat = $('<div id="'+id+'_stat"></div>');
                stat.appendTo(box2);


                box1.appendTo(container);
                box2.appendTo(container);

                if( fl==1 ) {
                    box2.hide();
                }else{
                    box1.hide();
                }


                
                bln.bind("click", function(e){
                    box1.hide();
                    box2.show();

                });



                bu.bind("click", function(e){
                    
                    document.body.style.cursor="wait";
                    bsGUIFallBlock(id + '_stat', '<img src="/images/system/loaderh.gif" alt="" border="0" align="absmiddle"/> загрузка ', 0);

                    JsHttpRequest.query(
                        '/?part=file', 
                        {
                            'req':'uploadTempFile',
                            'upl':document.getElementById(id + '_uf'),
                            'provid':prov,
                            'nodeid':node
                        },
                        
                        function(result, errors) {
                            if (result) {
                                if (result['errcode']=='complete') {
                                    var aResource = eval( "(" + result['data2']['resource'] + ")");
                                    
                                    var v=aResource['src'];
                                    var f=bsStrCropBefore(v, '.');
                                    var e=bsStrCropAfter(v, '.');
                                    /*v=f+'&asp&x=mn&w=250&h=250&m=c&r=0&bsp&.'+e;*/
                                    v=f+'&asp&x=mn&w=250&h=250&m=c&r=0&bsp&.'+e;

                                    
                                    $('#'+imgid).attr("src", v);
                                    $('input[name="'+id+'"]').attr("value", aResource['src']);

                                    bsGUIFallBlock(id + '_stat', '', 0);
                                    
                                }else{
                                    bsGUIAlert(result['errcode']);                                
                                }
                                box2.hide();
                                    box1.show();
                                    document.body.style.cursor="default";
                            }
                        },
                        true 
                    ); 
                });
    }
    
   


    function bsGUIChangeImgBox3( id, containerfield, prov, node, w, h, imgid ){
        /*$('#'+id).hide();*/
        var v=$('input[name="'+id+'"]').attr("value");
        
        if( v!=null ) {       
        
            var f=bsStrCropBefore(v, '.');
            var e=bsStrCropAfter(v, '.');
            v=f+'&asp&x=mn&w='+w+'&h='+h+'&m=c&r=0&bsp&.'+e;
            $('#'+imgid).attr("src", v);
        
        }else{
            /*v='/images/system/noimg'+250+'x'+250+'.gif';*/
            $('#'+imgid).attr("src", '');
      
        }
    }

     function bsGUISetImgBox3( w, h, imgid, v ){
        
        if( v!=null ) {       
            /*
            var f=bsStrCropBefore(v, '.');
            var e=bsStrCropAfter(v, '.');
            v=f+'&asp&x=mn&w='+w+'&h='+h+'&m=c&r=0&bsp&.'+e;
            */
            $('#'+imgid).attr("src", v);
        
        }else{
            $('#'+imgid).attr("src", '');
      
        }
    }



    /*function bsGUIModal( blockid, openid, closeid ){
        $(document).ready(function(){
            $('#'+blockid).dialog({ 
                modal: true, 
                overlay: { 
                    opacity: 0.5, 
                    background: "black" 
                    },
                autoOpen: false
                } );
            
           
            $('#'+openid).bind('click', function(e){
                $('#'+blockid).dialog('open');
                
            }); 

            
            $('#'+closeid).bind('click', function(e){
                $('#'+blockid).dialog('close');
                
            }); 

      });

    }*/


    /* cid,title,clevel
     * order by cleft */
    function bsGUIMakeTreeSelector(aNodes, name){
        var selector=$('<select name="'+name+'" id="'+name+'" use="f" class="f_long"></select>');
        for( key in aNodes) {
            
            var title="";
            
            if( aNodes[key]['clevel']>0 ) {
                title="&nbsp;&nbsp;&#124;";
                var i=0;
                for( i=0; i<aNodes[key]['clevel']; i++) {
                    title=title+"&mdash;";
                }
                title=title+"&nbsp;";

            }

            if( aNodes[key]['type']=='section' ) {
                title=title+'['+aNodes[key]['xtitle']+']';
            }else{
                title=title+aNodes[key]['xtitle'];
            }
            var option=$('<option value="'+aNodes[key]['cid']+'">'+title+'</option>');
            option.appendTo(selector);

        }
        return selector;
    }

function bsGUIMakeTreeBlock(aNodes, name){
        var selector=$('<div id="'+name+'" ></div>');
        for( key in aNodes) {
            
            var title="";
            
            if( aNodes[key]['clevel']>0 ) {
                title="&nbsp;&nbsp;&#124;";
                var i=0;
                for( i=0; i<aNodes[key]['clevel']; i++) {
                    title=title+"&mdash;";
                }
                title=title+"&nbsp;";

            }

            title=title+aNodes[key]['title'];
            var option=$('<div>'+title+'</div>');
            option.appendTo(selector);

            /*alert(aNodes[key]['title']);*/
        }
        return selector;
    }


    function isFunction(o){
        if( typeof(o) == 'function' ) {
            return true;  
        }
        return false;
    }

    function isSet(varname)  {
      if(typeof( window[ varname ] ) != "undefined") return true;
      else return false;
    }

    
    function bsGUIGetLoaderElement(){
        return '<span><img src="/basis/images/all/loaderh.gif" border="0" align="absmiddle"> загрузка</span>';
    }

    function bsGUIGetAlertElement(msg){
        if( typeof(msg)=='undefined' ) {
            var msg="произошла ошибка";
        }
        return '<span><img src="/basis/images/all/exclamation.png" border="0" align="absmiddle"> '+msg+'</span>';
    }


    /* id--jquery descriptor */
    function bsGUIShowLoaderIn(id){
        var c=$(id);
        c.empty();
        var cn=$(bsGUIGetLoaderElement());
        cn.appendTo(c);
    }

    function bsGUIHideLoaderIn(id){
        var c=$(id);
        c.empty();
    
    }

    function bsGUISetInvalidFormHelper(formid,submitid,statid){
    
        $("form[name='"+formid+"'] *[use='f']").bind("change click", function(e){
            if( $('#'+submitid).attr('disabled') ) {
                    bsGUIFallBlock(statid,bsGUIGetAlertElement('не все обязательные поля заполнены верно'),5000);
            }else{
                bsGUIFallBlock(statid,' ',5000);
            }
        });
    }

    /*
    function bsGUISetInvalidSubmitHelper(formid,submitid,statid){
    
        $("form[name='"+formid+"'] input[id='"+submitid+"']").bind("click", function(e){
            if( $('#'+submitid).attr('disabled') ) {
                    bsGUIFallBlock(statid,bsGUIGetAlertElement('не все обязательные поля заполнены верно'),5000);
            }else{
                bsGUIFallBlock(statid,' ',5000);
            }
        });
    }
    */

    this.initFX=initFX;
    function initFX(){
        
        $('input.f_checkinput[type="checkbox"]').bind('click',function(e){
            var v=$(this).attr('value');
            var i=$(this).attr('id');
            var ib=bsStrCropAfter(i,'fx_');
            if( $('#'+i).attr('checked') ){
                $('#'+ib).attr('value',' ');
            }else{
                $('#'+ib).attr('value','');
            }
           
        });
        
        $('input.f_checkinput[type="text"]').bind('keyup',function(e){
            var v=$(this).attr('value');
            var i=$(this).attr('id');
            i='fx_'+i;
            if( v=='' ) {
                $('#'+i).attr('checked',false);
            }else{
                $('#'+i).attr('checked',true);
            }
        });
       
        return true;
    }



    function bsGUISetCheckInput(check,inputs){
         
        if( isset(check)!='undefined' && isset(inputs)!='undefined' ) {
        
            $(check).bind('click',function(e){
                if( $(check).attr('checked') ){
                    $(inputs).attr('value',' ');
                }else{
                    $(inputs).attr('value','');
                }               
            });
            
            $(inputs).bind('keyup',function(e){
                var v=$(this).attr('value');
                if( v=='' ) {
                    $(check).attr('checked',false);
                }else{
                    $(check).attr('checked',true);
                }
            });

        }

    }

    function bsGUISet2AlignedInputs(ctl,input1,input2){

             var v1=$(input1).attr('value');
                var v2=$(input2).attr('value');
                if( (typeof(v1)=='undefined' || typeof(v2)=='undefined') && !(typeof(v1)=='undefined' && typeof(v2)=='undefined') ) {
                    $(ctl).attr('value','');
                }else{
                    $(ctl).attr('value','1');
                } 

        if( isset(ctl)!='undefined' && isset(input1)!='undefined' && isset(input2)!='undefined' ) {
            $(input1+","+input2).bind('keyup',function(e){
                var v1=$(input1).attr('value');
                var v2=$(input2).attr('value');
                if( (typeof(v1)=='undefined' || typeof(v2)=='undefined') && !(typeof(v1)=='undefined' && typeof(v2)=='undefined') ) {
                    $(ctl).attr('value','');
                }else{
                    $(ctl).attr('value','1');
                }   
            
            });
        }
    }
    
    function bsGUISetCheckCheck(check,inputs){
        
        if( isset(check)!='undefined' && isset(inputs)!='undefined' ) {
        
        
            $(check).bind('click',function(e){
                if( !$(check).attr('checked') ){
                    $(inputs).attr('checked',false);
                }               
            });
            
            $(inputs).bind('click',function(e){
                var ret=1;
                $(inputs).each(function(key,val){                        
                    if($(val).attr('checked')){
                        ret=ret*0;
                    }
                });
                if(ret==0){
                    $(check).attr('checked',true);
                }else{
                    /*$(check).attr('checked',false);*/
                }
                    
            });

        }

    }

