function openwin(url, width, height, features, name)
{
 features = features + ',Width=' + width.toString() + ',Height=' + height.toString();
 if (screen)
 {
  var x, y;
  y = (screen.availHeight - height) / 2;
  x = (screen.availWidth - width) / 2;
  features = features + ',screenX=' + x.toString() + ',screenY=' + y.toString() + ',left=' + x.toString() + ',top=' + y.toString() + ',scrollbars=no';
 }
 if (name == undefined)
  {name = "KubwaDeNewWin";}
 //window.name = 'newwindow';
 var d = new Date();
 name = name + d.getTime();
 Fenster = window.open(url, name, features);
 Fenster.focus();
}

function openwin2(url, width, height, features, name)
{
 show('DarkBG');
 show('PopupWindow');

 height = height + 15;

 var WinElement = document.getElementById('PopupWindow');
 WinElement.style.width = width.toString() + 'px';
 WinElement.style.height = height.toString() + 'px';
 var x = Math.round((screen.availWidth - width) / 2);
 var y = Math.round(((screen.availHeight - 160) - height) / 2);
 WinElement.style.left = x.toString() + 'px';
 WinElement.style.top = y.toString() + 'px';

 var IFrameElement = document.getElementById('PopupFrame')
 IFrameElement.style.width = width.toString() + 'px';
 IFrameElement.style.height = height.toString() + 'px';
 IFrameElement.src = url;
}

function Closepopup()
{
 hide('DarkBG');
 hide('PopupWindow');

 var IFrameElement = document.getElementById('PopupFrame');
 IFrameElement.src = 'about:blank';
}


function openhelpwin(name)
{
 var width = 449;
 var height = 400;
 var features = 'resizeable=yes,Width=' + width.toString() + ',Height=' + height.toString();
 if (screen)
 {
  var x, y;
  y = (screen.availHeight - height) / 2;
  x = (screen.availWidth - width) / 2;
  features = features + ',screenX=' + x.toString() + ',screenY=' + y.toString() + ',left=' + x.toString() + ',top=' + y.toString() + ',scrollbars=no';
 }
 //window.name = 'newwindow';
 Fenster = window.open('http://kubwa.de/index.php?cmd=helpwin&pos=' + name, 'KubwaDeHelpWin', features);
 Fenster.focus();
}

function openwindisclaimer(width, height)
{
 var features = 'Width=' + width.toString() + ',Height=' + height.toString();
 if (screen)
 {
  var x, y;
  y = (screen.availHeight - height) / 2;
  x = (screen.availWidth - width) / 2;
  features = features + ',screenX=' + x.toString() + ',screenY=' + y.toString() + ',left=' + x.toString() + ',top=' + y.toString() + ', scrollbars=yes';
 }
 Fenster = window.open("http://www.disclaimer.de/disclaimer.htm", 'KubwaDeDisclaimerWin', features);
 Fenster.focus();
}

function showhide(name)
{
 var e = document.getElementById(name);
 e.style.display = (e.style.display == 'block') ? 'none' : 'block';
 return;
}

function hide(name)
{
 var e = document.getElementById(name);
 e.style.display='none';
 return;
}

function show(name)
{
 var e = document.getElementById(name);
 e.style.display='block';
 return;
}

function DelAsk(Adresse, Text)
{
 if (typeof(Text) == "undefined")
  {Text = "!! WARNUNG !!\n\nBist du sicher, dass du diese Aktion ausführen willst ?\nMit dem Klick auf -Ok- führst du sie aus.";}
 var Wert = false;
 Wert = confirm(Text);
 if (Wert)
  {setTimeout("top.location = '" + Adresse + "'", 50);}
 else
  {return;}
}

function RefreshAddress()
{
 var e = document.getElementById('addresses');
 var a = document.getElementById('sendto');
 a.value = e.value;
}

function RefreshImage()
{
 var Zufallszahl = String(Math.floor(999999999 * Math.random()));
 SetImageSrc("image", "RandomImage.php?Dummy=" + Zufallszahl);
}

