// JavaScript Document
<!--
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_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_findObj(n, d) { //v4.01
  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 && d.getElementById) x=d.getElementById(n); return x;
}

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_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function dosearch(bSubmit) {
	var o = document.forms['SearchForm'].elements['Search']
	var oNav = document.getElementById('nav_bar_select')
	var bSearchNav = false;
	if (oNav && oNav.options[oNav.selectedIndex].value !='') {doNavMenu(); bSearchNav = true;}
	if (o) {
		var sTmp = o.value
		if (sTmp.length < 3 && !bSearchNav) {
			alert('Please enter at least 3 characters in search box')
			return false
		} else if (sTmp == 'Search' && !bSearchNav) { 
			o.value = ''
			o.focus()
			return false
		} else { 
			var oFrm = o.form
			if (bSearchNav && sTmp == 'Search') oFrm.removeChild(o);
			if (bSubmit==1) {oFrm.submit(); return false};
			return true
		}
	} else {
		return false
	}
}

function doNavMenu() {
	var o=document.getElementById('nav_bar_select')
	var oFrm = document.getElementById('SearchForm')
	var sAction = '';
	var sSearchVal = oFrm.elements['Search'].value;
	if (o && oFrm) {
		//first clear any fields we already did from form
		for (var i=(oFrm.elements.length-1);i>=0;i--) {
			switch (oFrm.elements[i].name) {
				case 'Search':
					break;
				default:
					oFrm.removeChild(oFrm.elements[i]);
			}
		}
		var sVal = o.options[o.selectedIndex].value
		switch (sVal) {
			case 'Clearance0-500':
				oFrm.appendChild(navMenuElement('priceFrom','0'))
				oFrm.appendChild(navMenuElement('priceTo','500'))
				break;
			case 'Clearance500-1000':
				oFrm.appendChild(navMenuElement('priceFrom','500'))
				oFrm.appendChild(navMenuElement('priceTo','1000'))
				break;
			case 'Clearance1000-5000':
				oFrm.appendChild(navMenuElement('priceFrom','1000'))
				oFrm.appendChild(navMenuElement('priceTo','5000'))
				break;
			case 'Clearance5000-10000':
				oFrm.appendChild(navMenuElement('priceFrom','5000'))
				oFrm.appendChild(navMenuElement('priceTo','10000'))
				break;
			case 'Clearance10000+':
				oFrm.appendChild(navMenuElement('priceFrom','10000'))
				oFrm.appendChild(navMenuElement('priceTo','999999'))
				break;
		}
		switch (sVal) {
			case 'Men':
			case 'Women':
				sAction = (sSearchVal=='' || sSearchVal == 'Search') ? '':'m_watches.asp';
				break;
			case 'DealOfTheDay':
				location.href = sBase + '/watch-of-the-day'
				return;
			case 'Clearance':
			case 'ClearanceAll':
			case 'Clearance0-500':
			case 'Clearance500-1000':
			case 'Clearance1000-5000':
			case 'Clearance5000-10000':
			case 'Clearance10000+':
				//oFrm.appendChild(navMenuElement('f','SaleDuJour'))
				oFrm.appendChild(navMenuElement('PerPage','All'))
				oFrm.action = sBase + '/sale?'
				oFrm.Search.value='';
				oFrm.submit();
				break;
			case '':
				sAction = 'watches.asp'
				break;
			default:
				sAction = 'm_watches.asp'
		}
		oFrm.action = sBase + '/' + sAction;
		switch (sVal) {
			case 'Men':
			case 'Women':
				oFrm.appendChild(navMenuElement('Gender',sVal))
				break;
			case 'Sale':
				oFrm.appendChild(navMenuElement('Sale','Sale'))
				break;
			case 'SaleMen':
				oFrm.appendChild(navMenuElement('Gender','Men'))
				oFrm.appendChild(navMenuElement('Sale','Sale'))
				break;
			case 'SaleWomen':
				oFrm.appendChild(navMenuElement('Gender','Women'))
				oFrm.appendChild(navMenuElement('Sale','Sale'))
				break;
			case 'GiveawayQualified':
				oFrm.appendChild(navMenuElement('Giveaway Qualified','Giveaway Qualified'))
		}
	}
}

