function toggle_center_block(block_id, w, h) { 
  f = document.getElementById(block_id); 
  
  if (f.style.display == "block") { 
    f.style.display = "none"; 
  } // прячем блок 
  else { 
    // Для начала узнаем размеры видимой области страницы 
    var myWidth = 0, myHeight = 0; 
    if (typeof(window.innerWidth) == 'number') { 
      // для всего кроме MSIE 
      myWidth = window.innerWidth; 
      myHeight = window.innerHeight; 
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) { 
      // IE6+ 
      myWidth = document.documentElement.clientWidth; 
      myHeight = document.documentElement.clientHeight; 
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) { 
      // IE4 
      myWidth = document.body.clientWidth; 
      myHeight = document.body.clientHeight; 
    } 
  
    // Теперь уточняем, насколько страница прокручена вниз и вбок 
    var scrOfX = 0, scrOfY = 0; 
    if(typeof(window.pageYOffset) == 'number') { 
      // Netscape и его родственники 
      scrOfY = window.pageYOffset; 
      scrOfX = window.pageXOffset; 
    } else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) { 
      // DOM 
      scrOfY = document.body.scrollTop; 
      scrOfX = document.body.scrollLeft; 
    } else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) { 
    // IE6 
    scrOfY = document.documentElement.scrollTop; 
    scrOfX = document.documentElement.scrollLeft; 
  } 
  
    // А теперь позиционируем наш блок 
    f.style.top = String(Math.round((myHeight - h) / 2) + scrOfY) + 'px'; 
    f.style.left = String(Math.round((myWidth - w) / 2) + scrOfX) + 'px'; 
//    f.style.width = w + ((3 + 1) * 2); 
//    f.style.height = h + ((3 + 1) * 2); 
    f.style.display = "block"; 
  } // показываем блок 
} // toggle_center_block


function my_confirm(alert_txt) {
   if(confirm(alert_txt)) 
   return true; 
   else return false;
}

var is_show_full = false;
function ShowFullLangBlock()
{
    toggle_center_block('blockraspod', 300, 200);
    
    ///document.body.onclick = function(){ShowFriefCommentsBlock()};
    
    if(document.body.addEventListener) 
    {
        document.addEventListener('click', ShowFriefCommentsBlock, false);
    }
    else if(document.body.attachEvent)
    {
        document.body.attachEvent('onclick', ShowFriefCommentsBlock);
    }
    ClickFullComments();
}

function ClickFullComments(e)
{
    is_show_full = true;
}

function ShowFriefCommentsBlock()
{
    if(!is_show_full)
    {
        if(document.body.addEventListener) 
        {
            document.removeEventListener('click', ShowFriefCommentsBlock, false);
        }
        else if(document.body.attachEvent)
        {
            document.body.detachEvent('onclick', ShowFriefCommentsBlock);
        }
        
        document.getElementById('blockraspod').style.display = 'none';
    }
    else is_show_full = false;
}

function HideNewCommentsBlock()
{
    document.getElementById('blockraspod').style.display = 'none';
}

function getXmlHttp(){
  var xmlhttp;
  try {
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (e) {
    try {
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (E) {
      xmlhttp = false;
    }
  }
  if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
    xmlhttp = new XMLHttpRequest();
  }
  return xmlhttp;
}


function get_desc(item) {
    var req = getXmlHttp();
    req.open('GET', './modules/get_desc.php?id='+item, true); 
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            if(req.status == 200) {
               document.getElementById("blockraspod2").innerHTML=req.responseText;
            }
        }
    }
  
    req.send(null); 
}

/* функция транслитерации */
function translit(s)
 {
  var t="аaбbвvгgдdеeёjoжzhзzиiйjjкkлlмmнnоoпpрrсsтtуuфfхkhцcчchшshщshhыyэehюjuяjaАAБBВVГGДDЕEЁJoЖZhЗZИIЙJjКKЛLМMНNОOПPРRСSТTУUФFХKhЦCЧChШShЩShhЫYЭEhЮJuЯJa _";
      t=t.replace(/([а-яёЁ\s])([a-z~_]+)/gi,'.replace(/$1/g,"$2")');
      t=t+'.replace(/([\!\.\,\ь\Ь\ъ\Ъ\(\)\\\/\?\'\"])/g,"")';
   return eval("s"+t);
//   mm.replace(/\!/gi,'');
//   return t;
 }

// настройки хранить в Cookies до конца сессии
function setCookie(name, value){
 $.cookie(name, value, {expires: 0});
//  alert("Cookie set: "+name+"="+value);
}


// открытие в новом окне с шириной w и высотой h
function NW(url,wind,w,h) {
  var target_win1=window.open(url, wind, 'toolbar=no,location=no,status=no,menubar=no,resizable=no,directories=no,scrollbars=no,width='+w+',height='+h+'');
}

function get_details(type,id) {
  $('.tabl05').html('');
  if ($('#row'+id).html()=='') {
    $('#a'+id).html(' << ');
    $('#a'+id).attr('title','свернуть');
    $('#row'+id).html('<td colspan="8">загружается ...</td>');
    $.get('./modules/ajax/get_details.php',{id: id, type: type},function(data){$('#row'+id).html(data)});
  }
  else {
    $('#a'+id).html(' >> ');
    $('#a'+id).attr('title','развернуть');
    $('#row'+id).html('');
  }
  return false;
}
function set_up(id,act,type) {
   // читаем данные из формы И готовим аргументы для аякс-запроса
   var post=[];
   post.push({name: 'id', value: id});
   post.push({name: 'act', value: act});
   post.push({name: 'type', value: type});
   switch (type){
     case 'text':
        var flds=new Array('rekl_title','rekl_text','rekl_link','rekl_isactive','rekl_order');
        for (i in flds){
          fld_type=$('#'+flds[i]+id).attr('type');
          switch (fld_type){
             case 'checkbox': post.push({name: flds[i], value: ($('#'+flds[i]+id).attr('checked')==true)?1:0 });
             break
             case 'text': post.push({name: flds[i], value:$('#'+flds[i]+id).attr('value')});
             break
          }
          
        }
     break
   }
$.post('./modules/ajax/set_up.php',post,function(data){alert(data)});
   switch (act) {
     case 'sav': return false;
     break
     case 'del': return true;
     break
     case 'new': return true;
     break
   }
}

function get_gal_menu(id,block){
   $('#detail'+block).html('загружается ...');
   $.get('./modules/ajax/get_gal_menu.php',{'id': id, 'block': block},function(data){$('#detail'+block).html(data)});
}

function countdown(chars){
  var txt=$('#txt').attr('value');
//  txt=txt.replace(/\s+/g, "");
  if (txt.length>chars) {
    txt=$('#txt').attr('value').substring(0,chars);
    $('#txt').attr('value',txt);
  }
  var aa=chars-txt.length;
  $("#symbols").html(aa.toString());
}

