var num = 0;

function changeBg(div_id){
document.getElementById(div_id).style.backgroundImage="url('images/a9.jpg')";
}
function changeBg2(div_id){
document.getElementById(div_id).style.backgroundImage="url('images/a8.jpg')";
}

function show_login() {
document.getElementById('abs_div_hid').style.visibility='visible';
document.getElementById('avt_div3').style.visibility='hidden';
}

function hide_login() {
document.getElementById('avt_div3').style.visibility='visible';
document.getElementById('abs_div_hid').style.visibility='hidden';
}


function menu_on(num){
document.getElementById(num).style.visibility='visible';
}

function hide_all () {
document.getElementById('p7').style.visibility='hidden';
document.getElementById('p8').style.visibility='hidden';
}


function relate (){
  var rel = event.relatedTarget;
  alert(rel);
}

function showVotingResults(id)
{
   var a
   var b
   var url
   vidWindowWidth=550;
   vidWindowHeight=450;
   a=(screen.height-vidWindowHeight)/5;
   b=(screen.width-vidWindowWidth)/2;
   features="top="+a+",left="+b+",width="+vidWindowWidth+",height="+vidWindowHeight+",toolbar=no,menubar=no,location=no,directories=no,scrollbars=no,resizable=no";
   url="/site.php?id="+id+"&graph=true";
   window.open(url,'',features,true);
}

function wopen(url) {
   var a
   var b
   var url
   vidWindowWidth=700;
   vidWindowHeight=600;
   a=(screen.height-vidWindowHeight)/5;
   b=(screen.width-vidWindowWidth)/2;
   features="top="+a+",left="+b+",width="+vidWindowWidth+",height="+vidWindowHeight+",toolbar=no,menubar=no,location=no,directories=no,scrollbars=no,resizable=no";
   window.open(url,'',features,true);
}

function insertTag(tagstart, tagend) {
  var elem = document.getElementById('content');
  
  // Mozilla и другие вменяемые браузеры
  if (elem.setSelectionRange) {
    elem.value = elem.value.substring(0, elem.selectionStart) +
                  tagstart +
                  elem.value.substring(elem.selectionStart, elem.selectionEnd) +
                  tagend +
                  elem.value.substring(elem.selectionEnd, elem.value.length);
  }
  // MSIE
  else {
    var selectedText = document.selection.createRange().text;
    if (selectedText != "") {
      var newText = tagstart + selectedText + tagend;
      document.selection.createRange().text = newText;
    }
  }
}

function quote(username, content) {
  var quote_str = "[quote][b]" + username + " писал(а)[/b]:\n"+content+"[/quote]\n";
  var elem = document.getElementById('content');
  
  if (elem.setSelectionRange) {
    elem.value = elem.value.substring(0, elem.selectionStart) + quote_str +
                 elem.value.substring(elem.selectionStart, elem.selectionEnd) +
  		   elem.value.substring(elem.selectionEnd, elem.value.length);
  }
  else if ((document.selection)) {
     elem.focus();
     document.selection.createRange().text = quote_str+document.selection.createRange().text;
  } 
  else {
    elem.value += quote_str;
  }  
}

function insertAtCursor(myValue) {
  var myField = document.getElementById('content');
  if (document.selection) {
    myField.focus();
    sel = document.selection.createRange();
    sel.text = myValue;
  }
  else if (myField.selectionStart || myField.selectionStart == '0') {
    var startPos = myField.selectionStart;
    var endPos = myField.selectionEnd;
    myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos, myField.value.length);
  }
  else {
    myField.value += myValue;
  }
}

function ctrlEnter_test()
{
  var k=event.keyCode;
  if(k==13) {
    if(event.ctrlKey) {
      if (document.getElementById('content').value=='') {alert('Нельзя отправлять пустое сообщение!');}
      else {
        document.forms['fmess'].submit();
        document.getElementById('content').value='';
      }
    }
  }
}









