//mmjs
function MM_findObj(n, d) { //v4.0
	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 && document.getElementById) x=document.getElementById(n); return x;
}

function MM_preloadImages() { //v3.0
	var d=document; 
	if(d.images) {
		if(!d.MM_p) d.MM_p=new Array();
			var i,j=d.MM_p.length,a=MM_preloadImages.arguments;
		for(i=0; i<a.length; i++)
		if (a[i].indexOf("#")!=0) {
			d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];
		}
	}
}

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_reloadPage(init) {  //reloads the window if Nav4 resized
	if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
		document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
	else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
// -->

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];}
}

function MM_showHideLayers() { //v3.0
	var i,p,v,obj,args=MM_showHideLayers.arguments;
	for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
	if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
		obj.visibility=v; }
}

function MM_setTextOfTextfield(objName,x,newText) { //v3.0
	var obj = MM_findObj(objName); if (obj) obj.value = newText;
}

function WS_initialize() {
	WS_hideall ();
	MM_swapImgRestore();
}

function WS_hideall() {
	MM_showHideLayers('topcatlayer1','','hide');
	MM_showHideLayers('topcatlayer2','','hide');
	MM_showHideLayers('topcatlayer3','','hide');
	MM_showHideLayers('topcatlayer4','','hide');
	MM_showHideLayers('topcatlayer5','','hide');
	MM_showHideLayers('topcatlayer6','','hide');
	MM_showHideLayers('topcatlayer7','','hide');
	MM_showHideLayers('topcatlayer8','','hide');
	MM_showHideLayers('topcatlayer9','','hide');
	MM_showHideLayers('topcatlayer10','','hide');
	MM_showHideLayers('topcatlayer11','','hide');
	MM_showHideLayers('topcatlayer12','','hide');
}

var WS_menu=null;

function WS_doinTopCat(num,switchOn) {
	MM_swapImgRestore();
	MM_swapImage('topcat' + num,'',switchOn,1);
	MM_showHideLayers('topcatlayer' + num,'','show');
	if (WS_menu != null) {window.clearTimeout(WS_menu);}
}

function WS_dooutTopCat(num) {
	if (WS_menu != null) {window.clearTimeout(WS_menu);}
	WS_menu=window.setTimeout('WS_initialize()',500);
}

var agt  = navigator.userAgent.toLowerCase();
var nav4 = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
         && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
				 && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1)
				 && (parseInt(navigator.appVersion) == 4));

function clearSearch () {
	if (document.searchform.words.value == 'keyword or item #') {
		document.searchform.words.value = '';
	}
}

function searchValueCheck () {
	if (document.searchform.words.value == '') {
		document.searchform.words.value = 'keyword or item #';
	}
}

function clearJoinEmail () {
	if (document.joinemailform.e0.value != '') {
		document.joinemailform.e0.value = '';
	}
}

function joinEmailCheck () {
	if (document.joinemailform.e0.value == '') {
		document.joinemailform.e0.value = ' email address';
	}
}

function cartCountCheck(state) {
  var elem = document.getElementById ('basketQty');
  if( elem ) {
    if( state ) {
      elem.className = 'basketCountLinkOn';
    }
    else {
      elem.className = 'basketCountLink';
    }
  }
}

// for cart
var supported = navigator.userAgent.indexOf("Mozilla") == 0 && navigator.userAgent.substring(8,9) >= 3;
function shiptoPopUp(filename, windowname, height, width) {
	if(supported) {
		popup = window.open(filename,windowname,"resizable=yes,scrollbars=yes,status=no,height="+height+",width="+width+",screenX=4,screenY=4,top=4,left=4");
		popup.focus();
		return false;
	} else {
		return true;
	}
}

// for popups
function createPopUp(url, name, optionString) {
	if (!name){
		name = "newwnd";
	}
	if (!optionString){
		optionString = "toolbar=no,location=no,directories=no,scrollbars=yes,resizable=yes,height=500,width=730,screenX=4,screenY=4,top=4,left=4";
	}		
	win = window.open(url, name, optionString);
	win.focus();
}

