// Regex for find domain extention
function xtractFile(data)
{
	data = data.replace(/^\s|\s$/g, "");

	if (/\.\w+$/.test(data)) {
		var m = data.match(/([^\/\\]+)\.(\w+)$/);
		if (m)
			return {filename: m[1], ext: m[2]};
		else
			return {filename: "no file name", ext:null};
	} else {
		var m = data.match(/([^\/\\]+)$/);
		if (m)
			return {filename: m[1], ext: null};
		else
			return {filename: "no file name", ext:null};
	}
}


// script for date footer
function monthYearDate()
{
    
	fullDomain = window.location.host;
	var site = xtractFile(fullDomain);
	
	var currentDay = new Date;
    var currentMonth = (currentDay.getMonth())+1;
    var currentYear = currentDay.getFullYear();
    
    switch(currentMonth)
    {
        case 1:
        currentMonth = "January";
        break;
        
        case 2:
        currentMonth = "February";
        break;
        
        case 3:
        currentMonth = "March";
        break;
        
        case 4:
        currentMonth = "April";
        break;
        
        case 5:
        currentMonth = "May";
        break;
        
        case 6:
        currentMonth = "June";
        break;
        
        case 7:
        currentMonth = "July";
        break;
        
        case 8:
        currentMonth = "August";
        break;
        
        case 9:
        currentMonth = "September";
        break;
        
        case 10:
        currentMonth = "October";
        break;
        
        case 11:
        currentMonth = "November";
        break;
        
        case 12:
        currentMonth = "December";
        break;
        
    }
	if(site.ext == "dk")
	{
		//Aprom ID for DK site for all pages
		document.write("Maj 2011");
	}
	else
	{
		document.write(currentMonth + " " + currentYear);
    }
}


/** ========================= BEGIN POLL ======================**/
/**
*
*/
function acc_resizeTD()
{
	var hauteurMax = $("#menu_acc .contents").height();
	$("#menu_acc .contents").each(function(){
		var increment = 1;
		var node = $(this).find("td[class!=tableContent]");
		var nbTD = node.length;
		var hauteurMin = hauteurMax / nbTD;
		$(node).each(function(){
			//$(this).toggleClass("line" + (increment + 1));
			$(this)[0].className = "line" + (increment + 1);
			$(this).css("height", hauteurMin + "px");
			increment = 1 - increment;
		});
		
		$(this).find(".tableContent").css("border-bottom", "none");
		$(".tableContentMain td").css({"text-align": "left"});
		$(".tableContentMain").each(function(){
			$(this).find(".tableContent:last").css({"width": "50px", "text-align": "right"});
		});
	});
	
	$(".tableContent").css("padding-left", "0px");
	
	// position button
	var tailleButton = $(".btn_container_blue").width();
	var tailleX = 218; // taille du block sans la marge
	var valeur = ((tailleX / 2) - (tailleButton / 2));
	if($.browser.msie && $.browser.version=="6.0")
		var valeur = (valeur / 2)  - 5;
	else
		var valeur = valeur - 8;
	$(".btn_container_blue").css("margin-left",  valeur + "px");// 
}

/**
*	Change "quick poll" en "quick poll result"
*/
function acc_setQPRtile()
{
	$("#box7").attr("id", "box9");
	acc_setTitlePicture("box9");
	tmpPoll.var1 = true;
}

/**
*	Inverse du dessus
*/
function acc_setQPtile()
{
	$("#box9").attr("id", "box7");
	acc_setTitlePicture("box7");
}
/**======================= END POLL ========================**/

