var printValues = "";

function dubzSlider (thisSlide)
{
	$(thisSlide).slider({
		min: 0,
		max: stopValue,
		slide: function(event, ui) {
		
            var var1 = $("#slide1").data("value.slider"); var var2 = $("#slide2").data("value.slider"); var var3 = $("#slide3").data("value.slider"); var var4 = $("#slide4").data("value.slider"); var var5 = $("#slide5").data("value.slider"); var var6 = $("#slide6").data("value.slider"); var var7 = $("#slide7").data("value.slider"); var var8 = $("#slide8").data("value.slider"); var var9 = $("#slide9").data("value.slider"); var var10 = $("#slide10").data("value.slider"); var slideValue = ""; var resultsValue = "";

            switch(thisSlide)
            {
                case "#slide1":
                    var1 = ui.value; slideValue = "#slide1Value"; resultsValue = "#results1";
                    $("#calcMid #mirror-right #whitePod #mid #tip #tip0").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip1").show(); $("#calcMid #mirror-right #whitePod #mid #tip #tip2").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip3").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip4").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip5").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip6").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip7").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip8").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip9").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip10").hide();
                    break;
                case "#slide2":
                    var2 = ui.value; slideValue = "#slide2Value"; resultsValue = "#results2";
                    $("#calcMid #mirror-right #whitePod #mid #tip #tip0").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip1").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip2").show(); $("#calcMid #mirror-right #whitePod #mid #tip #tip3").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip4").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip5").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip6").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip7").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip8").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip9").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip10").hide();
                    break;
                case "#slide3":
                    var3 = ui.value; slideValue = "#slide3Value"; resultsValue = "#results3";
                    $("#calcMid #mirror-right #whitePod #mid #tip #tip0").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip1").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip2").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip3").show(); $("#calcMid #mirror-right #whitePod #mid #tip #tip4").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip5").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip6").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip7").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip8").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip9").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip10").hide();
                    break;
                case "#slide4":
                    var4 = ui.value; slideValue = "#slide4Value"; resultsValue = "#results4";
                    $("#calcMid #mirror-right #whitePod #mid #tip #tip0").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip1").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip2").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip3").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip4").show(); $("#calcMid #mirror-right #whitePod #mid #tip #tip5").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip6").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip7").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip8").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip9").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip10").hide();
                    break;
                case "#slide5":
                    var5 = ui.value; slideValue = "#slide5Value"; resultsValue = "#results5";
                    $("#calcMid #mirror-right #whitePod #mid #tip #tip0").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip1").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip2").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip3").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip4").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip5").show(); $("#calcMid #mirror-right #whitePod #mid #tip #tip6").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip7").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip8").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip9").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip10").hide();
                    break;
                case "#slide6":
                    var6 = ui.value; slideValue = "#slide6Value"; resultsValue = "#results6";
                    $("#calcMid #mirror-right #whitePod #mid #tip #tip0").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip1").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip2").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip3").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip4").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip5").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip6").show(); $("#calcMid #mirror-right #whitePod #mid #tip #tip7").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip8").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip9").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip10").hide();
                    break;
                case "#slide7":
                    var7 = ui.value; slideValue = "#slide7Value"; resultsValue = "#results7";
                    $("#calcMid #mirror-right #whitePod #mid #tip #tip0").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip1").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip2").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip3").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip4").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip5").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip6").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip7").show(); $("#calcMid #mirror-right #whitePod #mid #tip #tip8").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip9").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip10").hide();
                    break;
                case "#slide8":
                    var8 = ui.value; slideValue = "#slide8Value"; resultsValue = "#results8";
                    $("#calcMid #mirror-right #whitePod #mid #tip #tip0").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip1").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip2").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip3").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip4").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip5").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip6").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip7").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip8").show(); $("#calcMid #mirror-right #whitePod #mid #tip #tip9").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip10").hide();
                    break;
                case "#slide9":
                    var9 = ui.value; slideValue = "#slide9Value"; resultsValue = "#results9";
                    $("#calcMid #mirror-right #whitePod #mid #tip #tip0").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip1").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip2").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip3").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip4").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip5").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip6").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip7").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip8").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip9").show(); $("#calcMid #mirror-right #whitePod #mid #tip #tip10").hide();
                    break;
                case "#slide10":
                    var10 = ui.value; slideValue = "#slide10Value"; resultsValue = "#results10";
                    $("#calcMid #mirror-right #whitePod #mid #tip #tip0").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip1").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip2").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip3").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip4").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip5").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip6").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip7").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip8").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip9").hide(); $("#calcMid #mirror-right #whitePod #mid #tip #tip10").show();
                    break;
            }
            
			totalSlide = parseInt(var1)+parseInt(var2)+parseInt(var3)+parseInt(var4)+parseInt(var5)+parseInt(var6)+parseInt(var7)+parseInt(var8)+parseInt(var9)+parseInt(var10);
            printValues = var1 + "," + var2 + "," + var3 + "," + var4 + "," + var5 + "," + var6 + "," + var7 + "," + var8 + "," + var9 + "," + var10;

			if (totalSlide > stopValue)
			{
				return false;
			}
			else
			{
				$(slideValue).text(ui.value); $(resultsValue).text(ui.value);
				$("#totalSlideValue").text(totalSlide);
                $("#calcMid #mirror-right #whitePod #mid #copy #preTarget").show(); 
                $("#calcMid #mirror-right #whitePod #mid #copy #postTarget").hide(); 
                $("#calcMid #mirror-right #whitePod #mid #tip").show(); 
			    $("#calcMid #current").css({background:"none"});
			}
			
			if (totalSlide == stopValue)
			{
                $("#calcMid #mirror-right #whitePod #mid #copy #preTarget").hide(); 
                $("#calcMid #mirror-right #whitePod #mid #copy #postTarget").show(); 
                $("#calcMid #mirror-right #whitePod #mid #tip").hide();
                $("a#printResults").attr({href: "/printresults.aspx?scores="+printValues});
			    $("#calcMid #current").css({background:"#ff6602"});
                $("#emailResults").show();
			}
		}
	});
}


