/* Begin General Scripts */
//Get the true height of any given page
function getPageHeight() {
	return document.getElementById('container').offsetHeight -25;
}

//Get Y Coordinate of an object
function findPosY(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		while (1) {
			curtop+=obj.offsetTop;
			if (!obj.offsetParent) {
				break;
			}
			obj=obj.offsetParent;
		}
	} else if (obj.y) {
		curtop+=obj.y;
	}
	return curtop;
}

function isIridesse()
{
	if (typeof(locale) != "undefined" && locale != "")
	{
		if (locale.toLowerCase().indexOf("ird") > -1)
		{
			return true;
		}
	}
	return false;
}

/* Begin Navagation Script */
navHover = function() {
	var NavItem = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<NavItem.length; i++) {
		NavItem[i].onmouseover=function() {
			this.className+=" navhover";
		};
		NavItem[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" navhover\\b"), "");
		};
	}
};

var navDisabled = false;

function navOnOff() { 
	changeSignOut();
	if (navDisabled) {
		document.write('<style>#nav LI:hover UL {LEFT: -999em;}</style>');
	}
	else {	
		if (window.attachEvent) { 
			window.attachEvent("onload", navHover); 
			window.attachEvent("onload", subnavHover); 
		}
	}
}

/* Begin Navagation Script */
subnavHover = function() {
	var NavItem = document.getElementById("subnav").getElementsByTagName("LI");
	for (var i=0; i<NavItem.length; i++) {
		NavItem[i].onmouseover=function() {
			this.className+=" navhover";
		};
		NavItem[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" navhover\\b"), "");
		};
	}
};

/* Begin Search Script*/
var SearchDiv;
var timerOn = false;
var timecount = 800;
var isSearchOpen = false; 
var advSearchIsOpen = false;
var advMenuItems = "";
var searchFieldHasFocus = false;
var isSearchCloseBlocked = false;
var SearchDivLink;

function stopTimer()
{
	if (timerOn) 
	{
		clearTimeout(timerID);
		timerID = null;
		timerOn = false;
	}
}

function checkifSearchOpen()
{
	if(isSearchOpen)
	{
		closeSearch();
	}
	else
	{
		if (!navDisabled) {openSearch();}
	}
	
	s.prop3 = "Search";
    s.eVar8 = "Search";
    void(s.t());

}

function openSearch()
{
	SearchDiv = document.getElementById("search");
	SearchDiv.className += " searchOn";
	isSearchOpen = true;
	document.getElementById("ctlHeader_ctlSearch_searchError").innerHTML = "&nbsp;";
	document.getElementById("ctlHeader_ctlSearch_searchError").style.display = "none";
	document.forms[0].ctlHeader_ctlSearch_searchInput.value = "";
	SearchDivLink = document.getElementById("navSearch");
	SearchDivLink.className += " searchLinkOn";
}

function closeSearchTime()
{ 
	if(isSearchOpen)
	{
		if (timerOn == false) 
		{
			timerID = setTimeout("closeSearch()", timecount);
			timerOn = true;
		}
	}
}

function closeSearch()
{
	if (isSearchCloseBlocked == false && searchFieldHasFocus == false)
	{
		SearchDiv = document.getElementById("search");
		SearchDiv.className = SearchDiv.className.replace(new RegExp("( )?searchOn\\b"), "");
		SearchDivLink = document.getElementById("navSearch");
		SearchDivLink.className = SearchDivLink.className.replace(new RegExp("( )?searchLinkOn\\b"), "");
		isSearchOpen = false;
		if (advSearchIsOpen)
		{
			closeAdvSearch();
			advSearchIsOpen = false;
		}
	}
	else
	{
		stopTimer();
		timerID = setTimeout("closeSearch()", timecount);
		timerOn = true;
	}
}

function blockSearchClose()
{
	isSearchCloseBlocked = true;
}

function unblockSearchClose()
{
	isSearchCloseBlocked = false;
	// If timer is already on, restart it so that the close delay consistently starts from when the blocking stops
	if (timerOn == true)
	{
		stopTimer();
		timerID = setTimeout("closeSearch()", timecount);
		timerOn = true;
	}
}

function openAdvSearch()
{
	updateSelects();
	advSearchIsOpen = true;
	var simpleSearchBtn = document.getElementById("searchButton");
//	simpleSearchBtn.className +=" buttonHide";
	simpleSearchBtn.style.visibility = "hidden";
	var advSearchLink = document.getElementById("divAdvSearch");
	advSearchLink.className +=" advSearchHide";
	var advSearchDrops = document.getElementById("advSearchDrops");
	advSearchDrops.className = advSearchDrops.className.replace(new RegExp("( )?advSearchDropsHide\\b"), "");
	var advSearchBtn = document.getElementById("seachBrdButton");
	advSearchBtn.className = advSearchDrops.className.replace(new RegExp("( )?seachBrdButtonHide\\b"), "");
	
	var svcLocator = ServiceLocator.getInstance();
	svcLocator.getService("advancedSearchMenuService").getSearchDropdownValues();
}

