﻿
/*
*/


String.prototype.leftTrim = function () {
	return (this.replace(/^\s+/,""));
};

String.prototype.rightTrim = function () {
	return (this.replace(/\s+$/,""));
};

String.prototype.trim = function () {
	return (this.replace(/\s+$/,"").replace(/^\s+/,""));
};

String.prototype.superTrim = function () {
	return(this.replace(/\s+/g," ").replace(/\s+$/,"").replace(/^\s+/,""));
};

String.prototype.removeWhiteSpaces = function () {
	return (this.replace(/\s+/g,""));
};


function openWindow(url, windowTitle, width, height) {
    var wnd = window.open(
		url,
		windowTitle,
		"width=" + width + ",height=" + height + ",hotkeys=no,location=no,resizable=yes,menubar=no,toolbar=no,scrollbars=yes"
	);

    wnd.focus();
}


function gebi(id) {
	return document.getElementById(id);
}


function hideMenu(id) {
    gebi(id).className = 'hide';
}


function showMenu(id) {
	gebi(id).className = 'show';
}


function getNumberByString(word) {
	var no = 0;
	
	switch(word) {
		case "Eins":
			no = 1;
			break;
		
		case "Zwei":
			no = 2;
			break;
		
		case "Drei":
			no = 3;
			break;
		
		case "Vier":
			no = 4;
			break;
		
		case "Fünf":
			no = 5;
			break;
		
		case "Sechs":
			no = 6;
			break;
		
		case "Sieben":
			no = 7;
			break;
		
		case "Acht":
			no = 8;
			break;
		
		case "Neun":
			no = 9;
			break;
			
		case "Zehn":
			no = 10;
			break;
		
		default:
		case "Null":
			no = 0;
			break;
	}
	
	return no;
}


function addLoadEvent(func) {
	var oldonload = window.onload;
	
	if(typeof window.onload != 'function') {
		window.onload = func;
	}
	else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}


function getKeyCode(event) {
	//event = event || window.event;
	//return event.keyCode;
	
	if(!event) {
		event = window.event;
	}
	
	if(event.which) {
		return event.which;
	}
	else if(event.keyCode) {
		return event.keyCode;
	}
}


function displayKeyCode(object) {
	object.onkeydown = function(event) {
		var charCode = getKeyCode(event);
		var charString = String.fromCharCode(charCode);
	}
}


function checkBrowser() {
    var browser = 'moz';
    var realBrowser = '';
	var name = navigator.userAgent;
	name = name.toLowerCase();
	
	var ie = false;
	
	if(navigator.userAgent.indexOf("MSIE") > 0) {
		ie = true;
		realBrowser = 'ie';
	}
	else{
		ie = false;
		
		if(name.indexOf("safari") > 0) {
			realBrowser = 'safari';
		}
		else if(navigator.product == "Gecko") {
			realBrowser = 'moz';
		}
		else if(name.indexOf("opera") != -1) {
			realBrowser = 'opera';
		}
		else if(name.indexOf("khtml") != -1) {
			realBrowser = 'khtml';
		}
		else if(name.indexOf("konqueror") != -1) {
			realBrowser = 'konqueror';
		}
		else {
			realBrowser = 'moz';
		}
	}
	
	if(ie) {
		browser = 'ie';
	}
	else {
		//browser = 'moz';
		browser = realBrowser;
	}
	
	return browser;
}


function CapricaBase() {
	this.gebi = gebi;
	this.hideMenu = hideMenu;
	this.showMenu = showMenu;
	this.getNumberByString = getNumberByString;
	this.addLoadEvent = addLoadEvent;
	this.getKeyCode = getKeyCode;
	this.displayKeyCode = displayKeyCode;
	this.checkBrowser = checkBrowser;
}


CapricaBase = new CapricaBase();

