//Generic Overlay
var overlay;
var overlayready;

function resetSwf(){
    
        if (document.all){
            iWidth = document.documentElement.clientWidth;
            iHeight= document.documentElement.clientHeight;
        }
        else if (document.layers){
            iWidth = window.innerWidth;
            iHeight= window.innerHeight;
        }
        else if (document.getElementById){
            iHeight= window.innerHeight;
            if ((iHeight-100) < 450){
                iWidth = (window.innerWidth - 17);
            } else {
                iWidth = window.innerWidth;
            }
            
        }
        iHeight = iHeight - 200;
        
        if (iWidth > 960){
            getStyleObject("feature").width = iWidth + "px";
            getStyleObject("feature").height = iHeight + "px";
            getStyleObject("masterFlash").width = iWidth + "px";
        } else {
            getStyleObject("feature").width = 960 + "px";
            getStyleObject("feature").height = iHeight + "px";
            getStyleObject("masterFlash").width = 960 + "px";
        }
        
        }
function getStyleObject(objectId) {
    if(document.getElementById && document.getElementById(objectId)) {
    return document.getElementById(objectId).style;
    } else if (document.all && document.all(objectId)) {
    return document.all(objectId).style;
    } else if (document.layers && document.layers[objectId]) {
    return document.layers[objectId];
    } else {
    return false;
    }
}          

function toggleProductBorder(productId, on) {
    if($ && on) {
        $('productTitle_' + productId).className='productTitleOver';
        $('productImage_' + productId).className='productImageOver'
    }
    else if($) {
        $('productTitle_' + productId).className='productTitle';
        $('productImage_' + productId).className='productImage';
    }
}

function openRadio(url) {
    window.open(url, 'radio','location=0,status=0,scrollbars=0,resizable=0,toolbar=0,menubar=0,width=270,height=53')
}

function ajaxSubmit(frmId) {
    var frm = $(frmId);
    
    var ajaxOptions = {
        'method': 'post',
        'onSuccess': function(responseText) {throwError(responseText)},
        'onFailure': function(responseText) {throwError(responseText)}
    };
    
    var ajaxRequest = new Ajax(frm.getProperty('action'), ajaxOptions);    
    ajaxRequest.request(frm.toDataObject());
}

function validateProductSend() {
    var error = "";
    var yourName = $("txtYourName").value;
    var yourEmail = $("txtYourEmail").value;
    var recipient1 = $("txtEmail1").value;
    var recipient2 = $("txtEmail2").value;
    var recipient3 = $("txtEmail3").value;
    var reEmail = /^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i
    
    if(yourName == "") error = "Your name is required!";
    else if(yourEmail == "") error = "Your e-mail is required!";
    else if(!reEmail.test(yourEmail)) error = "Please enter your valid e-mail address!";
    else if(recipient1 == "") error = "At least one recipient is required!";
    else if(!reEmail.test(recipient1)) error = "Please enter your valid e-mail address";
    else if(recipient2 != "" && !reEmail.test(recipient2)) error = "Please enter your valid e-mail address for the second recipient!";
    else if(recipient3 != "" && !reEmail.test(recipient3)) error = "Please enter your valid e-mail address for the third recipient!";
    
    if(error == "") {
        var frm = $("sendProductForm");
    
        var ajaxOptions = {
            'method': 'post',
            'onSuccess': function(responseText) {toggleProductSend();throwError(responseText);},
            'onFailure': function(responseText) {throwError(responseText)}
        };
        
        var ajaxRequest = new Ajax(frm.getProperty('action'), ajaxOptions);    
        ajaxRequest.request(frm.toDataObject());
    }
    else throwError(error);
}

function toggleProductSend() {
    if($("productEmail").getStyle('display') == 'none') {
        $("productInfo").setStyle('display', 'none');
        $("productEmail").setStyle('display', '');
    }
    else { 
        $("productInfo").setStyle('display', '');
        $("productEmail").setStyle('display', 'none');
    }
    
    $$('.errorZone').each(function(el) {el.setHTML("");el.setStyle('display','none');});
    $$('.messagingZone').each(function(el) {el.setHTML("");});
}
            
function showWishlistComment() {
    $('wishlistCommentOption').setStyle('display', 'none');
    $('wishlistComment').setStyle('display', '');
}

function wishlistAdd(productId) {
    Wishlist.add(productId);
    $('wishlistCommentOption').setStyle('display', '');
    $('wishlistAddButton').setStyle('display', 'none');
    $('wishlistGoButton').setStyle('display', '');
    $$('.messagingZone').each(function(el) {el.setHTML("This item has been added to your wishlist!");});
}