function closeAdvSearch()
{
	document.getElementById("search").style.height = "";
	var simpleSearchBtn = document.getElementById("searchButton");
//	simpleSearchBtn.className = simpleSearchBtn.className.replace(new RegExp("( )?buttonHide\\b"), "");
	simpleSearchBtn.style.visibility = "visible";
	var advSearchLink = document.getElementById("divAdvSearch");
	advSearchLink.className = advSearchLink.className.replace(new RegExp("( )?advSearchHide\\b"), "");
	var advSearchDrops = document.getElementById("advSearchDrops");
	advSearchDrops.className += " advSearchDropsHide";
	var advSearchBtn = document.getElementById("seachBrdButton");
	advSearchBtn.className += " seachBrdButtonHide";
}

function handleSearchDropdownChange(id)
{
	updateSelects();
}

function initSearch()
{
	// Set up services
	var svcLocator = ServiceLocator.getInstance();
	svcLocator.registerService("searchValidationService", new SearchValidationService());
	svcLocator.registerService("advancedSearchMenuService", new AdvancedSearchMenuService());
	svcLocator.registerService("errorLogService", new ErrorLogService());

	// Register a couple of convenience handles	
	var viewLocator = ViewLocator.getInstance();
	viewLocator.registerView("searchPanel", document.getElementById("search"));
	viewLocator.registerView("searchError", document.getElementById("ctlHeader_ctlSearch_searchError"));
	
	// Set up event handler
	var searchCheckHandler = new SearchPanelEventHandler();
	subscribe(searchCheckHandler);
	
	closeSearch();
	
	//viewLocator.getView("searchError").style.display = "none";
	
	var inputHandle;
	var defaultButton = null;

	var formHandle = document.forms[0];
	var inputs = formHandle.getElementsByTagName('input');

	// Look for the first <input> tag with type="image" or type="submit" that's not search related
	for (var i=0; i < inputs.length; i++)
	{
		if ((inputs[i].type == "image" || inputs[i].type == "submit") 
			&& inputs[i].id.toLowerCase() != "ctlheader_ctlsearch_btnsimplesearch"
			&& inputs[i].id.toLowerCase() != "ctlheader_ctlsearch_btnadvancedsearch")
		{
			defaultButton = inputs[i];
			break;
		}
	}

	if (typeof(ValidatorOnSubmit) == "undefined")
	{
		// Go through all input fields, add key handlers to detect enter key
		// Only do this though if the DOMValidation libraries are not being used. The
		// DOMValidation library inserts code as well which conflicts with this and is
		// intended to override form behaviour
		for (var j=0; j < inputs.length; j++)
		{
			inputHandle = inputs[j];
			inputHandle.onkeydown = function(e) 
			{		
				e = e || window.event;
				if (e.keyCode == 13) 
				{
					if (defaultButton && typeof(defaultButton.click) != "undefined") 
					{
						defaultButton.click();
						e.cancelBubble = true;
						if (e.stopPropagation) e.stopPropagation();
						return false;
					}
					else
					{
						// If there was no input field selected of type image or submit, then just submit the form
						document.forms[0].submit();
						return true;
					}
				}
			};
		}
	}

	// We don't want a key handler for the search input field - let the enter key propagate to the form onsubmit handler
	document.getElementById("ctlHeader_ctlSearch_searchInput").onkeydown = function(e)
	{
		e = e || window.event;
		if (e.keyCode == 13) 
		{
			submitSearch();
			e.cancelBubble = true;
			if (e.stopPropagation) e.stopPropagation();
			return false;
		}
	};
	
	// Track field focus for the search input field. If the focus is on the search input field, 
	// indicate to the onsubmit handler it should not allow the submit to proceed
	document.getElementById("ctlHeader_ctlSearch_searchInput").onfocus = function(e)
	{
		searchFieldHasFocus = true;
		blockSearchClose();
	};
	
	document.getElementById("ctlHeader_ctlSearch_searchInput").onblur = function(e)
	{
		searchFieldHasFocus = false;
		unblockSearchClose();
	};
	
	// Handler for onsubmit - checks whether it should proceed or not based on whether focus is on the search input field or not
	var previousOnSubmit = document.forms[0].onsubmit;
	document.forms[0].onsubmit = function()
	{
		if (searchFieldHasFocus == true)
		{
			submitSearch();
			return false;
		}
		else if (typeof(Page_ValidationActive) != "undefined" && Page_ValidationActive == true && typeof(Page_IsValid) != "undefined")
		{
			return Page_IsValid;
		}
		else
		{
			return true;
		}
	};
	
	if (isAjaxEnabled() == false)
	{
		// Go into simple mode if Ajax not available
		var advancedButton = document.getElementById("divAdvSearch");
//		advancedButton.className +=" advSearchHide";
		advancedButton.innerHTML = "";
		
		if (document.forms[0].cookielessNoResultsMessage)
		{
			if (document.forms[0].cookielessNoResultsMessage.value != "")
			{
				openSearch();
				viewLocator.getView("searchError").style.display = "block";
				viewLocator.getView("searchError").innerHTML = document.forms[0].cookielessNoResultsMessage.value;
				viewLocator.getView("searchError").className = "errorText";
				document.getElementById("ctlHeader_ctlSearch_searchInput").focus();
			}
		}
		
		if (document.forms[0].cookielessDidYouMeanMessage)
		{
			if (document.forms[0].cookielessDidYouMeanMessage.value != "")
			{
				var didYouMeanArray = document.forms[0].cookielessDidYouMeanMessage.value.split(";"); // Value is in the form of <keyword>;<queryString>
				if (didYouMeanArray.length >= 2)
				{
					openSearch();
					
					var query = window.location.search.split("?").join("");
					var sessionId = "";
					var sessionIdQSVal = URLFactory.extractQueryStringValue(query, "mysid2");
					
					if (sessionIdQSVal != "")
					{
						sessionId = "&mysid2=" + sessionIdQSVal;
					}

					var newURL = "/Shopping/CategoryBrowse.aspx?search=1&search_params=" + didYouMeanArray[1] + sessionId;
					viewLocator.getView("searchError").style.display = "block";
					viewLocator.getView("searchError").innerHTML = didYouMeanLiteral.split("{0}").join('<a href="' + newURL + '">' + didYouMeanArray[0] + '</a>');
					viewLocator.getView("searchError").className = "";
					document.getElementById("ctlHeader_ctlSearch_searchInput").focus();
				}
			}
		}
	}
	
	if (shouldPriceBeVisible() == false)
	{
		removeMenu("searchPriceRanges");
	}
}

