<!--
//prepend all Image sources with this globalization variable Q.03.13.06
var ImageServerVar='';
//alert(testing);
window.top.name="preview";
// Detect OS type
if (navigator.userAgent.indexOf('Windows NT 5.1') != -1) var ostype="winxp";
else if (navigator.userAgent.indexOf('Windows NT 5.0') != -1) var ostype="win2000";
else if (navigator.userAgent.indexOf('Windows 98') != -1) var ostype="win98";
else if (navigator.userAgent.indexOf('Windows 95') != -1) var ostype="win95";
else if ((navigator.userAgent.indexOf('WinNT') != -1) || (navigator.userAgent.indexOf('Windows NT') != -1)) var ostype="winnt";
else if ((navigator.userAgent.indexOf('Mac') != -1)) var ostype="mac";
else var ostype="undefined";
// Detect Browser type
var bN = navigator.appName;
var agent = navigator.userAgent.toLowerCase();

/* USE THIS TO DISABLE SEARCH 
function CatchEmptySearch() {
	alert('Search is currently unavailable.\nPlease try back later.');
	return false;
} */

//New Search Function
function CatchEmptySearch() {
	var searchForm = document.searchForm;
	var search = document.getElementById("siteSearch_input").value;
	var valid = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-.%' ";
	var temp = "";
	var invalidflag = 0;
	
	if (search == "") {
		alert('Please enter your search criteria\nthen click the Go button.');
		searchForm.focus();
		return false;
	}
	else if (search.substring(0,1) == " ") {
		alert('Please remove any leading spaces\nfrom your search criteria and try again.');
		searchForm.focus();
		return false;
	}
	else if (search == "-" || search == "." || search == "%" || search == "'" || search == " ") {
		alert('Your search criteria is too general.\nPlease add to it and try again.');
		searchForm.focus();
		return false;
	}
	
	for (var i=0; i < search.length; i++)
	{
		temp="" + search.substring(i,i+1);
		if (valid.indexOf(temp)=="-1") {
			invalidflag = 1;
			break;
		}
	}
		
	if (invalidflag==1) {
		alert("Your search criteria contains an invalid character(s).\nValid characters are numbers, letters, spaces, and . - % '.\nPlease remove any invalid characters and try again.");
		searchForm.focus();
		return false;
	}
	else {
		return true;
	}
}

function changeImages() {
	if (document.images) {
		for (var i=0; i<changeImages.arguments.length; i+=3) {
			document[changeImages.arguments[i]].src = eval(changeImages.arguments[i+1] + ".src");
		}
	}
}

function ShowSizeChart(chart){
	var LeftPosition = (screen.width) ? (screen.width-602)/2 : 0;
	var TopPosition = (screen.height) ? (screen.height-580)/2 : 0;
	var page = 'http://www.ae.com/'+jsContextRoot+'/browse/sizechart/'+chart+'.jsp';
	var popup = window.open(page,"sizechart",'toolbar=0,top='+TopPosition+',left='+LeftPosition+',location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width=602,height=580');
	popup.focus();
}

//Configurable Function for Popups
function ConfigurablePopup(url,w,h,winName,scroll,resiz,topPos,leftPos)
{
var popup = window.open(url,winName,'toolbar=0,top='+topPos+',left='+leftPos+',width='+w+',height='+h+',location=0,directories=0,status=0,menubar=0,scrollbars='+scroll+',resizable='+resiz);
popup.location=url;
popup.opener=self;
popup.focus();
}

//Generic Function for Popups
function popup(url,w,h)
{
var width = w;
var height = h;
var LeftPosition = (screen.width) ? (screen.width-width)/2 : 0;
var TopPosition = (screen.height) ? (screen.height-height)/2 : 0;
var popupURL = url;
var popup = window.open(popupURL,"AEO",'toolbar=0,top='+TopPosition+',left='+LeftPosition+',width='+width+',height='+height+',location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1');
popup.location=popupURL;
popup.opener=self;
popup.focus();
}

/*******************************************************************************************
 * Function	: scanKeypress
 * Parameters	: Key press event
 * This function submits the form when the user hits the enter key(IE and NN compatable )
 *******************************************************************************************/
var nav4=window.Event ? true : false;
if (document.layers) document.captureEvents(Event.KEYPRESS);

if (nav4 && document.layers)
 document.onkeypress=scanKeypress;
 
function scanKeypress(e)
{
    if (nav4)
   		var whichCode=e.which;
	else
    	if (e.type=="keypress")
      		var whichCode=e.keyCode;
    	else
      		var whichCode=e.button;
 	if (whichCode==13)
	{
		return false;
	}
	else return true;
}

