var is_ie = 0;
var agt = navigator.userAgent.toLowerCase();
var is_major = parseInt(navigator.appVersion);
is_ie = (agt.indexOf("msie") != -1);
var is_opera = (agt.indexOf("pera") != -1);

var is_ie3  = (is_ie && (is_major < 4));
var is_ie4  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5") == -1) && (agt.indexOf("msie 6") == -1) && (agt.indexOf("msie 7") == -1) && (agt.indexOf("msie 8") == -1 && (agt.indexOf("msie 9") == -1)));
var is_ie6  = (is_ie && (agt.indexOf("msie 6") != -1)) && (agt.indexOf("msie 7") == -1) && (agt.indexOf("msie 8") == -1 && (agt.indexOf("msie 9") == -1));
var is_ie7  = (is_ie && (agt.indexOf("msie 7") != -1));
var is_ie5up  = (is_ie  && !is_ie3 && !is_ie4);
var is_gecko = (agt.indexOf("gecko") != -1);
var is_chrome = (agt.indexOf("chrome") != -1);
var hideables=0;
var hideable= new Array();
var saved_elements = {};

//window.onerror = noerrorinhere;

if (is_ie4)
{
  hol = function (element_id)
  {
    var element = eval(element_id);
    return element;
  }
  $ = function (element_id)
  {
    var element = eval(element_id);
    return element;
  }
}
else
{
  hol = function (element_id)
  {
    return document.getElementById(element_id);
  }
  $ = function (element_id)
  {
    return element = document.getElementById(element_id);
  }
}

$$ = function (element_id)
{
  if(typeof saved_elements[element_id] !== "undefined") return saved_elements[element_id];
  saved_elements[element_id] = $(element_id);
  return saved_elements[element_id];
}

//get all elements by classname (hack, y..)
function getElementsByClassName(class_name, target)
{
  if(target == undefined)target = document;

  var all_obj, ret_obj=new Array(), j=0, teststr;

  if(target.all)all_obj = target.all;
  else if(target.getElementsByTagName)all_obj = target.getElementsByTagName("*");

  for(i=0;i < all_obj.length;i++)
  {
    if(!all_obj[i].className)continue;
    if(all_obj[i].className.indexOf(class_name) != -1)
    {
      teststr = "," + all_obj[i].className.split(" ").join(",") + ",";
      if(teststr.indexOf("," + class_name + ",") != -1)
      {
        ret_obj[j] = all_obj[i];
        j++;
      }
    }
  }
  return ret_obj;
}


function noerrorinhere(err,url,line)
{

  /*
  if(is_ie5up && line!=277) // || is_gecko
  {
  var failurevar='[b]Javascript-Error Report[/b]*br*[b] Error: [/b]'+err+'*br*'+'[b] Line: [/b]'+line+'*br*'+'*br*[b] Page: [/b]'+url;
  hol('javascripterror').innerHTML='Auf dieser Seite ist ein JavaScript-Fehler aufgetreten, die Administration wurde benachrichtigt.';
  hol('failureiframe').src='send_javascripterror.php?val=$val&error='+failurevar;
  return true;
  }*/
  return true;
}


//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
//
function getPageScroll()
{
  if (self.pageYOffset)
  {
    return self.pageYOffset;
  }
  else if (document.documentElement && document.documentElement.scrollTop)
  { // Explorer 6 Strict
    return document.documentElement.scrollTop;
  }
  else if (document.body)
  {// all other Explorers
    return document.body.scrollTop;
  }
}

function gettraveltimejs(fn)
{

  time=hol('traveltimemod_'+fn).value;
  fx=hol('js_fx').value*1;
  fy=hol('js_fy').value*1;
  fz=hol('js_fz').value*1;

  //if(is_gecko)alert(hol('x_'+fn));
  dx=hol('x_'+fn).value*1;
  dy=hol('y_'+fn).value*1;
  dz=hol('z_'+fn).value*1;

  if(hol('javascripterror').innerHTML!='')hol('javascripterror').innerHTML='';
  //if(!isNaN(dx) && !isNaN(dy) && !isNAN(dz))
  //{
  if(dx=='')dx=-1;
  if(dy=='')dy=-1;

  if(fx==dx)time=time-1;
  if ((fx==dx && fy==dy))time=time-1; //Eigene Siedlung
  hol('traveltimeresult_'+fn).innerHTML='ETA '+ time;
  //}
  //else hol('javascripterror').innerHTML='Bitte nur Zahlen eingeben!';
}





function neighbor(x,y)
{
  if(x+1==y)return true;
  if(x-1==y)return true;
  if(x==6 && y==1)return true;
  if(x==1 && y==6)return true;
}

function resizedaframe(iframe)
{
  //iframe=hol('iframe');
  if(is_ie)
  {
    iframe.height=iframe.Document.body.scrollHeight+16;
    //alert();
  }
  else
  {
    iframe.height = 0;
    iframe.height = frameheight(iframe)+16;
    if(iframe.height == 0)setTimeout("resizedaframe(iframe)",50);
  }
  //if (iframe.Document && iframe.Document.body.scrollHeight)iframe.height = iframe.Document.body.scrollHeight+10;
}

function frameheight(frameid) {
  if (frameid.document && frameid.document.body && frameid.document.body.scrollHeight) {
    return frameid.document.body.scrollHeight;
  } else if (frameid.contentDocument){
    return frameid.contentDocument.body.scrollHeight;
  }
}