function submitSearch()
{
	var searchTerm = document.forms[0].ctlHeader_ctlSearch_searchInput.value;
	var formHandle = document.forms[0];
	var elementHandle;
	var searchCriteria = null;
	
	var elementNames = new Object();
	elementNames["categories"] = "searchCategories";
	elementNames["priceRanges"] = "searchPriceRanges";
	elementNames["materials"] = "searchMaterials";
	elementNames["gemstones"] = "searchGemstones";
	elementNames["preciousMetals"] = "searchPreciousMetals";
	elementNames["pearlTypes"] = "searchPearlTypes";
	

	document.getElementById("ctlHeader_ctlSearch_searchError").innerHTML = "&nbsp;";
	document.getElementById("ctlHeader_ctlSearch_searchError").style.display = "none";
	
	if (advSearchIsOpen == true)
	{
		searchCriteria = new Object();
		for (var name in elementNames)
		{
			elementHandle = formHandle.elements[elementNames[name]];
			if (elementHandle)
			{
				searchCriteria[name] = "";
				if (elementHandle.selectedIndex > 0)
				{
					searchCriteria[name] = elementHandle.options[elementHandle.selectedIndex].value;
				}
			}
		}
	}

	// Omniture reporting
	s.eVar2 = searchTerm;
	s.eVar9 = "Search";
	s.prop3 = "Search";
	s.prop4 = "Search";
	s.hier1 = "Search,Search";
	void(s.t());

	if (isAjaxEnabled() == true)
	{
		if (typeof(ServiceLocator) != "undefined")
		{
			var svcLocator = ServiceLocator.getInstance();
			if (svcLocator.getService("searchValidationService") != null)
			{
				svcLocator.getService("searchValidationService").isSearchEmpty(searchTerm, searchCriteria);
			}
		}
	}
	else
	{
		var query = window.location.search.split("?").join("");
		var sessionId = "";
		var sessionIdQSVal = URLFactory.extractQueryStringValue(query, "mysid2");
		var referrer = escape(window.location.href);

		if (sessionIdQSVal != "")
		{
			sessionId = "&mysid2=" + sessionIdQSVal;
		}
		
		window.location.href = "/Shopping/SearchRedirect.aspx?keywords=" + escape(searchTerm) + sessionId + "&urlReferer=" + referrer;
	}
}
/*End Search Script*/

/* Begin Country Drop Down Script */
function countryCheck() {
	if (window.attachEvent) {
		window.attachEvent("onload", countryHover);
	}
}
countryHover = function() {
	var CountryItem = document.getElementById("country").getElementsByTagName("LI");
	for (var i=0; i<CountryItem.length; i++) {
		CountryItem[i].onmouseover=function() {
			this.className+=" countryhover";
		};
		CountryItem[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" countryhover\\b"), "");
		};
	}
};

