
wopen = function ( url, width, height, option ) {
	if ( url ) {
		var innerWidth = ",width=600";
		if ( width ) innerWidth = ",width=" + width;

		var innerHeight = ",height=400px";
		if ( width ) innerHeight = ",height=" + height;

		var innerOption = "status=no,toolbar=no,scrollbars=yes,location=yes,menu=yes";
		if ( option && option != "" ) innerOption = option;

		innerOption += innerWidth + innerHeight;

		var now = new Date();
		var wname = "w" + now.getTime();	
		window.open ( url, wname, innerOption );
	}
}


setCookie = function ( name, value, expires, path, domain, secure ) {

	var curCookie = name + "=" + escape(value) +
		((expires) ? "; expires=" + expires.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");

	document.cookie = curCookie;
}


setExtCookie = function ( src ) {

	var iframes	= document.getElementsByName ('extCookieFrame');
	var ifrm	= null;
	
	if ( iframes.length == 0 ) {
		ifrm = document.createElement('iframe');
		ifrm.src		= src;
		ifrm.style.left		= '0px';
		ifrm.style.top		= '-200px';
		ifrm.style.width	= '1px';
		ifrm.style.height	= '1px';
		ifrm.style.position	= 'absolute';
		ifrm.name		= 'extCookieFrame';
		document.body.appendChild (ifrm);
	}
	else {
		ifrm			= iframes[0];
		ifrm.src		= src;
	}
	
}


getCookie = function ( name ) {
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);

	if (begin == -1) {
		begin = dc.indexOf(prefix);
		if (begin != 0) {
			return "";
		}
	}
	else {
		begin += 2;
	}

	var end = document.cookie.indexOf(";", begin);
	if (end == -1) {
		end = dc.length;
	}

	return unescape(dc.substring(begin + prefix.length, end));
}


getEPOQCookie = function ( CookieName ) {
	var SessionID   = "";

	if ( !CookieName || CookieName == "undefined" ) CookieName = "DePauli_SID";

	SessionID = getCookie ( CookieName );
	if ( SessionID == 0 || SessionID == "" || SessionID == null) {
		var dat = new Date ();

		SessionID = dat.getTime().toString(16) + (Math.random ()*1000000000000000000).toString(16);
		setCookie ( CookieName, SessionID, null, "/" );
	}
	return ( SessionID );
}



getXCoordinates = function ( e ) {
	var xcoord = 0;
	if( !e ) {
		if( window.event ) {
			//Internet Explorer
			e = window.event;
		} else {
			//total failure, we have no way of referencing the event
			return 0;
		}
	}
	
	if( typeof( e.pageX ) == 'number' ) {
		//most browsers
		xcoord = e.pageX;
	} else if( typeof( e.clientX ) == 'number' ) {
		//Internet Explorer and older browsers
		//other browsers provide this, but follow the pageX/Y branch
		xcoord = e.clientX;
		var badOldBrowser =	( window.navigator.userAgent.indexOf( 'Opera' ) + 1 ) ||
					( window.ScriptEngine && ScriptEngine().indexOf( 'InScript' ) + 1 ) ||
					( navigator.vendor == 'KDE' );
		if( !badOldBrowser ) {
			if( document.body && document.body.scrollLeft ) {
				//IE 4, 5 & 6 (in non-standards compliant mode)
				xcoord += document.body.scrollLeft;
			} else if( document.documentElement && document.documentElement.scrollLeft ) {
				//IE 6 (in standards compliant mode)
				xcoord += document.documentElement.scrollLeft;
			}
		}
	} else {
		//total failure, we have no way of obtaining the mouse coordinates
		return 0;
	}

	return xcoord;
}


getYCoordinates = function ( e ) {
	var ycoord = 0;

	if( !e ) {
		if( window.event ) {
			//Internet Explorer
			e = window.event;
		} else {
			//total failure, we have no way of referencing the event
			return 0;
		}
	}
	
	if( typeof( e.pageX ) == 'number' ) {
		//most browsers
		ycoord = e.pageX;
	} else if( typeof( e.clientX ) == 'number' ) {
		//Internet Explorer and older browsers
		//other browsers provide this, but follow the pageX/Y branch
		ycoord = e.clientY;
		var badOldBrowser =	( window.navigator.userAgent.indexOf( 'Opera' ) + 1 ) ||
					( window.ScriptEngine && ScriptEngine().indexOf( 'InScript' ) + 1 ) ||
					( navigator.vendor == 'KDE' );
		if( !badOldBrowser ) {
			if( document.body && document.body.scrollTop ) {
				//IE 4, 5 & 6 (in non-standards compliant mode)
				ycoord += document.body.scrollTop;
			} else if( document.documentElement && document.documentElement.scrollTop ) {
				//IE 6 (in standards compliant mode)
				ycoord += document.documentElement.scrollTop;
			}
		}
	} else {
		//total failure, we have no way of obtaining the mouse coordinates
		return 0;
	}

	return ycoord;
}