// [BEGIN] tabs system
function ChangeOnglet_2(id, nbreOnglet) 
{   
	$(document).ready( function()
	{
	   	$(".mainContent #profilePage").css("display" , "block"); 
		
		$(".tabsLeft").removeClass("tabsLeft_active");
		$(".tabsCenter").removeClass("tabsCenter_active");
		$(".tabsRight").removeClass("tabsRight_active");
				
		$(".tabsLeft").removeClass("tabsLeft_activeFirst");
		$(".tabsRight").removeClass("tabsRight_activeLast");
		
	
		for(i=1; i<=nbreOnglet; i++)
		{
			$(".content_" + i).css("display" , "none");
			$(".content_" + i).css("visibility" , "hidden");
			$(".tab_" + i).removeClass("active");
		}
		
		$(".content_" + id).css("display" , "block");
		$(".content_" + id).css("visibility" , "visible");
	
		var tempSelector = id-1;
		
		//alert(tempSelector); // currentSlide
		//alert(nbreOnglet);
		
		if(tempSelector == 0)
		{
		    $(this).find(".tabsLeft:eq("+tempSelector+")").addClass("tabsLeft_activeFirst");
		    $(this).find(".tabsCenter:eq("+tempSelector+")").addClass("tabsCenter_active");
		    $(this).find(".tabsRight:eq("+tempSelector+")").addClass("tabsRight_active");
		}else if(tempSelector == (nbreOnglet-1)){
		    $(this).find(".tabsLeft:eq("+tempSelector+")").addClass("tabsLeft_active");
		    $(this).find(".tabsCenter:eq("+tempSelector+")").addClass("tabsCenter_active");
		    $(this).find(".tabsRight:eq("+tempSelector+")").addClass("tabsRight_activeLast");
		}else{
		    $(this).find(".tabsLeft:eq("+tempSelector+")").addClass("tabsLeft_active");
		    $(this).find(".tabsCenter:eq("+tempSelector+")").addClass("tabsCenter_active");
		    $(this).find(".tabsRight:eq("+tempSelector+")").addClass("tabsRight_active");
		}
		
	}); 	
} 
// [END] tabs system


// function for landing page
// anchor + flash autoplay
function displayVideo(videoId){
    
     document.getElementById("flashContainerLanding").displayVideo(videoId);
     //self.location.hash = "landingTitle";
     window.scrollTo(0,70);
}



// function for media-center page
// anchor + flash autoplay
function playVideo(videoID, title,description) {

	if ($('div').hasClass('alternateFlashContainer')) 
	{
        window.scrollTo(0,70);
		changeTitleMediaCenter(title,description);
	}
	else
	{
		document.getElementById("flashContainer").playVideo(videoID);
		window.scrollTo(0,70);
		changeTitleMediaCenter(title,description);
	}
    
    //self.location.hash = "#flashContainer";
    
}

function changeTitleMediaCenter(title,description)
{
    $("document").ready(function() {
        
        $(".mediaCenterTitle").empty();
        $(".mediaCenterTitle").append(title);
		$(".mediaCenterDescription").empty();
        $(".mediaCenterDescription").append(description);
        
    });
}

