/*------------------*/
/* Useful functions */
/*------------------*/
function isIE() {
	return (/msie/).test( navigator.userAgent.toLowerCase());
};
var browser = {
		version: (navigator.userAgent.toLowerCase().match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/) || [])[1],
		safari: /webkit/.test(navigator.userAgent.toLowerCase()),
		opera: /opera/.test(navigator.userAgent.toLowerCase()),
		msie: /msie/.test(navigator.userAgent.toLowerCase()) && !/opera/.test(navigator.userAgent.toLowerCase()),
		mozilla: /mozilla/.test(navigator.userAgent.toLowerCase()) && !/(compatible|webkit)/.test(navigator.userAgent.toLowerCase())
	};

function isCompatibleBrowser( enableSafari, enableOpera ){
	var sAgent = navigator.userAgent.toLowerCase() ;
	// Internet Explorer
	if ( sAgent.indexOf("msie") != -1 && sAgent.indexOf("mac") == -1 && sAgent.indexOf("opera") == -1 )	{
		var sBrowserVersion = navigator.appVersion.match(/MSIE (.\..)/)[1] ;
		return ( sBrowserVersion >= 5.5 ) ;
	}
	// Gecko (Opera 9 tries to behave like Gecko at this point).
	if ( navigator.product == "Gecko" && navigator.productSub >= 20030210 && !( typeof(opera) == 'object' && opera.postError ) ) return true ;
	// Opera
	if ( enableOpera && navigator.appName == 'Opera' && parseInt( navigator.appVersion, 10 ) >= 9 ) return true ;
	// Safari
	if ( enableSafari && sAgent.indexOf( 'safari' ) != -1 ) return ( sAgent.match( /safari\/(\d+)/ )[1] >= 312 ) ;	// Build must be at least 312 (1.3)
	return false ;
};

function modalWin(url,dlgW,dlgH,vArguments) {
	var modWin = "";
	if (window.showModalDialog) {
		window.showModalDialog(url,vArguments,"status=no;dialogWidth:"+dlgW+"px;dialogHeight:"+dlgH+"px");
	} else {
		var screenX = window.innerWidth/2 - dlgW/2;
		var screenY = document.body.clientHeight/2 - dlgH/2;
		modWin = window.open(url,'','height='+dlgH+',width='+dlgW+',left='+screenX+',top='+screenY+',dependent=yes,toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,modal=yes');
		modWin.moveTo(200,200);
	}
	if (vArguments!=null&&vArguments!='') modWin.dialogArguments=vArguments;
};

function $$(a){return document.getElementById(a);};

function XmlHttp() {
	var xhr;
	if(window.XMLHttpRequest){xhr = new XMLHttpRequest;}
	else if(window.ActiveXObject){
		try{xhr=new ActiveXObject("Msxml2.XMLHttp")}
		catch(e){
			try{xhr=new ActiveXObject("Microsoft.XMLHttp");}
			catch(e2){}
		}
	}
	return xhr;
};

function absTop(el) {return (el.offsetParent)?el.offsetTop+absTop(el.offsetParent):el.offsetTop;};
function absLeft(el) {return (el.offsetParent)?el.offsetLeft+absLeft(el.offsetParent):el.offsetLeft;};
//function absTop(el) {return (el.offsetParent)?el.offsetTop-el.scrollTop+absTop(el.offsetParent):el.offsetTop;};
//function absLeft(el) {return (el.offsetParent)?el.offsetLeft-el.scrollLeft+absLeft(el.offsetParent):el.offsetLeft;};

function easeOut(t,d,b,c) {return -(c-b)*(t/=d)*(t-2)+b;};
function easeIn(t,d,b,c) {return (c-b)*(t/=d)*t+b;};
function easeInStrong(t,d,b,c) {return (c-b)*(t/=d)*t*t*t+b;};
function easeOutStrong(t,d,b,c) {return -(c-b)*((t=t/d-1)*t*t*t-1)+b;};
function easeInOut(t,d,b,c) {
	if ((t/=d/2)<1) return (c-b)/2*t*t+b;
	return -(c-b)/2*((--t)*(t-2)-1)+b;
}
function easeInOutStrong(t,d,b,c) {
	if ((t/=d/2)<1) return (c-b)/2*t*t*t*t+b;
	else return b-(c-b)/2*((t-=2)*t*t*t-2);
}

