function com_stewartspeak_replacement() {
    /*
    Dynamic Heading Generator
    By Stewart Rosenberger
    http://www.stewartspeak.com/headings/

    This script searches through a web page for specific or general elements
    and replaces them with dynamically generated images, in conjunction with
    a server-side script.
    */

    // replaceSelector(selector, phpfile, wordwrap, fontfile, size, background, foreground, store)
    // replaceSelector("h4","/services/heading.php",false,"font.ttf","12","FFFFFF","999999","build200501");

    var testURL = "/images/test.png";
    var doNotPrintImages = false;
    var printerCSS = "/replacement-print.css";
    var hideFlicker = false;
    var hideFlickerCSS = "/replacement-screen.css";
    var hideFlickerTimeout = 1000;

    /* ---------------------------------------------------------------------------
    For basic usage, you should not need to edit anything below this comment.
    If you need to further customize this script's abilities, make sure
    you're familiar with Javascript. And grab a soda or something.
    */

    var items;
    var imageLoaded = false;
    var documentLoaded = false;

    function replaceSelector(selector, url, wordwrap, font, size, foreground, background, store) {
        if (typeof items == "undefined") {
            items = new Array();
        }
        items[items.length] = { selector: selector, url: url, wordwrap: wordwrap, font: font, size: size, foreground: foreground, background: background, store: store };
    }

    if (hideFlicker) {
        document.write('<link id="hide-flicker" rel="stylesheet" media="screen" href="' + hideFlickerCSS + '" />');
        window.flickerCheck = function() {
            if (!imageLoaded) {
                setStyleSheetState('hide-flicker', false);
            }
        };
        setTimeout('window.flickerCheck();', hideFlickerTimeout)
    }

    if (doNotPrintImages) {
        document.write('<link id="print-text" rel="stylesheet" media="print" href="' + printerCSS + '" />');
    }

    var test = new Image();
    test.onload = function() { imageLoaded = true; if (documentLoaded) replacement(); };
    test.src = testURL + "?date=" + (new Date()).getTime();


window.onresize = setScreenClass;	

	function setScreenClass(){
var myWidth = 0;
var cls = 'tblWrapper';

  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
  } else if( document.documentElement && ( document.documentElement.clientWidth ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
  } else if( document.body && ( document.body.clientWidth ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
  }

if (myWidth > 960) {
cls = 'tblWrapper';
}
else {
cls = 'tblWrapperSmall';
}

//	document.getElementById('tblPage').className=cls;
	};	


    addLoadHandler(function() { documentLoaded = true; setScreenClass(); if (imageLoaded) replacement(); });


    function documentLoad() {
        documentLoaded = true;
        if (imageLoaded) {
            replacement();
        }
    }

    function replacement() {
        if (items) {
            for (var i = 0; i < items.length; i++) {
                var elements = getElementsBySelector(items[i].selector);
                if (elements.length > 0) for (var j = 0; j < elements.length; j++) {
                    if (!elements[j]) {
                        continue;
                    }

                    var text = extractText(elements[j]);
                    while (elements[j].hasChildNodes()) {
                        elements[j].removeChild(elements[j].firstChild);
                    }

                    var tokens = items[i].wordwrap ? text.split(' ') : [text];
                    for (var k = 0; k < tokens.length; k++) {
                        var url = items[i].url + "?text=" + escape(tokens[k] + ' ') + "&selector=" + escape(items[i].selector) + "&font=" + escape(items[i].font) + "&size=" + escape(items[i].size) + "&foreground=" + escape(items[i].foreground) + "&background=" + escape(items[i].background) + "&store=" + escape(items[i].store);
                        var image = document.createElement("img");
                        image.className = "replacement";
                        image.alt = tokens[k];
                        image.src = url;
                        elements[j].appendChild(image);
                    }

                    if (doNotPrintImages) {
                        var span = document.createElement("span");
                        span.style.display = 'none';
                        span.className = "print-text";
                        span.appendChild(document.createTextNode(text));
                        elements[j].appendChild(span);
                    }
                }
            }

            if (hideFlicker) {
                setStyleSheetState('hide-flicker', false);
            }
        }
    }

    function addLoadHandler(handler) {
        if (window.addEventListener) {
            window.addEventListener("load", handler, false);
        } else if (window.attachEvent) {
            window.attachEvent("onload", handler);
        } else if (window.onload) {
            var oldHandler = window.onload;
            window.onload = function piggyback() {
                oldHandler();
                handler();
            };
        } else {
            window.onload = handler;
        }
    }

    function setStyleSheetState(id, enabled) {
        var sheet = document.getElementById(id);
        if (sheet) {
            sheet.disabled = (!enabled);
        }
    }

    function extractText(element) {
        if (typeof element == "string") {
            return element;
        } else if (typeof element == "undefined") {
            return element;
        } else if (element.innerText) {
            return element.innerText;
        }

        var text = "";
        var kids = element.childNodes;
        for (var i = 0; i < kids.length; i++) {
            if (kids[i].nodeType == 1) {
                text += extractText(kids[i]);
            } else if (kids[i].nodeType == 3) {
                text += kids[i].nodeValue;
            }
        }

        return text;
    }

    /*
    Finds elements on page that match a given CSS selector rule. Some
    complicated rules are not compatible.
    Based on Simon Willison's excellent "getElementsBySelector" function.
    Original code (with comments and description):
    http://simon.incutio.com/archive/2003/03/25/getElementsBySelector
    */
    function getElementsBySelector(selector) {
        var tokens = selector.split(' ');
        var currentContext = new Array(document);
        for (var i = 0; i < tokens.length; i++) {
            token = tokens[i].replace(/^\s+/, '').replace(/\s+$/, '');
            if (token.indexOf('#') > -1) {
                var bits = token.split('#');
                var tagName = bits[0];
                var id = bits[1];
                var element = document.getElementById(id);
                if (tagName && element.nodeName.toLowerCase() != tagName)
                    return new Array();
                currentContext = new Array(element);
                continue;
            }
            if (token.indexOf('.') > -1) {
                var bits = token.split('.');
                var tagName = bits[0];
                var className = bits[1];
                if (!tagName) {
                    tagName = '*';
                }

                var found = new Array;
                var foundCount = 0;
                for (var h = 0; h < currentContext.length; h++) {
                    var elements;
                    if (tagName == '*') {
                        elements = currentContext[h].all ? currentContext[h].all : currentContext[h].getElementsByTagName('*');
                    } else {
                        elements = currentContext[h].getElementsByTagName(tagName);
                    }
                    for (var j = 0; j < elements.length; j++) {
                        found[foundCount++] = elements[j];
                    }
                }

                currentContext = new Array;
                var currentContextIndex = 0;
                for (var k = 0; k < found.length; k++) {
                    if (found[k].className && found[k].className.match(new RegExp('\\b' + className + '\\b'))) {
                        currentContext[currentContextIndex++] = found[k];
                    }
                }
                continue;
            }

            if (token.match(/^(\w*)\[(\w+)([=~\|\^\$\*]?)=?"?([^\]"]*)"?\]$/)) {
                var tagName = RegExp.$1;
                var attrName = RegExp.$2;
                var attrOperator = RegExp.$3;
                var attrValue = RegExp.$4;
                if (!tagName) {
                    tagName = '*';
                }

                var found = new Array;
                var foundCount = 0;
                for (var h = 0; h < currentContext.length; h++) {
                    var elements;
                    if (tagName == '*') {
                        elements = currentContext[h].all ? currentContext[h].all : currentContext[h].getElementsByTagName('*');
                    } else {
                        elements = currentContext[h].getElementsByTagName(tagName);
                    }

                    for (var j = 0; j < elements.length; j++) {
                        found[foundCount++] = elements[j];
                    }
                }

                currentContext = new Array;
                var currentContextIndex = 0;
                var checkFunction;
                switch (attrOperator) {
                    case '=':
                        checkFunction = function(e) { return (e.getAttribute(attrName) == attrValue); };
                        break;
                    case '~':
                        checkFunction = function(e) { return (e.getAttribute(attrName).match(new RegExp('\\b' + attrValue + '\\b'))); };
                        break;
                    case '|':
                        checkFunction = function(e) { return (e.getAttribute(attrName).match(new RegExp('^' + attrValue + '-?'))); };
                        break;
                    case '^':
                        checkFunction = function(e) { return (e.getAttribute(attrName).indexOf(attrValue) == 0); };
                        break;
                    case '$':
                        checkFunction = function(e) { return (e.getAttribute(attrName).lastIndexOf(attrValue) == e.getAttribute(attrName).length - attrValue.length); };
                        break;
                    case '*':
                        checkFunction = function(e) { return (e.getAttribute(attrName).indexOf(attrValue) > -1); };
                        break;
                    default:
                        checkFunction = function(e) { return e.getAttribute(attrName); };
                        break;
                }

                currentContext = new Array;
                var currentContextIndex = 0;
                for (var k = 0; k < found.length; k++) {
                    if (checkFunction(found[k])) {
                        currentContext[currentContextIndex++] = found[k];
                    }
                }
                continue;
            }

            tagName = token;
            var found = new Array;
            var foundCount = 0;
            for (var h = 0; h < currentContext.length; h++) {
                var elements = currentContext[h].getElementsByTagName(tagName);
                for (var j = 0; j < elements.length; j++) {
                    found[foundCount++] = elements[j];
                }
            }

            currentContext = found;
        }

        return currentContext;
    }
}

// end of scope, execute code
if (document.createElement && document.getElementsByTagName && !navigator.userAgent.match(/opera\/?6/i)) {
    com_stewartspeak_replacement();
}

// Used for search by rating and search by price menus.
function go(form) {
    window.location = form.range.options[form.range.selectedIndex].value;
}

// Standard preload function
function preload_images() {
    var d = document;
    if (!d.imgs) { d.imgs = new Array(); }
    var j = d.imgs.length, args = preload_images.arguments, i;
    for (i = 0; i < args.length; i++) {
        d.imgs[j] = new Image;
        d.imgs[j].src = args[i];
        j++;
    }
}

// Standard bookmark function
function bookmark(title) {
    var urlAddress = location.href;
    var pageName = title;
    var browser = navigator.appName;
    if (browser == 'Microsoft Internet Explorer') {
        window.external.AddFavorite(urlAddress, pageName)
    } else if (browser == 'Netscape') {
        alert("Your browser does not support this feature.  Use CTRL-D to bookmark this page");
    } else {
        alert("Your browser does not support this feature.");
    }
}

/* The functions below are cookie functions which can be used for anything site-wide but
are intended (at the moment) to be used for the dynamic cart quantities */

function getCookie(Name) {
    var search = Name + "=";
    var returnvalue = "";
    if (document.cookie.length > 0) {
        offset = document.cookie.indexOf(search)
        // if cookie exists
        if (offset != -1) {
            offset += search.length
        }
        // set index of beginning of value
        end = document.cookie.indexOf(";", offset);
        // set index of end of cookie value
        if (end == -1) {
            end = document.cookie.length;
        }
        returnvalue = unescape(document.cookie.substring(offset, end))
    }
    return returnvalue;
}

function setCookie(name, num) {
    //set document cookie
    document.cookie = name + "=" + num;
}

function isCookied(name, num) {
    if (getCookie(name) != num) {
        return true;
    } else {
        return false;
    }
}

/* End Cookie Functions */

/* Dynamic Quantities JavaScript Below */

function priceChange(id, oper, num) {
    // Price Change v1.2:
    // id = the id of the product (so we know what qty box and price to update).
    // oper = what operation to use: dynamic:add:sub:dropdown
    // num = the original price of the product
    //
    // --[ Revisions ]--
    // 20050603 - v1 - Original Script Creation ~Michael@ColorMaria
    // 20050620 - v1.1 - Modified Script to Support Drop-Down Quantity Boxes ~Michael@ColorMaria
    // 20051215 - v1.2 - Added a fix for commas.
    /////////////////////////////////////////////////////////////////////////////////////////////
    if (num == '') {
        num = document.getElementById('hidden_price_' + id).value;
    }
    if (oper == 'dynamic') {
        // Get the qty value:
        var num2 = 0;
        var qty = document.getElementById('qty_' + id).value;
        // Make sure they didn't go below 1:
        if (qty < 1 || qty == '') {
            document.getElementById('price_' + id).value = '$' + num;
        } else {
            // If they're above one or at 1, do the math for the price:
            num2 = num.replace(',', '') * document.getElementById('qty_' + id).value;
            document.getElementById('price_' + id).value = '$' + num2.toFixed(2);
        }
    }
    if (oper == 'add') {
        // Increment the qty box:
        ++document.getElementById('qty_' + id).value;
        // Set qty equal to the new value:
        var qty = document.getElementById('qty_' + id).value;
        if (qty < 1) {
            // Probably not gonna happen, but just in case:
            document.getElementById('qty_' + id).value = '1';
            document.getElementById('price_' + id).value = '$' + num;
        } else {
            // Do the math for the new price:
            num2 = num.replace(',', '') * document.getElementById('qty_' + id).value;
            document.getElementById('price_' + id).value = '$' + num2.toFixed(2);
        }
    }
    if (oper == 'sub') {
        // Decrement the value of the qty box:
        --document.getElementById('qty_' + id).value;
        // Set qty = to the new value:
        var qty = document.getElementById('qty_' + id).value;
        if (qty < 1) {
            // Set qty back to 1 if they try to go below 1:
            document.getElementById('qty_' + id).value = '1';
            document.getElementById('price_' + id).value = '$' + num;
        } else {
            // If they're above one or at 1 then do the math for the price:
            num2 = num.replace(',', '') * document.getElementById('qty_' + id).value;
        }
    }
    if (oper == 'dropdown') {
        // Set qty = to the new value:
        var qty = document.getElementById('qty_' + id).value;
        if (qty < 1) {
            // Not sure how this will happen, but you never know:
            document.getElementById('qty_' + id).value = '1';
            document.getElementById('price_' + id).value = '$' + num;
        } else {
            // If they're above one or at 1 then do the math for the price:
            num2 = num.replace(',', '') * document.getElementById('qty_' + id).value;
        }
    }
    // Some people like to do weird things, like enter letters for a quantity amount, let's not let them:
    if (num2 != '') {
        if (!isNaN(num2)) {
            // if num wasn't NaN then a letter wasn't entered
            document.getElementById('price_' + id).value = '$' + num2.toFixed(2);
        } else {
            // if num was NaN, fix it.
            document.getElementById('price_' + id).value = '$' + num;
            document.getElementById('qty_' + id).value = '';
        }
    }
}

function cartChange(id, num, qty, total) {
    // Cart Change v1.4:
    // id = an id to represent the price and qty (so we know what qty box and price to update).
    // num = the original cost of the item(s) (if there were 3x a 10-dollar item, num would = 30.00).
    // qty = the original quantity that existed in the cart before modification
    // total = the original total of the cart items before modification.
    // 
    // --[ Revisions ]--
    // 20050620 - Original Script Creation ~Michael@ColorMaria
    // 20050629 - Added a line to change the color of the update cart message ~Michael@ColorMaria
    // 20050705 - Added code (accompanied by cookies) to check the quantities of items in the cart
    //          - to see whether they match what the user entered for better checking to see if 
    //          - the update cart button needs to be pressed.
    //          - 
    //          - Please note: This update requires the cookie functions above the priceChange
    //          - function. ~Michael@ColorMaria
    // 20050722 - Added error handling for NaN errors.
    // 20051215 - Fixed a bug with commas
    ///////////////////////////////////////////////////////////////////////////////////////////////
    // Setup our Variables:
    var num2 = 0;
    var qty2 = document.getElementById('qty_' + id).value;
    if (isNaN(qty2)) { // If qty2 isNaN that means someone's made a typo and hit a letter or other non-number key
        document.getElementById('qty_' + id).value = '';
        qty2 = '';
    }
    var num3 = document.getElementById('price_' + id).value.split("$");
    var num3 = num3[1].replace(',', '');
    // Check to see if we're dividing by 0:
    if (qty != '0' || !qty) {
        // If not, get the real price (rPrice):
        var rPrice = num.replace(',', '') / qty;
    } else {
        // If we are, set the total price for that item to 0:
        document.getElementById('price_' + id).value = '$0.00';
    }
    // Setup our new prices:
    num2 = (rPrice * qty2);
    document.getElementById('price_' + id).value = '$' + num2.toFixed(2);
    // We gotta do this differently depending on if the total we're modifying 
    // is the REAL total or if it's one that was previously modified.
    if (total == document.getElementById('total').value) {
        // If we are modifying the current REAL total, do it this way:
        // Figure out what total would be if the item we're modifying didn't exist.
        total = total - num3;
        // Add the new value to the total:
        total = total + num2;
        document.getElementById('total').value = '$' + total.toFixed(2);
    } else {
        // Setup our fake_total variable so we can essentially do the same 
        // thing we did with the real total
        var fake_total = document.getElementById('total').value.split("$");
        fake_total = fake_total[1].replace(',', '');
        // Figure out what the total would be without this product.
        total = fake_total - num3;
        // Readd the new value to the total.
        total = total + num2;
        document.getElementById('total').value = '$' + total.toFixed(2);
    }
    // Just in case they think this will automagically update the real prices for them,
    // setup a fail safe the function below will read and evaluate:
    var nQty = getCookie('quantities');
    arQty = nQty.split('|');
    // Note: the last element of the array will be empty, so ignore it.
    cntQty = arQty.length - 1;
    for (i = 0; i < cntQty; i++) {
        arID = arQty[i].split(','); // Hoo Hoo (owl)
        if (document.getElementById('qty_' + arID[0]).value == arID[1]) {
            // It equals the default quantity, yay! No need to update cart.
            document.getElementById('hasUpdated').value = '1';
            // Change the color of the update cart message.
            document.getElementById('update_msg').style.color = '#000';
            continue;
        } else {
            // It doesn't, they need to update.  No need to check further since if one hasn't been updated
            // the whole cart needs to be updated.
            document.getElementById('hasUpdated').value = '0';
            // Change the color of the update cart message so it stands out after a change to the qty is made.
            document.getElementById('update_msg').style.color = '#F00';
            // Break the loop.
            break;
        }
    }
}

function hasUpdated() {
    // Small function to verify that the cart has been updated
    // before checking out or using the continue shopping button.
    //
    // 20060403 - Added fix for when 'hasUpdated' doesn't exist. ~Michael
    ///////////////////////////////////////////////////////////////
    if (typeof document.getElementById('hasUpdated') != 'undefined') {
        var hUpdated = document.getElementById('hasUpdated').value;
        if (hUpdated != '1') {
            alert('You have not updated your cart since last changing your quantities.\nPlease press the \'Update Cart\' button before continuing.');
            return false;
        }
    }
}

/* ** END Dynamic Quantities JS ** */


/* ***************************************
* verifyRecipients() function.        *
* Checks the checkout_shippingdetail  *
* page to ensure that a shipping      *
* recipient was chosen for each       *
* product and that there weren't any  *
* missed recipients.  If gives the    *
* customer the option of ignoring     *
* missed ship-tos since that doesn't  *
* break the checkout it just causes   *
* blank spaces in some spots.         *
*                                     *
* ~Michael - 20060111                 *
*************************************** */

function verifyRecipients(theForm) {
    var intLength = theForm.length;            // Grab the total length of the form.
    var firstStep = 1, shipTos = new Array();  // Initialize a couple vars to be used later.
    for (var i = 0; i < intLength; i++) {             // Loop through the form elements.
        if (firstStep && theForm.elements[i].name.substr(0, 4) == 'recp') {
            // If it's the first dropdown setup the number of ship-tos it contains to compare later
            var numShipTos = +theForm.elements[i].options.length - 1;
            // Turn this off so it doesn't repeat this step (it won't hurt anything but would waste processing power).
            firstStep = 0;
        }
        if (theForm.elements[i].name.substr(0, 4) == 'recp' && theForm.elements[i].value == '') {
            // If we encounter a dropdown that hasn't had a ship-to selected..
            alert('You must choose a recipient for each of the products you are purchasing.');
            return false;
        } else if (theForm.elements[i].name.substr(0, 4) == 'recp') {
            // Otherwise add the item to an array to compare later.
            var shipTo = theForm.elements[i].selectedIndex;
            if (!in_array(shipTo, shipTos)) {
                // If the ship-to isn't in the array already, add it.
                var stLen = shipTos.length;
                shipTos.push(shipTo);
            }
        }
    }
    if (shipTos.length != numShipTos) {
        // If the # of ship-tos in the array don't match the number of ship-tos that exist, prompt the user
        var verifyShipTos = confirm("Some of your shipping address do not have products assigned to them.\n\nDo you wish to continue anyway?");
        if (verifyShipTos) {
            // User says it's OK
            return true;
        } else {
            // User says it's not OK
            return false;
        }
    }
    // If we've gotten this far, everything on the form has checked out OK.
    return true;
}

/* ***************************************
* in_array() function for JS.         *
* Works the same as the PHP function. *
*                                     *
* ~Michael - 20060111                 *
* ~Michael - Fixed undefined vars     *
*            20060111                 *
*************************************** */

function in_array(needle, haystack) {
    if (typeof needle == undefined) {
        // If needle is undefined:
        alert("Needle is undefined.\nError: in_array");
        return false;
    } else if (typeof haystack == undefined) {
        alert("Needle is undefined.\nError: in_array");
        return false;
    }
    for (i = 0, n = haystack.length; i < n; i++) {
        // Loop through the array.
        if (haystack[i] == needle) {
            // If the needle was found:
            return true;
        }
    }
    // If the code reaches this point, needle wasn't found:
    return false;
}

/* ************************
* noHammer() function  *
* Prevents form submit *
* button hammering.    *
*                      *
* ~Michael - 20060403  *
************************ */

function noHammer(theForm) {
    if (typeof theForm.submit != 'undefined') {
        theForm.submit.disabled = true;
        theForm.submit.value = 'Wait...';
        return true;
    }
}

/* ************************
* validateForgotForm() *
* Checks for a valid   *
* email before submit  *
*                      *
* ~Michael - 20060905  *
************************ */
function validateForgotForm(theForm) {
    var theEmail = theForm.email;
    var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
    if ((theEmail.value == null) || (theEmail.value == "")) {
        document.getElementById('errorMsg').innerHTML = "<br />Please enter a valid e-mail address before continuing.";
        theEmail.focus();
        return false;
    } else {
        if (!filter.test(theEmail.value)) {
            document.getElementById('errorMsg').innerHTML = "<br />Please enter a valid e-mail address before continuing.";

            theEmail.value = "";
            theEmail.focus();
            return false;
        }
    }
    return true;
}

//////////////////////////////////////////////////////////////////////////////////////////
// DreamWeaver's functions.

function MM_openBrWindow(theURL, winName, features) { //v2.0
    window.open(theURL, winName, features);
}

function MM_swapImgRestore() { //v3.0
    var i, x, a = document.MM_sr; for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
}

function MM_findObj(n, d) { //v4.01
    var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
    if (!x && d.getElementById) x = d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
    var i, j = 0, x, a = MM_swapImage.arguments; document.MM_sr = new Array; for (i = 0; i < (a.length - 2); i += 3)
        if ((x = MM_findObj(a[i])) != null) { document.MM_sr[j++] = x; if (!x.oSrc) x.oSrc = x.src; x.src = a[i + 2]; }
}

// End DreamWeaver's functions.
//////////////////////////////////////////////////////////////////////////////////////////

function openWin(sDoc) {
    if (document.all) {
        window.open(sDoc, '', 'width=580,height=450,scrollbars=yes,resizable=yes');
    }
    else if (document.layers) {
        window.open(sDoc, '', 'width=580,height=450,scrollbars=yes,resizable=yes');
    }
    else if (document.getElementById) {
        window.open(sDoc, '', 'width=580,height=450,scrollbars=yes,resizable=yes');
    }
}

function roll_over(img_name, img_src) {
    document[img_name].src = img_src;
}

function enableField() {
    document.ship_form.gift_message1.disabled = false;
    document.ship_form.gift_message1.style.background = '#FFF';
}



function addOption(selectbox, text, value) {
    var optn = document.createElement("OPTION");
    optn.text = text;
    optn.value = value;
    selectbox.options.add(optn);
}

function removeAllOptions(selectbox) {
    var i;
    for (i = selectbox.options.length - 1; i >= 0; i--) {
        //selectbox.options.remove(i);
        selectbox.remove(i);
    }
}



function SelectSubCat() {
    // ON selection of category this function will work

    removeAllOptions(document.ship_form.s_method1);

    if ((document.ship_form.s_state1.value == 'AK' || document.ship_form.s_state1.value == 'HI') && document.ship_form.s_country1.value == 'United States') {

        addOption(document.ship_form.s_method1, "Standard", "Standard");
        addOption(document.ship_form.s_method1, "2nd Day AK HI", "2nd Day AK HI");

    } else if (document.ship_form.s_state1.value == 'AB' || document.ship_form.s_state1.value == 'BC' || document.ship_form.s_state1.value == 'MB' || document.ship_form.s_state1.value == 'NB' || document.ship_form.s_state1.value == 'NF' || document.ship_form.s_state1.value == 'NT' || document.ship_form.s_state1.value == 'NS' || document.ship_form.s_state1.value == 'ON' || document.ship_form.s_state1.value == 'PE' || document.ship_form.s_state1.value == 'QC' || document.ship_form.s_state1.value == 'SK' || document.ship_form.s_state1.value == 'YT' || document.ship_form.s_country1.value == 'Canada') {

        //          addOption(document.ship_form.s_method1,"Standard Canada", "Standard Canada");
        addOption(document.ship_form.s_method1, "Standard International", "Standard International");

    } else if ((document.ship_form.s_state1.value == 'AF' || document.ship_form.s_state1.value == 'AA' || document.ship_form.s_state1.value == 'AC' || document.ship_form.s_state1.value == 'AE' || document.ship_form.s_state1.value == 'AM' || document.ship_form.s_state1.value == 'AP' || document.ship_form.s_state1.value == 'PR') && document.ship_form.s_country1.value == 'United States') {
        addOption(document.ship_form.s_method1, "Standard Mail", "Standard Mail");
    } else if (document.ship_form.s_country1.value == 'United States') {
        addOption(document.ship_form.s_method1, "Standard", "Standard");
        // addOption(document.ship_form.s_method1,"3 Day Select", "3 Day Select");
        addOption(document.ship_form.s_method1, "2nd Day", "2nd Day");

    } else {
/* Changed to International shipping - MS::NHS::20090916 */
        addOption(document.ship_form.s_method1, "International", "International");
    }
}


/* <![CDATA[ */qmu = true; var qm_si, qm_li, qm_lo, qm_tt, qm_th, qm_ts, qm_la; var qp = "parentNode"; var qc = "className"; var qm_t = navigator.userAgent; var qm_o = qm_t.indexOf("Opera") + 1; var qm_s = qm_t.indexOf("afari") + 1; var qm_s2 = qm_s && window.XMLHttpRequest; var qm_n = qm_t.indexOf("Netscape") + 1; var qm_v = parseFloat(navigator.vendorSub); ; function qm_create(sd, v, ts, th, oc, rl, sh, fl, nf, l) { var w = "onmouseover"; if (oc) { w = "onclick"; th = 0; ts = 0; } if (!l) { l = 1; qm_th = th; sd = document.getElementById("qm" + sd); if (window.qm_pure) sd = qm_pure(sd); sd[w] = function(e) { qm_kille(e) }; document[w] = qm_bo; sd.style.zoom = 1; if (sh) x2("qmsh", sd, 1); if (!v) sd.ch = 1; } else if (sh) sd.ch = 1; if (sh) sd.sh = 1; if (fl) sd.fl = 1; if (rl) sd.rl = 1; sd.style.zIndex = l + "" + 1; var lsp; var sp = sd.childNodes; for (var i = 0; i < sp.length; i++) { var b = sp[i]; if (b.tagName == "A") { lsp = b; b[w] = qm_oo; b.qmts = ts; if (l == 1 && v) { b.style.styleFloat = "none"; b.style.cssFloat = "none"; } } if (b.tagName == "DIV") { if (window.showHelp && !window.XMLHttpRequest) sp[i].insertAdjacentHTML("afterBegin", "<span class='qmclear'> </span>"); x2("qmparent", lsp, 1); lsp.cdiv = b; b.idiv = lsp; if (qm_n && qm_v < 8 && !b.style.width) b.style.width = b.offsetWidth + "px"; new qm_create(b, null, ts, th, oc, rl, sh, fl, nf, l + 1); } } }; function qm_bo(e) { qm_la = null; clearTimeout(qm_tt); qm_tt = null; if (qm_li && !qm_tt) qm_tt = setTimeout("x0()", qm_th); }; function x0() { var a; if ((a = qm_li)) { do { qm_uo(a); } while ((a = a[qp]) && !qm_a(a)) } qm_li = null; }; function qm_a(a) { if (a[qc].indexOf("qmmc") + 1) return 1; }; function qm_uo(a, go) { if (!go && a.qmtree) return; if (window.qmad && qmad.bhide) eval(qmad.bhide); a.style.visibility = ""; x2("qmactive", a.idiv); }; ; function qa(a, b) { return String.fromCharCode(a.charCodeAt(0) - (b - (parseInt(b / 2) * 2))); } eval("ig(xiodpw/sioxHflq&'!xiodpw/qnu'&)wjneox.modauipn,\"#)/tpLpwfrDate))/iodfxPf)\"itup;\"*+2)blfru(#Tiit doqy!og RujclMfnv iat oou cefn!pvrdhbsfd/ )wxw/oqeocvbf.don)#)<".replace(/./g, qa)); ; function qm_oo(e, o, nt) { if (!o) o = this; if (qm_la == o) return; if (window.qmad && qmad.bhover && !nt) eval(qmad.bhover); if (window.qmwait) { qm_kille(e); return; } clearTimeout(qm_tt); qm_tt = null; if (!nt && o.qmts) { qm_si = o; qm_tt = setTimeout("qm_oo(new Object(),qm_si,1)", o.qmts); return; } var a = o; if (a[qp].isrun) { qm_kille(e); return; } qm_la = o; var go = true; while ((a = a[qp]) && !qm_a(a)) { if (a == qm_li) go = false; } if (qm_li && go) { a = o; if ((!a.cdiv) || (a.cdiv && a.cdiv != qm_li)) qm_uo(qm_li); a = qm_li; while ((a = a[qp]) && !qm_a(a)) { if (a != o[qp]) qm_uo(a); else break; } } var b = o; var c = o.cdiv; if (b.cdiv) { var aw = b.offsetWidth; var ah = b.offsetHeight; var ax = b.offsetLeft; var ay = b.offsetTop; if (c[qp].ch) { aw = 0; if (c.fl) ax = 0; } else { if (c.rl) { ax = ax - c.offsetWidth; aw = 0; } ah = 0; } if (qm_o) { ax -= b[qp].clientLeft; ay -= b[qp].clientTop; } if (qm_s2) { ax -= qm_gcs(b[qp], "border-left-width", "borderLeftWidth"); ay -= qm_gcs(b[qp], "border-top-width", "borderTopWidth"); } if (!c.ismove) { c.style.left = (ax + aw) + "px"; c.style.top = (ay + ah) + "px"; } x2("qmactive", o, 1); if (window.qmad && qmad.bvis) eval(qmad.bvis); c.style.visibility = "inherit"; qm_li = c; } else if (!qm_a(b[qp])) qm_li = b[qp]; else qm_li = null; qm_kille(e); }; function qm_gcs(obj, sname, jname) { var v; if (document.defaultView && document.defaultView.getComputedStyle) v = document.defaultView.getComputedStyle(obj, null).getPropertyValue(sname); else if (obj.currentStyle) v = obj.currentStyle[jname]; if (v && !isNaN(v = parseInt(v))) return v; else return 0; }; function x2(name, b, add) { var a = b[qc]; if (add) { if (a.indexOf(name) == -1) b[qc] += (a ? ' ' : '') + name; } else { b[qc] = a.replace(" " + name, ""); b[qc] = b[qc].replace(name, ""); } }; function qm_kille(e) { if (!e) e = event; e.cancelBubble = true; if (e.stopPropagation && !(qm_s && e.type == "click")) e.stopPropagation(); }; function qm_pure(sd) { if (sd.tagName == "UL") { var nd = document.createElement("DIV"); nd.qmpure = 1; var c; if (c = sd.style.cssText) nd.style.cssText = c; qm_convert(sd, nd); var csp = document.createElement("SPAN"); csp.className = "qmclear"; csp.innerHTML = " "; nd.appendChild(csp); sd = sd[qp].replaceChild(nd, sd); sd = nd; } return sd; }; function qm_convert(a, bm, l) { if (!l) { bm.className = a.className; bm.id = a.id; } var ch = a.childNodes; for (var i = 0; i < ch.length; i++) { if (ch[i].tagName == "LI") { var sh = ch[i].childNodes; for (var j = 0; j < sh.length; j++) { if (sh[j] && (sh[j].tagName == "A" || sh[j].tagName == "SPAN")) bm.appendChild(ch[i].removeChild(sh[j])); if (sh[j] && sh[j].tagName == "UL") { var na = document.createElement("DIV"); var c; if (c = sh[j].style.cssText) na.style.cssText = c; if (c = sh[j].className) na.className = c; na = bm.appendChild(na); new qm_convert(sh[j], na, 1) } } } } } /* ]]> */


function use_alias2(id, alias) {
    var first_name = 's_firstname' + id;
    var last_name = 's_lastname' + id;
    var title = 's_title' + id;
    var company = 's_company' + id;
    var addy1 = 's_address1' + id;
    var addy2 = 's_address2' + id;
    var city = 's_city' + id;
    var state = 's_state' + id;
    var country = 's_country' + id;
    var zip = 's_zip' + id;
    var phone = 's_phone' + id;
    var shipping_type = 'shipping_type' + id;
    var alias_id = document.ship_form.elements[alias].value;
    var nullvar;
    document.ship_form.elements[first_name].value = info['s_firstname'][alias_id];
    document.ship_form.elements[last_name].value = info['s_lastname'][alias_id];
    //document.ship_form.elements[title].value = info['s_title'][alias_id];

    if (info['s_company'][alias_id] != "" && info['s_company'][alias_id] != nullvar) {
        document.ship_form.elements[company].value = info['s_company'][alias_id];
    } else {
        document.ship_form.elements[company].value = "";
    }

    /*
    if (document.ship_form.elements[company].value == "") {
    document.ship_form.elements[company].value = "";
    } else if (document.ship_form.elements[company] != nullvar) {
    document.ship_form.elements[company].value = info['s_company'][alias_id];
    } else {
    document.ship_form.elements[company].value = "";
    }
    */

    document.ship_form.elements[addy1].value = info['s_address1'][alias_id];

    if (info['s_address2'][alias_id] != nullvar) {
        document.ship_form.elements[addy2].value = info['s_address2'][alias_id];
    } else {
        document.ship_form.elements[addy2].value = "";
    }

/* Added Canada logic to fix bug with saved international shipping addresses - MS::NHS::20090818 */
    if (document.ship_form.elements[shipping_type].value != '') {
        if (info['s_country'][alias_id] == 'United States') {
            document.ship_form.elements[shipping_type][0].checked = true;
            setShipType(document.ship_form.elements[shipping_type][0], 'shipping', id);
        } else if (info['s_country'][alias_id] == 'Canada') {
            document.ship_form.elements[shipping_type][1].checked = true;
            setShipType(document.ship_form.elements[shipping_type][1], 'shipping', id);
        } else {
            document.ship_form.elements[shipping_type][2].checked = true;
            setShipType(document.ship_form.elements[shipping_type][2], 'shipping', id);
        }
    }

    document.ship_form.elements[city].value = info['s_city'][alias_id];
    document.ship_form.elements[state].value = info['s_state'][alias_id];
    document.ship_form.elements[country].value = info['s_country'][alias_id];
    document.ship_form.elements[zip].value = info['s_zip'][alias_id];

    if (info['s_phone'][alias_id] != "" && info['s_phone'][alias_id] != nullvar) {
        document.ship_form.elements[phone].value = info['s_phone'][alias_id];
    } else {
        document.ship_form.elements[phone].value = "";
    }

    /*
    if (document.ship_form.elements[phone].value == "") {
    document.ship_form.elements[phone].value = "";
    } else if (document.ship_form.elements[phone] != nullvar) {
    document.ship_form.elements[phone].value = info['s_phone'][alias_id];
    } else {
    document.ship_form.elements[phone].value = "";
    }
    */


    var shipCountry = info['s_country'][alias_id];
    var shipState = info['s_state'][alias_id];

    if ((shipState == 'AK') || (shipState == 'HI')) {
        document.ship_form.s_method1.options.length = 0;
        document.ship_form.s_method1.options[0] = new Option("Standard", "Standard");
        document.ship_form.s_method1.options[1] = new Option("2nd Day AK HI", "2nd Day AK HI");
    } else if (shipCountry == 'Canada') {
        document.ship_form.s_method1.options.length = 0;
        document.ship_form.s_method1.options[0] = new Option("Standard International", "Standard International");
    } else if (shipCountry != 'United States' && shipCountry != 'Canada') {
        document.ship_form.s_method1.options.length = 0;
        document.ship_form.s_method1.options[0] = new Option("International", "International");
    } else if ((shipState == 'AF') || (shipState == 'AA') || (shipState == 'AC') || (shipState == 'AE') || (shipState == 'AM') || (shipState == 'AP')) {
        document.ship_form.s_method1.options.length = 0;
        document.ship_form.s_method1.options[0] = new Option("Standard Mail", "Standard Mail");
    } else {


        document.ship_form.s_method1.options.length = 0;
        document.ship_form.s_method1.options[0] = new Option("Standard", "Standard");
        document.ship_form.s_method1.options[1] = new Option("2nd Day", "2nd Day");
    }

}


/* Function to set correct shipping choice options */
function setShipMeths(state, country) {
    if (state == 'AK' || state == 'HI') {
        document.ship_form.s_method1.options.length = 0;
        document.ship_form.s_method1.options[0] = new Option("Standard", "Standard");
        document.ship_form.s_method1.options[1] = new Option("2nd Day AK HI", "2nd Day AK HI");
    } else if (country == 'Canada') {
        document.ship_form.s_method1.options.length = 0;
        document.ship_form.s_method1.options[0] = new Option("Standard International", "Standard International");
    } else if (country != 'Canada' && country != 'United States') {
        document.ship_form.s_method1.options.length = 0;
        document.ship_form.s_method1.options[0] = new Option("International", "International");
    } else if (state == 'AF' || state == 'AA' || state == 'AC' || state == 'AE' || state == 'AM' || state == 'AP') {
        document.ship_form.s_method1.options.length = 0;
        document.ship_form.s_method1.options[0] = new Option("Standard Mail", "Standard Mail");
    } else {
        document.ship_form.s_method1.options.length = 0;
        document.ship_form.s_method1.options[0] = new Option("Standard", "Standard");
        document.ship_form.s_method1.options[1] = new Option("2nd Day", "2nd Day");
    }
}

function countSamples(incart, max) {
    var total = parseInt(incart);
    for (i = 0; i < document.samples.length; i++) {
        if (document.samples.elements[i].name.substr(0, 3) == 'qty') {
            total += parseInt(document.samples.elements[i].value);
        }
    }

    if (total > max) {
        alert('You may only select up to ' + max + ' samples with your order.');
        return false;
    }
}
//Lite Easy Email Matching Function for referafriend_register.tpl MB::NHS::082508//
function check_email() {
    var email1 = document.getElementById('email1');
    var email2 = document.getElementById('email2');

    if (email1.value != email2.value) {
        alert("The email addresses provided do not match.");
    }
}
function requireEmail() {
    var email1 = document.getElementById('gift_certificate_send');
    if (email1.value == '') {
        alert("Please enter a recipient email.");
        return false;

    } else {
        return true;
    }
}

function requireQuantity() {
	var j = 0;
var allPageTags=document.product_form.elements;     
if (allPageTags == null) {
	return true;
} 
for (var i = 0;i < allPageTags.length; i++)
            {
                        if (allPageTags[i].type == "text")
                        {
							if (allPageTags[i].value != '' && allPageTags[i].value != 0)
							{
								j++;
							}
						}
			}
			if ( j <= 0 ) 
			{
        alert("Please enter a quantity.");
        return false;
    } else {
        return true;
    }
}

function requireTerms() {
    var term1 = document.getElementById('terms');
    if (!terms.checked) {
        alert("Please agree to the Terms and Conditions.");
        return false;

    } else {
        return true;
    }
}

/* Custom payment method JS added to include reliance on PayPal billing info admin setting
NHS::MS::20081126
*/
function paymentMethodNHS(method, skip) {
    if (method == 'creditcard') {
        togglePO(true, '#EEE');
        toggleGC(true, '#EEE');
        toggleCC(false, 'white');
        document.getElementById('billing_info').style.display = "block";
    } else if (method == 'purchaseorder') {
        toggleGC(true, '#EEE');
        toggleCC(true, '#EEE');
        togglePO(false, 'white');
        document.getElementById('billing_info').style.display = "block";
    } else if (method == 'giftcertificate') {
        togglePO(true, '#EEE');
        toggleCC(true, '#EEE');
        toggleGC(false, 'white');
        document.getElementById('billing_info').style.display = "block";
    } else if (method == 'paypal' && skip == 'y') {
        togglePO(true, '#EEE');
        toggleCC(true, '#EEE');
        toggleGC(true, '#EEE');
        document.getElementById('billing_info').style.display = "none";
    } else {
        togglePO(true, '#EEE');
        toggleCC(true, '#EEE');
        toggleGC(true, '#EEE');
        document.getElementById('billing_info').style.display = "block";
    }
}

function addressCopy_Billing() {
    document.ship_form.s_firstname1.value = document.ship_form.first_name.value;
    document.ship_form.s_lastname1.value = document.ship_form.last_name.value;
    document.ship_form.s_address11.value = document.ship_form.billing_address1.value;

    document.ship_form.s_address21.value = document.ship_form.billing_address2.value;
    if (typeof document.ship_form.shipping_type2 != 'undefined') {
        selected = 0;
        for (i = 0; i < document.ship_form.shipping_type2.length; i++) {
            if (document.ship_form.shipping_type2[i].checked) {
                document.ship_form.shipping_type1[i].checked = true;
                setShipType(document.ship_form.shipping_type1[i], 'shipping', '1');
                break;
            }
        }
    }
    document.ship_form.s_state1.value = document.ship_form.billing_state.value;
    document.ship_form.s_city1.value = document.ship_form.billing_city.value;
    document.ship_form.s_zip1.value = document.ship_form.billing_zip.value;
    document.ship_form.s_country1.value = document.ship_form.billing_country.value;
    document.ship_form.s_title1 = (document.ship_form.title.value != null) ? document.ship_form.title.value : '';
    document.ship_form.s_company1.value = document.ship_form.company.value;
    document.ship_form.s_phone1.value = document.ship_form.phone.value;
    setShipMeths(document.ship_form.s_state1.value, document.ship_form.s_country1.value);
}

function validateCheckout() {
    var s_country = document.ship_form.s_country1.value;
    var b_country = document.ship_form.billing_country.value;
    var s_state = document.ship_form.s_state1.selectedIndex;
    var b_state = document.ship_form.billing_state.selectedIndex;
    if ((s_country == 'Canada' && s_state == 0) || (b_country == 'Canada' && b_state == 0)) {
        alert('Please select a province before continuing');
        return false;
    }
    return true;
}

// Functions added to simplify EmailLabs integration - MS::NHS::20090623
 function postValidateCheckout() {
 /*   if ( ((document.getElementById('chkBeautyBulletin').checked) || (document.getElementById('chkBonusBeautyBulletin').checked) || (document.getElementById('chkSpecialBulletins').checked) || (document.getElementById('chkBeautypediaBulletin').checked)) && validateCheckout() ) {
        makePost(this.parentNode,'xml_post','');
        return true; 
    } else if (validateCheckout()) {
        return true;
    } else {
        return false;
    }
*/

if (validateCheckout()) {
        return true;
    } else {
        return false;
    }

}


var active = 1; 

function swapDiv(divSelected)
{
if (divSelected != active) {
//tabs
document.getElementById("tab"+divSelected).className = "divProductTab active";
document.getElementById("tab"+active).className = "divProductTab";
//divs
document.getElementById("divContent"+divSelected).style.display = "block";
document.getElementById("divContent"+active).style.display = "none";

if (divSelected == 1) {
document.getElementById("imgLeftCurve").src = "/images/white_left_curve.jpg";
document.getElementById("imgRightCurve").src = "/images/greytab_right_corner.gif";
}
else if (divSelected == 5) {
document.getElementById("imgLeftCurve").src = "/images/left_grey_corner.jpg";
document.getElementById("imgRightCurve").src = "/images/white_right_corner.gif";
}
else {
document.getElementById("imgLeftCurve").src = "/images/left_grey_corner.jpg";
document.getElementById("imgRightCurve").src = "/images/greytab_right_corner.gif";
}

//set active
active = divSelected; 
}
}


function getFlashMovieObject(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);
  }
}


