﻿
var btnClicked = "";
var currentQuestion;
function closeInfoBubble()
{    
    $('#bubble').css('display', 'none');
}
function openInfoBubble(id)
{//open the information bubble based on the link that was clicked
    var activeLink;
    activeLink = "#info" + id;
    $('#bubble').css('display', 'block');
    $('#ctl00_ctl00_ContentPlaceholderMain_MainContent_bubbleText>*').css('display', 'none');
    $(activeLink).css('display', 'block');   
}
function startSlide()
{//this transitions from the get started page into the questions (slideshow)
    $('#getStarted').css('display', 'none');
    $('#progressBar').css('display', 'block');
    $('#btnHolder').css('display', 'block');
    $('#bottomer').css('display', 'none');
 
    $('#ctl00_ctl00_ContentPlaceholderMain_MainContent_divTransition').cycle(
    {//slideshow settings
        fx: 'scrollLeft',
        timeout:0,
        easing: 'backinout',
        after: onAfter,
        before: onBefore,
        prev: '#btnPrevious',
        next: '#btnNext',
        startingSlide: 0
    });
    disablePrevious();
    disableNext();
}
function onBefore()
{//close the information bubble before the slide transitions to the next question
    closeInfoBubble();
} 
function onAfter()
{//determine which function to call based on which button was clicked after the slide has been transitioned
//btnClicked variable is set on the onclick of the button
    if(btnClicked == 'next'){
        nextQuestion();}
    else if(btnClicked == 'prev'){
        previousQuestion();}
}
function nextB()
{
    btnClicked = "next";
}
function prevB()
{
btnClicked = 'prev';
}
function disableNext()
{
    $('#btnNext').attr('disabled', 'disabled');
    $('#btnNext').removeAttr('class', 'enabledNext');
    $('#btnNext').attr('class', 'disabledNext');
}
function enableNextBtn()
{
    $('#btnNext').removeAttr('disabled');
    $('#btnNext').removeAttr('class', 'disabledNext');
    $('#btnNext').attr('class', 'enabledNext');    
}
function disablePrevious()
{
    $('#btnPrevious').attr('disabled', 'disabled');
    $('#btnPrevious').removeAttr('class', 'enabledPrevious');
    $('#btnPrevious').attr('class', 'disabledPrevious');
}
function enablePrevious()
{
    $('#btnPrevious').removeAttr('class', 'disabledPrevious');
    $('#btnPrevious').attr('class', 'enabledPrevious');
    $('#btnPrevious').removeAttr('disabled');
}
function nextQuestion()
{  //disable previous step button if the first question is visible
    if($('#question1').css('display') != 'block')
        enablePrevious();
        
    disableNext();
    
    //enable next step button if an answer was given previously    
    getCurrentQuestion();
    
    var selectedAnswer = "input[name='question" + currentQuestion + "']:checked";
    if($(selectedAnswer).val() != null)
        enableNextBtn(); 
        
    if($('#getResults').css('display') == 'block'){
    //stop the slideshow when it reaches the end of all questions  
        $('#ctl00_ctl00_ContentPlaceholderMain_MainContent_divTransition').cycle('stop');
        $('#btnHolder').css('display', 'none');
        $('#progressBar').css('display', 'none');
        produceResults();
    }      
}
function previousQuestion()
{ 
    if($('#question1').css('display') == 'block')
        { disablePrevious();}
    else 
        enablePrevious(); 
    enableNextBtn();   
}

function enableNext(value){
    //enables the next button when the user selects an answer    
    
    getCurrentQuestion();
    var currentProgress = "#progress" + currentQuestion;
   $(currentProgress).removeAttr('class', 'empty-circle');
   $(currentProgress).attr('class', 'filled-circle');
   $('#questionNr').text(currentQuestion + " of 8");
    var selectedAnswer = value;
    enableNextBtn();    
}
function getCurrentQuestion()
{
    $("div .questions").each(function(){
        if( $(this).attr('style').indexOf('block') > 0 )
        {
            var style;
            style = $(this).attr('style').toUpperCase();
            
            if ((style.indexOf('Z-INDEX: 9') >= 0) || (style.indexOf('Z-INDEX: 10') >= 0))
            {
                currentQuestion = $(this).attr("id").substring(8,9);
            }
        }
    });
}

//***************** results page ***********************//
// populate the result query string
var queryString = '';
var question1 = ''; 
var question2 = ''; 
var question3 = '';
var question4 = '';
var question5 = '';
var question6 = '';
var question7 = '';
var question8 = '';

