//original file: util.js----------------------------------------------------------
	function addLoadListener(fn) {

		if (typeof window.addEventListener != 'undefined') {
			window.addEventListener('load', fn, false);
		} else if (typeof document.addEventListener != 'undefined') {
			document.addEventListener('load', fn, false);
		} else if (typeof window.attachEvent != 'undefined') {
			window.attachEvent('onload', fn);
		} else {
			var oldfn = window.onload;
			if (typeof window.onload != 'function') {
				window.onload = fn;
			} else {
				window.onload = function() {
					oldfn();
					fn();
				};
			}
		}
	}


	function attachEventListener(target, eventType, functionRef, capture) {
		if (target == null) return false;	// null check, so it won't throw a js error on IE
		
		if (typeof target.addEventListener != "undefined") {
			target.addEventListener(eventType, functionRef, capture);
		} else if (typeof target.attachEvent != "undefined") {
			target.attachEvent("on" + eventType, functionRef);
		} else {
			eventType = "on" + eventType;
			if (typeof target[eventType] == "function") {
				var oldListener = target[eventType];
				target[eventType] = function() {
					oldListener();
					return functionRef();
				}
			} else {
				target[eventType] = functionRef;
			}
		}
		return true;
	}
	
	
	function getElementsByAttribute(attribute, attributeValue)
	{
		var elementArray = new Array();
		var matchedArray = new Array();

		if (document.all) {
			elementArray = document.all;
		} else {
			elementArray = document.getElementsByTagName("*");
		}

		for (var i = 0; i < elementArray.length; i++) {
			if (attribute == "class") {
				var pattern = new RegExp("(^| )" + attributeValue + "( |$)");
				if (elementArray[i].className.match(pattern)) {
					matchedArray[matchedArray.length] = elementArray[i];
				}
			} else if (attribute == "for") {
				if (elementArray[i].getAttribute("htmlFor") || elementArray[i].getAttribute("for")) {
					if (elementArray[i].htmlFor == attributeValue) {
						matchedArray[matchedArray.length] = elementArray[i];
					}
				}
			} else if (elementArray[i].getAttribute(attribute) == attributeValue) {
				matchedArray[matchedArray.length] = elementArray[i];
			}
		}
		return matchedArray;
	}
	
	function preloadImage(src, protocolDomain){
        if(protocolDomain){
                src = protocolDomain+src;
        }
        var image = new Image();
        image.src = src;

    }
    
	function preload_cart_images(prefix) {
	
		/* images from cart_info.jsp */
		var image1 = new Image();
		image1.src = prefix + '/images/logo_alt.gif';
		var image2 = new Image();
		image2.src = prefix + '/images/checkout.png';
		var image3 = new Image();
		image3.src = prefix + '/images/sign_in_pop.gif';
		var image4 = new Image();
		image4.src = prefix + '/images/close.gif';
		var image5 = new Image();
		image5.src = prefix + '/images/keep_shopping_txt.gif';
		var image6 = new Image();
		image6.src = prefix + '/images/hackersafe-2.gif';

		/* images from css */
		var image7 = new Image();
		image7.src = prefix + '/images/3.gif';
		var image8 = new Image();
		image8.src = prefix + '/images/fade.png';
		var image9 = new Image();
		image9.src = prefix + '/images/cart_top3.gif';
		var image10 = new Image();
		image10.src = prefix + '/images/cart_shade_tile.png';
		var image11 = new Image();
		image11.src = prefix + '/images/gradient_4.gif';
		var image12 = new Image();
		image12.src = prefix + '/images/cart_bottom.png';
		
		var image13 = new Image();
		image13.src = prefix + '/images/logo.png';
		var image14 = new Image();
		image14.src = prefix + '/images/checkout.gif';	
		var image15 = new Image();
		image15.src = prefix + '/images/bg.gif';
		var image16 = new Image();
		image16.src = prefix + '/images/cart_shade_tile2.gif';
		var image17 = new Image();
		image17.src = prefix + '/images/utility_nav_bg.gif';
		var image18 = new Image();
		image18.src = prefix + '/images/sign_in.gif';
		var image19 = new Image();
		image19.src = prefix + '/images/close_2.gif';
		var image20 = new Image();
		image20.src = prefix + '/images/submit2.gif';
		var image21 = new Image();
		image21.src = prefix + '/images/international.gif';
		var image22 = new Image();
		image22.src = prefix + '/images/back.gif';
		var image23 = new Image();
		image23.src = prefix + '/images/continue_2.gif';
		
		/*nav*/
		var image24 = new Image();
		image24.src = prefix + '/images/nav_bg.gif';
		var image25 = new Image();
		image25.src = prefix + '/images/nav.gif';
		var image26 = new Image();
		image26.src = prefix + '/images/nav_corner_r.png';
		var image27 = new Image();
		image27.src = prefix + '/images/main_bg.gif';		
		var image28 = new Image();
		image28.src = prefix + '/images/shadow.png';		
		var image29 = new Image();
		image29.src = prefix + '/images/top_shade.png';		
		
		var image30 = new Image();
		image30.src = prefix + '/images/styles_bg.gif';		
		var image31 = new Image();
		image31.src = prefix + '/images/delete_x.png';
		var image31 = new Image();
		image31.src = prefix + '/images/item_slot_blink.gif';
		var image32 = new Image();
		image32.src = prefix + '/images/up.gif';
		var image33 = new Image();
		image33.src = prefix + '/images/down.gif';
		var image34 = new Image();
		image34.src = prefix + '/images/sizechart_button.gif';	// replace foot_go.gif with this 
		var image35 = new Image();
		image35.src = prefix + '/images/close_x.gif';
		var image36 = new Image();
		image36.src = prefix + '/images/thawte.gif';
		var image37 = new Image();
		image37.src = prefix + '/images/gradient_2.gif';
		var image38 = new Image();
		image38.src = prefix + '/images/cart_bg.gif';
		var image39 = new Image();
		image39.src = prefix + '/images/cart_bg.gif';
		var image40 = new Image();
		image40.src = prefix + '/images/empty_bg.gif';
				
		var image41 = new Image();
		image41.src = prefix + '/images/keep_shopping.gif';
		var image42 = new Image();
		image42.src = prefix + '/images/continue.gif';
		
	}
	
	function preload_cat_overlay(prefix) {
		var image1 = new Image();
		image1.src = prefix + '/images/popup_bg.png';
	}
	
	function preload_atc(prefix) {
		var image1 = new Image();
		image1.src = prefix + '/images/add_to_cart_over.gif';
		
		var image2 = new Image();
		image2.src = prefix + '/images/add_to_cart.gif';
	}
	
	function preload_ajax_loader(prefix) {
		var image1 = new Image();
		image1.src = prefix + '/images/fade.png';
	}
	