function addpoll(checkbox,val)
{
  if(checkbox.checked!=false)
  {
    hol('polldummy').innerHTML='<iframe src="forum_poll_create.php?val='+val+'&pid='+checkbox.value+'" onload="resizedaframe(this)" marginwidth="0" marginheight="0" frameborder="0" vspace="0" hspace="0" style="overflow:visible; width:100%; "></iframe>';
  }
  else
  {
    hol('polldummy').innerHTML='';
  }
}

function code(art,text)
{
  url=prompt(text,"http://");
  if(url!=null && url!="")add("["+art+"]"+url+"[/"+art+"]");
}
function codestart(art,text)
{
  url=prompt(text,text);
  if(url!=null && url!="")add("["+art+"="+url+"]");
}
function adv_code(art,text,text2)
{
  url=prompt(text,text);
  if(url!=null && url!="")add("["+art+"="+url+"]"+url+"[/"+art+"]");
  /*title=prompt(text,url);
  if(title!=null && title!="")add(title+"[/"+art+"]");
  else if(url!=null && url!="")add("[/"+art+"]");*/
}


function addcolor(text)
{
  colorvar=hol('color');
  colourvar=colorvar.value;
  add('[color=' + colourvar + ']','[/color]', text);

}

function gotosite(where)
{
  window.location.href = where;
}

function gat(field)
{
  if(is_ie)
  {
    selectedText = (document.formy) ? document.selection.createRange().text : document.getSelection();
    if (field.createTextRange) field.caretPos = document.selection.createRange().duplicate();
  }
  return true;
}


function add(begin, end, insert_text)
{
  if(end == undefined)
  {
    end = "";
  }
  if(insert_text == undefined)
  {
    insert_text = "";
  }
  var textfeld;

  textfeld = hol('post');

  // IE
  if (is_ie)
  {
    var selection = document.selection.createRange().text;
    if (!selection)
    {
      selection = insert_text;
    }
    textfeld.focus();

    document.selection.createRange().text = begin + selection + end;
  }
  else
  {
    var replaced = false;
    var start_pos = textfeld.selectionStart;
    var end_pos = textfeld.selectionEnd;
    if (end_pos - start_pos)
    {
      replaced = true;
    }
    var scroll_temp = textfeld.scrollTop;
    var selection = (textfeld.value).substring(start_pos, end_pos);
    if (!selection)
    {
      selection = insert_text;
    }
    var substitute;

    substitute = begin + selection + end;
    textfeld.value = textfeld
    .value.substring(0, start_pos) + substitute + textfeld.value.substring(end_pos, textfeld.value.length);
    textfeld.focus();
    //replace selection
    if (replaced)
    {
      var selection_temp = start_pos + (begin.length + selection.length + end.length);
      textfeld.selectionStart = selection_temp;
      textfeld.selectionEnd = selection_temp;
    }
    else
    {
      textfeld.selectionStart = start_pos + begin.length;
      textfeld.selectionEnd = start_pos + begin.length + selection.length;
    }
    textfeld.scrollTop = scroll_temp;
    // reposition cursor if possible
    if (textfeld.createTextRange)
    {
      textfeld.caretPos = document.selection.createRange().duplicate();
    }
  }
}


function hide(id)
{
  hol(id).style.display = 'none';

}
function show(id)
{

  if(!is_ie)hol(id).style.display = 'inline';
  else hol(id).style.display = 'block';
}
function showb(id)
{
  hol(id).style.display = 'block';
}

function ShipDescrWindow(id) {
  window.open('manual_shipdata_descriptions.php?val=$val&ship='+id, "","width=517,innerheight=356,height=376,menubar=no,resizeable=no,scrollbars=no,status=no,toolbar=no");
}


function hideall()
{
  for(i=1;i<=hideables;i++)hol(hideable[i]).style.display = 'none';
}

function goto_ask_site(where,msg)
{
  if(confirm(msg)==true)
  {
    //alert(where);
    window.location.href = where;
  }
}

function change(id)
{
  if(is_ie5up || is_gecko || is_opera)
  {
    var div = hol(id);
    if(div.style.display != 'block')
    {
      div.style.display = 'block';
    }
    else
    {
      div.style.display = 'none';
    }
  }
}

function changetd(id)
{
  if(is_ie5up || is_gecko || is_opera)
  {
    var div = hol(id);
    if(div.style.display != 'table-cell')
    {
      div.style.display = 'table-cell';
    }
    else
    {
      div.style.display = 'none';
    }
  }
}

function changetr(id)
{
  if(is_gecko || is_opera)
  {
    var div = hol(id);
    if(div.style.display != 'table-row')
    {
      div.style.display = 'table-row';
    }
    else
    {
      div.style.display = 'none';
    }
  }
  else change(id);
}


var tempX = 0;
var tempY = 0;
//if (!is_ie) document.captureEvents(event.MOUSEMOVE)
document.onmousemove = getMouse;

function getMouse(e)
{
  if (is_ie)
  {
    var body = (window.document.compatMode && window.document.compatMode == "CSS1Compat") ?
    window.document.documentElement : window.document.body || null;

    tempX = event.clientX + body.scrollLeft+1;
    tempY = event.clientY + body.scrollTop+1;
  }
  else
  {
    tempX = e.pageX+1;
    tempY = e.pageY+1;
  }
  return true;
}

// Correctly handle PNG transparency in Win IE 5.5 or higher.
// http://homepage.ntlworld.com/bobosola. Updated 02-March-2004

