﻿// BuildAVehicle JavaScript

/*
#########################################################################################
## Global Section - All variables and/or constants                                     ##
#########################################################################################
*/

//Global Constants
OPTIONS_EXCLUDED = 1;
OPTIONS_INCLUDED = 2;
OPTIONS_REQUIRED = 3;
OPTIONS_NEWPRICE = 4;
OPTIONS_REQUIREONEOF = 5;

//Global Variables
var m_iPreviousExteriorColorId = null;
var m_iPreviousSummarySection = 1;
var m_oExteriorColorCell = null;
var m_oInteriorColorCell = null
var m_iInteriorOptionId = null;
var m_iExteriorOptionId = null;
var m_sDestinationCharge = "$0";
var m_iTimeout;
var m_oSelectedOption = null;
var m_iSelectedEdmundsIdExcluded = null;
var m_iSelectedEdmundsIdIncluded = null;
var m_iSelectedEdmundsIdRequired = null;
var m_iSelectedEdmundsIdNewPrice = null;

var JDPowerReviewCar1 = null;
var JDPowerReviewCar2 = null;
var JDPowerReviewCar3 = null;

var m_interstRate = 0;
var m_loanTerm = 0;

// Global Functions


/*
############################
## Used In Multiple Pages ##
############################
*/

// AcceptDialog_Accept_Click
// take user to next page if they accept the price change
// 
// @author	kgrove - 4/3/06
// @edit	-
// @param	p_bAcceptDialogOkClick - used for options page - should not be hard coded in here - need to figure out a better way
// @return	none
function AcceptDialog_Accept_Click(p_bAcceptDialogOkClick) {
    if (m_iAcceptDialogIndicator == 0) { // BuildAVehicleStep3
        var sVehicleOptions = "";
        
        if (m_iInteriorOptionId != null) {
            sVehicleOptions = m_iInteriorOptionId;
        }
        if (m_iExteriorOptionId != null) {
            if (m_iInteriorOptionId != null) {
                sVehicleOptions += "," + m_iExteriorOptionId;
            }
            else {
                sVehicleOptions = m_iExteriorOptionId;
            }
        }   
        window.location.href = "BuildAVehicleStep4.aspx?VehicleOptions=" + sVehicleOptions;
    }
    else if (m_iAcceptDialogIndicator == 1) { // BuildAVehicleStep4 - Previous Page Logic
        window.location.href = m_iAcceptDialogIndicatorURL;//"BuildAVehicleStep3.aspx";
    }
    else if (m_iAcceptDialogIndicator == 2) { // BuildAVehicleStep4 - Options Pop Up Window
            var oCheckBoxes = document.getElementsByTagName("INPUT");
        var sExcludedOptions = m_oSelectedOption.parentNode.getAttribute("ExcludedOptions");
        var sIncludedOptions = m_oSelectedOption.parentNode.getAttribute("IncludedOptions");
        var sRequiredOptions = m_oSelectedOption.parentNode.getAttribute("RequiredOptions");
        var sNewPriceOptions = m_oSelectedOption.parentNode.getAttribute("NewPriceOptions");
        var sRequireOneOfOptions = m_oSelectedOption.parentNode.getAttribute("RequireOneOfOptions");
        
        if (p_bAcceptDialogOkClick) {
            hideWebDialog("tblAcceptDialog");
            m_oSelectedOption.checked = true;
        }  
        
        if (m_iSelectedEdmundsIdExcluded != null) {
            var sSelectedEdmundsIdExcluded = m_iSelectedEdmundsIdExcluded.getAttribute("EdmundsId");                
        }
        if (m_iSelectedEdmundsIdIncluded != null) {
            var sSelectedEdmundsIdIncluded = m_iSelectedEdmundsIdIncluded.getAttribute("EdmundsId");                
        }
        if (m_iSelectedEdmundsIdRequired != null) {        
            var sSelectedEdmundsIdRequired = m_iSelectedEdmundsIdRequired.getAttribute("EdmundsId");                        
        }
        if (m_iSelectedEdmundsIdNewPrice != null) {
            var sSelectedEdmundsIdNewPrice = m_iSelectedEdmundsIdNewPrice.getAttribute("EdmundsId");                
        }
        
        for (var i = 0; i < oCheckBoxes.length; i++) {            
            if (oCheckBoxes[i].type == "checkbox") {            
                var sElementId = oCheckBoxes[i].id;
                sElementId = sElementId.replace("ctl00_mainContentPlaceHolder_", "");           
                
                //EXCLUDED - if an option is excluded in a package, it should be disabled
                if (sExcludedOptions != null) {
                    if (sExcludedOptions.length > 0 && sExcludedOptions.indexOf(sElementId, 0) >= 0) {                    
                        if (m_iSelectedEdmundsIdExcluded != null) {  //This Handles The Or Situation (Only Set The One They Selected
                            if (parseInt(sElementId) == parseInt(sSelectedEdmundsIdExcluded)) {
                                var oSpanElement = document.getElementById(oCheckBoxes[i].id + "_label");
                                setElementOptions(OPTIONS_EXCLUDED, oCheckBoxes[i], oSpanElement, m_oSelectedOption.checked);
                            }
                        }
                        else {  // This is the And Situation And EveryThing Gets Set
                            var oSpanElement = document.getElementById(oCheckBoxes[i].id + "_label");
                            setElementOptions(OPTIONS_EXCLUDED, oCheckBoxes[i], oSpanElement, m_oSelectedOption.checked);
                        }
                    }
                }
                //
                //INCLUDED - if an option is included in a package, it should be disabled            
                if (sIncludedOptions != null) {
                    if (sIncludedOptions.length > 0 && sIncludedOptions.indexOf(sElementId, 0) >= 0) {    
                        if (m_iSelectedEdmundsIdIncluded != null) {  //This Handles The Or Situation (Only Set The One They Selected
                            if (parseInt(sElementId) == parseInt(sSelectedEdmundsIdIncluded)) {
                                var oSpanElement = document.getElementById(oCheckBoxes[i].id + "_label");
                                setElementOptions(OPTIONS_INCLUDED, oCheckBoxes[i], oSpanElement, m_oSelectedOption.checked);
                            }
                        }
                        else {  // This is the And Situation And EveryThing Gets Set
                            var oSpanElement = document.getElementById(oCheckBoxes[i].id + "_label");
                            setElementOptions(OPTIONS_INCLUDED, oCheckBoxes[i], oSpanElement, m_oSelectedOption.checked);
                        }                                    
                    }
                }
                //
                //REQUIRED - if an option is required by another option, it should be selected and disabled
                if (sRequiredOptions != null) {
                    if (sRequiredOptions.length > 0 && sRequiredOptions.indexOf(sElementId, 0) >= 0) {        
                        if (m_iSelectedEdmundsIdRequired != null) {  //This Handles The Or Situation (Only Set The One They Selected
                            if (parseInt(sElementId) == parseInt(sSelectedEdmundsIdRequired)) {
                                var oSpanElement = document.getElementById(oCheckBoxes[i].id + "_label");
                                setElementOptions(OPTIONS_REQUIRED, oCheckBoxes[i], oSpanElement, m_oSelectedOption.checked);
                            }
                        }
                        else {  // This is the And Situation And EveryThing Gets Set
                            var oSpanElement = document.getElementById(oCheckBoxes[i].id + "_label");
                            setElementOptions(OPTIONS_REQUIRED, oCheckBoxes[i], oSpanElement, m_oSelectedOption.checked);
                        }
                    }
                }
                //
                //NEW PRICE - if an option has a new price because of another option, it should be displayed
                if (sNewPriceOptions != null) {
                    if (sNewPriceOptions.length > 0 && sNewPriceOptions.indexOf(sElementId, 0) >= 0) {                    
                        if (m_iSelectedEdmundsIdNewPrice != null) {  //This Handles The Or Situation (Only Set The One They Selected
                            if (parseInt(sElementId) == parseInt(sSelectedEdmundsIdNewPrice)) {
                                var oSpanElement = document.getElementById(oCheckBoxes[i].id + "_label");
                                setElementOptions(OPTIONS_NEWPRICE, oCheckBoxes[i], oSpanElement, m_oSelectedOption.checked);
                            }
                        }
                        else {  // This is the And Situation And EveryThing Gets Set
                            var oSpanElement = document.getElementById(oCheckBoxes[i].id + "_label");
                            setElementOptions(OPTIONS_NEWPRICE, oCheckBoxes[i], oSpanElement, m_oSelectedOption.checked);
                        }
                    }                
                }
            }
        }
        calculateOptionTotal("ctl00_mainContentPlaceHolder_", p_bAcceptDialogOkClick);
    }
    else if (m_iAcceptDialogIndicator == 3) { // Get Quote Now Logic
        var oButton = document.getElementById("ctl00_mainContentPlaceHolder_ibtnQuote");
        
        oButton.click();
    }
}