/*------------------------------*/
/* Event functions              */
/*------------------------------*/
function addEvent(obj, evType, fn) {
	if (obj) {
		if (obj.addEventListener){ 
	   		obj.addEventListener(evType, fn, false); 
	   		return true; 
		} else if (obj.attachEvent){ 
	   		var r = obj.attachEvent("on"+evType, fn); 
	   		return r; 
	 	} else { 
	   		return false; 
	 	} 
	} else {
		return false;
	}
};
function removeEvent(obj, evType, fn) {
	if (obj) {
		if (obj.removeEventListener) obj.removeEventListener(evType,fn,false);
		else obj.detachEvent("on" + evType,fn);
	}
};
function jumpToFirstField() {
	if (document.forms[0]) {
		var f = document.forms[0];
			if (f.elements[0].type.toLowerCase()!='hidden'){
				f.elements[0].focus();
				return true;
			}
	}
	return false;
};
function initForm(){
	addEvent(window,"load",jumpToFirstField);
}

/*------------------------------*/
/* String enhancement functions */
/*------------------------------*/
String.prototype.Contains = function( textToCheck ){
	return ( this.indexOf( textToCheck ) > -1 ) ;
};

String.prototype.ReplaceAll = function( searchArray, replaceArray ) {
	var replaced = this ;
	for ( var i = 0 ; i < searchArray.length ; i++ ) {
		replaced = replaced.replace( searchArray[i], replaceArray[i] ) ;
	}
	return replaced ;
};

String.prototype.StartsWith = function( value ) {
	return ( this.substr( 0, value.length ) == value ) ;
};

String.prototype.EndsWith = function( value, ignoreCase ) {
	var L1 = this.length ;
	var L2 = value.length ;
	if ( L2 > L1 ) return false ;
	if ( ignoreCase ) {
		var oRegex = new RegExp( value + '$' , 'i' ) ;
		return oRegex.test( this ) ;
	}
	else return ( L2 == 0 || this.substr( L1 - L2, L2 ) == value ) ;
};

String.prototype.Remove = function( start, length ) {
	var s = '' ;
	if ( start > 0 ) s = this.substring( 0, start ) ;
	if ( start + length < this.length ) s += this.substring( start + length , this.length ) ;
	return s ;
};

String.prototype.Trim = function() {
	// We are not using \s because we don't want "non-breaking spaces to be caught".
	return this.replace( /(^[ \t\n\r]*)|([ \t\n\r]*$)/g, '' ) ;
};

String.prototype.LTrim = function(){
	// We are not using \s because we don't want "non-breaking spaces to be caught".
	return this.replace( /^[ \t\n\r]*/g, '' ) ;
};

String.prototype.RTrim = function(){
	// We are not using \s because we don't want "non-breaking spaces to be caught".
	return this.replace( /[ \t\n\r]*$/g, '' ) ;
};

String.prototype.ReplaceNewLineChars = function( replacement ){
	return this.replace( /\n/g, replacement ) ;
};

/*-----------------------------*/
/* Array enhancement functions */
/*-----------------------------*/
Array.prototype.AddItem = function( item ) {
	var i = this.length ;
	this[ i ] = item ;
	return i ;
};

Array.prototype.IndexOf = function( value ) {
	for ( var i = 0 ; i < this.length ; i++ ) {
		if ( this[i] == value ) return i ;
	}
	return -1 ;
};

Array.prototype.Random = function() {
	return this.sort( function() {return Math.round(Math.random())-0.5} ); 
};

/*----------------------------*/
/* Date enhancement functions */
/*----------------------------*/
Date.prototype.DayName = function(l) {
	var d;
	if (l=="en") {d=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"];} 
	else {d=["Sonntag","Montag","Dienstag","Mittwoch","Donnerstag","Freitag","Samstag","Sonntag"];}
	return d[this.getDay()];
};
Date.prototype.MonthName = function(l) {
	var m;
	if (l=="en") {m=["January","February","March","April","May","June","July","August","September","October","November","December"];}
	else {m=["Januar","Februar","M&auml;rz","April","Mai","Juni","Juli","August","September","Oktober","November","Dezember"];}
	return m[this.getMonth()];
};
Date.prototype.Kalenderwoche = Date.prototype.CalendarWeek = function() {
  var x=this.Donnerstag();
  var y=(new Date(x.getFullYear(),0,4)).Donnerstag();
  return Math.floor(1.5+(x.getTime()-y.getTime())/86400000/7)
};
Date.prototype.Donnerstag = Date.prototype.Thursday = function() {
  var x=new Date();
  x.setTime(this.getTime() + (3-((this.getDay()+6) % 7)) * 86400000);
  return x;
};