function wishlistAddComment(productId, comment) {
    if(comment == "") {
        Wishlist.removeComment(productId);
        $('wishlist_comment_view').setHTML("");
        $('wishlistCommentView').setStyle('display', 'none');
        $('wishlistComment').setStyle('display', 'none');
        $('wishlistCommentOption').setStyle('display', '');
        $$('.messagingZone').each(function(el) {el.setHTML("");});
    }
    else {
        Wishlist.addComment(productId, comment);
        $('wishlistComment').setStyle('display', 'none');
        $('wishlistAddButton').setStyle('display', 'none');
        $('wishlistGoButton').setStyle('display', '');
        $('wishlistCommentView').setStyle('display', '');
        $('wishlist_comment_view').setHTML(Wishlist.getComment(productId));
        $$('.messagingZone').each(function(el) {el.setHTML("This comment has been added to your wishlist!");});
    }
}

function wishlistSetEditComment(productId) {
    $('wishlist_comment').value = Wishlist.getComment(productId);
    $('wishlistComment').setStyle('display', '');
    $('wishlistCommentView').setStyle('display', 'none');
}

function wishlistEditComment(productId, comment) {
    if(comment == "") Wishlist.removeComment(productId);
    else Wishlist.addComment(productId, comment);
    $$('.messagingZone').each(function(el) {el.setHTML("This comment has been updated in your wishlist!");});
}

function wishlistCancelComment(productId) {
    $('wishlistComment').setStyle('display', 'none');
    if(Wishlist.check(productId)) {
        $('wishlistGoButton').setStyle('display', '');  
        $('wishlistAddButton').setStyle('display', 'none');                
        if(Wishlist.getComment(productId)) $('wishlistCommentView').setStyle('display', '');
        else $('wishlistCommentOption').setStyle('display', '');
    }
    else {
        $('wishlistAddButton').setStyle('display', '');                    
        $('wishlistGoButton').setStyle('display', 'none'); 
    } 
}


/* WISH LIST FUNCTIONS */
function wishlistOverlayAddComment(productId, comment) {
    if(comment == "") {
        Wishlist.removeComment(productId);        
        $('wishlist_comment_view_' + productId).setHTML("");
    }
    else {
        Wishlist.addComment(productId, comment);
        $('wishlist_comment_view_' + productId).setHTML(Wishlist.getComment(productId));
    }
    
    $('wishlistComment_' + productId).setStyle('display', 'none');
    $('wishlistCommentView_' + productId).setStyle('display', '');
}

function wishlistOverlaySetEditComment(productId) {
    $('wishlist_comment_' + productId).value = (Wishlist.getComment(productId))? Wishlist.getComment(productId) : '';
    $('wishlistComment_' + productId).setStyle('display', '');
    $('wishlistCommentView_' + productId).setStyle('display', 'none');
}

function wishlistOverlayCancelComment(productId) {
    $('wishlistComment_' + productId).setStyle('display', 'none');
    if(Wishlist.check(productId)) {
        if(Wishlist.getComment(productId)) $('wishlistCommentView_' + productId).setStyle('display', '');
    }
}

function toggleEmailContainer() {
    var display = $('sendWishListContainer').getStyle('display');
    if(display == "none"){
        $('sendWishListContainer').setStyle('display', 'block');
    } else {
        $('sendWishListContainer').setStyle('display', 'none');
    }
}

function clearInput(id) {
    $(id).value = "";

}

function checkWishList() {
    var wishList = Wishlist.get();
    if(wishList != null && wishList != false && wishList != "") {
        overlay.open('/overlays/wishlist.jsp?productids=' + Wishlist.get())
    }else{
        overlay.open('/overlays/wishlist_empty.jsp')
   }
}

function clearWishList() {
    Wishlist.clear();
    $("wishLeftContainer").setStyle('display','none');
    $("noItemsWishList").setStyle('display','block');
    $("printBtn").setStyle('display','none');
    $("emailBtn").setStyle('display','none');
    $("clearBtn").setStyle('display','none');
}

function wishlistRemove(productId) {
    if(Wishlist.count()==1) {
        clearWishList();
    }
    else {
        Wishlist.remove(productId);
        overlay.close();
        overlay.open('/overlays/wishlist.jsp?productids=' + Wishlist.get());
    }
}

function validateEmailSignup() {
    var error = "";
    var email = $("txtEmail").value;
    var reEmail = /^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i
     
    if(email == "") error = "E-mail is a required!";
    else if(!reEmail.test(email)) error = "Please enter a valid e-mail address";
    else if(email != $("txtEmailConfirm").value) error = "Your e-mail addresses don't match!";
    
    if(error == "") ajaxSubmit("frmEmailSignup");
    else throwError(error);
}


function validateWishlistSend() {
    var error = "";
    var email = $("txtEmailAddress").value;
    var reEmail = /^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i
     
    if(email == "") error = "E-mail is a required!";
    else if(!reEmail.test(email)) error = "Please enter a valid e-mail address";
    
    if(error == "") ajaxSubmit("sendWishListForm");
    else throwError(error);
}


function throwError(error) {
    $$(".errorZone").each(function(el) {
        el.setHTML(error);
        el.setStyle('display', '');
    });
}

