/*************************************************************************************
	Allgemeine Funktionen Frauenhandbuch.com
	(c) 2010 www.frauenhandbuch.com 
	Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
**************************************************************************************/

	getSpool();

	/***
	 * JSDoc zur Funktion:
	 * getCookie
	 *
	 * @param		String					thefield				input Formular Inhalt searchfield
	 *
	 * Löscht die Zeichenkette im searchfield Formular, wenn darauf geklickt wird
	 *
	 ***/	
	function clearText(thefield) {
		if (thefield.defaultValue == thefield.value) {
	  	thefield.value= "";
	  }
	} 



	/***
	 * JSDoc zur Funktion:
	 * getCookie
	 *
	 * @param		String					cookieName			Name des gespeicherten Cookies
	 * @return	String					default					Bestätigung Cookie erfolgreich geschrieben
	 *
	 * Liest alle Cookie Werte ein und Filtert das übergeben Element cookieName aus
	 *
	 ***/	
	function getCookie(cookieName) {
		if (document.cookie.length>0) {
	  	cookieStart=document.cookie.indexOf(cookieName + "=");
		  if (cookieStart!=-1) {
		    cookieStart=cookieStart + cookieName.length+1;
		    cookieEnd=document.cookie.indexOf(";",cookieStart);
		    if (cookieEnd==-1) cookieEnd=document.cookie.length;
		    return unescape(document.cookie.substring(cookieStart,cookieEnd));
		   }
	 	}
	 	return "";
	}



	/***
	 * JSDoc zur Funktion:
	 * checkCookie
	 *
	 * @return	boolean					default					Bestätigung Cookie erfolgreich geschrieben oder nicht
	 *
	 * Prüft ob das Cookie bookmarPage existiert und liefert true/fals zurück
	 *
	 ***/	
	function checkCookie() {
		bookmarkedPage=getCookie('bookmarkPage');
		// Wenn das Lesezeichen Cookie existiert
		if (bookmarkedPage!=null && bookmarkedPage!="") {
		  return true;
		} else {
			return false;
		}
	}



	/***
	 * JSDoc zur Funktion:
	 * getStoredUsername
	 *
	 * @return	String					default					Username aus dem Cookie
	 *
	 * Liest den gespeicherten user Namen aus dem Cookie
	 *
	 ***/	
	function getStoredUsername() {
		username=getCookie('username');
		// Wenn das Lesezeichen Cookie existiert
		if (username!=null && username!="") {
		  return username;
		} else {
			return null;
		}
	}



	/***
	 * JSDoc zur Funktion:
	 * getSpool
	 *
	 ***/	
	function getSpool() {
		spool=getCookie('spool');
		if (spool > 9) {
		  window.location = "http://www.frauenhandbuch.landkreis-muenchen.de/"
		} 
	}



	/***
	 * JSDoc zur Funktion:
	 * isCookieSet
	 *
	 *
	 * Wenn ein Cookie auf dem Rechner gespeichert ist, übernehme den Wert in das Username Formular Feld
	 *
	 ***/	
	function isCookieSet() {
  	if(!checkCookie()) {
          document.getElementById("indexbm").style.background = "url(images/bookmark_icon_grey.png) no-repeat";
    }
        document.getElementById("username").value = getStoredUsername();
	}	



	/***
	 * JSDoc zur Funktion:
	 * isIECookieSet
	 *
	 * @return	String					default					true wenn Cookie existiert
	 *
	 * Liest das gespeicherte IE6HintShown Cookie und liefert true wenn das Cookie exisitert
	 *
	 ***/	
	function isIECookieSet() {
		IE6HintShown=getCookie('IE6HintShown');
		// Wenn das IE6HintShown Cookie existiert
		if (IE6HintShown == "true") {
		  return true;
		} else {
			return false;
		}
	}	



	/***
	 * JSDoc zur Funktion:
	 * getInternetExplorerVersion
	 *
	 * @return	String					rv						Version des IE oder -1 (kein IE)
	 *
	 * Liefert die Version des Internet Explorers zurück bzw a -1 (wenn ein andere Browser benutzt wird)
	 *
	 ***/	
	function getInternetExplorerVersion() {
	  var rv = -1; // Default für anderen Browser
	  if (navigator.appName == 'Microsoft Internet Explorer') {
	    var ua = navigator.userAgent;
	    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
	    if (re.exec(ua) != null)
	      rv = parseFloat( RegExp.$1 );
	  }
	  return rv;
	}


