﻿function submitMe(item) {
    if ((item.options[item.selectedIndex].value).length > 0) {
        window.open(item.options[item.selectedIndex].value);
    }
}

function ProductTab(tab) {
    //FIRST UPDATE THE TAB
    document.getElementById("FeaturesTab").style.display = "none";
    document.getElementById("SpecificationsTab").style.display = "none";
    document.getElementById("MaterialsTab").style.display = "none";
    document.getElementById("VideoTab").style.display = "none";
    document.getElementById(tab).style.display = "block";

    //NEXT UPDATE THE IMAGE
    document.getElementById("FeaturesTabImage").src = "skins/skin_1/images/FeaturesTab.gif";
    document.getElementById("SpecificationsTabImage").src = "skins/skin_1/images/SpecificationsTab.gif";
    document.getElementById("MaterialsTabImage").src = "skins/skin_1/images/MaterialsTab.gif";
    document.getElementById("VideoTabImage").src = "skins/skin_1/images/VideoTab.gif";
    document.getElementById(tab + "Image").src = "skins/skin_1/images/" + tab + "Selected.gif";
}

function MHMProductLargeClick(pid) {
    //alert(document.getElementById("ProductPic" + pid).src);
    if (document.getElementById("ProductPic" + pid)["onclick"]) {
        document.getElementById("ProductPic" + pid)["onclick"]();
    }
}

function verify(f) {
    for (var i = 0; i < f.length; i++) {
        var e = f.elements[i];

        if (e.name == "ea") {
            if (e.value == "") {
                alert("Please enter your e-mail address.");
                f.elements[i].focus();
                return false;
            }

            var emailReg = ".+@.+\\.[a-z]+";
            var regex = new RegExp(emailReg);
            if (!regex.test(e.value)) {
                alert("The e-mail address you entered is invalid, please try again.");
                f.elements[i].focus();
                return false;
            }
        }
    }
}

function QuicktimeDetection() {
    var haveqt = false;

    if (navigator.plugins) {
        for (i = 0; i < navigator.plugins.length; i++) {
            if (navigator.plugins[i].name.indexOf("QuickTime") >= 0)
            { haveqt = true; }
        }
    }
    return haveqt;
}

function EmailEmptyText() {
    if (document.getElementById("ea").value == "") {
        document.getElementById("ea").value = "email address";
    }
    else if (document.getElementById("ea").value == "email address") {
        document.getElementById("ea").value = "";
    }    
}

function SearchEmptyText() {
    if (document.getElementById("ProductSearch").value == "") {
        document.getElementById("ProductSearch").value = "product search";
    }
    else if (document.getElementById("ProductSearch").value == "product search") {
    document.getElementById("ProductSearch").value = "";
    }
}

function IsNumeric(sText) {
    var ValidChars = "0123456789";
    var IsNumber = true;
    var Char;

    for (i = 0; i < sText.length && IsNumber == true; i++) {
        Char = sText.charAt(i);
        if (ValidChars.indexOf(Char) == -1) {
            IsNumber = false;
        }
    }
    return IsNumber;
}

function MHMChangeColorDropDown(ColorName) {
    var x = document.getElementById("Color");
    for (var i = 0; i < x.options.length; i++) {
        if (x.options[i].value.replace(" ", "").toLowerCase() == ColorName + ",") {
            x.options[i].selected = true;            
            if (document.getElementById("ColorNameWebFriendly"))
            {
                document.getElementById("ColorNameWebFriendly").value = x.options[i].value.replace(",", "");
            }
            break;
        }
    }
    document.getElementById("Color").onchange();   // when you click a color image you need to refresh the size inventory    
}

function ImageMouseOver (ID) {
    document.getElementById(ID).src = 'images/Category/medium/' + ID + '.jpg';
}

function ImageMouseOut(ID) {
    document.getElementById(ID).src = 'images/Category/large/' + ID + '.jpg';
}

function HomeImageMouseOver(ID) {
    document.getElementById(ID).src = 'skins/Skin_1/images/' + ID + 'Hover.jpg';
}

function HomeImageMouseOut(ID) {
    document.getElementById(ID).src = 'skins/Skin_1/images/' + ID + '.jpg';
}