function findStores(frmId) {
    var frm = $(frmId);
    
    var ajaxOptions = {
        'method': 'post',
        'onSuccess': function(responseText) {
            $('overlay_content').setStyle('height','575px');
            $("storeResults").setHTML(responseText);
        },
        'onFailure': function(responseText) {$("storeResults").setHTML(responseText)}
    };
    
    var ajaxRequest = new Ajax(frm.action, ajaxOptions);    
    ajaxRequest.request(frm.toDataObject());
}

function openPrintWindow(url, width, height) {
    if(width == undefined) width = 600;
    if(height == undefined) height = 400;
    window.open(url, "express_print","location=0,status=0,scrollbars=0,width="+width+",height="+height);
}

function validateFormFields(pageid) {
    var page_id = pageid;
    if(document.getElementById('setState').value != "" || ( document.getElementById('txtZipCode').value != ""))
    {
        $('errorBox').setStyle('display','none');
        findStores('frmStoreLocator');
    }
    else
    {
        if (page_id != 'wishlist'){
            $('overlay_content').setStyle('height','410px');
        }
        $('errorBox').setStyle('display','block');
        $('errorBox').setHTML('Please select a State or enter a Zip Code to search for<br/>Express Stores near you.');
    }
}

/*
Script: Element.Form.js
    Contains Element prototypes to deal with Forms and their elements.

License:
    MIT-style license.
*/

/*
Class: Element
    Custom class to allow all of its methods to be used with any DOM element via the dollar function <$>.
*/

Element.extend({

    /*
    Property: toDataObject
        Reads the children inputs of the Element and generates a data object, based on their values. Used internally in <Ajax>
    
    Example:
        (start code)
        new Ajax('test.htm').request($('myForm').toDataObject());
        (end)
    */

    toDataObject: function(){
        var vals = {};
        this.getFormElements().each(function(el){
            var name = el.name;
            var val  = el.getValue();
            if (val === false || !name || el.disabled) return;
            if ($chk(vals[name])&&this.type=='checkbox') vals[name] = [vals[name]];
            if ($type(vals[name])=='array') vals[name].push(val);
            else vals[name] = val;
        });
        return(vals);
    }

});


/**
 * Loader
 *      An extention to the Ajax class that allows for better parsing of the
 *      Response Text.
 * 
 * @usage
 *      var myLoader = new Loader(url, formId, {'options': 'options'});
 *
 * @todo
 *      Styles handling.
 *      More diverse response object.
 *
 * @example
 *      new Loader('test.htm', {onLoad: function(response) {alert(response.title);}});
 *
 * @author Josh Zeigler <jzeigler@resource.com>
 * @author Toby Miller <tmiller@resource.com>
 */

