// JavaScript Document
// -----------------------------------------------------------------------------------
function evalKeyForSubmit(event, frm) {

   if(event && (event.which == 13 || event.keyCode==13)) { // IE: ...event.keyCode...
 	  frm.submit();
   }else {
      return true;
   }
}
//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
//
function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}

// -----------------------------------------------------------------------------------

//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

// -----------------------------------------------------------------------------------

//
// getKey(key)
// Gets keycode. If 'x' is pressed then it hides the lightbox.
//
function getKey(e){
	if (e == null) { // ie
		keycode = event.keyCode;
	} else { // mozilla
		keycode = e.which;
	}
	key = String.fromCharCode(keycode).toLowerCase();
	
	if(key == 'x'){
	}
}

// -----------------------------------------------------------------------------------

//
// listenKey()
//
function listenKey () {	document.onkeypress = getKey; }
	
// ---------------------------------------------------

function showSelectBoxes(){
	selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "visible";
	}
    objects = document.getElementsByTagName("object");
    for (i = 0; i != objects.length; i++) {
        objects[i].style.visibility = "visible";
    }
	embeds = document.getElementsByTagName("embed");
    for (i = 0; i != embeds.length; i++) {
        embeds[i].style.visibility = "visible";
    }
    window.focus();
}

// ---------------------------------------------------

function hideSelectBoxes(){
	selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		if(selects[i].id != "UserInfoBoxStatus") {
			selects[i].style.visibility = "hidden";
		}
	}
    objects = document.getElementsByTagName("object");
        for (i = 0; i != objects.length; i++) {
		objects[i].style.visibility = "hidden";
	}
	embeds = document.getElementsByTagName("embed");
    for (i = 0; i != embeds.length; i++) {
        embeds[i].style.visibility = "hidden";
    }
}

// ---------------------------------------------------

