﻿/* WOM */
function womOn() {
    window.onload = womGo;
}

function womGo() {
    for (var i = 0; i < woms.length; i++) {
        if (typeof woms[i] == "function") {
            woms[i]();
        }
        else {
            eval(woms[i]);
        }
    }
}

function womAdd(func) {
    woms[woms.length] = func;
}

var woms = new Array();

womOn();



/* Log Functions */
function debugAlert(msg) {
    if (typeof debug != 'undefined') {
        alert(msg);
    }
}



/* Flash Load */
function GetFlashMovie(movieName) {
    if (window.document[movieName]) {
        return window.document[movieName];
    }
    if (navigator.appName.indexOf("Microsoft Internet") == -1) {
        if (document.embeds && document.embeds[movieName])
            return document.embeds[movieName];
    }
    else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
    {
        return document.getElementById(movieName);
    }
}



/* Cross Browser */
/* http://www.dynamicdrive.com/dynamicindex9/browsersniffer.htm for documentation */
var exclude = 1;
var agt = navigator.userAgent.toLowerCase();
var win = 0; var mac = 0; var lin = 1;
if (agt.indexOf('win') != -1) { win = 1; lin = 0; }
if (agt.indexOf('mac') != -1) { mac = 1; lin = 0; }
var lnx = 0; if (lin) { lnx = 1; }
var ice = 0;
var ie = 0; var ie4 = 0; var ie5 = 0; var ie6 = 0; var com = 0; var dcm;
var op5 = 0; var op6 = 0; var op7 = 0;
var ns4 = 0; var ns6 = 0; var ns7 = 0; var mz7 = 0; var kde = 0; var saf = 0;
if (typeof navigator.vendor != "undefined" && navigator.vendor == "KDE") {
    var thisKDE = agt;
    var splitKDE = thisKDE.split("konqueror/");
    var aKDE = splitKDE[1].split("; ");
    var KDEn = parseFloat(aKDE[0]);
    if (KDEn >= 2.2) {
        kde = 1;
        ns6 = 1;
        exclude = 0;
    }
}
else if (agt.indexOf('webtv') != -1) { exclude = 1; }
else if (typeof window.opera != "undefined") {
    exclude = 0;
    if (/opera[\/ ][5]/.test(agt)) { op5 = 1; }
    if (/opera[\/ ][6]/.test(agt)) { op6 = 1; }
    if (/opera[\/ ][7-9]/.test(agt)) { op7 = 1; }
}
else if (typeof document.all != "undefined" && !kde) {
    exclude = 0;
    ie = 1;
    if (typeof document.getElementById != "undefined") {
        ie5 = 1;
        if (agt.indexOf("msie 6") != -1) {
            ie6 = 1;
            dcm = document.compatMode;
            if (dcm != "BackCompat") { com = 1; }
        }
    }
    else { ie4 = 1; }
}
else if (typeof document.getElementById != "undefined") {
    exclude = 0;
    if (agt.indexOf("netscape/6") != -1 || agt.indexOf("netscape6") != -1) { ns6 = 1; }
    else if (agt.indexOf("netscape/7") != -1 || agt.indexOf("netscape7") != -1) { ns6 = 1; ns7 = 1; }
    else if (agt.indexOf("gecko") != -1) { ns6 = 1; mz7 = 1; }
    if (agt.indexOf("safari") != -1 || (typeof document.childNodes != "undefined" && typeof document.all == "undefined" && typeof navigator.taintEnabled == "undefined")) { mz7 = 0; ns6 = 1; saf = 1; }
}
else if ((agt.indexOf('mozilla') != -1) && (parseInt(navigator.appVersion) >= 4)) {
    exclude = 0;
    ns4 = 1;
    if (typeof navigator.mimeTypes['*'] == "undefined") {
        exclude = 1;
        ns4 = 0;
    }
}
if (agt.indexOf('escape') != -1) { exclude = 1; ns4 = 0; }
if (typeof navigator.__ice_version != "undefined") { exclude = 1; ie4 = 0; }


function NetshirtStop() {

    if (ie == 1) {
        document.execCommand('Stop');
        window.status = "RSK Netshirt";

    }

} //end NetshirtStop

function findTopPos(obj) {
    var curleft = curtop = 0;
    if (obj.offsetParent) {
        do {
            curleft += obj.offsetLeft;
            curtop += obj.offsetTop;
        } while (obj = obj.offsetParent);
    };
    return curtop;
}