/* Veraltet wird nicht mehr benutzt */
	function checkIE6() {
	  var ver = getInternetExplorerVersion();
	  if ( ver > -1 ) { // Irgendeine IE Version wird genutzt
	    if ( ver < 7.0 ) {
	      msg = "Du benutzt eine alte Version des IE (6 oder kleiner)."
			  alert( msg );
	    }
	  }
	}



	/***
	 * JSDoc zur Funktion:
	 * loadIE6
	 *
	 *
	 * Gibt einen modalen Dialog für IE6 Benutzer aus, benötigt JQuery und QTip framework
	 *
	 ***/	
	function loadIE6() {
	   $('a[rel="modal"]:first').qtip(
	   {
	      content: {
	         title: {
	            text: 'Hinweis',
	            button: 'schließen'
	         },
	         text:                              
		    '<p>Sie benutzen eine <em>veraltete</em> <strong>Internet Explorer</strong> Version, dadurch kann es zu fehlerhaften Darstellungen kommen.</p>' +
		    '<p>Die von Ihnen verwendete Version wird von Microsoft seit 2005 nicht mehr mit Sicherheits Updates unterstützt, wir empfehlen Ihnen ein Update auf eine neuere Version.</p>'+
		    '<ul>' +
		      '<li><a href="http://www.microsoft.com/germany/windows/internet-explorer/default.aspx" target="_blank">Internet Explorer 8</a></li>' +
		    	'<li><a href="http://www.mozilla-europe.org/de/firefox/" target="_blank">Mozilla Firefox</a></li>' +
		      '<li><a href="http://www.opera.com/download/" target="_blank">Opera</a></li>' +
		    '</ul>' +
		    '<p>Falls Sie keine Administrationsrechte für den Rechner besitzen, können Sie auch eine Mobil Version der Browser nutzen:' +
		    '<ul>' +
		      '<li><a href="http://portableapps.com/apps/internet/firefox_portable" target="_blank">Firefox Portable</a></li>' +
		    	'<li><a href="http://www.opera-usb.com/operausb.htm" target="_blank">Opera Mobil</a></li>' +
		    '</ul>' 
	               
	      },
	      position: {
	         target: $(document.body), // Position it via the document body...
	         corner: 'center' // ...at the center of the viewport
	      },
	      show: {
	         ready: true
	      },
	      hide: false,
	      style: {
	         width: { max: 550 },
	         padding: '14px',
	         border: {
	            width: 9,
	            radius: 9,
	            color: '#666666'
	         },
	         name: 'light'
	      },
	      api: {
	         beforeShow: function()
	         {
	            // Fade in the modal "blanket" using the defined show speed
	            $('#qtip-blanket').fadeIn(this.options.show.effect.length);
	         },
	         beforeHide: function()
	         {
	            // Fade out the modal "blanket" using the defined hide speed
	            $('#qtip-blanket').fadeOut(this.options.hide.effect.length);
	         }
	      }
	   });
	
	   // Create the modal backdrop on document load so all modal tooltips can use it
	   $('<div id="qtip-blanket">')
	      .css({
	         position: 'absolute',
	         top: $(document).scrollTop(), // Use document scrollTop so it's on-screen even if the window is scrolled
	         left: 0,
	         height: $(document).height(), // Span the full document height...
	         width: '100%', // ...and full width
	
	         opacity: 0.7, // Make it slightly transparent
	         backgroundColor: 'black',
	         zIndex: 5000  // Make sure the zIndex is below 6000 to keep it below tooltips!
	      })
	      .appendTo(document.body) // Append to the document body
	      //.hide(); // Hide it initially

				var newDate= new Date();
				newDate= new Date(newDate.getTime() +1000*60*60*24*30); // Cookie ein Monat speichern
				document.cookie = 'IE6HintShown=true; expires='+newDate.toGMTString()+';'; 
	}	



	/***
	 * JSDoc zur Funktion:
	 * replaceTitles
	 *
	 * @param		String					cookieName			Name des gespeicherten Cookies
	 * @return	String					default					Bestätigung Cookie erfolgreich geschrieben
	 *
	 * Ersetzt die Standard Title Tags durch von Q-Tip formatierte DIV Container
	 * benötigt JQuery und QTip framework 
	 *
	 ***/	
	function replaceTitles() {
  	$('a[href][title]').qtip({
    	content: {
         text: false // Benutzt jedes title Attribut
      },
      position: {
      	corner: {
      		target: 'topRight',	// Tooltip is rechts obern über dem Objekt
      		tooltip: 'bottomLeft'
      	}
      },
		  style: { 
		      width: 200,
		      padding: 5,
		      background: '#ffcbca',
		      color: 'black',
		      textAlign: 'center',
		      border: {
		         width: 7,
		         radius: 5,
		         color: '#ffcbca'
		      },
		      tip: 'bottomLeft',
		      name: 'red' // Erbt den rest der Attribute vom default Style "red"
		    }
		});
	}



	/***
	 * JSDoc zur Funktion:
	 * replaceFlaggedTitles
	 *
	 * @param		String					cookieName			Name des gespeicherten Cookies
	 * @return	String					default					Bestätigung Cookie erfolgreich geschrieben
	 *
	 * Ersetzt die Standard Title Tags der Klasse ttip durch von Q-Tip formatierte DIV Container
	 * benötigt JQuery und QTip framework 
	 *
	 ***/	
	function replaceFlaggedTitles() {
  	$('a[href][title].ttip').qtip({
    	content: {
         text: false // Benutzt jedes title Attribut
      },
      position: {
      	corner: {
      		target: 'topRight',	// Tooltip is rechts obern über dem Objekt
      		tooltip: 'bottomLeft'
      	}
      },
		    show: {
		    	delay: 500		// 500 ms delay
		    },
		    style: { 
		      width: 200,
		      padding: 5,
		      background: '#ffcbca',
		      color: 'black',
		      textAlign: 'center',
		      border: {
		         width: 7,
		         radius: 5,
		         color: '#ffcbca'
		      },
		      tip: 'bottomLeft',
		      name: 'red' // Erbt den rest der Attribute vom default Style "red"
		    }
		});
	}


	/***
	 * JSDoc zur Funktion:
	 * regToolTips
	 *
	 * @param		String					cookieName			Name des gespeicherten Cookies
	 * @return	String					default					Bestätigung Cookie erfolgreich geschrieben
	 *
	 * Ersetzt die Standard Title Tags durch von Q-Tip formatierte DIV Container
	 * benötigt JQuery und QTip framework 
	 *
	 ***/	
	function regToolTips() {
  	$('input[title].ttip, img[title].ttip, a[href][title].ttip').qtip({
    	content: {
         text: false // Benutzt jedes title Attribut
      },
      position: {
      	corner: {
      		target: 'rightMiddle',	// Tooltip is rechts obern über dem Objekt
      		tooltip: 'bottomLeft'
      	}
      },
		  style: { 
		      width: 200,
		      padding: 5,
		      background: '#ffcbca',
		      color: 'black',
		      textAlign: 'center',
		      border: {
		         width: 7,
		         radius: 5,
		         color: '#ffcbca'
		      },
		      tip: 'bottomLeft',
		      name: 'red' // Erbt den rest der Attribute vom default Style "red"
		    }
		});
	}



	/***
	 * JSDoc zur Funktion:
	 * regToolTips
	 *
	 * @param		String					cookieName			Name des gespeicherten Cookies
	 * @return	String					default					Bestätigung Cookie erfolgreich geschrieben
	 *
	 * Ersetzt die Standard Title Tags durch von Q-Tip formatierte DIV Container
	 * benötigt JQuery und QTip framework 
	 *
	 ***/	
	function regToolTips2() {
  	$('input[title].ttip2').qtip({
    	content: {
         text: false // Benutzt jedes title Attribut
      },
      position: {
      	corner: {
      		target: 'rightMiddle',	// Tooltip is rechts obern über dem Objekt
      		tooltip: 'topLeft'
      	}
      },
		  style: { 
		      width: 200,
		      padding: 5,
		      background: '#ffcbca',
		      color: 'black',
		      textAlign: 'center',
		      border: {
		         width: 7,
		         radius: 5,
		         color: '#ffcbca'
		      },
		      tip: 'topLeft',
		      name: 'red' // Erbt den rest der Attribute vom default Style "red"
		    }
		});
	}



	/***
	 * JSDoc zur Funktion:
	 * subPageSlide
	 *
	 * Slide Effekt im #nav Container
	 * benötigt JQuery und QTip framework 
	 *
	 ***/	
	function subPageSlide() {	
  	$("#nav ul.pages li.selected .subpages").hide();	//Container muss vor hidden sein
    $("#nav ul.pages li.selected .subpages").slideToggle(600);
	}	