//
// pause(numberMillis)
// Pauses code execution for specified time. Uses busy code, not good.
// Code from http://www.faqts.com/knowledge_base/view.phtml/aid/1602
//
function pause(numberMillis) {
	var now = new Date();
	var exitTime = now.getTime() + numberMillis;
	while (true) {
		now = new Date();
		if (now.getTime() > exitTime)
			return;
	}
}
// #################################################################################################
// Globale Funktionen ##############################################################################
// #################################################################################################
var Utf8 = {

    // public method for url encoding
    encode : function (string) {
        string = string.replace(/\r\n/g,"\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    },

    // public method for url decoding
    decode : function (utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;

        while ( i < utftext.length ) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i+1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i+1);
                c3 = utftext.charCodeAt(i+2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }

        return string;
    }

}

function htmlentities(str,typ) { // std HTMLENTITIES PHP funktion nur in JS
    typ = 0;
	if(typeof str=="undefined") str="";
    if(typeof typ!="number") typ=2;
	typ=Math.max(0,Math.min(3,parseInt(typ)));
	   
   	str=str.replace(/&/g,"&amp;");
	str=str.replace(/</g,"&lt;");
   	str=str.replace(/>/g,"&gt;");
	if(typ==1 || typ==3) str=str.replace(/'/g,"&#039;");
	if(typ==2 || typ==3) str=str.replace(/'/g,"&quot;");
	
	var entity=new Array(
      "&nbsp;","&iexcl;","&cent;","&pound;","&curren;","&yen;","&brvbar;","&sect;",
      "&uml;","&copy;","&ordf;","&laquo;","&not;","&shy;","&reg;","&macr;",
      "&deg;","&plusmn;","&sup2;","&sup3;","&acute;","&micro;","&para;","&middot;",
      "&cedil;","&sup1;","&ordm;","&raquo;","&frac14;","&frac12;","&frac34;","&iquest;",
      "&Agrave;","&Aacute;","&Acirc;","&Atilde;","&Auml;","&Aring;","&AElig;","&Ccedil;",
      "&Egrave;","&Eacute;","&Ecirc;","&Euml;","&Igrave;","&Iacute;","&Icirc;","&Iuml;",
      "&ETH;","&Ntilde;","&Ograve;","&Oacute;","&Ocirc;","&Otilde;","&Ouml;","&times;",
      "&Oslash;","&Ugrave;","&Uacute;","&Ucirc;","&Uuml;","&Yacute;","&THORN;","&szlig;",
      "&agrave;","&aacute;","&acirc;","&atilde;","&auml;","&aring;","&aelig;","&ccedil;",
      "&egrave;","&eacute;","&ecirc;","&euml;","&igrave;","&iacute;","&icirc;","&iuml;",
      "&eth;","&ntilde;","&ograve;","&oacute;","&ocirc;","&otilde;","&ouml;","&divide;",
      "&oslash;","&ugrave;","&uacute;","&ucirc;","&uuml;","&yacute;","&thorn;","&yuml;"
      );
	
    for(var i = 0; i< entity.legth; i++) {
		eval("str=str.replace(/"+String.fromCharCode(i*1+160)+"/g,\""+entity[i]+"\");");
	}
   
	return str;
}
function wrapEnt(string, anzahl) {
	// Schleife mit leerzeichen
	var stri = "";
	var ar_leer = string.split(" ");
	// einzelne Wörter durchschleifen
	for(var i = 0; i < ar_leer.length; i++) {
		// Wenn anzahl buchstaben > anzahl
		if(ar_leer[i].length > anzahl) {
			// NAch ANZAHL buchstaben leerzeichen einfügen
			newStr = "";
			for(var x=0; x < ar_leer[i].length; x=x+anzahl) {
				newStr += ar_leer[i].substr(x,anzahl);
				newStr += " ";
			}
			// neuen String setzten
			stri += newStr;
		}else {
			// neuen String setzten
			stri += ar_leer[i]+" ";
		}
	}
	// Rückgabe des Strings
	return stri;
}
function addslashes(str) {
	str=str.replace(/\'/g,'\\\'');
	str=str.replace(/\"/g,'\\\"');
	str=str.replace(/\\/g,"\\");
	//str=str.replace(/\0/g,'\\0');
	return str;
}
function stripslashes(str) {
	str=str.replace(/\\'/g,'\'');
	str=str.replace(/\\"/g,'"');
	str=str.replace(/\\\\/g,'\\');
	//str=str.replace(/\\0/g,'\0');
	return str;
}
function urlencode(str) {
	str=str.replace(/\+/g,'%2B');
	str = escape(Utf8.encode(str));
	return str;
}
function urldecode(str) {
	str=str.replace(/\+/g,' ');
	str = unescape(str);
	return str;
}

function insert(input, aTag, eTag) {
  input.focus();
  /* fuer IE */
  if(typeof document.selection != 'undefined') {
    /* Einfuegen von Formatierungscodes */
    var range = document.selection.createRange();
    var insText = range.text;
    range.text = aTag + insText + eTag;
    /* Cursorposition setzen */
    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();
  }
  /* fuer neuere auf Gecko basierende Browser */
  else if(typeof input.selectionStart != 'undefined')
  {
    /* Einfgen des Formatierungscodes */
    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);
    /* Anpassen der Cursorposition */
    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;
  }
  /* fr die brigen Browser */
  else
  {
    var message = 'Leider unterstützt der Browser diese Funktion nicht vollständig.\nDer HTML-Befehl wird am Ende des Textes eingefügt.';
    alert(message);
    input.value = input.value + aTag + eTag;
  }
}
// ---------------------------------------------------
// Smilies
// ---------------------------------------------------
var smilie = new Array()
smilie[0] = new Array(new Array(":-X",":X",":-x",":x"),"wry.gif");
smilie[1] = new Array(new Array("8-0"),"shock.gif");
smilie[2] = new Array(new Array(":-P",":P",":-p",":p"),"tongue.gif");
smilie[3] = new Array(new Array(':-"',':"'),"whistling.gif");
smilie[4] = new Array(new Array("X-(","x(","X(","x-("), "angry.gif");
smilie[5] = new Array(new Array(":'("), "cry.png");
smilie[6] = new Array(new Array(":-)",":)"),"happy.gif");
smilie[7] = new Array(new Array(":-|",":|"), "hmmm.png");
smilie[8] = new Array(new Array(":-O",":O",":-o",":o"), "confused.gif");
smilie[9] = new Array(new Array(";-)",";)"), "wink.gif");
smilie[10] = new Array(new Array("B-)","8-)","B)","8)"), "sunglasses.gif");
smilie[11] = new Array(new Array(":-/",":/"), "itsok.gif");
smilie[12] = new Array(new Array(":-D",":D",":-d",":d"), "grin.gif");
smilie[13] = new Array(new Array(":-(",":("), "sad.png");
smilie[14] = new Array(new Array(':-$',':$'), "blush.gif");
smilie[15] = new Array(new Array(":-S",":S",":-s",":s"), "pout.png");
smilie[16] = new Array(new Array("^^"), "verryhappy.png");

function smiliereplace(text,baseurl) {
	for(var x=0; x < smilie.length; x++) {
		//for(var i=0; i < smilie[x][0].length; i++) {
			eval("var rpl = /:"+[x]+":/g");
			text = text.replace(rpl, '<img src="'+baseurl+'img/smilies/'+smilie[x][1]+'" border="0" align="absbottom">');
		//}
	}
	//alert(text);
	return text;
}
function reg(txt) {
	var res = "";
	for(var z=0; z < txt.length; z++) {
		var t = txt[z];
		if(t == "D" || t == "B" || t == "d" || t == "0" || t == "8")
			res = res+txt[z];
		else 
			res = res + "\\"+txt[z];
		
	}
	return res;
}
// ---------------------------------------------------