function pageNavCheck() {
	if (window.attachEvent) {
		window.attachEvent("onload", pagenavHover);
	}
	var PageNavUL = document.getElementById("pagenav").getElementsByTagName("UL");

}
/* Begin Page Navigation Drop Down Script */
pagenavHover = function() {
	var PageNavItem = document.getElementById("pagenav").getElementsByTagName("LI");
	for (var i=0; i<PageNavItem.length; i++) {
		PageNavItem[i].onmouseover=function() {
			this.className+=" pagenavhover";
		};
		PageNavItem[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" pagenavhover\\b"), "");
		};
	}
};

/*Begin Sort By*/
var sortByOpen=false;
var SortByItem;
var sorttimerOn = false;
var sorttimecount = 0;
function checkSortBy() {
	if (sortByOpen) {
		closeSortBy();
	}
	else {
		openSortyBy();	
	}
}
function startSortByClose() {
	if(sortByOpen){
		if (sorttimerOn == false) {
			sorttimerID=setTimeout("closeSortBy()", sorttimecount);
			sorttimerOn = true;
		}
	}
}
function stopSortByClose() {
	if (sorttimerOn) {
		clearTimeout(sorttimerID);
		sorttimerID = null;
		sorttimerOn = false;
	}
}
function openSortyBy() {
	SortByItem = document.getElementById("sortByItemsUL");
	SortByItem.style.display = "block";
	sortByOpen=true;
	
	/*The following keeps the Sort By link black until the Sub link list is closed.*/
	var SortByLink = document.getElementById("sortByUL").getElementsByTagName("LI");
	for (var i=0; i<SortByLink.length; i++) {
		SortByLink[i].onmouseover=function() {
			this.className+=" sortbyhover";
		};
		SortByLink[i].onclick=function() {
			this.className=this.className.replace(new RegExp("( )?sortbyhover\\b"), "");
		};
		SortByLink[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp("( )?sortbyhover\\b"), "");
		};

	}
}
function closeSortBy(){
	SortByItem.style.display = "none";
	sortByOpen=false;
}
/*End Sort By*/

/*Begin image swaps functions*/
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_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_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 rollOver(source) {
	MM_swapImage(source.id,'',imgOver(document.getElementById(source.id).src),1)
}
function imgOver(source)
{ // change Mouseover image source at run-time
	if (source.indexOf("_over") == -1) // do not add if image is already selected
		return source.replace(/.gif/gi, "_over.gif");
	else
		return source;
}

function setOn(source) {
	MM_swapImage(source.id,'',imgOn(document.getElementById(source.id).src),1)
}
function imgOn(source)
{ // change Mouseover image source at run-time
	if (source.indexOf("_on") == -1) // do not add if image is already selected
		return source.replace(/_over.gif/gi, "_on.gif");
	else
		return source;
}


/*End image swaps functions*/

/*PDFs */
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

/*Begin Holiday Banner scripts*/
var bannerDiv;
var bannertimerOn = false;
var bannertimecount = 800;
var isBannerOpen = false; 

function openBannerInfo(){	
	if (bannertimerOn) {
		clearTimeout(bannertimerID);
		bannertimerID = null;
		bannertimerOn = false;
	}
	else {
		bannerDiv = document.getElementById("bannerPosition");
		bannerDiv.className+=" bannerOpen";
		isBannerOpen = true;
	}
}
function stopBannerTime() {
	if (bannertimerOn) {
		clearTimeout(bannertimerID);
		bannertimerID = null;
		bannertimerOn = false;
	}
}
function closeBannerTime(){ 
	if(isBannerOpen){
		if (bannertimerOn == false) {
			bannertimerID=setTimeout("closeBannerInfo()", bannertimecount);
			bannertimerOn = true;
		}
	}
}
function closeBannerInfo(){
	bannerDiv.className=bannerDiv.className.replace(new RegExp("( )?bannerOpen\\b"), "");
	isBannerOpen = false;
	bannertimerOn = false;
}
/*End Holiday Banner scripts*/

/* Begin Incontent Layer scripts */
var divPopupHolder;
var divPopupHolderHeight;
var divMaskHolder;
var divPopupHolderTop;
var blnPopupMask;

function ringSizeConversion(thisobj){
	linkAboutRingSizes();
}