$("document").ready(function() {
   
   /*var hasString = false;
   var inputVal = $(this).val();
   $("input.loginEmail").blur( function () { 
		if(inputVal=='')
		{
			   $(this).val('E-mail');
               hasString = false;
        }
		else
		{
               hasString = true;
        }
	} );
   
   $("input").focus(function () {
         if(!hasString)
		 {
               $(this).val('');
         }
    });
	*/

	
   // for standard content accordion system
	/* [BEGIN] default close version */
	var voletOuvert = $('.hiddenLabel').text();
	if((voletOuvert > 0) && (voletOuvert < 15))
	{
		voletOuvert = voletOuvert-1;
	
		$(".titleAccordionContent a:eq("+ voletOuvert +")").addClass("selected");
		$(".titleAccordionContent a:eq("+ voletOuvert +")").parent().addClass("openContent");
		$(".titleAccordionContent a:eq("+ voletOuvert +")").parent().next().toggle();
	}
	if($(".titleAccordionContent a").hasClass("selected"))
	{
			$(".titleAccordionContent a.selected").css("background-image", "url(../images/moinsPuce.jpg)");
			$(".titleAccordionContent a.selected").parent().next().css("display", "block");
	}
	$(".titleAccordionContent a").click(function(){
		
		if($(this).hasClass("selected")){
		
		    $(this).css("background-image", "url(../images/plusPuce.jpg)");
			$(this).removeClass("selected");
			$(this).parent().removeClass("openContent");
			$(this).parent().find(".accordionContentTrait").removeClass("contentTraitMoins");
		
		}else{
			
			$(this).css("background-image", "url(../images/moinsPuce.jpg)");
			$(this).addClass("selected");
			$(this).parent().addClass("openContent");
			$(this).parent().find(".accordionContentTrait").addClass("contentTraitMoins");
		
		}		
		$(this).parent().next().toggle();
	});
	/* [END] default close version */
	/* [BEGIN] default open version */
	var voletOuvert = $('.hiddenLabel').text();
	if((voletOuvert > 0) && (voletOuvert < 15))
	{
		voletOuvert = voletOuvert-1;
	
		$(".titleAccordionContentWhite a:eq("+ voletOuvert +")").addClass("selected");
		$(".titleAccordionContentWhite a:eq("+ voletOuvert +")").parent().addClass("openContentWhite");
		$(".titleAccordionContentWhite a:eq("+ voletOuvert +")").parent().next().toggle();
	}
	$(".titleAccordionContentWhite a").click(function(){
		
		if($(this).hasClass("selected")){
		
			$(this).removeClass("selected");
			$(this).parent().removeClass("openContentWhite");
			$(this).parent().find(".accordionContentTraitWhite").addClass("contentTraitMoinsWhite");
		
		}else{
			
			$(this).addClass("selected");
			$(this).parent().addClass("openContentWhite");
			$(this).parent().find(".accordionContentTraitWhite").removeClass("contentTraitMoinsWhite");
		
		}
		$(this).parent().next().toggle();
	
	});
	/* [END] default open version */   



    // for tab area system
	// [BEGIN] hand cursor and text-decoration on roll-hover
	$(this).find(".tabsCenter").hover(function()
	{
		$(this).css("cursor", "pointer");
		$(this).css("color", "white");
	},function(){
		$(this).css("text-decoration", "none");
	});
	$(this).find(".tabsCenter_active").hover(function()
	{
		$(this).css("cursor", "pointer");
		$(this).css("color", "#6fd0ff");
	},function(){
		$(this).css("text-decoration", "none");
	});
	// [END] hand cursor and text-decoration on roll-hover
	// [BEGIN] add default _active class
	
	/*$(this).find(".tabs").find(".tabsLeft:first").addClass("tabsLeft_active");
	$(this).find(".tabs").find(".tabsCenter:first").addClass("tabsCenter_active");
	$(this).find(".tabs").find(".tabsRight:first").addClass("tabsRight_active");*/
	
	// [END] add default _active class	   
     
     
    
    // setinterval    
    if($('.recipeStep').length > 0)
    {
         var recipesAdjustFunction = setTimeout(function(){recipesAdjust();},1000);    
    }
    
    function recipesAdjust(recipesBcle)
    {
        
        var ingredienElementHeight;
        var stepNumber;

        ingredienElementHeight = $(".recipesIngredients").height();
        ingredienElementHeight += 15;

        stepNumber = $('.recipesElements > .recipeStep').length;

        for(var i=0; i<stepNumber; i++)
        {
            var posTop = 0;
            posTop = $(".recipesElements").find(".recipeStep:eq(" + i + ")").position();
            posTop = posTop.top;
            
            if(posTop > ingredienElementHeight)
            {
                $(".recipesElements").find(".recipeStep:eq(" + i + ")").css("width","100%");    
            }
        };  
       
    }

   
     


    // for recipes bottom links
    previewString = $(".footerLinksRecipes .linkLeft a").text();
    nextString = $(".footerLinksRecipes .linkRight a").text();
    
    previewSize = previewString.length;
    nextSize = nextString.length;
    
    if(previewSize >= 35)
    {
        previewString = previewString.substr(0,34) + "...";
        $(".footerLinksRecipes .linkLeft a").text(previewString);
    }
    
    if(nextSize >= 35)
    {
        nextString = nextString.substr(0,34) + "...";
        $(".footerLinksRecipes .linkRight a").text(nextString);
    }   
    
    
    // landing page thumbnail carosel
	marginLeft = 0;
	numberElement = $('.landingPageVideoThumbnailTable tbody tr td').length;
	currentFirstElement = 1;
	currentLastElement = 3;

    // define the carousel height
    if($('.landingPageVideoThumbnailTable').length > 0)
    {
        var hauteurCarousel = $(".landingPageVideoThumbnailTable tbody").find("tr:eq(" + 0 + ")").height();
        $(".mainContent .landingContent .containerCarousel").css("height", hauteurCarousel+"px");
    }
	
	// hide arrows if not enought elements for scrolling
	if(numberElement < 4)
	{
		$(".landingCarouselArrow .preview").css("display", "none");
		$(".landingCarouselArrow .next").css("display", "none");
	}
	// on load
	$(".landingCarouselArrow .preview").css("display", "none");
	$(".landingCarouselArrow .preview").click(function(){
		// move table element
		if(currentFirstElement > 1)
		{
			currentFirstElement--;
			currentLastElement--;
			marginLeft += 244;
			$(".landingPageVideoThumbnailTable").animate({"left" : marginLeft}, "slow");
		}
		// hide/show arrows
		if(marginLeft == 0)
		{
			$(".landingCarouselArrow .preview").css("display", "none");
			$(".landingCarouselArrow .next").css("display", "block");
		}else{
			$(".landingCarouselArrow .preview").css("display", "block");
			$(".landingCarouselArrow .next").css("display", "block");
		}
	});
	$(".landingCarouselArrow .next").click(function(){
		// move table element
		if(currentLastElement < numberElement)
		{
			currentFirstElement++;
			currentLastElement++;
			marginLeft -= 244;
			$(".landingPageVideoThumbnailTable").animate({"left" : marginLeft}, "slow");
		}
		// hide/show arrows
		if(currentLastElement >= numberElement)
		{
			$(".landingCarouselArrow .next").css("display", "none");
			$(".landingCarouselArrow .preview").css("display", "block");
		}else{
			$(".landingCarouselArrow .landingCarouselArrow .next").css("display", "block");
			$(".landingCarouselArrow .preview").css("display", "block");
		}
	});        
   
   
    // for references accordion
    var voletOuvert = false;
    	
	$(".references span").click(function(){
		
		if(voletOuvert == false)
		{
		    $(".references").find("p").css("display", "block");
		    $(".references").find("span").css("background-image", "url('/images/moinsPuce.jpg')");
		    voletOuvert = true;
		}
		else if(voletOuvert == true){
		    $(".references").find("p").css("display", "none");
		    $(".references").find("span").css("background-image", "url('/images/plusPuceGrey.jpg')");
		    voletOuvert = false;		
		}
	
	});
	

    // for cta right carosel system
    if($('.carouselSlideshow').length > 0)
    {
	    firstSlideShowLoading = true;
	    totalElements = $('.carouselSlideshow > *').length; // for pagination
	    currentElement = 1;
	    var firstDefilCta = true;
	    prevCta = false;
	    
	    function determineNextElement()
	    {
	        if(!firstDefilCta)
	        {
		        if(currentElement == totalElements)
		        {
			        currentElement = 1;
		        }else{
			        currentElement++;
		        }
		    }
		    
		    firstDefilCta = false;
    		
		    $('.currentPage').text(currentElement);	    
	    }
	    
	    function determinePreviewElement()
	    {
            if(firstSlideShowLoading != true)
		    {
			    if(currentElement == 1)
			    {
				    currentElement = totalElements;
			    }else{
				    currentElement--;
			    }
		    }else{
			    currentElement = totalElements;
		    }
    		
		    $('.currentPage').text(currentElement);   
	    }
	    
	    function determineNextElementAuto()
	    {
	        if(!prevCta)
	        {
	            determineNextElement();
	        }
	        resizeBefore(); 
	        prevCta = false;
	    }
	    	    
	    $('#next').click(function (){
            //determineNextElement();
	    });
	    
	    $('#prev').click(function (){	
		    determinePreviewElement(); 
		    prevCta = true;
	    });
	    
	    $('.currentPage').text(currentElement);
	    $('.totalPages').text(totalElements);
	    
        $('.carouselSlideshow').cycle({
		    fx:     'scrollHorz', 
		    timeout: 6000, 
		    next:   '#next',
		    prev: 	'#prev',
		    before: determineNextElementAuto, 
		    pause: 1 		
	    });    
    }

    function resizeBefore()
    {
	    // for onLoad test
	    if(firstSlideShowLoading == true)
	    {
		    firstSlideShowLoading = false;
	    }
    }
    
    if($('.carouselSlideshow > *').length < 2)
    {
        $('.carouselLegend').css("display", "none");
    }
	
	// for footer radian
   currentHeight = $(".footerCloud").height();
   currentHeight += 25;
   
   $(".bckImg").css("height", currentHeight);
   
   
   // [BEGIN] for toggle in action-plan-steps result page
	$(".actionPlanResultTitle a").click(function(){
		
		if($(this).hasClass("selectedResult")){
	
		    $(this).parent().parent().parent().find(".actionPlanResultContent").css("display", "none");
			$(this).removeClass("selectedResult");
			$(this).css("color", "white");		

		}else{
		    
		    $(this).parent().parent().parent().find(".actionPlanResultContent").css("display", "block");
			$(this).addClass("selectedResult");
			$(this).css("color", "white");	
		}		

	});
	
	$(".titleAccordionContentAP a").click(function(){
		
		if($(this).hasClass("selected")){
		
		    $(this).css("background-image", "url(../images/actionPlan/result/plusPuceGrey.jpg)");
		    $(this).removeClass("selected");
			$(this).parent().next().removeClass("showElement");
		
		}else{

			$(this).css("background-image", "url(../images/actionPlan/result/moinsPuce.jpg)");
			$(this).addClass("selected");
			$(this).parent().next().addClass("showElement");
		
		}		
	});
	// [END] for toggle in action-plan-steps result page


    // function for profil tab color
    $('.profilAP2 tbody tr:nth-child(odd)').addClass('grey');
    $('.profilAP2 tbody tr td.darkGrey:odd').addClass('lightGrey'); 
	
	
	//Change la langue du share
	var addthis_config ={
		ui_language: "da"
	}
	
	
});


