/*
 The StringComparator compares two string with each other.
 
 @param a string a
 @param b String b
 @return (a > b) = 1, (a == b) = 0,  (a < b) = -1
 */
function StringComparator(a, b) {
	var s1 = transformStringToBeComparable(a);
	var s2 = transformStringToBeComparable(b);
	return (s1==s2) ? 0 : (s1>s2) ? 1 : -1;
}

/*
 Transforms the string s.
  
 @param s the string to be transformed
 @return lowercase string without german umlauts
 */
function transformStringToBeComparable(s) {
	var transformed = s.toLowerCase();
	transformed = transformed.replace(/ä/g, "a");
	transformed = transformed.replace(/ö/g, "o");
	transformed = transformed.replace(/ü/g, "u");
	transformed = transformed.replace(/ß/g, "s");
	return transformed;
}

/*
 Descending number comparator. 
 
 @param n1 number 1
 @param n2 number 2
 @return compare value (n2 - n1)
*/
function DescNumberComparator(n1, n2) {
	return n2 - n1;
}

/*
 Adds thousand separator to specified number.
 If sep is not specified, "," will be used.
 
 @param n the number to be formatted
 @param sep the separator string (normally a single character)
*/
function thousandSeparator(n, sep) {
	var sRegExp = new RegExp('(-?[0-9]+)([0-9]{3})'),
	sValue = n + '';
	if (sep === undefined) { sep = ','; }
	while(sRegExp.test(sValue)) {
		sValue = sValue.replace(sRegExp, '$1' + sep + '$2');
	}
	return sValue;
}

/*
 Activates alpha transparent PNG background images for IE browser version 5.5 - 7.0.
 Expects an css background-image 
 */
function setBackgroundImageTransparentForIE(elementId) {
	var version = parseFloat(navigator.appVersion.split('MSIE')[1]);
	if ((version >= 5.5) && (version < 7) && (document.body.filters)) {
		// if IE5.5+ on win32, then display PNGs with AlphaImageLoader
		var cBGImg = $(elementId).currentStyle.backgroundImage;
		if (cBGImg != undefined && cBGImg != "") {
			var cImage = cBGImg.substring(cBGImg.indexOf('"') + 1, cBGImg.lastIndexOf('"'));
			if (cImage != "") {
				$(elementId).style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + cImage + "', sizingMethod='scale')";
				$(elementId).style.backgroundImage = "none";
			}
		}
  };
}

