function $() {
  var elements = new Array();

  for (var i = 0; i < arguments.length; i++) {
    var element = arguments[i];
    if (typeof element == 'string')
      element = document.getElementById(element);

    if (arguments.length == 1)
      return element;

    elements.push(element);
  }

  return elements;
}

//start DOM
if(typeof DOM=="undefined"){
    var DOM=new Object();
}

/**
 *  Returns the width of the window canvas
 * 
 *  @return {Number}
 *  @scope public
 */
DOM.getClientWidth = function () /* :Number */{
    var w=0;
    if (self.innerWidth) w = self.innerWidth;
    else if (document.documentElement && document.documentElement. clientWidth ) w = document.documentElement. clientWidth ;
    else if (document.body) w = document.body. clientWidth ;
    return w;
};

/**
 *  Returns the height of the window canvas
 * 
 *  @return {Number}
 *  @scope public
 */
DOM.getClientHeight = function () /* :Number */{
    var h=0;
    //alert(document.documentElement.clientHeight+' '+document.body.scrollHeight);
    if (self.innerHeight) h = self.innerHeight;
    else if (document.documentElement && document.documentElement.clientHeight) h = document.documentElement.clientHeight;
    else if (document.body) h = document.body.clientHeight;
    return h;
};

DOM.getHeight = function (el) {
    var h=0;
    if (document.getElementById) {
        h = $(el).offsetHeight;
    }

    return h;
};
//end DOM

function checkPass(val1, val2){
    if($(val1).value==$(val2).value) return true;
    else {alert('Пароли не совпадают!'); return false;}
}

function copyQ(autor) {
    txt='';
    if (window.getSelection&&!window.opera) txt = window.getSelection();
    else if (document.getSelection) txt=document.getSelection();
    else if (document.selection) txt=document.selection.createRange().text;
    txt='<div class="qu">'+autor+'<br>'+txt+'</div><br>';
}

function setCaret (textObj) {
    if (textObj.createTextRange) {
        textObj.caretPos = document.selection.createRange().duplicate();        
    }
}

function insertAtCaret (textObj, textV) {    
    textV=textV.replace(/\[\?\]/g,'');
    if (textV=='') return;
    var ver=8;
    if(document.all && !window.opera){
        if (textObj.createTextRange && textObj.caretPos) {
            var caretPos = textObj.caretPos;
            caretPos.text = (caretPos.text.charAt(caretPos.text.length - 1) == ' ') ?textV + ' ' : textV;
        } else {
            textObj.value += textV
        }
    } else {
        var brows = navigator.userAgent.toString();
        var scrollTop, scrollLeft;
        if (textObj.type == 'textarea' &&  typeof textObj.scrollTop != 'undefined'){
            scrollTop  = textObj.scrollTop;
            scrollLeft = textObj.scrollLeft;
        }                
        if(brows.search(/opera\/?(\d*.\d*)/i) != -1) ver = RegExp.$1;
        if(textObj.selectionStart>=0  && ver>=8){
            if(textObj.textLength != undefined){ 
                var selLength = textObj.textLength; 
                var selStart = textObj.selectionStart; 
                var selEnd = textObj.selectionEnd; 
                if (selEnd == 1 || selEnd == 2)  selEnd = selLength;  
                var s1 = (textObj.value).substring(0,selStart); 
                var s2 = (textObj.value).substring(selStart, selEnd) 
                var s3 = (textObj.value).substring(selEnd, selLength); 
                if (s2) textObj.value = s1 + textV + s2 + textV + s3; 
                else   textObj.value = s1 + textV + s3; 
                textObj.setSelectionRange(selStart+textV.length,selStart+textV.length); 
            } 
            if (typeof scrollTop != 'undefined'){
                textObj.scrollTop  = scrollTop;
                textObj.scrollLeft = scrollLeft;
            }
        } else {
            textObj.value+=textV;
        }
    }
}

