function art_events(){
    if ($('add_art')!=null){
        document.getElements('a[id^=add_art]').each(function(item){
            item.addEvent('click',function(e){
                var pars = $('add_art').get('href').split('?');
                e.stop();
                add_art(pars[pars.length-1]);
            });
        });
    }
    if ($('edit_art')!=null){
        $('edit_art').addEvent('click',function(e){
            var pars = $('edit_art').get('href').split('?');
            e.stop();
            add_art(pars[pars.length-1]);
        });
    }
    if ($('del_art')!=null){
        $('del_art').addEvent('click',function(e){
            var pars = $('del_art').get('href').split('?');
            e.stop();
            del_art(pars[pars.length-1]);
        });
    }
    if ($('act_art')!=null){
        $('act_art').addEvent('click',function(e){
            var pars = $('act_art').get('href').split('?');
            e.stop();
            del_art(pars[pars.length-1]);
        });
    }
    if ($('add_photo')!=null){
        $('add_photo').addEvent('click',function(e){
            var pars = $('add_photo').get('href').split('?');
            e.stop();
            add_art_photo(pars[pars.length-1]);
        });
    }
    if ($('del_photo')!=null){
        document.getElements('a[id^=del_photo]').each(function(item){
            item.addEvent('click',function(e){
                var pars = item.get('href').split('?');
                e.stop();
                del_art_photo(pars[pars.length-1]);
            });
        });
    }
}

window.addEvent('domready', function(){
    art_events();
    create_artf();
});

function show_loader(){
    $('artform_edit').style.display = 'none';
    $('artform_loader').style.display = 'block';
}

function unshow_loader(){
    $('artform_edit').style.display = 'block';
    $('artform_loader').style.display = 'none';
}

function del_art_photo(article_id, type, photo_id) {
    
    var pars = $H({
        article_id:article_id, 
        type:type,
        photo_id:photo_id            
    }).toQueryString();
    
    
    var myRequest = new Request.HTML({
        url: 'modules/articles/ajax/del_photo.php',
        method: 'get',
        /*update: 'div_add_art',*/
        onRequest: show_loader,
        evalScripts: true,
        onComplete: function(){
            window.location.href = window.location.href;
        //art_events();
        //$('artform_loader').style.display = 'none';
        }
    }).send(pars);  


}

function add_art_photo(pars) {
    var myValues = $('artform_ancor').getCoordinates();
    $('artform_edit').setStyle('top',myValues.top-7);
    $('artform_loader').setStyle('top',myValues.top-7);
    $('loader_block').setStyles({
        width:'448px',
        height:'129px',
        paddingTop:'96px'
    });
    var myRequest = new Request.HTML({
        url: 'admin/articles/ajax/add_photo_art.php',
        method: 'get',
        update: 'artform_edit',
        evalScripts: true,
        onRequest: show_loader,
        onComplete: function(){
            block_other_cont();
            if($('artform_close')!=null){
                $('artform_close').addEvent('click', function(){
                    $('artform_edit').style.display = 'none';
                    $('artform_edit').empty();
                    $('trans_shield').destroy();
                });
                $('artform_close').addEvent('mouseover', function(){
                    $('artform_close').style.backgroundColor='#000000'
                });
                $('artform_close').addEvent('mouseout', function(){
                    $('artform_close').style.backgroundColor='#b1b8b0'
                });
            }
            unshow_loader();
            image_upload_init();
        }
    }).send(pars);
}

function del_art(pars) {
    var myRequest = new Request.HTML({
        url: 'admin/articles/ajax/add_art.php',
        method: 'get',
        update: 'div_add_art',
        evalScripts: true,
        onRequest: show_loader,
        onComplete: function(){
            art_events();
            $('artform_loader').style.display = 'none';
        }
    }).send(pars);
}

