function MM_showHideLayers() { //v9.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function SH(name) {
    _div = document.getElementById(name);  
    if (_div.style.visibility == "visible") _div.style.visibility="hidden"; else _div.style.visibility="visible";
}

function SetValue(id, value) {
    o = document.getElementById(id);  
    if (o != null) o.value=value;
}

function SetText(id, newText) { //v9.0
  with (document) if (getElementById && ((obj=getElementById(id))!=null))
    with (obj) innerHTML = unescape(newText);
  with (document) if (getElementById && ((obj=getElementById(id+'txt'))!=null))
    with (obj) value = unescape(newText);
}



function addtofavorites(url,dsc)
{
  //чтобы добавилась иконка, в корень сайта нужно положить favicon.ico
  window.external.addFavorite(url, dsc);
  return false;
}

function gotopage(pg)
{
  location.href=pg;
}

function checkdog(str)
{
  if (str.length<7) return false;
  for (var i = 1; i < str.length; i++) 
  {
    var ch = str.charAt(i);
    if (ch == "@") return true;
  }
  return false;
}

function checkdigit(str)
{
  if (str=='') return false;
  for (var i = 1; i < str.length; i++) 
  {
    var ch = str.charAt(i);
    if ((ch < "0")||(ch >"9")) return false;
  }
  return true;
}

function SetCookie(name, value, expire, path, domain, secure)
{
var today = new Date();
expires = new Date(today.getTime() + expire*24*60*60*1000);
 document.cookie = name + "=" + escape(value) +
                ((path) ? "; path=" + path : "") +
                ((domain) ? "; domain=" + domain : "") +
                ((secure) ? "; secure" : "");
}
//                ((expires) ? "; expires=" + expires.toGMTString() : "") +

function DeleteCookie(name, path, domain)
{
 if(GetCookieByName(name))
  document.cookie = name + "=" + 
                ((path) ? "; path=" + path : "") +
                ((domain) ? "; domain=" + domain : "") +
                "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  
}

function get_selection(id)
{
  selection='';
  if (document.selection!=null)
  {
    selection = document.selection.createRange().text;
  } 
  else 
  {
    d = document.getElementById(id);
    ss = d.selectionStart; // определяем координаты курсора
    es = d.selectionEnd; // определяем координаты курсора
    selection=d.value.substring(ss,es);
  }

  return selection;
}

function insert_selection(id, txt)
{
  selection='';
  if (document.selection!=null)
  {
    selection = 'ie';
  }

  d = document.getElementById(id);
  if (selection=='')
  {
    ss = d.selectionStart; // определяем координаты курсора
    es = d.selectionEnd; // определяем координаты курсора
    txt1 = d.value.substring(0,ss); // присваеваем txt1 часть текста перед курсором
    txt2 = d.value.substring(es, d.value.length); // присваеваем txt2 то, что после курсора
    d.value = txt1 + txt + txt2;  // выводим обе половинки с тем, что нужно было добавить
    d.focus();
    d.selectionEnd=ss+txt.length;
    d.selectionStart=ss+txt.length;
  }  
  else
  {
    d.focus();
    if (d.createTextRange) d.caretPos = document.selection.createRange().duplicate(); 
    d.caretPos.text = txt;
  }
}

function addUBBimg(id, iart)
{
  d = document.getElementById(id);
  i = document.getElementById(iart);
  art='';
  if (i!=null)
     art=i.value;
  
  if (art=='') { alert('Фото не выбрано'); return; }

  c="[img_"+art+"]";
  insert_selection(id, c);

//  if (d.createTextRange) d.caretPos = document.selection.createRange().duplicate(); 
//  d.caretPos.text = c;
}

function addlink(id)
{
  sel=get_selection(id);
  if (sel == "")  { alert("Выделите текст для ссылки мышью.");} 
  else
  {
    def="http://";
    l = prompt("Введите ссылку", def);
    if (!l) return false;
    if ((l==def)||(l=='')) return false;
    if (confirm ("Открывать эту ссылку в новом окне?")) l=l+" target=_blank";
    c = "[url="+l+"]"+sel+"[/url]";
    insert_selection(id, c);
  }
  return false;
}

function addsmile(i, id)
{
    c = "[sm"+i+"]";
    insert_selection(id, c);
//
//    d = document.getElementById(id);
// d.focus();
//    if (d.createTextRange) d.caretPos = document.selection.createRange().duplicate(); 
//    d.caretPos.text = c;
  return false;
}

function addUBBsimple(tagname, id)
{
  sel=get_selection(id);
  if (sel == "")  { alert("Выделите текст мышью.");} 
  else
  {
    c = "["+tagname+"]"+sel+"[/"+tagname+"]";
    insert_selection(id, c);
//    d = document.getElementById(id);
//    if (d.createTextRange) d.caretPos = document.selection.createRange().duplicate(); 
//    d.caretPos.text = c;
  }
  return false;
}

function addUBBp(id)
{
  addUBBsimple('p', id);
}

function addUBBptt(id)
{
  addUBBsimple('ptt', id);
}

function addUBBptv(id)
{
  addUBBsimple('ptv', id);
}

function addUBBb(id)
{
  addUBBsimple('b', id);
}

function addUBBi(id)
{
  addUBBsimple('i', id);
}

function addUBBu(id)
{
  addUBBsimple('u', id);
}

function addUBBcenter(id)
{
  addUBBsimple('center', id);
}

function addUBBright(id)
{
  addUBBsimple('right', id);
}

function addUBBleft(id)
{
  addUBBsimple('left', id);
}

function openpicture(w,h,p)
{
  param='';
  if (screen.availWidth-w-100<0) { w=screen.availWidth-100; param=', scrollbars=yes'; }
  if (screen.availheight-h-100<0) { h=screen.availHeight-100; param=', scrollbars=yes'; }
  window.open(p,"schema"+h+w,"height="+h+",width="+w+param+",left="+(screen.availWidth-w)/2+",top="+(screen.availHeight-h)/2);
  return false;
}

function showme(id)
{
  e=document.getElementById('div'+id);
//  alert (id);
  if (e==null) return false;
 
  i=document.getElementById('img'+id);
	if(e.style.display=="none")
	{
		i.src="/images/minus.gif";
		e.style.display="";
	}
	else
	{
		i.src="/images/plus.gif";
		e.style.display="none";	
	}
return false;
}

function rshowme(id)
{
  e=document.getElementById('rdiv'+id);
//  alert (id);
  if (e==null) return false;
 
  i=document.getElementById('rimg'+id);
	if(e.style.display=="none")
	{
		i.src="/images/minus.gif";
		e.style.display="";
	}
	else
	{
		i.src="/images/plus.gif";
		e.style.display="none";	
	}
return false;
}

function selectall()
{
      var frm = document.rootform;
      var len = frm.elements.length;
      for (var i = 0; i < len; i++) 
      {
        var elem = frm.elements[i];
        if (elem.name.substr(0, 4) == "ids[")
          elem.checked = true;

      }
      return false;
}
function deselectall()
{
      var frm = document.rootform;
      var len = frm.elements.length;
      for (var i = 0; i < len; i++)
      {
        var elem = frm.elements[i];
        if (elem.name.substr(0, 4) == "ids[")
          elem.checked = false;
      }
      return false;
}