/* functionality to allow flash to interact with divs on the page */

function openOverlay(iframeUrl, containerClass, dialogHeight) {
    if (containerClass === 'BnRRequestQuoteBox') { return };

    var sharingDialogContents = '<iframe class="OverlayFloatingSharingFrame" id="myiframe" width="100%" src="' + iframeUrl + '" scrolling="no" frameborder="0" allowTransparency="true"></iframe>';
    var standardDialogCloseLink = '<div style="width: 97%; text-align: right; padding: 5px;"><a onclick="closeOverlay();">Close</a></div>';

    var requestQuoteContents = '<div class="OverlayFloatingQuoteFrame">';
    requestQuoteContents += standardDialogCloseLink;
    requestQuoteContents += '<iframe id="myiframe" height="540" width="636" src="' + iframeUrl + '" scrolling="auto" frameborder="0" allowTransparency="true"></iframe>';
    requestQuoteContents += standardDialogCloseLink;
    requestQuoteContents += '</div>';

    var standardDialogContents = '<div class="OverlayFloatingFrame">';
    standardDialogContents += standardDialogCloseLink;
    standardDialogContents += '<iframe id="myiframe" height="540" width="784" src="' + iframeUrl + '" scrolling="auto" frameborder="0" allowTransparency="true"></iframe>';
    standardDialogContents += standardDialogCloseLink;
    standardDialogContents += '</div>';

    var overlay = document.getElementById("divOverlay");


    overlay.style.height = "100%";
    overlay.style.width = "100%";
    overlay.style.top = "0";
    overlay.style.left = "0";
    overlay.style.position = "absolute";





    var contents = '<div class="OverlayBackground">';
    contents += '<div class="OverlayShadowBackground"></div>';
    contents += '<div class="OverlayFloatingContainer">';
    contents += '<div class="OverlayFloatingVertMiddleTable"><div class="OverlayFloatingVertMiddleCell">';

    var bnrRequestQuoteContents = "";

    bnrRequestQuoteContents += '<div id="ProductDetailsControl" class="mainbodydiv ProductDetailsControl">';
    bnrRequestQuoteContents += '<div id="AddToQuoteRequestPopup" >';
    bnrRequestQuoteContents += '<div class="progressBackgroundFilter"></div>';
    bnrRequestQuoteContents += '<div id="AddToQuoteRequestPopupMessageContainer">';


    bnrRequestQuoteContents += '<div class="HeaderBar">';
    bnrRequestQuoteContents += '<span class="HeaderTitle">Added to your cart</span>';
    bnrRequestQuoteContents += '<span class="CloseButtonContainer"><a class="CloseButton" onclick="closeOverlay();"><span>X</span></a></span>';
    bnrRequestQuoteContents += '</div>';
    bnrRequestQuoteContents += '<div class="ContentArea">';
    bnrRequestQuoteContents += '<iframe id="myiframe" height="100%" width="100%" src="' + iframeUrl + '" frameborder="0" ></iframe>';

    bnrRequestQuoteContents += '</div>';

    bnrRequestQuoteContents += '</div>';
    bnrRequestQuoteContents += '</div>';

    bnrRequestQuoteContents += '</div>';



    var instructionsBoxContents = '<iframe class="InstructionsOverlayFrame"  width="100%" src="Netshirt_OrderInstructionEntry.aspx" scrolling="no" frameborder="0" allowTransparency="true"></iframe>';




    if (containerClass == "BnRRequestQuoteBox") {

        overlay.innerHTML = bnrRequestQuoteContents;
        return;
    }


    if (containerClass != null) {

        if (containerClass == "SharingDialogBox") {
            contents += sharingDialogContents;
        }
        else if (containerClass == "instructionsBox") {

            contents += instructionsBoxContents;


        }
        else if (containerClass == "RequestQuoteBox") {
            contents += requestQuoteContents;
        }
        else if (containerClass == "BnRRequestQuoteBox") {
            contents += bnrRequestQuoteContents;
        }
        else {
            contents += standardDialogContents;
        }
    }
    else {
        contents += standardDialogContents;
    }

    contents += '</div></div></div></div>';



    overlay.innerHTML = contents

};