function add_art(pars) {
    var myValues = $('artform_ancor').getCoordinates();
    $('artform_edit').setStyle('top',myValues.top-7);
    $('artform_loader').setStyle('top',myValues.top-7);
    $('loader_block').setStyles({
        width:'625px',
        height:'401px',
        paddingTop:'370px'
    });
    var myRequest = new Request.HTML({
        url: 'admin/articles/ajax/add_art.php',
        method: 'get',
        update: 'artform_edit',
        evalScripts: true,
        onRequest: show_loader,
        onComplete: function(){
            if ($('date_articles')!=null)
            {
                new DatePicker('input[id^=date_articles]',{
                    pickerClass: 'datepicker_vista', 
                    positionOffset: {
                        x: 0, 
                        y: 5
                    }, 
                    days: ['Вс', 'Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб'],
                    months: ['Январь', 'Февраль', 'Март', 'Апрель', 'Май', 'Июнь', 'Июль', 'Август', 'Сентябрь', 'Октябрь', 'Ноябрь', 'Декабрь'],
                    allowEmpty:true,
                    //startView: 'decades',
                    inputOutputFormat: 'Y-m-d'
                });
            }
            block_other_cont();
            if (tinyMCE) {
                setup();
            }
            if($('art_butt')!=null){
                $('art_butt').addEvent('click', function(e){
                    $('area_news').set('value', tinyMCE.get('area_news').getContent());
                    tinyMCE.get('area_news').remove();
                    var myHTMLRequest = new Request.HTML({
                        url:'admin/articles/ajax/update_arts.php',
                        update: 'div_add_art',
                        onRequest: function(){
                            show_loader();
                        },
                        onComplete: function(){
                            art_events();
                            $('artform_loader').style.display = 'none';
                            $('artform_edit').empty();
                            $('trans_shield').destroy();
                        }
                    });
                    myHTMLRequest.post($('art_form'));
                    e.stop();
                });
            }
            if($('artform_close')!=null){
                $('artform_close').addEvent('click', function(){
                    tinyMCE.get('area_news').remove();
                    $('artform_edit').style.display = 'none';
                    $('artform_edit').empty();
                    $('trans_shield').destroy();
                });
                $('artform_close').addEvent('mouseover', function(){
                    $('artform_close').style.backgroundColor='#000000';
                });
                $('artform_close').addEvent('mouseout', function(){
                    $('artform_close').style.backgroundColor='#b1b8b0';
                });
            }
            unshow_loader();
        }
    }).send(pars);
}

function setup() {
    tinyMCE.init({
        // General options
        mode : "textareas",
        elements : "ajaxfilemanager",
        theme : "advanced",
        plugins :"safari,pagebreak,style,layer,table,save,advhr,advimage, advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
        // Theme options
        extended_valid_elements : "iframe[name|src|framespacing|border|frameborder|scrolling|title|height|width],a[name|href|target|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]",
        theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
        theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,undo,redo,|,link,unlink,anchor,image,cleanup,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
        theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,fullscreen",
        theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak",
        theme_advanced_toolbar_location : "top",
        theme_advanced_toolbar_align : "left",
        theme_advanced_statusbar_location : "bottom",
        theme_advanced_resizing : true,


        file_browser_callback : "ajaxfilemanager",
        

        language : "ru",
        content_css : "style.css",
        editor_selector : "mceEditor",
        textarea_trigger : "area_news",

        // Drop lists for link/image/media/template dialogs
        template_external_list_url : "lists/template_list.js",
        external_link_list_url : "lists/link_list.js",
        external_image_list_url : "lists/image_list.js",
        media_external_list_url : "lists/media_list.js",

        // Replace values for the template plugin
        template_replace_values : {
            username : "Some User",
            staffid : "991234"
        }
    });
}   
function ajaxfilemanager(field_name, url, type, win) {
    var ajaxfilemanagerurl = "admin/tiny_mce/plugins/ajaxfilemanager/ajaxfilemanager.php";
    switch (type) {
        case "image":
            break;
        case "media":
            break;
        case "flash":
            break;
        case "file":
            break;
        default:
            return false;
    }
    tinyMCE.activeEditor.windowManager.open({
        url: "admin/tiny_mce/plugins/ajaxfilemanager/ajaxfilemanager.php",
        width: 782,
        height: 500,
        inline : "yes",
        close_previous : "no"
    },{
        window : win,
        input : field_name
    });
            
/*            return false;         
            var fileBrowserWindow = new Array();
            fileBrowserWindow["file"] = ajaxfilemanagerurl;
            fileBrowserWindow["title"] = "Ajax File Manager";
            fileBrowserWindow["width"] = "782";
            fileBrowserWindow["height"] = "440";
            fileBrowserWindow["close_previous"] = "no";
            tinyMCE.openWindow(fileBrowserWindow, {
              window : win,
              input : field_name,
              resizable : "yes",
              inline : "yes",
              editor_id : tinyMCE.getWindowArg("editor_id")
            });
            
            return false;*/
}
// Отключаем все экземпляры TinyMCE, для сохранения содержимого.
/*if (tinyMCE) {
  for (n in tinyMCE.instances) {
    inst = tinyMCE.instances[n];
    if (tinyMCE.isInstance(inst)) {
      tinyMCE.execCommand('mceRemoveControl', false, inst.editorId);
    }
  }
}
/*
var form = $('#my-form-id');

// Обрабатываем форму
$.ajax({
  type: "POST",
  url: form.attr('action'),
  data: form.serialize(),
  success: function (html) {
    form.html(html);
  },
  error: function (status) {
    alert('Error: '+ status);
  },
  complete: function (x, status) {
    // Снова подключаем редактор ко всем существующим контролам.
    if (tinyMCE) {
      $('textarea.mceEditor').each(function () {
        tinyMCE.execCommand('mceAddControl', false, this.id);
      });
    }
  }
});*/
function startUpload(){
    show_loader();
    return true;
}

