var W3CDOM = (document.createElement && document.getElementsByTagName);
var dirty = false;
function topnav()
{
        if (dirty) return;
	var moo = document.getElementsByClassName('over');
	var mouseOvers = new Array();
	var mouseOuts = new Array();

	for (var i=0; i < moo.length; i++) {
		moo[i].onmouseover = mouseGoesOver;
		moo[i].onmouseout = mouseGoesOut;
		var suffix = moo[i].src.substring(moo[i].src.lastIndexOf('.'));
		mouseOuts[i] = new Image();
		mouseOuts[i].src = moo[i].src;
		mouseOvers[i] = new Image();
		mouseOvers[i].src = moo[i].src.substring(0,moo[i].src.lastIndexOf('.')) + "_over" + suffix;
		moo[i].number = i;
	}
        dirty = true;
	function mouseGoesOver()
	{
		this.src = mouseOvers[this.number].src;
	}
	function mouseGoesOut()
	{
		this.src = mouseOuts[this.number].src;
	}
}

function popUp(url, height, width) {
	window.open(url, '', "width="+width+", height="+height+", resizable=yes, toolbar=no, menubar=no, location=no");
}

/* top nav tooltip */
Event.observe(window,"load",navToolTip);
var dv = null;
function navToolTip(e) {
	/* workaround until prototype library conflicts are resolved */
	var arr = new Array("primarynav_womens","primarynav_mens","primarynav_apartment","primarynav_sale","primarynav_general_category","primarynav_blog");
	for (var i=0; i<arr.length; i++) {
		var cur = $(arr[i]);
		if (cur) {
			var children = cur.descendants();
			children.each(function(c) {
				var curTag = c.tagName.toLowerCase();
				if (curTag.indexOf('a') >= 0) {
					if (c.title.toLowerCase().indexOf("mens") >= 0) {
						Event.observe(c, 'mouseover', shopMensAndWomen);
					} else if (c.title.toLowerCase().indexOf("apartment") >= 0) {
						Event.observe(c, 'mouseover', shopApartment);
					} else if (c.title.toLowerCase().indexOf("sale") >= 0) {
						Event.observe(c, 'mouseover', shopSale);
					} else if (c.title.toLowerCase().indexOf("gifts") >= 0) {
						Event.observe(c, 'mouseover', shopGifts);
					} else if (c.title.toLowerCase().indexOf("blog") >= 0) {
						Event.observe(c, 'mouseover', visitUoBlog);
					}
					Event.observe(c, 'mouseout', removeToolTip);
					c.removeAttribute("title");
				}
			});
		}
	}
}
function shopMensAndWomen(e) {
	createDiv('Shop Clothing, Accessories and Shoes', Event.pointerX(e), Event.pointerY(e));
}
function shopApartment(e) {
	createDiv('Shop Bedding, Wall Art, Furniture and More', Event.pointerX(e), Event.pointerY(e));
}
function shopSale(e) {
	createDiv('Shop Sale', Event.pointerX(e), Event.pointerY(e));
}
function shopGifts(e) {
	createDiv('Shop Holiday Gifts', Event.pointerX(e), Event.pointerY(e));
}
function visitUoBlog(e) {
	createDiv('Visit the UO Blog', Event.pointerX(e), Event.pointerY(e));
}
function createDiv(txt, x, y) {
	dv = document.createElement('div');
	document.body.appendChild(dv);
	//set the inner styling of the div tag 
	dv.style.position = "absolute";       
	dv.style.left = x + "px";
	dv.style.top = y + "px";
	dv.style.zIndex = 9999;
	dv.style.overflow = "hidden";
	dv.style.padding = "4px";
	dv.style.margin = "8px";
	dv.style.background = "#ffffff";
	dv.style.border = "solid 1px #999999";
	dv.style.color = "#999999";
	//set the html content inside the div tag
	dv.innerHTML = txt;
}
function removeToolTip() {
	document.body.removeChild(dv);
	dv = null;
}