function createPopUp (pwidth,pheight,blnMask,obj,ptop,href,bColor,blnBorder,mColor,opacity ) 
{
	divPopupHolderTop = ptop;
	blnPopupMask = blnMask;
	if(blnPopupMask) {ptop = ptop} else {ptop = ptop + getPageScrollTop();}
	divPopupHolderHeight = pheight;
	if (blnPopupMask) {pBorderWidth = 1} else {pBorderWidth = 5}
	if (typeof blnBorder == 'undefined'){} else {if(!blnBorder) {pBorderWidth = 0}} 
	//if (typeof blnBorder != 'undefined') {pBorderWidth = blnBorder}
	if (typeof bColor == 'undefined'){if (blnPopupMask) {borderColor = "E2E0DB"} else {borderColor = "E0E0E0"}}
	else {borderColor=bColor}
	var destURL = href
	var isSafari = (navigator.userAgent.toLowerCase().indexOf("safari") != -1);true;false;
	//if (isSafari) {alert(destURL)}
	//if (destURL.length < 1 ) {destURL=href}
	//Kill existing pop up windows first
	//if (divPopupHolder) {closePopUp}
	txtPopUpContent = '<iframe id="iframeContent" name="iframeContent" src="'+destURL+'" style="border:0; width:'+pwidth+'px; height:'+pheight+'px" frameborder="0" scrolling="no"></iframe>'
	divPopupHolder = document.createElement("div");
	document.body.insertBefore(divPopupHolder, document.body.firstChild);
	divPopupHolder.id = "divPopUp"
	divPopupHolder.className= "divPopUp"
	divPopupHolder.style.position = "absolute";
	divPopupHolder.style.width = pwidth +"px";
	divPopupHolder.style.marginLeft = Math.round((pwidth+(pBorderWidth*2))/2)*-1 + "px"
	divPopupHolder.style.left = "50%";
	divPopupHolder.style.top = ptop +"px";
	divPopupHolder.style.borderWidth = pBorderWidth +"px";
	divPopupHolder.style.borderColor = borderColor
	divPopupHolder.style.borderStyle ="solid"
	divPopupHolder.innerHTML = txtPopUpContent;

	//Create Footer Mask to cover contents below
	divMaskHeaderHolder = document.createElement("div");
	document.body.insertBefore(divMaskHeaderHolder, document.body.firstChild);
	divMaskHeaderHolder.id = "divMaskHeader"
	if (blnPopupMask) {divMaskHeaderHolder.className= "divHeaderMask"
		if (typeof mColor == 'undefined'){}
		else {divMaskHolder.style.backgroundColor =mColor;}
	}
	else {divMaskHeaderHolder.className= "divClearMask"}
	divMaskHeaderHolder.style.height = "84px"
	divMaskHeaderHolder.style.top = "0px"
	divMaskHeaderHolder.innerHTML = "&nbsp;";
	divMaskHeaderHolder.onclick = closePopUp;

	//Create Mask to cover contents below
	divMaskHolder = document.createElement("div");
	document.body.insertBefore(divMaskHolder, document.body.firstChild);
	divMaskHolder.id = "divMask"
	if (blnPopupMask) {
		divMaskHolder.className= "divMask";
		if (typeof mColor == 'undefined'){}
		else {
			divMaskHolder.style.backgroundColor =mColor;
		}
	}
	else {divMaskHolder.className= "divClearMask"}
	var pagebtmPad = 25;
	var pagetopPad = 0;
	var headerHeight = 84;
	if (isIridesse()) {
		pagebtmPad = -10;
		pagetopPad = 0;
		headerHeight = 48;
	}
	divMaskHolder.style.height = (getPageHeight() + pagebtmPad - headerHeight) +"px"
	divMaskHolder.style.top = (pagetopPad + headerHeight) +"px"
	divMaskHolder.innerHTML = "&nbsp;";
	divMaskHolder.onclick = closePopUp;

	//Create Footer Mask to cover contents below
	divMaskFooterHolder = document.createElement("div");
	document.body.insertBefore(divMaskFooterHolder, document.body.firstChild);
	divMaskFooterHolder.id = "divMaskFooter"
	if (blnPopupMask) {
		divMaskFooterHolder.className= "divFooterMask";
	}
	else {divMaskFooterHolder.className= "divClearMask"}	
	divMaskFooterHolder.style.height = "80px"
	divMaskFooterHolder.style.top = getPageHeight()+ pagebtmPad +"px"
	divMaskFooterHolder.innerHTML = "&nbsp;";
	divMaskFooterHolder.onclick = closePopUp;

	//IE 6 hack to make the mask cover over select elements
	if (isIE6()) 
	{
		divMaskIframeHolder = document.createElement("iframe");
		divMaskIframeHolder.id = "divShimMask";
		divMaskIframeHolder.className = "divShimMask";
		//divMaskIframeHolder.src = "placeholder.gif";
		//divMaskIframeHolder.src = "";
		divMaskIframeHolder.src = "/shared/images/misc/clr.gif"
		divMaskIframeHolder.scrolling ="no";
		divMaskIframeHolder.frameBorder ="0";
		divMaskIframeHolder.style.width = "960px";
		divMaskIframeHolder.style.height = (getPageHeight() + pagebtmPad) +"px";
		document.body.insertBefore(divMaskIframeHolder, document.body.firstChild);
	}
	
	//if(!blnPopupMask) {window.onscroll = keepAlive;}
}