function correctPNG()
{

  for(var i=0; i<document.images.length; i++)
  {
    var img = document.images[i];
    var imgName = img.src.toUpperCase();

    if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
    {

      var imgID = (img.id) ? "id='" + img.id + "' " : "";
      var imgClass = (img.className) ? "class='" + img.className + "' " : "";
      var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
      var imgStyle = "display:inline;margin-top:0px;margin-left:0px;z-index:0;" + img.style.cssText;
      if (img.align == "left") imgStyle = "float:left;" + imgStyle;
      if (img.align == "right") imgStyle = "float:right;" + imgStyle;
      if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle;
      var strNewHTML = "<div " + imgID + imgClass + imgTitle + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";" + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" + "(src=\'" + img.src + "\', sizingMethod='scale');\"></div>";
      img.outerHTML = strNewHTML;
      i = i-1;
    }
  }
}
if(is_ie6 && !is_opera && !is_chrome)window.attachEvent("onload", correctPNG);




function changelinkbox(id)
{
  if(hideable[id]!=false)
  {

    if(is_ie5up || is_gecko || is_opera)
    {
      var div = hol(id);
      if(div.style.display == 'block')
      {
        div.style.display = 'none';
      }
      else
      {
        div.style.display = 'block';

        if(tempX-250>0)pos=tempX-240;
        else pos=tempX+10;
        if(pos<160)pos=160;
        if(!is_ie)
        {
          div.style.left=pos+"px";
          div.style.top=tempY+5+"px";
        }
        else
        {
          div.style.left=pos;
          div.style.top=tempY+5;
        }
      }
    }
  }
}
function getWindowWidth()
{
  if (is_ie)
  {
    return document.body.offsetWidth;
  }
  else
  {
    return window.innerWidth;
  }
}

function addInfoBox(item, id)
{
  var width = 0;
  if(item.offsetWidth == 0) width = (item.firstChild.offsetWidth + 10);
  else  width = (item.offsetWidth + 10);

  $(id).style.left = width + "px";
  item.appendChild($(id));
  $(id).style.display = 'block';

  if(getLeftPosOnPage(item) + width + $(id).offsetWidth > getWindowWidth())
  {
    $(id).style.left = "auto";
    $(id).style.right = (item.offsetWidth + 10) + "px";
    item.insertBefore($(id), item.firstChild);
  }
}

//thx to http://www.quirksmode.org/js/findpos.html
function getLeftPosOnPage (item)
{
  var curleft = 0;
  if (item.offsetParent)
  {
    do
    {
      curleft += item.offsetLeft;
    } while (item = item.offsetParent);
    return curleft;
  }
}

function showlinkbox(id)
{
  var div = hol(id);
  var pos;
  var temp_posY;
  div.style.display = 'block';

  temp_posY = tempY - div.offsetHeight + 15;
  if(temp_posY < 10) temp_posY = 10;

  if(is_gecko || is_opera)
  {
    if(tempX-250>0)pos=tempX-240;
    else pos=tempX+10;
    if(pos<160)pos=160;

    if(!is_ie)
    {
      div.style.left=pos+"px";
      div.style.top=temp_posY+15 + "px";
    }
    else
    {
      div.style.left=pos;
      div.style.top=temp_posY+15 + "px";
    }
  }
  else
  {
    if(tempX-250>0)pos=tempX-240;
    else pos=tempX+10;
    if(pos<160)pos=160;
    div.style.left=pos;
    div.style.top=temp_posY;
  }
}

function hidelinkbox(id)
{
  if(hideable[id]!=false)
  {
    if(is_ie5up || is_gecko || is_opera)
    {
      var div = hol(id);
      div.style.display = 'none';
    }
  }
}
function changeclicklinkbox(id)
{
  if(hideable[id]!=false)
  {
    hideable[id]=false;
    var div = hol(id);
    div.style.display = 'block';
    if(is_gecko || is_opera)
    {
      if(tempX-170>0)div.style.left=tempX-170 + "px";
      else div.style.left=tempX+10 + "px";
      div.style.top=tempY+15 + "px";
    }
    else
    {
      if(tempX-170>0)div.style.left=tempX-170;
      else div.style.left=tempX+10;
      div.style.top=tempY+15;
    }
  }
  else
  {
    hideable[id]=true;
    var div = hol(id);
    div.style.display = 'none';
  }
}

function changerow(id)
{
  if(is_gecko || is_opera)
  {
    var div = hol(id);

    if(!hol(id))return false;

    if(div.style.display != 'none')
    {
      div.style.display = 'none';
    }
    else
    {
      div.style.display = 'table-row';
    }
  }
  else
  {
    var div = hol(id);
    if(!div.style.display || div.style.display != 'none')
    {
      div.style.display = 'none';
    }
    else
    {
      div.style.display = 'block';
    }
  }
}

function changepmrow(id, val)
{

  var div = hol('msg'+id);
  if(is_gecko || is_opera)
  {
    if(div.style.display != 'none')
    {
      div.style.display = 'none';
    }
    else
    {
      div.style.display = 'table-row';
    }
  }
  else
  {
    if(!div.style.display || div.style.display != 'none')
    {
      div.style.display = 'none';
    }
    else
    {
      div.style.display = 'block';
    }
  }
  try
  {
    loadHTML("dynamic_data.html.php?val=" + val + "&get=changePMStatus&changePM="+id, hol('status'+id));
  }
  catch(e){} //doesnt matter, if that doesnt work out.

}
//special thx to Stuart Langridge (http://www.kryogenix.org/code/browser/sorttable/) for giving me the idea how to do this..
//although i rewrote it completely ;)
// - nukey, 22.01.05
var sortierspalte;

function sortieren(link)
{
  sortierspalte = link.parentNode.cellIndex;
  var table = getParent(link, 'TABLE');
  var dontsortit;
  var newRows = new Array();
  for (i=1;i<table.rows.length;i++)if(table.rows[i].className!='blue2')newRows[i-1]=table.rows[i];
  else {dontsortit=table.rows[i].cells[0].innerText; newRows[i-1]=table.rows[i]; }
  newRows.sort(sort_num);
  if(parseFloat(decomma(table.rows[1].cells[sortierspalte].innerText))-parseFloat(decomma(table.rows[table.rows.length-2].cells[sortierspalte].innerText))<0)newRows.reverse();
  for (i=0;i<newRows.length;i++)if(dontsortit!=newRows[i].cells[0].innerText)table.tBodies[0].appendChild(newRows[i]);
  for (i=0;i<newRows.length;i++)if(dontsortit==newRows[i].cells[0].innerText)table.tBodies[0].appendChild(newRows[i]);
}

function sort_num(a,b)
{
  var firstcell = parseFloat(decomma(a.cells[sortierspalte].innerText));
  var secondcell = parseFloat(decomma(b.cells[sortierspalte].innerText));
  if (isNaN(firstcell)) firstcell = 0;
  if (isNaN(secondcell)) secondcell = 0;
  return firstcell-secondcell;
}

function decomma(text)
{
  texty='';
  for(i=0;i<=text.length;i++)
  {
    if(!isNaN(text.charAt(i)))texty=texty+text.charAt(i);
  }
  return texty;
}

function getParent(el, pTagName)
{
  if (el == null) return null;
  else if (el.nodeType == 1 && el.tagName.toLowerCase() == pTagName.toLowerCase())	// Gecko bug, supposed to be uppercase
  return el;
  else
  return getParent(el.parentNode, pTagName);
}		//funny thing... until the nodeType is one, he steps through ^^ (and tagname=table, of course..)

function oeffnenmanual(what) {
  window.open("manual/?val="+"#"+what);
}
function oeffnenStory()
{
  //popup by efrait
  window.open("http://www.efrait.at/aquata/story/seite.html", "Story","width=600,innerheight=520,height=530,menubar=no,resizeable=no,scrollbars=no,status=no,toolbar=no");
}
function oeffnenanb() {
  window.open("http://www.efrait.at/aquata/anb/anb.html", "Fenster","width=700,height=750,scrollbars=yes");
}
function oeffnenANB() {
  window.open("http://www.efrait.at/aquata/anb/anb.html", "Fenster","width=700,height=750,scrollbars=yes");
}
function oeffnenBC(val) {
  if(val=="")val="&";
  window.open("manual_battlecalc?val="+val, "Kampfrechner","width=900,height=800,scrollbars=yes");
}
function oeffnenBC2(val) {
  if(val=="")val="&";
  window.open("manual_battlecalc_V2?val="+val, "Kampfrechner 2","width=900,height=800,scrollbars=yes");
}
function mainPageSetScanActive(scanpicid,scancost,scanname)
{
  hol('scantypelabel').innerHTML=scanname;
  hol('scancost').innerHTML=scancost;
  scanpic=hol('scanpic'+scanpicid);

  for(i=2;i<=6;i++)
  {
    otherscanpic=hol('scanpic'+i);
    if(!otherscanpic)continue;
    hol('go_'+i).value='';
    if(otherscanpic.src.substring(otherscanpic.src.length-11, otherscanpic.src.length) == "_active.jpg")
    {
      srcstring=otherscanpic.src.substring(0, otherscanpic.src.length-11) + "_normal.jpg";
      otherscanpic.src=srcstring;
    }

  }
  if(scanpic.src.substring(scanpic.src.length-11, scanpic.src.length) == "_normal.jpg")
  {
    activepic=scanpic.src.substring(0, scanpic.src.length-11) + "_active.jpg";
    scanpic.src=activepic;
    hol('go_'+scanpicid).value='true';
  }
}

function changeCsName()
{
  var name=hol("csname").innerHTML;
  hol("csname").innerHTML="<input type=\"text\" name=\"csname\" class=\"input\" value=\""+name+"\">";
  hol("changenamelink").innerHTML="";

}

function changeName()
{
  var name=hol("change_name").innerHTML;
  hol("change_name").innerHTML="<input type=\"text\" name=\"change_name\" class=\"input\" value=\""+name+"\">";
  hol("change_name_link").innerHTML="";

}

function switch_fightreport_rows(uniqueid)
{
  swapdata('yourslink'+uniqueid,'yoursnonlink'+uniqueid);
  swapdata('alllink'+uniqueid,'allnonlink'+uniqueid);
  for(i=1;i<=13;i++)
  {
    changerow('alonerows'+uniqueid+i);
    changerow('allrows'+uniqueid+i);
  }

}
function swapdata(id_1,id_2)
{
  var temp=hol(id_1).innerHTML;
  hol(id_1).innerHTML=hol(id_2).innerHTML;
  hol(id_2).innerHTML=temp;
}

//	Asynchronius data-loading

var count=0;
var selId=0;

// Eintrag einer Dropdown hinzuf�gen
function appendSelection(value, text, target)
{
  var opt = document.createElement('option');
  opt.text = text;
  opt.value = value;

  try { target.add(opt, null); } // non IE
  catch(e) { target.add(opt); } // IE
}

// Dropdownbox l�schen
function clearSelect(target)
{
  for (i = target.length - 1; i>=0; i--)
  target.remove(i);
}

// Eintr�ge laden (AJAX)
function loadDataFromXML(target, xml)
{
  clearSelect(target);
  loadXML(xml, target);
}

// load an xml - file
function loadXML(filename, target)
{
  req = getAsynchRequest();

  req.onreadystatechange = function()
  {
    getmessage(target)
  };

  if(!req) return false;
  req.open('GET', filename, true);
  req.send(null);
}

function create_on_top_request(filename, what, width)
{
  if(width == undefined) width = 356;
  backdiv = document.createElement('div');
  backdiv.style.backgroundColor = '#000000';
  backdiv.style.height = document.body.scrollHeight;
  backdiv.style.width = document.body.scrollWidth;
  backdiv.style.position = 'absolute';
  backdiv.style.left = '0px';
  backdiv.style.top = '0px';
  backdiv.style.zIndex = 5;
  backdiv.style.verticalAlign = 'middle';
  backdiv.id = 'backdiv';

  topdiv = document.createElement('div');
  topdiv.style.height = document.body.scrollHeight;
  topdiv.style.width = document.body.scrollWidth;
  topdiv.style.position = 'absolute';
  topdiv.style.left = '0px';
  topdiv.style.top = '0px';
  topdiv.style.zIndex = 6;
  topdiv.style.verticalAlign = 'middle';
  topdiv.id = 'topdiv';


  setOpacity(backdiv, 0.8);


  prependElement(backdiv, hol('contentTD'));
  prependElement(topdiv, hol('contentTD'));


  topdiv.innerHTML = "<div class=\"tablecontent\" id=\"innertopdiv\" style=\"position:absolute; width:"+width+"; left:" + (getWindowWidth() - width)/2 + ";" + " top:" + Math.floor(getPageScroll() + getWindowHeight()/2 - 160) +";\"><div class=\"tabletitle\"><table width=\"100%\"><tr><td>" + what + "</td><td><a href=\"JavaScript:close_on_top_request('backdiv', 'topdiv');\">Schliessen</a></td></tr></table></div><div class=\"tablecontent_content\" style=\"height:auto;\" id=\"top_inner_content\" >Lade...</div>";

  //
  // when experiencing additional problems with the pos, we can use this too:
  // #innertopdiv
  // {
  //   top: expression(document.body.scrollTop - this.offsetHeight + this.offsetHeight + (getWindowHeight() - 340)/2);
  // }


  loadHTML(filename, hol('top_inner_content'));
}

// getheight & width taken from http://www.howtocreate.co.uk/tutorials/javascript/browserwindow with many thanks!
function getWindowHeight()
{
  var myWidth = 0, myHeight = 0;
  if( typeof(window.innerWidth) == 'number' )
  {
    //Non-IE
    return window.innerHeight;
  }
  else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    return document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    return document.body.clientHeight;
  }
}

