function login() {
  if (document.getElementById("login").style.display=='none') {
    document.getElementById("login").style.display = '';
  }
  else {
    document.getElementById("login").style.display = 'none';
  }
}
function show() {
  document.getElementById("createtopic").style.display="block";
}
function hidenshow(wtf) {
  var cur = document.getElementById(wtf).style.display;
  if (cur == 'none') { document.getElementById(wtf).style.display = ''; }
  else { document.getElementById(wtf).style.display = 'none'; }
}
function del(num, loc, type) {
  if (confirm("Are you sure you want to delete "+type+" #"+num+"?")) { window.location=loc+'?id='+num; } 
}
function bold() {
  bold_word = prompt('Въведете думичките, които искате да са удебелени', '');
  if (bold_word!=null && bold_word!='') {
    form.textarea.value=form.textarea.value+'[b]'+bold_word+'[/b]';
  }
  SetEnd(form.textarea);
}
function und() {
  und_word = prompt('Въведете думичките, които искате да са подчертани', '');
  if (und_word!=null && und_word!='') {
    form.textarea.value=form.textarea.value+'[u]'+und_word+'[/u]';
  }
  SetEnd(form.textarea);
}
function it() {
  it_word = prompt('Въведете думичките, които искате да са наклонени', '');
  if (it_word!=null && it_word!='') {
    form.textarea.value=form.textarea.value+'[i]'+it_word+'[/i]';
  }
  SetEnd(form.textarea);
}
function image() {
  img = prompt('Въведете URL-то на картинката', 'http://');
  if (img!=null && img!='http://') {
    form.textarea.value=form.textarea.value+'[img]'+img+'[/img]';
  }
  SetEnd(form.textarea);
}
function url() {
  url_word = prompt('Въведете URL-то на линка', 'http://');
  url_word2 = prompt('Въведете думата, към която ще бъде току-що-въведеното URL', '');
  if (url_word!=null && url_word!='' && url_word2!=null && url_word2!='') {
    form.textarea.value=form.textarea.value+'[url href=\"'+url_word+'\" target=\"new\"]';
    form.textarea.value=form.textarea.value+url_word2+'[/url]';
  }

  SetEnd(form.textarea);
}
function color() {
  col_word = prompt('Въведете цвят като hex или дума на английски. Пример:', 'red');
  col_word2 = prompt('Въведете думичките, които искате да са оцветени в този цвят', '');
  if (col_word!=null && col_word!='' && col_word2!=null && col_word2!='') {
    form.textarea.value=form.textarea.value+'[color="'+col_word+'"]';
    form.textarea.value=form.textarea.value+col_word2+'[/color]';
  }
  SetEnd(form.textarea);
}
function quote(text, user) {
  form.textarea.value += "[quote]"+user+":"+text.replace("\n", String.fromCharCode(32))+"[/quote]";
  SetEnd(form.textarea);
}
function SetEnd (TB) {
  if (TB.createTextRange) {
    var FieldRange = TB.createTextRange();
    FieldRange.moveStart('character', TB.value.length);
    FieldRange.collapse();
    FieldRange.select();
  }
}
function toggle(what,targetId) {
  target = document.getElementById(targetId);
  target.style.display = (what.checked)?'':'none';
} 
function showhide() {
  if (avatarz.style.display=='none') {
    avatarz.style.display = '';
    document.getElementById("checkbox").checked = true;
  }
  else {
    avatarz.style.display = 'none';
    document.getElementById("checkbox").checked = false;
  }
}
function add() {
  i = document.getElementById("count").value;
  i++;
  till = document.getElementById("add").innerHTML;
  document.getElementById("add").innerHTML += '<input type=\"text\" name=\"answer['+i+']\" class=\"input\"><br>'
  document.getElementById("count").value = i;
}
function jump() {
  var jump;
  jump = document.move.change.options[document.move.change.selectedIndex].value;
  if (jump!="current") { location = jump; }
}
function edit(id) {
  var hide = document.getElementById(id);
  hide.style.display='none';
  var edit = document.getElementById('edit'+id);
  edit.style.display='';
}
function hide(id) {
  var edited = document.getElementById('edit'+id).value;
  xmlHttp=GetXmlHttpObject()
  if (xmlHttp==null) {
    alert ("Browser does not support HTTP Request")
    return
  }
  var url="rename.php?id="+id+"&title="+edited;
  //xmlHttp.onreadystatechange = alert('YES!');
  xmlHttp.open("REQUEST",url,true)
  xmlHttp.send(null) 
  
  document.getElementById(id).innerHTML = edited;
  document.getElementById('edit'+id).style.display='none';
  document.getElementById(id).style.display='';
}
function GetXmlHttpObject() {
  var xmlHttp=null;
  try { xmlHttp=new XMLHttpRequest(); }
  catch (e) {
    try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }
    catch (e) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }
  }
  return xmlHttp;
} 