function navMenuElement(sName,sValue) {
	var el = document.createElement('input')
	el.setAttribute('type','hidden');
	el.setAttribute('name',sName);
	el.setAttribute('value',sValue);
	return el
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


function ShowHide(obj,bShow,ib) {
	if (typeof(obj)=='string') obj=document.getElementById(obj);
	var val = (bShow) ? ((ib=='i') ? 'inline' : 'block') :'none';
	if (obj) {obj.style.display = val}
}

function AddBrandBG() {
	var o = document.getElementById('show_add_brands');
	if (o.className == 'show_add_brands') {
		o.className = 'hide_add_brands';
	} else {
		o.className = 'show_add_brands';
	}
}
//-->

<!--  to hide script contents from old browsers
//
//  Cookie Functions
//  Written by:  Bill Dortch, hIdaho Design
//  The following functions are released to the public domain.
//
//
// "Internal" function to encode cookie value.  This permits cookies to
// contain whitespace, comma and semicolon characters.
//
function encode (str) {
  var dest = "";
  var len = str.length;
  var index = 0;
  var code = null;
  for (var i = 0; i < len; i++) {
    var ch = str.charAt(i);
    if (ch == " ") code = "%20";
    else if (ch == "%") code = "%25";
    else if (ch == ",") code = "%2C";
    else if (ch == ";") code = "%3B";
    else if (ch == "\b") code = "%08";
    else if (ch == "\t") code = "%09";
    else if (ch == "\n") code = "%0A";
    else if (ch == "\f") code = "%0C";
    else if (ch == "\r") code = "%0D";
    if (code != null) {
      dest += str.substring(index,i) + code;
      index = i + 1;
      code = null;
    }
  }
  if (index < len)
    dest += str.substring(index, len);
  return dest;
}
//
// "Internal" function to decode cookie values.
//
function decode (str) {
  var dest = "";
  var len = str.length;
  var index = 0;
  var code = null;
  var i = 0;
  while (i < len) {
    i = str.indexOf ("%", i);
    if (i == -1)
      break;
    if (index < i)
      dest += str.substring(index, i);
    code = str.substring (i+1,i+3);
    i += 3;
    index = i;
    if (code == "20") dest += " ";
    else if (code == "25") dest += "%";
    else if (code == "2C") dest += ",";
    else if (code == "3B") dest += ";";
    else if (code == "08") dest += "\b";
    else if (code == "09") dest += "\t";
    else if (code == "0A") dest += "\n";
    else if (code == "0C") dest += "\f";
    else if (code == "0D") dest += "\r";
    else {
      i -= 2;
      index -= 3;
    }
  }
  if (index < len)
    dest += str.substring(index, len);
  return dest;
}
//
// "Internal" function to return the decoded value of a cookie
//
function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return decode(document.cookie.substring(offset, endstr));
}
//
//  Function to return the value of the cookie specified by "name".
//    name - String object containing the cookie name.
//
function GetCookie (name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
      return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break;
  }
  return null;
}
//
//  Function to create or update a cookie.
//    name - String object object containing the cookie name
//    value - String object containing the cookie value.  May contain
//      any valid sting characters, including whitespace, commas and quotes.
//    expires - Date object containing the expiration data of the cookie,
//      or null to expire the cookie at the end of the current session.
//

function SetCookie (name, value, expires) {
  document.cookie = name + "=" + encode(value) + ((expires == null) ? "" : ("; expires=" + expires.toGMTString()));
}
//  Function to delete a cookie. (Sets expiration date to current date/time)
//    name - String object containing the cookie name
//

