/***** Konstanten *************************************************************/
var acConfig = {
	flashLayerDefault: "<div id='flashLayerClose'><img src='/de/img/dlc/close.gif' border='0' /></div>",
	breadcrumbHeadline: "",
	// Schriftvergrößerung
	fontsize: {
		// Bereich, der vergrößert werden soll
		contentClass: '.infobox_content',
		
		// Elemente, die vergrößert werden sollen
		resizeTags: ['h5', 'h6', 'p', 'span', 'li', 'a', 'td', '.tblHeader'],
		
		// Anzahl der Schritte
		maxSteps: [3, -3],
		
		// Schritt falls keine Angaben im Cookie eingetragen sind
		initialStep: 0,

		// Selector-IDs für die einzelnen Schriftgrößen
		actionId: ['#bigTool', '#tinyTool'],

		// Cookie-Name
		cookieName: 'ac_fontsize'
	},
	
	// SocialBookmarkLinks
	sbmk: {
		twitter: 'http://twitter.com/home?status=',
		facebook: 'http://www.facebook.com/sharer.php?u=',
		digg: 'http://digg.com/submit?url=',
		delicious: 'http://del.icio.us/post?url=',
		misterWong: 'http://www.mister-wong.de/index.php?action=addurl&bm_url=',
		stumbleUpon: 'http://www.stumbleupon.com/submit?url=',
		google: 'http://www.google.com/bookmarks/mark?op=add&bkmk='
	},
	
	// Registrierung - Hilfetexte
	reg: {
		// field [headline, content]
		firstname: '<h3>Vorname</h3><p>Bitte geben Sie Ihren Vornamen an.</p>',
		lastname: '<h3>Nachname</h3><p>Bitte geben Sie Ihren Nachnamen an.</p>',
		email: '<h3>E-Mail Adresse</h3><p>Bitte geben Sie eine gültige E-Mail-Adresse an. Dies ist Ihr Benutzer- name.</p>',
		emailerror: '<h3 style="color:#F00;">Fehler: E-Mail Adresse</h3><p style="color:#F00;">Bitte überprüfen Sie Ihre E-Mail Adresse.</p>',
		birthdate: '<h3>Geburtsdatum</h3><p>Bitte geben Sie Ihr Geburtsdatum ein (z.B. 05.12.1958).</p>',
		username: '<h3>Benutzername</h3><p>Bitte wählen Sie einen leicht merkbaren Benutzernamen aus. Dieser dient zum Login und kann nachträglich nicht mehr verändert werden.<br /><br />Bitte beachten Sie:<br />* mind. 8 Zeichen<br />* keine Sonderzeichen<br />* Groß- und Kleinschreibung beachten</p>',
		password: '<h3>Passwort</h3><p>Bitte beachten Sie:<ul style="margin:0;padding:0; line-height:1em;"><li style="line-height:1em;">mind. 8 Zeichen</li><li style="line-height:1em;">keine Sonderzeichen</li><li style="line-height:1em;">Groß- und Kleinschreibung beachten</li></p>',
		passwordComparison: '<h3>Passwortbestätigung</h3><p>Bitte geben Sie noch einmal zur Kontrolle Ihr Passwort ein.</p>',
		hasdiabetes: '<h3>Sind Sie Diabetiker?</h3><p>Bitte geben Sie an, ob Sie Diabetiker sind. Diese Information hilft uns, die Serviceleistungen unserer Internetseite optimal auf Ihre persönlichen Bedürfnisse abzustimmen.<br />...mehr Infos</p>',
		longStreet: '<h3>Straße</h3><p>Bitte geben Sie Ihre Straße an (kein Postfach/ Packstation).</p>',
		digit4PointerNumber: '<h3>Hausnummer</h3><p>Bitte geben Sie Ihre Hausnummer an.</p>',
		digit4Zip: '<h3>Postleitzahl</h3><p>Bitte geben Sie Ihre fünfstellige Postleitzahl an.</p>',
		longPointerCity: '<h3>Ort</h3><p>Bitte geben Sie Ihren Wohnort an.</p>',
		areaCode: '<h3>Telefon</h3><p>Bitte geben Sie die Vorwahl Ihrer Telefonnummer an, unter der wir Sie am besten erreichen können.</p>',
		phoneNumber: '<h3>Telefon</h3><p>Bitte geben Sie die Durchwahl Ihrer Telefonnummer an, unter der wir Sie am besten erreichen können.</p>'
	},
	
	// ajax parameters for xmlHTTPrequests
	acAjax: {
		// [urlPath, parameters, success-functions, error-functions]
		awt: ['/AllocateXMLDataServlet?searchValue=/services/awt/awt_aktion_', 'awtSuccess()', 'awtError()'],
		flashLayer: ['', '', '', '']
	}
};

