﻿
//BEGIN Product Option Select Script
//check screen.css for the css of optionSelectorHoverColor, optionSelectorSelectedColor, optionSelectorUnselectedColor

function ShowUserMustClickOptionMessage(showMessage) //"true" = show message, "false" = hide message
{
    var additionalPriceElementName = FindElementByPartialName("lblMessageChooseOption", "div");
    var additionalPriceElement = getObject(additionalPriceElementName);

    if (additionalPriceElement !== null) {
        if (showMessage === "true") {
            additionalPriceElement.style.display = "inline";
        }
        else {
            additionalPriceElement.style.display = "none";
        }
    }
}

function highlightoption(id, optionName, optionControlID, lblClickedOptionID, hylControlID, msgControlID) {
    var objectid = getObject(id);
    var style2 = objectid.style;

    if (objectid.className != "ItemOptionSelected") {
        objectid.setAttribute("class", "ItemOptionHover"); //firefox
        objectid.setAttribute("className", "ItemOptionHover"); //ie
    }

    var optioncontrol = getObject(optionControlID);
    if (optioncontrol) {
        optioncontrol.innerHTML = optionName;
        optioncontrol.innerText = optionName;
        optioncontrol.style.display = "inline";
    }
    //hide the clicked option
    var lblClickedOptionElement = getObject(lblClickedOptionID);
    if (lblClickedOptionElement) {
        lblClickedOptionElement.style.display = "none";
    }

    ShowUserMustClickOptionMessage("false");
}

function unhighlightoption(id, optionControlID, lblClickedOptionID, hylControlID, msgControlID) {
    var objectid = getObject(id);
    var style2 = objectid.style;

    if (objectid.className != "ItemOptionSelected") {
        objectid.setAttribute("class", "ItemOption"); //firefox
        objectid.setAttribute("className", "ItemOption"); //ie
    }

    var optioncontrol = getObject(optionControlID);
    if (optioncontrol) {
        optioncontrol.innerHTML = "";
        optioncontrol.innerText = "";
        optioncontrol.style.display = "none";
    }
    //show the clicked option
    var lblClickedOptionElement = getObject(lblClickedOptionID);
    if (lblClickedOptionElement) {
        lblClickedOptionElement.style.display = "inline";
    }

    ShowUserMustClickOptionMessage("false");
}

function initialselectoption(id, optionName, optionControlID, lblClickedOptionID, optionPrice, tboSelectedProductOptionGuid, selectedOptionGuid) {
    var objectid = getObject(id);
    var style2 = objectid.style;

    objectid.setAttribute("class", "ItemOptionSelected"); //firefox
    objectid.setAttribute("className", "ItemOptionSelected"); //ie

    //set the selected option in the label
    //but hide it to show the clicked option label instead
    var optioncontrol = getObject(optionControlID);
    if (optioncontrol) {
        optioncontrol.innerHTML = optionName;
        optioncontrol.innerText = optionName;
        optioncontrol.style.display = "none";
    }
    //show the clicked option
    var lblClickedOptionElement = getObject(lblClickedOptionID);
    if (lblClickedOptionElement) {
        lblClickedOptionElement.innerHTML = optionName;
        lblClickedOptionElement.innerText = optionName;
        lblClickedOptionElement.style.display = "inline";
    }

    ShowUserMustClickOptionMessage("false");


    var typeSelectedId = FindElementByPartialName("lblOptionTypeSelected", "span");
    var typeSelectedElement = getObject(typeSelectedId);
    if (typeSelectedElement) {
        typeSelectedElement.style.display = "inline";
    }

    var typeUnSelectedId = FindElementByPartialName("lblOptionTypeUnselected", "span");
    var typeUnSelectedElement = getObject(typeUnSelectedId);
    if (typeUnSelectedElement) {
        typeUnSelectedElement.style.display = "none";
    }

    var tboSelectedProductOptionGuidElement = getObject(tboSelectedProductOptionGuid);
    if (tboSelectedProductOptionGuidElement) {
        tboSelectedProductOptionGuidElement.value = selectedOptionGuid;
    }
}

function FlipTheBasketImage(isOn, addbutton, disabledimage) 
{
    var activeElementName;
    var inactiveElementName;
    
    if(addbutton != null && addbutton.length>0)
    {
        activeElementName = addbutton;
    }
    else
    {
        activeElementName = FindElementByPartialName("btnAddToCart", "input");
    }
    
    if(addbutton != null && addbutton.length>0)
    {
        inactiveElementName = disabledimage;
    }
    else
    {
        inactiveElementName = FindElementByPartialName("disabledAddToCart", "img");
    }
    

    if (activeElementName !== null && inactiveElementName !== null) {
        var btn = getObject(activeElementName);
        var image = getObject(inactiveElementName);

        if (btn !== null && image !== null) {
            if (isOn == "true") {
                //show the active button
                btn.style.display = "inline";
                //hide the inactive button
                image.style.display = "none";
            }
            else {
                //hide the active button
                btn.style.display = "none";
                //show the inactive button
                image.style.display = "inline";
            }
        }
    }
}