function isIE6() {
	var agt=navigator.userAgent.toLowerCase();
    var appVer = navigator.appVersion.toLowerCase();
    var is_minor = parseFloat(appVer);
    var is_major = parseInt(is_minor);
    var iePos  = appVer.indexOf('msie');
    if (iePos !=-1) {
       is_minor = parseFloat(appVer.substring(iePos+5,appVer.indexOf(';',iePos)));
       is_major = parseInt(is_minor);
    }
	if ((iePos!=-1) && is_major<7) {return true}
	else {return false}
}

function closePopUp()
{
	if (typeof(divPopupHolder) != "undefined")
	{
		closePopUpFollowup();
		setTimeout("closePopUpHistoryFollowup()", 50);
	}
}



function closePopUpFollowup()
{
	if (typeof(divPopupHolder) != "undefined")
	{
		divPopupHolder.innerHTML = "";
		document.body.removeChild(divPopupHolder);
		divMaskHeaderHolder.innerHTML = "";
		document.body.removeChild(divMaskHeaderHolder);
		divMaskHolder.innerHTML = "";
		document.body.removeChild(divMaskHolder);
		divMaskFooterHolder.innerHTML = "";
		document.body.removeChild(divMaskFooterHolder);
		if (isIE6()) {document.body.removeChild(divMaskIframeHolder);}
		window.onscroll = "";
	}
}

function closePopUpHistoryFollowup()
{
	var model = ProductModel.getInstance();
	var stateSnapshot = model.getStateSnapshot();

	if (stateSnapshot.popup != "")
	{
		// Don't set the history if the popup property hasn't been set. Just means that a popup is closing that wasn't using
		// this history manager.
		model.setBrowseStatesNoSideEffects({popup:""});
		HistoryManager.getInstance().addHistoryItem(URLFactory.convertStateToHash(model.getStateSnapshot()));
	}
}

function closePopUpViaReg() {
	if (typeof divPopupHolder != "undefined") {
		divPopupHolder.innerHTML = "";
		document.body.removeChild(divPopupHolder);
		divMaskHeaderHolder.innerHTML = "";
		document.body.removeChild(divMaskHeaderHolder);
		divMaskHolder.innerHTML = "";
		document.body.removeChild(divMaskHolder);
		divMaskFooterHolder.innerHTML = "";
		document.body.removeChild(divMaskFooterHolder);
		if (isIE6()) {document.body.removeChild(divMaskIframeHolder);}
		window.onscroll = "";
	}
	else {
		// Its a pop up window and we close the window.
		window.close();}
}

function keepAlive() {
	newptop = divPopupHolderTop + getPageScrollTop();
	divPopupHolder.style.top = newptop +"px";
}

function createMiniPopUp (pwidth,pheight,ptop,pleft,href) {
	change('btnSendVideo','selectOn');
	
	divMiniPopupHolderTop = ptop;
	divMiniPopupHolderHeight = pheight;
	var destURL = href
	txtPopUpContent = '<iframe id="iframeMiniContent" name="iframeMiniContent" src="'+destURL+'" style="border:0; width:'+pwidth+'px; height:'+pheight+'px" frameborder="0" scrolling="no"></iframe>'
	divMiniPopupHolder = document.createElement("div");
	document.body.insertBefore(divMiniPopupHolder, document.body.firstChild);
	divMiniPopupHolder.id = "divMiniPopUp"
	divMiniPopupHolder.className= "divMiniPopUp"
	divMiniPopupHolder.style.position = "absolute";
	divMiniPopupHolder.style.width = pwidth +"px";
	divMiniPopupHolder.style.marginLeft = "0px"
	divMiniPopupHolder.style.left = pleft +"px";
	divMiniPopupHolder.style.top = ptop +"px";
	
	if(top==self) {
	divMiniPopupHolder.style.top = "137px";
	divMiniPopupHolder.style.left = "50%";
	divMiniPopupHolder.style.marginLeft = "-342px";
	}
	
	divMiniPopupHolder.innerHTML = txtPopUpContent;
	
		//Create Mask to cover contents below
	divMiniMaskHolder = document.createElement("div");
	document.body.insertBefore(divMiniMaskHolder, document.body.firstChild);
	divMiniMaskHolder.id = "divMiniMask"
	divMiniMaskHolder.className= "divClearMask";
	divMiniMaskHolder.style.height = (getPageHeight()) +"px"
	divMiniMaskHolder.style.top = "0px"
	divMiniMaskHolder.innerHTML = "&nbsp;";
	divMiniMaskHolder.onclick = closeMiniPopUp;

}



function closeMiniPopUp()
{
		if (typeof(divMiniPopupHolder) != "undefined")
	{
		divMiniPopupHolder.innerHTML = "";
		document.body.removeChild(divMiniPopupHolder);
		divMiniMaskHolder.innerHTML = "";
		document.body.removeChild(divMiniMaskHolder);
		change('btnSendVideo','');
	}
	
		
}