$(document).ready(function () {
/**
 *  init functions start
 */
	 $('#loginLayer #loginLayerClose').click(function() {
				hideFlashLayer("loginLayer");
		});
	
		/** 2click social plugins *********************************************/
		if($('.infobox_subline_new').length > 0){
			$('.infobox_subline_new').socialSharePrivacy({
				services:{
					facebook : {'txt_fb_on': '','txt_fb_off': ''}, 
					twitter : {'txt_twitter_on': '','txt_twitter_off': ''},
					gplus : {'txt_gplus_on': '','txt_gplus_off': ''}
				},
  			'cookie_domain' : location.host,
  			info_link: '/services/de/impressum/rechtliche_hinweise/index.html#socialPlugins'
			}); 
    }
    $("#social_share_privacy_rights").click(function(ssprEvt) {
    	ssprEvt.preventDefault();
    	$("#layerRights").trigger("click");
    	try {
    		console.log("scrollto111");
    		$("#layerbox_content").animate({scrollTop:'100px'}, 'slow');
    	}catch(exc) {}
    });
    
		/** 2click social plugins *********************************************/
	
	
	var radioJack = $(".radioBox");
	var jackBox = $(".jqTransformCheckboxWrapper");
 		
		// try - falls Elemente vorhanden, werden diese initialisiert
 		try {
 			if($(".infobox_headline")) {
 				acConfig.breadcrumbHeadline = $(".infobox_headline").html();
 			}
 			if($(".produkt_headline")) {
				acConfig.breadcrumbHeadline = $(".infobox_headline").html();
 			}
 			
			
			$(".content_scrollDLC").jScrollPane({showArrows: true});					// initialises scrollbar		
			$(".dlc_scroll").jScrollPane({showArrows: true});									// initialises scrollbar		

			$(function(){$(".transForm").jqTransform();});	
		
				Cufon.replace('.headline_area', {hover: 'true'});
				Cufon.replace('.headline', {hover: 'true'});
				Cufon.replace('#produkteNavi a.trigger', {hover: 'true'});
				Cufon.replace('.produkt_headline h2', {hover: 'true'});
				Cufon.replace('.produkt_headline p', {hover: 'true'});
				Cufon.replace('.more_link', {hover: 'true'});
				Cufon.replace('#newsHeadline h3', {hover: 'true'});
				Cufon.replace('.infobox_headline', {hover: 'true'});
				Cufon.replace('#breadcrumb', {hover: 'true'});
				Cufon.replace('#produktheadline span', {hover: 'true'});
				Cufon.replace('.description .text', {hover: 'true'});
				Cufon.replace('a.home_link_produkte', {hover: 'true'});
				Cufon.replace('a.home_link_erleben', {hover: 'true'});
				Cufon.replace('#product-group-0 p', {hover: 'true'});
				Cufon.replace('#product-group-1 p', {hover: 'true'});
				Cufon.replace('#product-group-2 p', {hover: 'true'});
				Cufon.replace('#product-group-3 p', {hover: 'true'});
			
			
			// font infos
			$("#fontInfo1 span").click(function() {
				$("#fontInfo1").css("display","none");
			});
			$("#fontInfo2 span").click(function() {
				$("#fontInfo2").hide("display","none");
			});
 		} catch(initExc){}

		/* Schrift vergrößern? */
		var cookieDate = new Date();
		cookieDate = new Date(cookieDate.getTime() + (1000*60*60*24*365));
		try {
			$(acConfig.fontsize.actionId[0]).mousedown(function(event){
				event.preventDefault();
				if(acConfig.fontsize.initialStep < acConfig.fontsize.maxSteps[0]) {
					acConfig.fontsize.initialStep = acConfig.fontsize.initialStep + 1;
					document.cookie = acConfig.fontsize.cookieName + "=" + acConfig.fontsize.initialStep + ";path=/;expires=" + cookieDate.toGMTString();
					tagLoop(+1);
				} else {
					alert('Die maximale Schriftgröße ist erreicht!');
					
					//nice alert box no final design
					// $("body").append('<div id="fontInfo1"><span>x</span>Die maximale Schriftgröße ist erreicht!</div>');
					// $("#fontInfo1").show();
				}
				return false;
			});
		
			$(acConfig.fontsize.actionId[1]).mousedown(function(event){
				event.preventDefault();
				if(acConfig.fontsize.initialStep > acConfig.fontsize.maxSteps[1]) {
					acConfig.fontsize.initialStep = acConfig.fontsize.initialStep - 1;
					document.cookie = acConfig.fontsize.cookieName + "=" + acConfig.fontsize.initialStep + ";path=/;expires=" + cookieDate.toGMTString();
					tagLoop(-1);
				} else {
					alert('Die maximale Schriftgröße ist erreicht!');
					
					//nice alert box no final design
					// $("body").append('<div id="fontInfo2"><span>x</span>Die maximale Schriftgröße ist erreicht!</div>');
					// $("#fontInfo2").show();
				}
				return false;
			});
		} catch(resizeExc){}

		var allCookies,	acCookie, i, len;
		allCookies = document.cookie.split(';');
		len = allCookies.length;
		for (i = 0; i < len; i += 1) {
			acCookie = trim(allCookies[i]);
			if(acCookie.indexOf(acConfig.fontsize.cookieName) > -1) {
				acConfig.fontsize.initialStep = parseInt(acCookie.substring(acCookie.indexOf("=")+1),10)
				tagLoop(acConfig.fontsize.initialStep);
			}
		}
		
		// social boookmarks - footer
		/* twitter 					*/		$("#sbkmk01").attr("href", acConfig.sbmk.twitter + location.href);
		/* facebook					*/		$("#sbkmk02").attr("href", acConfig.sbmk.facebook + location.href + "&t=" + document.title);
		/* delicious				*/		$("#sbkmk03").attr("href", acConfig.sbmk.delicious + location.href);
		/* digg							*/		$("#sbkmk04").attr("href", acConfig.sbmk.digg + location.href + "&title=" + document.title);
		/* mister wong			*/		$("#sbkmk05").attr("href", acConfig.sbmk.misterWong + location.href + "&bm_description=" + document.title);
		/* stumble upon			*/		$("#sbkmk06").attr("href", acConfig.sbmk.stumbleUpon + location.href + "&title=" + document.title);
		/* google bookmarks */		$("#sbkmk07").attr("href", acConfig.sbmk.google + location.href + "&title=" + document.title);
		
/**
 * 	init functions end
 */

function tagLoop(step) {
	var reTagsLen = acConfig.fontsize.resizeTags.length;
	
	for (var i = 0; i < reTagsLen; i++) {
		$('.infobox_content ' + acConfig.fontsize.resizeTags[i]).each(function(index) {
			if($(this).css('font-size') != undefined) {
				fontSize = $(this).css('font-size');
				fontSize = fontSize.substring(0,fontSize.indexOf('px'))
				fontSize = parseInt(fontSize, 10) + parseInt(step, 10);
				fontSize = fontSize + "px";
				$(this).css('font-size', fontSize)
			}
		});
	}
}

	$(".frageImg01").mousedown(function(){
		var leng = $(".frageImg01").length;
		var i;
		for(i = 0; i < leng; i++) {
			$(".frageImg01")[i].src = "/de/img/shared/checked_false.gif";
		}
	});
	$(".frageImg01").mouseup(function(){
		$("#hidden01").val(this.id);
		this.src = "/de/img/shared/checked_true.gif";
	});

	$("#canvas").click(function(){
		$("#canvas").css('display','none');
	});
	
	$('#smallImg2').click(function() {
	  $(this).animate({
	    top: '-=150'
	  }, 5000, function() {
	    // Animation complete.
	  });
	});
	
	$('.footerLnk').click(function(){
		var layerID = $(this).attr('rel');
		$(layerID).addClass( "active2", "normal" );
		$(layerID).children("div").stop(true, true).animate({opacity: "show"}, "normal");
	});
	
	
/********** tools tipp ***********/
	$('#contentBottom #service a').mouseover(function(){
		$('#tipp').html($(this).attr('rel'));
	});
	$('#contentBottom #service a').mouseout(function(){
		$('#tipp').html('');
	});

	$('#printTool').mousedown(function(printEvent){
		if(location.href.indexOf(".html") > -1) {
			var printPath = window.location.href + "?print=true";
			window.open(printPath,"printWindow","width=700,height=680,left=50,top=50,scrollbars=yes");
			return false;
		} else {
			self.print();
		}
	});
	
	$('#suggestTool').mousedown(function(){
		$('#ifr_mailtofriend').css('display','block');
		$('#mailtofriendIcon').css('display','block');
	});

/********** home services hover layer ***********/

		// show hover graphic
		$("#serviceContainer").mouseenter(function(){
			$(".servicesHover").show();
		});
		// hide hover graphic
		$("#serviceContainer").mouseleave(function(){
			$(".servicesHover").hide();
		});
	
/********** tv tipp layer ***********/
			// LAYER open
			$(".openTippLayer").click(function(){
				$(".newsLayer").show();
			});
			// URL wird an Iframe uebergeben
			$(".openTippLayer").mousedown(function(){
				$("#tippFrame").attr("src",$(this).attr("rel"));
			});
			// LAYER close
			$(".closeLayer").click(function(){
				$(".newsLayer").hide();
			});


/********** layer imprint / rights ***********/

			// show transparent background
			$("#layerImprint, #layerRights, #glossaryTool").click(function(event) {
					event.preventDefault();
					
					$("#exposeMask").animate({opacity: "show"}, "normal");
					$("#exposeMask").css({"height": (($("#home_content").height())) - 133 + 'px'});
					$("#exposeMask").css({"height": (($("#home_content.erleben").height())) - 138 + 'px'});
					$("#exposeMask").css({"height": (($("#produkte_content").height())) - 128 + 'px'});
					$("#exposeMask").css({"height": (($("#home_content.home").height())) - 138 + 'px'});

					if($(this).attr("id") === "layerImprint") {
						if($("#flashLayerImprint #layerbox_content").html() == "") {
							$.get('/content/services/impressum/impressum.xml', function(xmlBody){
								$(xmlBody).find('contentBody').each(function(bodyID){
									$("#flashLayerImprint #layerbox_content").html($(this).text());
								});
								$("#flashLayerImprint .content_scroll_imprint").jScrollPane({showArrows: true});							
							});
						}
						if($('#flashLayerRights').css("display") === "block") {$('#flashLayerRights').hide();}
						$('#flashLayerImprint').show();
					}

					if($(this).attr("id") === "layerRights") {
						if($("#flashLayerRights #layerbox_content").html() == "") {
							$.get('/content/services/impressum/rechtliche_hinweise.xml', function(xmlBody){
								$(xmlBody).find('contentBody').each(function(bodyID){
									$("#flashLayerRights #layerbox_content").html($(this).text());
								});
								$("#flashLayerRights .content_scroll_imprint").jScrollPane({showArrows: true});
							});
						}
						
						if($('#flashLayerImprint').css("display") === "block") {$('#flashLayerImprint').hide();}
						$('#flashLayerRights').show();
					}
					
					$('html, body, window').animate({scrollTop:0}, 'slow');
			});

			// close layer and mask
			$('.close_imprint').click(function(event) {
					$('#flashLayerImprint').hide();
					$("#exposeMask").animate({opacity: "hide"}, "normal");
			});
			$('.close_rights').click(function(event) {
					$('#flashLayerRights').hide();
					$("#exposeMask").animate({opacity: "hide"}, "normal");
			});
			$('.close_glossary').click(function(event) {
					$('#flashLayerGlossary').hide();
					$("#exposeMask").animate({opacity: "hide"}, "normal");
			});
			
			// Glossar Layer oeffnen
			$('#glossaryTool').click(function(event) {
				$('#flashLayerGlossary').show();
				$('html, body, window').animate({scrollTop:0}, 'slow');
				event.preventDefault();
			});
			
			// Produktvideos Layer oeffnen
			$(".openFlashVideo").click(function(event){
				$("#produkteLayerFlash").show();
				$("#zoomContainer").hide();
				event.preventDefault();
			});
							
/********** Background-Abfrage ***********/

			if ($('#content').height() < 560) {
					$('#content').addClass('short');
			}
			if ($('#content').height() < 460) {
				$('#content').addClass('minBG');
			}
			
/********** services slider startseite ***********/

	try {
		$('#slider1').bxSlider({
			infiniteLoop: true,
			mode: 'fade',
			speed: 1200,
			auto: false,
			pause: 3000
		});
	
		$('#slider2').bxSlider({
			infiniteLoop: true,
			mode: 'fade',
			speed: 1200,
			auto: false,
			pause: 3000
		});
	} catch(bxSliderExc){}
	
	$('.sliderList').mouseover(function(){
		$(this).parent().next('.bx-prev').show();
		$(this).parent().next('.bx-prev').next('.bx-next').show();
		$(this).parent().next('.bx-prev').mouseover(function(){
			$(this).show();
			$(this).next('.bx-next').show();
		});
		$(this).parent().next('.bx-prev').next('.bx-next').mouseover(function(){
			$(this).show();
			$(this).prev('.bx-prev').show();
		});
		$(this).parent().next('.bx-prev').mouseout(function(){
			$(this).hide();
			$(this).next('.bx-next').hide();
		});
		$(this).parent().next('.bx-prev').next('.bx-next').mouseout(function(){
			$(this).hide();
			$(this).prev('.bx-prev').hide();
		});
	});

	$('.sliderList').mouseout(function(){
		$(this).parent().next('.bx-prev').hide();
		$(this).parent().next('.bx-prev').next('.bx-next').hide();
	});
				

/********** REGISTRATION LISTENER ***********/

	// -- siehe -> registration.js
			
// submitForms
		$("#submitPersonalData, #submitDiabData, #submitContactData").click(function(event) {
			event.preventDefault();
			$("#userData").submit();
		});
		$("#submitPasswordRequest").click(function(event) {
			event.preventDefault();
			$("#requestPasswordForm").submit();
		});
		$("#submitLogin").click(function(event) {
			event.preventDefault();
			$('form[name|="loginForm"]').submit();
		});
		$("#submitLoginErr").click(function(event) {
			event.preventDefault();
			$('form[name|="loginErrForm"]').submit();
		});
	
	// planner
	$("#popupGoOn1").click(function(){
		closerFn("#mlkglass");
		closerFn("#popup1");
		closerFn(".popupGoBtn");
		location.href = $(this).attr('rel');
	});
	
	if(location.hash != ""){
		closerFn("#mlkglass");
		closerFn("#popup1");
		if(location.hash.substring(1) != "content1") {
			if(location.hash.indexOf("#/") > -1) {
				tabSlider("#" + location.hash.substring(2));
			} else {
				tabSlider("#" + location.hash.substring(1));
			}
		}		
	}
	
	$("a.tab").click(function() {								// When a link is clicked
		$(".tabs li").each(function(index) {		
			$(".tabs li a").removeClass("active");			// switch all tabs off
		});
		$(this).addClass("active");								// switch this tab on
		$(".content").slideUp();									// slide all content up
		var content_show = $(this).attr("title");
		$("#" + content_show).slideDown();				// slide this content up
	});
	
	$("#mlkglass0").click(function(){
		showFn("#mlkglass1");
		showFn("#popup4");
		showFn(".popupGoBtn2");
	});
	$(".popupGoBtn2").click(function(){
		closerFn("#mlkglass0");
		closerFn("#mlkglass1");
		closerFn("#popup4");
		closerFn(".popupGoBtn2");
	});

	$("#anleitung").click(function(){
		showFn("#mlkglass2");
		showFn("#popupInfo");
		showFn("#popupInfoSub");
		showFn("#closer4");
	});

	$("#closer4").click(function(){
		closerFn("#mlkglass2");
		closerFn("#popupInfo");
		closerFn("#popupInfoSub");
		closerFn("#closer4");
	});


	$("td.dayTime").mouseover(function() {
		$(this).css("background","transparent url(/de/img/planner/neuer_wert.gif) no-repeat 15px 5px");
		
	});
	$("td.dayTime").mouseout(function() {
		$(this).css("background","transparent url(/de/img/planner/trans.gif) no-repeat 15px 5px");
	});

	$("td.dayTime").click(function() {
		location.href = this.id + "&" + location.search.substring(1);
	});
	$(".noDate").click(function() {
		location.href = $(this).attr("href") + "&" + location.search.substring(1);
	});

	$("#closer3").click(function(){
		location.href = "/planner/listAppointments.htm" + $(this).attr("rel");
	});
	
	$("#closer").click(function(){
		location.href = "/planner/listMeasuredValues.htm";
	});
	
	if($("#dateID").length > 0){ $("#dateID").val($("#dateIDstr").html()); }
	if($("#slotID").length > 0){ $("#slotID").val($("#slotIDstr").html()); }
	
	$("#mgDL").click(function(){
		$("#Unit").val($(this).attr("value"));
	});
	$("#mmolL").click(function(){
		$("#Unit").val($(this).attr("value"));
	});
	
	if($("#Unit").attr("value") === "mg/dl") {
		$('input[name="unitChck"]')[0].checked = true;
		$('input[name="unitChck"]')[1].checked = false;
	}
	if($("#Unit").attr("value") === "mmol/l") {
		$('input[name="unitChck"]')[0].checked = false;
		$('input[name="unitChck"]')[1].checked = true;
	}

	$("#showKalenderwoche").click(function(){
		var jetzt = new Date();
		var tag = jetzt.getDate();
		if(tag<10){tag = "0" + tag;}
		var mon = jetzt.getMonth()+1;
		if(mon<10){mon = "0" + mon;}
		
		var yea = jetzt.getFullYear();
		location.href= $(this).attr("rel") + "?date=" + tag + "." + mon + "." + yea;
	});
	$("#showTagesverlauf").click(function(){
		location.href= $(this).attr("rel") + "?w=" + $("#chartPeriod").attr("value");
	});
	$("#showMesswert").click(function(){
		if($('select[name="startDD"]').val() != "" && $('select[name="startDD"]').val() != "" && $('select[name="startYYYY"]').val() != "" && $('select[name="endDD"]').val() != "" && $('select[name="endMM"]').val() != "" && $('select[name="endYYYY"]').val() != "") {
			location.href= $(this).attr("rel") + "?startDate=" + $('select[name="startDD"]').val() + "." + $('select[name="startMM"]').val() + "." + $('select[name="startYYYY"]').val() + "&endDate=" + $('select[name="endDD"]').val() + "." + $('select[name="endMM"]').val() + "." + $('select[name="endYYYY"]').val();
		}
	});
	
	// serachresult pagination
	$(".pageResults").click(function(pageEvent){
		pageEvent.preventDefault();
		location.href="/ACCUCHEK_SOLR/select/?q=" + $("strong#searchterm").html() + "&rows=10&start=" + 10*(parseInt($(this).html())) + "&indent=on&wt=xslt&tr=accu-chek_search.xsl&version=2.2";
	});	
	
	$('#flashLayerH #flashLayerClose').click(function() {
		$('#highscoreFrame').attr('src','');
	
		hideFlashLayer("flashLayerH");
	});

	$("#profile-image-save input").click(function(){
		$.ajax({
			url: "/user/ProfileImageServlet?action=view",
			success: function(data) {
				if(data != "") {
					$("#profilBildBox img", window.parent.document).attr("src",data);
				}
				$("#flashLayerClose", window.parent.document).trigger("click");
			}
		});
	});
	
	// set Protocol for twitter und facebook links
	$("a").each(function(index) {
		if(location.protocol === "https:") {
			try {
				if($(this).attr("href").indexOf("twitter.com") > -1 || $(this).attr("href").indexOf("facebook.com") > -1) {
					var aTmp = $(this).attr("href").replace(/http:/, "https:");
					$(this).attr("src", aTmp);
				}
			} catch(except){}
		}
	});
	$("iframe").each(function(index) {
		if(location.protocol === "https:") {
			try {
				if($(this).attr("src").indexOf("twitter.com") > -1 || $(this).attr("src").indexOf("facebook.com") > -1) {
					var iframeTmp = $(this).attr("src").replace(/http:/, "https:");
					$(this).attr("src", iframeTmp);
				}
			} catch(except){}
		}
	});
	
	$("#flashLayerPlanner #flashLayerClose").click(function() {
		$("#ifr_planner").attr("src","/content/redirect_sec_content.jsp?target=/planner/start.htm");
		hideFlashLayer("flashLayerPlanner");
		$("#lightboxBack").hide();
		$("#flashLayerClose").hide();
		if($(this).attr("rel") == "reload") {
			location.reload();
		}
	});

});
// show/hide TippBox für (Registrierung)
function showTippBox(boxID, boxText) {
	$(boxID).html(boxText);
	$(boxID).css("display","inline-block");
}
function hideTippBox(boxID) {
	$(boxID).html('');
	$(boxID).css("display","none");
}
function moveFieldBG(fieldID, position) {
	position = "0px " + position;
 	$(fieldID).css("background-position",position);
}