function SetImageSrc(ImageID, URL)
{
 document.getElementById(ImageID).src = URL;
 return;
}

function FetchURL(Adresse)
{
 var Zufallszahl = String(Math.floor(999999999 * Math.random()));
 AjaxRequest.get({'url':Adresse + '&Dummy=' + Zufallszahl, 'onSuccess':function(req){}});
 return;
}

function WebRedirect(toAddress)
{
 setTimeout(self.location.href = toAddress, 1);
 return;
}



function FetchHelpPopupContent(HelpPage, Session, HelpPopup)
{
 document.getElementById(HelpPopup).innerHTML = "<center><br><img src='template/25-1.gif' border=0><br>Lade Hilfe... (Bitte warten)</center>";
 var Zufallszahl = String(Math.floor(999999999 * Math.random()));
 AjaxRequest.get({'url':'FetchToolTipHelp.php?sd=' + Session + '&pos=' + HelpPage + '&Dummy=' + Zufallszahl,
                  'onSuccess':function(req)
                   {
                    var Result = req.responseText.split("|");
                    if (Result[0] == "INFO_FOUND")
                    {
                     try
                      {document.getElementById(HelpPopup).innerHTML = Result[1];}
                     catch(e){}
                    }
                    else
                    {
                     try
                      {document.getElementById(HelpPopup).innerHTML = "<b>Fehler</b><br><br>Die Information konnte leider nicht abgerufen werden.<br>Bitte klicke auf das Fragezeichen.";}
                     catch(e){}                    
                    }                    
                   }
                 });
 return;
}



function isDigit(ch){if ((ch >= '0') && (ch <= '9')){return true;}else{return false;}}
function isAlpha(ch){if (((ch >= 'a') && (ch <= 'z')) || ((ch >= 'A') && (ch <= 'Z'))){return true;}else{return false;}}
function isAlnum(ch){if (isAlpha(ch) || isDigit(ch)){return true;}else{return false;}}

function notIn( str1, str2 )
{
 var i = 0;
 var j = str2.length;
 for(i = 0; i < j; i++)
 {
  var str3 =  str2.charAt(i);
  if(str1.indexOf(str3) != -1)
   {return false;}
 }
 return true;
}

function checkUsername(username, mustBeQuoted)
{
 var i = 0;
 var j = username.length;
 if (username.charAt(0) != '"')
 {
  if ((username.charAt(0) <  ' ') || (username.charAt(0) >  '~') || !notIn(mustBeQuoted, username.charAt(0)))
   {return false;}
  for(i = 1; i < j; i++)
  {
   if (((username.charAt(i) < ' ') || (username.charAt(i) >  '~') || !notIn ( mustBeQuoted, username.charAt(i))) && (username.charAt(i - 1) != '\\'))
    {return false;}
  }
 }
 else
 {
  if (username.charAt(j - 1) != '"')
   {return false;}
  for(i = 1; i < j - 1; i++)
  {
   if (((username.charAt(i) == '\n') || (username.charAt(i) == '\r') || (username.charAt(i) == '\"')) && (username.charAt(i - 1) != '\\'))
    {return false;}
  }
 }
 return true;
}

function checkNr(nr)
{
 var i = 0;
 var j = nr.length;
 if(j < 1)
  {return false;}
 for(i = 0 ;i < j; i++)
 {
  if((nr.charAt(i) < '0') || (nr.charAt(i) > '9'))
   {return false;}
 }
 return true;
}

function checkIpnr(ipnr)
{
 var iL = 0;
 var iC = 0;
 var i = 0;
 var sNr = "";
 for(i = 0; i < ipnr.length; i++)
 {
  if (ipnr.charAt(i) == '.')
  {
   if (!iL || (iL> 3) || parseInt(sNr, 10) > 255)
    {return false;}
   iC++;
   iL = 0;
   sNr = "";
   continue;
  }
  if (isDigit (ipnr.charAt(i)))
  {
   iL++;
   sNr = sNr + ipnr.charAt(i);
   continue;
  }
  return false;
 }
 if (parseInt(sNr, 10) > 255)
  {return false;}
 if (((iC == 3) && (iL >= 1) && (iL <= 3)) || ((iC == 4) && (!iL)))
  {return true;}
 else
  {return false;}
}

