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","primarynav_whatsnew","primarynav_brands","primarynav_trends");
	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("men's") >= 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);
					} else if (c.title.toLowerCase().indexOf("new") >= 0) {
						Event.observe(c, 'mouseover', whatsNew);
					} else if (c.title.toLowerCase().indexOf("trends") >= 0) {
						Event.observe(c, 'mouseover', shopTrends);
					} else if (c.title.toLowerCase().indexOf("brands") >= 0) {
						Event.observe(c, 'mouseover', shopBrands);
					}
					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 whatsNew(e) {
	createDiv("Shop What's New", Event.pointerX(e), Event.pointerY(e));
}
function shopTrends(e) {
	createDiv('Shop Trends', Event.pointerX(e), Event.pointerY(e));
}
function shopBrands(e) {
	createDiv("Shop Brands", 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() {
	if (dv != null) {
		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() {
	if (cidDiv != null) {
		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();
		}
	}
}