// script for resize system (Aa)

var sCookie  = 'pspAa';
var iDefSize = 11;
var iDefH2Size = 16;
var iMaxSize = 14;
var iMaxH2Size = 18;
var iMinSize = 11;
var iMinH2Size = 16;
var iCurSize = iDefSize;
var iCurH2Size = iDefH2Size;

 $(document).ready(function() {

    iCurSize = $.cookie(sCookie);
    var tempA = false;
    
    var hFooter = $(".bckImg").height();
    
    if(null == iCurSize)
    {
       iCurSize = iDefSize;     
       iCurH2Size = iDefH2Size;
    }else{
    
        // for footer resize
        $(".bckImg").height(hFooter + 40)
    
        // for tab system adaptation
        if((navigator.appName) == "Netscape")
        {
            $(".contentBoxTabTop").css('margin-top', '-25px');   
        } 
    }
    
    if(iCurSize == iDefSize)
    {
    
        // for footer resize
        $(".bckImg").height(hFooter)    
    
        // for tab system adaptation
        if((navigator.appName) == "Netscape")
        {
            $(".contentBoxTabTop").css('margin-top', '-21px');   
        }   
    }
    
    // for action plan
    $(".ctaButtom a").css('font-size', iDefSize);  
    
    // for Insulin interview
    $(".insulinInterviewLeftButton a").css('font-size', iDefSize);
    $(".ctaButtomAPBis a").css('font-size', iDefSize);
    
    $(".mainContent").css('font-size', iCurSize+'px');
    $(".footerLinks").css('font-size', (iCurSize-1)+'px');
    $(".footerCloudContainer").css('font-size', (iCurSize-1)+'px');
    $(".landingContentTop .ctaButtom a").css("font-size", "11px");
    
    // bullet point
    $(".mainContent ul").css('font-size', iCurSize+'px');
    $(".mainContent ol").css('font-size', iCurSize+'px');
    $(".mainContent ul li p").css('font-size', iCurSize+'px');
    $(".mainContent ol li p").css('font-size', iCurSize+'px');    
    
    // for profile page only
    $(".askAnExpertSlider p").css('font-size', (iCurSize)+'px'); 
    $(".reminderSettings p").css('font-size', (iCurSize)+'px'); 
    $(".reminderSettings h2").css('font-size', (iCurH2Size)+'px');  
    $(".profil2SliderRight h2").css('font-size', (iCurH2Size)+'px'); 
    $(".profil2SliderLeft a").css('font-size', (iCurSize)+'px'); 
    $(".profil2SliderLeft h2").css('font-size', (iCurH2Size)+'px'); 
    $(".divNotYetAnswered p").css('font-size', (iCurSize)+'px');
	$(".accordionContent .titleAccordionContent a").css('font-size', (iCurH2Size)+'px');
	
	// for change engager result page
	$(".resultChangeEngager .resultChangeEngagerContent .divWrongAnswers h2").css('font-size', (iCurH2Size)+'px');
    
    $(".greenLinkList p").css('font-size', (iCurSize)+'px'); 
    
    $("#plus_minus").click(function(){
        if(tempA == false)
        {
            
            // for footer resize
            $(".bckImg").height(hFooter + 40);
            
            // to the normal size
            if(iCurSize < iMaxSize)
            {
                iCurSize = iMaxSize;
            }
			if(iCurH2Size < iMaxH2Size)
            {
                iCurH2Size = iMaxH2Size;
            }
            $(".mainContent").css('font-size', iCurSize+'px');
            $(".footerLinks").css('font-size', (iCurSize-1)+'px');
            
            // for tab system adaptation
            if((navigator.appName) == "Netscape")
            {
                $(".contentBoxTabTop").css('margin-top', '-25px');   
            }   
            
            // for Insulin interview
            $(".insulinInterviewLeftButton a").css('font-size', iDefSize);
            $(".ctaButtomAPBis a").css('font-size', iDefSize);
            
            // bullet point
            $(".mainContent ul li").css('font-size', iCurSize+'px');
            $(".mainContent ol li").css('font-size', iCurSize+'px');
            $(".mainContent ul li p").css('font-size', iCurSize+'px');
            $(".mainContent ol li p").css('font-size', iCurSize+'px');
                        
            // for profile page only
            $(".askAnExpertSlider p").css('font-size', (iCurSize)+'px'); 
            $(".reminderSettings p").css('font-size', (iCurSize)+'px'); 
            $(".reminderSettings h2").css('font-size', (iCurH2Size)+'px'); 
            $(".profil2SliderRight h2").css('font-size', (iCurH2Size)+'px'); 
            $(".profil2SliderLeft a").css('font-size', (iCurSize)+'px'); 
            $(".profil2SliderLeft h2").css('font-size', (iCurH2Size)+'px'); 
            $(".divNotYetAnswered p").css('font-size', (iCurSize)+'px');
			$(".accordionContent .titleAccordionContent a").css('font-size', (iCurH2Size)+'px');
			
			// for change engager result page
			$(".resultChangeEngager .resultChangeEngagerContent .divWrongAnswers h2").css('font-size', (iCurH2Size)+'px');
            
            $(".greenLinkList p").css('font-size', (iCurSize)+'px');         
            
            $(".footerCloudContainer").css('font-size', (iCurSize-1)+'px');
            $(".landingContentTop .ctaButtom a").css("font-size", "11px");
            $.cookie(sCookie, iCurSize, {path:'/'});        
            tempA = true;
        }else{
            
            // for footer resize
            $(".bckImg").height(hFooter);
        
            // to the small size
            if(iCurSize > iMinSize)
            {
                iCurSize = iDefSize;
            }
			if(iCurH2Size > iMinH2Size)
            {
                iCurH2Size = iDefH2Size;
            }
            $(".mainContent").css('font-size', iCurSize+'px');
            $(".footerLinks").css('font-size', (iCurSize-1)+'px');
            $(".footerCloudContainer").css('font-size', (iCurSize-1)+'px');
            $(".landingContentTop .ctaButtom a").css("font-size", "11px");
            
            // for tab system adaptation
            if((navigator.appName) == "Netscape")
            {
                $(".contentBoxTabTop").css('margin-top', '-21px'); 
            }   
            
            // bullet point
            $(".mainContent ul li").css('font-size', (iCurSize)+'px');
            $(".mainContent ol li").css('font-size', (iCurSize)+'px');
            $(".mainContent ul li p").css('font-size', iCurSize+'px');
            $(".mainContent ol li p").css('font-size', iCurSize+'px');
            
            // for profile page only
            $(".askAnExpertSlider p").css('font-size', (iCurSize)+'px'); 
            $(".reminderSettings p").css('font-size', (iCurSize)+'px');
            $(".reminderSettings h2").css('font-size', (iCurH2Size)+'px');
            $(".profil2SliderRight h2").css('font-size', (iCurH2Size)+'px');
            $(".profil2SliderLeft a").css('font-size', (iCurSize)+'px'); 
            $(".profil2SliderLeft h2").css('font-size', (iCurH2Size)+'px'); 
            $(".divNotYetAnswered p").css('font-size', (iCurSize)+'px');  
			$(".accordionContent .titleAccordionContent a").css('font-size', (iCurH2Size)+'px');
			
			// for change engager result page
			$(".resultChangeEngager .resultChangeEngagerContent .divWrongAnswers h2").css('font-size', (iCurH2Size)+'px');
            
             $(".greenLinkList p").css('font-size', (iCurSize)+'px');        
            
            $.cookie(sCookie, iCurSize, {path:'/'});        
            tempA = false;
        }
    });   
	
}) ;

