﻿/** !!! READ THIS !!!
*
* NOTE: Much of this javascript file depends on the client IDs written by asp.net. When used within
* a master page the ID elements will be rewritten and this file will need to be updated with that prefix.
* Currently on minnkota motor's production site, that prefix is: ctl00_ctl00_skin_body_area_body_
* The CSS files (all 3 of them) will also need to be updated with this prefix. This can be solved with a
* Global find/replace of the prefix.
*/

function setDefaults() {
    $("input[id$='Section1ValueHiddenField']").val("0");
    $("input[id$='Section2ValueHiddenField']").val("0");
    $("input[id$='Section3ValueHiddenField']").val("0");
    $("input[id$='Section4ValueHiddenField']").val("0");
    $("input[id$='Section5ValueHiddenField']").val("0");
    $("input[id$='Section6ValueHiddenField']").val("0");
    $("input[id$='LightBoxCloseHiddenField']").val("0");
    $("input[id$='TabClickedHiddenField']").val("false");
    $("input[id$='ResultsHidingOverride']").val("false");
    $("input[id$='CurrentNavigationHiddenField']").val("0");
    $("input[id$='NavigationHiddenField']").val("0");
    $("input[id$='CurrentSectionHiddenField']").val("1");
    $("input[id$='SectionHiddenField']").val("1");
    $("input[type='radio']").val("0");
}

function initializeMotorSelection()
{
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(showMotorSelection);
    showLightBox();
    showResultsOverlay(true);
}


function showHelp(url) {
    $("#learn_more_lightbox").load(url, null, function() {
        $("#learn_more_lightbox").css({ display: 'block' }).width($('form').width()).height($('form').height());
        $("#selectamotor_overlay").css({ display: 'block' }).width($('form').width()).height($('form').height());

        $(".close").click(function() {
            $("#learn_more_lightbox").css({ display: 'none' });
            $("#selectamotor_overlay").css({ display: 'none' });
        });
    });
}

//$(document).ready(realignSelectionBox);

function realignSelectionBox() {
    if($('#selectamotor_overlay:visible').length > 0) {
        $('#selectamotor_overlay').height($('form').height());
        $('#selectamotor_overlay').width($('form').width());
        $('#selectamotor_lightbox').width($('form').width());
        var pos = {
          sTop : function() {
            return window.pageYOffset
            || document.documentElement && document.documentElement.scrollTop
            ||  document.body.scrollTop;
          },
          wHeight : function() {
            return window.innerHeight
            || document.documentElement && document.documentElement.clientHeight
            || document.body.clientHeight;
          }
        };
        
        $('#selectamotor_lightbox').each(function() {
            var $this = $(this);
            var elHeight = $this.height();
            var elTop = pos.sTop() + (pos.wHeight() / 2) - (elHeight / 2);
            $this.css({
              position: 'absolute',
              marginTop: '0',
              top: elTop
            });
        });
    }
}

$(window).resize(realignSelectionBox);
$(window).scroll(realignSelectionBox);

   
function showLightBox()
{
    $("#selectamotor_overlay").css({
        'display': 'block'
    });
    $("#selectamotor_lightbox").css({ 'display': 'block' }).width($('form').width());//.height($('form').height());
    $("#selectamotor_overlay").remove().prependTo('body').width($('form').width());//.height($('form').height());
}

function hideLightBox(navigationIndex) {
    setDefaults();
    $("#selectamotor_overlay").css({ 'display': 'none' });
    $("#selectamotor_lightbox").css({ 'display': 'none' });

    selectNavigation(navigationIndex);
}

function doMotorOptions()
{
    document.getElementById("LightBoxCloseHiddenField").value = 1;
    showResultsOverlay(false);
    doPostBack();
}

function showResultsOverlay(show)
{
    var overlay = $("[id$='no_results_overlay']");
    var lightBox = $("[id$='no_results_lightbox']");

    if (show)
    {
        overlay.show();
        lightBox.show();
        $("#results").addClass('placeholder');
    }
    else
    {
        overlay.hide();
        lightBox.hide();
        $("#results").removeClass('placeholder');
    }    
}