//  starting quiz values
var currentQuestion = 1;

var answer1 = 0;
var answer2 = 0;
var answer3 = 0;
var answer4 = 0;
var answer5 = 0;
var radAnswer = "";
//  /starting quiz values

function initQuiz()
{
    $("#Question2Item").hide();
    $("#Question3Item").hide();
    $("#Question4Item").hide();
    $("#Question5Item").hide();
    $("#btnPrev").hide();

    $(".group1").hide();
    $(".group2").hide();
    $(".group3").hide();
    $(".group4").hide();
    $("#tip2").hide();
    $("#tip3").hide();
    $("#tip4").hide();
    $("#tip5").hide();
    $("#tip6").hide();
    

    if (answer1 > 0)
    {
        $("#btnNext").show();
    }
    else
    {
        $("#btnNext").hide();
    }
    $("#quiz").show();
    $("#thanks").hide();
}


function switchItems(isScore)
{
    switch(currentQuestion)
    {
        case 1:
            if (isScore == true)
                catchScore("Question1");
            $("#Question1Item").show();
            $("#Question2Item").hide();
            $("#Question3Item").hide();
            $("#Question4Item").hide();
            $("#Question5Item").hide();
            $("#btnPrev").show();
            $("#tip1").show();
            $("#tip2").hide();
            $("#tip3").hide();
            $("#tip4").hide();
            $("#tip5").hide();
            $("#tip6").hide();
            //$("#quizContainer #mirror-right .pod").css({height:"auto"});
            if (answer2 > 0)
            {
                $("#btnNext").show();
            }
            else
            {
                $("#btnNext").hide();
            }
            $("#quiz").show();
            $("#thanks").hide();
            break;

        case 2:
            if (isScore == true)
                catchScore("Question1");
            $("#Question1Item").hide();
            $("#Question2Item").show();
            $("#Question3Item").hide();
            $("#Question4Item").hide();
            $("#Question5Item").hide();
            $("#btnPrev").show();
            $("#tip2").show();
            $("#tip1").hide();
            $("#tip3").hide();
            $("#tip4").hide();
            $("#tip5").hide();
            $("#tip6").hide();
            //$("#quizContainer #mirror-right .pod").css({height:"auto"});
            if (answer2 > 0)
            {
                $("#btnNext").show();
            }
            else
            {
                $("#btnNext").hide();
            }
            $("#quiz").show();
            $("#thanks").hide();
            break;

        case 3:
            if (isScore == true)
                catchScore("Question2");
            $("#Question1Item").hide();
            $("#Question2Item").hide();
            $("#Question3Item").show();
            $("#Question4Item").hide();
            $("#Question5Item").hide();
            $("#btnPrev").show();
            $("#tip3").show();
            $("#tip2").hide();
            $("#tip1").hide();
            $("#tip4").hide();
            $("#tip5").hide();
            $("#tip6").hide();
            //$("#quizContainer #mirror-right .pod").css({height:"220px"});
            if (answer3 > 0)
            {
                $("#btnNext").show();
            }
            else
            {
                $("#btnNext").hide();
            }
            $("#quiz").show();
            $("#thanks").hide();
            break;

        case 4:
            if (isScore == true)
                catchScore("Question3");
            $("#Question1Item").hide();
            $("#Question2Item").hide();
            $("#Question3Item").hide();
            $("#Question4Item").show();
            $("#Question5Item").hide();
            $("#btnPrev").show();
            $("#tip4").show();
            $("#tip2").hide();
            $("#tip3").hide();
            $("#tip1").hide();
            $("#tip5").hide();
            $("#tip6").hide();
            //$("#quizContainer #mirror-right .pod").css({height:"auto"});
            if (answer4 > 0)
            {
                $("#btnNext").show();
            }
            else
            {
                $("#btnNext").hide();
            }
            $("#quiz").show();
            $("#thanks").hide();
            break;

        case 5:
            if (isScore == true)
                catchScore("Question4");
            $("#Question1Item").hide();
            $("#Question2Item").hide();
            $("#Question3Item").hide();
            $("#Question4Item").hide();
            $("#Question5Item").show();
            $("#btnPrev").show();
            $("#tip5").show();
            $("#tip2").hide();
            $("#tip3").hide();
            $("#tip4").hide();
            $("#tip1").hide();
            $("#tip6").hide();
            //$("#quizContainer #mirror-right .pod").css({height:"auto"});
            if (answer5 > 0)
            {
                $("#btnNext").show();
            }
            else
            {
                $("#btnNext").hide();
            }
            $("#quiz").show();
            $("#thanks").hide();
            break;

        case 6:
            if (isScore == true)
                catchScore("Question5");
            $("#quiz").hide();
            $("#thanks").show();
            $("#tip1").hide();
            $("#tip2").hide();
            $("#tip3").hide();
            $("#tip4").hide();
            $("#tip5").hide();
            $("#tip6").show();
            
            $(".finalScore").text(currentScore);
            
            if (currentScore < 45)
                $(".group1").show();
            else if ((currentScore >= 45) && (currentScore < 65))
                $(".group2").show();
            else if ((currentScore >= 65) && (currentScore < 85))
                $(".group3").show();
            else if ((currentScore >= 85))
                $(".group4").show();
            
            break;
    }
}