getOffsetLeft = function ( element ) {
	
	var left = element.offsetLeft;
	if ( element.offsetParent != null ) left += getOffsetLeft ( element.offsetParent );

	return ( left );
}


getOffsetTop = function ( element ) {
	
	var top = element.offsetTop;
	if ( element.offsetParent != null ) top += getOffsetTop ( element.offsetParent );

	return ( top );
}

addNewEventListener = function ( el, event, fkt, phase ) {
	// Lösche einen eventuell vorhandenen Eventlistener, damit nicht zwei gleiche Events hintereinander auftreten.
	removeNewEventListener ( el, event, fkt, phase );
	
	if (el.addEventListener) { // DOM-konform
		el.addEventListener ( event, fkt, phase );	// DOM: installiere den neuen Eventlistener
	}
	else {
		if ( el.attachEvent ) { // IE
			el.attachEvent ( "on"+event, fkt );	// IE: installiere den neuen Eventlistener
		}
	}
}

removeNewEventListener = function ( el, event, fkt, phase ) {
	if (el.removeEventListener) { // DOM-konform
		el.removeEventListener ( event, fkt, phase );	// DOM: Lösche einen eventuell vorhandenen Eventlistener
	}
	else {
		if ( el.detachEvent ) { // IE
			el.detachEvent ( "on"+event, fkt );	// IE: Lösche einen eventuell vorhandenen Eventlistener
		}
	}
}

hasItem = function ( arr, wert ) {
	for ( i=0; i<arr.length; i++ ) {
		if ( arr[i] == wert ) return ( i );
	}
	return ( -1 );
}

removeItem = function ( arr, pos ) {
	for ( i=pos; i<(arr.length-1); i++ ) arr[i] = arr[i+1];
	arr.pop();
	return ( arr );
}

getQueryStringValue = function ( name ) {
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var results = regex.exec( window.location.href );
	if( results == null ) {
		return "";
	}
	else {
		return results[1];
	}
}

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			   string: navigator.userAgent,
			   subString: "iPhone",
			   identity: "iPhone/iPod"
	    	},
	    	{
	    		   string: navigator.userAgent,
	    		   subString: "iPad",
	    		   identity: "iPad"
	    	},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

/*
 * Gr 2010-12-14
 * 		 	Slideshow mit Ueberblend-Effekt erzeugen
 * 			Slideshow-Komponente und die einzelenen Slideshow-Bilder werden 
 * 			ueber den Startseitengenerator angelegt und verwaltet.
 * 
 */

// init vars
var intSlideShowItems = 0;
var intSlideShowPosition = 1; // array index of next slideshow element to load
var intSlideShowInterval = 4000; // display each image x milliseconds
var intSlideShowFadeTime = 2000;
var activeSlideShow = null;
var pauseSlideShow = null;
var bSlideShowRepeat = true; // run slideshow continuously after pageload 
// create array 
var arrSlideShowImages = new Array();

var intOldPos = null;

function vanish() {
	// fade div CurrentSideImg out
	$("#NextSlideImage").css("display", "block");

	// move marker for active control element
	updateControls(intSlideShowPosition);
	
	// get top div
	$("#CurrentSlideImage").fadeToggle(intSlideShowFadeTime, 'swing');

	// wait for fadeout to complete, call swapImages
	activeSlideShow = window.setTimeout("swapImages()", intSlideShowFadeTime);
}

