﻿// ------------------------------------------------------------------------------------------
// Copyright AspDotNetStorefront.com, 1995-2010.  All Rights Reserved.
// http://www.aspdotnetstorefront.com
// For details on this license please visit  the product homepage at the URL above.
// THE ABOVE NOTICE MUST REMAIN INTACT.
// ------------------------------------------------------------------------------------------
function $bindMethod(object, method) {
  return function() {
    return method.apply(object, arguments);
  };
}

function $window_addLoad(handler) {
    if (window.addEventListener) { 
        window.addEventListener('load',handler,false);
    }
    else if (document.addEventListener) {
        document.addEventListener('load',handler,false);
    }
    else if (window.attachEvent) { 
        window.attachEvent('onload',handler);
    }
    else {
        if (typeof window.onload=='function') {
            var oldload=window.onload;
            window.onload = function(){
                oldload();
                handler();
            }
        } 
        else { window.onload=init; }
    }

}

function $getElement(id, handler) {
    var el = document.getElementById(id);
    return el;
}

var Keys = {
    Enter: 13
}

function $handleSearchEnterKey(id, handler) {
    var el = $getElement(id);    
    if(el) {
        var delKeypress = function(e) {

            var keyCode;
            if (e && e.which) {
                keyCode = e.which;
            }
            else if (typeof (event) != 'undefined') {
                keyCode = event.keyCode;
            }

            // we must manually invoke the Page_ClientValidate
            // method here since relying on the normal behavior
            // is not guaranteed to set the appropriate validation flags
            // to stop the postback.
            if (keyCode == Keys.Enter) {
                if (typeof (Page_ClientValidate) != 'undefined') {
                    if (Page_ClientValidate() == false) {
                        return;
                    }
                }

                handler();

                return false;
            }
        }
        
        el.onkeypress = delKeypress;
    }

}


/** Img rollover function. **/
function rollover(name, source) {
    document.images[name].src = source;
}

/** Preload image function: takes an array of img srouces. **/
function preload(aImgSrc) {
    for (var i = 0; i < aImgSrc.length; i++) {
        var newImg = new Image();
        newImg.src = aImgSrc[i];
        aImgSrc["img_" + i] = newImg;
    }
}

// openMe creates a window with a set name, location, and size
function openBook4Time(winURL) {
    var width = 817;
    var height = 697;
    var winName = "book4time";

    //only launch window if we've set a width and height
    if (width > 0 && height > 0) {
        launchWin(winName, winURL, width, height);
    }
}

function launchWin(winName, winURL, width, height) {
    var ieIncrement = ((navigator.appName + "").indexOf("Netscape") == -1) ? 15 : 0;
    eval(winName + "=window.open('" + winURL + "','" + winName + "','resizable=yes,scrollbars=yes,width=" + (width + ieIncrement) + ",height=" + (height + ieIncrement) + ",top=5,left=75')");
    eval("window." + winName + ".focus()");
}

function checkKeyword(keyword, defaultText) {
    var minKeywordLength = 0;
    var maxKeywordLength = 0;
    minKeywordLength += 3;
    maxKeywordLength += 30;
    var errMsg = '';
    //alert("minKeywordLength " + minKeywordLength);
    var searchTerms = '';
    searchTerms = keyword.value;
    //alert("searchTerms.length " + searchTerms.length);

    var invalidSearchTermMessage = 'Invalid characters found.'; // probably want to change this message! 
    var invalidChars = /[<>'"%;|^]/; // add all illegal characters here. 
    var matches_array = searchTerms.match(invalidChars);
    if (matches_array != null && matches_array.length > 0) {
        // show the user a dialog if '<' or '>' or '!' are found in the keyword. 
        alert(invalidSearchTermMessage);
        return false;
    }


    var noSearchTerm = 'Please enter a keyword or item number';
    var shortSearchTerm = 'Your keyword or item number must be at least 3 characters long';

    if (searchTerms == defaultText) {
        alert(noSearchTerm);
        return false;
    }
    if (searchTerms == '') {
        alert(noSearchTerm);
        return false;
    } else if (searchTerms.length < minKeywordLength) {
        alert(shortSearchTerm);
        return false;
    } else {
        return true;
    }
}

function newsletterFormSubmit() {
    var eEmail = document.getElementById('emailaddress').value;
    var cURL = document.location.href
    if (cURL.indexOf('uk')>0) {
        var eURL = '/subscribe.aspx?a=topsub&Sub=' + eEmail;
    }else {
        var eURL = '/subscribe.aspx?a=topsub&Sub=' + eEmail;
    }
    document.location.href = eURL;
    return false;
}

//added for cart color/size options
function addOption(selectbox, text, value) {
    var optn = document.createElement("OPTION");
    optn.text = text;
    optn.value = value;
    selectbox.options.add(optn);
}


var aCatImgs = new Array();

aCatImgs[aCatImgs.length] = "/App_Themes/skin_1/images/topnavspa_off.gif";
aCatImgs[aCatImgs.length] = "/App_Themes/skin_1/images/topnavspa_on.gif";

aCatImgs[aCatImgs.length] = "/App_Themes/skin_1/images/topnavskincare_off.gif";
aCatImgs[aCatImgs.length] = "/App_Themes/skin_1/images/topnavskincare_on.gif";

aCatImgs[aCatImgs.length] = "/App_Themes/skin_1/images/topnavantiaging_off.gif";
aCatImgs[aCatImgs.length] = "/App_Themes/skin_1/images/topnavantiaging_on.gif";

aCatImgs[aCatImgs.length] = "/App_Themes/skin_1/images/topnavbathbody_off.gif";
aCatImgs[aCatImgs.length] = "/App_Themes/skin_1/images/topnavbathbody_on.gif";

aCatImgs[aCatImgs.length] = "/App_Themes/skin_1/images/topnavcellulite_off.gif";
aCatImgs[aCatImgs.length] = "/App_Themes/skin_1/images/topnavcellulite_on.gif";

aCatImgs[aCatImgs.length] = "/App_Themes/skin_1/images/topnavfootwear_off.gif";
aCatImgs[aCatImgs.length] = "/App_Themes/skin_1/images/topnavfootwear_on.gif";

aCatImgs[aCatImgs.length] = "/App_Themes/skin_1/images/topnavshapewear_off.gif";
aCatImgs[aCatImgs.length] = "/App_Themes/skin_1/images/topnavshapewear_on.gif";

aCatImgs[aCatImgs.length] = "/App_Themes/skin_1/images/topnavbeauty_off.gif";
aCatImgs[aCatImgs.length] = "/App_Themes/skin_1/images/topnavbeauty_on.gif";

aCatImgs[aCatImgs.length] = "/App_Themes/skin_1/images/topnavremede_off.gif";
aCatImgs[aCatImgs.length] = "/App_Themes/skin_1/images/topnavremede_on.gif";

aCatImgs[aCatImgs.length] = "/App_Themes/skin_1/images/topnavgifts_off.gif";
aCatImgs[aCatImgs.length] = "/App_Themes/skin_1/images/topnavgifts_on.gif";

aCatImgs[aCatImgs.length] = "/App_Themes/skin_1/images/topnavbrands_off.gif";
aCatImgs[aCatImgs.length] = "/App_Themes/skin_1/images/topnavbrands_on.gif";

preload(aCatImgs);




