function warning (url) {
	
   mess = confirm ("Sind Sie sich sicher?");
	
   if (mess) {
	   window.location.href = url;
      return;
	}
   else {
		return;
	}
}

function openViewlet(htmlFile,htmlWidth,htmlHeight)
{
	if(document.all)
	{
		htmlWidth+=5;
		htmlHeight+=10;
	}
	window.open(htmlFile,'Leelou','width='+htmlWidth+',height='+htmlHeight+',top=10,left=20');
} 

function newVote () {
	window.open (document.URL+"?vote=new","newVote");
}

function up(formNumber) {
	document.forms[formNumber].command.name = "up";
	document.forms[formNumber].submit();
}

function down(formNumber) {
	document.forms[formNumber].command.name = "down";
	document.forms[formNumber].submit();
}

function openNewWindow(url) {
	open(url,"newWindow","dependent=no,locationbar=no,resizable=yes,status=yes,width=640,height=480,scrollbars=yes");
}

function openContactWindow(url) {
	open(url,"newWindow","dependent=no,locationbar=no,resizable=yes,status=yes,width=640,height=480,scrollbars=yes");
}

function openNewHelpWindow(url) {
	open(url,"Hilfe","dependent=no,locationbar=no,resizable=yes,status=yes,width=640,height=480,scrollbars=yes");
}

function openNewReportWindow(url) {
	open(url,"newWindow","dependent=no,locationbar=no,resizable=yes,status=yes,width=640,height=480,scrollbars=yes,menubar=no,toolbar=yes");
}

function openControlWindow(url) {
	controlWindow = open (url,"controlWindow","dependent=no,locationbar=no,resizable=yes,status=no,width=250,height=450");
}

function reloadMainWindow () {
	opener.location.reload();
}

function sendForm(formNumber, action) {
	document.forms[formNumber].mode.value = action;
	document.forms[formNumber].submit();
}

function contVote (nextStart)
{
	document.forms[0].start.value = nextStart;
	document.forms[0].submit();
}

/* check-Kram */
// whitespace characters
var whitespace = " \t\n\r";

// Removes all characters which appear in string bag from string s.

function stripCharsInBag (s, bag)

{   var i;
    var returnString = "";

    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }

    return returnString;
}


// Removes all whitespace characters from s.
// Global variable whitespace (see above)
// defines which characters are considered whitespace.

function stripWhitespace (s)

{   return stripCharsInBag (s, whitespace)
}


// Check whether string s is empty.

function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}

// Returns true if character c is a digit 
// (0 .. 9).

function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}


// isInteger (STRING s [, BOOLEAN emptyOK])
// 
// Returns true if all characters in string s are numbers.
//
// Accepts non-signed integers only. Does not accept floating 
// point, exponential notation, etc.
//
// We don't use parseInt because that would accept a string
// with trailing non-numeric characters.
//
// By default, returns defaultEmptyOK if s is empty.
// There is an optional second argument called emptyOK.
// emptyOK is used to override for a single function call
//      the default behavior which is specified globally by
//      defaultEmptyOK.
// If emptyOK is false (or any value other than true), 
//      the function will return false if s is empty.
// If emptyOK is true, the function will return true if s is empty.
//
// EXAMPLE FUNCTION CALL:     RESULT:
// isInteger ("5")            true 
// isInteger ("")             defaultEmptyOK
// isInteger ("-5")           false
// isInteger ("", true)       true
// isInteger ("", false)      false
// isInteger ("5", false)     true

function isInteger (s)

{   var i;

    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isInteger.arguments[1] == true);

    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);

        if (!isDigit(c)) return false;
    }

    // All characters are numbers.
    return true;
}

function sumArray ( inputarray )
{
	sum = 0;
	count = 0;
	
	for ( count; count < inputarray.length; count++ )
	{
		sum += inputarray[count];
	}
	window.status = sum;
//	sum = 0;	
	sum++;sum--;
	return sum;
}

var resultArray = new Array ();

function checkInput ( element, partID, mpv, mav, row )
{
	if (!resultArray[partID])
		resultArray[partID] = new Array ();
		
	var tempVal = stripWhitespace (element.value);

	if ( isEmpty(tempVal) )
		tempVal = 0;
		
	if (!isInteger(tempVal))
	{
		tempVal = 0;
		alert ("Sie haben keine (ganze) Zahl eingegeben!");
		element.focus();
	}
	
	if (tempVal > mpv)
	{
		tempVal = 0;
		alert ("Bitte nur Zahlen kleiner als " + mpv + " eingeben ");
		element.focus();
	}
	
	tempVal++;
	tempVal--; // muss doch einfacher gehen?!?!
	resultArray[partID][row] = tempVal;
	sum = sumArray (resultArray[partID]);
	if  ( sum > mav )
	{
		tempVal = 0;
		resultArray[partID][row] = 0;
		alert ("Sie haben nur " + mav + " Stimmen, jetzt aber schon " + sum + " Stimmen vergeben!");
		element.focus();
	}
	
	element.value = tempVal;
}