function stopUpload(success,article_id){
    var pars='id='+article_id;
    myRequest = new Request.HTML({
        url: 'admin/articles/ajax/show_selected_art.php',
        method: 'get',
        update: 'div_add_art',
        evalScripts: true,
        onComplete: function(){
            $('artform_loader').style.display = 'none';
            art_events();
        }
    }).send(pars);
    $('artform_edit').empty();
    var result = ''; 
    $('trans_shield').destroy();
    return true;   
}

function my_getSize(elem, withoutBounds) {
    var s = [0, 0];
    if (elem == document) {
        s =  [Math.max(
            document.documentElement["clientWidth"],
            document.body["scrollWidth"], document.documentElement["scrollWidth"],
            document.body["offsetWidth"], document.documentElement["offsetWidth"]
            ), Math.max(
            document.documentElement["clientHeight"],
            document.body["scrollHeight"], document.documentElement["scrollHeight"],
            document.body["offsetHeight"], document.documentElement["offsetHeight"]
            )];
    } else if (elem){
        function getWH() {
            s = [elem.offsetWidth, elem.offsetHeight];
            if (!withoutBounds) return;
            var padding = 0, border = 0;
            each(s, function(i, v) {
                var which = i ? ['Top', 'Bottom'] : ['Left', 'Right'];
                each(which, function(){
                    s[i] -= parseFloat(getStyle(elem, "padding" + this)) || 0;
                    s[i] -= parseFloat(getStyle(elem, "border" + this + "Width")) || 0;
                });
            });
            s = [Math.round(s[0]), Math.round(s[1])];
        }
        if (!isVisible(elem)) {
            var props = {
                position: "absolute", 
                visibility: "hidden", 
                display:"block"
            };
            var old = {};
            each(props, function(i, val){
                old[i] = elem.style[i];
                elem.style[i] = val;
            });
            getWH();
            each(props, function(i, val){
                elem.style[i] = old[i];
            });
        } else getWH();

    }
    return s;
}