// AcceptDialog_Cancel_Click
// is run when user clicks the cancel button on the accept dialog window
// 
// @author	kgrove - 3/17/06
// @edit	-
// @param	none
// @return	none
function AcceptDialog_Cancel_Click() {
    if (m_iAcceptDialogIndicator == 2) {
        addAcceptDialogMessage("", "");
        m_oSelectedOption.checked = false;
        calculateOptionTotal("ctl00_mainContentPlaceHolder_", false);
    }
    hideWebDialog("tblAcceptDialog");
}

/*
##########################
## BuildNewVehicle.ascx ##
##########################
*/

// resetBuildANewCarComboBoxes
// resets the comboboxes for the build a new car control
// 
// @author	kgrove - 03/13/06
// @edit	-
// @param	p_iPosition - Where in the chain the combobox resides
//          p_sControlIndicator - View State ID for the page
//          p_sImageRootPath - path to the root of the image directory
// @return	the outer HTML of the element
function resetBuildANewCarComboBoxes(p_iPosition, p_sControlIndicator, p_sImageRootPath) {    
    var oYear = document.getElementById(p_sControlIndicator + "ddlYear");
    var oMake = document.getElementById(p_sControlIndicator + "ddlMake");
    var oModel = document.getElementById(p_sControlIndicator + "ddlModel");    
    var oButton = document.getElementById(p_sControlIndicator + "btnGo");    
    
    switch (p_iPosition) {
        case 1: //Year
            _addOption(oModel, "Select a Model", "0");            
            oModel.value = "0";
            oModel.disabled = true;            
            oButton.disabled = true;
            oButton.src = p_sImageRootPath + "gobutton_large_off.gif";
            oButton.style.cursor = "default";
            break;
        case 2: //Make            
            oButton.disabled = true;
            oButton.src = p_sImageRootPath + "gobutton_large_off.gif";
            oButton.style.cursor = "default";
            break;
        case 3: //Model
            oButton.disabled = false;
            oButton.src = p_sImageRootPath + "gobutton_large.gif";
            oButton.style.cursor = "pointer";
            break;        
    }

}

/*
#######################################
## BuildAVehicleInteriourColors.aspx ##
#######################################
*/