function getWindowWidth()
{
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' )
  {
    //Non-IE
    return window.innerWidth;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    return document.documentElement.clientWidth;

  }
  else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
  {
    //IE 4 compatible
    return document.body.clientWidth;
  }
}
function close_on_top_request(div1, div2)
{
  div1_obj = hol(div1);
  div1_obj.parentNode.removeChild(div1_obj);
  div2_obj = hol(div2);
  div2_obj.parentNode.removeChild(div2_obj);
}

function update_with_data(filename, content_div)
{
  if(content_div)content_div.parentNode.parentNode.removeChild(content_div.parentNode);
  if(hol('backdiv'))hol('backdiv').parentNode.removeChild(hol('backdiv'));
  if(hol('topdiv'))hol('topdiv').parentNode.removeChild(hol('topdiv'));

  loadHTML(filename, hol('javascripterror'));
}

function update_and_close_fullpage(filename, content_div)
{
  if(hol('backdiv'))hol('backdiv').parentNode.removeChild(hol('backdiv'));
  if(hol('topdiv'))hol('topdiv').parentNode.removeChild(hol('topdiv'));

  loadHTML(filename, content_div);
}

function delete_pm(filename, content_div)
{
  var title = hol('title' + content_div.id);

  if(title)title.parentNode.removeChild(title);

  loadHTML(filename, content_div);

}