function produceResults()
{
    question1 = $("input[name='question1']:checked").val(); 
    question2 = $("input[name='question2']:checked").val();
    question3 = $("input[name='question3']:checked").val();
    question4 = $("input[name='question4']:checked").val();
    question5 = $("input[name='question5']:checked").val();
    question6 = $("input[name='question6']:checked").val();
    question7 = $("input[name='question7']:checked").val();
    question8 = $("input[name='question8']:checked").val();
    
    queryString = "q1=";
    if(question1 == '1_1')
        queryString += '1A';
    else if(question1 == '1_2')
        queryString += '1B';
    else if(question1 == '1_3')
        queryString += '1C';
    else if(question1 == '1_4')
        queryString += '1D';
    else
        queryString += '1E';
    
    queryString += '&q2=';
    if(question2 == '2_1')
        queryString += '2A';
    else if(question2 == '2_2')
        queryString += '2B';
    else 
        queryString +='2C';
        
    q3();
    q4();
    q5();
    q6();
    q7();
    q8();
    window.location = '/feeding-nutrition/results?' + queryString;
}
function q3()
{
    queryString += '&q3=';
    if(question3 == '3_1')
    {
        if(question2 == '2_3')
        {
            if (question1 == '1_1' || question1 == '1_2' || question1 =='1_3')
                queryString += '3A123F';
            else if(question1 == '1_4' || question1 == '1_5')
                queryString += '3A45F';
        }
        else if(question2 == '2_1' || question2 == '2_2')
        {
            if(question1 == '1_1' || question1 == '1_2')
                queryString +='3A12SB';
            else if(question1 == '1_3')
                queryString += '3A3SB';
            else if(question1 == '1_4' || question1 == '1_5')
                queryString += '3A45SB';
        }             
    }
    else if(question3 == '3_2')
        queryString += '3BNR';
    else if(question3 = '3_3')
    {
        if(question2 == '2_3')
        {
            if (question1 == '1_1' || question1 == '1_2')
                queryString += '3C12F';
            else if (question1 == '1_3')
                queryString += '3C3F';
            else if (question1 == '1_4' || question1 == '1_5')
                queryString += '3C45F';
        }
        else if (question2 == '2_1' || question2 == '2_2')
        {
             if (question1 == '1_1' || question1 == '1_2' || question1 == '1_3')
                queryString += '3C123SB';
            else if (question1 == '1_4' || question1 == '1_5')
                queryString += '3C45SB';
        }
    }                
   
}
function q4()
{
    queryString+= '&q4=';
    if (question4 == '4_1')
    {   
        if (question2 == '2_3')
        {
            if (question1 == '1_1')
                queryString += '4A1F';
            else
                queryString += '4A2345F';
        }
        else if(question2 == '2_2')
        {
            if(question1 == '1_1')
                queryString += '4A1S';
            else if(question1 == '1_2' || question1 == '1_3')
                queryString += '4A23S';
            else
                queryString += '4A45S';
        }
        else 
        {
            if(question1 == '1_1')
                queryString += '4A1B';
            else if(question1 == '1_2' || question1 == '1_3')
                queryString += '4A23B';
            else 
                queryString += '4A45B'; 
        }
    }
    else if(question4 == '4_2')
    {
        if(question2 == '2_3')
        {
            if(question1 == '1_1')
                queryString += '4B1F';
            else
                queryString += '4B2345F';           
        }
        else if(question2 == '2_2')
        {
            if(question1 == '1_1')
                queryString += '4B1S';
            else if(question1 == '1_2' || question1 == '1_3')
                queryString += '4B23S';
            else 
                queryString += '4B45S';
        }        
         else
         {
            if(question1 == '1_1')
                queryString += '4B1B';
            else if(question1 == '1_2' || question1 == '1_3')
                queryString += '4B23B';
            else 
                queryString += '4B45B';
        }
    }
    else
        queryString += '4CNR';
}
function q5()
{
    queryString += '&q5=';
    if(question5 == '5_1')
    {
        if(question2 == '2_1')
        {
            if(question1 == '1_4' || question1 == '1_5')
                queryString += '5A45B';
            else
                queryString += '5A123B';
        }
        else
        {
           if(question1 == '1_1')
                queryString += '5A1FS';
            else if(question1 == '1_2' || question1 == '1_3')
                queryString += '5A23FS';
            else 
                queryString += '5A45FS';
        }      
    }
    else if(question5 == '5_2')
    {
        if(question2 == '2_1')
        {
            if(question1 == '1_1' || question1 == '1_2')
                queryString += '5B12B';
            else
                queryString += '5B345B';
        }
        else if(question2 == '2_2')
        {
            if(question1 == '1_1' || question1 =='1_2')
                queryString += '5B12S';
            else if (question1 == '1_3')
                queryString += '5B3S';
            else
                queryString += '5B45S';
        }
        else 
        {
            if(question1 == '1_1' || question1 =='1_2')
                queryString += '5B12F';
            else if (question1 == '1_3')
                queryString += '5B3F';
            else
                queryString += '5B45F';
        }
    }
    else
        queryString += '5CNR';      
}
function q6()
{
queryString += '&q6=';
    if(question6 == '6_1')
    {   
        queryString += '6ANR';
    }
    else
    {
        queryString += '6BNR';
    }
}
function q7()
{
    queryString += '&q7=';
    if(question7 == '7_1')
    {
        if(question2 == '2_3')
            queryString += '7AF';
        else if (question2 == '2_2')
        {
            if(question1 == '1_1' )
                queryString += '7A1S';
            else if (question1 == '1_3'|| question1 =='1_2')
                queryString += '7A23S';
            else
                queryString += '7A45S';
        }
        else
        {
            if(question1 == '1_1' )
                queryString += '7A1B';
            else if (question1 == '1_3'|| question1 =='1_2')
                queryString += '7A23B';
            else
                queryString += '7A45B';
        }        
    }
    else if(question7 == '7_2')
    {
        if(question2 == '2_3')
        {
            if(question1 == '1_1')
                queryString += '7B1F';
            else 
                queryString += '7B2345F';
        }
        else 
        {
            if(question1 == '1_1')
                queryString += '7B1SB';
            else 
                queryString += '7B2345SB';
        }
    }
    else
        queryString += '7CNR';
}
function q8()
{
    queryString += '&q8=';
    if(question8 == '8_1')
    {
        if(question2 == '2_1')
            queryString += '8AB';
        else if(question2 == '2_2')
            queryString += '8AS';
        else    
            queryString += '8AF';
    }
    else 
        queryString += '8BNR';    
}