function getPageScrollTop(){
	var yScrolltop;
	//var yTestScrolltop;
	if (self.pageYOffset ) {
		yScrolltop = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop ){	 // Explorer 6 Strict
		yScrolltop = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScrolltop = document.body.scrollTop;
	}
	//yTestScrolltop = yScrolltop
	//this is a change from tiffany.com in the yScrolltop value if true
	var pageHeight = getPageHeight();
	if(pageHeight - divPopupHolderHeight - yScrolltop -25 < 0) {yScrolltop = pageHeight - divPopupHolderHeight}
	else {yTestScrolltop = yScrolltop}
	return yScrolltop;
}

/* Begin Incontent Layer scripts */

/*Begin View Overlay scripts*/
var ViewDiv;
var viewtimerOn = false;
var viewtimecount = 0;
var isViewOpen = false; 

function stopViewTimer(){
	if (viewtimerOn) {
		clearTimeout(viewtimerID);
		viewtimerID = null;
		viewtimerOn = false;
	}
}

function openInfoPanel(id) {
	ViewDiv = document.getElementById(id);
	checkifViewOpen();
}
function checkifEngraveOpen() {
	ViewDiv = document.getElementById("engraveOpts");
	checkifViewOpen();
}
function checkifSpecsOpen() {
	ViewDiv = document.getElementById("specs");
	checkifViewOpen();
}

function checkifBOPSOpen() {
	ViewDiv = document.getElementById("bops");
	checkifViewOpen();
}

function checkifRelSizeOpen() {
	ViewDiv = document.getElementById("relSize");
	checkifViewOpen();
}
function checkifViewOpen(){
	if(isViewOpen){
		closeView();
	}
	else{
		openView();
	}
}
function openView(){
	ViewDiv.className+=" viewOn";
	isViewOpen = true;
}
function closeViewTime(){ 
	if(isViewOpen){
		if (viewtimerOn == false) {
			viewtimerID=setTimeout("closeView()", viewtimecount);
			viewtimerOn = true;
		}
	}
}
function closeView(){
	ViewDiv.className=ViewDiv.className.replace(new RegExp("( )?viewOn\\b"), "");
	isViewOpen = false;
}

function checkForOverlay() 
{
	var queryOverlayInURL = window.location.search.split("?").join("");
	var overlayParam = URLFactory.extractQueryStringValue(queryOverlayInURL, "overlay");
	openMarketingPopUp(overlayParam);
}
if (typeof(BrowserUtils) != "undefined")
{
	BrowserUtils.addOnLoadHandler(checkForOverlay);
}
/*End View Overlay scripts*/

function isAjaxEnabled()
{
	if (document.forms[0])
	{
		if (document.forms[0].isAjaxEnabled)
		{
			if (document.forms[0].isAjaxEnabled.value.toLowerCase() == "false")
			{
				return false;
			}
		}
	}
	return true;
}

function areCookiesEnabled()
{
	if (document.forms[0])
	{
		if (document.forms[0].areCookiesEnabled)
		{
			if (document.forms[0].areCookiesEnabled.value.toLowerCase() == "false")
			{
				return false;
			}
		}
	}
	return true;
}

function show(showLayer) 
{
	var whichElShow = document.getElementById(showLayer);
	if (whichElShow != null && typeof(whichElShow) != "undefined")
	{
		whichElShow.style.display = "block";
	}
}