function DeleteCookie (name) {
  var exp = new Date();
  var cval = GetCookie (name);
  document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

function showCurTable (aCurrs) {
	var i;
	sDiv = '<div style="width:284px; color:#ffffff; background-color:#' + sMediumColor + '; text-align:center; font-size:11px; font-weight:bold; padding:4px; margin:-1px 0px 0px -1px;">Currency Calculator</div>';
	sDiv += '<div style="width:260px; border:1px solid #' + sMediumColor + '; font-family:Verdana; font-size:12px; color:#1f395a; padding:6px 15px; background-color:#fff; margin:0px 0px 1px -1px;">';
	sDiv += '<p>The following rates are provided for your information only and may not reflect those of the financial institution that handles your transaction.</p>';
	sDiv += '<table width="100%" border="0" align="center" cellpadding="0" cellspacing="5" style="font-size:12px;">';
	for (i=0;i<aCurrs.length;i++) {
		sDiv += '<tr><td align="right"><strong>'+aCurrs[i][3]+aCurrs[i][1]+'</strong></td><td >'+aCurrs[i][0]+' <span style="font-size:9px; font-style:italic;">('+aCurrs[i][2]+')</span></td></tr>';
	}
	sDiv += '</table><p style="color:#' + sMediumColor + '; font-size:9px; text-align:left; font-style:italic;"><span style="color:#000;">Payments made to TheWatchery.com are only accepted in U.S. dollars.</span><br />The accuracy of the exchange rates listed above cannot be guaranteed. To ensure that you have the most up-to-date information, please confirm the current exchange rates before making any transactions that might be affected. Foreign currency rates can be found at www.CurrencySource.com. Rates may vary for actual transactions, and TheWatchery.com does not guarantee that it will enter into any transaction at any rate displayed.</p></div>';
	//<br><a href="<%=sBase%>/vat.asp" target="_blank">VAT table</a> // could not add due to mouseaway rules
	return sDiv;
}


function hidePct(sID) {
	//alert('hiding')
	var o = document.getElementById("open_pct_div");
	if (o) {
		o.parentNode.removeChild(o);
	}
}

function showAmtOff(sVal) {
	if (sVal.length>0 && sVal.toLowerCase()=='mysterym') {
		ShowHide('input_code',false);
		ShowHide('show_final_price',true);
	} else {
		alert('incorrect code!');
		hidePct();
	}
}

function showCode(sCode, sImgPath) {
	if (sCode) {
		var sCodeDiv;
		sCodeDiv = '<div id="show_code_div" style="border:3px solid #000; width:201px; text-align:center; margin:auto; padding:0px; background-image:url(' + sImgPath + 'images/seasonalImages/pop_up_back.jpg); margin-top:-120px; height:82px">';
		sCodeDiv += '<a href="javascript:ShowHide(\'show_code_div\', false)">';
		//sCodeDiv += '<span style="font-weight:bold; font-size:14px;">' + sCode + '</span>';
		sCodeDiv += '<img src="' + sImgPath + 'images/SeasonalImages/md_mystery_code.jpg" title="' + sCode + '" width="201" height="82"/>';
		sCodeDiv += '</a></div>';
		return sCodeDiv;
		//alert(sCode);
	}
}

var currPctOffTimeout;
function showPct(iAmt, iFinal, sCode, sImgPath, sID) {
	hidePct();
	//if (currPctOffTimeout) clearTimeout(currPctOffTimeout);
	//currPctOffTimeout = setTimeout('hidePct()',4000);
	var sPctDiv;
	sPctDiv = '<div id="open_pct_div" style="border:3px solid #000; width:152px; background-image:url(' + sImgPath + 'images/seasonalImages/pop_up_back.jpg); color:#000000; text-align:center; padding:4px; margin:40px 0px 0px -13px; position:relative; z-index:250;" >';
	// the form div
	sPctDiv += '<div id="input_code" style="display:block">';
	sPctDiv += '<form name="saleCode" id="sale_code" onsubmit="showAmtOff(this.elements[\'code\'].value);return false">';
	sPctDiv += '<span style="font-size:10px; color:#000;">Enter code to see how much you\'ll save</span>';
	sPctDiv += '<input type="text" name="code" style="width:120px">';
	sPctDiv += '<input type="submit" name="submit" value="Get price" onClick="ShowHide(\'md_code_holder_' + sID + '\',false);">';
	sPctDiv += '</form>';
	sPctDiv += '<div style="font-size:10px; text-align:center; width:140px;"><a href="" onClick="document.getElementById(\'md_code_holder_' + sID + '\').innerHTML = showCode(\''+ sCode + '\', \'' + sImgPath + '\'); return false" style="font-size:10px;">get code</a> | ';
	sPctDiv += '<a href="javascript:ShowHide(\'open_pct_div\',false); ShowHide(\'md_code_holder_' + sID + '\',false)" style="font-size:10px;">Close pop up</a></div>';
	sPctDiv += '</div>';
	// the results div
	sPctDiv += '<div id="show_final_price" style="display:none">';
	sPctDiv += '<span style="font-size:14px; font-weight:bold;" >Take an additional ' + iAmt +'% OFF this item</span><br>';
	sPctDiv += '<span style="font-size:9px; font-weight:normal; ">when you enter coupon code ' + sCode + ' at checkout</span><br>';
	sPctDiv += '<span style="font-weight:bold">Final discount price: ' + iFinal + '</span></p>';
	sPctDiv += '<a href="javascript:ShowHide(\'open_pct_div\',false)" style="font-size:10px; text-align:center; width:140px; margin:auto; display:block;">Close</a>';
	sPctDiv += '</div>';
	// end of results
	sPctDiv += '<div id="md_code_holder_' + sID + '" style="position:absolute; z-index:17; left:-25px; top:190px" ></div>';
	sPctDiv += '</div>';
	
	return sPctDiv;
}

function showPctStam(iPct, iAmt, iFinal, sCode, sImgPath, sID) {
	hidePct();
	//if (currPctOffTimeout) clearTimeout(currPctOffTimeout);
	//currPctOffTimeout = setTimeout('hidePct()',4000);
	var o = document.getElementById('save_percent_' + sID);
	o.style.padding = '0px';
	o.style.height = '71px';
	o.style.backgroundImage = 'url(' +sImgPath + 'images/spacer.gif)';
	o.innerHTML = '<img src="' + sImgPath + 'images/seasonalimages/shopping_bag_pumpkin_burst.gif">';
	setTimeout("showPctDiv('" + iPct + "','" + iAmt + "','" + iFinal + "','" + sCode + "','" + sImgPath + "','" + sID + "')",100);
}

function showPctDiv(iPct, iAmt, iFinal, sCode, sImgPath, sID) {
	var sPctDiv;
	var bTrick;
	if (parseFloat(iAmt) > 0) {
		bTrick = true;
	} else {
		bTrick = false;
	}
		
	sPctDiv = '<div id="open_pct_div" style="border:3px solid #000; width:152px;  text-align:center; padding:25px 4px 4px 4px; margin:40px 0px 0px -13px; position:relative;';
	if (bTrick) {
		sPctDiv = sPctDiv + 'color:#000000; background-image:url(' + sImgPath + 'images/seasonalImages/pop_up_back_pumpkin.jpg); " >';
		sPctDiv += '<div id="show_final_price" style="display:block;">';
		sPctDiv += 'Additional <span style="font-size:14px; font-weight:bold;" >' + iAmt +'% OFF</span><br/>';
		sPctDiv += 'Use coupon code <span style="font-size:14px; font-weight:bold;" >' + sCode + '</span><br/>';
		sPctDiv += '<span style="font-weight:bold">Final price: ' + iFinal + '</span><br/>(Total Savings ' + iPct + '%)<br/>';
	} else {
		sPctDiv = sPctDiv + 'color:#fcaf48; background-image:url(' + sImgPath + 'images/seasonalImages/pop_up_back_trick.jpg); " >';
		sPctDiv += '<div id="show_final_price" style="display:block;">';
		sPctDiv += 'Pay <span style="font-size:14px; font-weight:bold;" >' + Math.abs(iAmt) +'% </span> more for this item<br>';
		sPctDiv += 'DON\'T use coupon code <span style="font-size:14px; font-weight:bold;" >' + sCode + '</span><br>';
		sPctDiv += 'or <span style="font-weight:bold">Pay Trick Price: ' + iFinal + '</span><br/>';
	}
	sPctDiv += '<a href="javascript:hidePctDiv(\''+ sID + '\', \'' + sImgPath + '\')" style="font-size:10px; text-align:center; width:140px; margin:auto; display:block; color:#fff;">Close</a>';
	sPctDiv += '</div>';
	sPctDiv += '<div id="md_code_holder_' + sID + '" style="position:absolute; z-index:17; left:-25px; top:190px" ></div>';
	sPctDiv += '</div>';
	
	var oPctDiv = document.getElementById('show_pct_' + sID);
	oPctDiv.style.display = 'block';
	oPctDiv.innerHTML = sPctDiv;

	var o = document.getElementById('save_percent_' + sID);
	o.style.padding = '23px 0px 0px 0px';
	o.style.height = '48px';
	o.style.backgroundImage = 'url(' +sImgPath + 'images/seasonalimages/shopping_bag_pumpkin.gif)';
	o.innerHTML = '&nbsp;';
}

function hidePctDiv(sID,sImgPath) {
	var oPctDiv = document.getElementById('show_pct_' + sID);
	oPctDiv.style.display = 'none';
}


function search_ac(){
	if(typeof YAHOO=="undefined"||!YAHOO){}else{
		YAHOO.example.BasicRemote = function() {
			// Use an XHRDataSource
			var oDS = new YAHOO.util.XHRDataSource(sBase + "/SearchSuggest.asp");
			// Set the responseType
			oDS.responseType = YAHOO.util.XHRDataSource.TYPE_TEXT;
			// Define the schema of the delimited results
			oDS.responseSchema = {
				recordDelim: "\n",
				fieldDelim: "\t"
			};
			// Enable caching
			oDS.maxCacheEntries = 5;
		
			// Instantiate the AutoComplete
			var oAC = new YAHOO.widget.AutoComplete("Search", "myContainer", oDS);
			// Disable the browser's built-in autocomplete caching mechanism
			oAC.allowBrowserAutocomplete = false;
			
			return {
				oDS: oDS,
				oAC: oAC
			};
		}();
	}
};

/* for quick view */
function qView(lID,lMDItem,sBase)  {
	//alert (myScrollTop())	
	var sParent = document.getElementById(lID);
	var x = getPosition(sParent).x - 3;
	var y = getPosition(sParent).y - 5;
	var oQV = document.getElementById('quick_view_div');
	//alert(x + ', ' + y);
	oQV.style.left = x + 'px';
	oQV.style.top = y + 'px';
	oQV.style.display = 'block';
	//document.getElementById('itemPopup').style.top = myScrollTop() + 75 + 'px';
	//document.getElementById('PopupTitle').innerHTML = document.getElementById('PopupTitle').innerHTML.replace("title",lID);
	var csFileName = sBase + '/quick_view.asp?id=' + lMDItem;
	parent.document.getElementById('qv_frame').src = csFileName;
	//document.getElementById('itemPopup').style.display = 'block';
}

function hideQV()  { 
	var oQV = parent.document.getElementById('quick_view_div');
	oQV.style.display = 'none';
}

function getPosition(e){
	var left = 0;
	var top  = 0;

	while (e.offsetParent){
		left += e.offsetLeft;
		top  += e.offsetTop;
		e     = e.offsetParent;
	}

	left += e.offsetLeft;
	top  += e.offsetTop;

	return {x:left, y:top};
}
-->