// script for change engager radio button test
function ChangeEngagerQCheck()
{
	// script for change engager radio button test
	$(".changeEngagerQBox .buttonMultipleChangeEngager").each(function(){
		var nbrChecked = $(this).find("input:checked").length;
		if(nbrChecked<1)
		{
			$(".changeEngagerQBoxErrorMessage").css("display","block");
			valRet = false;
			return valRet;
		}
		else
		{
			valRet = true;
		}
	});
	return valRet;
}



// script for insulin Interview
function insulinInterview()
{
    // count element number to check
    var nbElement = $("#JSForm > *").length;
  
    
    // for check testtest
    var addCookies = true;
    
    
    // for answer value stockage
    var qResult = new Array();


    // DOM traversing
    for(var i=0; i<nbElement; i++)
    {
        var temp = $("#JSForm").find("#qL" + i);
        var temp2 = temp.attr('class');
        var temp3 = ""; // for input value temp stockage

        if(temp2 == "JSFormButton")// for button
        {
        
            // count answer possibility
            var nbreQuest = ($("#qL0 span > *").length)/3;
            var nbreChecked = 0;
            
            for(var j=0; j<nbreQuest; j++)
            {
                if ($("input#q"+i+"-"+j).is(':checked')) 
                {
                    nbreChecked++;
                    temp3 = $("input#q"+i+"-"+j).val();
                }
            }
            
            // check if an answer if checked
            if(nbreChecked<2 && nbreChecked>0)
            {
                // push value in qResult array
                qResult[i] = temp3;
            }else{
                // no value checked
                insulinInterviewError(1);
                addCookies = false;

                return false;                              
            }
            
            
        }
        else if(temp2 == "JSFormSlider")// for slider
        { 
            
            var tempScroll = $("#JSForm").find("#qL" + i);
            var tempScrollResult = 0;
            
            // find slider value
            tempScrollResult = $(tempScroll).find(".sliderInfo").val();
            
            // push value in qResult array
            qResult[i] = tempScrollResult;
        }       
        
    }
    
    // add cookies
    if(addCookies)
    {
        addInsulinInterviewCookies(qResult);
    }  
}


