/******************************************************	*/
/***		DOCUMENT									*/
/******************************************************	*/

// getElementByClassName
if (!document.getElementsByClassName) {
	document.getElementsByClassName = function(cl) {
		var retnode = [];
		var myclass = new RegExp('\\b'+cl+'\\b');
		var elem = this.getElementsByTagName('*');
		for (var i = 0; i < elem.length; i++) {
			var classes = elem[i].className;
			if (myclass.test(classes)) {
				retnode.push(elem[i]);
			}
		}
		return retnode;
	};
}

// Diverse Schnellfunktionen:
if (!document.hideID) {
	document.hideID = function(id) {
		element = document.getElementById(id);
		if (element) element.style.display = "none";
	}
}
if (!document.showID) {
	document.showID = function(id) {
		element = document.getElementById(id);
		if (element) element.style.display = "";
	}
}
if (!document.setClass) {
	document.setClass = function(id, css_class) {
		element = document.getElementById(id);
		if (element) element.className = css_class;
	}
}
if (!document.toggleID) {
	document.toggleID = function(id) {
		element = document.getElementById(id);
		if (element)
			if (element.style.display=="") element.style.display = "none";
			else element.style.display = "";
	}
}

/******************************************************	*/
/***		LOCATION									*/
/******************************************************	*/

// Ändert Variableninhalte in der URL
if (!location.replaceURL) {
	location.replaceURL = function(url, name, value) {
		if (url.indexOf(name)==-1) {
			if (url.indexOf("?")==-1) var add = "?"; else var add = "&";
			url = document.location.href + add + name + "="+value;
		} else {
			var expr1 = new RegExp(name + "=.*?&");
			url = (url+"&").replace(expr1, name + '='+value+'&');
			url = url.substr(0, url.length-1);
		}
		return url;
	}
}

if (!location.getVar) {
	location.getVar = function(name, url) {
		if (typeof(url)=="undefined") var url = window.location.search;
		var results = new RegExp("(^|[\\?&])"+escape(name)+"=([^&#]*)").exec(url);
		if (results == null) return false;
		else return results[2];
	}
}

// Ändert Variableninhalte in der aktuellen URL, per Objekt {name:"wert",...}, und gibt sie zurück
//if (!location.rewriteURL) {
if (typeof(location.rewriteURL) == "undefined") {
	location.rewriteURL = function(obj, sid, url) {
		if (typeof(url)=="undefined") var url = url = location.href;
		for (k in obj) {
			var v = encodeURIComponent(obj[k]);
			if (typeof(sid)!="undefined" && sid!=false && sid!="") var n = sid+"_"+k; 
			else var n = k;
			if (new RegExp('(^|[\\?&])'+n+'=.*?($|[&#])','ig').test(url)) {
				var url = url.replace(new RegExp("(^|[\\?&])"+n+"=[^&#]*",'ig'), ((v!="")?"$1"+n+"="+v:"$1"));
			} else if (v != "") {
				var result = /(^.*?)($|[#].*)/i.exec(url);
				url = result[1] + ((!/\?/i.test(url))?'?':'&') + n+"="+v + result[2];
			}
		}
		return url;
	}
}

/******************************************************	*/
/***		NODE										*/
/******************************************************	*/

var print_window;
if (!document.print) {
	document.print = function(id, head) {
		if (!(!print_window)) print_window.close();
		var content = document.getElementById(id).innerHTML;
			content = content.replace(/(\r\n|\n\r|\r|\n)/gm,'').replace(/\<script[^>]*?\>.*?\<\/script\>/gmi, '');
			content = content.replace(/(fontimg.php.*?)("|')/gmi, '$1&color=044184$2');
			print_window = window.open('','print_content','scrollbars=yes,width=668,height=600');

		print_window.document.open();
		print_window.document.write('<html>');
		if (typeof(head) != "undefined") {
			print_window.document.write('<head>');
			print_window.document.write(head);
			print_window.document.write('</head>');
		}
		print_window.document.write('<body id="printing" onload="window.print()">');
		print_window.document.write(content);
		print_window.document.write('</body>');
		print_window.document.write('</html>');
		print_window.document.close();
	}
}

if (typeof(Node) != "undefined") {
	if (!Node.print) {
			if (!(!print_window)) print_window.close();
			Node.prototype.print = function(head) {
			var content= this.innerHTML;
			content = content.replace(/(\r\n|\n\r|\r|\n)/gm,'').replace(/\<script[^>]*?\>.*?\<\/script\>/gmi, '');
			content = content.replace(/(fontimg.php.*?)("|')/gmi, '$1&color=044184$2');
			print_window = window.open('','print_content','scrollbars=yes,width=668,height=600');

			print_window.document.open();
			print_window.document.write('<html>');
			if (typeof(head) != "undefined") {
				print_window.document.write('<head>');
				print_window.document.write(head);
				print_window.document.write('</head>');
			}
			print_window.document.write('<body id="printing" onload="window.print()">');
			print_window.document.write(content);
			print_window.document.write('</body>');
			print_window.document.write('</html>');
			print_window.document.close();
		}
	}
}

/******************************************************	*/
/***		ARRAY										*/
/******************************************************	*/

// Durchsucht das Array
if (!Array.getIndex) {
	Array.prototype.getIndex = function(search) {
		for (var i=0; i < this.length; i++) {
			if (this[i] == search) {
				return i;
			}
		}
		return false;
	}
}

/******************************************************	*/
/***		NUMBER										*/
/******************************************************	*/

if (!Number.fill) {
	Number.prototype.fill = function(anz) {
		var ret = this.toString();
		for (var i=ret.length; i<anz; i++) {ret = "0" + ret;}
		return ret;
	}
}

/******************************************************	*/
/***		DATE										*/
/******************************************************	*/

// Tag der Woche (0 = Montag, 6 = Sonntag)
if (!Date.getWeekDay) {
	Date.prototype.getWeekDay = function() {return new Date(this.getTime()-(24*60*60*1000)).getDay();}
}
// Woche des Jahres
if (!Date.getWeek) {
	Date.prototype.getWeek = function() {
		var jahr = new Date(this.getFullYear(), 0, 1);
		var jahr = new Date(jahr.getTime() + (-jahr.getWeekDay()+7*Math.round((jahr.getWeekDay())/7))*24*60*60*1000);
		var woche = Math.ceil((this.getTime() - jahr.getTime()) / (7*24*60*60*1000));
		if (woche < 10) return "0" + woche;
		else return woche;
	}
}

/******************************************************	*/
/***		JSON										*/
/******************************************************	*/

var JSON = JSON || {};  
// implement JSON.stringify serialization  
JSON.stringify = JSON.stringify || function (obj) {  
	var t = typeof (obj);  
	if (t != "object" || obj === null) {  
		// simple data type  
		if (t == "string") obj = '"'+obj+'"';  
		return String(obj);  
	}  
	else {  
		// recurse array or object  
		var n, v, json = [], arr = (obj && obj.constructor == Array);  
		for (n in obj) {  
			v = obj[n]; t = typeof(v);  
			if (t == "string") v = '"'+v+'"';  
			else if (t == "object" && v !== null) v = JSON.stringify(v);  
			json.push((arr ? "" : '"' + n + '":') + String(v));  
		}  
		return (arr ? "[" : "{") + String(json) + (arr ? "]" : "}");  
	}  
};  