function trim(str) {
	// returns the String without any leading or closing whitespaces like: \f, \n, \t, \v and white space 
	// ^\s+ 		==> deletes one to all(+) leading(^) whitespaces (\s)
	// \s+$			==>	deletes one to all(+) closing($) whitespaces (\s)

	str = str.replace(/^\s+|\s+$/g, "");
	return str;
}

// debug function to ease development
function cL(ausgabe) {
	console.log(ausgabe);
}

//planner
function closerFn(closerID) {$(closerID).css("display","none");}
function showFn(closerID) {$(closerID).css("display","block");}

function tabSlider(sliderIndex) {
	try {
		$(".active").each(function(index) {
			$(".active").removeClass("active"); 						// switch all tabs off
		});
		$(sliderIndex).addClass("active");								// switch this tab on
		$(".content").slideUp();													// slide all content up
		var content_show = $(sliderIndex).attr("title");
		$("#" + content_show).slideDown();								// slide this content up
	} catch(exc){}
}	

function setDateString(tdIndex) {
	var day     = tdIndex.substring(3,5);
	var month   = tdIndex.substring(5,7);
	var year    = tdIndex.substring(7,11);
	var dTime = tdIndex.substring(15);
	dayTimeStr  = new Array("", "Vor dem Fr&uuml;hst&uuml;ck", "1,5-2 nach dem Fr&uuml;hst&uuml;ck", "Vor dem Mittagesssen", "1,5-2 nach dem Mittagesssen", "Vor dem Abendesssen", "1,5-2 nach dem Abendesssen", "Vor dem Schlafen");

	$("#dTime").html(day + "." + month + "." + year + "&nbsp;-&nbsp;" + dayTimeStr[dTime]);
}
function checkMeasuredvalue(val){
	if (isNaN(val) || val === ""){
		$('#Measuredvalue').val("");
		setTimeout("$('#Measuredvalue').focus()",10);
		return false;
	} else {
		return true;
	}
}
function checkTimeString(val){
	if (val.length == 5 && !isNaN(val.charAt(0)) && !isNaN(val.charAt(1)) && !isNaN(val.charAt(3)) && !isNaN(val.charAt(4)) && val.charAt(2) == ':'){
		return true;
	}else{
		$('#BegindateTimeString').val("");
		setTimeout("$('#BegindateTimeString').focus()",10);
		return false;
	}
}