function selectoption(id, textboxoptionid, textboxoptionname, optionid, optionName, tboSelectedProductOptionGuid, optionControlID, lblClickedOptionID, hylControlID, msgControlID, panelProductWarningID, optionNameDisplay, optionPrice, hylControlID2, btnAddToCartID, disabledAddToCartID) {
    //all of the possible page control ids that contain options (S, M L) are stored in 
    //the textboxoptionid textbox.
    
    var objectid = getObject(textboxoptionid);
    var controls = objectid.value;

    //now split on the comma
    var theList = controls.split(",");

    //alert("thelist.length"+theList.length);
    if (theList.length > 0) {
        //set all the backgrounds to unselected white
        for (i = 0; i < theList.length; i++) 
        {
            var found = theList[i];
            control = getObject(found);
            if(control!=null)
            {
                var style1 = control.style;
                control.setAttribute("class", "ItemOption"); //firefox
                control.setAttribute("className", "ItemOption"); //ie
            }
        }
        //the id control needs to be highlighted
        var control2 = getObject(id);
        var style2 = control2.style;
        control2.setAttribute("class", "ItemOptionSelected"); //firefox
        control2.setAttribute("className", "ItemOptionSelected"); //ie

        //set the selection into the form fields
        //var contents = control2.value;

        //save the selection in the textbox for later retrieval
        var control3 = getObject(textboxoptionname);
        control3.value = optionName;

        //set the guid string into our selection textbox
        var controlGuidTextbox = getObject(tboSelectedProductOptionGuid);
        controlGuidTextbox.value = optionid;

        //set the selected option in the label
        //but hide it to show the clicked option label instead
        var optioncontrol = getObject(optionControlID);
        optioncontrol.innerHTML = optionName;
        optioncontrol.innerText = optionName;
        optioncontrol.style.display = "none";

        //show the clicked option
        var lblClickedOptionElement = getObject(lblClickedOptionID);
        lblClickedOptionElement.innerHTML = optionNameDisplay;
        lblClickedOptionElement.innerText = optionNameDisplay;
        lblClickedOptionElement.style.display = "inline";

        //now turn off the hyperlink and message
        var hylControlElement = getObject(hylControlID);
        hylControlElement.innerHTML = "";
        hylControlElement.innerText = "";
        hylControlElement.style.display = "none";

        var hylControlElement2 = getObject(hylControlID2);
        if (hylControlElement2 !== null) {
            hylControlElement2.style.display = "none";
        }
        //now turn off the hyperlink and message
        var msgControlElement = getObject(msgControlID);
        msgControlElement.innerHTML = "";
        msgControlElement.innerText = "";
        msgControlElement.style.display = "none";

        //now turn off warning message panel
        var panelProductWarningElement = getObject(panelProductWarningID);
        panelProductWarningElement.style.display = "none";

        FlipTheBasketImage("true", btnAddToCartID, disabledAddToCartID);

        //find the price's additional charge and change it to be the additional amount
        var additionalPriceElementName = FindElementByPartialName("spanAdditionalPrice", "span");
        var additionalPriceElement = getObject(additionalPriceElementName);
        
        var additionalSalePriceElementName = FindElementByPartialName("spanSaleAdditionalPrice", "span");
        var additionalSalePriceElement = getObject(additionalSalePriceElementName);

        var additionalSpringSalePriceElementName = FindElementByPartialName("spanSpringSaleAdditionalPrice", "span");
        var additionalSpringSalePriceElement = getObject(additionalSpringSalePriceElementName);


        if (additionalPriceElement !== null && additionalPriceElement.id !== "__PREVIOUSPAGE") {
            if (optionPrice != "$0.00") {
                additionalPriceElement.innerHTML = " + " + optionPrice;
                additionalPriceElement.innerText = " + " + optionPrice;
                if (additionalSalePriceElement !== null){
                    additionalSalePriceElement.innerHTML = " + " + optionPrice;
                    additionalSalePriceElement.innerText = " + " + optionPrice;
                }
                if (additionalSpringSalePriceElement !== null){
                    additionalSpringSalePriceElement.innerHTML = " + " + optionPrice;
                    additionalSpringSalePriceElement.innerText = " + " + optionPrice;
                }           
            }
            else {
                additionalPriceElement.innerHTML = "";
                additionalPriceElement.innerText = "";
                 if (additionalSalePriceElement !== null){
                    additionalSalePriceElement.innerHTML = "";
                    additionalSalePriceElement.innerText = "";
                }
                if (additionalSpringSalePriceElement !== null){
                    additionalSpringSalePriceElement.innerHTML = "";
                    additionalSpringSalePriceElement.innerText = "";
                }            
            }
        }

        ShowUserMustClickOptionMessage("false");

        var typeSelectedId = FindElementByPartialName("lblOptionTypeSelected", "span");
        var typeSelectedElement = getObject(typeSelectedId);
        typeSelectedElement.style.display = "inline";

        var typeUnSelectedId = FindElementByPartialName("lblOptionTypeUnselected", "span");
        var typeUnSelectedElement = getObject(typeUnSelectedId);
        typeUnSelectedElement.style.display = "none";
    }
    else {
        FlipTheBasketImage("true", btnAddToCartID, disabledAddToCartID);
    }

}