function checkChecks ( element, partID, mav, row )
{

	if (!resultArray[partID])
		resultArray[partID] = new Array ();

	resultArray[partID][row] = (element.checked == true)?1:0;
	sum = sumArray (resultArray[partID]);
	if (sum > mav)
	{
		element.checked = false;
		resultArray[partID][row] = 0;
		alert ("Bitte nur " + mav + " selektieren");
	}
}

function setInArray ( partID, row, value )
{
	if (!resultArray[partID])
		resultArray[partID] = new Array ();
	value++;value--;
	resultArray[partID][row] = value;
}

function markAll (incstep)
{
   for (i=2; i<document.listqu.elements.length; i+=incstep)
   {
      if (document.listqu.elements[i].type=="checkbox")
      {
         document.listqu.elements[i].checked = !document.listqu.elements[i].checked;
      }  // 
   }
   return;
}


/* Benutzer auf RealServer anlegen */

function userToReal()
{
   document.useredit.toreal.value="yes";
   document.useredit.submit();
   return;
}


/* Benutzer von RealServer loeschen */

function userRemoveFromReal()
{
   document.useredit.fromreal.value="yes";
   document.useredit.submit();
   return;
}


/* Fokus auf Eingabefeld der Diskussion setzen */

function setInputFocus ()
{
   if (parent.input)
   {
      parent.input.document.forms[0].form_comment.focus();
   }  // if
}


/* Bestimmten Frame der Diskussion neu laden */

usersreload = false;
activityreload = false;
outputreload = false;

function reloadFrame (frame)
{
   if (eval ("parent."+frame) )
   {
      if (eval("parent."+frame+".location"))
      {
         if (eval ("parent."+frame+".location.href"))
         {
            url = eval ("parent."+frame+".location.href");
            if (url.indexOf("blind")!=-1) return;
            // alert ("top."+frame+".location.reload()");
            eval ("parent."+frame+".location.reload()");
         }  // if
      }  // if
   }  // if
}

var windowHandle=0;

function openStartWindow (url)
{
   if (windowHandle==0||windowHandle.closed)
   {
//      newWidth    = screen.width-25;
      newWidth    = screen.width-10;
      newHeight   = screen.height - 100;
      windowHandle = open (
         url,
         "appwindow",
         "dependent=no,locationbar=no,resizable=yes,status=no,width="+newWidth+",height="+newHeight+",scrollbars=yes"
      );
      windowHandle.moveTo(0,0);
      windowHandle.focus();
   }  // if
   else
   {
      windowHandle.focus();
   }  // else
}


function checkClose (isMain,logoutUrl)
{
   if (!isMain)
   {
      if (opener && (opener.closed==false))
      {
         opener.setTimeout ("checkClose(true,'"+logoutUrl+"')", 100);
      }  // if
   }  // if
   else
   {
      if (windowHandle.closed)
      {
         open (logoutUrl,"logout","height=1,width=1,status=no,scrollbars=no,locationbar=no,menubar=no,toolbar=no");
      }  // if
   }  // else
}

var keyStr = "ABCDEFGHIJKLMNOP" +
			"QRSTUVWXYZabcdef" +
			"ghijklmnopqrstuv" +
			"wxyz0123456789+/" +
			"=";

function encode64(input) {
  var output = "";
  var chr1, chr2, chr3 = "";
  var enc1, enc2, enc3, enc4 = "";
  var i = 0;

  do {
	 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 = output + 
		keyStr.charAt(enc1) + 
		keyStr.charAt(enc2) + 
		keyStr.charAt(enc3) + 
		keyStr.charAt(enc4);
	 chr1 = chr2 = chr3 = "";
	 enc1 = enc2 = enc3 = enc4 = "";
  } while (i < input.length);

  return output;
}

function decode64(input) {
  var output = "";
  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 =
  var base64test = /[^A-Za-z0-9\+\/\=]/g;
  if (base64test.exec(input)) {
	 alert("There were invalid base64 characters in the input text.\n" +
		   "Valid base64 characters are A-Z, a-z, 0-9, ´+´, ´/´, and ´=´\n" +
		   "Expect errors in decoding.");
  }
  input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

  do {
	 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 = output + String.fromCharCode(chr1);

	 if (enc3 != 64) {
		output = output + String.fromCharCode(chr2);
	 }
	 if (enc4 != 64) {
		output = output + String.fromCharCode(chr3);
	 }

	 chr1 = chr2 = chr3 = "";
	 enc1 = enc2 = enc3 = enc4 = "";

  } while (i < input.length);

  return output;
}
