﻿var header = forum;

if(forumID!='') {
forumID = forumID.substring(0, forumID.length-1);
forumID = parseInt(forumID)+1;
if(forumID>1) header += '&nbsp;&raquo;&nbsp;side&nbsp;' + forumID;
}

function showPage(x) {
  if(x>0) {
  location.href = "forum.aspx?id=" + x + "1";
  }
  else {
  location.href = "forum.aspx";
  }
}

function setButton() {
var thisID = forumID;
if(thisID=='') thisID = '1';
var navButton = 'b' + thisID;
if(document.getElementById(navButton)) document.getElementById(navButton).style.color = 'rgb(229,27,36)';
}

function goBack() {
  var previousPage = document.referrer;
  if(previousPage.indexOf("forum.aspx?thread=")==-1) {
  location.href = 'javascript:history.back()';
  }
  else {
  location.href = 'forum.aspx';
  }
}

function textLimit(field) {
  if(field.value.length>5121) {
  alert('Max. 5.000 tegn');
  field.value = field.value.substring(0, 5120);
  }
  if((!is_ie6)&&(!is_opera)) {
  field.style.height = field.scrollHeight + 'px';
  }
}

function trim(str) {
return( (""+str).replace(/^\s*([\s\S]*\S+)\s*$|^\s*$/,'$1') );
}

function correct(str) {
str = str.replace(new RegExp('\r\n','g'), ' ');
str = str.replace(new RegExp('    ','g'), ' ');
str = str.replace(new RegExp('   ','g'), ' ');
str = str.replace(new RegExp('  ','g'), ' ');
return str;
}

function checkForm(form) {
  var initiate = true;
  if(threadID=='') {
    form.head.value = trim(form.head.value);
    if(form.head.value=='') {
    alert('Indtast emne');
    form.head.focus();
    initiate = false;
    }
  }
  if(!initiate) {
  return false;
  }
  var proceed = true;
  form.name.value = trim(form.name.value);
  form.text.value = correct(form.text.value);
  form.text.value = trim(form.text.value);
  if(form.name.value=='') {
  alert('Indtast afsender');
  form.name.focus();
  proceed = false;
  }
  else if(form.text.value=='') {
  form.text.focus();
  proceed = false;
  }
  if(!proceed) {
  return false;
  }
  if(threadID=='') {
  document.getElementById("forumcontrol").innerHTML = '<span class="feedback">Vent mens emne oprettes...</span>';
  }
  else {
  document.getElementById("forumcontrol").innerHTML = '<span class="feedback">Vent mens indlæg sendes...</span>';
  }
  return true;
}

function setFocus() {
window.clearTimeout(Id);
document.forms[0].elements[0].focus();
}

function updateData(postID) {
  if(document.getElementById("formarea").innerHTML=='') {
    var strForm = '<form action="forumupdate.aspx" method="post" onsubmit="return checkForm(this)"><table class="type2" cellspacing="0">';
    if(postID==0) {
    strForm += '<tr><td style="padding-left:0px;padding-top:4px">Nyt emne</td><td><input name="head" type="text" class="userinput" style="width:300px" value="" maxlength="64" /></td></tr>';
    strForm += '<tr><td style="padding-left:0px;padding-top:4px">Afsender</td><td><input name="name" type="text" class="userinput" style="width:300px" value="" maxlength="64" /></td></tr>';
    strForm += '<tr><td style="padding-left:0px;padding-top:4px">Skriv oplæg&nbsp;</td><td><textarea name="text" style="width:300px" onkeyup="textLimit(this.form.text)"></textarea><input type="hidden" name="item" value="' + postID + '" /></td></tr>';
    }
    else {
    strForm += '<tr><td style="padding-left:0px;padding-top:4px">Afsender</td><td><input name="name" type="text" class="userinput" style="width:300px" value="" maxlength="64" /></td></tr>';
    strForm += '<tr><td style="padding-left:0px;padding-top:4px">Skriv indlæg&nbsp;</td><td><textarea name="text" style="width:300px" onkeyup="textLimit(this.form.text)"></textarea><input type="hidden" name="item" value="' + postID + '" /></td></tr>';
    }
    strForm += '<tr><td></td><td id="forumcontrol" style="padding-top:10px;padding-bottom:20px"><input type="submit" class="btn" value="Send" onfocus="this.blur()" /></td></tr>';
    strForm += '</table></form>';
    document.getElementById("formarea").innerHTML = strForm;
    window.scrollTo(0,0);
    if((!is_ie6)&&(!is_opera)) {
    document.forms[0].text.style.height = document.forms[0].text.scrollHeight + 'px';
    document.forms[0].text.style.overflowY = 'hidden';
    document.forms[0].text.style.overflowX = 'auto';
    }
    Id = window.setTimeout("setFocus()",1);
  }
  else {
  window.location.reload();
  }
}