//original file: cart_scrolling.js----------------------------------------------------------

	function cart_scrolling(){
		
		var scrollId = document.getElementById('scroll');
		var cartItems = document.getElementById('cartitems');

		if (!cartItems) { return; }

		/* there should be at least 3 */
		var sets = cartItems.getElementsByTagName('li');

		/* last row */
		var startCartPos = document.getElementById('startCartPos');
		var start = parseInt(startCartPos.value);	// start is 0-based
		
		for (var i=0; i < sets.length; i++){
			if (i >= start && i < start + 4){
				sets[i].style.display = "block";
			}else{
				sets[i].style.display = "none";
			}
		}
		
		var pageup = document.getElementById('pageup');
		attachEventListener(pageup, "click", scrollUp, false);
		if (start > 0){
			pageup.style.display = "";
		}else{
			pageup.style.display = "none";
		}
		
		var pagedown = document.getElementById('pagedown');
		attachEventListener(pagedown, "click", scrollDown, false);
		if (start + 4 < sets.length){
			pagedown.style.display = "";
			
		}else{
			pagedown.style.display = "none";
		}
		
	}

	
	/* use this if you are hiding all but the last three rows */
	function scrollDown() {
		var scrollId = document.getElementById('scroll');
		var cartItems = document.getElementById('cartitems');

		if (!cartItems) { return; }

		/* there should be at least 3 */
		var sets = cartItems.getElementsByTagName('li');

		/* last row */
		var startCartPos = document.getElementById('startCartPos');
		var start = parseInt(startCartPos.value);

		if (start + 3 + 3 < sets.length){	// start + 3 + 3 = index of last li to show if we scroll down 3
			start = start + 3; 
			
		}else{
			start = sets.length - 4;
		}
		startCartPos.value = start;
		
		for (var i=0; i < sets.length; i++){
			if (i >= start && i < start + 4){
				sets[i].style.display = "block";
			}else{
				sets[i].style.display = "none";
			}
		}
		
		
		var pageup = document.getElementById('pageup');
		if (start > 0){
			pageup.style.display = "";
		}else{
			pageup.style.display = "none";
		}
		
		
		var pagedown = document.getElementById('pagedown');
		if (start + 4 < sets.length){
			pagedown.style.display = "";
		}else{
			pagedown.style.display = "none";
		}
	}

	/* use this if you are hiding all but the last three rows */
	function scrollUp() {
		var scrollId = document.getElementById('scroll');
		var cartItems = document.getElementById('cartitems');

		if (!cartItems) { return; }

		/* there should be at least 3 */
		var sets = cartItems.getElementsByTagName('li');

		/* last row */
		var startCartPos = document.getElementById('startCartPos');
		var start = parseInt(startCartPos.value);

		if (start - 3 >= 0 ){	// start + 3 + 3 = index of last li to show if we scroll down 3
			start = start - 3; 
		}else{
			start = 0
		}
		startCartPos.value = start;
		
		for (var i=0; i < sets.length; i++){
			if (i >= start && i < start + 4){
				sets[i].style.display = "block";
			}else{
				sets[i].style.display = "none";
			}
		}
		
		
		var pageup = document.getElementById('pageup');
		if (start > 0){
			pageup.style.display = "";
		}else{
			pageup.style.display = "none";
		}
		
		
		var pagedown = document.getElementById('pagedown');
		if (start + 4 < sets.length){
			pagedown.style.display = "";
		}else{
			pagedown.style.display = "none";
		}
	}
	
