/**
 *	A spacer element for the alignment of HTML components
 */
var Spacer = function(width) {
	var img = document.createElement("img");
	img.src = "img/spacer.gif";
	img.style.width = width + "px";
	return img;
}

/**
 *	Returns the height of the inner browser (i.e. the content) window.
 */
function getWindowHeight() {
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	return myHeight;
}

function isEmail(inValue) {
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(inValue)) return true;
	else return false;
}


/**
 *	Changes the opacity of a given object
 */
function changeOpacity(obj, op) {
	// get relevant style object
	var s;
	
	if(obj.style) {
		s = obj.style;
	} else {
		s = document.getElementById(obj).style;
	}
	
	// set opacity
	s.opacity = (op / 100);
	s.MozOpacity = (op / 100);
	s.KhtmlOpacity = (op / 100);
	//s.filter = "alpha(opacity=" + op + ")";
	s.filter = "alpha(opacity: " + op + ");";

}

function startLog() {
	if(logPush) {
		logPush.activate();  
	} else {
		logPush = new PushObject("/log/system", onSystemEvent);
		logPush.activate(); 
	}
}

function stopLog() {
	if (logPush) {
		logPush.deactivate();  
	}
}

/*
 * indexOf function for javascript Array
 */
Array.prototype.indexOf = function(obj) {
	for(var i=0; i<this.length; i++) {
		if (this[i]==obj) return i;
	}
	return -1;
}

String.prototype.trim = function () {
    var s = this.replace(/^\s*/, "");
   	return s.replace(/\s*$/, "");
}
	    
/*
 * Note: Array.prototype.contains notation does not work, SOAP parameter error (?)
 */
function arrayContains(array, obj) {
	for (var i=0; i<array.length; i++) {
		if (array[i]==obj) return true;
	}
	return false;
}

/**
 *	Checks whether the key pressed in a form field was enter: If so, the 
 *	form is submitted automatically. Required in any form containing more
 *	than 1 text input control.
 */
function entercheck(fld,evt) {
	var keycode;
	if (window.event) 
		keycode = window.event.keyCode;
	else if (evt) 
		keycode = evt.which;
	else return true;
	
	if (keycode == 13) {
		if (fld.form.onsubmit()) {
			fld.form.submit();
		}
		return false;
	} else
		return true;
}

function rgb2hex(inRgb) {
	var numbers = new Array("0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F");
	var colorstring = inRgb.substring(inRgb.indexOf('(')+1, inRgb.indexOf(')'));
	var colors = colorstring.split(",");
	var string = "#";
	for (i=0; i<3; i++) {
		var val = parseInt(colors[i]);
		string = string + numbers[parseInt(val/16)] + numbers[val%16];
	}
	return string;
}

function getBrowserLanguage() {
	if(IE) var language = navigator.userLanguage;
	else var language = navigator.language;
	if(language.indexOf("de") > -1) return "de";
	else if(language.indexOf("en") > -1) return "en";
	else return null;
}

/**
 *	DEBUG: prints a debug message to the screen (a div with the id 'debug')
 */
function debug(txt) {
	var debug = document.getElementById("debug");
	if (debug) debug.innerHTML = txt;
}