function insulinInterviewError(r)
{
    if(r == 1)
    {
        $(".interviewErrorMsg").css('display', 'block');
    }
}


function addInsulinInterviewCookies(qResult)
{
    date=new Date;
    date.setMonth(date.getMonth()+1); // for one month
    
    for(var i=0; i<6; i++)
    {
        write_cookie("insulinInterviewCookies" + i, qResult[i], date);
        
        if(i == 5)
        {
            // for url validation
            return true;
        }
    }
    

}


// functions for cookies gestion
function write_cookie(nom, valeur, expires) {
  document.cookie=nom+"="+escape(valeur)+
  ((expires==null) ? "" : ("; expires="+expires.toGMTString()));
}

function arguments_cookies(offset){
  var endstr=document.cookie.indexOf (";", offset);
  if (endstr==-1) endstr=document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr)); 
}

function read_cookie(nom) {
  var arg=nom+"=";
  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 arguments_cookies(j);
    i=document.cookie.indexOf(" ",i)+1;
    if (i==0) break;
  }
  return null; 
}

var params = {
	quality: "high",
	align: "middle",
	play: "true",
	loop: "true",
	allowFullScreen:"true",
	devicefont: "false",
	scale: "showall",
	id: "flashObject",
	wmode: "transparent"
};


// script for random picture in Good life with diabetes page
function randomPicture()
{
    $(document).ready(function() {
    
        var randomnumber = Math.floor(Math.random()*3);
        $(this).find(".randomPicture img:eq(" + randomnumber + ")").css("display", "block");
    });   
}
function randomPicture2()
{
    $(document).ready(function() {
    
        var randomnumber = Math.floor(Math.random()*2);
        $(this).find(".randomPicture img:eq(" + randomnumber + ")").css("display", "block");
    });   
}