///// giftcard balance popup
function BalInqPopup()
{
	var LeftPosition = (screen.width) ? (screen.width-340)/2 : 0;
	var TopPosition = (screen.height) ? (screen.height-222)/2 : 0;
	var balanceurl = '/'+jsContextRoot+'/checkout/gc_balance_inquiry_popup.jsp';
	var balPopup = window.open(balanceurl,"balance_pop",'toolbar=0,top='+TopPosition+',left='+LeftPosition+',location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=340,height=275');
	if(navigator.appName.substring(0,8)=="Netscape")
	{
		balPopup.location = balanceurl;
		balPopup.opener = self;
	}
	balPopup.focus();
}

function cartFmDropDown(){
	$(document).ready(function() {
		if(typeof allModals != 'undefined'){ // close quick view on add to bag
			var openModals = allModals.openSet();
			$.each(openModals, function(key, modal){
				if(modal.isQuickView()) modal.close();
			});
		}
		setTimeout("loadMenuBag()", 1000);
	});
}

function noAjaxCartFmDropDown( htmlVal ) {
	$(document).ready(function() {
		if(typeof allModals != 'undefined'){ // close quick view on add to bag
			var openModals = allModals.openSet();
			$.each(openModals, function(key, modal){
				if(modal.isQuickView()) modal.close();
			});
		}
		setTimeout(function() {
			noAjaxLoadMenuBag(htmlVal);
		}, 1000);
	});
}

function noAjaxLoadMenuBag( htmlVal ) {
	if (!!htmlVal) {
		$('#cart_flyout_scratch').html(htmlVal);
		window.scrollTo(0,0);
		animateIt();
	}
}

function noAjaxUpdateMenuBag( htmlVal ) {
	if (!!htmlVal) {
		$('#cart_flyout_scratch').html(htmlVal);
		reloadMenuBag();
	}
}

function loadMenuBag() {
	$('#cart_flyout_scratch').load('/'+jsContextRoot+'/global/nav/nav_myBag_scratch.jsp', '', animateIt);
	var timer_scroll=setTimeout("window.scrollTo(0,0);",5);
}
/* this updates the content of the bag drop down and the count without causing the drop down to appear */
function updateMenuBag(){
	$('#cart_flyout_scratch').load('/'+jsContextRoot+'/global/nav/nav_myBag_scratch.jsp', '', reloadMenuBag);
}

var menuBagPostAnimateTimer;
function animateIt() {
	//$.ie6selectFix({toggle: 'hide', className: DROPDOWNie6selectFixClass});
	setTimeout(function() {
		$('#tl_myBag_count').empty().append($('#tmp_myBag_count').html());
		$('#tl_myBag_flyout').empty().append($('#tmp_myBag_flyout_recent').html());
		var myBag = $('#toolLinks li.tl_myBag');
		myBag.addClass('js_hover');
		clearTimeout(menuBagPostAnimateTimer);
		menuBagPostAnimateTimer = setTimeout(function() {
			myBag.removeClass('js_hover');
			reloadMenuBag();
		}, 3000);
	}, 0);
}

function reloadMenuBag() {
	//$.ie6selectFix({className: DROPDOWNie6selectFixClass});
	$('#tl_myBag_count').empty().append($('#tmp_myBag_count').html());
	$('#tl_myBag_flyout').empty().append($('#tmp_myBag_flyout_all').html());
}


function getViewportDimensions()
{
	var viewportwidth;
	var viewportheight;
	// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
	if (typeof window.innerWidth != 'undefined')
	{
		viewportwidth = window.innerWidth,
		viewportheight = window.innerHeight
	}
	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
	else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0)
	{
		viewportwidth = document.documentElement.clientWidth,
		viewportheight = document.documentElement.clientHeight
	}
	// older versions of IE
	else
	{
		viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
		viewportheight = document.getElementsByTagName('body')[0].clientHeight
	}
	return [viewportwidth, viewportheight];
}

function trim(str){
	while(''+str.charAt(0)==' ')
	str=str.substring(1,str.length);
	while(''+str.charAt(str.length-1)==' ')
	str=str.substring(0,str.length-1);
	return str;
}

function initNavAnimationForIE6() {
	// For IE6 to do the hover effect
	if($.browser.msie && ($.browser.version < 7)) {
		$.each( { girls: ".girlsSubNav ", tgirls: ".tgirlsSubNav ", boys: ".boysSubNav ", tboys: ".tboysSubNav ", gifts: ".giftsSubNav " }, function(i, n){
			$.each( { IEhover: ".submenucontent", IEhoverleft: ".submenuleft" }, function(j, o){
				$(n + o).hover(
					function () {
						$(this).addClass(i + '_' + j);
					}, 
					function () {
						$(this).removeClass(i + '_' + j);
					}
				);
			});
		});
	} else return;
}
$(document).ready(function() {
	initNavAnimationForIE6();
});

function isArray(obj) {
   if (obj.constructor.toString().indexOf("Array") == -1)
      return false;
   else
      return true;
}