var Loader = Ajax.extend({
    /**
     * defaultOptions
     * Options used in typical implementations
     *
     * method:      get or post
     * applyStyles: true or false
     * onLoad:      callback
     * runScripts:  automatically run scripts before onLoad
     * applyStypes: automatically apply styles before onLoad
     */
    defaultOptions: {
        'method': 'get',
        'applyStyles': true,
        'onLoad': Class.empty,
        'runScripts': false,
        'applyStyles': true
    },
    
    /**
     * regexp
     * Regular expressions used for parsing
     *
     * html:        strips off the html tags
     * title:       extracts the page title
     * body:        extracts the body
     * onload:      extracts the onload calls from the body tag
     * scripts:     extracts all of the inline script blocks
     * extScripts:  extracts all of the external script blocks
     * styles:      extracts all of the inline style blocks
     * extStyles:   extracts all of the external stylesheets
     */
    regexp: {
        'title':        /\<title[^\>]*\>([\s\S]*?)\<\/title\>/i,
        'body':         /\<body[^\>]*\>([\s\S]*?)\<\/body\>/i,
        'onload':       /\<body[^\>]+onload=\"([^\"]+)\"[^\>]*\>/i,
        'scripts':      /\<script([^\>]*)\>([\s\S]*?)\<\/script\>/i,
        'scriptSrc':    /src=\"([^\"]+)\"/i,
        'scriptType':   /type=\"([^\"]+)\"/i,
        'styles':       /\<style([^\>]*)\>([\s\S]*?)\<\/style\>/i,
        'links':        /\<link([^\>]*)\>/i,
        'cssRel':       /rel=\"([^\"]+)\"/i,
        'cssType':      /type=\"([^\"]+)\"/i,
        'cssMedia':     /media=\"([^\"]+)\"/i,
        'cssHref':      /href=\"([^\"]+)\"/i
    },
    //"
    /**
     * initialize
     * Initialize an instance of the Loader object
     *
     * @param string url
     * @param mixed array or object representation of options
     * @return void
     */
    initialize: function(url, options) {
        this.setOptions($merge(this.defaultOptions, options));
        //if ($defined(this.options.data)) this.data = this.options.data;
        this.parsed = {
            'text':     null,
            'xml':      null,
            'title':    null,
            'body':     null,
            'onload':   null,
            'scripts':  [],
            'styles':   []
        };
        this.parent(url, {'onComplete': this.parseResponse.bind(this)});
    },
    
    /**
     * parseRespone
     * Parse the returned response
     *
     * @param string response text
     * @param string response xml
     * @return void
     */
    parseResponse: function(responseText, responseXML) {
        this.parsed.text = responseText;
        this.parsed.xml = responseXML;
        
        while (this.regexp.scripts.test(responseText)) {
            var scripts = this.regexp.scripts.exec(responseText);
            if (scripts.length > 0) {
                this.parsed.scripts.push({
                    'type': (type = this.regexp.scriptType.exec(scripts[1])) ? type[1] : null,
                    'src':  (src = this.regexp.scriptSrc.exec(scripts[1])) ? src[1] : null,
                    'code': scripts[2]
                });
            }
            responseText = responseText.replace(this.regexp.scripts, '');
        }

        while (this.regexp.links.test(responseText)) {
            var links = this.regexp.links.exec(responseText);
            if (links.length > 0) {
                this.parsed.styles.push({
                    'rel':      (rel = this.regexp.cssRel.exec(links[1])) ? rel[1] : null,
                    'type':     (type = this.regexp.cssType.exec(links[1])) ? type[1] : null,
                    'media':    (media = this.regexp.cssMedia.exec(links[1])) ? media[1] : null,
                    'href':     (href = this.regexp.cssHref.exec(links[1])) ? href[1] : null,
                    'code':     links[2]
                });
            }
            responseText = responseText.replace(this.regexp.links, '');
        }
        
        while (this.regexp.styles.test(responseText)) {
            var styles = this.regexp.styles.exec(responseText);
            if (styles.length > 0) {
                this.parsed.styles.push({
                    'type':     (type = this.regexp.cssType.exec(styles[1])) ? type[1] : null,
                    'media':    (media = this.regexp.cssMedia.exec(styles[1])) ? media[1] : null,
                    'href':     (href = this.regexp.cssHref.exec(styles[1])) ? href[1] : null,
                    'code':     styles[2]
                });
            }
            responseText = responseText.replace(this.regexp.styles, '');
        }
        
        if(this.regexp.title.test(responseText)) this.parsed.title = this.regexp.title.exec(responseText)[1];
        if(this.regexp.onload.test(responseText)) this.parsed.onload = this.regexp.onload.exec(responseText)[1];
        if(this.regexp.body.test(responseText)) this.parsed.body = this.regexp.body.exec(responseText)[1];
        
        if(this.options.applyStyles) this.applyStyles();
        this.prepareScripts();
    },
    
    prepareScripts: function() {
        var completed = function(idx) {
             {
                if(this.options.runScripts) this.executeScripts();
                this.fireEvent('onLoad', this.parsed);
            }
        }.bind(this);
        
        var getRemoteScript = function(src, idx) {                
            var onComplete = function(responseText) {
                this.parsed.scripts[idx].code = responseText;
                if(i+1 == this.parsed.scripts.length) completed();
            }.bind(this);
            
            new Ajax(src, {
                'method':       'get',
                'onComplete':    onComplete
            }).request();
        }.bind(this);

        if(this.parsed.scripts.length > 0) {
            for(var i=0; i < this.parsed.scripts.length; i++) {
                if(this.parsed.scripts[i].src) {
                    getRemoteScript(this.parsed.scripts[i].src, i);
                }
                else if(i+1 == this.parsed.scripts.length) completed();
            }
        }
        else completed();
    },
    
    executeScripts: function() {
        if(this.parsed.scripts) {
            var scripts = "";
            for(var i = 0; i < this.parsed.scripts.length; i++) {
                if(this.parsed.scripts[i].code) scripts = scripts + this.parsed.scripts[i].code;
            }
            eval(scripts);
        }
    },
    
    applyStyles: function() {
        if(this.parsed.styles) {
            this.parsed.styles.each(function(links) {
                if(links.href && links.type.toLowerCase() == "text/css") new Asset.css(links.href);
            });
            
            var styles = "";
            for(var i = 0; i < this.parsed.styles.length; i++) {
                if(this.parsed.styles[i].code) styles = styles + this.parsed.styles[i].code;
            }
            var stylesheet = new Element('style', {type:'text/css'}).injectInside(document.head);
            if(!!window.ie) document.styleSheets[document.styleSheets.length-1].cssText = styles;
            else stylesheet.appendText(styles);
        }
    },
    
    load: function() {
        this.request(this.data);
    }
});

Loader.implement(new Events, new Options);


