<!--

/* These scripts have been tested with the following browsers.
   Some scripts do not work in all browsers and examples are provided

   Firefox 1.0
   IE 6.0
   Opera 6.01
   Opera 7.54
   Netscape 4.76
   Netscape 6.21
*/

// returns true if the browser is IE
function isIE()
{
	ua = navigator.userAgent.toLowerCase();
	return ua.indexOf('msie') != -1 
		&& ua.indexOf('opera') == -1 
		&& ua.indexOf('webtv') == -1;
}

// returns true if the browser is Opera
function isOpera()
{
	ua = navigator.userAgent.toLowerCase();
	return (ua.indexOf('opera') != -1); 
}


// sets the value of the specified form object
function setTextBox(id, value)
{
	document.forms[0].elements[id].value = value;
}

// returns the value of the specified form object
function getTextBox(id)
{
	return(document.forms[0].elements[id].value);
}

// sets the value of the specified form object
// in the page that opened this one
function setOpeningTextBox(id, value)
{
	window.opener.document.forms[0].elements[id].value = value;
}

// returns the value of the specified form object
// in the page that opened this one
function getOpeningTextBox(id)
{
	return(window.opener.document.forms[0].elements[id].value);
}

// sets the text of an element (e.g. span) on different browsers
// This will not work in Opera 6 or Netscape 4. 
// If this functionality is essential use <input type="text"> and setTextBox()
// apply a style to make the input look more like a label 
function setText(id, text)
{

if (document.all)            
   document.all(id).innerText = text;
else if(document.getElementById)   
	{    
	// Opera 6 falls in here, but neither innerText nor inner HTML work for it      
	x = document.getElementById(id);	
	x.innerHTML= ''; // fix for MAC IE 5.1 or higher 
	x.innerHTML= text;    
	}
else if (document.layers)
   {
   		// Nestcape 4: do nothing. 
		// For this to work in netscape 4, you need to define a layer with absolute position
		// and write to the layer. The layer loses the absolute positioning after being written to
		// so the absolute positioning needs to be applied again. See example below		
		//	lyr = document.layers[id];
		//	positionedTxt = '<P CLASS="layerclass">' + text + '</P>';
		//	lyr.document.open();
		//	lyr.document.write(positionedTxt);
		//	lyr.document.close();		
   }
}
   
// reads the text of an element (e.g. span, or div) on different browsers
// This will not work in Opera 6 or Netscape 4. 
function getText(id)
{
if (document.all)               
	return document.all(id).innerText;
else if(document.getElementById)              
	return document.getElementById(id).innerHTML;                                
else if (document.layers)                    
     return '';// can't read the text here
}

// this function shows or hides the specified element (div, span, input, etc)
// isVisible=0: hidden
//  isVisible=1: visible
// Netscape 4 requires the use of layers with absolute positioning      
function setVisible(id, isVisible) 
{  
	if(document.getElementById)   //gecko(NN6) + IE 5+
	{
        document.getElementById(id).style.visibility = isVisible ? "visible" : "hidden";   
		document.getElementById(id).style.display = isVisible ? "inline" : "none"; 
	}
 	else if(document.all) // IE 4 
 	{   
        document.all[id].style.visibility = isVisible ? "visible" : "hidden";
	}
	else if(document.layers)    //NN4+
       document.layers[id].visibility = isVisible ? "show" : "hide";
}

// this function selects the value of a drop down list 
function selectValue(id, value) 
{  
    list = null
	if(document.getElementById)   //gecko(NN6) + IE 5+
	{
        list = document.getElementById(id);
	}
 	else if(document.all) // IE 4 
 	{   
        list = document.all[id];
	}
	
	for(var i=0;i<list.length; i++){
		if(list[i].value == value) {
			list.selectedIndex= i;
		}
	}
}

// this function shows the specified element (div, span, input, etc)
// Netscape 4 requires the use of layers with absolute positioning 
function showElement(id)
{
	setVisible(id, 1);
}
// this function hides the specified element (div, span, input, etc)
// Netscape 4 requires the use of layers with absolute positioning 
function hideElement(id)
{
	setVisible(id, 0);
}

// sets the background colour of the specified element
// Netscape 4 requires the use of layers with absolute positioning 
function setColour(id, colour)
{
	if (document.all)                
    	document.all(id).style.backgroundColor = colour;
    else if(document.getElementById)              
        document.getElementById(id).style.backgroundColor = colour;                               
    // else if (document.layers)
    // to use layers, the style needs to be applied to the layer
}