function showProductWarning(link, hylProductWarningID, linkText, msg, lblProductWarningID, optionName, lblOptionID, lblClickedOptionID, panelProductWarningID, textboxoptionid, textboxoptionname, tboSelectedProductOptionGuid, omnitureClickEvent, hylProductWarningID2) {
    var hylElement = getObject(hylProductWarningID);
    var hylElement2 = getObject(hylProductWarningID2);
    var lblElement = getObject(lblProductWarningID);
    var panelProductWarningElement = getObject(panelProductWarningID);

    //	if(lblElement.innerHTML == "" || lblElement.innerHTML == null)
    //	{
    if (link !== "") {
        hylElement.href = link;
        hylElement.innerHTML = linkText;
        hylElement.innerText = linkText;
        hylElement.style.display = "block";

        if (hylElement2) {
            hylElement2.href = link;
            //hylElement2.innerText = linkText;
            hylElement2.style.display = "block";

            if (omnitureClickEvent !== "") {
                hylElement.setAttribute("onclick", omnitureClickEvent);
                hylElement2.setAttribute("onclick", omnitureClickEvent);
            }
        }

        lblElement.style.display = "none";
    }
    else {
        hylElement.style.display = "none";
        hylElement2.style.display = "none";
    }

    lblElement.innerHTML = msg;
    lblElement.innerText = msg;
    lblElement.style.display = "block";
    panelProductWarningElement.style.display = "block";

    //set the option name 
    var lblOptionElement = getObject(lblOptionID);
    lblOptionElement.innerHTML = optionName;
    lblOptionElement.innerText = optionName;
    lblOptionElement.style.display = "inline";

    //hide the clicked option but set it
    var lblClickedOptionElement = getObject(lblClickedOptionID);
    lblClickedOptionElement.innerHTML = optionName;
    lblClickedOptionElement.innerText = optionName;
    lblClickedOptionElement.style.display = "none";

    //unselect the selected option
    var objectid = getObject(textboxoptionid);
    var controls = objectid.value;

    //now split on the comma
    var theList = controls.split(",");

    //set all the backgrounds to unselected white
    for (i = 0; i < theList.length; i++) {
        var found = theList[i];
        var control = getObject(found);
        if(control!=null)
        {
            var style1 = control.style;
            control.setAttribute("class", "ItemOption"); //firefox
            control.setAttribute("className", "ItemOption"); //ie
        }
        
    }

    //clear the hidden boxes
    var control3 = getObject(textboxoptionname);
    control3.value = "";

    //set the guid string into our selection textbox
    var controlGuidTextbox = getObject(tboSelectedProductOptionGuid);
    controlGuidTextbox.value = "";

    FlipTheBasketImage("false");
    ShowUserMustClickOptionMessage("false");

    var typeSelectedId = FindElementByPartialName("lblOptionTypeSelected", "span");
    var typeSelectedElement = getObject(typeSelectedId);
    typeSelectedElement.style.display = "none";

    var typeUnSelectedId = FindElementByPartialName("lblOptionTypeUnselected", "span");
    var typeUnSelectedElement = getObject(typeUnSelectedId);
    typeUnSelectedElement.style.display = "inline";


}

function highlightProductWarning(id, optionName, optionControlID, lblClickedOptionID) {
    var objectid = getObject(id);
    var style2 = objectid.style;

    var optioncontrol = getObject(optionControlID);
    optioncontrol.innerHTML = optionName;
    optioncontrol.innerText = optionName;
    optioncontrol.style.display = "inline";


    var lblClickedOptionElement = getObject(lblClickedOptionID);
    lblClickedOptionElement.style.display = "none";
    ShowUserMustClickOptionMessage("false");
}