// set breadcrumb
function setBreadcrumb() {
	try {
		var sectionUri = "", locationToken = "", sectionLink = "", moduleLink = "", functionLink = "", subfunctionLink = "", bcAppendix = "", breadcrumbHTML = "";
		sectionUri = location.href.substring(location.href.indexOf(".de/") + 4);
	
		if(sectionUri.indexOf("/de/") > -1) {
			
			locationToken = sectionUri.split("/");		
	
			if(locationToken[locationToken.length-1].indexOf(".html") > -1) {
				breadcrumbHTML += '<span>&gt;</span> ' + acConfig.breadcrumbHeadline;
			}
			
			$("#breadcrumb").append(breadcrumbHTML);
			Cufon.replace('#breadcrumb', {hover: 'true'});
		}

	} catch(breadcrumbExc){}
}

// get xml oder html files -> lookup @ acConfig.acAjax
// /services/awt/awt_aktion_ .html

function getXMLContent(requestID, ajaxParams) {
	$.ajax({
		url: acConfig.acAjax[requestID][0] + ajaxParams + ".html",
		success: function(data) {
			if(data.indexOf("No such file") > -1 || data.indexOf("Error in building") > -1) {
				getXMLContent("/services/awt/awt_aktion_default.html", "xmlHeader", "xmlContent");
			} else {
				var dataToken = data.split('|');
				$("#xmlHeader").html(dataToken[0]);
				$("#xmlContent").html(dataToken[1]);
			}
			Cufon.replace('.infobox_headline', {hover: 'true'});
		},
		error: function() {
			$("#" + aimHeadline).html('Lieber Benutzer,');
			$("#" + aimContent).html('Leider sind zur Zeit keine weiteren Informationen für diese Aktion verfügbar.<br />Bitte versuchen Sie es zu einem späteren Zeitpunkt noch einmal oder wenden Sie sich an unseren <a hrerf="/service/de/kontakt/kontakt.html">Kundeservice</a>.<br />&nbsp;<br /><b>Ihr Accu-Chek Team</b>');
		}
	});
}