function swapImages() {
	activeSlideShow = null;
	// get faded out div
	var currentTop = $("#CurrentSlideImage");
	// get div displayed currently
	var currentBack = $("#NextSlideImage");

    intOldPos = intSlideShowPosition;

	currentTop.css("display", "none");

	intSlideShowPosition ++;
	intSlideShowPosition = intSlideShowPosition % intSlideShowItems; // valid range: 0 - (arrSlideImage.length -1) 
	
	// put #CurrentSlideImage in the background
	currentTop.attr("class", "SlideShowHidden");
	currentTop.attr("id", "temp");
	currentTop.children("a:first-child").attr("id", "temp");
	currentTop.children("a:first-child img:first-child").attr("id", "temp");
	
	currentBack.attr("id", "CurrentSlideImage"); // put new img to top
	// update id of a- and img-tag
	currentBack.children("a:first-child").attr("id", "SlideLinkCurrent");
	currentBack.children("a:first-child img:first-child").attr("id", "SlideCurrent");
	
	// update onclick attribute:
	// check if array contains legitimate function call - checkEval usually is defined in control_....js
	if ( checkEval(arrSlideShowImages[intOldPos][2]) == true ) {
		strCurrLmc = "arrSlideShowImages[" + intOldPos + "][2]";
        $("#CurrentSlideImage").unbind("click").click(function() { execute( eval(strCurrLmc) ); return false; });
	} else {
		$("#CurrentSlideImage").unbind("click");
	}
	
	currentTop.attr("id", "NextSlideImage");
	// update innerHTML
	currentTop.children("a:first-child").attr("id", "SlideLinkNext");
	currentTop.children("a:first-child").attr("href", arrSlideShowImages[intSlideShowPosition][1]);

	strImgTag = assembleImgTag(intSlideShowPosition);
	currentTop.children("a:first-child").attr("innerHTML", strImgTag);
	
    // update onclick attrib. for background-element:
	if ( intSlideShowPosition > -1 && checkEval(arrSlideShowImages[intSlideShowPosition][2]) == true ) {
		strNextLmc = "arrSlideShowImages[" + intSlideShowPosition + "][2]";
        $("#NextSlideImage").unbind("click").click(function() { execute( eval(strNextLmc) ); return false; });
	} else {
		$("#NextSlideImage").unbind("click");
	}

	currentTop.attr("class", "");
	$("#CurrentSlideImage").css("display", "block");
	
	if(bSlideShowRepeat) {
		// display image for intSlideShowInterval ms
		pauseSlideShow = window.setTimeout("vanish()", intSlideShowInterval);
	}
}

function stopSlideshow(){

	if (activeSlideShow != null) {
		updateControls(intSlideShowPosition);
	}
	
	if (pauseSlideShow != null) intSlideShowPosition--; // intSlideShowPosition points to index of displayed img 
	
	// clear any active timeouts
	window.clearTimeout(activeSlideShow);
	activeSlideShow= null;
	window.clearTimeout(pauseSlideShow);
	pauseSlideShow = null;
	// toggle jQuery animations off globally
	$.fx.off;
	bSlideShowRepeat = false; // interrupt slideshow
	$.fx.on;
	$("#SlideCtrlStop").attr("class", "SlideControl SlideShowDisabled");
	$("#SlideCtrlStart").attr("class", "SlideControl");
	$("#SlideCtrlStart").show();
}

function showSlide(intArrayIdx) {
	$("#NextSlideImage").attr("style", "display: none;");
	
	// make sure nothing slideshow-related is happening
	if ( activeSlideShow != null || pauseSlideShow != null || bSlideShowRepeat ) {stopSlideshow();}

	if (intSlideShowPosition != intArrayIdx) {

		tmp = $("#CurrentSlideImage");

		tmp.children("a:first-child").attr("href", arrSlideShowImages[intArrayIdx][1]);
		tmp.children("a:first-child").attr("innerHTML", assembleImgTag(intArrayIdx));
		// update onclick
		if ( checkEval(arrSlideShowImages[intArrayIdx][2]) == true ) {
			strLmc = "arrSlideShowImages[" + intArrayIdx + "][2]";
            tmp.unbind("click").click(function() { execute( eval(strLmc) ); return false; });
		} else {
			tmp.unbind("click");
		}
		
	}
	updateControls(intArrayIdx);
	intSlideShowPosition = intArrayIdx;
	
	// take care of possibly set style="display:none;"  
	$("#CurrentSlideImage").addClass("SlideShowForceDisplay");
}

function assembleImgTag(intArrayIdx) {
	strImgTag = "";
	
	try {
		strImgTag = "<img src=\"" + arrSlideShowImages[intArrayIdx][0] + "\"alt=\"";
		strImgTag = strImgTag + arrSlideShowImages[intArrayIdx][3];
		strImgTag = strImgTag + "\" id=\"SlideCurrent\" style=\"\" \/>";
	} catch (e) {
	}	
	
	return strImgTag;
}

function updateControls(intNewPosition) {
	// move marker for active control element 
	$("#SlideControls div").removeClass("SlideControlActive");
	$("#SlideCtrl" + intNewPosition).addClass("SlideControlActive");
}

// Gr 2011-05-06 - Prev / Next-Btn fuer fashionsisters

function showNextSlide() {
	var next = intSlideShowPosition;
	if ( !bSlideShowRepeat ) next++;
    // make sure that next is a valid index of the image-array
    if ( next > (arrSlideShowImages.length -1) ) next = 0;
	showSlide(next);
	updateControls(next);
}

