/*<![CDATA[*/

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * Javascript Functions      														   *
 * ----------------------------------------------------------------------------------- *
 * Version:					1.0													   *
 * Author:					re-lounge (http://www.re-lounge.com)					   *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 			*/
 
/* --------------------------------------------------------------------------------------
 * FUNCTION P7_limit(a,b) 
 * --------------------------------------------------------------------------------------
 * Emulates min-width functionality in IE. (v1.1.2)
 * Author: P7, www.projectseven.com
 */
function P7_limit(a,b) {
	return;
	document.p7limit=a;
	document.p7min=b;
 	if(document.getElementById&&navigator.appVersion.indexOf("MSIE")>-1&&!window.opera){
		if(window.attachEvent){
			window.attachEvent("onresize",P7_setMinWidth);
			window.attachEvent("onload",P7_setMinWidth);
		} else {
			onload=P7_setMinWidth;
			onresize=P7_setMinWidth;
		}
	}
}
P7_limit('pageContainer',995);

/* --------------------------------------------------------------------------------------
 * FUNCTION P7_setMinWidth()
 * --------------------------------------------------------------------------------------
 * Emulates min-width functionality in IE. (v1.1.2)
 * Author: P7, www.projectseven.com
 */
function P7_setMinWidth(){
	return;
	var cw,w,pl,pr,ml,mr,br,bl,ad,theDiv=document.p7limit;
	var g=document.getElementById(theDiv);
	w=parseInt(document.p7min);
	if(g&&document.body&&document.body.clientWidth){
		gs=g.currentStyle;
		cw=parseInt(document.body.clientWidth);
		pl=parseInt(gs.paddingLeft);
		pr=parseInt(gs.paddingRight);
		ml=parseInt(gs.marginLeft);
		mr=parseInt(gs.marginRight);
		bl=parseInt(gs.borderLeftWidth);
		br=parseInt(gs.borderRightWidth);
		ml=ml?ml:0;
		mr=mr?mr:0;
		pl=pl?pl:0;
		pr=pr?pr:0;
		bl=bl?bl:0;
		br=br?br:0;
		ad=pl+pr+ml+mr+bl+br;
		if(cw<=w){
			w-=ad;
			g.style.width=w+"px";
		} else {
			g.style.width="auto";
		}
	}
}

/* --------------------------------------------------------------------------------------
 * FUNCTION openBigPicture()
 * --------------------------------------------------------------------------------------
 * Defines width and high of popup that will be opened big image
 * Author: re-lounge, http://www.re-lounge.com
 */
function openBigPicture( url , name ) {
	if (navigator.appName == "Microsoft Internet Explorer") {
		openWindow(url,name,'790','580');
	}
	else {
		openWindow(url,name,'790','550');
	}
}

/* --------------------------------------------------------------------------------------
 * FUNCTION openGalery()
 * --------------------------------------------------------------------------------------
 * Defines width and high of popup that will be opened for showing galery-images
 * Author: re-lounge, http://www.re-lounge.com
 */
function openGalery( url , name ) {
	openWindow(url,name,'790','580');
}


/* --------------------------------------------------------------------------------------
 * FUNCTION openWindow()
 * --------------------------------------------------------------------------------------
 * Opens a popup window.
 * Author: re-lounge, http://www.re-lounge.com
 */
function openWindow( url , name , width , height ){
	window.open(url,name,"width="+width+",height="+height+",scrollbars=yes");
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 *																					   *
 * 	service related functions	  												       *
 *																					   *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 			*/

/* --------------------------------------------------------------------------------------
 * FUNCTION showCssObject(obj)
 * --------------------------------------------------------------------------------------
 * Shows the element referenced by "obj".
 * Author: re-lounge, http://www.re-lounge.com
 */
function showCssObject(obj) {
	obj.style.display = "block";
}

/* --------------------------------------------------------------------------------------
 * FUNCTION hideCssObject(obj)
 * --------------------------------------------------------------------------------------
 * Hides the element referenced by "obj".
 * Author: re-lounge, http://www.re-lounge.com
 */
function hideCssObject(obj) {
	obj.style.display = "none";
}

/* --------------------------------------------------------------------------------------
 * FUNCTION closeRegister(id)
 * --------------------------------------------------------------------------------------
 * Closes the register with "id" reference and hides or shows the appropriate register 
 * headlines.
 * Author: re-lounge, http://www.re-lounge.com
 */
function closeRegister(id) {
	SetCookie(id,"1",expdateAll,"/");
	hideCssObject(document.getElementById(id));
	hideCssObject(document.getElementById(id+"_link_close"));
	showCssObject(document.getElementById(id+"_link_open"));
}

/* --------------------------------------------------------------------------------------
 * FUNCTION openRegister(id)
 * --------------------------------------------------------------------------------------
 * Opens the register with "id" reference and hides or shows the appropriate register 
 * headlines.
 * Author: re-lounge, http://www.re-lounge.com
 */
function openRegister(id) {
	DeleteCookie(id,"/");
	showCssObject(document.getElementById(id));
	showCssObject(document.getElementById(id+"_link_close"));
	hideCssObject(document.getElementById(id+"_link_open"));
}

/* --------------------------------------------------------------------------------------
 * FUNCTION initRegister()
 * --------------------------------------------------------------------------------------
 * Initialises all registers and register headlines after page loading. Uses cookies to
 * do that. 
 * Author: re-lounge, http://www.re-lounge.com
 */
function initRegister() {
	//alert("initRegister");
	for(var i = 0; i < regArray.length; i++ ) {
		//wenn kein Cookie da, Register offen zeigen
		if (GetCookie(regArray[i])==null) {	
			showCssObject(document.getElementById(regArray[i]));
			showCssObject(document.getElementById(regArray[i]+"_link_close"));
			hideCssObject(document.getElementById(regArray[i]+"_link_open"));
		} 
		//wenn Cookie da, Register geschlossen zeigen
		else {
			if(document.getElementById(regArray[i]) != null) {
				hideCssObject(document.getElementById(regArray[i]));
				hideCssObject(document.getElementById(regArray[i]+"_link_close"));
				showCssObject(document.getElementById(regArray[i]+"_link_open"));			
			}
		}
	}
}

//for template home.html
//var regArray = ['fontsize','doc2','doc3','doc4','doc5']; 
//for template content.html
//var regArray = ['fontsize','doc5']; 
//event_attach( 'onload' , initRegister );

/* --------------------------------------------------------------------------------------
 * FUNCTION event_attach()
 * --------------------------------------------------------------------------------------
 * Takes care of attaching event handlers (functions) to events. this 
 * simplifies the process of attaching multiple handlers to a single event
 * Author: Ruthsarian, http://webhost.bridgew.edu/etribou/layouts/
 */
function event_attach( event , func ) {
	if ( ( typeof( func ) ).toLowerCase() != 'function' ) {
		return;
	}
	if ( ( typeof( document.event_handlers ) ).toLowerCase() == 'undefined' ) {
		document.event_handlers = new Array();
	}
	if ( ( typeof( document.event_handlers[ event ] ) ).toLowerCase() == 'undefined' ) {
		document.event_handlers[ event ] = new Array();
	}
	if ( window.attachEvent ) {
		window.attachEvent( event , func );
	} else {
		if ( ( typeof( eval( 'window.' + event ) ) ).toLowerCase() != 'function' ) {
			eval( 'window.' + event + ' = function () { if ( ( typeof( document.event_handlers[ \'' + event + '\' ] ) ).toLowerCase() != \'undefined\' ) { for ( i = 0 ; i < document.event_handlers[ \'' + event + '\' ].length ; i++ ) { document.event_handlers[ \'' + event + '\' ][ i ](); } } } ' );
		}
		document.event_handlers[ event ][ document.event_handlers[ event ].length ] = func;
	}
}

/* --------------------------------------------------------------------------------------
 * FUNCTION setStylesheet()
 * --------------------------------------------------------------------------------------
 * Changes current stylesheet (to given stylesheet reference "val") and reloads page.
 * Author: re-lounge, http://www.re-lounge.com
 */
function setStylesheet(val) {
	// Set cookie
	SetCookie("style",val,expdateAll,"/");
	// Reload
	window.history.go(0);
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 *																					   *
 * 	Cookie related functions														   *
 *																					   *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 			*/

/* --------------------------------------------------------------------------------------
 * FUNCTION cookiesEnabled()
 * --------------------------------------------------------------------------------------
 * Verifies if cookies are enabled and writes "true" or "false" in a global variable.
 * Author: re-lounge, http://www.re-lounge.com
 */
function cookiesEnabled(){
	var now = new Date();
	var val = String(now.getTime());
	SetCookie("cookieTest",val);
	cookiesEnabled = false;
	if (GetCookie("cookieTest")==val)
		return true;
	else
		return false;
} 
var cookiesEnabled = cookiesEnabled();
 
/* --------------------------------------------------------------------------------------
 * FUNCTION initCookieDate()
 * --------------------------------------------------------------------------------------
 * Initialises cookie expiries for new and changed cookies.
 * Author: re-lounge, http://www.re-lounge.com
 *
 * The following data is collected in cookies:
 *
 * - Current style used
 * - Current view of service elements in service area (open or closed)
 * - Current view service area (open or closed)
 *
 * The cookie expiry is 3 months for all element data.
 *
 */
function initCookieDate(){
	expdateAll = new Date ();
	expdateAll.setTime(expdateAll.getTime() + (3 * 30 * 24 * 60 * 60 * 1000));	// 3 Monate
}
initCookieDate();

// --------------------------------------------------------------------------------------
//  Cookie Functions -- "Night of the Living Cookie" Version (25-Jul-96)
// --------------------------------------------------------------------------------------
//
//  Written by:  Bill Dortch, hIdaho Design <bdortch@hidaho.com>
//  The following functions are released to the public domain.
//
//  This version takes a more aggressive approach to deleting
//  cookies.  Previous versions set the expiration date to one
//  millisecond prior to the current time; however, this method
//  did not work in Netscape 2.02 (though it does in earlier and
//  later versions), resulting in "zombie" cookies that would not
//  die.  DeleteCookie now sets the expiration date to the earliest
//  usable date (one second into 1970), and sets the cookie's value
//  to null for good measure.
//
//  Also, this version adds optional path and domain parameters to
//  the DeleteCookie function.  If you specify a path and/or domain
//  when creating (setting) a cookie**, you must specify the same
//  path/domain when deleting it, or deletion will not occur.
//
//  The FixCookieDate function must now be called explicitly to
//  correct for the 2.x Mac date bug.  This function should be
//  called *once* after a Date object is created and before it
//  is passed (as an expiration date) to SetCookie.  Because the
//  Mac date bug affects all dates, not just those passed to
//  SetCookie, you might want to make it a habit to call
//  FixCookieDate any time you create a new Date object:
//
//    var theDate = new Date();
//    FixCookieDate (theDate);
//
//  Calling FixCookieDate has no effect on platforms other than
//  the Mac, so there is no need to determine the user's platform
//  prior to calling it.
//
//  This version also incorporates several minor coding improvements.
//
//  **Note that it is possible to set multiple cookies with the same
//  name but different (nested) paths.  For example:
//
//    SetCookie ("color","red",null,"/outer");
//    SetCookie ("color","blue",null,"/outer/inner");
//
//  However, GetCookie cannot distinguish between these and will return
//  the first cookie that matches a given name.  It is therefore
//  recommended that you *not* use the same name for cookies with
//  different paths.  (Bear in mind that there is *always* a path
//  associated with a cookie; if you don't explicitly specify one,
//  the path of the setting document is used.)
//  
//  Revision History:
//
//    "Toss Your Cookies" Version (22-Mar-96)
//      - Added FixCookieDate() function to correct for Mac date bug
//
//    "Second Helping" Version (21-Jan-96)
//      - Added path, domain and secure parameters to SetCookie
//      - Replaced home-rolled encode/decode functions with Netscape's
//        new (then) escape and unescape functions
//
//    "Free Cookies" Version (December 95)
//
//
//  For information on the significance of cookie parameters, and
//  and on cookies in general, please refer to the official cookie
//  spec, at:
//
//      http://www.netscape.com/newsref/std/cookie_spec.html    
//
//******************************************************************
//
// "Internal" function to return the decoded value of a cookie
//
function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}
//
//  Function to correct for 2.x Mac date bug.  Call this function to
//  fix a date object prior to passing it to SetCookie.
//  IMPORTANT:  This function should only be called *once* for
//  any given date object!  See example at the end of this document.
//
function FixCookieDate (date) {
  var base = new Date(0);
  var skew = base.getTime(); // dawn of (Unix) time - should be 0
  if (skew > 0)  // Except on the Mac - ahead of its time
    date.setTime (date.getTime() - skew);
}
//
//  Function to return the value of the cookie specified by "name".
//    name - String object containing the cookie name.
//    returns - String object containing the cookie value, or null if
//      the cookie does not exist.
//
function GetCookie (name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
      return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break; 
  }
  return null;
}
//
//  Function to create or update a cookie.
//    name - String object containing the cookie name.
//    value - String object containing the cookie value.  May contain
//      any valid string characters.
//    [expires] - Date object containing the expiration data of the cookie.  If
//      omitted or null, expires the cookie at the end of the current session.
//    [path] - String object indicating the path for which the cookie is valid.
//      If omitted or null, uses the path of the calling document.
//    [domain] - String object indicating the domain for which the cookie is
//      valid.  If omitted or null, uses the domain of the calling document.
//    [secure] - Boolean (true/false) value indicating whether cookie transmission
//      requires a secure channel (HTTPS).  
//
//  The first two parameters are required.  The others, if supplied, must
//  be passed in the order listed above.  To omit an unused optional field,
//  use null as a place holder.  For example, to call SetCookie using name,
//  value and path, you would code:
//
//      SetCookie ("myCookieName", "myCookieValue", null, "/");
//
//  Note that trailing omitted parameters do not require a placeholder.
//
//  To set a secure cookie for path "/myPath", that expires after the
//  current session, you might code:
//
//      SetCookie (myCookieVar, cookieValueVar, null, "/myPath", null, true);
//
function SetCookie (name,value,expires,path,domain,secure) {
  document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}

//  Function to delete a cookie. (Sets expiration date to start of epoch)
//    name -   String object containing the cookie name
//    path -   String object containing the path of the cookie to delete.  This MUST
//             be the same as the path used to create the cookie, or null/omitted if
//             no path was specified when creating the cookie.
//    domain - String object containing the domain of the cookie to delete.  This MUST
//             be the same as the domain used to create the cookie, or null/omitted if
//             no domain was specified when creating the cookie.
//
function DeleteCookie (name,path,domain) {
  if (GetCookie(name)) {
    document.cookie = name + "=" +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

/*]]*/