// flashLayer Request
function flashLayer(layerType, file) {
	try {
		$.ajax({
			url: "/erleben/de/content.jsp?url="+file,
			//url: file,
			success: function(data) {
			
				if(layerType != "none") {
					$("#" + layerType).show();
					if(layerType === "flashLayerB" || layerType === "flashLayerG" || layerType === "flashLayerPlanner") {
						$("#lightboxBack").show();
					}
					$("#" + layerType + " div.layerBody").html(data);
				} else {
					$("#flashLayerB div.layerBody").html(data);
				}
				
				// nice scrollbars for long FlashLayers
				try {$(".content_scroll").jScrollPane({showArrows: true});} catch(e) {}
				try {$(".content_scroll700").jScrollPane({showArrows: true});} catch(e) {}

    		var paginationArray;
    		try {
	    		$('ul.flashLayer').easyPaginate({step: 1, delay: 0, numeric: true});
	    	} catch(paginateEx){}
				paginationArray = $("#pagination li");
				$(paginationArray[paginationArray.length-2]).css("border-width","0");
				$('#layerbox_social .layerPrintIcon').click(function(){
					printFlashLayer($(this).parent().parent().html());
				});

				$('#flashLayerClose img').click(function() {
					var closerParent = $("#flashLayerClose").parent().parent().attr("id");
					$("#flashLayerClose").parent().html("");
					hideFlashLayer(closerParent);
					if($("#lightboxBack").css('display','block')){$("#lightboxBack").css('display','none');}
					if($("#exposeMask").css('display','block')){$("#exposeMask").css('display','none');}

					// reset facebookFrame for FlashLayers
					$("#" + closerParent + " div.fbBody").html("");

					// reload parent location if iframe login process
					try {
						if($(this).parent().next().children().attr("id") === "iframeTool") {
							location.reload();
						}
					} catch(exc){}

					if(closerParent === "flashLayerB") {
						$("#flashLayerB").css("background","url('/de/img/shared/layer760.png')");
					}
				});

				$(".startButton").parent().css("cursor","pointer");
				$(".startButton").parent().click(function(startBtnEvt){
					location.href = $(this).children().attr("rel");
				});

				var tmpLink = "http://www.facebook.com/plugins/like.php?href=" + encodeURIComponent("http://" + location.host + location.pathname + "?fbURL=" + location.hash.substring(2)) + "&send=false&layout=button_count&width=150&show_faces=false&action=recommend&colorscheme=light&font&height=21";
				$("#fbLikeBtn").attr("src", tmpLink);

				Cufon.replace('.layerbox_head', {hover: 'true'});
			},
			error: function() {
				$("#lightboxBack").show();
				$("#flashLayerErr").show();
				$("#flashLayerErr div").html(acConfig.flashLayerDefault);
				$('#flashLayerClose img').click(function() {
					var closerParent = $("#flashLayerClose").parent().parent().attr("id");
					$("#flashLayerClose").parent().html("");
					hideFlashLayer(closerParent);
					if($("#lightboxBack").css('display','block')){$("#lightboxBack").css('display','none');}
				});
			}
		});
	} catch(e) {}
}