var Overlay = new Class({
    options: {
        'executeScripts':       true,       // Option to evaluate scripts in the response text
        'ajaxMethod':           'get',      // Option to evaluate the whole response text
        'status':               'closed',   // Status of ModalWindow (open, recycling or closed)
        'defaultWidth':         400,
        'defaultHeight':        500
    },
    
    initialize: function(templateUrl, options) {
        this.setOptions(options);
        this.template = {'url': templateUrl, 'base': null, 'title': null, 'properties': null};
        this.eventKeyDown = this.closeKeyListener.bindWithEvent(this);
        this.eventPosition = this.setCover.bind(this);
        this.getTemplate();
        this.overlayMargin = 0;
    },
    
    buildTemplate: function(response) {
        this.template.base = response.body;
        this.template.title = response.title;
        var properties = {};
        for(var i = 0; i < response.scripts.length; i++) {
            if(response.scripts[i].type.toLowerCase() == "text/properties") {
                properties = response.scripts[i].code;
                break;
            }
        }
        this.template.properties = eval("(" + properties + ")");
        this.overlay = new Element('div', {'id': 'overlay' + new Date().getTime().toString()}).setStyles({'position': 'absolute', 'zIndex': '1001', 'left': '50%', 'display': 'none'});
        
        this.overlay.setHTML(this.template.base);
        
        this.templateHeight = this.overlay.offsetHeight;
        if(this.template.properties.options.overlayMargin) this.overlayMargin = this.template.properties.options.overlayMargin;
        
        this.buildCover(); 
    },
    
    buildCover: function() {
        var coverProps = this.template.properties.cover;
        if(coverProps.enabled) {
            var coverId = "cover" + new Date().getTime().toString();
            this.cover = new Element('div', {'id': coverId});
            this.cover.setStyles({'position': 'absolute', 'width': '100%', 'left': '0', 'display': 'none', 'zIndex': '1000'});
            if(coverProps.background) this.cover.setStyle('background-color', coverProps.background);
            if(coverProps.opacity) this.cover.setStyle('opacity', coverProps.opacity);            
            if(coverProps.close) {this.cover.addEvent('click', this.close.bind(this)); this.cover.setStyle('cursor', 'pointer');} 
            this.cover.injectInside(document.body);
        }
        overlayready = true;
    },
    
    displayContent: function(response) {
        if(this.template.properties.options.loadingClass) $(this.template.properties.zones.content).removeClass(this.template.properties.options.loadingClass);
        if(this.template.properties.zones.title && response.title) $(this.template.properties.zones.title).setHTML(response.title);
        if(response.body) $(this.template.properties.zones.content).setHTML(response.body);
        if(this.template.properties.options.autoHeight) {
            var maxHeight = (Window.getHeight() - (this.overlayMargin*2) - this.templateHeight);
            if((this.overlay.offsetHeight > maxHeight) && (maxHeight > 0)) {$(this.template.properties.zones.content).setStyle('height', maxHeight + 'px');}
        }
        if(this.options.executeScripts && response.scripts) {this.contentLoader.executeScripts();}
    },
    
    getTemplate: function() {
        var buildTemplate = this.buildTemplate.bind(this);
        this.templateLoader = new Loader(this.template.url, {onLoad: buildTemplate});
        this.templateLoader.load();
    },
    
    getContent: function(url, formid) {
        var displayContent = this.displayContent.bind(this);
        this.contentLoader = new Loader(url, {onLoad: displayContent});
        this.contentLoader.load();
    },
    
    setCover: function() {
        this.cover.setStyles({'display': '', 'top': Window.getScrollTop() + 'px', 'height': Window.getHeight() + 'px'});
    },
    
    setButtons: function() {
        var closers = this.template.properties.buttons.close;
        if(closers != null) {
            for(var i=0; i < closers.length; i++) {
                $(closers[i]).setStyle('cursor', 'pointer');
                $(closers[i]).addEvent('click', this.close.bind(this));
            }
        }
    },
    
    open: function(url, formid, width, height) {
        if(this.template.properties.cover && this.template.properties.cover.enabled) this.setCover();
        this.top = Window.getScrollTop() + this.overlayMargin;
        
        this.overlay.injectInside(document.body);
        if(this.options.status == "closed") this.overlay.injectInside(document.body);//this.template.properties.transitions.open();
        else if(this.options.status == "open") this.template.properties.transitions.recycle();

        if(!width && !height) {
            var page = url.substring(url.indexOf("/overlays/")+10,url.indexOf(".jsp")+4);

            if(overlaySizes[page]) {
                width = overlaySizes[page].width;
                height = overlaySizes[page].height;
            }
            else {
                width = this.options.defaultWidth;
                height = this.options.defaultHeight;
            }
        }
        
        if(width) {
            this.overlay.setStyles({'width': width + 'px', 'marginLeft': '-' + (width / 2) + 'px'});
            $("overlay_titlebar").setStyle('width', (width-65)+'px');
        }
  
        if(height) $(this.template.properties.zones.content).setStyle('height', height + 'px');
        if(this.template.properties.options.loadingClass) $(this.template.properties.zones.content).addClass(this.template.properties.options.loadingClass);
        this.overlay.setStyles({'display': '', 'top': this.top + 'px'});
        
        document.addEvent('keydown', this.eventKeyDown);
        window.addEvent('scroll', this.eventPosition).addEvent('resize', this.eventPosition);
        
        if(this.template.properties.buttons) this.setButtons();
        
        this.options.status == "open";
        this.getContent(url, formid);
    },    
    
    closeKeyListener: function(event) {
        // close the ModalWindow when the user presses CTRL + W, CTRL + X, ESC
        if((event.control && event.key == "w") || (event.control && event.key == "x") || (event.key == "esc")) {
            this.close();
            event.stop();
        }
    },
    
    close: function() {
        if(this.template.properties.transitions && this.template.properties.transitions.close) {
        }
        else {
            this.overlay.setStyle('display', 'none');
            this.cover.setStyle('display', 'none');
        }
        document.removeEvent('keydown', this.eventKeyDown);
        window.removeEvent('scroll', this.eventPosition).removeEvent('resize', this.eventPosition);
        
        if(this.template.properties.zones.title) $(this.template.properties.zones.title).setHTML("");
        $(this.template.properties.zones.content).setHTML("");
        this.options.status = "closed";
    }
});

