function elem(id)
  {
  return document.getElementById(id);
  }

function picture(id,src){
    node=elem(id);
    newpic=document.createElement('img');
    newpic.src=src;
    newpic=node.appendChild(newpic);
}
function remvPic(id){
    node=elem(id);
    node.removeChild(node.lastChild);
}

function get_http(){
      var xmlhttp;
      /*@cc_on
      @if (@_jscript_version >= 5)
        try {
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                xmlhttp = new
                ActiveXObject("Microsoft.XMLHTTP");
            } catch (E) {
                xmlhttp = false;
            }
        }
      @else
        xmlhttp = false;
      @end @*/
      if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
        try {
            xmlhttp = new XMLHttpRequest();
        } catch (e) {
            xmlhttp = false;
        }
      }
      return xmlhttp;
   }

function takeContent(divid,url,picurl) {
   if (picurl != false)
     {
     picture(divid,picurl);
     }
   //--
        if(!this.http){
            this.http = get_http();
        }
        // Запрос
        if (this.http) {
            var http = this.http;

            this.http.open("GET",url, true);

            this.http.onreadystatechange = function() {
                if (http.readyState == 4) {
                    if (divid) document.getElementById(divid).innerHTML=http.responseText;
                  }
            }
        }
        this.http.send(null);
    }

function showform()
  {
  document.getElementById("addform").style.display="";
  hide("addlink");
  }

function hide(LayerName){
  document.getElementById(LayerName).style.visibility="hidden";
}

function winop(mark,id)
  {
  windop = window.open("vote.php?id="+id+"&mark="+mark,"mywin","height=120,width=300,left=100,top=30");
  return windop;
  }

function add_child_br(id,text)
  {
  newNode = document.createTextNode(text);
  br = document.createElement('br');
  id.appendChild(newNode);
  id.appendChild(br);
  }

function clear_elem(id)
  {
  if (id.lastChild)
    {
    while(id.lastChild) { id.removeChild(id.lastChild) }
    }
  }

function comment_check(id)
  {
  var comment_err = document.getElementById("comment_err");
  var comment_message = document.getElementById("comment_message");

  clear_elem(comment_err);
  var result = new Array('');
  var smiles = new RegExp(":([0-9]+):","g");
  var nourl = new RegExp("(http:\/\/)*([a-zA-Z0-9_-]+)( )*.( )*(ru|com|net|org|ws|biz|su|info|com.ru|spb.ru|msk.ru)");
  if (comment_message.value.match(smiles))
    {
    result = comment_message.value.match(smiles);
    }

  if(nourl.test(comment_message.value))
    {
    add_child_br(comment_err,"- В комментарии нельзя указывать адреса сайтов");
    }

  if (result.length > 5)
    {
    add_child_br(comment_err,"- В комментарии может быть не более 5 смайликов");
    }

  if (comment_message.value == 0)
    {
    add_child_br(comment_err,"- Вы не ввели комментарий");
    }
  else if (comment_message.value.length > 1000)
    {
    add_child_br(comment_err,"- Комментарий не может быть более 1000 символов");
    }

  if (!comment_err.lastChild)
    {
    takeContent('new_comment','/ajax/post_comment.php?id='+id+'&imya='+comm_imya.value+'&mess='+comment_message.value,'/img/ajax/post_comment.gif');
    elem('addform').style.display = 'none';
    return false;
    }
  }

function check_login()
  {
  if(document.getElementById("login").value.length == 0)
    {
    document.getElementById("login").focus();
    alert("Нужно ввести логин");
    return false;
    }

  if(document.getElementById("password").value.length == 0)
    {
    document.getElementById("password").focus();
    alert("Нужно ввести пароль");
    return false;
    }

  document.login_form.submit();
  }

function insertText(elname, what)
  {
  if (document.forms['inputform'].elements[elname].createTextRange)
    {
    document.forms['inputform'].elements[elname].focus();
    document.selection.createRange().duplicate().text = what;
    }
  else if ((typeof document.forms['inputform'].elements[elname].selectionStart) != 'undefined')
    { // for Mozilla
    var tarea = document.forms['inputform'].elements[elname];
    var selEnd = tarea.selectionEnd;
    var txtLen = tarea.value.length;
    var txtbefore = tarea.value.substring(0,selEnd);
    var txtafter =  tarea.value.substring(selEnd, txtLen);
    var oldScrollTop = tarea.scrollTop;
    tarea.value = txtbefore + what + txtafter;
    tarea.selectionStart = txtbefore.length + what.length;
    tarea.selectionEnd = txtbefore.length + what.length;
    tarea.scrollTop = oldScrollTop;
    tarea.focus();
    }
  else
    {
    document.forms['inputform'].elements[elname].value += what;
    document.forms['inputform'].elements[elname].focus();
    }
  }