// interiorColorPageLoad
// page load function for interiorColor
// 
// @author	kgrove - 3/15/06
// @edit	-
// @param	p_sInteriorColor - name of the interior color which is selected
//          p_iInteriorColorPrice - the interior color price
// @return	none
function interiorColorPageLoad(p_sInteriorColor, p_iInteriorColorPrice, p_iExteriorColorPrice, p_iInteriorColorId, p_sDestinationCharge) {
    var oLabel = parent.document.getElementById("ctl00_mainContentPlaceHolder_lblIntColor");
    var oHeaderInteriorColor = parent.document.getElementById("ctl00_mainContentPlaceHolder_lblInteriorColor");       
    var iHeight = parseInt(document.getElementById("tblIntColors").clientHeight) + 25;
    var oIFrame = parent.document.getElementById("ctl00_mainContentPlaceHolder_fraInteriorColors");      
    var oOptions = parent.document.getElementById("ctl00_mainContentPlaceHolder_lblOptions");           
    var oExteriorColor = parent.document.getElementById("ctl00_mainContentPlaceHolder_txtExteriorColor");
    var oInteriorColor = parent.document.getElementById("ctl00_mainContentPlaceHolder_txtInteriorColor");
    var oTotalMSRPLabel = parent.document.getElementById("ctl00_mainContentPlaceHolder_lblTotalMSRP");
    var oMSRPLabel = parent.document.getElementById("ctl00_mainContentPlaceHolder_lblMSRP");
    var oInteriorColorCell = document.getElementById('selector_' + p_iInteriorColorId);
    
    parent.m_oInteriorColorCell = oInteriorColorCell;
    m_oInteriorColorCell = oInteriorColorCell;
    
    oExteriorColor.value = p_iExteriorColorPrice;
    oInteriorColor.value = p_iInteriorColorPrice;
    oOptions.innerHTML = parseInt(p_iInteriorColorPrice) + parseInt(p_iExteriorColorPrice);        
    oOptions.innerHTML = formatCurrency(oOptions.innerHTML);
    oTotalMSRPLabel.innerHTML = parseInt(stripDollar(oMSRPLabel.innerHTML)) + (parseInt(p_iInteriorColorPrice) + parseInt(p_iExteriorColorPrice)) + parseInt(stripDollar(p_sDestinationCharge));
    //var total = oTotalMSRPLabel.innerHTML;
    oTotalMSRPLabel.innerHTML = formatCurrency(oTotalMSRPLabel.innerHTML);            
    oLabel.innerHTML = p_sInteriorColor;
    oHeaderInteriorColor.innerHTML = p_sInteriorColor;
    oIFrame.style.height = iHeight + "px";

    
    // Re-calculate monthly payment -- We should do this from the parent window. 
    // CalculateMonthlyPayment2(oTotalMSRPLabel, true);   
}

/*
#############################
## BuildAVehicleStep1.aspx ##
#############################
*/

// resetBuildACarComboBoxes
// resets the comboboxes for the build a new car page
// 
// @author	kgrove - 03/13/06
// @edit	-
// @param	p_iPosition - Where in the chain the combobox resides
//          p_sControlIndicator - View State ID for the page
//          p_sImageRootPath - path to the root of the image directory
// @return	the outer HTML of the element
function resetBuildACarComboBoxes(p_iPosition, p_sControlIndicator, p_sImageRootPath) {
    var oYear = document.getElementById(p_sControlIndicator + "ddlYear");
    var oMake = document.getElementById(p_sControlIndicator + "ddlMake");
    var oModel = document.getElementById(p_sControlIndicator + "ddlModel");    
    var oButton = document.getElementById(p_sControlIndicator + "ibtnNext");    
    
    switch (p_iPosition) {
        case 1: //Year
            _addOption(oModel, "Select a Model", "0");            
            oModel.value = "0";
            oModel.disabled = true;            
            oButton.disabled = true;            
            oButton.style.cursor = "default";
            break;
        case 2: //Make            
            oButton.disabled = true;            
            oButton.style.cursor = "default";
            break;
        case 3: //Model
            oButton.disabled = false;            
            oButton.style.cursor = "pointer";
            break;        
    }

}

/*
#############################
## BuildAVehicleStep2.aspx ##
#############################
*/


// onStyleChange
// when the style changes set the appropriate MSRP and Invoice Prices
// 
// @author	kgrove - 3/16/06
// @edit	-
// @param	p_iMSRP - MSRP
//          p_iInvoice - Invoice Price
//          p_iTMV - True Market Value Price
//          p_sStyleName - the name of the vehicles style
//          p_sDestinationCharge - the destination charge for the vehicle
// @return	none
function onStyleChange(p_iMSRP, p_iInvoice, p_iTMV, p_sStyle, p_sImagePath, p_sDestinationCharge) {
    var oMSRPLabel = document.getElementById("ctl00_mainContentPlaceHolder_lblMSRP");
    var oTotalMSRPLabel = document.getElementById("ctl00_mainContentPlaceHolder_lblTotalMSRP");
    var oInvoiceLabel = document.getElementById("ctl00_mainContentPlaceHolder_lblInvoice");
    var oTMVLabel = document.getElementById("ctl00_mainContentPlaceHolder_lblTMV");
    var oMSRPTextBox = document.getElementById("ctl00_mainContentPlaceHolder_txtMSRP");
    var oInvoiceTextBox = document.getElementById("ctl00_mainContentPlaceHolder_txtInvoicePrice");
    var oTMVPriceTextBox = document.getElementById("ctl00_mainContentPlaceHolder_txtTMVPrice");
    var oStyle = document.getElementById("ctl00_mainContentPlaceHolder_lblSelStyleString");
    var oStyleTextBox = document.getElementById("ctl00_mainContentPlaceHolder_txtStyleName");
    var oImage = document.getElementById("ctl00_mainContentPlaceHolder_imgVehicle");
    var oImageTextBox = document.getElementById("ctl00_mainContentPlaceHolder_txtImagePath");
    
    oMSRPLabel.innerHTML = p_iMSRP;
    oTotalMSRPLabel.innerHTML = parseInt(stripDollar(p_sDestinationCharge)) + parseInt(stripDollar(p_iMSRP));
   // var total = oTotalMSRPLabel.innerHTML
    oTotalMSRPLabel.innerHTML = formatCurrency(oTotalMSRPLabel.innerHTML);
    oInvoiceLabel.innerHTML = p_iInvoice;
    //oTMVLabel.innerHTML = p_iTMV; For the Edmunds Data
    oStyle.innerHTML = p_sStyle;
    oMSRPTextBox.value = p_iMSRP;
    oInvoiceTextBox.value = p_iInvoice;
    oTMVPriceTextBox.value = p_iTMV;    
    oStyleTextBox.value = p_sStyle;
    oImage.src = p_sImagePath;
    oImageTextBox.value = p_sImagePath;

    // Calcualte monthly payment
    CalculateMonthlyPayment2(oTotalMSRPLabel, false);
}

