// Tool Tip
wmtt = null;

document.onmousemove = updateWMTT;

function updateWMTT(e) {
	x = (document.all) ? window.event.x + document.body.scrollLeft : e.pageX;
	y = (document.all) ? window.event.y + document.body.scrollTop  : e.pageY;
	if (wmtt != null) {
		wmtt.style.left = (x + 20) + "px";
		wmtt.style.top 	= (y + 20) + "px";
	}
}

function showWMTT(id) {
	wmtt = document.getElementById(id);
	wmtt.style.display = "block"
}

function hideWMTT() {
	wmtt.style.display = "none";
}
// Tool Tip Ende

function isArray(obj) {
   if (obj.constructor.toString().indexOf("Array") == -1)
      return false;
   else
      return true;
}

function in_array(item,arr) {
	for(p=0;p<arr.length;p++) if (item == arr[p]) return true;
	return false;
}

function getIndex(item,arr) {
	for(p=0;p<arr.length;p++) if (item == arr[p]) return p;
	return -1;
}

function radioInputMoreThanOne(obj) {
	// Wenn ein Radio-Input-Feld nur eine Option hat, ist es vom Typ "HTMLInputElement".
	// Hat es mehr als eine Option, ist es vom Typ "Object()"
	if (obj.constructor.toString().indexOf("HTMLInputElement") == -1)
		return true;
	else
		return false;
}

function strltrim() {
	//Match spaces at beginning of text and replace with a null string
	return this.replace(/^\s+/,'');
}

function strrtrim() {
	//Match spaces at end of text and replace with a null string
	return this.replace(/\s+$/,'');
}

function strtrim() {
	//Match spaces at beginning and end of text and replace with null strings
	return this.replace(/^\s+/,'').replace(/\s+$/,'');
}

String.prototype.ltrim = strltrim;
String.prototype.rtrim = strrtrim;
String.prototype.trim = strtrim;

function swap_content(id) {
	displayType=(document.getElementById(id).style.display=='none') ? 'block' : 'none';
	document.getElementById(id).style.display = displayType;
}

function ConfirmAndSubmit(text,form) {
	if (confirm(text)) {
		document.forms[form].submit();
	}
}

function remoteServer(g_remoteServer) {
	var head = document.getElementsByTagName('head').item(0);
	var old  = document.getElementById('fileLoader');
	if (old) head.removeChild(old);

	script = document.createElement('script');
	script.src = g_remoteServer;
	script.type = 'text/javascript';
	script.defer = true;
	script.id = 'fileLoader';
	void(head.appendChild(script));
}

function CheckPassword(fName, pField) {
	var tStr = document.forms[fName].elements[pField].value.trim();
	if (tStr.length<5 || tStr.length>15) {
		alert("Das Login-Passwort muss zwischen 5 und 15 Zeichen lang sein!");
		return false;
	}
	for (var i=0; i<tStr.length; i++) {
		nextChar = tStr.substr(i,1);
		if ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz�������_-01234567890+#&$".indexOf(nextChar)==-1) {
			alert("Fehler! Das Login-Passwort darf nur aus Buchstaben (A-Z, a-z), Zahlen (0-9) und den Sonderzeichen _ - + # & $ bestehen!");
			return false;
		}
	}
	return true;
}

	function CheckPflichtfelder(formName, fArray, errorText) {
		var weiter = true;
		var debug = false;
		for (var i=0; i<fArray.length; i++) {
			// alert(document.forms[formName].elements[fArray[i]].type);
			if (document.forms[formName].elements[fArray[i]].type=="checkbox") {
				if (debug) alert("checkbox");
				if (document.forms[formName].elements[fArray[i]].checked==false) {
					if (errorText.length) alert(errorText);
					return false;
				}
			}
			if (document.forms[formName].elements[fArray[i]].type=="text" || document.forms[formName].elements[fArray[i]].type=="textarea") {
				if (debug) alert("text / textarea");
				if (document.forms[formName].elements[fArray[i]].value.trim()=="") {
					if (errorText.length) alert(errorText);
					return false;
				}
			}
			if (document.forms[formName].elements[fArray[i]].type=="select-one") {
				if (debug) alert("select-one");
				var check = false;
				for (var j=0; j<document.forms[formName].elements[fArray[i]].length; j++) {
					if (document.forms[formName].elements[fArray[i]][j].selected && document.forms[formName].elements[fArray[i]][j].value.trim()!="") check=true;
				}
				if (check==false) {
					if (errorText.length) alert(errorText);
					return false;
				}
			}
			if (!document.forms[formName].elements[fArray[i]].type) {
				// vermutlich ein Radio-Button:
				if (debug) alert("undefined");
				if (document.forms[formName].elements[fArray[i]][0].type=="radio") {
					if (debug) alert("radio");
					var check = false;
					for (var j=0; j<document.forms[formName].elements[fArray[i]].length; j++) {
						if (document.forms[formName].elements[fArray[i]][j].checked) check=true;
					}
					if (check==false) {
						if (errorText.length) alert(errorText);
						return false;
					}
				}
			}
		}
		return weiter;
	}

	
function number_format (number, decimals, dec_point, thousands_sep)
{
  var exponent = "";
  var numberstr = number.toString ();
  var eindex = numberstr.indexOf ("e");
  if (eindex > -1)
  {
    exponent = numberstr.substring (eindex);
    number = parseFloat (numberstr.substring (0, eindex));
  }
  
  if (decimals != null)
  {
    var temp = Math.pow (10, decimals);
    number = Math.round (number * temp) / temp;
  }
  var sign = number < 0 ? "-" : "";
  var integer = (number > 0 ? 
      Math.floor (number) : Math.abs (Math.ceil (number))).toString ();
  
  var fractional = number.toString ().substring (integer.length + sign.length);
  dec_point = dec_point != null ? dec_point : ".";
  fractional = decimals != null && decimals > 0 || fractional.length > 1 ? 
               (dec_point + fractional.substring (1)) : "";
  if (decimals != null && decimals > 0)
  {
    for (i = fractional.length - 1, z = decimals; i < z; ++i)
      fractional += "0";
  }
  
  thousands_sep = (thousands_sep != dec_point || fractional.length == 0) ? 
                  thousands_sep : null;
  if (thousands_sep != null && thousands_sep != "")
  {
	for (i = integer.length - 3; i > 0; i -= 3)
      integer = integer.substring (0 , i) + thousands_sep + integer.substring (i);
  }
  
  return sign + integer + fractional + exponent;
}	


	function ZeigeSterne(n) {
		for (var i=1; i<6; i++) {
			if (i<=n) document.getElementById("star_"+i).src="media/icons/stern-voll.gif";
			else document.getElementById("star_"+i).src="media/icons/stern-leer.gif";
		}
	}