function delete_and_close_fullpage(filename, content_div)
{
  if(hol('backdiv'))hol('backdiv').parentNode.removeChild(hol('backdiv'));
  if(hol('topdiv'))hol('topdiv').parentNode.removeChild(hol('topdiv'));

  var title = hol('title' + content_div.id);

  if(title)title.parentNode.removeChild(title);

  loadHTML(filename, content_div);

}

function sendPMFormData(filename, result_div, status_element)
{
  elements = new Array();

  form = hol('dynamic_form');

  query = "";

  if(hol('pmtarget'))
  {
    query += hol('pmtarget').name + "=" + escape(hol('pmtarget').value) + "&";
  }



  for (var i=0; i < form.length; i++)
  {
    tempvalue = form.elements[i].value;

    if(form.elements[i].type == "checkbox")
    {
      if(!form.elements[i].checked)continue;
      else tempvalue = form.elements[i].value;
    }

    if(form.elements[i].type == "radio")
    {
      if(!form.elements[i].checked)continue;
      else  tempvalue = form.elements[i].value;
    }

    query += form.elements[i].name + "=" + escape(tempvalue) + "&";
  }

  req = getAsynchRequest();
  req.open('POST', filename, true);
  req.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=ISO-8859-1");
  req.setRequestHeader("Content-length", query.length);
  req.setRequestHeader("Connection", "close");
  req.send(query);

  req.onreadystatechange = function()
  {
    getinnerHTML(hol('javascripterror'))
    if(status_element)status_element.innerHTML = "Beantwortet";
  };



  if(result_div)result_div.parentNode.parentNode.removeChild(result_div.parentNode);
  if(hol('backdiv'))hol('backdiv').parentNode.removeChild(hol('backdiv'));
  if(hol('topdiv'))hol('topdiv').parentNode.removeChild(hol('topdiv'));


  //return false;
}
function sendFormData(filename, result_div)
{
  elements = new Array();

  form = hol('dynamic_form');

  query = "";

  if(hol('pmtarget'))
  {
    query += hol('pmtarget').name + "=" + escape(hol('pmtarget').value) + "&";
  }

  for (var i=0; i < form.length; i++)
  {
    tempvalue = form.elements[i].value;

    if(form.elements[i].type == "checkbox")
    {
      if(!form.elements[i].checked)continue;
      else tempvalue = form.elements[i].value;
    }

    if(form.elements[i].type == "radio")
    {
      if(!form.elements[i].checked)continue;
      else  tempvalue = form.elements[i].value;
    }


    query += form.elements[i].name + "=" + escape(tempvalue) + "&";
  }

  req = getAsynchRequest();
  req.open('POST', filename, true);
  req.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=ISO-8859-1");
  req.setRequestHeader("Content-length", query.length);
  req.setRequestHeader("Connection", "close");
  req.send(query);

  req.onreadystatechange = function()
  {
    getinnerHTML(hol('javascripterror'))
  };



  if(result_div)result_div.parentNode.parentNode.removeChild(result_div.parentNode);
  if(hol('backdiv'))hol('backdiv').parentNode.removeChild(hol('backdiv'));
  if(hol('topdiv'))hol('topdiv').parentNode.removeChild(hol('topdiv'));


  //return false;
}