/*
#############################
## BuildAVehicleStep3.aspx ##
#############################
*/

// onStyleChange
// when the style changes set the appropriate MSRP and Invoice Prices
// 
// @author	kgrove - 3/16/06
// @edit	-
// @param	p_iMSRP - MSRP
//          p_iInvoice - Invoice Price
//          p_iTMV - True Market Value Price
//          p_sStyleName - the name of the vehicles style
//          p_sDestinationCharge - the destination charge for the vehicle
// @return	none
function onColorChange(p_sImagePath) {    
    var oImage = document.getElementById("ctl00_mainContentPlaceHolder_imgVehicle");           
    oImage.src = p_sImagePath;
}


// submitNCBStep3
// submit NCB Step 3 page
// 
// @author	kgrove - 3/16/06
// @edit	jrober - 10/18/07
// @param	none
// @return	none
function submitNCBStep3() {
    var iExteriorColor = document.getElementById("ctl00_mainContentPlaceHolder_txtExteriorColor").value;
    var iInteriorColor = document.getElementById("ctl00_mainContentPlaceHolder_txtInteriorColor").value;    
    var sInteriorOptionMessage = null;
    var sExteriorOptionMessage = null;
    var sOptionMessage = "";
    
    document.forms[0].submit();
    
    if (m_oInteriorColorCell != null) {
        sInteriorOptionMessage = m_oInteriorColorCell.getAttribute("OptionMessage");
        m_iInteriorOptionId = m_oInteriorColorCell.getAttribute("vo_id");
    }
    if (m_oExteriorColorCell != null) {
        sExteriorOptionMessage = m_oExteriorColorCell.getAttribute("OptionMessage");    
        m_iExteriorOptionId = m_oExteriorColorCell.getAttribute("vo_id");
    }
    
    if (sExteriorOptionMessage != null) {
        sOptionMessage = "The Exterior Color You Have Seleced Will Require The Following Option: ";
        sOptionMessage += sExteriorOptionMessage + "<BR><BR>";
    }
    
   if (sInteriorOptionMessage != null) {        
        sOptionMessage += "The Interior Color You Have Seleced Will Require The Following Option: ";
        sOptionMessage += sInteriorOptionMessage + "<BR><BR>";
    }
    
    if (sOptionMessage != "" && 1 == 2) {
        sOptionMessage += "Click Accept To Continue To Step 4 Or Cancel To Change Your Selection.<BR><BR>";
        sOptionMessage += "***Note: If You Accept The Above Options May Require Additional Selections.  "
                            + "The Additional Selections Will Be Reflected In Step 4.";
        m_iAcceptDialogIndicator = 0;
        var oCancelImage = document.getElementById("imgCancel");
        oCancelImage.src = m_sImageRoot + "sm_button_cancel.jpg";
        addAcceptDialogMessage(sOptionMessage, "Option Change Alert");
        showWebDialog("tblAcceptDialog", true);
    }
    else {
        m_iAcceptDialogIndicator = 0;
        AcceptDialog_Accept_Click(true);
        
        //need to make the BuildAVehicle Redirect conditional to prevent the page from reloading.
        if (m_iInteriorOptionId == null && m_iInteriorOptionId == null) 
        {            
            window.location.href = "BuildAVehicleStep4.aspx";
        }        
    }
}