function pasteQ(){
//   if (txt!='') document.forms.addreply.newtext.value=document.forms.addreply.newtext.value+txt;//insertAtCaret($(newtext),txt);
//alert ($('wysiwygnewtext').contentWindow.document.body.innerHTML);
//   $('wysiwygnewtext').contentWindow.document.body.innerHTML+=$('wysiwygnewtext').contentWindow.document.body.innerHTML;
wysiwyg_settext('newtext', '777');
//alert (document.getElementById('wysiwygnewtext').contentDocument);
document.frames.wysiwygnewtext.document.body.innerHTML+=txt;
//var dc=document.frames.wysiwygnewtext.document.getElementsByClassName("qu");
//dc.style.backgroundColor="#000000";

//document.frames.wysiwygnewtext.document.body.dc.style.backgroundColor="#EEEEEE";

//alert(document.frames.wysiwygnewtext.document.body.innerHTML);
}

function slimLayer(id){
    document.getElementById(id).style.display = (document.getElementById(id).style.display != 'block') ? 'block' : 'none';
}
function backToTheme(uri){
    window.location.href=uri;
}

function run_flash(){
    var sw1 = new SWFObject("/i/flash.swf", "video", "721", "125", "6", "#FFFFFF");
    sw1.addParam("wmode", "transparent");
    sw1.addParam("scale", "exactfit");
    sw1.addParam("salign", "lb");
    sw1.addParam("allowScriptAccess", "sameDomain");
    sw1.write("flash");
}

function insert_map(){
    var sw1 = new SWFObject("/i/map2.swf", "maps", "505", "455", "7", "#FFFFFF");
    sw1.addParam("wmode", "transparent");
    sw1.addParam("scale", "exactfit");
    sw1.addParam("align", "middle");
    //sw1.addParam("salign", "lb");
    sw1.addParam("allowScriptAccess", "sameDomain");
    sw1.write("proezd_map");
}

function create_bar(){
    $('header').innerHTML += '<div id="fly-bar"><img src="/i/fly_bar.gif" usemap="#fly_map" alt="" /></div>'+
    '<map name="fly_map" id="fly_map">'+
    '<area shape="rect" coords="19,5,39,20" href="/" alt=" На главную" title="На главную" />'+
    '<area shape="rect" coords="42,5,62,20" href="/contacts/" alt="Написать письмо" title="Написать письмо" />'+
    '<area shape="rect" coords="68,5,93,20" href="/info/site_map.html" title="Карта сайта" />'+
    '</map>';
    move_bar();
}

function move_bar(){
    if (document.body.clientWidth <= min_width){
        $('fly-bar').style.left = min_width-el_width+'px';
    } else {
        left_pos = parseInt((parseInt(document.body.clientWidth)-el_width));
        $('fly-bar').style.left = left_pos+'px';
    }
}

function init_size_old(){
var sumh=0;
var toth=0;
var elh=0;
    toth  = DOM.getClientHeight();
    sumh  = DOM.getHeight('header');
    sumh += DOM.getHeight('footer');
    elh = toth-sumh;
        //alert(toth+' '+sumh+' '+elh);
    if(elh>0){
        $('left').style.height=elh+'px';
        //alert($('left').style.height);
    }
}

function init_size(){
var lefth  = DOM.getHeight('left');
var contenth = DOM.getHeight('content');
//alert(lefth + ' ' + contenth);
var tmph = Math.max(lefth, contenth);
var bodyh  = DOM.getClientHeight();
var headh  = DOM.getHeight('header');
var footh  = DOM.getHeight('footer');
if((headh + tmph + footh) > bodyh){
    $('left').style.height = tmph + 'px';
} else if ((headh + tmph + footh) <= bodyh) {
    $('left').style.height = bodyh - headh - footh + 'px';
}
}

function load_actions () {
    min_width=955;
    el_width=122;//95

    create_bar();
    init_size();
    run_flash();
    if($('proezd_map')) insert_map();
}
function resize_actions () {
    move_bar();
    init_size();
}

if (document.getElementById) {
    window.onload = load_actions;
    window.onresize = resize_actions;
}




function OpenPic(path, width, height, title, isprint){
WinPic=window.open('','','width='+width+',height='+height+',toolbar=no,location=no,directories=no,status=no,menubar=yes,copyhistory=no,resizable=no,scrollbars=no');
WinPic.document.write('<html><title>'+title+'</title><body style="margin: 0; padding: 0;"><img title=Закрыть src='+path+' height=100% width=100% style="cursor: hand;" onclick="window.close();"></body></html>');
}