function sendFormDataSaveToTarget(form, filename, result_div)
{
  elements = new Array();

  form = hol(form);

  query = "";


  for (var i=0; i < form.length; i++)
  {
    tempvalue = form.elements[i].value;

    if(form.elements[i].type == "checkbox")
    {
      if(!form.elements[i].checked)continue;
      else tempvalue = form.elements[i].value;
    }

    if(form.elements[i].type == "radio")
    {
      if(!form.elements[i].checked)continue;
      else  tempvalue = form.elements[i].value;
    }


    query += form.elements[i].name + "=" + escape(tempvalue) + "&";
  }

  req = getAsynchRequest();
  req.open('POST', filename, true);
  req.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=ISO-8859-1");
  req.setRequestHeader("Content-length", query.length);
  req.setRequestHeader("Connection", "close");
  req.send(query);

  req.onreadystatechange = function()
  {
    getinnerHTML(result_div);
  };
}

// load a simple html
function loadHTML(filename, target)
{
  req = getAsynchRequest();

  if(target!=null)
  {
    req.onreadystatechange = function()
    {
      getinnerHTML(target)
    };
  }

  if(!req) return false;
  req.open('GET', filename, true);
  req.send(null);
}



// insert the html
function getinnerHTML(target)
{
  if (req.readyState == 4 && req.status == 200)
  {
    if(req.responseText != "")target.innerHTML = req.responseText;
  }
}
// insert the xml
function getmessage(target)
{
  if (req.readyState == 4 && req.status == 200)
  {
    data=req.responseXML.getElementsByTagName("data");
    for(i=0;i<data.length;i++)
    {
      id=parseInt(data[i].getElementsByTagName("id")[0].firstChild.nodeValue, 10);
      Name=data[i].getElementsByTagName("name")[0].firstChild.nodeValue;
      appendSelection(id, Name, target);
    }
    reselect(target);
  }
}

// selects the first entry.
function reselect(target)
{
  target.options[0].selected = true;
}
                                      