/*
// for add this configuration
var addthis_config = {
    
    services_exclude: 'email',
    services_custom : {
        name: "Courriel",
        url: "http://" + location.hostname + "/send-to-friend.aspx?previewUrl=" + document.URL + "&previewTitle=",
        icon: "/images/mail.jpg"
    }
     
}
*/
// for action plan step update panel js update
function actionPlanUpdatePanel()
{
   
    // [BEGIN] for toggle in action-plan-steps result page
    $(".actionPlanResultTitle a").click(function(){
		
        if($(this).hasClass("selectedResult")){
	
            $(this).parent().parent().parent().find(".actionPlanResultContent").css("display", "none");
	        $(this).removeClass("selectedResult");
	        $(this).css("color", "white");		

        }else{
		    
            $(this).parent().parent().parent().find(".actionPlanResultContent").css("display", "block");
	        $(this).addClass("selectedResult");
	        $(this).css("color", "white");	

        }		

    });
	
    $(".titleAccordionContentAP a").click(function(){
		
        if($(this).hasClass("selected")){
		
            $(this).css("background-image", "url(../images/actionPlan/result/plusPuceGrey.jpg)");
            $(this).removeClass("selected");
	        $(this).parent().next().removeClass("showElement");
		
        }else{

	        $(this).css("background-image", "url(../images/actionPlan/result/moinsPuce.jpg)");
	        $(this).addClass("selected");   
	        $(this).parent().next().addClass("showElement");
		
        }		
    });
    // [END] for toggle in action-plan-steps result page	    

}
//function for send country variable to flash player for Omniture tracking
function getCountryForOmniture(){
	var omnitureCountry = "";
	var countryHostName = window.location.hostname;
	var extension=countryHostName.substring(countryHostName.lastIndexOf("."));
	if(extension==".in")
	{omnitureCountry = "novo2changingmydiabetesin,novocbtchangingmultisuitein";}
	if(extension==".dk")
	{omnitureCountry = "novochangingmydiabetesdk";}
	if(extension==".com")
	{omnitureCountry = "novo2changingmydiabetescom,novocbtchangingmultisuitecom";}
	return omnitureCountry;
}