// loadInteriorColors
// loads the interior colors page
// 
// @author	kgrove - 3/15/06
// @edit	-
// @param	p_oElement - element which was clicked on
//          p_iExteriorColorId - id for the exterior color
//          p_sExteriorColorName - name for the exterior color
//          p_iColorEdmundsId - edmunds id of the exterior color they have choosen
// @return	none
function loadInteriorColors(p_oElement, p_iExteriorColorId, p_sExteriorColorName, p_iColorEdmundsId) {
    var oIFrame = parent.document.getElementById("ctl00_mainContentPlaceHolder_fraInteriorColors");
    var oHeaderExteriorColor = parent.document.getElementById("ctl00_mainContentPlaceHolder_lblExteriorColor");
    var oExteriorColor = parent.document.getElementById("ctl00_mainContentPlaceHolder_lblExtColor");
    var oSelectedColor = parent.document.getElementById("ctl00_mainContentPlaceHolder_selector_" + p_iExteriorColorId);
    //oSelectedColor.style.border = "0px";
    
    p_oElement.style.border = "1px SOLID #ED9E00";
    
    var iPrice = p_oElement.getAttribute("Price");
    
    if (m_iPreviousExteriorColorId != null) {
        var oPreviousColor = parent.document.getElementById("ctl00_mainContentPlaceHolder_selector_" + m_iPreviousExteriorColorId);   
        oPreviousColor.innerHTML = "";
    }
    if (m_iPreviousExteriorColorId != null)
    {
        var oPreviousColorCell = parent.document.getElementById("ctl00_mainContentPlaceHolder_" + m_iPreviousExteriorColorId);   
        oPreviousColorCell.style.borderColor = "#000000";
    }
    
    oHeaderExteriorColor.innerHTML = p_sExteriorColorName;
    oExteriorColor.innerHTML = p_sExteriorColorName;
    if (iPrice == null) {
        iPrice = 0;
    }
    oSelectedColor.innerHTML = "<img src='" + m_sImageRoot + "selector_wingding.jpg' style='border-width:0px;' />";
    oIFrame.src = "BuildAVehicleInteriorColors.aspx?ExteriorColor=" + p_iExteriorColorId + "&ExteriorColorPrice=" 
                    + iPrice + "&InteriorColorPrice=0&ExteriorColorName=" + p_sExteriorColorName
                    + "&ExtColorJatoId=" + p_iColorEdmundsId + "&IFrame=true";    
    m_iPreviousExteriorColorId = p_iExteriorColorId;
    m_oExteriorColorCell = p_oElement;
    
    
        
}

/*
#############################
## BuildAVehicleStep4.aspx ##
#############################
*/


// additionalOptions
// sets up page with all required data
// 
// @author	kgrove - 3/08/06
// @edit	-
// @param	p_sMessage - Message to be displayed to user (list of options assoicated with selection)
//          p_oElement - element which was clicked on
// @return	none
function additionalOptions(p_sMessage, p_oElement) {    
    m_oSelectedOption = p_oElement;
    m_iSelectedEdmundsIdExcluded = null;
    m_iSelectedEdmundsIdIncluded = null;
    m_iSelectedEdmundsIdRequired = null;
    m_iSelectedEdmundsIdNewPrice = null;    
    if (p_oElement.checked && p_sMessage != "") {        
        m_iAcceptDialogIndicator = 2
        if (p_sMessage.indexOf("<input") > 0) {
            var oCancelImage = document.getElementById("imgCancel");
            oCancelImage.src = m_sImageRoot + "sm_button_cancel.jpg";
            addAcceptDialogMessage(p_sMessage, "Option Change Alert");
            showWebDialog("tblAcceptDialog", true);
        }
        else {
            AcceptDialog_Accept_Click(true);
        }
        var oRadioGroup = document.getElementsByName("optSelectGroup_exclude");                        
        if (oRadioGroup.length > 0) {
            m_iSelectedEdmundsIdExcluded = getSelectedRadio(oRadioGroup);
        }
        var oRadioGroup = document.getElementsByName("optSelectGroup_include");        
        if (oRadioGroup.length > 0) {
            m_iSelectedEdmundsIdIncluded = getSelectedRadio(oRadioGroup);
        }
        var oRadioGroup = document.getElementsByName("optSelectGroup_require");        
        if (oRadioGroup.length > 0) {
            m_iSelectedEdmundsIdRequired = getSelectedRadio(oRadioGroup);
        }
        var oRadioGroup = document.getElementsByName("optSelectGroup_newprice");        
        if (oRadioGroup.length > 0) {
            m_iSelectedEdmundsIdNewPrice = getSelectedRadio(oRadioGroup);
        }        
    }
    else {
        m_iAcceptDialogIndicator = 2;
        AcceptDialog_Accept_Click(false);
    }
}


// setElementOptions
// sets the elements options based on the type passed in
// 
// @author	kgrove - 3/17/06
// @edit	-
// @param	p_iOptionType - type of option (ex. excluded, included, etc.)
//          p_oElement - elmement to be changed
//          p_oSpanElement - elements span tag to be changed
//          p_bDirection - whether to set or remove the option
// @return	none
function setElementOptions(p_iOptionType, p_oElement, p_oSpanElement, p_bDirection) {
    var sClassName = "";
    var sText = "";
    var sTitle = "";
    
    if (p_bDirection) {
        switch (parseInt(p_iOptionType)) {
            case OPTIONS_EXCLUDED:
                sClassName = "ncb_opt_excluded";
                sText = "EXCLUDED";
                sTitle = "Excluded by another selection.";
                p_oElement.checked = false;
                break;    
                        
            case OPTIONS_INCLUDED:
                sClassName = "ncb_opt_included";
                sText = "INCLUDED";
                sTitle = "Included by another selection.";
                break;
                
            case OPTIONS_REQUIRED:
                sClassName = "ncb_opt_required";
                sText = "REQUIRED";
                sTitle = "Required by another selection.";
                p_oElement.checked = true;
                break;
                
            case OPTIONS_NEWPRICE:
                sClassName = "ncb_opt_newprice";
                sText = "NEW PRICE";
                sTitle = "Change in price due to another selected option.";
                p_oElement.checked = true;
                break;
        }
        p_oSpanElement.className = sClassName;
        p_oSpanElement.innerHTML = sText;
        p_oSpanElement.title = sTitle;
        p_oElement.className = sClassName;
        p_oElement.title = sTitle;
        p_oElement.disabled = true;
    }
    else {
        p_oSpanElement.className = "ncb_opt_unselected";
        p_oSpanElement.innerHTML = "";
        p_oSpanElement.title = "Click here to select this option";
        p_oElement.className = "ncb_opt_unselected";
        p_oElement.title = "Click here to select this option";
        p_oElement.disabled = false;
        if (p_iOptionType == OPTIONS_REQUIRED || p_iOptionType  == OPTIONS_NEWPRICE) {
            p_oElement.checked = false;
        }
    }
}