Overlay.implement(new Events, new Options);

/**
 * Preload all mouseover images on the page and define a mouseover and mouseout
 * event for those images. All that is required is that the image has a class
 * name consisting of mouseover_* with the * being the rollover key to
 * apply to the mouseover image.
 *
 * i.e. look at the following examples to see how the class name is parsed
 *      <img class="mouseover_r" src="myimage.gif" alt=""/>
 *      out image = myimage.gif
 *      over image = myimage_r.gif
 *
 * @important! this function must be called by the onload event
 *
 * @param image(id string) - id of element to apply mouseover functionality.
 *      if undefined, the script will check and apply to all img elements.
 * @return void
 *
 * @author Toby Miller <tmiller@resource.com>
 * @author Josh Zeigler <jzeigler@resource.com>
*/

function mouseover(image)
{
    // set internal vars
    var extlist = ['gif', 'jpg', 'jpeg'];
    var ext = null;
    var re = null;
    var klass = null;
    var key = null;
    var src = null;
    var oversrc = null;
    

    var init = function(el) {
        // get image source and class name
        src = el.src;
        klass = el.className;

        if (klass.contains('mouseover_')) {
            // strip out additional classes (if they exist)
            re = new RegExp('.*(mouseover_[a-zA-Z0-9-]+).*');
            klass = klass.replace(re, '$1');

            // find the supported extension
            extlist.each(function(x) {
                re = new RegExp('\\.' + x + '$');
                if (src.match(re)) {
                    ext = x;
                }
            });

            if (ext != null) {
                // get this mouseover key
                re = new RegExp('mouseover(_[a-zA-Z0-9-]+)');
                key = klass.replace(re, '$1');

                // get this mouseovers over src
                re = new RegExp('\\.' + ext + '$');
                oversrc = src.replace(re, key + '.' + ext);

                // preload both over and out images
                el.overImage = new Image();
                el.overImage.src = oversrc;
                el.outImage = new Image();
                el.outImage.src = src;
                
                // setup onmouseover event
                el.addEvent('mouseenter', function(){
                    this.setProperty('src', this.overImage.src);
                });

                // setup onmouseout event
                el.addEvent('mouseleave', function(){
                    this.setProperty('src', this.outImage.src);
                });
            }
        }

        // reset vars
        ext = null;
        re = null;
        klass = null;
        key = null;
        src = null;
        oversrc = null;
    };

    if(image != undefined) {
        init($(image));
    }
    else {
        $$('img').each(init);
    }
}

//on DOMReady, load up the mouse over events
window.addEvent('domready', mouseover);


/**
 * SWFObject v1.4: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
 *
 * SWFObject is (c) 2006 Geoff Stearns and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 * **SWFObject is the SWF embed script formerly known as FlashObject. The name was changed for
 *   legal reasons.
 */