/* tooltip for CID message */
var cidDiv = null;
Event.observe(window,"load",showCidToolTip);
Event.observe(window,"load",showSavedCidToolTip);
function showCidToolTip(e) {
	// check if objects exist
	if ($("cidToolTip")) {
		Event.observe($("cidToolTip"), 'mouseover', cidToolTip);
		Event.observe($("cidToolTip"), 'mouseout', removeCidToolTip);
	}
}
function showSavedCidToolTip(e) {
	if ($("savedCidToolTip")) {
		Event.observe($("savedCidToolTip"), 'mouseover', cidToolTip);
		Event.observe($("savedCidToolTip"), 'mouseout', removeCidToolTip);
	}
}
function createCidDiv(txt, x, y) {
	cidDiv = document.createElement('div');
	document.body.appendChild(cidDiv);
	//set the inner styling of the div tag 
	cidDiv.style.position = "absolute";       
	cidDiv.style.left = x + "px";
	cidDiv.style.top = y + "px";
	cidDiv.style.zIndex = 9999;
	cidDiv.style.width = "260px";
	cidDiv.style.height = "80px"
	cidDiv.style.overflow = "hidden";
	cidDiv.style.padding = "4px";
	cidDiv.style.margin = "8px";
	cidDiv.style.background = "#ffffff";
	cidDiv.style.border = "solid 1px #999999";
	cidDiv.style.color = "#000000";
	cidDiv.style.fontSize = "11px";
	cidDiv.style.lineHeight = "14px";
	//set the html content inside the div tag
	cidDiv.innerHTML = txt;
}
function cidToolTip(e) {
	var content = '<div id="cidContent" style="position:relative;">';
	content += '<iframe src="" border="0" frameborder="0" height="80" width="260" class="selectBlocker"></iframe>';
	content += '<div style="position:absolute; top:0px; left:0px; z-index:2">This is the 3 or 4 digit code found on the back of your credit card or front of an American Express card. It helps protect your card from unauthorized use.';
	content += '<br/><img src="/urban/images/2007_holiday/cid.jpg" style="padding-top:3px;" /></div></div>';
	createCidDiv(content, Event.pointerX(e), Event.pointerY(e));
}
function removeCidToolTip() {
	document.body.removeChild(cidDiv);
	cidDiv = null;
}

/* tool tip for mobile terms and conditions */
Event.observe(window,"load",showMobileTermsToolTip);
function showMobileTermsToolTip(e) {
	var aTags = document.getElementsByTagName("a");
	if ((aTags.length > 0) && ((location.href.indexOf("myaccount.") > 0) || (location.href.indexOf("account_menu.") > 0) || (location.href.indexOf("emailsignup.") > 0))) {
		for (var i=0; i<aTags.length; i++) {
			var c = aTags[i];
			if (c.href == "http://form.acumob.com/resources/uo/uohelp.php") {
				c.href = "javascript:void(0)";
				c.target = "_self";
				Event.observe(c, 'mouseover', mobileTermsTip);
				Event.observe(c, 'mouseout', removeToolTip);
				break;
			} else {
				continue;
			}
		}
	}
}
function createMobileTermsDiv(txt, x, y) {
	dv = document.createElement('div');
	document.body.appendChild(dv);
	//set the inner styling of the div tag 
	dv.style.position = "absolute";       
	dv.style.left = x + "px";
	dv.style.top = y + "px";
	dv.style.zIndex = 9999;
	dv.style.width = "260px";
	dv.style.overflow = "hidden";
	dv.style.padding = "4px";
	dv.style.margin = "-80px 0px 0px -55px";
	dv.style.background = "#ffffff";
	dv.style.border = "solid 1px #999999";
	dv.style.color = "#000000";
	dv.style.fontSize = "11px";
	dv.style.lineHeight = "14px";
	//set the html content inside the div tag
	dv.innerHTML = txt;
}
function mobileTermsTip(e) {
	var content = "To receive monthly text promotions and updates, enter your mobile number. 2 msgs per month. Msg &amp; Data Rates May Apply. To discontinue service reply STOP to 868686. All major carriers supported.";
	createMobileTermsDiv(content, Event.pointerX(e), Event.pointerY(e));
}

/* add coremetrics element tags */
var tagsTimer = null;
function addPageElementTags() {
	if (location.href.indexOf("productdetail.jsp") > 0) {
		// pass an array of ids to function to add cm pageElementTags
		$w("addToWishlistLink shareThisProductLink emailAFriendLink facebookImgLink facebookLink diggImgLink diggLink myspaceImgLink myspaceLink deliciousImgLink deliciousLink checkAvailabilityLink sizeChartLink photoTabLink videoTabLink detailsTabLink reviewsTabLink askAndAnswerTabLink").each(function(x) {
			if ($(x)) {
				Event.observe(x, 'mouseup', function(e) {
					cmCreatePageElementTag(x,"Product Detail");
				});
			}
		});
	}
	// add to more uo links
	if ($("facebookMoreUO")) {
		clearTimeout(tagsTimer);
		tagsTimer = null;
		$w("facebookMoreUO twitterMoreUO textMoreUO rssMoreUO").each(function(m) {
			if ($(m)) {
				Event.observe(m, 'mouseup', function(e) {
					cmCreatePageElementTag(m,"More UO");
				});
				
			}
		});
	} else {
		tagsTimer = setTimeout("addPageElementTags()",100);	
	}
}
addPageElementTags();