function MakeUrl(href, arglist) {
  var result = '';
  var key = 0;
  var name = 0;
  var value = 0;
  var sep = "?";
  var argString = "";
  
  if (!arglist) {
    arglist = new Object();
  }
  
  if (href.indexOf("?") != -1) {
    sep = "&";
  }
  for (key in arglist) {
    name = escape(key.toLowerCase());
    value = escape(arglist[key]);
    argString += sep + name + '=' + value;
    sep = "&";
  }
 
  result = href + argString;
  return result;
}

function GetParameter(variable, def) { 
  var query = window.location.search.substring(1); 
  var vars = query.split("&"); 
  for (var i=0;i<vars.length;i++) { 
    var pair = vars[i].split("="); 
    if (pair[0] == variable) { 
      return pair[1]; 
    } 
  } 
  return def;
}
// for cart popups
function createCartPopUp(url, name, optionString) {
	if (!name){
		name = "newwnd";
	}
	if (!optionString){
		optionString = "toolbar=no,location=no,directories=no,scrollbars=1,resizable=0,height=390,width=470,screenX=4,screenY=4,top=4,left=4";
	}		
	win = window.open(url, name, optionString);
	win.focus();
}

function LinkFromFlash(href, redirect) {
	var confirm_redirect = true;
	// Add dbcmlv=1 to the URL to debug
	// (Short for DeBug CoreMetrics LiveView)
	if (document.URL.indexOf('dbcmlv=1') != -1) {
		if (redirect) {
			confirm_redirect = confirm("LinkFromFlash, OK to redirect:\nHref: "
										+ href + "\nName: " + name);
		} else {
			alert("LinkFromFlash:\nHref: " + href + "\nName: " + name);
		}
	}
	if (redirect && confirm_redirect) {
		document.location = href;
	}
}

function emailPassword()
{
        href = "../acct/index.cfm?action=requestpass&action1=times&submit=1&e0=" +
        window.document.signinform.e0.value;
        window.document.location = href;
}

// ======================================================================
/*
 *
 * imgID   - string - the id of the <img>
 * onoroff - string - "on" or "off" to indicate which version of the
 *                    src of the image to display
 */
function rolloverBtn(imgID, onoroff) {

	var newSrc = "../../images/common/btn_" + imgID + "_" + onoroff + ".gif";


//alert(newSrc);


	if (document.getElementById) {
		document.getElementById(imgID).src = newSrc;
	}
	else if (document.all) {
		document.all[imgID].src = newSrc;
	}

}
// ======================================================================


function closeWindow() {

	/* this fools IE 7, Firefox 1.5, Opera 9 into thinking the window
	 * was opened by a script, so they will allow the window to close */
	/* (Does not work on Firefox 2 nor Safari 3 for Windows) */
	window.open('','_parent','');

	window.close();
}

// ======================================================================


// This implementation based on quirksmode.org/js/cookies.html
function readCookie(name) {
        var cookieKey = name + "=";
        var cookieList = document.cookie.split(";");
    var result = null;

        for (var i = 0; i < cookieList.length; i++) {
                var thisCookie = cookieList[i];
        //var len = thisCookie.length;
        // Trim leading whitespace - probably a for loop would be better here
        while (thisCookie.charAt(0) == " ") {
            thisCookie = thisCookie.substring(1, thisCookie.length);
        }
                if (thisCookie.toUpperCase().indexOf(cookieKey.toUpperCase()) == 0) {
            result = thisCookie.substring(cookieKey.length, thisCookie.length);
            break;
        }
        }
        return result;
}

function removeCartItem(item) {
    document.cartForm[item].value = "remove";
}

// Force a location to load (or re-load) a URL
function forceLoad(loc, url) {
    if ((loc.href != url) && (loc.href != url + loc.hash)
        && (loc.href != url + '#')) {
        loc.href = url;
    } else {
        loc.reload(true);
    }
}

function editMonogramming(item) {
    alert(item);
    document.cartForm[item].value = "edit";
    document.cartForm.submit();
}