// calculateOptionTotal
// calculates the option total
// 
// @author	kgrove - 3/14/06
// @edit	-
// @param	p_sControlIndicator - View State ID for the page
// @return	none
function calculateOptionTotal(p_sControlIndicator, p_bShowChange) {    
    var OriginalPrice = document.getElementById(p_sControlIndicator + "lblMSRP");
    var TotalOptions = document.getElementById(p_sControlIndicator + "lblOptions");
    var TotalPrice = document.getElementById(p_sControlIndicator + "lblTotalMSRP");    
    var oCheckBoxes = document.getElementsByTagName("INPUT");    
    var oSelectedOptions = document.getElementById(p_sControlIndicator + "txtSelectedOptions");
    var oOptionsPrice = document.getElementById(p_sControlIndicator + "txtOptionsTotal");
    var oTotalMSRP = document.getElementById(p_sControlIndicator + "txtTotalMSRP");
    var sDestinationCharge = oCheckBoxes[0].parentNode.getAttribute("DestinationCharge");
    
    TotalOptions.innerHTML = "$0";
    TotalPrice.innerHTML = parseInt(stripDollar(OriginalPrice.innerHTML)) + parseInt(stripDollar(m_sDestinationCharge));
    //var total = TotalPrice.innerHTML
    TotalPrice.innerHTML = formatCurrency(TotalPrice.innerHTML);    
    oSelectedOptions.value = ""; 
    for (var i = 0; i < oCheckBoxes.length; i++) {            
        if (oCheckBoxes[i].type == "checkbox") {            
            var iMSRP = parseInt(stripDollar(oCheckBoxes[i].parentNode.getAttribute("OptionValue")));           
            
            if (oCheckBoxes[i].checked) {        
                TotalOptions.innerHTML = parseInt(stripDollar(TotalOptions.innerHTML)) + iMSRP;
                TotalOptions.innerHTML = formatCurrency(TotalOptions.innerHTML);
                TotalPrice.innerHTML = parseInt(stripDollar(TotalPrice.innerHTML)) + iMSRP;
                //total = TotalPrice.innerHTML;
                TotalPrice.innerHTML = formatCurrency(TotalPrice.innerHTML);
                oSelectedOptions.value += oCheckBoxes[i].parentNode.getAttribute("vo_id") + ",";
            }            
        }
    }
    oOptionsPrice.value = TotalOptions.innerHTML;
    oTotalMSRP.value = TotalPrice.innerHTML;

    // Re-calculate monthly payment
    CalculateMonthlyPayment2(TotalPrice, false);
    
    //Show User New Options Total
    if (p_bShowChange == true) {
        var oOKDialog = document.getElementById("tblOkDialog");
        var iScreenWidth = document.documentElement.offsetWidth;        
        var iScreenHeight = document.documentElement.offsetHeight;
        if (!m_bIsIE) {
            iScreenWidth = window.innerWidth;
            iScreenHeight = window.innerHeight;
        }
        var iLeft = ((iScreenWidth - 863) / 2) + 667;
        var iTop = ((iScreenHeight - 180) / 2) + document.documentElement.scrollTop;          
        
	    oOKDialog.style.top = iTop + "px";
	    oOKDialog.style.left = iLeft + "px";
	    oOKDialog.style.width = "182px";
    	
        addOkDialogMessage("Your Options Now Total: " + TotalOptions.innerHTML
                            + " <br><br>Which Brings Your Total MSRP To: " + TotalPrice.innerHTML
                            , "Price Change");	
        showElement("tblOkDialog");
        window.clearTimeout(m_iTimeout);
        window.clearTimeout(m_iAnimationTimer);
        oOKDialog.style.filter = "Alpha(Opacity=100)";
        m_iTimeout = window.setTimeout("animateMenuOut('tblOkDialog', 100)", 3000);
    }
}

function hideJDPowerReviews()
{
    
    var lblRev1 = document.getElementById("ctl00_mainContentPlaceHolder_tdCar1Rev");
    var lblRev2 = document.getElementById("ctl00_mainContentPlaceHolder_tdCar2Rev");
    var lblRev3 = document.getElementById("ctl00_mainContentPlaceHolder_tdCar3Rev");
    
    lblRev1.style.visibility = "hidden";
    lblRev2.style.visibility = "hidden";
    if(lblRev3 != null)
    {
        lblRev3.style.visibility = "hidden";
    }
    
}

function displayJDPowerReview(car)
{
    
    var oOKDialog = document.getElementById("tblOkDialog");
    
    oOKDialog.style.width = "800px";
    window.clearTimeout(m_iTimeout);
    window.clearTimeout(m_iAnimationTimer);
    oOKDialog.style.filter = "Alpha(Opacity=100)";
	if(car == "1")
	{
	    var lblRev = document.getElementById("ctl00_mainContentPlaceHolder_tdCar1Rev");
        addOkDialogMessage(lblRev.innerHTML, "JD Power Review");
    }
    if(car == "2")
    {
        var lblRev = document.getElementById("ctl00_mainContentPlaceHolder_tdCar2Rev");
        addOkDialogMessage(lblRev.innerHTML, "JD Power Review");
    }
    if(car == "3")
    {
        var lblRev = document.getElementById("ctl00_mainContentPlaceHolder_tdCar3Rev");
        addOkDialogMessage(lblRev.innerHTML, "JD Power Review");
    }
    showWebDialog("tblOkDialog", true);
    
}