function hide(hideLayer) 
{
	var whichElHide = document.getElementById(hideLayer);
	if (whichElHide != null && typeof(whichElHide) != "undefined")
	{
		whichElHide.style.display = "none";
	}
}
// Header functions to show and hide sign out button
	function nameDefined(ckie,nme)
	{
		var splitValues
		var i
		for (i=0;i<ckie.length;++i)
		{
			splitValues=ckie[i].split("=")
			if (splitValues[0]==nme) return true
		}
		return false
	}
	function delBlanks(strng)
	{
		var result=""
		var i
		var chrn
		for (i=0;i<strng.length;++i) {
			chrn=strng.charAt(i)
			if (chrn!=" ") result += chrn
		}
		return result
	}
	function getCookieValue(ckie,nme)
	{
		var splitValues
		var i
		for(i=0;i<ckie.length;++i) {
			splitValues=ckie[i].split("=")
			if(splitValues[0]==nme) return splitValues[1]
		}
		return ""
		}
		function testCookie(cname, cvalue) {  //Tests to see if the cookie 
		var cookie=document.cookie           //with the name and value 
		var chkdCookie=delBlanks(cookie)  //are on the client computer
		var nvpair=chkdCookie.split(";")
		if(nameDefined(nvpair,cname))       //See if the name is in any pair
		{   
			tvalue=getCookieValue(nvpair,cname)  //Gets the value of the cookie
			if (tvalue == cvalue) return true
			else return false
		}
		else return false
	}
	function changeSignOut() {
		if (testCookie("last_activity", "yes") && testCookie("samebrowsersession", "1")) {
			change('divHeader','divHeaderSecure');
			setCookie();
		}
	}
	function setCookie()
	{
		var futdate = new Date()		//Get the current time and date
		var expdate = futdate.getTime()  //Get the milliseconds since Jan 1, 1970
		expdate += 30*60*1000  //expires in 30 minutes
		futdate.setTime(expdate)
		var newCookie="last_activity=yes; path=/;"// domain=dev.tiffany.us;"	//Set the new cookie values up 
		newCookie += " expires=" + futdate.toGMTString()
		window.document.cookie=newCookie //Write the cookie
	}
	
	function setCookieValue(name, value)
	{
		var futdate = new Date()		//Get the current time and date
		var expdate = futdate.getTime()  //Get the milliseconds since Jan 1, 1970
		expdate += 364*24*60*60*1000  //expires in about one year
		futdate.setTime(expdate)
		var newCookie = name + "=" + value + "; path=/;"// domain=dev.tiffany.us;"	//Set the new cookie values up 
		newCookie += "expires=" + futdate.toGMTString()
		window.document.cookie=newCookie //Write the cookie
	}
	
	function change(id, newClass) {
		identity=document.getElementById(id);
		identity.className=newClass;
	}
	
	function openSubWindow(url, winWidth, winHeight) {
      closeSubWindow();
      if (parseInt(navigator.appVersion) >= 4) {
        var xPos = (screen.availWidth-winWidth)/2;
        var yPos = (screen.availHeight-winHeight)/2;
      } else {
        var xPos = 300;
        var yPos = 400;
      }  
      attrib = "menubar=0,status=0,personalbar=0,titlebar=0,toolbar=0,location=0,top=" + yPos + ",left=" + xPos + ",width=" + winWidth + ",height=" + winHeight +",resizable=0,scrollbars=1";
      subWin = window.open(url, 'subWin', attrib);
      subWin.focus();
    }
    function closeSubWindow() {
      if ((document.subWin) && (!subWin.closed)) {
        subWin.close();
      } else {
  	    document.subWin = new Object();
      }
    }
	
	//Imported existing function
	function processLinks(url) {
		top.location.href = url;
	}
	
	function setStatus(linkHandle)
    {
	    var newStatusString = "";   
	   
	    if(linkHandle.firstChild.nodeValue !=null && linkHandle.firstChild.nodeValue !="" && linkHandle.firstChild.nodeValue != 'undefined' )
	    {
	        newStatusString = linkHandle.firstChild.nodeValue;
	    }
	    else if (linkHandle.getAttribute("alt") !=null && linkHandle.getAttribute("alt") !="" && linkHandle.getAttribute("alt") != 'undefined')
	    {
	        newStatusString = linkHandle.getAttribute("alt");
    	    
	    }
	    else if (linkHandle.getAttribute("title") !=null && linkHandle.getAttribute("title") !="" && linkHandle.getAttribute("title") != 'undefined')
	    {
	        newStatusString = linkHandle.getAttribute("title");
	    }
	    else if (linkHandle.firstChild.getAttribute("alt") !=null && linkHandle.firstChild.getAttribute("alt") !="" && linkHandle.firstChild.getAttribute("alt") != 'undefined')
	    {
	        newStatusString = linkHandle.firstChild.getAttribute("alt");	    
	    }
	    else if (linkHandle.firstChild.getAttribute("title") !=null && linkHandle.firstChild.getAttribute("title") !="" && linkHandle.firstChild.getAttribute("title") != 'undefined')
	    {
	        newStatusString = linkHandle.firstChild.getAttribute("title");	    
	    }
    	
	    window.status = newStatusString;
	    return true;	
    }
    
    function clearStatus()
    {
	    window.status = "";
	    return true;
    }

function msBetweenDates(date1, date2)
{
	var timeDifference = 0;
	if (typeof(date1) != "undefined" && date1 != null && typeof(date2) != "undefined" && date2 != null)
	{
		timeDifference = date2.getTime() - date1.getTime();
	}
	return timeDifference;
}

// ------------------------------------------------
// Handle the problem where ActiveX controls in IE rewrite the page title when
// there is a hash as part of the URL. The onFocus event in the ActiveX control
// will handle most of it, but doesn't work until the user has actually clicked
// on the control at least once.
function pageTitle_verify()
{
	var currentPageTitle = document.title;
	if (currentPageTitle != originalPageTitle)
	{
		document.title = originalPageTitle;
	}
}
//Common Module Functions
	var siteName="Tiffany & Co. For The Press";
	function downloadToUser(U,L) 
	{
	//Use U for URL, L for logging
	window.location.replace("/Common/Services/FileDownload.aspx?filePath="+U)
	if (typeof L == 'undefined'){} 
	else {omnitureDownloadTracking(U,L);}
	}
	
	
	function omnitureDownloadTracking(linkObject,downloadName) 
	{
	var s = s_gi(s_account);
	downloadName = siteName + " | " + downloadName
	s.tl(linkObject,'d',downloadName);		
	}