// This is called by the preview button on the main pip page
function vPersPopUp(url, name, optionString) {
    var arglist = new Object();
    arglist.bypassedge = 1;
        arglist.perstext = document.pipform.perstext.value;
        if (document.pipform.perstext2 != null) {
                        arglist.perstext2 = document.pipform.perstext2.value;
        }
        if (document.pipform.perstext3 != null) {
                        arglist.perstext3 = document.pipform.perstext3.value;
        }
    return popupMonoPreview(url, name, optionString, arglist);
}

function popupMonoPreview(url, name, optionString, arglist) {
    if (!arglist) {
        arglist = new Object();
                arglist.perstext = document.pipform.perstext.value;
                if (document.pipform.perstext2 != null) {
                        arglist.perstext2 = document.pipform.perstext2.value;
                }
                if (document.pipform.perstext3 != null) {
                        arglist.perstext3 = document.pipform.perstext3.value;
                }
    }

    var url = MakeUrl(url, arglist);

    if (!name){
        name = "newwnd";
    }

    if (!optionString){
        optionString = "toolbar=no,location=no,directories=no,scrollbars=yes," +
            "resizable=yes,height=500,width=830,screenX=4,screenY=4,top=4,left=4";
    }

    win = window.open(url, name, optionString);
    win.focus();
}

// This is called by the preview button on the Monogram page
function vPersPopUp_Mono(url, name, optionString,previewId,nooftextboxes,sku) {
    var arglist = new Object();
    arglist.bypassedge = 1;

        arglist.perstext = eval("document.pipform.i_" + previewId + "_1").value;
        if(nooftextboxes  == 3 ){
                arglist.perstext2 = eval("document.pipform.i_" + previewId + "_2").value;
                arglist.perstext3 = eval("document.pipform.i_" + previewId + "_3").value;
        }
        if(nooftextboxes  == 2 ){
                arglist.perstext2 = eval("document.pipform.i_" + previewId + "_2").value;
        }



        arglist.persstyle=eval("document.pipform.s_" + previewId).value;
        if(eval("document.pipform.c_" + previewId) != undefined){
                arglist.perscolor=eval("document.pipform.c_" + previewId).value;
        } else {
        //      arglist.perscolor=eval("document.pipform.c_" + previewId).value;
        }

        arglist.thisSkuId=sku;

    if (!optionString){
        optionString = "toolbar=no,location=no,directories=no,scrollbars=yes," +
            "resizable=yes,height=500,width=830,screenX=4,screenY=4,top=4,left=4";
    }

   return popupMonoPreview_Mono(url, name, optionString, arglist);
}
function giftWrap_pip(url, name, optionString) {
    var url = MakeUrl(url);
        if (!name){
        name = "GiftWrap";
    }
    if (!optionString){
        optionString = "toolbar=no,location=no,directories=no,scrollbars=yes,resizable=yes,height=300,width=400";
    }
    win = window.open(url, name, optionString);
    win.focus();
}

function popupMonoPreview_Mono(url, name, optionString, arglist) {
    if (!arglist) {
        arglist = new Object();
    }

    var url = MakeUrl(url, arglist);

    if (!name){
        name = "newwnd";
    }
    if (!optionString){
        optionString = "toolbar=no,location=no,directories=no,scrollbars=yes," +
            "resizable=yes,height=500,width=730,screenX=4,screenY=4,top=4,left=4";
    }
    win = window.open(url, name, optionString);
    win.focus();
}



/*
This function attach an event handler to any event in the dhtml
*/
function RegisterWindowLoadEvent(fnHandler)
{
	var evt = "onload";
	var source = window;
	if (arguments.length > 1) evt = arguments[1];
	if (arguments.length > 2) source = arguments[2];
	if ( typeof window.addEventListener != "undefined" )
	{
		source.addEventListener( evt.replace("on", ""), fnHandler, false );
	}
	else
	{
		if ( typeof source.attachEvent != "undefined" )
		{
			source.attachEvent( evt, fnHandler );
			//alert(evt);
		}
		else
		{
			if ( source.onload != null )
			{
				var oldOnload = source.onload;
				source.onload = function ( e )
						{
							oldOnload( e );
							fnHandler();
						}
			}
			else
			{
				source.onload = fnHandler;
			}
		}
	}
}

