//********************************************************************
//*-------------------------------------------------------------------
//*	This file combines five javascript files into one:
//*
//*		* jQuery hoverIntent plugin
//*		* jQuery cookie plugin
//*		* util.js (standard site-wide utilites)
//*		* validation.js (qty and add-to-cart validation)
//*		* jQuery simpleModal plugin
//*
//*	These files are being included here, in global.js, as every
//* page needs these files.
//*-------------------------------------------------------------------
//********************************************************************

function isPositiveWholeNumber(a){for(var b=0;b<a.length;b++){var c=a.charAt(b);if(c<"0"||c>"9"){return false}}return true}function validateQuantities(a){var b,c,d=false;for(b in a){c=a[b];trimMe(c);if(c==null||c.value.length==0||isNaN(c.value)||c.value<1||!isPositiveWholeNumber(c.value)){d=true;c.focus();break}}if(d){alert("Quantity must be a valid positive whole number.");return false}else{return true}}function validateItemAttrs(a,b,c){if(typeof a=="string"&&typeof b=="string"){var d,e,f=true;for(d=0,l=c.length;d<l;d++){e=c[d];if(e.value>=1){f=false;if(e.type!="hidden"&&e.style.display!="none"&&!e.disabled){e.focus()}break}}if(f){alert("Quantity must be a valid positive whole number.");return false}else{return true}}}function dispMsg(a,b,c){if(c){alert("Valid "+a+" should be selected.");return false}else{return true}}function validateAttr(a,b,c,d){var e,a,b,f=false;a=a.id.split("-")[2];if(a=="color"){if(b==null||b.value.length==0||b.value==0){f=true;dispMsg(a,b,f)}}else if(a=="size"){if(b==null||b.value.length==0||b.value<1){f=true;dispMsg(a,b,f)}}else if(a=="amount"){if(b==null||b.value.length==0||b.value<1){f=true;dispMsg(a,b,f)}}else if(a=="strength"){if(b==null||b.value.length==0||b.value==0){f=true;dispMsg(a,b,f)}}if(f){return false}else{f=validateQuantity(c,d);return f}}function validateAttrs(a,b,c,d){var e,f,g,h=false;for(e=0,l=b.length;e<l;e++){g=b[e];f=a[e].id.split("-")[2];if(f=="color"){if(g==null||g.value.length==0||g.value=="00"){h=true;dispMsg(f,g,h)}}else if(f=="size"){if(g==null||g.value.length==0||g.value=="00"){h=true;dispMsg(f,g,h)}}else if(f=="strength"){if(g==null||g.value.length==0||g.value=="00"){h=true;dispMsg(f,g,h)}}}if(h){return false}else{h=validateQuantity(c,d);return h}}function validateQuantity(a,b){var c=a.value;if(b){c="1"}if(a==null||a.value.length==0){alert("Quantity is a required field.");a.value=c;a.focus();return false}else if(isNaN(a.value)){alert("Quantity must be a valid number.");a.value=c;a.focus();return false}else if(a.value<1){alert("Quantity must be greater than zero");a.value=c;a.focus();return false}else{return true}}function hideDD(){$(this).children(".dd").slideUp();$(this).removeClass("facet-on")}function showDD(){$(this).addClass("facet-on");$(this).children(".dd").slideDown()}function isEmpty(a){if(a==null){return true}else{return!a.match(/[^\s]/)}}function getCookie(a){var b=document.cookie.match(a+"=(.*?)(;|$)");if(b)return unescape(b[1]);else return null}function bundleDesc(){$("#attributes").find("div[id*=item] a[id*=viewDesc]").toggle(function(){$(this).addClass("on");$(this).addClass("onDesc");$(this).parent().next().slideDown(250);$(this).html("Hide Description")},function(){$(this).removeClass("on");$(this).removeClass("onDesc");$(this).parent().next().slideUp(250);$(this).html("View Description")})}function toggleDesc(a){var b=$("#description a");b.click(function(){$(this).parent().fadeOut(290,function(){$(this).siblings().fadeIn(290)})})}function getUserCookieValue(a,b){var c=getCookie(a);if(c==null)return null;var d="@";var e="~~~";var f=b+e+"(.*?)("+d+")";var g=c.match(f);if(g)return unescape(g[1]);else return null}function displayAmountValue(a,b){var c="0.00";c=getUserCookieValue(a,b);if(c!=null){var d=c.indexOf(".");if(c.length-d>3)c=c.substring(0,d+3);else if(d!=-1&&c.length-d==2)c=c+"0";else if(d==-1)c=c+".00"}else{c="0.00"}document.write(c)}function displayIntegerValue(a,b){var c="0";c=getUserCookieValue(a,b);if(c==null)c="0";document.write(c)}function Add2WishList(a){var b=a.getElementsByTagName("input");var c,d;for(c in b){d=b[c].id;if(d!=null&&d.indexOf("quantity")!=-1){b[c].value=1}}if(!busy){busy=true;a.action="InterestItemAdd";a.URL.value="InterestItemDisplay";a.submit()}}function Add2ShopCart(a){if(!busy){busy=true;a.action="OrderItemAdd";a.URL.value="OrderCalculate?updatePrices=1&calculationUsageId=-1&dummaryparam=1&URL=ProductDisplay";a.submit()}}function convertToLowerCase(a){var b=a.value;b=b.toLowerCase();a.value=b}function trimMe(a){var b=a.value;b=b.replace(/^\s+|\s+$/g,"");a.value=b}function fieldClear(a){if(a.Val){if(a.value==""){a.value=a.Val;a.Val=null;a.first=null}else{a.Val=null}}else if(!a.first){a.Val=a.value;a.value="";a.first="true"}}function utf8StringByteLength(a){if(a===null)return 0;var b=String(a);var c=127;var d=2047;var e=b.length;for(i=0;i<b.length;i++){chr=b.charCodeAt(i);if(chr>c)e=e+1;if(chr>d)e=e+1}return e}function isValidUTF8length(a,b){if(utf8StringByteLength(a)>b)return false;else return true}function isValidEmail(a){if(containsDoubleByte(a)){return false}if(a.length==0){return true}else if(a.length<5){return false}else{if(a.indexOf(" ")>0){return false}else{if(a.indexOf("@")<1){return false}else{if(a.lastIndexOf(".")<a.indexOf("@")+2){return false}else{if(a.lastIndexOf(".")>=a.length-2){return false}}}}}return true}function containsDoubleByte(a){var b=new String(a);var c=127;for(var d=0;d<b.length;d++){chr=b.charCodeAt(d);if(chr>c){return true}}return false}(function(a){a.fn.hoverIntent=function(b,c){var d={sensitivity:7,interval:100,timeout:0};d=a.extend(d,c?{over:b,out:c}:b);var e,f,g,h;var i=function(a){e=a.pageX;f=a.pageY};var j=function(b,c){c.hoverIntent_t=clearTimeout(c.hoverIntent_t);if(Math.abs(g-e)+Math.abs(h-f)<d.sensitivity){a(c).unbind("mousemove",i);c.hoverIntent_s=1;return d.over.apply(c,[b])}else{g=e;h=f;c.hoverIntent_t=setTimeout(function(){j(b,c)},d.interval)}};var k=function(a,b){b.hoverIntent_t=clearTimeout(b.hoverIntent_t);b.hoverIntent_s=0;return d.out.apply(b,[a])};var l=function(b){var c=(b.type=="mouseover"?b.fromElement:b.toElement)||b.relatedTarget;while(c&&c!=this){try{c=c.parentNode}catch(b){c=this}}if(c==this){return false}var e=jQuery.extend({},b);var f=this;if(f.hoverIntent_t){f.hoverIntent_t=clearTimeout(f.hoverIntent_t)}if(b.type=="mouseover"){g=e.pageX;h=e.pageY;a(f).bind("mousemove",i);if(f.hoverIntent_s!=1){f.hoverIntent_t=setTimeout(function(){j(e,f)},d.interval)}}else{a(f).unbind("mousemove",i);if(f.hoverIntent_s==1){f.hoverIntent_t=setTimeout(function(){k(e,f)},d.timeout)}}};return this.mouseover(l).mouseout(l)}})(jQuery);jQuery.cookie=function(a,b,c){if(typeof b!="undefined"){c=c||{};if(b===null){b="";c.expires=-1}var d="";if(c.expires&&(typeof c.expires=="number"||c.expires.toUTCString)){var e;if(typeof c.expires=="number"){e=new Date;e.setTime(e.getTime()+c.expires*24*60*60*1e3)}else{e=c.expires}d="; expires="+e.toUTCString()}var f=c.path?"; path="+c.path:"";var g=c.domain?"; domain="+c.domain:"";var h=c.secure?"; secure":"";document.cookie=[a,"=",encodeURIComponent(b),d,f,g,h].join("")}else{var i=null;if(document.cookie&&document.cookie!=""){var j=document.cookie.split(";");for(var k=0;k<j.length;k++){var l=jQuery.trim(j[k]);if(l.substring(0,a.length+1)==a+"="){i=decodeURIComponent(l.substring(a.length+1));break}}}return i}};var busy=false;(function(a){var b=a.browser.msie&&parseInt(a.browser.version)==6&&typeof window["XMLHttpRequest"]!="object",c=null,d=[];a.modal=function(b,c){return a.modal.impl.init(b,c)};a.modal.close=function(){a.modal.impl.close()};a.fn.modal=function(b){return a.modal.impl.init(this,b)};a.modal.defaults={appendTo:"body",focus:true,opacity:50,overlayId:"simplemodal-overlay",overlayCss:{},containerId:"simplemodal-container",containerCss:{},dataId:"simplemodal-data",dataCss:{},minHeight:null,minWidth:null,maxHeight:null,maxWidth:null,autoResize:false,autoPosition:true,zIndex:1e3,close:true,closeHTML:'<a class="modalCloseImg" title="Close"></a>',closeClass:"simplemodal-close",escClose:true,overlayClose:false,position:null,persist:false,modal:true,onOpen:null,onShow:null,onClose:null};a.modal.impl={o:null,d:{},init:function(b,d){var e=this;if(e.d.data){return false}c=a.browser.msie&&!a.boxModel;e.o=a.extend({},a.modal.defaults,d);e.zIndex=e.o.zIndex;e.occb=false;if(typeof b=="object"){b=b instanceof jQuery?b:a(b);e.d.placeholder=false;if(b.parent().parent().size()>0){b.before(a("<span></span>").attr("id","simplemodal-placeholder").css({display:"none"}));e.d.placeholder=true;e.display=b.css("display");if(!e.o.persist){e.d.orig=b.clone(true)}}}else if(typeof b=="string"||typeof b=="number"){b=a("<div></div>").html(b)}else{alert("SimpleModal Error: Unsupported data type: "+typeof b);return e}e.create(b);b=null;e.open();if(a.isFunction(e.o.onShow)){e.o.onShow.apply(e,[e.d])}return e},create:function(e){var f=this;d=f.getDimensions();if(f.o.modal&&b){f.d.iframe=a('<iframe src="javascript:false;"></iframe>').css(a.extend(f.o.iframeCss,{display:"none",opacity:0,position:"fixed",height:d[0],width:d[1],zIndex:f.o.zIndex,top:0,left:0})).appendTo(f.o.appendTo)}f.d.overlay=a("<div></div>").attr("id",f.o.overlayId).addClass("simplemodal-overlay").css(a.extend(f.o.overlayCss,{display:"none",opacity:f.o.opacity/100,height:f.o.modal?d[0]:0,width:f.o.modal?d[1]:0,position:"fixed",left:0,top:0,zIndex:f.o.zIndex+1})).appendTo(f.o.appendTo);f.d.container=a("<div></div>").attr("id",f.o.containerId).addClass("simplemodal-container").css(a.extend(f.o.containerCss,{display:"none",position:"fixed",zIndex:f.o.zIndex+2})).append(f.o.close&&f.o.closeHTML?a(f.o.closeHTML).addClass(f.o.closeClass):"").appendTo(f.o.appendTo);f.d.wrap=a("<div></div>").attr("tabIndex",-1).addClass("simplemodal-wrap").css({height:"100%",outline:0,width:"100%"}).appendTo(f.d.container);f.d.data=e.attr("id",e.attr("id")||f.o.dataId).addClass("simplemodal-data").css(a.extend(f.o.dataCss,{display:"none"})).appendTo("body");e=null;f.setContainerDimensions();f.d.data.appendTo(f.d.wrap);if(b||c){f.fixIE()}},bindEvents:function(){var e=this;a("."+e.o.closeClass).bind("click.simplemodal",function(a){a.preventDefault();e.close()});if(e.o.modal&&e.o.close&&e.o.overlayClose){e.d.overlay.bind("click.simplemodal",function(a){a.preventDefault();e.close()})}a(document).bind("keydown.simplemodal",function(a){if(e.o.modal&&e.o.focus&&a.keyCode==9){e.watchTab(a)}else if(e.o.close&&e.o.escClose&&a.keyCode==27){a.preventDefault();e.close()}});a(window).bind("resize.simplemodal",function(){d=e.getDimensions();e.setContainerDimensions(true);if(b||c){e.fixIE()}else if(e.o.modal){e.d.iframe&&e.d.iframe.css({height:d[0],width:d[1]});e.d.overlay.css({height:d[0],width:d[1]})}})},unbindEvents:function(){a("."+this.o.closeClass).unbind("click.simplemodal");a(document).unbind("keydown.simplemodal");a(window).unbind("resize.simplemodal");this.d.overlay.unbind("click.simplemodal")},fixIE:function(){var b=this,c=b.o.position;a.each([b.d.iframe||null,!b.o.modal?null:b.d.overlay,b.d.container],function(a,b){if(b){var d="document.body.clientHeight",e="document.body.clientWidth",f="document.body.scrollHeight",g="document.body.scrollLeft",h="document.body.scrollTop",i="document.body.scrollWidth",j="document.documentElement.clientHeight",k="document.documentElement.clientWidth",l="document.documentElement.scrollLeft",m="document.documentElement.scrollTop",n=b[0].style;n.position="absolute";if(a<2){n.removeExpression("height");n.removeExpression("width");n.setExpression("height",""+f+" > "+d+" ? "+f+" : "+d+' + "px"');n.setExpression("width",""+i+" > "+e+" ? "+i+" : "+e+' + "px"')}else{var o,q;if(c&&c.constructor==Array){var r=c[0]?typeof c[0]=="number"?c[0].toString():c[0].replace(/px/,""):b.css("top").replace(/px/,"");o=r.indexOf("%")==-1?r+" + (t = "+m+" ? "+m+" : "+h+') + "px"':parseInt(r.replace(/%/,""))+" * (("+j+" || "+d+") / 100) + (t = "+m+" ? "+m+" : "+h+') + "px"';if(c[1]){var s=typeof c[1]=="number"?c[1].toString():c[1].replace(/px/,"");q=s.indexOf("%")==-1?s+" + (t = "+l+" ? "+l+" : "+g+') + "px"':parseInt(s.replace(/%/,""))+" * (("+k+" || "+e+") / 100) + (t = "+l+" ? "+l+" : "+g+') + "px"'}}else{o="("+j+" || "+d+") / 2 - (this.offsetHeight / 2) + (t = "+m+" ? "+m+" : "+h+') + "px"';q="("+k+" || "+e+") / 2 - (this.offsetWidth / 2) + (t = "+l+" ? "+l+" : "+g+') + "px"'}n.removeExpression("top");n.removeExpression("left");n.setExpression("top",o);n.setExpression("left",q)}}})},focus:function(b){var c=this,d=b||"first";var e=a(":input:enabled:visible:"+d,c.d.wrap);e.length>0?e.focus():c.d.wrap.focus()},getDimensions:function(){var b=a(window);var c=a.browser.opera&&a.browser.version>"9.5"&&a.fn.jquery<="1.2.6"?document.documentElement["clientHeight"]:a.browser.opera&&a.browser.version<"9.5"&&a.fn.jquery>"1.2.6"?window.innerHeight:b.height();return[c,b.width()]},getVal:function(a){return a=="auto"?0:a.indexOf("%")>0?a:parseInt(a.replace(/px/,""))},setContainerDimensions:function(b){var c=this;if(!b||b&&c.o.autoResize){var e=a.browser.opera?c.d.container.height():c.getVal(c.d.container.css("height")),f=a.browser.opera?c.d.container.width():c.getVal(c.d.container.css("width")),g=c.d.data.outerHeight(true),h=c.d.data.outerWidth(true);var i=c.o.maxHeight&&c.o.maxHeight<d[0]?c.o.maxHeight:d[0],j=c.o.maxWidth&&c.o.maxWidth<d[1]?c.o.maxWidth:d[1];if(!e){if(!g){e=c.o.minHeight}else{if(g>i){e=i}else if(g<c.o.minHeight){e=c.o.minHeight}else{e=g}}}else{e=e>i?i:e}if(!f){if(!h){f=c.o.minWidth}else{if(h>j){f=j}else if(h<c.o.minWidth){f=c.o.minWidth}else{f=h}}}else{f=f>j?j:f}c.d.container.css({height:e,width:f});if(g>e||h>f){c.d.wrap.css({overflow:"auto"})}}if(c.o.autoPosition){c.setPosition()}},setPosition:function(){var a=this,b,c,e=d[0]/2-a.d.container.outerHeight(true)/2,f=d[1]/2-a.d.container.outerWidth(true)/2;if(a.o.position&&Object.prototype.toString.call(a.o.position)==="[object Array]"){b=a.o.position[0]||e;c=a.o.position[1]||f}else{b=e;c=f}a.d.container.css({left:c,top:b})},watchTab:function(b){var c=this;if(a(b.target).parents(".simplemodal-container").length>0){c.inputs=a(":input:enabled:visible:first, :input:enabled:visible:last",c.d.data[0]);if(!b.shiftKey&&b.target==c.inputs[c.inputs.length-1]||b.shiftKey&&b.target==c.inputs[0]||c.inputs.length==0){b.preventDefault();var d=b.shiftKey?"last":"first";setTimeout(function(){c.focus(d)},10)}}else{b.preventDefault();setTimeout(function(){c.focus()},10)}},open:function(){var b=this;b.d.iframe&&b.d.iframe.show();if(a.isFunction(b.o.onOpen)){b.o.onOpen.apply(b,[b.d])}else{b.d.overlay.show();b.d.container.show();b.d.data.show()}b.focus();b.bindEvents()},close:function(){var b=this;if(!b.d.data){return false}b.unbindEvents();if(a.isFunction(b.o.onClose)&&!b.occb){b.occb=true;b.o.onClose.apply(b,[b.d])}else{if(b.d.placeholder){var c=a("#simplemodal-placeholder");if(b.o.persist){c.replaceWith(b.d.data.removeClass("simplemodal-data").css("display",b.display))}else{b.d.data.hide().remove();c.replaceWith(b.d.orig)}}else{b.d.data.hide().remove()}b.d.container.hide().remove();b.d.overlay.hide().remove();b.d.iframe&&b.d.iframe.hide().remove();b.d={}}}}})(jQuery)