//original file: cart.js----------------------------------------------------------
	 
	addLoadListener(hoverCheckout);
	
	addLoadListener(hoverDelete);
	
	/*on detail page when you hover over the atc button */
	addLoadListener(addCartHover);
	
	/*show a different color when they hover over arrow when their is more than 9 products in the cart */
	addLoadListener(hoverArrow);
	
	/* product detail page, a new image is shown when customer hover over different views */
	addLoadListener(viewHover);
	
	   
	   /**
	    * Update the cart status that is shown on the static page
	    */
		function updateCart(response, arg) {
			
			asyncGet(arg.context + '/templates/cart_info.jsp', 'updateCartDisplay', {'elementId': arg.elementId});

		}

		function updateCartDisplay(response, arg) {
		
			document.getElementById(arg.elementId).innerHTML= response;
			
			//show up and down arrow if necessary
			cart_scrolling();
			
			
			
			/* Fix IE png transparency issue, we need timeout because we need the checkout.png image to
			 * be downloaded FIRST before we pngfix it, or IE6 will be stuck on downloading checkout.png
			 */ 
 			var arVersion = navigator.appVersion.split("MSIE")
			var version = parseFloat(arVersion[1])
			if ((version < 7) && (document.body.filters)){
				pngfixer(document.getElementById('checkout'), '');
				hoverCheckout();
			}
			
			hoverDelete();
			
			setHeight();
			
			load_javascript(staticPath+"/scripts/size_chart.js");

			// these are called with addLoadListener; 
			// but when cart_info.jsp was updated via ajax, functions added via addLoadListener doesn't get executed
			// guess because page wasn't loaded. So we will call these load listener for stuff inside  cart_info.jsp
			 goSizeHover();
             openSideSizeChart();
             hoverCheckout();
             updateButtonSizeHover();

			
			/* Alternate IE solution...			
			if ((version < 7) && (document.body.filters))
			{
				setTimeout("pngfixer(document.getElementById('checkout'), '');", 500);
				setTimeout("hoverCheckout()", 750);
			}
			*/
		}
		
		/**
		 * Updates the layer(popup) div contain the checkout page.
		*/
		function updateCOPage(response, arg) {
		
			var pos = response.indexOf("Thank You for Your Order");
			
			if(pos >=0) {
				location.href = arg.success_url;
			
			} else {
				document.getElementById(arg.elementId).innerHTML= response;
				//close the ajax loader
				closeAjaxLoader();
			}
			
			myregexp = new RegExp("<!--current_page:(.*)-->");
            mymatch = myregexp.exec(response);
            
            if(mymatch){
                current_co = mymatch[1];
                
                yahoo_tracking();
                google_tracking();
            }
            
		}
		
		

		
		function multiShipment(vf, context) {
         						
 			var step = document.getElementById("STEP");
 			step.value = "10";
 						
 			var successMultiShipCheckout = document.getElementById("successMultiShipCheckout");
 			
 			//alert('the value for success multi co is ' + successMultiShipCheckout.value);
 			
 			var successCheckout = document.getElementById("successCheckout");
 					
 			successCheckout.value = successMultiShipCheckout.value;
 			
 			var field = document.createElement("input");
			field.setAttribute("type","hidden");
			field.setAttribute("value","");
			field.setAttribute("name","goto_multiship");
			vf.appendChild(field);
 			asyncPost(context + '/servlet/Cart', vf, 'updateCOPage', {'elementId': 'co_top'});
         						
         }
         
         
         /*
         *  We could not using quotes in the jsonString (issue with escaping).  Instead, we used "::", so we need to search and replace.
	     */
         
         function onShippingMethodChangeUpdateTotalDiv(jsonString) {
			
			jsonString = jsonString.replace(/::/g, '"');
			var shippingJSONObject = eval( '(' + jsonString + ')' );
			var totalPrice = document.getElementById('totalPrice');
			var taxAmount = document.getElementById('taxAmount');
			var shippingDiscount = document.getElementById('shippingDiscount');
			var shippingMethod = document.getElementById('shipping_method_id');
			
			//alert('the selected in is ' + shippingMethod.selectedIndex);
			
			for(sm in shippingJSONObject.totalPrice) {
				
				if(shippingMethod.options[shippingMethod.selectedIndex].value == sm) {
				
					totalPrice.innerHTML = shippingJSONObject.totalPrice[sm];
				}	
					
			}
				
			for(sm in shippingJSONObject.tax) {
				
				if(shippingMethod.options[shippingMethod.selectedIndex].value == sm) {
					taxAmount.innerHTML = shippingJSONObject.tax[sm]
				}
					
			}
			
			if(shippingDiscount) {	
				for(sm in shippingJSONObject.shippingDiscount) {
					
					if(shippingMethod.options[shippingMethod.selectedIndex].value == sm) {
						shippingDiscount.innerHTML = shippingJSONObject.shippingDiscount[sm];
					}
				}
			}

		}
		
		
		
		function giftWrapStatus() {
 						
 			var addGiftWrapping = document.getElementById("add_gift_wrapping");
 			var giftMessage = document.getElementById("gift_message_span");
 						
 			if(addGiftWrapping.checked) {
 							
 				giftMessage.style.visibility = 'visible';
 							
 			} else {
 							
 				giftMessage.style.visibility = 'hidden';
 				giftMessage.value= '';
 			}
 						
 		}
 		
 		function giftWrapStatus(k) {
						
			var addGiftWrapping = k.length > 0 ? document.getElementById("add_gift_wrapping_" + k) : document.getElementById("add_gift_wrapping");
			var giftMessage = k.length > 0 ? document.getElementById("gift_message_span_" + k) : document.getElementById("gift_message_span");
						
			if(addGiftWrapping.checked) {
							
				giftMessage.style.visibility = 'visible';
			
			} else {
							
				giftMessage.style.visibility = 'hidden';
				giftMessage.value= '';
			}
						
		}
		
		function handle_login_out(response, arg){
			document.getElementById(arg.elementId).innerHTML=response;
		}
		
		var imageJSON_arr = {};
		var mainViewImages = {};
		
		/*
		*	When a user select a color on the product detail page.
		* 1. we update the images
		* 2. update hidden form field choiceName_1 with the selected color value.
		* 3. update size dropdown options and deselect previous selected size if any
		* 4. change css class of selected color to indicate to user and deselect any other selected color option
		* 5. show selected color the "Choose your color" pill drop down 
		*
		*/	
        function updateProductImageColorDetails(context, color_choice_value_id, color_name, product_id, imageJSON, sku_id) {

            //store the imageJSON globally, so that contextual update might update it later
            if(typeof imageJSON_arr[''+color_choice_value_id] == "undefined")
			imageJSON_arr[''+color_choice_value_id] = imageJSON;
            	else
			imageJSON = imageJSON_arr[''+color_choice_value_id];
            /*Step 1 */

            //we need to substitute all "::" with quotes
            imageJSON = imageJSON.replace(/::/g, "\"");

            var imageJSONObj = eval('(' + imageJSON + ')');

            var main_view = document.getElementById('main_view');

            mainViewImages[color_choice_value_id+'_'+product_top_tag_id] = imageJSONObj.images[0].pv_1_m;
            mainViewImages[color_choice_value_id+'_'+product_angle_tag_id] = imageJSONObj.images[1].pv_2_m;
            mainViewImages[color_choice_value_id+'_'+product_side_tag_id] = imageJSONObj.images[2].pv_3_m;
            //dumpProps(mainViewImages);

            //thumbnail 3
            if(imageJSONObj.images[2].pv_3_m) {
                    change_mouseover_image_ie6_v2("view3", "product_main_image", color_choice_value_id+'_'+product_side_tag_id, '', 'main_view');
                    //main_view.className = "product";
                    //swap_image("product_main_image", imageJSONObj.images[2].pv_3_m);
                     var imagePV3 = new Image();
					imagePV3.src = imageJSONObj.images[2].pv_3_m;
                    //main_view.src= imagePV3.src;
                    preloadImage(imageJSONObj.images[2].pv_3_m, secureProtocolDomain);
            }

            //thumbnail 1
            if(imageJSONObj.images[0].pv_1_m) {
                    change_mouseover_image_ie6_v2("view1", "product_main_image", color_choice_value_id+'_'+product_top_tag_id, '', 'main_view');
                    //main_view.className = "product";
                    //swap_image("product_main_image", imageJSONObj.images[0].pv_1_m);
                    var imagePV1 = new Image();
					imagePV1.src = imageJSONObj.images[0].pv_1_m;
                    //main_view.src= imagePV1.src;
                    preloadImage(imageJSONObj.images[0].pv_1_m, secureProtocolDomain);
            }



            //thumbnail 2
            if(imageJSONObj.images[1].pv_2_m) {
                    change_mouseover_image_ie6_v2("view2", "product_main_image", color_choice_value_id+'_'+product_angle_tag_id, '', 'main_view');
                    //main_view.className = "product";
                    //swap_image("product_main_image", imageJSONObj.images[1].pv_2_m);
                    var imagePV2 = new Image();
					imagePV2.src = imageJSONObj.images[1].pv_2_m;
                    main_view.src= imagePV2.src;
                    preloadImage(imageJSONObj.images[1].pv_2_m, secureProtocolDomain);
            }
			
			var arVersion = navigator.appVersion.split("MSIE");
			var version = parseFloat(arVersion[1]);
			if (version < 7){
				//After a main image was swapped, run this once for IE6 browser for png transparency fix
				pngfixerproduct(main_view, '', '234', '282', '');
			}
			
			
						
			/*Step 2*/
			document.product_form.choiceName_1.value = color_choice_value_id;
			
			/*Step 3*/
			document.product_form.choiceName_2.value = '';
			var sizeInfo = document.getElementById('shoesize');
			if(sizeInfo)
				sizeInfo.innerHTML = 'Choose Your Size';
			displayAddToCartButton(staticPath, context, '2', '1', sku_id);
			
			document.getElementById("sizechart").innerHTML="<table cellspacing=\"0\" class=\"sizetable\"><tbody><tr><td colpan=\"4\" style=\"height:10px;\">please wait...</td></tr></tbody></table>";
			
			asyncGet(context + '/product/product_size.jsp', 'copyToElementInnerHtml', {'elementId': 'sizechart'}, 'product_id=' + product_id + '&color_choice_value_id=' + color_choice_value_id);
			
			/*Step 4*/
			var productColorOptionUL = document.getElementById('product_color_options');
			var sets = productColorOptionUL.getElementsByTagName('ul');

			for (i=0; i<sets.length; i++) {
				sets[i].getElementsByTagName('li')[0].className = ""; 
			}
			
			var selectProductColorLI = document.getElementById('color_' + color_choice_value_id);
			if(selectProductColorLI)
				selectProductColorLI.className = 'currentstyle';
		
			/*Step 5*/
			var colorPill = document.getElementById('shoestyle');
			if(colorPill)
				colorPill.innerHTML = '<span class="sizing">'+color_name+'</span>';
		
			recentlyViewedSku(context, sku_id);
		
			scrollTo(0,0);
			
			/** for contextual editing, we need to know which color of product it's editing**/
            storeColorId(color_choice_value_id);
            storeTagId(product_angle_tag_id);
		}
		
		/*
		*	When a user select a size on the product detail page
		*	1. update hidden form field choiceName_2 with the selected size value.
		*   2. hide the size dropdown element.
		* 	3. update size info element with selected size value
		*/
		function updateProductSizeDetails(size_choice_value_id, size_choice_name, sizeElement) {
			document.product_form.choiceName_2.value = size_choice_value_id;
			hideElement(sizeElement);
			
			var sizeInfo = document.getElementById('shoesize');
			if(sizeInfo)
				sizeInfo.innerHTML = '<span class="sizing">' + size_choice_name + '</span>';
		}
		
		// calls updateProductSizeDetails(size_choice_value_id, size_choice_name, sizeElement)
		// and also the function to display the correct "add to cart" button
		function updateProductSizeDetailsShowCartButton(staticPath, contextPath, sizeChoiceNameId, colorChoiceNameId, size_choice_value_id, size_choice_name, sizeElement, sku_id) {
			updateProductSizeDetails(size_choice_value_id, size_choice_name, sizeElement);
			displayAddToCartButton(staticPath, contextPath, sizeChoiceNameId, colorChoiceNameId, sku_id);
		}
		
		
		/*
		*	Same as above, but for popups. We need a different name than 'shoesize'
		*   to distinguish parent window and children window elements. Currently
		*   specifically used by out of stock popup.
		*/
		function updateProductSizeDetailsPopup(size_choice_value_id, size_choice_name, sizeElement) {
			document.outofstockform.choiceName_2.value = size_choice_value_id;
			hideElement(sizeElement);
			
			var sizeInfo = document.getElementById('shoesize_popup');
			if(sizeInfo)
				sizeInfo.innerHTML = size_choice_name;
				
			/* update hidden param as well, this is what the form actually needs to process */
			
		}
		
		
		
		
		/*
		*	When a user select a size on the product cat all page
		*	1. update hidden form field choiceName_2 with the selected size value.
		*   2. hide the size dropdown element.
		* 	3. update size info element with selected size value
		*/
		function updateCatProductSizeDetails(key_id, size_choice_value_id, size_choice_name, sku_id) {
			var sizeChoice = eval('document.form_' + key_id + '.choiceName_2');
			sizeChoice.value = size_choice_value_id;
			
			var selectedSku = eval('document.form_' + key_id + '.selectedSku');
			selectedSku.value = sku_id;
			
			hideElement('sizechart_' + key_id);
			
			var sizeInfo = document.getElementById('shoesize_' + key_id);
			if(sizeInfo)
				sizeInfo.innerHTML = size_choice_name;
			var img = document.getElementById('shoeimg_' + key_id);
            if(img){
                    img.src=staticPath+'/images/add.gif';
            }
		}
		
		
		function showSizeElement(d) {
			if(!document.product_form.choiceName_1.value) {alert('Please select a color/style first.');	return false; }
			showElement(d);
		}
		
		
		/* HOVER DELETE BUTTONS IN SHOPPING CART */

		function hoverDelete() {
			var buttons = getElementsByAttribute('class', 'delete');
			if (!buttons) { return; }
		
			for (i=0; i<buttons.length; i++) {
				attachEventListener(buttons[i], "mouseover", showDel, false);
				attachEventListener(buttons[i], "mouseout", hideDel, false);
			}
			
		}
		
		function showDel(event) {
			if (typeof event == "undefined") {
				event = window.event;	
			}
			var element = getEventTarget(event);
			var picture;
			if(typeof staticPath == 'undefined'){
		        picture = "/images/delete_x_over.gif";
		    }else{
		        picture = staticPath+"/images/delete_x_over.gif";
		    }
			element.src = picture;
			//alert ('me');
		}
		
		function hideDel(event) {
			if (typeof event == "undefined") {
				event = window.event;	
			}
			var element = getEventTarget(event);
			var picture;
			
			if(typeof staticPath == 'undefined'){
		        picture = "/images/delete_x.gif";
		    }else{
		        picture = staticPath+"/images/delete_x.gif";
		    }
		    
			element.src = picture;
			//alert ('me');
		}
				
		
		
		
		
		/* HOVER CHECKOUT BUTTON */

	function hoverCheckout() {
		var checkout = document.getElementById('checkout');
		if (!checkout) { return; }

			attachEventListener(checkout, "mouseover", checkHover, false);
			attachEventListener(checkout, "mouseout", checkNormal, false);
	}

	function checkHover(event) {
		if (typeof event == "undefined") {
			event = window.event;	
		}
		var element = getEventTarget(event);
		var picture = "/images/checkout_on.gif";
		element.src = picture;
		
		var arVersion = navigator.appVersion.split("MSIE");
		var version = parseFloat(arVersion[1]);
		if (version < 7){
			// Fix png for IE
			pngfixer(element, " onmouseout=\"checkNormal()\" ");
		}
	}

	function checkNormal(event) {
		if (typeof event == "undefined") {
			event = window.event;	
		}
		var element = getEventTarget(event);
		var picture = "/images/checkout.gif";	
		element.src = picture;

		var arVersion = navigator.appVersion.split("MSIE");
		var version = parseFloat(arVersion[1]);
		if (version < 7){
			// Fix png for IE
			pngfixer(element, " onmouseover=\"checkHover()\" ");
		}
	}

	/* FOR IE TO HOVER SIDEBAR SHOPPING ITEMS */
	function hoverLi(){
		var cartItems = document.getElementById('cartitems');
		if (!cartItems) { return; }
		var lis = cartItems.getElementsByTagName('li');
		
		for (i=0; i<lis.length; i++) {
			attachEventListener(lis[i], "mouseover", hoverProduct, false);
			attachEventListener(lis[i], "mouseout", normalProduct, false);
		}
	}
	
	
	/*extends the grey bg for popup cart page */
	function setHeight(){

            var container = document.getElementById('container');

            if (!container) { return; };

            var pixelHeight = container.offsetWidth;

            var co = document.getElementById('co_top');

            if (!co) { return; };

            co.style.height = pixelHeight + "px";

}





		
		/* ADD TO CART HOVER */
		function addCartHover() {
			var thisID = document.getElementById('addtocart');
			if (!thisID) { return; }
			attachEventListener(thisID, "mouseover", cartHover, false);
			attachEventListener(thisID, "mouseout", cartNormal, false);
		}
		
		function cartHover(event) {
			if (typeof event == "undefined") {
				event = window.event;	
			}
			var element = getEventTarget(event);
			var picture = "/images/add_to_cart_over.gif";
			element.src = picture;
		}
		
		function cartNormal(event) {
			if (typeof event == "undefined") {
				event = window.event;	
			}
			var element = getEventTarget(event);
			var picture = "/images/add_to_cart.gif";
			element.src = picture;
		}
		
		function displayAddToCartButton(staticPath, contextPath, sizeChoiceNameId, colorChoiceNameId, sku_id) {
			var cart = document.getElementById('cart');
			
			if (cart) {
				var sizeVal = eval('document.product_form.choiceName_' + sizeChoiceNameId + '.value');
				var colorVal = eval('document.product_form.choiceName_' + colorChoiceNameId + '.value');
				
				if (sizeVal == '' || colorVal == '') {
					cart.style.background = 'url(' + staticPath + '/images/3_dimmed.gif)';
					cart.style.backgroundRepeat = 'no-repeat';
					cart.innerHTML = '<input type="image" src="' + staticPath + '/images/add_to_cart_out.gif" alt="Add to cart" class="submit" onclick="return false;">';
				} else {
					cart.style.background = 'url(' + staticPath + '/images/3.gif)';
					cart.style.backgroundRepeat = 'no-repeat';
					cart.innerHTML = '<input type="image" src="' + staticPath + '/images/add_to_cart.gif" id="addtocart" alt="Add to cart" class="submit" onclick="showBlinkingCartItem('+sku_id+'); asyncPost(\'' + contextPath + '/servlet/Cart\', this.form, \'updateCart\', {\'elementId\': \'cart_info\', \'context\' : \'' + contextPath + '\'}); return false;" />';
				}
			}		
		}
		
		
		
		
		
		
		
		
		
		
		
		
		/* PAGING ARROWS HOVER */
		function hoverArrow(){
				var pageup = document.getElementById('pageup');
				var pagedown = document.getElementById('pagedown');
				if (!pageup) { return };
				if (!pagedown) { return };
				
				attachEventListener(pageup, "mouseover", hoverUpArrow, false);
				attachEventListener(pageup, "mouseout", unHoverUpArrow, false);
				attachEventListener(pagedown, "mouseover", hoverDownArrow, false);
				attachEventListener(pagedown, "mouseout", unHoverDownArrow, false);
		}
		
		function hoverDownArrow(event) {
			if (typeof event == "undefined") {
				event = window.event;	
			}
			var element = getEventTarget(event);
			var picture = "/images/down_over.gif";
			element.src = picture;
		}
		
		function unHoverDownArrow(event) {
			if (typeof event == "undefined") {
				event = window.event;	
			}
			var element = getEventTarget(event);
			var picture = "/images/down.gif";
			element.src = picture;
		}
		
		function hoverUpArrow(event) {
			if (typeof event == "undefined") {
				event = window.event;	
			}
			var element = getEventTarget(event);
			var picture = "/images/up_over.gif";
			element.src = picture;
		}
		
		function unHoverUpArrow(event) {
			if (typeof event == "undefined") {
				event = window.event;	
			}
			var element = getEventTarget(event);
			var picture = "/images/up.gif";
			element.src = picture;
		}
		
		
		
		
		
		/* VIEW DETAIL HOVERS */
		function viewHover(){
				var view1 = document.getElementById('view1');
				var view2 = document.getElementById('view2');
				var view3 = document.getElementById('view3');
				if (!view1) { return };
				if (!view2) { return };
				if (!view3) { return };
				
				attachEventListener(view1, "mouseover", hoverView1, false);
				attachEventListener(view1, "mouseout", unHoverView1, false);
				attachEventListener(view2, "mouseover", hoverView2, false);
				attachEventListener(view2, "mouseout", unHoverView2, false);
				attachEventListener(view3, "mouseover", hoverView3, false);
				attachEventListener(view3, "mouseout", unHoverView3, false);
		}
		
        function storeColorId(color_id){
                /**for contextual editing, we need to know what tag it's using**/
                var param_obj = document.getElementById('ce_main_view_image_extra_params');
                if (param_obj != null && typeof param_obj != "undefined") {
                        param_obj.value = param_obj.value.replace(/color_id=[^&\"]*/,'color_id='+color_id);
                        //alert(param_obj.value);
                }


        }

        function storeTagId(tag_id){
                /**for contextual editing, we need to know what tag it's using**/
                var param_obj = document.getElementById('ce_main_view_image_extra_params');
                if (param_obj != null && typeof param_obj != "undefined") {
                        param_obj.value = param_obj.value.replace(/tag_id=[^&\"]*/,'tag_id='+tag_id);
                }


        }
        function hoverView1(event) {
                if (typeof event == "undefined") {
                        event = window.event;
                }
                var element = getEventTarget(event);
                var picture = "/images/view1_over.gif";
                element.src = picture;

                storeTagId(product_top_tag_id);
                //alert(document.getElementById('ce_main_view_image_extra_params').value);
                //ce_product_tag_id=product_angle_tag_id;
        }

        function unHoverView1(event) {
                if (typeof event == "undefined") {
                        event = window.event;
                }
                var element = getEventTarget(event);
                var picture = "/images/view1.gif";
                element.src = picture;
        }

        function hoverView2(event) {
                if (typeof event == "undefined") {
                        event = window.event;
                }
                var element = getEventTarget(event);
                var picture = "/images/view2_over.gif";
                element.src = picture;
                storeTagId(product_angle_tag_id);
        }

        function unHoverView2(event) {
                if (typeof event == "undefined") {
                        event = window.event;
                }
                var element = getEventTarget(event);
                var picture = "/images/view2.gif";
                element.src = picture;
        }

        function hoverView3(event) {
                if (typeof event == "undefined") {
                        event = window.event;
                }
                var element = getEventTarget(event);
                var picture = "/images/view3_over.gif";
                element.src = picture;

                storeTagId(product_side_tag_id);
        }
		
		function unHoverView3(event) {
			if (typeof event == "undefined") {
				event = window.event;	
			}
			var element = getEventTarget(event);
			var picture = "/images/view3.gif";
			element.src = picture;
		}

		
	function closeSizeChart(element) {
		element.style.display = 'none';
	}
	
	function mouseLeaves (element, evt) {
		if (typeof evt.toElement != 'undefined' && typeof element.contains != 'undefined') {
			return !element.contains(evt.toElement);
		} else if (typeof evt.relatedTarget != 'undefined' && evt.relatedTarget) {
			return !contains(element, evt.relatedTarget);
		}
	}

	function contains (container, containee) {
		while (containee) {
			if (container == containee) {
				return true;
			}
			containee = containee.parentNode;
		}
		return false;
	}
	
	/* blink the next cart item slot where the item will be added to */
	function showBlinkingCartItem(sku_id) {
		var matching = document.getElementById('cart_item_'+sku_id);
		if (!matching){
			var nextCartItem = document.getElementById('empty_item_slot');
			nextCartItem.style.visibility = 'visible';
		}else{
			var picture = "/images/item_slot_blink.gif";	 
			matching.src = picture;
		}
	}
	
	/* hover effect for header sign in, this is put in place to allow IE6 browsers to maintain hover 
	 * effect WITHOUT putting a value in href because action for sign-in link is a popup */
	function hoverHeaderSignin(){
		document.getElementById('header_signin').style.backgroundPosition = '-265px  62px';
	}
	function normalHeaderSignin(){
		document.getElementById('header_signin').style.backgroundPosition = '-265px 0';
		document.getElementById('header_signin').style.left = '265px';
	}
	
	/* call this to cookie the customer that he/she left the cart - used to determine whether to display product detail flash */
	function setJustLeftCart() {
		createCookie('just_left_cart','true');
	}
	
	/* call this to determine if the customer just left the cart - this also optionally removes the cookie */
	function justLeftCart(remove) {
		var val = readCookie('just_left_cart');
		if (remove) {
			eraseCookie('just_left_cart');
		}
		return val == 'true';
	}

//original file: login.js---------------------------------------------------------
addLoadListener(userLogin);

/* LOGIN */

function userLogin() {
	var login = document.getElementById('login');
	var closeLogin = document.getElementById('closelog');
	attachEventListener(closeLogin, "mouseover", hoverCloseLogin, false);
	attachEventListener(closeLogin, "mouseout", unHoverCloseLogin, false);
	attachEventListener(login, "click", showLogIn, false);
	attachEventListener(closeLogin, "click", hideLogIn, false);
}

function showLogIn() {
	var logdiv = document.getElementById('logincontain');
	var login = document.getElementById('login');

	/* We need to disable the display of login form when user is already signed in */
	if (logdiv != "" && login.className != "signedin") { 
 		logdiv.style.display = "block";	
	};
}

function hideLogIn() {
	var logdiv = document.getElementById('logincontain');
	var login = document.getElementById('login');

	/* We need to disable the display of login form when user is already signed in */	
	if (logdiv != "" && login.className != "signedin") { 
 		logdiv.style.display = "none";	
	};
}

function hoverCloseLogin(event) {
	if (typeof event == "undefined") {
		event = window.event;	
	}
	var element = getEventTarget(event);
	var picture;
	if(typeof staticPath == 'undefined'){
        picture = "/images/close_2_over.gif";
    }else{
        picture = staticPath+"/images/close_2_over.gif";
    }
	element.src = picture;
}

function unHoverCloseLogin(event) {
	if (typeof event == "undefined") {
		event = window.event;	
	}
	var element = getEventTarget(event);
	var picture;
	if(typeof staticPath == 'undefined'){
        picture = "/images/close_2.gif";
    }else{
        picture = staticPath+"/images/close_2.gif";
    }
	element.src = picture;
}

//original file: nav.js-----------------------------------------------------------

	var show_discount_in_nav = readCookie('show_discount_in_nav');
	if(show_discount_in_nav != 1)
		addLoadListener(showSubnav);
	
	/* DISPLAY SUBNAVIGATION */

function showSubnav() {
	var community = document.getElementById('community');
	var subNav = document.getElementById('subnav');
	if (!community) { return; }

	attachEventListener(community, "mouseover", displayNav, false);
	attachEventListener(community, "mouseout", hideNav, false);
	attachEventListener(subNav, "mouseover", displayNav, false);
	attachEventListener(subNav, "mouseout", hideNav, false);
	
}

function displayNav(event) {
	if (typeof event == "undefined") {
		event = window.event;	
	}
	var element = getEventTarget(event);

	var subNav = document.getElementById('subnav');
	if (!subNav) { return; }
	subNav.style.display = "block";	
}

function hideNav(event) {
	if (typeof event == "undefined") {
		event = window.event;	
	}
	var element = getEventTarget(event);

	var subNav = document.getElementById('subnav');
	if (!subNav) { return; }
	subNav.style.display = "none";	
}

function getEventTarget(event) {
	var targetElement = null;
	
	if (typeof event.target != "undefined") {
		targetElement = event.target;	
	} else {
		targetElement = event.srcElement;	
	}
	
	while (targetElement.nodeType == 3 && targetElement.parentNode != null) {
		targetElement = targetElement.parentNode;	
	}
	
	return targetElement;
}

//original file: country.js-----------------------------------------------------------
	addLoadListener(countryDropdown);


	/* INTERNATIONAL DROPDOWN */
	
	function countryDropdown() {
		var countryDiv = document.getElementById('international');
		var closeCountry = document.getElementById('closecountry');

		attachEventListener(closeCountry, "mouseover", hoverCloseCountries, false);
		attachEventListener(closeCountry, "mouseout", unHoverCloseCountries, false);
		attachEventListener(countryDiv, "click", showCountries, false);
		attachEventListener(closeCountry, "click", hideCountries, false);
	}
	
	function showCountries() {
		var countryDiv = document.getElementById('countrycontain');
		if (countryDiv) { 
	 		countryDiv.style.display = "block";	
		}
	}
	
	function hideCountries() {
		var countryDiv = document.getElementById('countrycontain');
		if (countryDiv) { 
	 		countryDiv.style.display = "none";	
		}
	}
	
function hoverCloseCountries(event) {
	if (typeof event == "undefined") {
		event = window.event;	
	}
	var element = getEventTarget(event);
	var picture;
		
	if(typeof staticPath == 'undefined'){
        picture = "/images/close_2_over.gif";
    }else{
        picture = staticPath+"/images/close_2_over.gif";
    }
	element.src = picture;
}

function unHoverCloseCountries(event) {
	if (typeof event == "undefined") {
		event = window.event;	
	}
	var element = getEventTarget(event);
	
	var picture;
	if(typeof staticPath == 'undefined'){
        picture = "/images/close_2.gif";
    }else{
        picture = staticPath+"/images/close_2.gif";
    }
	element.src = picture;
}	

//original file: sizing.js-----------------------------------------------------------
addLoadListener(goSizeHover);

/* GO SIZE HOVER */
function goSizeHover() {
	var thisID = document.getElementById('gobutton');
	if (!thisID) { return; }
	attachEventListener(thisID, "mouseover", goHover, false);
	attachEventListener(thisID, "mouseout", goNormal, false);
}

function goHover(event) {
	if (typeof event == "undefined") {
		event = window.event;	
	}
	var element = getEventTarget(event);
	var picture = "/images/sizechart_button_on.gif";	// replace foot_go_over.gif with this 
	element.src = picture;
}

function goNormal(event) {
	if (typeof event == "undefined") {
		event = window.event;	
	}
	var element = getEventTarget(event);
	var picture = "/images/sizechart_button.gif";	// replace foot_go.gif with this 
	element.src = picture;
}


/* UPDATE BUTTON HOVER */
addLoadListener(updateButtonSizeHover);

function updateButtonSizeHover() {
	var thisID = document.getElementById('update_button');
	if (!thisID) { return; }
	attachEventListener(thisID, "mouseover", updateButtonHover, false);
	attachEventListener(thisID, "mouseout", updateButtonNormal, false);
}

function updateButtonHover(event) {
	if (typeof event == "undefined") {
		event = window.event;	
	}
	var element = getEventTarget(event);
	var picture = "/images/update_cart_on.gif";	 
	element.src = picture;
}

function updateButtonNormal(event) {
	if (typeof event == "undefined") {
		event = window.event;	
	}
	var element = getEventTarget(event);
	var picture = "/images/update_cart.gif";	 
	element.src = picture;
}
//original file: popup.js-----------------------------------------------------------
/*
	This javascript class is responsible for showing a up. 
	It will adjust the position when the user scroll (horizon and vertical)
	
	Usage::

	url: the url that it need to async call to get content
	elementID: id of the document element it will populate the data into
	popUp(url, elementID) 
	
	
*/

	function popUp(url, elementID) {
	
		setHeight();
		popUpRelocate(elementID);
		asyncGet(url, 'updateCOPage', {'elementId': elementID});

		document.getElementById('co_top').style.display = "block";
		document.getElementById('pop_up_bg').style.display = "block";
		
		document.body.onscroll = popUpRelocate;
		window.onscroll = popUpRelocate;
	
	}
	
	function popUp(url, elementID, url_params) {
	
		setHeight();
		popUpRelocate(elementID);
		asyncGet(url, 'updateCOPage', {'elementId': elementID}, url_params);
		document.getElementById('co_top').style.display = "block";
		document.getElementById('pop_up_bg').style.display = "block";
		document.body.onscroll = popUpRelocate;
		window.onscroll = popUpRelocate;
	
	}
	
	function closePopUp() {
		document.getElementById("co").style.display="none"; 
		document.getElementById("co_top").style.display="none"; 
		document.getElementById("pop_up_bg").style.display = "none";
	}

	function scrolledX() {
		var scrolledX;
		if( self.pageYOffset ) {
		  scrolledX = self.pageXOffset;
		} else if( document.documentElement && document.documentElement.scrollTop ) {
		  scrolledX = document.documentElement.scrollLeft;
		} else if( document.body ) {
		  scrolledX = document.body.scrollLeft;
		}
		
		return scrolledX;
	}
	
	function scrolledY() {
		var scrolledY;
		if( self.pageYOffset ) {
		  scrolledY = self.pageYOffset;
		} else if( document.documentElement && document.documentElement.scrollTop ) {
		  scrolledY = document.documentElement.scrollTop;
		} else if( document.body ) {
		  scrolledY = document.body.scrollTop;
		}	
		
		return scrolledY;
	}


	function centerX() {
		
		var centerX;
		if( self.innerHeight ) {
		  centerX = self.innerWidth;
		} else if( document.documentElement && document.documentElement.clientHeight ) {
		  centerX = document.documentElement.clientWidth;
		} else if( document.body ) {
		  centerX = document.body.clientWidth;
		}
		
		return centerX;
	} 
	
	function centerY() {
	
		var centerY;
		if( self.innerHeight ) {
		  centerY = self.innerHeight;
		} else if( document.documentElement && document.documentElement.clientHeight ) {
		  centerY = document.documentElement.clientHeight;
		} else if( document.body ) {
		  centerY = document.body.clientHeight;
		}
	
		return centerY;	
	}
	
	function popUpRelocate() {
	
		var leftOffset = scrolledX() + 50;
		var topOffset = scrolledY() + 50;
		
		document.getElementById('co').style.top = topOffset + "px";
		document.getElementById('co').style.left = leftOffset + "px";
		
	}
	
	function showAjaxLoader() {
	
		setAjaxHelperHeight();
		document.getElementById('ajax_loader').style.display = "block";
	}
	
	function closeAjaxLoader() {
		document.getElementById('ajax_loader').style.display = "none";
	}
	
	function setAjaxHelperHeight(){

			var container = document.getElementById('container');
            if (!container) { return; };

            var pixelHeight = container.offsetWidth;
            var ajax_loader = document.getElementById('ajax_loader');

            if (!ajax_loader) { return; };

            ajax_loader.style.height = pixelHeight + "px";

	}
	
	
	function setHeight(){

            var container = document.getElementById('container');
            if (!container) { return; };

            var pixelHeight = document.body.offsetHeight;

            var co_top = document.getElementById('co_top');

            if (!co_top) { return; };

            co_top.style.height = pixelHeight + "px";
            
            var pop_up_bg = document.getElementById('pop_up_bg');

            if (!pop_up_bg) { return; };

            pop_up_bg.style.height = pixelHeight + "px";
	}
	

//original file: url.js-----------------------------------------------------------
/* any javascript functions that manipulate URLs should be placed here */

/* 
	pass in the protocol and domain and it will swap it into the _current_ location.
	you can use this to swap the current protocol and domain with a secure version.
*/
function swapProtocolDomain(protocolDomain) {

	/* no need to swap if they aren't different */
	var matchingIndex = window.location.href.indexOf(protocolDomain);
	if (matchingIndex > -1) {
		return window.location.href;
	}
	
	/* we'll search after the 7th char assuming "http://" */
	var slashIndex = window.location.href.indexOf('/', 7);
	
	/* if current protocol is "https://", we readjust to cater that instead */
	if(window.location.href.indexOf('https') > -1){
		slashIndex = window.location.href.indexOf('/', 8);
	}
	
	if (slashIndex > -1) {
		var swapOut = window.location.href.substr(0, slashIndex);
		var keep = window.location.href.substr(slashIndex);
		return protocolDomain + keep;
	} else {
		return protocolDomain;
	}
}

function gotoSwapProtocolDomain(protocolDomain){
        var resultURL = swapProtocolDomain(protocolDomain);
        if(window.location.href != resultURL){
                document.location=resultURL;
        }

}
//original file: tracking_code.js-----------------------------------------------------------

function yahoo_tracking(){

        page_name = current_co.replace('_body.jsp','.jsp');

        var ysm_accountid  = "1RMTCHKGUVVQGSVMHDL0GUDIQS0";
        load_javascript("//srv2.wa.marketingsolutions.yahoo.com" + "/script/ScriptServlet" + "?aid=" + ysm_accountid);

}

function google_tracking(){
        page_name = current_co.replace('_body.jsp','.jsp');

        var pageTracker = _gat._getTracker("UA-3801694-1");
        pageTracker._initData();
        pageTracker._trackPageview("/"+page_name);

}

function load_javascript(script_src){
        var script = document.createElement('script');
        script.type = 'text/javascript';
        script.src = script_src;
        document.getElementsByTagName('head')[0].appendChild(script);
}

//limit a textarea field to limited len. 
function EnforceMaximumLength(fld,len) {
		if(fld.value.length > len) { 			
			fld.value = fld.value.substr(0,len); 
		}
}

function flash_oos(context, product_id, color_id){
	scrollTo(0,0);
	popUp(context + '/leads/out_of_stock.jsp', 'co_top', 'product_id=' + product_id + '&color_choice_value_id=' + color_id + '&from=flash');
}
function flash_atc(context, product_id, sku_id, color_id, size_id){
	document.getElementById('flash_addToCart_color_input').value = color_id;
    document.getElementById('flash_addToCart_size_input').value = size_id;
    document.getElementById('flash_addToCart_product_id').value = product_id;
    showBlinkingCartItem(sku_id); 
    asyncPost(contextPath + '/servlet/Cart', document.getElementById('flash_addToCart_form'), 'updateCart', {'elementId': 'cart_info', 'context' : contextPath});
}
function flash_split(response, arg){
	//alert(response);
	if (response.indexOf('yes') >= 0){
		// in stock
		flash_atc(arg.context, arg.product_id, arg.sku_id, arg.color_id, arg.size_id);
	}else{
		// out of stock
		flash_oos(arg.context, arg.product_id, arg.color_id);
	}
}
function addToCartFromFlash(product_id, sku_id, size_id, color_id, context){
    //alert('Flash is calling to add sku ' + sku_id + ' to the cart: '+ product_id + '-' + size_id + '-' + color_id + '-' + context);
    asyncGet(context + '/category/ajax/isSkuInStock.jsp', 'flash_split', {'context':context, 'product_id':product_id, 'sku_id':sku_id, 'color_id':color_id, 'size_id':size_id}, 'sku_id=' + sku_id);
}