function block_other_cont(){
    var trashield = new Element('div', {
        id:'trans_shield'
    });
    trashield.setStyles({
        display:'block',
        position:'absolute',
        zIndex:'50',
        width:'100%',
        visibility:'visible',
        top:'0',
        left:'0',
        height:my_getSize(document)[1] + 'px'
    });
    trashield.inject(document.body);
}
function create_artf(artw,arth){
    var artf_edit = new Element('div',{
        id:'artform_edit'
    });
    artf_edit.setStyles({
        display:'none',
        position:'absolute',
        zIndex:'5000',
        width:'100%',
        visibility:'visible'
    });
    artf_edit.inject(document.body);
    ;
    
    var artf_loader = new Element('div',{
        id:'artform_loader'
    });
    artf_loader.setStyles({
        display:'none',
        position:'absolute',
        zIndex:'6000',
        width:'100%',
        visibility:'visible'
    });
    artf_loader.inject(document.body);
    var loader_block = new Element('span',{
        id:'loader_block'
    });
    loader_block.setStyles({
        display:'block',
        width:'625px',
        height:'771px',
        visibility:'visible',
        textAlign:'center',
        background:'#FFFFFF',
        border:'#CCCCCC 1px solid',
        margin:'0 auto',
        paddingTop:'360px'
    });
    loader_block.inject(artf_loader);
    var loaderimg = new Element('img', {
        src:"images/loader.gif"
    });
    loaderimg.inject(loader_block);
}
function image_upload_init(){
    var link=$('art_photo_browse');
    //var linkIdle = link.get('html');
    var photo_form=$('add_photo_form');
    var pb = new dwProgressBar({
        container: $('prob'),
        startPercentage: 0,
        speed:1,
        percentageID: 'perc',
        backgIm:'images/progress_red.gif',
        procIm:'images/progressbar.gif',
        width:120,
        height:12
    });
    function linkUpdate() {
        if (!swf.uploading) return;
        pb.set(swf.percentLoaded);
    }
    var swf = new Swiff.Uploader({
        path: 'admin/articles/js/Swiff.Uploader.swf',
        url: 'admin/articles/ajax/update_photos.php',
        typeFilter: {
            'Images (*.jpg, *.jpeg, *.gif)': '*.jpg; *.jpeg; *.gif;'
        },
        verbose: true,
        queued: false,
        multiple: false,
        target: link,
        instantStart: false,
        height:32,
        fileSizeMax: 2 * 1024 * 1024,
        onBeforeStart:  function() {
            swf.setOptions({
                data: $('add_photo_form').toQueryString()
            });
        },
        onSelectSuccess: function(files) {
            if (Browser.Platform.linux) window.alert('Warning: Due to a misbehaviour of Adobe Flash Player on Linux,\nthe browser will probably freeze during the upload process.\nSince you are prepared now, the upload will start right away ...');
            this.setEnabled(false);
            $('art_photo_filename').set('value',files[0].name)
        },
        onSelectFail: function(files) {
            alert('<em>' + files[0].name + '</em> was not added!', 'Please select an image smaller than 2 Mb. (Error: #' + files[0].validationError + ')');
        },
        appendCookieData: true,
        onQueue: linkUpdate,
        onFileComplete: function(file) {    
            this.setEnabled(true);
        },
        onComplete: function() {
            var pars='id='+$('article_id').get('value');
            myRequest = new Request.HTML({
                url: 'admin/articles/ajax/show_selected_art.php',
                method: 'get',
                update: 'div_add_art',
                evalScripts: true,
                onRequest: show_loader,
                onComplete: function(){
                    $('artform_loader').style.display = 'none';
                    art_events();
                }
            }).send(pars);
            $('artform_edit').empty();
            var result = ''; 
            $('trans_shield').destroy();
            if(document.getElement('.swiff-uploader-box')!=null){
                document.getElement('.swiff-uploader-box').destroy();
            }
        }
    });
    
    link.addEvents({
        click: function() {
            return false;
        },
        mouseenter: function() {
            this.addClass('hover');
            swf.reposition();
        },
        mouseleave: function() {
            this.removeClass('hover');
            this.blur();
        },
        mousedown: function() {
            this.focus();
        }
    });
    $('add_photo_butt').addEvent('click',function(){
        $('prob').setStyle('visibility','visible');
        swf.start();
    });
}

function link_mode(article_id, type) {
    var pars = $H({
        article_id:article_id, 
        type:type
    }).toQueryString();
    var myRequest = new Request.HTML({
        url: 'admin/articles/ajax/link_mode.php',
        method: 'get',
        update: 'link_mode',
        evalScripts: true,
        onComplete: function(){ }
    }).send(pars);
}



function close_link_mode(article_id, type) {
    var pars = $H({
        article_id:article_id, 
        type:type
    }).toQueryString();
    var myRequest = new Request.HTML({
        url: 'modules/articles/ajax/close_link_mode.php',
        method: 'get',
        update: 'link_mode',
        evalScripts: true,
        onComplete: function(){ }
    }).send(pars);
}