// reads the bakground colour of the specified element
// Netscape 4 requires the use of layers with absolute positioning 
function getColour(id)
{
	if (document.all)                
    	return document.all(id).style.backgroundColor;
    else if(document.getElementById)              
	
        return document.getElementById(id).style.backgroundColor;                               
    else if (document.layers)
		return ''; // can't deal with netscape 4
}
   
// enables the specified form object
function enable(id)
{
	if (document.all)                
    	return document.all(id).disabled=false;
    else if(document.getElementById)              
	
        return document.getElementById(id).disabled=false;  
}

// disables the specified form object
function disable(id)
{
	if (document.all)                
    	return document.all(id).disabled=true;
    else if(document.getElementById)              
	
        return document.getElementById(id).disabled=true;  
}

// Expands the panel to its full size (defined by the containing content
// this does not work in Opera or Netscape
	function expand(id)
	{
		if(document.all(id) != null)
		{
			document.all(id).style.overflow = "visible";
			document.all(id).style.height = "100%";
		}
		else if(document.getElementById(id) != null)
		{
			document.getElementById(id).style.overflow = "visible";
			document.getElementById(id).style.height = "100%";
	    }
	}
	
	// collapses the panel to the height specified for the panel (style="height=60px")
	// if the contents of the panel is more than the height then scrollbars are applied
	// this does not work in Opera or Netscape
	function collapse(id, size)
	{
		if(document.all(id) != null)
		{
			document.all(id).style.overflow = "auto";
			document.all(id).style.height = size;
		}
		else if(document.getElementById(id) != null)
		{
			document.getElementById(id).style.overflow = "auto";
			document.getElementById(id).style.height = size;
		}
	}
	
	
// sets the width of the element
function setTheWidth(id, width)
{

if(document.all)
		document.all(id).style.width = width;
	else if (document.getElementById)
		document.getElementById(id).style.width = width;

}

// replaces all instances of a character sequence within a text string
// For example replaceChars('1&nbsp;2', '&nbsp;', ' ') returns '1 2'
function replaceChars(text, toReplace, replaceWith) {
		temp = "" + text; // temporary holder
		
		while (temp.indexOf(toReplace)>-1) {
			pos= temp.indexOf(toReplace);
			temp = "" + (temp.substring(0, pos) + replaceWith + 
			temp.substring((pos + toReplace.length), temp.length));
		}
		return temp;
	}

// reads the query string parameters and returns them in an array
// for example:
// 		var params = getParams();
//		var colour = params["colour"];
function getParams() {
	url = window.location.href;
	idx = url.indexOf('?');
	params = new Array();
	if (idx != -1) {
		var pairs = url.substring(idx+1, url.length).split('&');
		for (var i=0; i<pairs.length; i++) {
			nameVal = pairs[i].split('=');
			params[nameVal[0]] = replaceChars(unescape(nameVal[1]), '+', ' ');
		}
	}
	return params;
}


    // this function hides and displays a panel based on the values of an asp check box
    // add an onClick event to check box to call this function, e.g. onClick="showPanel(this, Panel1)"
    // 
    // checkbox :- the ASP checkbox (this renders as a HTML checkbox wrapped in a span)
    // panel :- the name/id of the panel
	function showPanel(checkbox, panel)
	{
		// the check box is the first child node
		nodeIndex = 0;	
	    box = checkbox.childNodes[nodeIndex]; // check box wrapped in a span
		if(box.checked)
		{
		    showElement(panel);
		}
		else
		{
			hideElement(panel);
		}
	}
	
	// similar to the showPanel method, but the ID of the checkbox is passed in
	function showPanelByID(checkboxID, panel)
	{
		if(document.forms[0].elements[checkboxID].checked)
		{
		    showElement(panel);
		}
		else
		{
			hideElement(panel);
			
		}
	}
	
	// this function enables a control whenever a asp check box is selected
	// and disables it when it is deselected. 
	// this specifically works for an asp check box which renders within a span
	function enableControl(checkbox, control)
    {
		// For IE, the check box is the first child node, for all other browsers
		// a text element surrounds the check box so choose the second child node 
		nodeIndex = 0;
		if(!isIE())
			nodeIndex = 1;
			
	    chkbx = checkbox.childNodes[nodeIndex];
		if(chkbx.checked)
			enable(control);
		else
			disable(control);	
    }

	