/* -------------------------------------------------------------------- */
/* Determines if the browser is an Internet Explorer of
 * versions 1 through 6.
 *
 * @return true if is IE 1-6, false otherwise
 */
function isIE_1_6() {

        // if not IE...
        if (navigator.userAgent.indexOf("MSIE") == -1) {
                return false;
        }
        var majorNumber = navigator.userAgent.charAt(navigator.userAgent.indexOf("MSIE") + 5);
        // if is IE, but is IE 7 or newer...
        if (parseFloat(majorNumber) >= 7) {
                return false;
        }
        return true;
}

/* -------------------------------------------------------------------- */
/* Hides any <select> with the class. Intended for "Registry List" page.
 * Only runs on Internet Explorer 6 or earlier because old IEs won't let
 * their <select> elements display behind other elements.
 *
 * It doesn't work quite right. The <select> will flash on and then off quicky when you scroll down the drop-down menu.
 *
 * valid values for visibility: "visible" or "hidden"
 */
var sortTimer = null;

function hideSortBy () {
	if ( document.getElementById ('s1') )
		document.getElementById ('s1').style.visibility = 'hidden';
}

function showSortBy () {
	if ( document.getElementById ('s1') )
		document.getElementById ('s1').style.visibility = 'visible';
}

function hideTheSortBySelect (visibility) {
	// if is NOT an older IE...
    if (!isIE_1_6()) {
		// don't need this function
		return;
	}
	
	if ( (document.getElementById ('s1')) ) {
		if (visibility == 'hidden') {
			hideSortBy ();
		}
		
		if (sortTimer != null) {window.clearTimeout (sortTimer);}
		sortTimer = window.setTimeout ('showSortBy ();', 1500);
	}
}

/**
		Registers functions etc. for promotions
	**/
	function _registerPromotionsSignInEvents () {
        var taxExemptionBlock = dojo.byId ("apply-tax-exemption");

        // Quick test to see if we're on the Trade Tax Exemption page
        if (!taxExemptionBlock) {
            return;
        }
		
        var taxExempt = dojo.byId ("yesexemption");
        var notExempt = dojo.byId ("noexemption");
		
        dojo.connect (taxExempt, "onclick", function(evt) {
            dojo.byId("termsBlock").className = "show";
            // Remove errors on click
            dojo.query(".message").forEach("item.className='hide';");
        });

        dojo.connect (notExempt, "onclick", function(evt) {
            dojo.byId("termsBlock").className = "hide";
            // Remove errors on click
            dojo.query(".message").forEach("item.className='hide';");
        });

        dojo.connect(dojo.byId("accepttoc"), "onclick", function(evt){
            // Remove errors on click
            dojo.query(".message").forEach("item.className='hide';");
        });

		// Testing for user back-button shenanigans
			// This test is for when the user has selected that they want Tax Exemption
			// and they've already checked the T&C box.
			if (dojo.byId ("yesexemption").checked && dojo.byId("accepttoc").checked) {
	            // Remove errors
	            dojo.query(".message").forEach("item.className='hide';");
			}
			
			// This test is for when the user didn't check anything at all before
			// hitting "Start Shopping", then selected that they do not want
			// Tax Exemption.
			if (dojo.byId ("noexemption").checked) {
	            // Remove errors
	            dojo.query(".message").forEach("item.className='hide';");
	            dojo.query("#termsBlock").forEach("item.className='hide';");
			}
	};
	
	/**
		Sets the "promoApply" hidden field to 'yes' when the user applies a promo
	**/
	function _registerPromoApplyEvents () {
		var applyPromoBlock = dojo.byId ("applyPromoBlock");
		
		// Test to see if we have an "applyPromoBlock", then
		// apply the necessary code.
		if (applyPromoBlock) {
			var applyPromoButton = dojo.byId ("applyPromo");
			
			if (applyPromoButton) {
				dojo.connect (applyPromoButton, "onclick", function(evt) {
					dojo.byId ("promoApply").value = "yes";
				});
			}
		
		// Test to see if we have an "removePromoBlock", then
		// apply the necessary code.
		} else {
			return;
		}
    }