/* add utility function for form focus issues with IE */
function check4Return(e, frmName, btnName) {
	if (e.keyCode == 13) {
		if ((document.forms[frmName]) && (document.forms[frmName].elements[btnName])) {
			document.forms[frmName].elements[btnName].focus();
		}
	}
}

/* add pageElement tags to checkout buttons */
var checkoutTimer = null;
function checkoutPageElementTags() {
	// add to login page
	if (location.href.indexOf("checkout_login.jsp") >= 0) {
		// sign-in button
		if ($("fLogin")) {
			Event.observe($("fLogin"), 'mouseup', function(e) {
				cmCreatePageElementTag("Sign-In","Checkout Login");
			});
		}
		// name for sign-up button: Continue
		if (document.forms['regForm']) {
			var signup = document.forms['regForm'].elements['Continue'];
			if (signup) {
				Event.observe(signup, 'mouseup', function(e) {
					cmCreatePageElementTag("Sign-Up","Checkout Login");
				});
			}
		}
		// name for guest checkout button: Continue
		if (document.forms['guestCheckoutForm']) {
			var guest = document.forms['guestCheckoutForm'].elements['Continue'];
			if (guest) {
				Event.observe(guest, 'mouseup', function(e) {
					cmCreatePageElementTag("Guest","Checkout Login");
				});
			}
		}
		if (($("fLogin")) && (document.forms['regForm'])) {
			clearTimeout(checkoutTimer);
			checkoutTimer = null;
		} else {
			// set timer
			checkoutTimer = setTimeout("checkoutPageElementTags()",100);
		}	
	} else if (location.href.indexOf("full/shipping.jsp") >= 0) {
		// shipping page
		if (document.forms['shippingForm']) {
			var signup = $$("div.shoppingcart_checkout h5.button_checkout a");
			signup.each(function(s) {
				Event.observe(s, 'mouseup', function(e) {
					// check if guest checkout or not
					if (document.forms['guestAccountForm']) {
						cmCreatePageElementTag("Shipping Page","Guest Checkout");
					} else {
						cmCreatePageElementTag("Shipping Page","Regular Checkout");
					}	
				});
			});
		}
		if ($("guestAccountForm")) {
			var guest = $("continueBtn");
			Event.observe(guest, 'mouseup', function(e) {
				cmCreatePageElementTag("Shipping Page Create Account","Guest Checkout");
			});
		}
		if (document.forms['shippingForm']) {
			clearTimeout(checkoutTimer);
			checkoutTimer = null;
		} else {
			// set timer
			checkoutTimer = setTimeout("checkoutPageElementTags()",100);
		}
	} else if (location.href.indexOf("checkout/billing.jsp") >= 0) {
		if (document.forms['billingform']) {
			clearTimeout(checkoutTimer);
			checkoutTimer = null;
			var continueBtn = $$('div.shoppingcart_checkout h5.button_checkout input[value="Continue Checkout"]');
			continueBtn.each(function(c) {
				Event.observe(c, 'click', function(e) {
					// check for saved credit cards
					if ($("saveCard")) {
						// regular checkout
						cmCreatePageElementTag("Billing Page","Regular Checkout");
					} else {
						// guest checkout cannot save credit cards
						cmCreatePageElementTag("Billing Page","Guest Checkout");
					}
				});
			});
		} else {
			// set timer
			checkoutTimer = setTimeout("checkoutPageElementTags()",100);
		}
	} else if (location.href.indexOf("guest_co_thankyou.jsp") >= 0) {
		// thank you
		if ($("guestAccountForm")) {
			var guest = $("continueBtn");
			Event.observe(guest, 'mouseup', function(e) {
				cmCreatePageElementTag("Thank You Page Create Account","Guest Checkout");
			});
		}
	}
}
checkoutPageElementTags();