// checks the length of the text in the specified multi-line text area 
// to prevent it exceeding the max length on keydown event
function checkMaxLength(textArea, maxLength){
  len = textArea.value.length
  if (len > maxLength) 
		textArea.value = textArea.value.substring(0, maxLength);
}

// sets the remaining number of characters on keyup event
// by comparing the length of the text in the text area against the max length
function setRemainingCharacters(textArea, maxLength, countTxBx) {
	setRemainingCharacters(textArea, maxLength, countTxBx,false)
}

// sets the remaining number of characters on keyup event
// by comparing the length of the text in the text area against the max length
// the boolean value isNameEscaped indicates if the countTxBx is escaped and needs to be unescaped
// this is used in special cases where script is called from user controls on the page
function setRemainingCharacters(textArea, maxLength, countTxBx, isNameEscaped) {
	len = textArea.value.length;
	var cl;

	if ((len == 1) && (textArea.value.substring(0, 1) == " ")) {
		textArea.value = "";
		len = 0
	}
	if (len > maxLength) {
		textArea.value =textArea.value.substring(0, maxLength);
		cl = 0;
	}
	else {
		cl = maxLength - len;
	}
	if(isNameEscaped)	
	    setTextBox(unescape(countTxBx), cl);
	else
	    setTextBox(countTxBx, cl);
}

function ACT_DropListBox(ar)
{
var strIDs = '<SELECT SIZE="1" NAME="ACT_droplstbox" onClick="if(options[selectedIndex].value) window.location.href=(options[selectedIndex].value)">';
var sel = " SELECTED";
strIDs += '<OPTION ' + sel + ' VALUE="">Select category ...</OPTION>';

for (var i=1;i<=ar.length;i++)
{
if (ar[i].sURL !=null)
	{
	strIDs += '<OPTION VALUE="' + ar[i].sURL + '">' +ar[i].sName + '</OPTION>';
	}	
}
strIDs+='</SELECT>';
return strIDs;

}


function ACT_ListMenu(ar)
{
var strIDs = '<div id="flyout"><ul class="level1">';


for (var i=1;i<=ar.length;i++)
{
if (ar[i].sURL !=null)
{
strIDs += '<li class="folder"><a href="' + ar[i].sURL  +'">' +ar[i].sName +'</a>'; 
}
}
strIDs+=' </ul></div>';
return strIDs;

}


function ACT_MultiLevelMenu(ar)
{
var strIDs = '<div id="flyout"><ul class="level1">';

for (var i=1;i<=ar.length;i++)
{
	if (ar[i].sURL != null && ar[i].sName != 'Wedding Lists')
	{
	strIDs += '<li class="folder"><a href="' + ar[i].sURL  +'">' +ar[i].sName +'</a>'; 
	if (ar[i].pChild)
		{
			strIDs += '<ul class="level2">';
			for (var j=1;j<=ar[i].pChild.length;j++)
			{
				strIDs += '<li><a href="' + ar[i].pChild[j].sURL + '" class="submenu">' +ar[i].pChild[j].sName +'</a></li>';
			}
			strIDs += '</ul>';
		}	
	strIDs += '</li>';
	}
}
strIDs+=' </ul></div>';
return strIDs;
}


function productItems(ar)
{
var strIDs = '<ul class="siteMapUL">';

for (var i=1;i<=ar.length;i++)
{
	if (ar[i].sURL !=null)
	{
	strIDs += '<li><a href="' + ar[i].sURL  +'">' +ar[i].sName +'</a>'; 
	if (ar[i].pChild)
		{
			strIDs += '<ul class="siteMapUL">';
			for (var j=1;j<=ar[i].pChild.length;j++)
			{
				strIDs += '<li class="siteMap"><a href="' + ar[i].pChild[j].sURL + '">' +ar[i].pChild[j].sName +'</a></li>';
			}
			strIDs += '</ul>';
		}	
	strIDs += '</li>';
	}
}
strIDs+=' </ul></div>';
return strIDs;
}