function show_articles_editor(id){    
    
    
  
    
    var pars = $H({
        art_id:id, 
        mode:'art_edir_form'
    }).toQueryString();
   
   
    var s  = '?edit';
   
    if (id==0) s = '';
   
   
    /*
   
    var preload_editor = new Element('div',
    {
        'id':'art_preload',
        'src':'modules/articles/img/preload.gif',
        'styles': {
            
            'background': 'url("modules/articles/img/preload.gif") no-repeat scroll center center white', 
            'left': '0',            
            'position': 'fixed',
            'top': '0',           
            'z-index': '100',
            'height': '100%',
            'width': '100%',
            'opacity': '0.5'
            
        }    
    }).inject(document.body,'bottom');
   */
   
   
    var myRequest = new Request.HTML({
        url: 'modules/articles/ajax/actions.php'+s,
        method: 'get',       
        evalScripts: true,
        onComplete: function(a,b,c,d){ 
           
            var bg_editor = new Element('div',
            {
                'id':'bg_editor',
                'styles': {
                    'background-color': 'black',
                    'height': '100%',
                    'left': '0',
                    'opacity': '0',
                    'position': 'fixed',
                    'top': '0',           
                    'z-index': '100',
                    'width': '100%'                                   
                }    
            }).inject(document.body,'bottom');
            
            
            var contener_editor = new Element('div',
            {
                'id':'contener_editor',
                'styles': {
                    'position': 'absolute',
                    /*'top': '15%',*/
                    'z-index': '100',
                    'width': '100%',
                    'opacity': '0'
                    
                }              
            }).inject(document.body,'bottom');
    
  
            var win_editor = new Element('table',
            {
                'id':'win_editor',
                'styles': {        
                    
                    'margin': 'auto',
                    'padding': '15px 20px 0',
                    'width': '950px',
                    /*'height': '612px',*/
                    'background': 'url("modules/articles/img/preload.gif") no-repeat scroll center center white'
                },
                'html':'<tr><td valign="top"><div  style=\'float:right;\'><a href=\'#\' id=\'close_editor\'>Закрыть</a></div><div id=sub_contener_editor></div></td></tr>'
            }).inject($('contener_editor'),'bottom');
            
            var sub_contener_editor = $('sub_contener_editor').setStyle('opacity','0').set('html', c);
        
            // $('win_editor').getElement('textarea').setStyle('width','100%').setStyle('height','300px');
   
   
   
            bg_editor.set('morph', {
                duration: "1000", 
                transition: Fx.Transitions.Circ.easeInOut
            });
            bg_editor.morph({
                opacity: 0.5
            });
            bg_editor.get('morph');   
   
   
            var screen = innerSize();
            var s = contener_editor.getSize();
            var r = getScrollXY();      
                      
            contener_editor.setStyle('top', Math.ceil((screen.height-s.y)/2+r[1]) + "px");                      
          
   
   
   
            contener_editor.set('morph', {
                duration: "1000", 
                transition: Fx.Transitions.Circ.easeInOut
            });
            contener_editor.morph({
                opacity: 1
            });
            contener_editor.get('morph');   
   
   
   
   
            setTimeout(function(){                
                
                var el_1 = $('sub_contener_editor');  
                el_1.set('morph', {
                    duration: "1000", 
                    transition: Fx.Transitions.Circ.easeInOut
                });
                el_1.morph({
                    opacity: 1
                });
                el_1.get('morph');   
                
                
                setTimeout(function(){
                    $('win_editor').setStyle('background', 'white');
                }, 500);
                
            /*var el_2 = $('bg_editor');
                el_2.set('morph', {
                    duration: "1000", 
                    transition: Fx.Transitions.Circ.easeInOut
                });
                el_2.morph({opacity: 0.5});
                el_2.get('morph'); */
                
            /*setTimeout(function(){$('art_preload').destroy();}, 1000);*/
                
            },1000);
   
   
            editor_setup();
    
            function editor_setup() {
                tinyMCE.init({
                    // General options
                    mode : "textareas",
                    elements : "ajaxfilemanager",
                    theme : "advanced",
                    plugins :"safari,pagebreak,style,layer,table,save,advhr,advimage, advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
                    // Theme options
                    theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
                    theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,undo,redo,|,link,unlink,anchor,image,cleanup,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
                    theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,fullscreen",
                    theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak",
                    theme_advanced_toolbar_location : "top",
                    theme_advanced_toolbar_align : "left",
                    theme_advanced_statusbar_location : "bottom",
                    theme_advanced_resizing : true,


                    file_browser_callback : "ajaxfilemanager",
		

                    language : "ru",
                    content_css : "style.css",
                    editor_selector : "mceEditor",
                    textarea_trigger : "area_news",

                    // Drop lists for link/image/media/template dialogs
                    template_external_list_url : "lists/template_list.js",
                    external_link_list_url : "lists/link_list.js",
                    external_image_list_url : "lists/image_list.js",
                    media_external_list_url : "lists/media_list.js",

                    // Replace values for the template plugin
                    template_replace_values : {
                        username : "Some User",
                        staffid : "991234"
                    }
                });
              
            }
    
            function close_editor(){         
                tinyMCE.get('area_news').remove();
                contener_editor.destroy();        
                bg_editor.destroy();        
            }
   
   
   
    
    
            //события формы
    
            //событе на звкрытие окна
            if ($('close_editor'))
                $('close_editor').addEvent('click',function(e){
                    e.stop();
                    close_editor();
                });
        
            //событе на сохраннеие
            
            var form = $$('#win_editor form')[0];
             
            if(form){
                form.addEvent('submit', function(e) {
                   
                    if(e!==undefined) e.stop();
                                      
                    var new_text = tinyMCE.get('area_news').getContent(); 
                    $$("#win_editor form #area_news")[0].set('html',new_text);
                    
                    this.set('send', {
                        url:'modules/articles/ajax/actions.php?mode=art_save',
                        /*evalScripts: true,*/
                        onComplete: function(response) {
                            
                            //подгружаю обновленнйю статью     
                            
                            if($('div_add_art') && id!=0){                                
                                var myRequest = new Request.HTML({
                                    url: 'modules/articles/ajax/actions.php?mode=art_show&art_id='+id,
                                    method: 'get',
                                    update: 'div_add_art',
                                    evalScripts: true                                    
                                }).send();
                            }else {
                                if(typeof add_art_id != 'undefined'){
                                    window.location.href = "articles.php?id=" + add_art_id;
                                }else
                                    window.location.reload();
                            }
                            
                            
                            
                            close_editor();
                           
                        }
                    });
                    this.send();
                
                });
            } 
            
            
            if ($('save_editor'))
                $('save_editor').addEvent('click',function(e){                    
                    /*var new_text = tinyMCE.get('textarea_'+id).getContent(); 
            var p = $H({                
                editor_text:new_text,
                editor_id:id                
            }).toQueryString();       
            var myRequest = new Request.HTML({
                url: window.location.href,
                method: 'post',                 
                onSuccess: function(responseTree, responseElements, responseHTML, responseJavaScript) { // запрос выполнен уcпешно    
                    if (responseHTML.trim() == 'ok'){
                        $(id).set('html', new_text);                        
                        close_editor(id);
                    }else{
                        alert("При сохранении произошла ошибка.");
                    }
                }       
            }).send(p);
            
                     */
                    });
        }
    }).send(pars);
    return false;
}





function innerSize() {
    var de = document.documentElement;
    var h = self.innerHeight || ( de && de.clientHeight ) || document.body.clientHeight;
    var w = self.innerWidth || ( de && de.clientWidth ) || document.body.clientWidth;
    return {
        width:w,
        height:h
    };
}


function getScrollXY() {
    var scrOfX = 0, scrOfY = 0;
    if( typeof( window.pageYOffset ) == 'number' ) {
        // Netscape compliant
        scrOfY = window.pageYOffset;
        scrOfX = window.pageXOffset;
    } else if( document.body &&
        ( document.body.scrollLeft || document.body.scrollTop ) ) {
        // DOM compliant
        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;
    } else if( document.documentElement &&
        ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
        // IE6 Strict
        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;
    }
    return [ scrOfX, scrOfY ];
}