function showPreviousSlide() {
	var next = intSlideShowPosition;
	if ( bSlideShowRepeat ) next--;
	next--;
    // make sure that next is a valid index of the image-array
	if ( next < 0 ) next = arrSlideShowImages.length + next;
	showSlide(next);
	updateControls(next);
}


function startShow() {
	if (arrSlideShowImages.length >= 2) {
		var intIdx = 0;
		var bStartedManually = false;
		
		// start Slideshow via start-btn.
		if ( !bSlideShowRepeat ) {
			intIdx = intSlideShowPosition;
			bSlideShowRepeat = true;
			$("#SlideCtrlStart").attr("class", "SlideControl SlideShowDisabled");
			$("#SlideCtrlStart").hide();
			bStartedManually = true;
		}

		// init img tag attributes
		$("#SlideCurrent").attr("src", arrSlideShowImages[intIdx][0]);
		$("#SlideCurrent").attr("alt", arrSlideShowImages[intIdx][3]);
		
		tmp = $("#SlideLinkCurrent");
		tmp.attr("href", arrSlideShowImages[intIdx][1]);
		
		// set onclick current:		
		if ( checkEval( arrSlideShowImages[intIdx][2]) == true ) {
            strLmc = "arrSlideShowImages[" + intIdx + "][2]";
			$("#CurrentSlideImage").unbind("click").click(function() { execute(eval(strLmc)); return false; });
		} else {
			$("#CurrentSlideImage").unbind("click");
		}

		++intIdx;

		if ( intIdx > (arrSlideShowImages.length -1) ) intIdx = 0;

		$("#SlideNext").attr("src", arrSlideShowImages[intIdx][0]);
		$("#SlideNext").attr("alt", arrSlideShowImages[intIdx][3]);

		tmp = $("#SlideLinkNext");
		tmp.attr("href", arrSlideShowImages[intIdx][1]);
		
		// set onclick next:		
/*
		if ( checkEval( arrSlideShowImages[intIdx][2]) == true ) {
			$("#NextSlideImage").unbind("click").click(function() { execute( arrSlideShowImages[intIdx][2]); return false; });
		} else {
			$("#NextSlideImage").unbind("click");
		}
*/

        $("#NextSlideImage").css("display", "none");
        $("#CurrentSlideImage").css("display", "block");

		if ( !bStartedManually ) {
		pauseSlideShow = window.setTimeout("vanish()", intSlideShowInterval);
		} else {
			bStartedManually = false;
			// move marker for active control element
			updateControls(intIdx);
			vanish();
		}
	}
}

function execute( strFunctionCall ) {
	var topOpacity = $("#CurrentSlideImage").css("opacity");

	if ( topOpacity != undefined && topOpacity <= 0.35 && topOpacity > 0.0 ) {
		// foreground img nearly faded out, use onclick of background image
		$("#CurrentSlideImage").css("opacity", "0");
		$("#NextSlideImage").click();
	} else {
		try {
			stopSlideshow();
			// strFunctionCall = strFunctionCall.replace(/return false;/gi, "");
			strFunctionCall = strFunctionCall.replace(/return[\W\d\s]+false[\W\d\s]*;/gi, "");
			eval( strFunctionCall );
		} catch (err) {}

	}
}

/* Slideshow end */

function stripHTML(str) {
	var re= /<\S[^><]*>/g
	str = str.replace(re, "");
	return str.replace(/\&nbsp\;/g, " ");
}

function replaceUmlauteforFile(filename) {
	if (typeof filename != "number" && typeof filename != "string" ) {
		return filename;
	}
	if (filename == "") return "";
	if (typeof filename == "number") filename = String(filename);
	var result = filename;
	result=result.replace(/\u00fc/g, "ue");
	result=result.replace(/\u00f6/g, "oe");
	result=result.replace(/\u00e4/g, "ae");
	result=result.replace(/\u00dc/g, "UE");
	result=result.replace(/\u00d6/g, "OE");
	result=result.replace(/\u00c4/g, "AE");
	result=result.replace(/\u00df/g, "ss");
	result=result.replace(/\/-/g, "-");
	result=result.replace(/\//g, "-");
	return result;
}


htmlspecialchars  = function(str) {
	if (typeof(str) == "string") {
		str = str.replace(/;/g, "");
		str = str.replace(/"/g, "&quot;");
		str = str.replace(/</g, "&lt;");
		str = str.replace(/>/g, "&gt;");
	}
	return str;
 }