function PopupCenter(pageURL, title, w, h) {
    var left = (screen.width / 2) - (w / 2);
    var top = (screen.height / 2) - (h / 2);

    var targetWin = window.open(pageURL, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
}

function gup(name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(window.location.href);

    if (results == null)
        return "";
    else
        return results[1];
}



//  inventory dropdown messaging
function MHMSizeDropDown(ProductID, Size, ColorFlag) {
    if (Size.indexOf("[") != -1)
    {
        Size = Size.substring(0, Size.indexOf("[")) + ",";    
    }
    
    if (document.getElementById("Color") == null) {  // set just colors and drop out if no colors exist as the message is always on the page
        var xx = document.getElementById("Size"); //  loop through array of sizes and colors
        for (ii = 0; ii < ProductID.length; ii++) {
            var test = "";
            test = String(ProductID[ii]);
            test = test.substring(1, (test.length));
            if ((test.indexOf(",0") > -1)) { // if no inventory set message
                for (yy = 1; yy < xx.length; yy++) {
                    if (xx.options[yy].text.indexOf("[") != -1) {
                        if ((test.substring(0, test.indexOf(","))) == (xx.options[yy].text.substring(0, xx.options[yy].text.indexOf(" [")))) {
                            xx.options[yy].text = String(xx.options[yy].text) + " (Out of Stock)";
                        }
                    }
                    else {                        
                        if ((test.substring(0, test.indexOf(","))) == (xx.options[yy].text)) {
                            xx.options[yy].text = String(xx.options[yy].text) + " (Out of Stock)";
                        }
                    }
                }
            }
        }
        return;
    }    
    var z = document.getElementById("Color");      // reset Colors
    for (y = 1; y <= (z.length - 1); y++) {
        z.options[y].text = String(z.options[y].text).replace(" (Out of Stock)", "");
    }
    var zz = document.getElementById("Size");      // reset Sizes
    for (y = 1; y <= (zz.length - 1); y++) {
        zz.options[y].text = String(zz.options[y].text).replace(" (Out of Stock)", "");
    }
    if (Size.indexOf("-,-") > -1) {
        z.options[0].selected = true;
        zz.options[0].selected = true;
        //AllColorAllSize(ProductID);              
    }

    Size = Size.substring(0, Size.indexOf(",") + 1);
    var x = document.getElementById("Color"); //  loop through array of sizes and colors
    for (i = 0; i < ProductID.length; i++) {
        var test = "";
        test = String(ProductID[i]);

        if ((ColorFlag > 0) && (test.indexOf("," + Size) > -1) && (test.indexOf(",0") > -1)) { // if no inventory set message
            for (y = 1; y < x.length; y++) {
                if (x.options[y].text.indexOf("[") != -1) {
                    if ((test.substring(0, test.indexOf(","))) == (x.options[y].text.substring(0, x.options[y].text.indexOf(" [")))) {
                        x.options[y].text = String(x.options[y].text) + " (Out of Stock)";
                    }
                }
                else {
                    if ((test.substring(0, test.indexOf(","))) == (x.options[y].text)) {
                        x.options[y].text = String(x.options[y].text) + " (Out of Stock)";
                    }
                }                           
            }
        }
        else if ((ColorFlag > 0) && (test.indexOf("," + Size) > -1) && (test.indexOf(",0") == -1)) {  // if inventory set message
            for (y = 1; y <= (x.length - 1); y++) {
                if (x.options[y].text.indexOf("[") != -1) {
                    if ((test.substring(0, test.indexOf(","))) == (x.options[y].text.substring(0, x.options[y].text.indexOf(" [")))) {                        
                        x.options[y].text = String(x.options[y].text).replace(" (Out of Stock)", "");
                    }
                }
                else {
                    if ((test.substring(0, test.indexOf(","))) == (x.options[y].text)) {
                        x.options[y].text = String(x.options[y].text).replace(" (Out of Stock)", "");
                    }
                }                           
            }
        }
    }
}

function MHMColorDropDown(ProductID, Color, SizeFlag) {
    if (Color.indexOf("[") != -1) {
        Color = Color.substring(0, Color.indexOf("[")) + ",";
    }
    
    if (document.getElementById("Size") == null) {    // drop out if no sizes exist as the message is always on the page
        var xx = document.getElementById("Color"); //  loop through array of sizes and colors
        for (ii = 0; ii < ProductID.length; ii++) {
            var test = "";
            test = String(ProductID[ii]);

            if ((test.indexOf(",0") > -1)) { // if no inventory set message
                for (yy = 1; yy <= (xx.length - 1); yy++) {
                    if (xx.options[yy].text.indexOf("[") != -1) {
                        if ((test.substring(0, test.indexOf(","))) == (xx.options[yy].text.substring(0, xx.options[yy].text.indexOf(" [")))) {
                            xx.options[yy].text = String(xx.options[yy].text) + " (Out of Stock)";
                        }
                    }
                    else {
                        if ((test.substring(0, test.indexOf(","))) == (xx.options[yy].text)) {
                            xx.options[yy].text = String(xx.options[yy].text) + " (Out of Stock)";
                        }
                    }
                }
            }
        }
        return;
    }  //  END drop out if no sizes exist as the message is always on the page

    var z = document.getElementById("Color"); // reset Colors
    for (y = 1; y <= (z.length - 1); y++) {
        z.options[y].text = String(z.options[y].text).replace(" (Out of Stock)", "");
    }

    var zz = document.getElementById("Size"); // reset Sizes
    for (y = 1; y <= (zz.length - 1); y++) {
        zz.options[y].text = String(zz.options[y].text).replace(" (Out of Stock)", "");
    }
    if (Color.indexOf("-,-") > -1) {
        z.options[0].selected = true;
        zz.options[0].selected = true;
        //AllColorAllSize(ProductID);
    }

    Color = Color.substring(0, Color.indexOf(",") + 1);
    var x = document.getElementById("Size");
    for (i = 0; i < ProductID.length; i++) {   //  loop through array of sizes and colors
        var test = "";
        test = String(ProductID[i]);
        var Size = test.replace(Color, "");
        Size = Size.substring(0, Size.indexOf(","));

        if ((SizeFlag > 0) && (test.indexOf(Color) > -1) && (test.indexOf(",0") > -1)) {  // if no inventory set message            
            for (y = 1; y <= (x.length - 1); y++) {                
                if (x.options[y].text.indexOf("[") != -1) {
                    if (Size == (x.options[y].text.substring(0, x.options[y].text.indexOf(" [")))) {
                        x.options[y].text = String(x.options[y].text) + " (Out of Stock)";
                    }
                }
                else {
                    if (Size == (x.options[y].text)) {
                        x.options[y].text = String(x.options[y].text) + " (Out of Stock)";
                    }
                }
            }
        }
        else if ((SizeFlag > 0) && (test.indexOf(Color) > -1) && (test.indexOf(",0") == -1)) {   // if inventory set message        
            for (y = 1; y <= (x.length - 1); y++) {
                if (x.options[y].text.indexOf("[") != -1) {
                    if (Size == (x.options[y].text.substring(0, x.options[y].text.indexOf(" [")))) {
                        x.options[y].text = String(x.options[y].text).replace(" (Out of Stock)", "");
                    }
                }
                else {
                    if (Size == (x.options[y].text)) {
                        x.options[y].text = String(x.options[y].text).replace(" (Out of Stock)", "");
                    }
                }                        
            }
        }
    }
}

function AllColorAllSize(ProductID) {
    var x = document.getElementById("Size");
    var SizeCount = (x.length - 1);
    var SizeZeroCount = 0;
    var z = document.getElementById("Color");
    var ColorCount = (z.length - 1);
    var ColorZeroCount = 0;

    for (y = 1; y < z.length; y++) {
        ColorZeroCount = 0;
        var ColorName = z.options[y].text;
        for (i = 0; i < ProductID.length; i++) {
            var test = "";
            test = String(ProductID[i]);
            if ((test.indexOf(ColorName + ",") != -1) && (test.indexOf(",0") != -1)) {
                ColorZeroCount = ColorZeroCount + 1;
            }
        }
        //alert(ColorZeroCount + ":" + ColorCount);
        if (SizeCount == ColorZeroCount) {
            z.options[y].text = String(z.options[y].text) + " (Out of Stock)";
        }
    }

    for (y = 1; y < x.length; y++) {
        SizeZeroCount = 0;
        var SizeName = x.options[y].text;
        for (i = 0; i < ProductID.length; i++) {
            var test = "";
            test = String(ProductID[i]);
            var SizeNameString = "," + String(SizeName) + ",0";
            //alert(SizeNameString + ":" + test);
            if ((test.indexOf(SizeNameString)) > -1) {
                SizeZeroCount = SizeZeroCount + 1;
            }
        }
        //alert(SizeZeroCount + ":" + SizeCount);
        if (ColorCount == SizeZeroCount) {
            x.options[y].text = String(x.options[y].text) + " (Out of Stock)";
        }
    }
}




function InventoryPreset() {
    var ColorExists = document.getElementById("Color");
    var SizeExists = document.getElementById("Size");
    if (SizeExists != null && ColorExists == null) {
        //alert("Size exists");
        document.getElementById("Size").onchange();
    }

    if (ColorExists != null && SizeExists == null) {
        //alert("Color exists");
        document.getElementById("Color").onchange();
    }

    if (ColorExists == null && SizeExists == null) {
        //alert("no color no size");
        OneSizeInventoryCheck();
    }
}

function OneSizeInventoryCheck() {
    if (MHMOneSizeInventory == 0) {
        //alert("no inventory");
        document.getElementById("ProductAddToCartMHM").style.display = "none";
        document.getElementById("MHMCartValidation").style.display = "block";
        document.getElementById("MHMCartValidationText").value = "This item is currently out of stock.";             

        
    }
}


function GetDocWidth() {
    var D = document;
    return Math.max(
        $(document).width(),
        $(window).width(),
    /* For opera: */
        document.documentElement.clientWidth
        );
}

function GetDocHeight() {
    var D = document;
    return Math.max(
        $(document).height(),
        $(window).height(),
    /* For opera: */
        document.documentElement.clientHeight
        );
}