if(typeof deconcept=="undefined"){var deconcept=new Object();}
if(typeof deconcept.util=="undefined"){deconcept.util=new Object();}
if(typeof deconcept.SWFObjectUtil=="undefined"){deconcept.SWFObjectUtil=new Object();}
deconcept.SWFObject=function(_1,id,w,h,_5,c,_7,_8,_9,_a,_b){
if(!document.createElement||!document.getElementById){return;}
this.DETECT_KEY=_b?_b:"detectflash";
this.skipDetect=deconcept.util.getRequestParameter(this.DETECT_KEY);
this.params=new Object();
this.variables=new Object();
this.attributes=new Array();
if(_1){this.setAttribute("swf",_1);}
if(id){this.setAttribute("id",id);}
if(w){this.setAttribute("width",w);}
if(h){this.setAttribute("height",h);}
if(_5){this.setAttribute("version",new deconcept.PlayerVersion(_5.toString().split(".")));}
this.installedVer=deconcept.SWFObjectUtil.getPlayerVersion(this.getAttribute("version"),_7);
if(c){this.addParam("bgcolor",c);}
var q=_8?_8:"high";
this.addParam("quality",q);
this.setAttribute("useExpressInstall",_7);
this.setAttribute("doExpressInstall",false);
var _d=(_9)?_9:window.location;
this.setAttribute("xiRedirectUrl",_d);
this.setAttribute("redirectUrl","");
if(_a){this.setAttribute("redirectUrl",_a);}};
deconcept.SWFObject.prototype={setAttribute:function(_e,_f){
this.attributes[_e]=_f;
},getAttribute:function(_10){
return this.attributes[_10];
},addParam:function(_11,_12){
this.params[_11]=_12;
},getParams:function(){
return this.params;
},addVariable:function(_13,_14){
this.variables[_13]=_14;
},getVariable:function(_15){
return this.variables[_15];
},getVariables:function(){
return this.variables;
},getVariablePairs:function(){
var _16=new Array();
var key;
var _18=this.getVariables();
for(key in _18){
_16.push(key+"="+_18[key]);}
return _16;
},getSWFHTML:function(){
var _19="";
if(navigator.plugins&&navigator.mimeTypes&&navigator.mimeTypes.length){
if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","PlugIn");}
_19="<embed type=\"application/x-shockwave-flash\" src=\""+this.getAttribute("swf")+"\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\"";
_19+=" id=\""+this.getAttribute("id")+"\" name=\""+this.getAttribute("id")+"\" ";
var _1a=this.getParams();
for(var key in _1a){_19+=[key]+"=\""+_1a[key]+"\" ";}
var _1c=this.getVariablePairs().join("&");
if(_1c.length>0){_19+="flashvars=\""+_1c+"\"";}
_19+="/>";
}else{
if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","ActiveX");}
_19="<object id=\""+this.getAttribute("id")+"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\">";
_19+="<param name=\"movie\" value=\""+this.getAttribute("swf")+"\" />";
var _1d=this.getParams();
for(var key in _1d){_19+="<param name=\""+key+"\" value=\""+_1d[key]+"\" />";}
var _1f=this.getVariablePairs().join("&");
if(_1f.length>0){_19+="<param name=\"flashvars\" value=\""+_1f+"\" />";}
_19+="</object>";}
return _19;
},write:function(_20){
if(this.getAttribute("useExpressInstall")){
var _21=new deconcept.PlayerVersion([6,0,65]);
if(this.installedVer.versionIsValid(_21)&&!this.installedVer.versionIsValid(this.getAttribute("version"))){
this.setAttribute("doExpressInstall",true);
this.addVariable("MMredirectURL",escape(this.getAttribute("xiRedirectUrl")));
document.title=document.title.slice(0,47)+" - Flash Player Installation";
this.addVariable("MMdoctitle",document.title);}}
if(this.skipDetect||this.getAttribute("doExpressInstall")||this.installedVer.versionIsValid(this.getAttribute("version"))){
var n=(typeof _20=="string")?document.getElementById(_20):_20;
n.innerHTML=this.getSWFHTML();
return true;
}else{
if(this.getAttribute("redirectUrl")!=""){document.location.replace(this.getAttribute("redirectUrl"));}}
return false;}};
deconcept.SWFObjectUtil.getPlayerVersion=function(_23,_24){
var _25=new deconcept.PlayerVersion([0,0,0]);
if(navigator.plugins&&navigator.mimeTypes.length){
var x=navigator.plugins["Shockwave Flash"];
if(x&&x.description){_25=new deconcept.PlayerVersion(x.description.replace(/([a-z]|[A-Z]|\s)+/,"").replace(/(\s+r|\s+b[0-9]+)/,".").split("."));}
}else{try{
var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
for(var i=3;axo!=null;i++){
axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+i);
_25=new deconcept.PlayerVersion([i,0,0]);}}
catch(e){}
if(_23&&_25.major>_23.major){return _25;}
if(!_23||((_23.minor!=0||_23.rev!=0)&&_25.major==_23.major)||_25.major!=6||_24){
try{_25=new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));}
catch(e){}}}
return _25;};
deconcept.PlayerVersion=function(_29){
this.major=parseInt(_29[0])!=null?parseInt(_29[0]):0;
this.minor=parseInt(_29[1])||0;
this.rev=parseInt(_29[2])||0;};
deconcept.PlayerVersion.prototype.versionIsValid=function(fv){
if(this.major<fv.major){return false;}
if(this.major>fv.major){return true;}
if(this.minor<fv.minor){return false;}
if(this.minor>fv.minor){return true;}
if(this.rev<fv.rev){return false;}return true;};
deconcept.util={getRequestParameter:function(_2b){
var q=document.location.search||document.location.hash;
if(q){
var _2d=q.indexOf(_2b+"=");
var _2e=(q.indexOf("&",_2d)>-1)?q.indexOf("&",_2d):q.length;
if(q.length>1&&_2d>-1){
return q.substring(q.indexOf("=",_2d)+1,_2e);
}}return "";}};
if(Array.prototype.push==null){
Array.prototype.push=function(_2f){
this[this.length]=_2f;
return this.length;};}
var getQueryParamValue=deconcept.util.getRequestParameter;
var FlashObject=deconcept.SWFObject; // for backwards compatibility
var SWFObject=deconcept.SWFObject;