//returns a new object for an asynch request, depending on the browser.
function getAsynchRequest()
{                                      
  if (window.XMLHttpRequest)
  { // moz
    return new XMLHttpRequest();
  }
  else if (window.ActiveXObject)
  { // ie
    try
    {
      return new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e)
    {
      try
      {
        return new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch (e)
      {
        try
        {
          return new ActiveXObject("Microsoft.XMLDOM");
        }
        catch (e)
        {
        try
        {
          var xml = document.createElement("xml");
          document.body.appendChild(xml);    
          
          xml.open = function (method, target, dummy)
          {
            //method is not important; we will append the content anyway
            this.src_to_open = target;
            //the dummy isnt needed too..
          };
          
          xml.send = function (post_data)
          {
            this.src = this.src_to_open + '&' + post_data;
          }      
          
          return xml;

        }
        catch (e)
        {
          return false;
          hol('javascripterror').innerHTML="Die Ausf�hrung von ActiveX - Objekten wurde deaktiviert. Bitte aktivieren sie diese oder f�gen sie http://aquarion.org zu ihren vertrauensw�rdigen Websites hinzu!";
        }
        }
      }
    }
  }
}

/**
* suggest boxes
*/


function tryUserNameSuggestBox(inputname, spanname, val)
{
  input=hol(inputname);
  if(input.value.length >= 3)
  {
    loadXMLAsArray('dynamic_data.xml.php?val=' + val + '&get_users_starting_with=' + input.value, 'insertIntoSuggestionBox(\''+spanname+'\', \''+inputname+'\',');
  }
}

function tryUserNameSuggestBoxWithSeparators(inputname, spanname, val)
{
  input=hol(inputname);
  text = input.value;
  var previous_text = "";
  var names =  text.split(";");
  searchtext = names[names.length-1];

  for(i=0; i < names.length - 1; i++)previous_text += names[i]+";";
  if(searchtext.length >= 3)
  {
    loadXMLAsArray('dynamic_data.xml.php?val=' + val + '&get_users_starting_with=' + searchtext, 'insertIntoSuggestionBoxWithSeparators(\''+spanname+'\', \''+inputname+'\',\''+ previous_text+'\',');
  }
}

function tryUseFirstPossibility(e, inputname, spanname)
{
  if(!e)e = window.event;
  var keycode = e.keyCode? e.keyCode : e.charCode;

  if(keycode == 13)
  {
    var previous_text = "";
    var names =  text.split(";");
    for(i=0; i < names.length - 1; i++)previous_text += names[i]+";";

    suggestdiv = hol(spanname);
    suggestbox = suggestdiv.childNodes[0];

    input.value = previous_text + suggestbox.innerHTML+";";
    hide(spanname);
  }
}

function insertIntoSuggestionBoxWithSeparators(spanname, inputname, previous_text, userarray, event)
{

  insert_html="";
  for(key in userarray)
  {
    insert_html += "<div class='suggestions' id=suggestID_" + key + " onmousedown=\"suggestBoxWithSeparatorsMouseDown(" + key +", '"+spanname+"', '"+inputname+"' , '"+previous_text+"');\">" + userarray[key] +'</div>';
  }
  hol(spanname).innerHTML = insert_html;
  show(spanname);
}

function suggestBoxWithSeparatorsMouseDown(id, spanname, inputname, previous_text)
{
  input = hol(inputname);
  suggestbox = hol('suggestID_'+id);
  input.value = previous_text + suggestbox.innerHTML+";";
  hide(spanname);
}

function insertIntoSuggestionBox(spanname, inputname, userarray)
{
  insert_html="";
  for(key in userarray)
  {
    insert_html += "<div class='suggestions' id=suggestID_" + key + " onmousedown=\"suggestBoxMouseDown(" + key +", '"+spanname+"', '"+inputname+"');\">" + userarray[key] +'</div>';
  }
  hol(spanname).innerHTML = insert_html;
  show(spanname);
}

function suggestBoxMouseDown(id, spanname, inputname)
{
  input=hol(inputname);
  suggestbox=hol('suggestID_'+id);
  input.value=suggestbox.innerHTML;
  hide(spanname);
}




// load the xml
function loadXMLAsArray(filename, function_to_call)
{
  req = getAsynchRequest();

  req.onreadystatechange = function()
  {
    getXMLAsArray(function_to_call)
  };


  if(!req) return false;
  req.open('GET', filename, true);
  req.send(null);
}
 
// get the xml
function getXMLAsArray(function_to_call)
{
  if (req.readyState == 4 && req.status == 200)
  {
    temporary_data_array = new Array;
    data=req.responseXML.getElementsByTagName("data");
    for(i=0;i<data.length;i++)
    {
      id=parseInt(data[i].getElementsByTagName("id")[0].firstChild.nodeValue, 10);
      Name=data[i].getElementsByTagName("name")[0].firstChild.nodeValue;
      temporary_data_array[id] = Name;
    }
    if(function_to_call!="")eval(function_to_call + 'temporary_data_array' + ");");
  }
}

function addElement(element, target)
{
  try { target.appendChild(element, null); } // non IE
  catch(e) { target.appendChild(element); } // IE
}

function prependElement(element, target)
{
  try { target.appendChild(element, null); } // non IE
  catch(e) { target.appendChild(element); } // IE
}

function setOpacity(element, opacvalue)
{
  if(is_ie)element.style.filter = 'alpha(opacity='+opacvalue*100+')';
  else element.style.opacity = opacvalue;
}

function addto(element_name, text)
{
  hol(element_name).value += text;
}

function addJournalEntry(entry)
{
  add(entry);
}

function changePMTarget(targetspec)
{
  hide('pmtarget_normal');
  hide('pmtarget_send_to_allyadmins');
  hide('pmtarget_div');
  if(hol('pmtarget_' + targetspec))show('pmtarget_' + targetspec);
  else
  {
    show('pmtarget_div');
    hol('pmtarget_div').innerHTML = targetspec;
  }
}

function getJournalIfNotLoaded(val)
{
  if(hol('journal_entry_div').firstChild.tagName=="A")
  {
    loadHTML('dynamic_data.html.php?val=' + val + '&get=journal_entries', hol('journal_entry_div'));
  }
}

function checkSelects(select)
{
  form = select.form;
  value = select.value;
  toreplaceelement = select;
  shipchosen = new Array();
  shipchosen[value] = true;

  for(i=0; i < form.length; i++)
  {
    element = form.elements[i];
    if(element.tagName != "SELECT")continue;
    if(element.name.charAt(0) != select.name.charAt(0))continue;
    if(element.value == value && element != select) toreplaceelement = element;
    shipchosen[element.value] = true;
  }

  for(i = 1; i <= 12; i++)
  {
    if(!shipchosen[i] && toreplaceelement!=select)
    {
      toreplaceelement.selectedIndex = i;
    }
  }
}

/**
fleet-function, insert the needed number of points to the field
*/
function insertMaxNumber(num)
{
  num *= num < 0 ? -1 : 1;
  if(hol('number_1').value=="")hol('number_1').value = num + "p";
  else if(hol('number_2').value=="")hol('number_2').value = num + "p";
  else if(hol('number_3').value=="")hol('number_3').value = num + "p";
}

// inspired by http://www.quirksmode.org/blog/archives/2005/10/_and_the_winner_1.html.
//first rewritten to allow capture, 15.01.2008
//now rewritten to bypass the following problem:
//the functions got too long when anonymous - even the comments where taken as indicators in the array, it seemed..
//(think of: obj["on"+type+function(){sdfsdlfkn;//this is some sample comment lol}] = ...
//dont know exactly if this code got executed for its return-value or just used as string - bad one either way.
//nukey, 15.01.2008
if (!is_ie)
{
  //ff, compatible
  addEvent = function(obj, type, fn, capture)
  {
    if(typeof(capture) == "undefined")capture = false;
    obj.addEventListener(type, fn, capture);
  };

  //removes the event listener - the easy way. :P
  removeEvent = function ( obj, type, fn, capture )
  {
    if(typeof(capture) == "undefined")capture = false;
    obj.removeEventListener( type, fn, capture );
  };
}

if (is_ie)
{
  //adds an event.. the hard, but ie-compliant way
  addEvent = function(obj, type, fn, capture)
  {
    if(typeof(capture) == "undefined")capture = false;
    if(typeof(obj["on"+type+"temp"]) == "undefined")obj["on"+type+"temp"] = [];
    obj["on"+type+"temp"][obj["on"+type+"temp"].length] = fn;

    obj["on"+type] = function()
    {
      for(i in obj["on"+type+"temp"])
      {
        obj["on"+type+"temp"][i].call(obj);
      }
    }
    if(capture)obj.setCapture();
  };

  //removes the event listener - the hard, but ie-compliant way
  removeEvent = function ( obj, type, fn, capture )
  {
    if(typeof(capture) == "undefined")capture = false;

    var found = 0;
    for(i in obj["on"+type+"temp"])
    {
      if(obj["on"+type+"temp"] == fn)obj["on"+type+"temp"] = null;
      else if(typeof(obj["on"+type+"temp"]) == "function")found++;
    }
    if(found != 0)obj["on"+type+"temp"] = null;
    obj["on"+type] = null;

    if(capture)obj.releaseCapture();
  };
}


function highlightRowAndCol(thistable, color)
{
  if(typeof (highlightRowAndCol.tables) === "undefined")highlightRowAndCol.tables = [];
  var table = thistable.id;
  highlightRowAndCol.tables[table] = [];
  highlightRowAndCol.tables[table].color = color;
  trs = thistable.getElementsByTagName("tr");

  for(var i=0; i < trs.length;i++)
  {
    highlightRowAndCol.tables[table][i] = [];
    highlightRowAndCol.tables[table][i].tr = trs[i];
    tds = trs[i].getElementsByTagName("td");

    for(var j = 0; j < tds.length; j++)
    {
      highlightRowAndCol.tables[table][i][j] = tds[j];
      tds[j].i = i;
      tds[j].j = j;
      tds[j].over = function(){highlightRowAndCol.highlight(table, this.i, this.j)};
      tds[j].out = function(){highlightRowAndCol.unlight(table, this.i, this.j)};
      addEvent(tds[j], "mouseover",  function(){this.over()});
      addEvent(tds[j], "mouseout", function(){this.out()});
    }
  }
}

highlightRowAndCol.highlight = function(table, i, j)
{                    
  highlightRowAndCol.tables[table][i].tr.style.backgroundColor = highlightRowAndCol.tables[table].color;
  for(i_temp = 0; i_temp < i; i_temp++) highlightRowAndCol.tables[table][i_temp][j].style.backgroundColor = highlightRowAndCol.tables[table].color;
};

highlightRowAndCol.unlight = function(table, i, j)
{                    
  highlightRowAndCol.tables[table][i].tr.style.backgroundColor = "transparent";
  for(i_temp = 0; i_temp < i; i_temp++) highlightRowAndCol.tables[table][i_temp][j].style.backgroundColor = "transparent";
};
                                    
function actualizeChatScroll(height)
{
  $('chatcontainer').scrollTop += height;
}                             

function reformat_number(number)
{
  var output = "";
  output = "" + number;
  if(number > 1000)
  {
   output = "" + reformat_number (Math.floor(number/1000));
   output += "." + min_3_zeros(number - Math.floor(number/1000)*1000);  
  }
  return output;
}

function min_3_zeros(number)
{                                          
  if(number < 10) return ("00" + number);
  if(number < 100) return ("0" + number);
  else return number;
}
function refresh_time()
{
    var seconds=document.getElementById('seconds').innerHTML;
    var minutes=document.getElementById('minutes').innerHTML;
    var hours  =document.getElementById('hours').innerHTML;
    seconds++;
    if(seconds>=60)
    {
        minutes++;
        seconds=0;
        if(minutes<10) minutes="0"+minutes;
    }
    if(minutes>=60)
    {
        hours++;
        minutes="00";
    }
    if(seconds<10) seconds="0"+seconds;
    document.getElementById('hours').innerHTML=hours;
    document.getElementById('minutes').innerHTML=minutes;
    document.getElementById('seconds').innerHTML=seconds;
    window.setTimeout("refresh_time();", 1000);
}



function triggerSearchBox(inputname, spanname, val)
{
  input=hol(inputname);
  if(input.value.length >= 3)
  {
    loadXMLAsArray('dynamic_data.xml?val=' + val + '&get_info_about=' + input.value, 'insertIntosearchBoxResult(\''+spanname+'\'');
  }
}

function insertIntosearchBoxResult(spanname, userarray)
{
  insert_html="";
  for(key in userarray)
  {
    insert_html += "<div class='suggestions' id=suggestID_" + key + " onmousedown=\"searchBoxResultMouseDown(" + key +", '"+spanname+"');\">" + userarray[key] +'</div>';
  }
  hol(spanname).innerHTML = insert_html;
  show(spanname);
}

function searchBoxResultMouseDown(id, spanname)
{
  input=hol(inputname);
  suggestbox=hol('suggestID_'+id);
  input.value=suggestbox.innerHTML;
  hide(spanname);
}