function FormatNumber(num, decpoint, sep){
   if((arguments.length==2)||(arguments.length==1)) sep = ',';
   if(arguments.length==1) decpoint = '.';
   num = num.toString();
   a = num.split(decpoint);
   x = a[0];
   y = a[1];
   z = '';
   if(typeof(x)!='undefined'){
      for(i=x.length-1;i>=0;i--) z += x.charAt(i);
      z = z.replace(/(\d{3})/g, "$1" + sep);
      if(z.slice(-sep.length)==sep) z = z.slice(0, -sep.length);
      x = '';
      for(i=z.length-1;i>=0;i--) x += z.charAt(i);
      if((typeof(y)!='undefined')&&(y.length>0)) x += decpoint + y;
   }
   return x;
}

function SwitchMenu(obj){ 
   if(document.getElementById){ 
   var el = document.getElementById(obj); 
   var ar = document.getElementById("masterdiv").getElementsByTagName("span"); 
      if(el.style.display != "block"){
         for(var i=0; i<ar.length; i++){ 
            if(ar[i].className=="submenu")
            ar[i].style.display = "none"; 
         } 
         el.style.display = "block"; 
      }else{ 
         el.style.display = "none"; 
      } 
   } 
}

function selectall(form){
   for(var i=0; i<document.getElementById(form).elements.length; i++){
      var e = document.getElementById(form).elements[i];
      if((e.type=="checkbox")){
         e.checked = (document.getElementById(form).all.checked) ? true : false;
      }		
   }
}

function confirmIT(link, text){
   if(window.confirm(text) == true) document.location.href = link;
}

function htmlspecialchars(text){
   text=text.replace(/&/gi, "&amp;");
   text=text.replace(/</gi, "&lt;");
   text=text.replace(/>/gi, "&gt;");
   text=text.replace(/\"/gi, "&quot;");
   text=text.replace(/'/gi, "&#039;");
   return text;
}
function nl2br(text){
   text=text.replace(/\n/gi, "<br />");
   return text;
}

function showmenu(elmnt){
   document.getElementById(elmnt).style.visibility="visible";
}
function hidemenu(elmnt){
   document.getElementById(elmnt).style.visibility="hidden";
}

function wtbcodes(aTag, eTag, tForm, tElement,ynPrompt){
   var input = document.forms[tForm].elements[tElement];
   input.focus();
   if(typeof document.selection != 'undefined'){
      var range = document.selection.createRange();
      var insText = range.text;
      if(aTag == '[url]'){
         var tInpuu = prompt("URL:", "http://");
         if(tInpuu){
            if(tInpuu != 'http://'){
               var tInput = prompt("Text:", insText);
               aTag = '[url=' + tInpuu + ']';
               if(!tInput){
                  tInput = tInpuu;
               }
            }else return;
         }else return;
      }else{
         if(aTag == '[email]'){
            var tInpuu = prompt("eMail:", "");
            if(tInpuu){
               var tInput = prompt("Text:", insText);
               aTag = '[email=' + tInpuu + ']';
               if(!tInput){
                  tInput = tInpuu;
               }
            }else return;
         }else{
            if(ynPrompt != 'no'){
               var tInput = prompt("Text:", insText);
               if(!tInput) return;
            }else{
              var tInput = '';
            }
         }
      }
      range.text = aTag + tInput + eTag;
      range = document.selection.createRange();
      if(insText.length == 0){
         range.move('character', -eTag.length);
      }else{
         range.moveStart('character', aTag.length + insText.length + eTag.length);      
      }
         range.select();
   }else if(typeof input.selectionStart != 'undefined'){
      var start = input.selectionStart;
      var end = input.selectionEnd;
      var insText = input.value.substring(start, end);
      input.value = input.value.substr(0, start) + aTag + insText + eTag + input.value.substr(end);
      var pos;
      if(insText.length == 0){
         pos = start + aTag.length;
      }else{
         pos = start + aTag.length + insText.length + eTag.length;
      }
      input.selectionStart = pos;
      input.selectionEnd = pos;
   }else{
      var pos;
      var re = new RegExp('^[0-9]{0,3}$');
      while(!re.test(pos)){
         pos = prompt("Einfügen an Position (0.." + input.value.length + "):", "0");
      }
      if(pos > input.value.length){
         pos = input.value.length;
      }
      var insText = prompt("Bitte geben Sie den zu formatierenden Text ein:");
      input.value = input.value.substr(0, pos) + aTag + insText + eTag + input.value.substr(pos);
   }
}

var blinkColTbl = new Array();
blinkColTbl[0] = "black";
blinkColTbl[1] = "silver";
var blinkTimeout = 1000;

function blinky(){
   var blinkTimeout = 10000;
   blink();
}

function zucki(){
   var blinkTimeout = 20000;
   blink();
}

var blinkIdx = 0;

function blink(){
   if((document.all)&&(document.all.blink)){
      blinkIdx = (blinkIdx+=1) % 2;
      var color = blinkColTbl[blinkIdx];
      if(document.all.blink.length){
         for(i=0;i<document.all.blink.length;i++) document.all.blink[i].style.color=color;
      }else document.all.blink.style.color=color;
      setTimeout("blink();" , blinkTimeout);
   }
}

function HexArray(n){
   this.length = n
   for(i=0; i<10; i++) this[i] = i
   this[10] = "A"
   this[11] = "B"
   this[12] = "C"
   this[13] = "D"
   this[14] = "E"
   this[15] = "F"
   return(this)
}

hex = new HexArray()

function DezNachHex(x){
   var high = Math.floor(x / 16)
   var low = Math.floor(x - high * 16)
   return(hex[high] + "" + hex[low])
}

function Farbspiel(text){
   for(i=0;i<text.length;i++){
      FarbwertRot = 255 - (255 * i) / (text.length - 1)
      FarbwertGruen = 10
      FarbwertBlau = 10
      document.write("<span style=\"color: #" + DezNachHex(FarbwertRot) + DezNachHex(FarbwertGruen) + DezNachHex(FarbwertBlau) + ";\">" + text.substring(i, i + 1) + "</wtFont>")
   }
}

function MakeArray(n){
   this.length=n;
   for(var i=1; i<=n; i++) this[i]=i-1;
   return this
}

hex2=new MakeArray(16);
hex2[11]="A"; hex2[12]="B"; hex2[13]="C"; hex2[14]="D"; hex2[15]="E"; hex2[16]="F";

function ToHex(x){
   var high2 = x/16;
   var s = high2+"";
   s = s.substring(0,2);
   high2 = parseInt(s,10);
   var left = hex[high2+1];
   var low2 = x-high2*16;
   s = low2+"";
   s = s.substring(0,2);
   low2 = parseInt(s,10);
   var right = hex2[low2+1];
   var string = left+""+right;
   return string;
}

function rainbow(text){
   text = text.substring(3,text.length-4);
   color_d1 = 200;
   mul = color_d1/text.length;
   var page
   for(i=0;i<text.length;i++){
      color_d1 = 200*Math.sin (i/(text.length/3));
      color_h1 = ToHex(color_d1);
      color_d2 = mul*i;
      color_h2 = ToHex(color_d2);
      page = '<span style="color: #FF' + color_h1+color_h2+ ';">';
      page+= text.substring(i,i+1) + '</span>';
      document.write(page)
   }
}