function checkBoxValid1() {
    $(document).ready(function() {

        var valid0 = false;
        var valid1 = false;
        var validTotal = false;

        var n = $(".chckBoxTherapyValidator input:checked").length;
        if (n > 0) {
            valid0 = true;
        }

        var n1 = $(".chckBoxTherapyValidatorBis input:checked").length;
        if (n1 > 0) {
            valid1 = true;
        }

        if (valid0 == true && valid1 == true) {
            validTotal = true;
        }

        return validTotal;

    });

}  

function checkBoxValid2() {
    $(document).ready(function() {

        var valid0 = false;

        var n = $(".chckBoxTherapyValidatorMedication input:checked").length;
        if (n > 0) {
            valid0 = true;
        }

        return valid0;

    });

}

function checkBoxValid3() {
    $(document).ready(function() {

        var valid0 = false;
        var valid1 = false;
        var validTotal = false;

        var n = $(".chckBoxTherapyValidatorHealth1 input:checked").length;
        if (n > 0) {
            valid0 = true;
        }

        var n1 = $(".chckBoxTherapyValidatorHealth2 input:checked").length;
        if (n1 > 0) {
            valid1 = true;
        }

        if (valid0 == true && valid1 == true) {
            validTotal = true;
        }

        return validTotal;

    });

}

function checkBoxValidRegistration()
{
	$(document).ready(function(){
	 
	 var valid0 = false;
	 var valid1 = false;
	 var valid2 = false;
	 var validTotal = false;
	 
	 var n = $(".chckBoxTherapyValidator input:checked").length;
	 if(n>0)
	 {
		valid0 = true;
	 }
	 
	 var n1 = $(".chckBoxTherapyValidatorBis input:checked").length;
	 if(n1>0)
	 {
		valid1 = true;
	 }
							  
	 var n2 = $(".chckBoxTherapyValidatorBis2 input:checked").length;
	 if(n2>0)
	 {
		valid2 = true;
	 }
	 
	 if(valid0==true && valid1==true && valid2==true)
	 {
		validTotal = true;
	 }
												
	 return validTotal;
	 });
}