function displayJDPowerRatings(CodeToShow)
{    
    var oOKDialog = document.getElementById("tblOkDialog");
    
	oOKDialog.style.width = "300px";
	window.clearTimeout(m_iTimeout);
    window.clearTimeout(m_iAnimationTimer);
    oOKDialog.style.filter = "Alpha(Opacity=100)";
	
    addOkDialogMessage(CodeToShow, "JD Power Ratings");
    showWebDialog("tblOkDialog", true);
}

// detailsOnClick
// pop up details window when clicked
// 
// @author	kgrove - 3/16/06
// @edit	-
// @param	p_sDescription - description for the option
// @return	none
function detailsOnClick(p_sDescription) {
    var oOKDialog = document.getElementById("tblOkDialog");
    
	oOKDialog.style.width = "300px";
	window.clearTimeout(m_iTimeout);
    window.clearTimeout(m_iAnimationTimer);
    oOKDialog.style.filter = "Alpha(Opacity=100)";
	
    addOkDialogMessage(p_sDescription, "Option Description");
    showWebDialog("tblOkDialog", true);
}


// PreviousAlertNCBStep4
// fires when user hits previous from the options page
// 
// @author	kgrove - 4/20/06
// @edit	-
// @param	p_bVehicleSaved - indicates if the vehicle is already saved
//          p_bOverride - indicates vehicle was just saved on the page and there is no need to show the message
// @return	none
function PreviousAlertNCBStep4(p_bVehicleSaved, p_bOverride,p_Url) {
    var sMessage = "";
   
    if (p_bOverride) {
        window.location.href = p_Url;
    }
    else {
        if (p_bVehicleSaved) {
            sMessage = "Any Changes You Have Made To Your Options Will Be Lost Unless You Save.  If You Wish To Save Your Vehicle First Click Cancel And Save Your Vehicle.<br><br>Do You Wish To Loss Your Options And Continue Without Saving Your Vehicle?";
        }
        else {
            sMessage = "You Have Not Yet Saved Your Vehicle.  Going Back To The Color Selection Page Will Require You To Reselect Your Options.  If You Wish To Save Your Vehicle First Click Cancel And Save Your Vehicle.<br><br>Do You Wish To Lose Your Options And Continue Without Saving Your Vehicle?";
        }  
        m_iAcceptDialogIndicatorURL = p_Url;  
        m_iAcceptDialogIndicator = 1;
        var oCancelImage = document.getElementById("imgCancel");
        oCancelImage.src = m_sImageRoot + "sm_button_cancel.jpg";
        addAcceptDialogMessage(sMessage, "Lose Option Changes?");        
        showWebDialog("tblAcceptDialog", true);
    }
}

// ncb_GetQuoteNow
// fires when user loads Step 4 for first time
// 
// @author	dspol - 5/16/06
// @edit	-
// @param	none
// @return	none
function ncb_GetQuoteNow(msg, title, btnImagePath)
{
    //change the "close" button to an "accept" button
    var btnClose = parent.document.getElementById("imgClose");
    btnClose.src = btnImagePath;
    
    addOkActionDialogMessage(msg, title);
    showWebDialog('tblOkActionDialog', true);
    
}


// ncb_GetQuoteNow2
// fires when user loads Step 4 for first time
// 
// @author	kgrove - 5/18/06
// @edit	-
// @param	none
// @return	none
function ncb_GetQuoteNow2() {
    var oCancelImage = document.getElementById("imgCancel");
    var sMessage = "Thank you for using the CUDL New Car Builder, you are almost finished building your car.<br><br>"
                    + "If you would like to get a quote now please click accept.<br><br>"
                    + "If you would like to continue to build your vehicle click options.";
    
    oCancelImage.src = m_sImageRoot + "sm_button_options.jpg";
    m_iAcceptDialogIndicator = 3;
    addAcceptDialogMessage(sMessage, "Get Quote(s) Now?");
    showWebDialog("tblAcceptDialog", true);
}


// onclick_OKActionDialog
// fires when user loads Step 4 for first time
// 
// @author	dspol - 5/16/06
// @edit	-
// @param	none
// @return	none
function onclick_OKActionDialog() 
{
    //check to see the user's answer
    var oRdoQuote = parent.document.getElementById("rdoQuote");
    
    //if it's true, send them to the Quote page.
    if (oRdoQuote.checked == true)
    {
        var oGetQuoteBtn = parent.document.getElementById("ctl00_mainContentPlaceHolder_ibtnQuote");
        oGetQuoteBtn.click();
    }
}


/*
#############################
## BuildAVehicleStep5.aspx ##
#############################
*/


// displayPrint
// pop up the print page
// 
// @author	kgrove - 3/20/06
// @edit	-
// @param	none
// @return	none
function displayPrint() {
    //var sFeatures = "height=300px,location=no,menubar=no,status=no,width=300px,scrollbars=yes,resizable=yes";
    //window.open("PrintBuildAvehiclePopup.aspx", "winPrint", sFeatures);
    // pid=2 is the id for NCB
     var URL = "../print/default.aspx?toprint=1&pid=2";
    ShowPrintOptions(URL);
}



// loadVehicleSummary
// load the vehicle summary page with the information selected by the user
// 
// @author	kgrove - 3/20/06
// @edit	-
// @param	p_sFrameId - id of the frame
//          p_sFrameName - name of the frame
//          p_iDataSource - the id of the data source to show
//          p_iVehicleId - the id of the vehicle to show the information for
// @return	none
function loadVehicleSummary(p_sFrameId, p_sFrameName, p_iDataSource, p_iVehicleId) {    
    var oPreviousSelection = document.getElementById("tdSummarySection" + m_iPreviousSummarySection);
    
    
    var oCurrentSelection = document.getElementById("tdSummarySection" + p_iDataSource);
    
    oPreviousSelection.className = "tabUnSelected";
    oCurrentSelection.className = "tabSelected";   
      
    window.frames[p_sFrameName].location.replace(m_sRoot + "Common/VehicleSummary.aspx?DataSource=" + p_iDataSource + "&VehicleId=" + p_iVehicleId + "&FrameId=" + p_sFrameId + "&IFrame=true");
    m_iPreviousSummarySection = p_iDataSource;
}