function showHighscores(scoreParams) {
	var scoreURI = "";
	scoreParamsToken = scoreParams.split("|");

	if(scoreParamsToken[1].indexOf("bicycleGame") > -1) {
		if(scoreParams === "" || scoreParams === null || scoreParams === "undefined" ) {
			scoreURI = "/bicycleGame/fe/redirect_bicyclegame.jsp?ref=bicycleGame&target=isNotLoggedIn&gameAttr=";
		} else {
			scoreURI = "/bicycleGame/fe/redirect_bicyclegame.jsp?ref=bicycleGame&target=insertScore&gameAttr=" + scoreParams;
		}
	}
	if(scoreParamsToken[1].indexOf("pacManGame") > -1) {
		if(scoreParams === "" || scoreParams === null || scoreParams === "undefined" ) {
			scoreURI = "/mobile_online_game/fe/redirect_mobilegame.jsp?ref=mobileGamePM&target=isNotLoggedIn&gameAttr=";
		} else {
			scoreURI = "/mobile_online_game/fe/redirect_mobilegame.jsp?ref=mobileGamePM&target=insertScore&gameAttr=" + scoreParams;
		}
	}
	
	$("#highscoreFrame").attr("src",scoreURI);
	$("#highscoreFrame").attr('src', $('#highscoreFrame').attr('src'));
	$("#lightboxBack").show();
	$("#flashLayerH").show();

	$('#flashLayerH #flashLayerClose').click(function() {
		hideFlashLayer("flashLayerH");
	});
}
function showHighscoreList(gameName) {
	if(gameName === "" || gameName === null || gameName == undefined) {
		gameName = "mobileGamePM";
	}
	var gameURL = "/mobileGameServlet?action=getHighscores&gameName=" + gameName;
	try {
		$.ajax({
			url: gameURL,
			success: function(data) {
				if(gameName === "mobileGamePM") {
					$("#highscoreFrame").attr("src", "/mobile_online_game/fe/highscore.jsp");
				}
				if(gameName === "bicycleGame") {
					$("#highscoreFrame").attr("src", "/bicycleGame/fe/highscore.jsp");
				}
				$("#flashLayerH").show();
			}
		});
	} catch(e) {}
}