function unhighlightProductWarning(id, optionControlID, lblClickedOptionID, hylProductWarningID, lblProductWarningID) {
    var objectid = getObject(id);
    var style2 = objectid.style;

    var optioncontrol = getObject(optionControlID);
    optioncontrol.innerHTML = "";
    optioncontrol.innerText = "";
    optioncontrol.style.display = "none";

    //show the clicked option
    var lblClickedOptionElement = getObject(lblClickedOptionID);
    lblClickedOptionElement.style.display = "inline";

    ShowUserMustClickOptionMessage("false");
}

function doHide(pnlToHide, pnlToShow, pnlGetAnotherHide) {
    var tags = document.forms[0].getElementsByTagName("div");

    for (i = 0; i < tags.length; i++) {
        var t = tags[i];

        if (t.id !== "") {
            var tid = t.id;
            if (tid.indexOf("modalPage") >= 0) {
                t.style.display = "none";
            }
            else if (tid.indexOf("panelOverView") >= 0) {
                t.style.display = "block";
            }
            else if (tid.indexOf("panelEditView") >= 0) {
                t.style.display = "none";
            }
        }
    }
}

function doShow(pnlToHide, pnlToShow, pnlGetAnotherHide) {
    var tags = document.forms[0].getElementsByTagName("div");

    for (i = 0; i < tags.length; i++) {
        var t = tags[i];

        if (t.id !== "") {
            var tid = t.id;
            if (tid.indexOf("modalPage") >= 0) {
                t.style.display = "none";
            }
            else if (tid.indexOf("panelOverView") >= 0) {
                t.style.display = "block";
            }
            else if (tid.indexOf("panelEditView") >= 0) {
                t.style.display = "none";
            }
        }
    }

    var panelToHide = getObject(pnlToHide);
    panelToHide.style.display = "none";

    var panelToShow = getObject(pnlToShow);
    panelToShow.style.display = "block";

    var panelGetAnotherHide = getObject(pnlGetAnotherHide);
    if (panelGetAnotherHide !== null) {
        panelGetAnotherHide.style.display = "none";
    }
}

var lastopened;
var lastimgopened;

function doImageToggle(pnlToToggle, imgToToggle) {
    //debugger;
    var imageToToggle = getObject(imgToToggle);
    var panelToToggle = getObject(pnlToToggle);

    if (lastopened !== null) {
        if (lastopened !== pnlToToggle) {
            var closepanel = getObject(lastopened);
            var closeimg = getObject(lastimgopened);
            if (closepanel !== null) {
                closepanel.style.display = "none";
            }
            if (closeimg !== null) {
                closeimg.setAttribute("class", "FilterByGenderClosedImage"); //firefox
                closeimg.setAttribute("className", "FilterByGenderClosedImage"); //ie
            }
        }
    }

    if (panelToToggle) {
        if (panelToToggle.style.display === "block") {
            panelToToggle.style.display = "none";
            imageToToggle.setAttribute("class", "FilterByGenderClosedImage"); //firefox
            imageToToggle.setAttribute("className", "FilterByGenderClosedImage"); //ie
        }
        else {
            panelToToggle.style.display = "block";
            imageToToggle.setAttribute("class", "FilterByGenderOpenImage"); //firefox
            imageToToggle.setAttribute("className", "FilterByGenderOpenImage"); //ie
            lastopened = pnlToToggle;
            lastimgopened = imgToToggle;
        }
    }
}

function selectoptionAndSubmit(hyperlink, id, textboxoptionid) {
    //set the color 
    var objectid = getObject(textboxoptionid);
    if (objectid) {
        //attempt to clear all the previous selected stuff
        //and 
        var controls = objectid.value;

        //now split on the comma
        var theList = controls.split(",");

        if (theList.length > 0) {
            //set all the backgrounds to unselected white
            for (i = 0; i < theList.length; i++) {
                var found = theList[i];
                var control = getObject(found);
                var style1 = control.style;
                control.setAttribute("class", "ItemOption"); //firefox
                control.setAttribute("className", "ItemOption"); //ie
            }

        }
    }

    var control2 = getObject(id);
    var style2 = control2.style;
    control2.setAttribute("class", "ItemOptionSelected"); //firefox
    control2.setAttribute("className", "ItemOptionSelected"); //ie

    //fire the link
    document.forms[0].action = hyperlink;
    document.forms[0].submit();
}


//END Product Option Select Script