function doNextStep()
{
    var currentSectionIndex = parseInt($("input[id$='CurrentSectionHiddenField']").val());
    var sectionIndex = parseInt($("input[id$='SectionHiddenField']").val()) + 1;
    $("input[id$='TabClickedHiddenField']").val("false");
    if (sectionIndex < 7) {
        selectSection(sectionIndex);
    } else if (sectionIndex > 6) {
        selectSection(999); //MOTOR OPTIONS
    }
}

function showMotorSelection() {
    $("input[@type='checkbox']:disabled").parent().nextAll('h5').addClass('disabled');

    $("input[id$='TabClickedHiddenField']").val("true");

    $(".motoroptions").click(function() {
        selectSection(999);
        return false;
    });

    $("a.select").click(function() {
        showLightBox();
    });

    $("input:disabled + label").addClass("disabled");
    
    var navigationIndex = parseInt($("input[id$='NavigationHiddenField']").val());
    var sectionIndex = parseInt($("input[id$='SectionHiddenField']").val());
    
    showNavigation(navigationIndex);
    showSection(sectionIndex);

    if ($("[id$='no_results_overlay']").css("display") == "block") {
        showResultsOverlay(true);
    } else {
        showResultsOverlay(false);
    }
}

function selectNavigation(navigationIndex)
{
    var currentNavigationIndex = parseInt($("input[id$='CurrentNavigationHiddenField']").val());
        
        
        $("input[id$='CurrentNavigationHiddenField']").val(navigationIndex);
        $("input[id$='NavigationHiddenField']").val(navigationIndex);
        
        $("input[id$='SectionHiddenField']").val(1);
        $("input[id$='CurrentSectionHiddenField']").val(1);

        switch (navigationIndex) {
            case 1:
                $("div#header").addClass("freshwater").removeClass("saltwater").removeClass("primarypropulsion");
                break;
            case 2:
                $("div#header").addClass("saltwater").removeClass("freshwater").removeClass("primarypropulsion");
                break;
            case 3:
                $("div#header").addClass("primarypropulsion").removeClass("saltwater").removeClass("freshwater");
                break;
        }
        
        doPostBack();
    
}

function selectSection(sectionIndex,ignorePostBack)
{
    var currentSectionIndex = parseInt($("input[id$='CurrentSectionHiddenField']").val());
    if (currentSectionIndex != sectionIndex  || $("#motor_options").length > 0)
    {
        $("input[id$='CurrentSectionHiddenField']").val(sectionIndex);
        $("input[id$='SectionHiddenField']").val(sectionIndex);
                
        if(!ignorePostBack) doPostBack(); 
    }
}

function showNavigation(navigationIndex) {
    if (document.getElementById("FreshwaterListItem")) {
        var freshwaterListItem = document.getElementById("FreshwaterListItem");
        var saltwaterListItem = document.getElementById("SaltwaterListItem");
        var primaryListItem = document.getElementById("PrimaryListItem");

        switch (navigationIndex) {
            case 1:
                freshwaterListItem.className = "active";
                saltwaterListItem.className = "";
                primaryListItem.className = "";
                break;

            case 2:
                freshwaterListItem.className = "";
                saltwaterListItem.className = "active";
                primaryListItem.className = "";
                break;

            case 3:
                freshwaterListItem.className = "";
                saltwaterListItem.className = "";
                primaryListItem.className = "active";
                break;
        }
    }	            
}

