function getObjStyle(DivID) {
   var obj = document.layers ? document.layers[DivID] :
   document.getElementById ?  document.getElementById(DivID).style : document.all[DivID].style;
   return obj;
}

function ToggleMenu(menublock,menuflag) {
  r = getObjStyle(menublock);

  if(r.display == 'none'){
    r.display = 'block'; 
    setCookie(menublock, 1);
    document.images[menuflag].src = "img/minus.gif";
  } 
  else{
    r.display = 'none';  
    setCookie(menublock, 0);
    document.images[menuflag].src = "img/plus.gif";
  }
   
}

function ToggleAllMenuOn() {
  for (i = 0; i < document.images.length; i++){
     var item = document.images[i];

     if ( item.name.substring(0,8) == "menu_fl_" ){

       var block_id = item.name.substring(8,10)

       if( getObjStyle("menu_bl_"+block_id).display == 'none' ){
         getObjStyle("menu_bl_"+block_id).display = 'block';
         document.images["menu_fl_"+block_id].src = "img/minus.gif";
         setCookie("menu_bl_"+block_id, 1);
       }
     }
  }
}

function ToggleAllMenuOff() {

  for (i = 0; i < document.images.length; i++){
     var item = document.images[i];

     if ( item.name.substring(0,8) == "menu_fl_" ){

       var block_id = item.name.substring(8,10)

       if( getObjStyle("menu_bl_"+block_id).display == 'block' ){
         getObjStyle("menu_bl_"+block_id).display = 'none';
         document.images["menu_fl_"+block_id].src = "img/plus.gif";
         setCookie("menu_bl_"+block_id, 0);
       }
     }
  }
}

function menuLightOn(r)  {  r.backgroundColor='#6AB5FF'; }
function menuLightOff(r) {  r.backgroundColor='';        }

function menuClick(r) {
  document.location.href=r;
}

///////////////////////////////////////////
//var Opera7 		= (navigator.userAgent.indexOf('Opera')!=-1) && (navigator.userAgent.charAt(navigator.userAgent.indexOf('Opera')+6)>=7)

function get_selection() {
   if (document.getSelection){
	selection = document.getSelection();
/*
	if (!Opera7){
		selection = selection.replace(/\r\n\r\n/gi, "_doublecaret_");
		selection = selection.replace(/\r\n/gi, " ");
	       while (selection.indexOf("  ") !=-1) selection = selection.replace(/  /gi, ""); 
		selection = selection.replace(/_doublecaret_/gi, "\r\n\r\n");
	}
*/
  } else
      selection = document.selection.createRange().text;
}


function sendError() {

  if ( !selection && !confirm( "Уважаемый пользователь!\n\nВы можете выделить мышкой блок текста с ошибкой и он будет вставлен в сообщение.\nДля этого: нажмите кнопку [Отмена], выделите текст и нажмите [сообщить об ошибке!].\n\nДля формирования текста вручную нажмите кнопку [OK].\nЕсли хотите отказаться от посылки сообщения нажмите [Отмена]." ) ) return;
  else{
    document.form_send_err.ErrSelect.value = selection; 
    document.form_send_err.submit();
  }

}

function setCookie(name, value, expire) { 
  document.cookie = name + "=" + escape(value) + ((expire == null) ? "" : ("; expires=" + expire.toGMTString()));
}

function getCookie( Name ) {
  var search = Name + "=";

  if ( document.cookie.length > 0 ) { // if there are any cookies
    offset = document.cookie.indexOf(search) 

    if ( offset != -1 ) { // if cookie exists 
      offset += search.length;                      // set index of beginning of value
      end = document.cookie.indexOf(";", offset);   // set index of end of cookie value
      if ( end == -1 ) end = document.cookie.length;

      return unescape( document.cookie.substring(offset, end) );
    } 

  }

}

function openImageInNewWindow(ImageUrl){
	var newWindow;
	newWindow=window.open(ImageUrl,'Просмотр','height=500,width=820,location=no,menubar=no,resizable=no,scrollbars=no,toolbar=no,status=yes');
	if (window.focus) {newWindow.focus()}
}