// Gibt die Anzahl der makierten Checkboxen aus, die den Angegebenen Namen haben. Bsp.: controlName[]
function GetCheckCount(checkName) {

	var checks = document.getElementsByName(checkName);

	var i_ = 0;
	for ( var i = 0; i < checks.length; i++) {

		if (checks[i].checked == true)
			i_++;

	}

	return i_;

}

// Sleep
function sleep(milliSeconds) {
	var startTime = new Date().getTime(); // get the current time
	while (new Date().getTime() < startTime + milliSeconds)
		; // hog cpu
}

// L�dt den Inhalt der angegebenen URL

function RequestPage(url, id) {

	$("#" + id).load(url, function(response, status, xhr) {
		if (status == "error") {
			var msg = "Sorry but there was an error: ";
			$("#error").html(msg + xhr.status + " " + xhr.statusText);
		}
	});

	/*
	 * 
	 * 
	 * $.ajax({ url : url, cache : false, success : function(html) {
	 * 
	 * $("#" + id).delay(3000000).html(html); return true; }, error :
	 * function(e) { return false; } });
	 */
	return false;

}

function RequestContent(url, id) {

	document.getElementById(id).innerHTML = "<div id=\""
			+ id
			+ "_tmpContent\"><div class=\"loadIcon\">"
			+ "<img style=\"\" src=\""
			+ PAGE["rootPath"]
			+ "images/load.gif\" alt=\"loading\" title=\"Loading ...\" /><div class=\"label\">Loading ...</div></div>"
			+ "</div>";

	RequestPage(url, id + "_tmpContent");

}

function SendPage(url, data) {
	SendPage(url, data, null);
}

function SendPage(url, data, success) {
	SendPage(url, data, success, null);
}
function SendPage(url, data, success, error) {

	if (!error)
		error = function() {
			return false;
		}

	var config = {
		type : "POST",
		data : data,
		success : success,
		error : error
	}

	if (url)
		config.url = url;

	return $.ajax(config).responseText;

}

/**
 * Function : dump() Arguments: The data - array,hash(associative array),object
 * The level - OPTIONAL Returns : The textual representation of the array. This
 * function was inspired by the print_r function of PHP. This will accept some
 * data as the argument and return a text that will be a more readable version
 * of the array/hash/object that is given. Docs:
 * http://www.openjs.com/scripts/others/dump_function_php_print_r.php
 */
function dump(arr, level) {
	var dumped_text = "";
	if (!level)
		level = 0;

	// The padding given at the beginning of the line.
	var level_padding = "";
	for ( var j = 0; j < level + 1; j++)
		level_padding += "    ";

	if (typeof (arr) == 'object') { // Array/Hashes/Objects
		for ( var item in arr) {
			var value = arr[item];

			if (typeof (value) == 'object') { // If it is an array,
				dumped_text += level_padding + "'" + item + "' ...\n";
				dumped_text += dump(value, level + 1);
			} else {
				dumped_text += level_padding + "'" + item + "' => \"" + value
						+ "\"\n";
			}
		}
	} else { // Stings/Chars/Numbers etc.
		dumped_text = "===>" + arr + "<===(" + typeof (arr) + ")";
	}
	return dumped_text;
}

Array.prototype.foreach = function(callback) {
	for ( var k = 0; k < this.length; k++) {
		callback(k, this[k]);
	}
}

/**
 * Verbindet die angegebenen Array's miteinander.
 * @param arrays 
 * @return void
 */
Array.prototype.array_merge = function() {

	for ( var x = 0; x < arguments.length; ++x) {

		for ( var y = 0; y < arguments[x].length; ++y) {

			this[this.length] = arguments[x][y];
		}
	}
};

/**
 * Durchsucht den Array nach dem angegebenen Inhalt.
 * @param string value 
 * @return void
 */
Array.prototype.in_array = function() {

	for (i = 0; i < this.length; i++)
		if (this[i] == arguments[0])
			return true;

	return false;

};

function isInt(x) {
	var y = parseInt(x);
	if (isNaN(y))
		return false;
	return x == y && x.toString() == y.toString();
}

function replaceUmlauts(str, index){

	str = str.replace("/ä/g", "ae").replace("/ö/g", "oe").replace("/ü/g", "ue").
	replace("/Ä/g", "Ae").replace("/ö/g", "Oe").replace("/ü/g", "Ue");
	
	return str;
}