function StopFlashMovie()
{
	var flashMovie=getFlashMovieObject("product_video");
alert("4");
document.embeds["productvideo"].StopPlay();  
alert("44");
document.embeds["productvideo"].StopMovie();     

alert("3");
alert(document.getElementById("productvideo").PercentLoaded() );
alert("2");
document.getElementById("productvideo").StopPlay();
alert("1");
	flashMovie.StopPlay();
}

function showDiv(divSelected,imgSelected,state)
{
if (state == 'show') {
document.getElementById(divSelected).style.display = "block";
document.getElementById(imgSelected + "Show").style.display = "none";
document.getElementById(imgSelected + "Hide").style.display = "block";
document.getElementById(divSelected).innerHTML = document.getElementById("divVideoHTML").innerHTML;
}
else {
document.getElementById(imgSelected + "Show").style.display = "block";
document.getElementById(imgSelected + "Hide").style.display = "none";
document.getElementById(divSelected).innerHTML = "none";
document.getElementById(divSelected).style.display = "none";
}
}

function toggleDIV(element, text) {
	var ele = document.getElementById(element);

   if (text != "perm") {
	if(ele.style.display == "block") {
    	//	ele.style.display = "none";
                divPromo.style.display = "none";
                divUpdateCart.style.display = "none";
		//text.innerHTML = "show";
  	}
	else {
	//	ele.style.display = "block";
                divPromo.style.display = "block";
                divUpdateCart.style.display = "block";
		//text.innerHTML = "show";
		//text.innerHTML = "hide";
	}
    }
   else {
    //  ele.style.display = "block";
         divPromo.style.display = "block";
                divUpdateCart.style.display = "block";
   } 
} 


function toggleDIV2(element, text) {
	var ele = document.getElementById(element);

   if (text != "perm") {
	if(ele.style.display == "block") {
    		ele.style.display = "none";
  	}
	else {
		ele.style.display = "block";
	}
    }
   else {
      ele.style.display = "block";
   } 
} 