var Wishlist = {
    defaultOptions: {
        'expiration': 30,       //Wishlist expiration time in days
        'delimeter': ','        //Delimeter to be used for the cookie
    },
    
    init: function(options){
        this.options = Object.extend(($merge(this.defaultOptions, options)));
        
        this.items = Cookie.get('wishlist');
        if(!this.items) this.items = "";
        Cookie.set('wishlist', this.items, {'duration': this.options.expiration});
        this.updateCount();
    },
    
    get: function() {
        return(this.items);
    },
    
    count: function() {
        if(this.items) return(this.items.split(this.options.delimeter).length);
        else return(false);
    },
    
    updateCount: function () {
        if($("wishlistCount")) {
            var wlCount = this.count();
            if(wlCount > 0) {
                var strWLCount = "- " + wlCount + " item";
                if(wlCount > 1) strWLCount = strWLCount + "s";
                $("wishlistCount").setHTML(strWLCount);
            }
        }
    },
    
    check: function(productId) {
        return(this.items.split(this.options.delimeter).contains(productId));
    },
    
    add: function(productId) {
        if(this.items.contains(productId)) return(false);
        if(this.items == "") this.items = productId;
        else this.items = this.items + this.options.delimeter + productId;
        
        Cookie.set('wishlist', this.items, {'duration': this.options.expiration});
        this.updateCount();
        return(this.items);
    },
    
    remove: function(productId) {
        if(!this.items.contains(productId)) return(false);
        
        Cookie.remove(productId);
        var arrItems = this.items.split(this.options.delimeter);
        arrItems.remove(productId);
        this.items = arrItems.join(this.options.delimeter);
        
        Cookie.set('wishlist', this.items, {'duration': this.options.expiration});
        this.updateCount();
        return(this.items);
    },
    
    clear: function() {
        this.items.split(this.options.delimeter).each(function(id) {this.remove(id);}.bind(this));
        this.updateCount();
        return(this.items);
    },
    
    addComment: function(productId, comment) {
        if(!comment) comment = "";
    
        if(this.check(productId)) return(Cookie.set(productId, comment, {'duration': this.options.expiration}));
        else return(false);
    },
    
    removeComment: function(productId) {
        return(Cookie.remove(productId));
    },
    
    editComment: function(productId, comment) {
        if(!comment) comment = "";
        
        if(this.check(productId)) return(Cookie.set(productId, comment, {'duration': this.options.expiration}));
        else return(false);
    },
    
    getComment: function(productId) {
        if(Cookie.get(productId) && this.check(productId)) return(Cookie.get(productId));
        else return(false);
    }
};
window.onDomReady(Wishlist.init.bind(Wishlist));

var Ticker = new Class({
    defaultOptions: {
        'paused': false,
        'rightToLeft': false,
        'speed': 1
    },
    
    initialize: function(container, content, options) {
        this.setOptions($merge(this.defaultOptions, options));
        this.container = $(container);
        if(window.gecko && navigator.appVersion && navigator.appVersion.indexOf("Mac") != -1) $("ticker_container").setStyle('margin-top', '0');
        
        this.width = this.container.getStyle('width');
        this.ticker = new Element('div', {'id': 'ticker'}).setStyles({'width': '100%', 'overflow': 'hidden', 'white-space': 'nowrap'});        
        this.spacer = new Element('img', {'src': '/images/common/spacer.gif', 'height': '0'}).setStyle('width', this.width).injectInside(this.ticker);        
        this.content = new Element('span', {'id': 'ticker_content'}).setHTML(content).injectAfter(this.spacer);
        this.spacer.clone().injectAfter(this.content);        
        this.ticker.injectInside(this.container);
        
        var updatePosition = this.updatePosition.bind(this);
        window.addEvent('resize', updatePosition);
    },
    
    start: function() {
        this.ticker.scrollLeft = this.options.rightToLeft ? this.ticker.scrollWidth - this.ticker.offsetWidth : 0;
        this.scroll();
    },
    
    scroll: function() {
        if(!this.options.paused) this.ticker.scrollLeft += this.options.speed * (this.options.rightToLeft ? -1 : 1);
        if(this.options.rightToLeft && this.ticker.scrollLeft <= 0) this.ticker.scrollLeft = this.ticker.scrollWidth - this.ticker.offsetWidth;
        if(!this.options.rightToLeft && this.ticker.scrollLeft >= this.ticker.scrollWidth - this.ticker.offsetWidth) this.ticker.scrollLeft = 0;

        var scroller = this.scroll.bind(this);
        scroller.delay(30);
    },
    
    updatePosition: function() {
        this.width = this.container.offsetWidth;
        this.spacer.setStyle('width', this.width);
    }    
});

Ticker.implement(new Events, new Options);