// to limit characters in a textarea or text input field
// limitField : ID of form element to limit (string)
// limitCount : ID of element to place characters remaining count (string)
// limitNum : the maximum number of characters to allow in field (int)
function limitChars(limitField, limitCount, limitNum) {
	limitField = $('#'+limitField);
	limitCount = $('#'+limitCount);
	if (limitField.val().length > limitNum) {
		limitField.val(limitField.val().substring(0, limitNum));
		limitCount.html('0');
	} else {
		var count = limitNum - limitField.val().length;
		count = count === 0 ? '0' : count; // jQuery won't put the number value of 0 in the element using html(), so make a string
		limitCount.html(count);
	}
}

function parseQueryString( queryVal ) {
	/*
		parseQueryString - Extracts a query (key - value set) from the href of the current page; the href can also be overridden by passing a queryStr as the first parameter
		PARAMETERS:	queryVal - the href string to test; if none is supplied window.location.search is used
		RETURN:	a javascript object containing the query data
	*/
	queryVal = queryVal || window.location.search;
	if (queryVal) {
		var queryStart = queryVal.indexOf('?');
		if (queryStart !== -1) {
			queryVal = queryVal.substr(queryStart + 1);
			if (!queryVal) {
				return null;
			}
		} else {
			return null;
		}
		var data = {}, sets = queryVal.split('&');
		for (var i = 0, j = sets.length; i < j; i++) {
			var set = sets[i].split('=');
			if (set) {
				data[decodeURIComponent(set[0])] = (set[1])? decodeURIComponent(set[1]) : '';
			}
			set = null;
		}
		sets = null;
		return data;
	}
	queryVal = null;
	return null;
	
}
function generateQueryString( queryVal, locationVal ) {
	/*
		generateQueryString - Generates a query string from a set of data and a location
		PARAMETERS:	queryVal - the query data as a javascript object; the data can also be passed as a string
					locationVal - the href as a string; if empty, window.location.href is used and the new query is appended to any previously existing query
		RETURN:	the href including the query set as a string
	*/
	if (!locationVal) {
		locationVal = window.location.href;
	}
	if (queryVal) {
		var queryStart = locationVal.indexOf('?'), prevQuery = '';
		if (queryStart !== -1) {
			prevQuery = locationVal.substr(queryStart + 1);
			if (prevQuery && (prevQuery.charAt(prevQuery.length - 1) !== '&')) {
				locationVal += '&';
			}
		} else {
			locationVal += '?';
		}
		queryStart = prevQuery = null;
		var queryType = typeof queryVal;
		if (queryType == 'string') {
			locationVal += encodeURI(queryVal);
		} else if (queryType == 'object') {
			for (var i in queryVal) {
				locationVal += encodeURIComponent(i) + '=' + encodeURIComponent(queryVal[i]) + '&';
			}
			locationVal = stripLast(locationVal, '&');
		}
		queryType = null;
		locationVal = stripLast(locationVal, '?');
	}
	return locationVal;
}
function stripLast( str, chr ) {
	/*
		stripLast - Removes the end of a string if it matches a substring
		PARAMETERS:	str - the string to check
					chr - the substring to match
		RETURN:	the string without the match on the end
	*/
	if ((typeof str === 'string') && (typeof chr === 'string')) {
		var lastChar = str.length - chr.length;
		if (str.substr(lastChar) === chr) {
			str = str.substr(0, lastChar);
		}
		lastChar = null;
	}
	return str;
}

function replaceAmpsApos(str) {	/*	replaces Ampersand and Apostrophes */
	if (typeof str === 'string') {
		str=str.replace("&amp;","&");
		str=str.replace("&#39;","'");
	}
	return str;
}

(function() {
	// initiate code for inputs using defaultValue as their label field
	$("input.js_defaultAsLabel").live("focus", function( evt ) {
		if (this.defaultValue == this.value) {
			this.value = "";
		}
	}).live("blur", function( evt ) {
		if (!$.trim(this.value)) {
			this.value = this.defaultValue;
		}
	});
	
	$("form").live("submit", function( evt ) {
		$(this).find("input.js_defaultAsLabel").each(function() {
			if (this.defaultValue == this.value) {
				this.value = "";
			}
			setTimeout((function( el ) {
				return function() {
					if (!$.trim(el.value)) {
						el.value = el.defaultValue;
					}
				};
			})(this), 10);
		});
	});
	
	// use a modal for myBag flyout checkout link
	$(document).ready(function() {
		$("#tl_myBag_flyout").delegate("#tl_myBag_checkoutLink", "click", function( evt ) {
			if (linkCheckout) {
				evt.preventDefault();
				
				(new Modal({
					id: 'loginModal',
					useAjax: true,
					url: '/' + jsContextRoot + '/checkout/loginModal.jsp',
					height: 281,
					width: 560,
					shadow: true,
					overlay: true,
					clean: true,
					closeSelector: '#checkoutModalCloseLink'
				})).open();
				
				var s=s_gi(s_account);
				s.linkTrackVars='events';
				s.linkTrackEvents='event36';
				s.events='event36';
				s.tl(this,'o','Checkout From In Line Cart Click');
			}
		});
	});
})();


function mapAnchor(anchor) {
	window.location.hash = anchor;
}
 