function processAction(buttonType, isScore)
{
    // if previous, subtract 1 from currentQuestion
    if (buttonType == "prev")
    {
        if (currentQuestion > 0)
            currentQuestion = currentQuestion-1;
    }
    else
    {
        if (isScore)
        {
            // assume it's a *submit* action
            radAnswer = $("input[name='" + questionName(currentQuestion) + "']:checked").val();
            if (radAnswer.length == 0)
            {
                alert('You must select an answer');
                return false;
            }
            else
            {
                // only increment currentQuestion if radio button has been selected
                currentQuestion = currentQuestion+1;
            }
        }
        else
        {
            currentQuestion = currentQuestion+1;
        }
    }
    switchItems(isScore);
}


function catchScore(question)
{
    // get value of selected radio buton
    radAnswer = $("input[name='" + question + "']:checked").val();
    if (radAnswer.length == null)
    {
        alert('You must select an answer');
        return false;
    }
    
    switch(question)
    {
        case "Question1":
            answer1 = parseInt(radAnswer);
            break;
        case "Question2":
            answer2 = parseInt(radAnswer);
            break;
        case "Question3":
            answer3 = parseInt(radAnswer);
            break;
        case "Question4":
            answer4 = parseInt(radAnswer);
            break;
        case "Question5":
            answer5 = parseInt(radAnswer);
            break;
    }

    // add scores      
    currentScore = parseInt(answer1)+parseInt(answer2)+parseInt(answer3)+parseInt(answer4)+parseInt(answer5);
}


function questionName (questionNumber)
{
    var returnStr;

    switch(questionNumber)
    {
        case 1:
            returnStr = "Question1";
            break;
        case 2:
            returnStr = "Question2";
            break;
        case 3:
            returnStr = "Question3";
            break;
        case 4:
            returnStr = "Question4";
            break;
        case 5:
            returnStr = "Question5";
            break;
    }
    
    return returnStr;
}


function checkEmail(inputvalue){	
    var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
    if(pattern.test(inputvalue)){         
		return true;   
    }else{   
		return false; 
    }
}