function YahooSections(ar)
{
var strIDs = '';
for (var i=1;i<=ar.length;i++)
  {
  if (ar[i].sURL != null && ar[i].sName != 'Wedding Lists')
    {
    strIDs += '<a href="' + ar[i].sURL + '"><span class="actxxsmall"><b><font color="NETQUOTEVAR:FGCOLORCSS">' + ar[i].sName + '</font></b></span></a><br>';
      {
      if (ar[i].pChild)
        {
        for (var j=1;j<=ar[i].pChild.length;j++)
          {
          if (ar[i].pChild[j].sURL != null)
            {
            strIDs += '<a href="' + ar[i].pChild[j].sURL + '"><span class="actxxsmall"><font color="NETQUOTEVAR:FGCOLORCSS">' + ar[i].pChild[j].sName + '</font></span></a><br>';
            }
          }
        }
      }
    strIDs += '<br>'
    }
  }
return strIDs
}



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 resizeOuterTo(w,h) {
 if (parseInt(navigator.appVersion)>3) {
   if (navigator.appName=="Netscape") {
    top.outerWidth=w;
    top.outerHeight=h;
   }
   else top.resizeTo(w,h);
 }
}

function showNews(page)
{
	window.parent.location.href=page;
}

function emailPage()
    {        
    	window.location = "mailto:?subject=" +document.title 
	+ "&body=I%20thought%20you%20might%20be%20interested%20in%20this%20page%20on%20the%20new%20Equinox%20website%3A%0D%0A%0D%0APage%3A%20%20" 
	+document.title +"%0D%0A%0D%0AAddress%3A%20%20" +window.location;
    }

function printPage()
{
	window.print();
}

function bookmarkPage()
{
	if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
		var url=window.location.href;
		var title=document.title;		
		window.external.AddFavorite(url,title);	
	} else {
		alert("Your browser is prevents automatic bookmarking.\nPress (CTRL-D) to bookmark this page.");
	}
}

// checks if this news window is in a frame (as it should be)
// if not then the homesite is called in a fresh page
function checkFrames(){ 
	if(parent.frames.length == 0){			
		window.location.href="http://www.equinoxshop.com/acatalog/index.html";
	}
}

function openWindow(sUrl, nWidth, nHeight)
  	{  
	window.open(sUrl, 'popup', 'width=' + nWidth + ',height=' + nHeight + ',scrollbars, resizable');
}

function StockLevels(pItem)
{

if (pItem > 0)
{
return 'In stock: normally ships in 24 hours';
}
else
{
return 'Out of stock: Normally ships in 1-2 weeks<BR><BR>Please <a href="mailto:sales@equinoxshop.com">email Us</a> to confirm shipping times.';
}
}



// returns the height of the current window
function getWindowHeight() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return myHeight;
}

// returns the height of the current document
function getDocumentHeight(){
	return document.body.scrollHeight;
}

// sets the height of the specified element
function setHeight(elementId, size){
	if (document.all)            
	   document.all(elementId).height=size;
	else if(document.getElementById)   
		{       
		x = document.getElementById(elementId);	
		x.height = size  
		}
}

// sets the height of the newsfeed frame to a level less than the window height
function setFrameHeight(){
 frameheight =  getDocumentHeight() - 500;
  setHeight('newsfeed', frameheight);
}

/***********************************************************************
*
* setCookie -	Generic Set Cookie routine
*
* Input: sName	 -	Name of cookie to create
*	 sValue	 -	Value to assign to the cookie
*	 sExpire -	Cookie expiry date/time (optional)
*
* Returns: null
*
************************************************************************/

function setEquinoxCookie(sName, sValue, sExpire) 
    {
    var sCookie = sName + "=" + escape(sValue) +"; path=/";	// construct the cookie
    if (sExpire)
    	{
    	sCookie += "; expires=" + sExpire.toGMTString();	// add expiry date if present
    	}
    document.cookie = sCookie;					// store the cookie
    return null;
    }

/***********************************************************************
*
* getCookie	-	Generic Get Cookie routine
*
* Input: sName	-	Name of cookie to retrieve
*
* Returns:		Requested cookie or null if not found
*
************************************************************************/

function getEquinoxCookie(sName) 
    {
    var sCookiecrumbs = document.cookie.split("; "); 	// break cookie into crumbs array
    var sNextcrumb
    for (var i=0; i < sCookiecrumbs.length; i++) 
	{
		sNextcrumb = sCookiecrumbs[i].split("=");	// break into name and value
		if (sNextcrumb[0] == sName)			// if name matches
	    {
	     return unescape(sNextcrumb[1]); 		// return value
	    }
	}
	return null;
    }

/****************************************************
 * Checks if this is a wedding list delivery 
 */
function isWeddingDelivery(){
	if(getEquinoxCookie('weddingdelivery') == 'yes'){
		//alert('This is a wedding list purchase');
		return true;
	} else {
		//alert('This is not a wedding list purchase');
		return false;
	}
}