function toolsLogin() {
	$("#lightboxBack").show();
	$("#loginFrame").attr("src","/content/erleben/tools_redirect.jsp?target=fridgeGame");
	$('#loginFrame').attr('src', $('#loginFrame').attr('src'));
	$("#loginLayer").show();
}

// closeFlashLayer function for flash 
function closeFlashLayer(layerType){
	try {
		$("#" + layerType + " div.layerBody").html("");
		$("#" + layerType).hide();
		$("#lightboxBack").hide();
		
		return false;
	} catch(e) {}
}
// closeFlashLayer function for closeIcon
function hideFlashLayer(layerType){
	closeFlashLayer(layerType);
	try {
		$("#myContent")[0].closeLayer();
	} catch(e) {}
}

function printFlashLayer(l){
	print();
}
function makeScroll() {
	try {
		$("#layerRegister").jScrollPane({showArrows: true});
	} catch(except) {}
}
/***********************************
 ********			touch point		********
 ***********************************/

function activateRow(status, rowNumber) {
	var displayState = "table-row";
	if(navigator.appName.indexOf("Internet Explorer") > -1) {displayState = "block";}
	
	if(status) {
		if (rowNumber == "tbRow0"){
			for (var i = 1; i <= 8; i++){
				var tbIdOn = "tbRow" + i;
				$('#'+tbIdOn).css('display', displayState);
			}
			if ($("#useMeterproduct1").checked == true){
				$("#tbRow2").css('display', displayState);
			}else{
				$("#tbRow2").css('display', 'none');
			}
			if ($("#useDiabetesDataSoftware1").checked == true){
				$("#tbRow4").css('display', displayState);
			}else{
				$("#tbRow4").css('display', 'none');
			}
			$("#tbRow8").css('display', 'none');
		}else if (rowNumber == "tbRow10"){
			$("#tbRow10").css('display', displayState);
		}else{
			$('#'+rowNumber).css('display', displayState);
			if ($("#useMeterproduct1").checked == true){
				$("#tbRow9").css('display', 'none');
				$("#tbRow10").css('display', 'none');
			}
		}
	}else{
		if (rowNumber == "tbRow0"){
			for (var j = 1; j <= 8; j++){
				var tbIdOff = "tbRow" + j;
				$('#'+tbIdOff).css('display', 'none');
				document.metertestTouchPointForm.useMeterproduct[0].checked = false;
				document.metertestTouchPointForm.useMeterproduct[1].checked = false;
				document.metertestTouchPointForm.serialNoMeterProduct.value = "";
				document.metertestTouchPointForm.useDiabetesDataSoftware[0].checked = false;
				document.metertestTouchPointForm.useDiabetesDataSoftware[1].checked = false;
				document.metertestTouchPointForm.diabetesDataSoftwareProduct.options[0].selected = true;
				for (var k = 0; k < 6; k++){
					document.metertestTouchPointForm.answer1[k].checked = false;
					document.metertestTouchPointForm.answer2[k].checked = false;
					document.metertestTouchPointForm.answer3[k].checked = false;
				}
				document.metertestTouchPointForm.callbackMeterProduct[0].checked = false;
				document.metertestTouchPointForm.callbackMeterProduct[1].checked = false;
			}
		}else if (rowNumber == "tbRow10"){
			$("#tbRow10").css('display', 'none');
		}else{
			$('#'+rowNumber).css('display', 'none');
			if (rowNumber == "tbRow2"){
				$("#tbRow9").css('display', displayState);
				document.metertestTouchPointForm.serialNoMeterProduct.value = "";
			}
			if (rowNumber == "tbRow4") {document.metertestTouchPointForm.diabetesDataSoftwareProduct.options[0].selected = true;}
		}
	}
}

function showDemotool() {
	window.open('/content/produkte/insulinpumpentherapie/accu_chek_combo/demo_tool/demotool_popup.html','demotool','width=860,height=685,left=100top=50status=yes,menubar=no,location=no,toolbar=no,scrollbars=no,resizable=no');
}