function checkFqdn(fqdn)
{
 var iL = 0;
 var iC = 0;
 var i = fqdn.length - 1;
 if ((fqdn.charAt(0) == '.') || (fqdn.charAt(0) == '-'))
  {return false;}
 if (fqdn.charAt(i) == '.')
  {i = i - 1;}
 for(; i >= 0; i-- )
 {
  if (fqdn.charAt(i) == '.')
  {
   if (iL < 2 && iC < 2)
    {return false;}
   if (fqdn.charAt(i-1) == '-')
    {return false;}
   iC++;
   iL = 0;
   continue;
  }
  if (isAlnum (fqdn.charAt(i)))
  {
   iL++;
   continue;
  }
  if (fqdn.charAt(i) == '-')
  {
   if (!iL)
    {return false;}
   iL++;
   continue;
  }
  return false;
 }
 if (!iC || (iL == 1 && iC < 2) || (!iL && iC == 1))
  {return false;}
 return true;
}

function checkHostname(hostname)
{
 if (hostname.charAt(0) == '[')
 {
  if (hostname.charAt(hostname.length-1) != ']')
   {return false;}
  var ipnr = hostname.substring(1, hostname.length - 1);
  return checkIpnr(ipnr);
 }
 if ( hostname.charAt(0) == '#')
 {
  var nr = hostname.substring(1, hostname.length);
  return checkNr(nr);
 }
 return checkFqdn(hostname);
}

function checkEmailAdr(address)
{
 var status = true;
 var username = "";
 var hostname = "";
 if (address.length < 8)
  {return false;}
 var seperate = address.lastIndexOf("@");
 if (seperate == -1)
  {return false;}
 username = address.substring(0, seperate);
 if (!checkUsername(username, "<>()[],;:@\" "))
  {return false;}
 hostname = address.substring(seperate + 1, address.length);
 if (!checkHostname(hostname))
  {return false;}
 return true;
}



// This code was written by Tyler Akins and has been placed in the
// public domain.  It would be nice if you left this header intact.
// Base64 code from Tyler Akins -- http://rumkin.com

var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

function encode64(input)
{
 var output = new StringMaker();
 var chr1, chr2, chr3;
 var enc1, enc2, enc3, enc4;
 var i = 0;
 while (i < input.length)
 {
  chr1 = input.charCodeAt(i++);
  chr2 = input.charCodeAt(i++);
  chr3 = input.charCodeAt(i++);
  enc1 = chr1 >> 2;
  enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
  enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
  enc4 = chr3 & 63;
  if (isNaN(chr2))
   {enc3 = enc4 = 64;}
  else if (isNaN(chr3))
   {enc4 = 64;}
  output.append(keyStr.charAt(enc1) + keyStr.charAt(enc2) + keyStr.charAt(enc3) + keyStr.charAt(enc4));
 }
 return output.toString();
}

function decode64(input)
{
 var output = new StringMaker();
 var chr1, chr2, chr3;
 var enc1, enc2, enc3, enc4;
 var i = 0;
 // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
 input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
 while (i < input.length)
 {
  enc1 = keyStr.indexOf(input.charAt(i++));
  enc2 = keyStr.indexOf(input.charAt(i++));
  enc3 = keyStr.indexOf(input.charAt(i++));
  enc4 = keyStr.indexOf(input.charAt(i++));
  chr1 = (enc1 << 2) | (enc2 >> 4);
  chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
  chr3 = ((enc3 & 3) << 6) | enc4;
  output.append(String.fromCharCode(chr1));
  if (enc3 != 64)
   {output.append(String.fromCharCode(chr2));}
  if (enc4 != 64)
   {output.append(String.fromCharCode(chr3));}
 }
 return output.toString();
}