var TodaysDay = new Array('Sunday', 'Monday', 'Tuesday','Wednesday', 'Thursday', 'Friday', 'Saturday');
var TodaysMonth = new Array('January', 'February', 'March','April', 'May','June', 'July', 'August', 'September','October','November', 'December');
var DaysinMonth = new Array('31', '28', '31', '30', '31', '30', '31', '31', '30', '31', '30', '31');

function LeapYearTest (Year) 
{
    if (((Year % 400)==0) || (((Year % 100)!=0) && (Year % 4)==0)) 
    {
        return true;
    }
    else 
    {
        return false;
    }
}

function offsettheDate (offsetCurrentDay) 
{
    if (offsetCurrentDay > 6) 
    {
        offsetCurrentDay -= 6;
        DayOffset = TodaysDay[offsetCurrentDay-1];
        offsettheDate(offsetCurrentDay-1);
    }
    else 
    {
        DayOffset = TodaysDay[offsetCurrentDay];
        return true;
    }
}
function displayDate(dateVal) 
{
    DaystoAdd=dateVal;
    TodaysDate = new Date();
    
    
    CurrentYear = TodaysDate.getYear();
    if (CurrentYear < 2000) 
        CurrentYear = CurrentYear + 1900;
    currentMonth = TodaysDate.getMonth();
    DayOffset = TodaysDate.getDay();
    currentDay = TodaysDate.getDate();
    month = TodaysMonth[currentMonth];
    if (month == 'February') 
    {
        if (((CurrentYear % 4)==0) && ((CurrentYear % 100)!=0) || ((CurrentYear % 400)==0)) 
        {
            DaysinMonth[1] = 29;
        }
        else 
        {
            DaysinMonth[1] = 28;
        }
    }
    days = DaysinMonth[currentMonth];
    currentDay += DaystoAdd;
    if (currentDay > days) 
    {
        if (currentMonth == 11) 
        {
            currentMonth = 0;
            month = TodaysMonth[currentMonth];
            CurrentYear = CurrentYear + 1;
            }
        else 
        {
            month =
                TodaysMonth[currentMonth+1];
        }
        currentDay = currentDay - days;
    }
    DayOffset += DaystoAdd;
    
    offsettheDate(DayOffset);
	
	TheDate  = DayOffset + ', ';
    TheDate += currentDay + ' '; 
    TheDate += month + ' ';

    if (CurrentYear<100) CurrentYear="19" + CurrentYear;
    TheDate += CurrentYear;
    document.write(' '+TheDate);
}


// adds the specified number of days to the current day and returns the resulting date
	function addDays(numDays)
	{
    TodaysDate = new Date();
    
    
    CurrentYear = TodaysDate.getYear();
    if (CurrentYear < 2000) 
        CurrentYear = CurrentYear + 1900;
    currentMonth = TodaysDate.getMonth();
    DayOffset = TodaysDate.getDay();
    currentDay = TodaysDate.getDate();
    if (currentMonth == 1) 
    {
        if (((CurrentYear % 4)==0) && ((CurrentYear % 100)!=0) || ((CurrentYear % 400)==0)) 
        {
            DaysinMonth[1] = 29;
        }
        else 
        {
            DaysinMonth[1] = 28;
        }
    }
    days = DaysinMonth[currentMonth];
    currentDay += numDays;
    if (currentDay > days) 
    {
        if (currentMonth == 11) 
        {
            currentMonth = 0;
            CurrentYear = CurrentYear + 1;
            }
        else 
        {
            currentMonth = currentMonth+1;
        }
        currentDay = currentDay - days;
    }
    DayOffset += numDays;
    
	var newTime = new Date();
	newTime.setDate(currentDay); 
	newTime.setMonth(currentMonth);
	newTime.setYear(CurrentYear);
 
	return (newTime);
	}




	function setWeddingCookie(weddingNumber)
	{
		setEquinoxCookie('wedding', weddingNumber, addDays(1));
	}
	
	function checkWedding(weddingNumber)
	{
		accessWedding = getEquinoxCookie('wedding');
		
		if(accessWedding != weddingNumber)
			document.location.href = 'http://www.equinoxshop.com/html/weddinglists.shtml';
			
	}
	

	function pageScroll() {
    		window.scrollBy(0,2); // horizontal and vertical scroll increments
    		scrolldelay = setTimeout('pageScroll()',200); // scrolls every 100 milliseconds
	}
//-->