function closeOverlay() {
    var overlay = document.getElementById('divOverlay');
    if (overlay != null) {
        overlay.innerHTML = "";

        // Chrome fix
        overlay.style.height = "0";
        overlay.style.width = "0";

        overlay.removeAttribute('style');
    }
};

function openVideo(url, height, width) {
    document.getElementById('SpanOverlay').innerHTML = '<div class="backgroundFilter"></div><div id="movieDiv" class="movieDiv"></div>';
    document.getElementById('movieDiv').innerHTML = '<iframe name="help" src="http://www.bodekandrhodes.com/appareldesignstudio/studio/demo.html" width="850" height="550" frameborder="0" scrolling="auto"></iframe><br/><div style="width: 97%; text-align: right; padding: 10px;"><a onclick="closeOverlay();">Close</a></div>';
};
/*
End of Flash div interactivity support
*/

/*
bindDropDown binds a value-array and optionally a text-array to a the dropdown ("select" tag) 
Anders Rask, 18/05/2011
*/
function bindDropDown(dropDownId, valueArray, textArray, removeExisting, selectedValue, titleArray) {
    if ((typeof (valueArray) == 'undefined') || (valueArray == null)) {
        alert("Cannot bind dropdown '" + dropDownId + "' since passed in value array is undefined or null!")
    } else {
        if ((typeof (removeExisting) == 'undefined') || (removeExisting == null)) { removeExisting = true };
        if ((typeof (textArray) == 'undefined') || (textArray == null)) { textArray = valueArray };

        var list = document.getElementById(dropDownId);
        if ((typeof (list) === 'undefined') || (list === null)) { return };

        if ((typeof (selectedValue) == 'undefined') || (selectedValue == null)) { selectedValue = list.value };

        var fillTitles = false;
        if ((typeof (titleArray) === 'object') && (titleArray !== null) && (titleArray.length === valueArray.length)) {
            fillTitles = true;
        };

        var existingLength = 0;
        if (removeExisting) {
            while (list.options.length > 0) {
                list.remove(0);
            };
        } else {
            existingLength = list.length;
        };


        for (i = 0; i < valueArray.length; i++) {
            var newOption = document.createElement('option');
            newOption.text = textArray[i];
            newOption.value = valueArray[i];

            if (fillTitles) {
                newOption.title = titleArray[i];
            } else {
                newOption.title = '';
            };

            if (newOption.value == selectedValue) {
                var indexToSelect = (i + existingLength);
            };

            try {
                list.add(newOption, null); // doesn't work in IE
            }
            catch (ex) {
                list.add(newOption); // IE only
            }
        };

        if ((typeof (indexToSelect) != 'undefined') && (indexToSelect != null)) { list.selectedIndex = indexToSelect };
    };

};

/*
runFunctions executes a collection of functions
Anders Rask, 20/05/2011
*/
function runFunctions(fs) {
    if (typeof (fs) == "function") {
        fs();
    } else if (typeof (fs) == 'string') {
        eval(fs);
    } else {
        for (var i = 0; i < fs.length; i++) {
            if (typeof fs[i] == "function") {
                fs[i]();
            }
            else {
                eval(fs[i]);
            };
        };
    };
};

/* qCopyValue copies value(s) from controls in one group (as defined by a jQuery selector) to another group, Anders Rask, 24/08/2011 */
function qCopyValue(sourceSelector, targetSelector) {
    var s = $(sourceSelector);
    var t = $(targetSelector);

    var loopCount = 0;

    if ((s.length > 0) && (t.length > 0)) {
        for (i = 0; i < t.length; i++) {
            if ((i - loopCount * s.length) == s.length) { loopCount++ };
            t[i].value = s[i - loopCount * s.length].value;
        };
    };
};

/* qSetValue sets one value to one or more control in one group of controls (as defined by a jQuery selector), Anders Rask, 24/08/2011 */
function qSetValue(selector, value) {
    var o = $(selector);

    if (o.length > 0) {
        for (i = 0; i < o.length; i++) {
            o[i].value = value;
        };
    };
};

function getParameterByName(name, returnValueIfEmpty) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(window.location.href);

    if (results == null) {
        if (typeof (returnValueIfEmpty) !== 'undefined') {
            return returnValueIfEmpty;
        } else {
            return "";
        };
    } else {
        return decodeURIComponent(results[1].replace(/\+/g, " "));
    };
}