function showSection(sectionIndex) {

    if (document.getElementById("BoatTypeListIndex")) {
        var boatTypeListIndex = document.getElementById("BoatTypeListIndex");
        var boatLengthListIndex = document.getElementById("BoatLengthListIndex");
        var motorLocationListIndex = document.getElementById("MotorLocationListIndex");
        var shaftLengthListIndex = document.getElementById("ShaftLengthListIndex");
        var steeringControlListIndex = document.getElementById("SteeringControlListIndex");
        var batteriesListIndex = document.getElementById("BatteriesListIndex");

        var boatTypeSelection = document.getElementById("BoatTypeSelection");
        var boatLengthSelection = document.getElementById("BoatLengthSelection");
        var motorLocationSelection = document.getElementById("MotorLocationSelection");
        var shaftLengthSelection = document.getElementById("ShaftLengthSelection");
        var steeringControlSelection = document.getElementById("SteeringControlSelection");
        var batteriesSelection = document.getElementById("BatteriesSelection");

        switch (sectionIndex) {
            case 1:
                boatTypeListIndex.className = "active";
                boatLengthListIndex.className = "";
                motorLocationListIndex.className = "";
                shaftLengthListIndex.className = "";
                steeringControlListIndex.className = "";
                batteriesListIndex.className = "";

                boatTypeSelection.className = "boattypeActive";
                boatLengthSelection.className = "boatlength";
                motorLocationSelection.className = "motorlocation";
                shaftLengthSelection.className = "shaftlength";
                steeringControlSelection.className = "steeringcontrol";
                batteriesSelection.className = "batteries";

                break;

            case 2:
                boatTypeListIndex.className = "set";
                boatLengthListIndex.className = "active";
                motorLocationListIndex.className = "";
                shaftLengthListIndex.className = "";
                steeringControlListIndex.className = "";
                batteriesListIndex.className = "";

                boatTypeSelection.className = "boattype";
                boatLengthSelection.className = "boatlengthActive";
                motorLocationSelection.className = "motorlocation";
                shaftLengthSelection.className = "shaftlength";
                steeringControlSelection.className = "steeringcontrol";
                batteriesSelection.className = "batteries";
                break;
            case 3:
                boatTypeListIndex.className = "set";
                boatLengthListIndex.className = "set";
                motorLocationListIndex.className = "";
                shaftLengthListIndex.className = "";
                steeringControlListIndex.className = "";
                batteriesListIndex.className = "active";

                boatTypeSelection.className = "boattype";
                boatLengthSelection.className = "boatlength";
                motorLocationSelection.className = "motorlocation";
                shaftLengthSelection.className = "shaftlength";
                steeringControlSelection.className = "steeringcontrol";
                batteriesSelection.className = "batteriesActive";
                break;


            case 4:
                boatTypeListIndex.className = "set";
                boatLengthListIndex.className = "set";
                motorLocationListIndex.className = "active";
                shaftLengthListIndex.className = "";
                steeringControlListIndex.className = "";
                batteriesListIndex.className = "set";

                boatTypeSelection.className = "boattype";
                boatLengthSelection.className = "boatlength";
                motorLocationSelection.className = "motorlocationActive";
                shaftLengthSelection.className = "shaftlength";
                steeringControlSelection.className = "steeringcontrol";
                batteriesSelection.className = "batteries";
                break;

            case 5:
                boatTypeListIndex.className = "set";
                boatLengthListIndex.className = "set";
                motorLocationListIndex.className = "set";
                shaftLengthListIndex.className = "";
                steeringControlListIndex.className = "active";
                batteriesListIndex.className = "set";

                boatTypeSelection.className = "boattype";
                boatLengthSelection.className = "boatlength";
                motorLocationSelection.className = "motorlocation";
                shaftLengthSelection.className = "shaftlength";
                steeringControlSelection.className = "steeringcontrolActive";
                batteriesSelection.className = "batteries";
                break;


            case 6:
                boatTypeListIndex.className = "set";
                boatLengthListIndex.className = "set";
                motorLocationListIndex.className = "set";
                shaftLengthListIndex.className = "active";
                steeringControlListIndex.className = "set";
                batteriesListIndex.className = "set";

                boatTypeSelection.className = "boattype";
                boatLengthSelection.className = "boatlength";
                motorLocationSelection.className = "motorlocation";
                shaftLengthSelection.className = "shaftlengthActive";
                steeringControlSelection.className = "steeringcontrol";
                batteriesSelection.className = "batteries";
                break;

           
           
            default:
                boatTypeListIndex.className = "set";
                boatLengthListIndex.className = "set";
                motorLocationListIndex.className = "set";
                shaftLengthListIndex.className = "set";
                steeringControlListIndex.className = "set";
                batteriesListIndex.className = "set";

                boatTypeSelection.className = "boattype";
                boatLengthSelection.className = "boatlength";
                motorLocationSelection.className = "motorlocation";
                shaftLengthSelection.className = "shaftlength";
                steeringControlSelection.className = "steeringcontrol";
                batteriesSelection.className = "batteries";
                break;

        }
    }		    	            	            
}        
