
//	128 nbsp´s für Modalfenster-Title
var TITLE_SPACES = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
TITLE_SPACES += TITLE_SPACES;
TITLE_SPACES += TITLE_SPACES;
TITLE_SPACES += TITLE_SPACES;
TITLE_SPACES += TITLE_SPACES;


function formatURL(url) {
	// You can use this variables:
	var re1 = /\$LANGUAGE/g;
	var re2 = /\$COUNTRY/g;
	var re3 = /\$OEM/g;
	var re4 = /\$SCRIPTDIR/g;
	var re5 = /\$PRODUCT/g;

	url = url.replace(re1, window.top.theLanguage);
	url = url.replace(re2, window.top.theCountry);
	url = url.replace(re3, window.top.theOEM);
	url = url.replace(re4, window.top.theScriptDir);
	url = url.replace(re5, window.top.theProduct);
	return url;
}

//if (typeof(window.top.IMPORT_JS) == 'undefined') {
	//window.top.IMPORT_JS =
	IMPORT_JS = function(url, wnd) {
		url = formatURL(url);

		if (typeof(wnd) == 'undefined')
			wnd = window;
		if (typeof(wnd.loaded_js_files) == 'undefined') {
			wnd.loaded_js_files = new Object();
			//wnd.loaded_js_files.files = new Array();
		}
		if (typeof(wnd.loaded_js_files.files) == 'undefined') {
			wnd.loaded_js_files.files = new Array();
		}
		if (typeof(wnd.loaded_js_files.files[url]) == 'undefined') {
			//alert(url);
			wnd.loaded_js_files.files[url] = true;
			document.write("<SCRIPT src='" + url + "'></"+"SCRIPT>");
		}
	}
//}
//IMPORT_JS = window.top.IMPORT_JS;


jdecode = function(s) {
		var re = /\+/g;
		s = s.replace(re, "%20");
		return unescape(s);
	}
//------------------------------------------------------------------------------
//	Simuliert java.net.URLDecoder.encode()
jencode = function(s) {
		var re1 = /\+/g;
		var re2 = /%20/g;
		s = escape(s);
		return s.replace(re1, "%2B").replace(re2, "\+");
	}

// OO in JS -> target extends src
function copyBase(src, target) {
	for (pt in src.prototype) {
		target.prototype[pt]=src.prototype[pt];
	}
	target.prototype.toString=src.prototype.toString;
	target.prototype.valueOf=src.prototype.valueOf;
	target.prototype.base=src;

//	for (pt in src.prototype) {
//		target.prototype["_base" + pt]=src.prototype[pt];
//	}
}

function copyObject(src, target) {
	// um z.B. Language Objekte save zu extenden,
	// dh. sollte in src eine Variable nicht gesetzt sein, bleibt die in target definierte erhalten
	for (pt in src) {
		target[pt]=src[pt];
	}
}

function safeEscape(s) {
	if (!s)
		return "";

	return s.replace(/([&<'])/g,
		function ($1) {
			switch ($1)	{
				case "&":
					return "&amp;";
				case "<":
					return "&lt;";
				case "'":
					return "\\'";
				case "\"":
					return "\\\"";
			}
		}
	);
}

//------------------------------------------------------------------------------
//	String.startsWith und endsWith wie in Java
String.prototype.startsWith = function(prefix) {
	if (!prefix)
		return true;
	if (prefix.length > this.length)
		return false;
	return this.indexOf(String(prefix)) == 0;
}

String.prototype.endsWith = function(suffix) {
	if (!suffix)
		return true;
	if (suffix.length > this.length)
		return false;
	return this.lastIndexOf(String(suffix)) == this.length - String(suffix).length;
}

//------------------------------------------------------------------------------
//	Global-Unique-ID erzeugen
function getGUID() {

	var zeroStr = "0000000000000000";

	var timeStamp = new Date().valueOf().toString(16);
	timeStamp = zeroStr.substr(0, 10 - timeStamp.length) + timeStamp;

	var random = Math.random().toString(16).substr(2);
	random = zeroStr.substr(0, 16 - random.length) + random;

	var hrb = "32668";		//	HRB der CM-AG anstelle MAC-Adresse

	var guid = hrb + "0" + timeStamp.substring(0, 2)
			+ "-" + timeStamp.substring(2, 6)
			+ "-" + timeStamp.substring(6, 10)
			+ "-" + random.substring(0, 4)
			+ "-" + random.substring(4, 16);
	guid = guid.toUpperCase();

	return guid;
}

//------------------------------------------------------------------------------
//	Eine HashMap, die vom GarbageCollector abgeräumt werden kann
function CMHashMap() {
	this.map = new Array();
}

CMHashMap.prototype.get = function(key) {
	if (typeof(this.map[key]) == "undefined" || this.map[key] == null)
		return null;
	else
		return this.map[key];
}

CMHashMap.prototype.put = function(key, value) {
	this.map[key] = value;
	return this.map[key];
}

CMHashMap.prototype.remove = function(key) {
	var value = this.get(key);
	this.map[key] = null;
	var canTrash = true;
	for (var o in this.map) {
		if (this.map[o] != null) {
			canTrash = false;
			break;
		}
	}
	if (canTrash)
		this.map = new Array();

	return value;
}

//------------------------------------------------------------------------------
//	IE 5.0 kennt kein Array.push, splice, shift
//	Beachte: Nicht array.push("x") sondern Array.push(array, "x")
Array.push = function(array, value) {
	if (window.top.g_clientCheck.isIE55up || window.top.g_clientCheck.isMoz1up) {
		if (typeof(array.push) == "function")
			array.push(value);
	} else {
		array[array.length] = value;
	}
}

Array.pop = function(array) {
	if (window.top.g_clientCheck.isIE55up || window.top.g_clientCheck.isMoz1up) {
		if (typeof(array.pop) == "function")
			return array.pop();
		else
			return null;
	} else {
		if (array.length == 0) {
			return null;
		} else {
			var value = array[array.length-1];
			array.length --;
			return value;
		}
	}
}

Array.shift = function(array) {
	if (window.top.g_clientCheck.isIE55up || window.top.g_clientCheck.isMoz1up) {
		if (typeof(array.shift) == "function")
			return array.shift();
		else
			return null;
	} else {
		if (array.length == 0) {
			return null;
		} else {
			var value = array[0];
			for (var i = 0; i < array.length-1; i ++)
				array[i] = array[i+1];

			array.length --;
			return value;
		}
	}
}

Array.unshift = function(array, value) {
	if (window.top.g_clientCheck.isIE55up || window.top.g_clientCheck.isMoz1up) {
		if (typeof(array.unshift) == "function")
			array.unshift(value);
	} else {
		for (var i = array.length-1; i >= 0; i --)
			array[i+1] = array[i];

		array[0] = value;
	}
}