/*
##############################
## DealerLocateResults.aspx ##
##############################
*/

// allowSend
// determine if the send button should be enabled
// 
// @author	kgrove - 4/12/06
// @edit	-
// @param	p_sLocation - location to root of image directory
// @return	none
function allowSend(p_sLocation) {
    var sDealerId = document.getElementById("txtDealerId").value;
    var oSend = parent.document.getElementById("imgSend");
    var oSend1 = parent.document.getElementById("imgSend1");
    var oParentDealerId = parent.document.getElementById("ctl00_mainContentPlaceHolder_SelectedVehicle2_txtDealerId");
    
    if (sDealerId.length > 0) {
        //oSend.src = p_sLocation + "send_button.jpg";
        oSend.disabled = false;
        oSend.style.cursor = "pointer";
        /*
        oSend1.src = p_sLocation + "send_button.jpg";
        oSend1.disabled = false;
        oSend1.style.cursor = "pointer";
        */
        oParentDealerId.value = sDealerId;
    }
    else {
        //oSend.src = p_sLocation + "send_button_off.jpg";
        oSend.disabled = true;
        oSend.style.cursor = "default";
        /*
        oSend1.src = p_sLocation + "send_button_off.jpg";
        oSend1.disabled = true;
        oSend1.style.cursor = "default";
        */
        oParentDealerId.value = "";
    }
}


// Calculate monthly payment
// 
// @author	achow - 08/10/2009
// @param   LoanAmount - the loan amount to calculate
//          LoadFromParentDocument - Load the html elements from parent document.               
// @return	Monthtly Payment amount



function CalculateMonthlyPayment2(TotalMSRPControl, LoadFromParentDocument) {

    CalculateMonthlyPayment3(TotalMSRPControl.innerHTML, LoadFromParentDocument);
}
function CalculateMonthlyPayment2(LoadFromParentDocument) {
    var TotalMSRPControl = document.getElementById("ctl00_mainContentPlaceHolder_lblTotalMSRP");
    CalculateMonthlyPayment3(TotalMSRPControl.innerHTML, LoadFromParentDocument);
}

function CalculateMonthlyPayment3(TotalLoanAmount, LoadFromParentDocument) {
    var monthlyPaymentLabel;
    var monthlyPaymentTR;
    var imgCURates;    
    if (LoadFromParentDocument) {
        //alert("LoadFromParentDocument");
        monthlyPaymentLabel = parent.document.getElementById("lblMonthlyPayment");
        monthlyPaymentTR = parent.document.getElementById("trMonthlyPayment");
        imgCURates = parent.document.getElementById("ctl00_mainContentPlaceHolder_imgCURates");
        //This Code difference is bausing the error
        //imgCURates = document.getElementById("ctl00_mainContentPlaceHolder_imgCURates");
    }
    else {
        //alert("not LoadFromParentDocument");
        monthlyPaymentLabel = document.getElementById("lblMonthlyPayment");
        monthlyPaymentTR = document.getElementById("trMonthlyPayment");
        imgCURates = document.getElementById("ctl00_mainContentPlaceHolder_imgCURates");
    }

    DownPayment = "0"
    AnnualInterestRate = m_interstRate / 100
    MonthRate = AnnualInterestRate / 12
    NumPayments = m_loanTerm
    LoanAmount = parseInt(stripDollar(TotalLoanAmount));
    Prin = LoanAmount - DownPayment

    MonthPayment = Math.floor((Prin * MonthRate) / (1 - Math.pow((1 + MonthRate), (-1 * NumPayments))) * 100) / 100
    
    if (MonthPayment > 0) {

        monthlyPaymentTR.style.visibility = "";
        monthlyPaymentLabel.innerHTML = parseInt(MonthPayment);

        var querystring = "iCalculator=2&DropDown=HIDE&price=" + LoanAmount + "&rate=" + m_interstRate + "&term=" + m_loanTerm;
        var calculatorLink = "../Common/CalculatorPopUp.aspx?" + querystring;

        monthlyPaymentLabel.innerHTML = formatCurrency(monthlyPaymentLabel.innerHTML);
        monthlyPaymentLabel.title = imgCURates.title;
        monthlyPaymentTR.style.display = "";
        imgCURates.onclick = function() {
            openNewWindow(calculatorLink);
        }

      
    }
    else {
        monthlyPaymentTR.style.display = "none";

    }
}

function CalculateTotalMSRP(p_iMSRP, p_sDestinationCharge) {
    var oTotalMSRPLabel = document.getElementById("ctl00_mainContentPlaceHolder_lblTotalMSRP");
    oTotalMSRPLabel.innerHTML = parseInt(p_sDestinationCharge) + parseInt(p_iMSRP);
    var total = oTotalMSRPLabel.innerHTML
    oTotalMSRPLabel.innerHTML = formatCurrency(oTotalMSRPLabel.innerHTML);
    // Re-calculate monthly payment
    CalculateMonthlyPayment2(oTotalMSRPLabel, false); 
}

function openNewWindow(url) {
    var sFeatures = "titlebar=no,height=550px,location=no,menubar=no,status=no,width=500px,scrollbars=yes";
    window.open(url, "AutoSmartCalculator", sFeatures);
}
