/* kill all javascript error alerts  */
function WipeErrorAlert() {
return true;
}
window.onerror = WipeErrorAlert;

/* reload page on resize to cope with Netscape 4 weirdness */
/* resize.js 0.3 970811 by gary smith */

if(!window.saveInnerWidth) {
  window.onresize = resizeIt;
  window.saveInnerWidth = window.innerWidth;
  window.saveInnerHeight = window.innerHeight;
}

function resizeIt() {
    if (saveInnerWidth < window.innerWidth || 
        saveInnerWidth > window.innerWidth || 
        saveInnerHeight > window.innerHeight || 
        saveInnerHeight < window.innerHeight ) 
    {
        window.history.go(0);
    }
}

/* check whether browser complies with the Document Object Model i.e. Version 5 browser */

var domBrowser = (
	document.getElementById && document.getElementsByTagName && document.createElement
	&&
	!(navigator.userAgent.indexOf('MSIE 5') != -1 && navigator.userAgent.indexOf('Mac') != -1)
	);

/* add facility to hide or show text only for DOM-compliant browsers */

if (domBrowser)
	document.write('<style>.DomBrowserHide{display: none}</style>');
	document.write('<style>.DomBrowserShow{display: block}</style>');
	
/* add outlining function for msie only */

	// Returns the closest parent tag with tagName containing
	// the src tag. If no such tag is found - null is returned.
function checkParent( src, tagName ) {
	while ( src != null ) {
		if (src.tagName == tagName) 
			return src;
		src = src.parentElement;
	}
	return null;
}

	
	// Returns the first tag with tagName contained by
	// the src tag. If no such tag is found - null is returned.
function checkContent( src, tagName ) {
	var pos = src.sourceIndex ;
	while ( src.contains( document.all[++pos] ) )
		if ( document.all[pos].tagName == tagName )
			return document.all[pos] ;
	return null ;
}

      
	// Handle onClick event in the outline box
function outlineAction() {     
	var src = event.srcElement ;
	var item = checkParent( src, "LI" ) ;

	if ( parent != null ) {
		var content = checkContent( item, "UL" ) ;

		if ( content != null )
			if ( content.style.display == "" )
				content.style.display = "block" ;
			else
				content.style.display = "" ;
	}
	event.cancelBubble = true;
}
    
/* Now we add the persistent expand/collapse content function */

var enablepersist="on" //Enable saving state of content structure? (on/off) 
if (document.getElementById){ 
document.write('<style type="text/css">') 
document.write('.switchcontent{display:none;}') 
document.write('</style>') 
} 
function getElementbyClass(classname){ 
ccollect=new Array() 
var inc=0 
var alltags=document.all? document.all : document.getElementsByTagName("*") 
for (i=0; i<alltags.length; i++){ 
if (alltags[i].className==classname) 
ccollect[inc++]=alltags[i] 
} 
} 
function contractcontent(omit){ 
var inc=0 
while (ccollect[inc]){ 
if (ccollect[inc].id!=omit) 
ccollect[inc].style.display="none" 
inc++ 
} 
} 
function expandcontent(cid){ 
if (typeof ccollect!="undefined"){ 
contractcontent(cid) 
document.getElementById(cid).style.display=(document.getElementById(cid).style.display!="block")? "block" : "none" 
selectedItem=cid+"|"+document.getElementById(cid).style.display 
} 
} 
function revivecontent(){ 
selectedItem=getselectedItem() 
selectedComponents=selectedItem.split("|") 
contractcontent(selectedComponents[0]) 
document.getElementById(selectedComponents[0]).style.display=selectedComponents[1] 
} 
function get_cookie(Name) { 
var search = Name + "=" 
var returnvalue = ""; 
if (document.cookie.length > 0) { 
offset = document.cookie.indexOf(search) 
if (offset != -1) { 
offset += search.length 
end = document.cookie.indexOf(";", offset); 
if (end == -1) end = document.cookie.length; 
returnvalue=unescape(document.cookie.substring(offset, end)) 
} 
} 
return returnvalue; 
} 
function getselectedItem(){ 
if (get_cookie(window.location.pathname) != ""){ 
selectedItem=get_cookie(window.location.pathname) 
return selectedItem 
} 
else 
return "" 
} 
function saveswitchstate(){ 
if (typeof selectedItem!="undefined") 
document.cookie=window.location.pathname+"="+selectedItem 
} 
function do_onload(){ 
getElementbyClass("switchcontent") 
if (enablepersist=="on" && getselectedItem()!="") 
revivecontent() 
} 
if (window.addEventListener) 
window.addEventListener("load", do_onload, false) 
else if (window.attachEvent) 
window.attachEvent("onload", do_onload) 
else if (document.getElementById) 
window.onload=do_onload 
if (enablepersist=="on" && document.getElementById) 
window.onunload=saveswitchstate 

/* The survey cookie to let the site open windows as necessary without popping up a survey form */

function writeSurveyTempCookie()
{
    var expire = new Date();
    expire.setTime(expire.getTime() + 30000);
    document.cookie="eChoiceSurveyTemp=XXXX" +"; expires="+expire.toGMTString()+"; path=/";  
}

/* Check an email address */

var testresults
function checkemail(){
var str=document.feedback.email.value
var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
if (filter.test(str))
testresults=true
else{
alert("Please give us a valid email address")
testresults=false
}
return (testresults)
}

function checkaddress(){
if (document.layers||document.getElementById||document.all)
return checkemail()
else
return true
}

/* Used on HLA1a */

function SetHomePropSame(){
for (i=0;i<document.forms[0].HomePropSame.length;i++)
	{
		if (document.forms[0].HomePropSame[1].checked)
		{
			document.getElementById('textdiv').style.display='block';
		}
 	   else {
 	        document.getElementById('textdiv').style.display='none';
 	   }
	}
}

/* Michael Suodenjoki's auto-caption for images */

function addCaption( oImgElem, bUseCaptionMarker )
{
  // Insert Caption
  var oCaptionElem = document.createElement("div");
  oCaptionElem.className = "caption";

  if( bUseCaptionMarker)
  {
    var oCaptionMarkerElem = document.createElement("div");
    oCaptionMarkerElem.className = "caption-marker";
    var oCaptionMarkerTextElem = document.createTextNode("\u25A1");
    oCaptionMarkerElem.appendChild(oCaptionMarkerTextElem);
    oCaptionElem.appendChild(oCaptionMarkerElem );
  }

  var oCaptionTextElem = document.createElement("div");
  oCaptionTextElem.className = "caption-text";
  var oCaptionText = document.createTextNode( oImgElem.alt );
  oCaptionTextElem.appendChild(oCaptionText );
  oCaptionElem.appendChild(oCaptionTextElem);

  if( oImgElem.getAttribute("copyright") != null )
  {
    var oCopyrightElem = document.createElement("div");
    oCopyrightElem.className = "copyright";
    var oCopyrightText = document.createTextNode( 
      oImgElem.getAttribute("copyright") );
    oCopyrightElem.appendChild(oCopyrightText);
    oCaptionElem.appendChild(oCopyrightElem );
  }

  if(oImgElem.nextSibling) 
    oImgElem.parentNode.insertBefore(oCaptionElem,
      oImgElem.nextSibling);
  else
    oImgElem.parentNode.appendChild(oCaptionElem);

  with(oImgElem.style)
  {
    oCaptionElem.style.width = (oImgElem.width+borderLeft+
      borderRight+paddingLeft+paddingRight)+"px";
  }

  return true; 
}

/* easytoggle2.js for tabbed displays
   - Simon Willison, 5th November 2003
   - See http://simon.incutio.com/archive/2003/11/06/easytoggle
*/

addEvent(window, 'load', et_init);

var et_toggleElements = [];

/* Initialisation */
function et_init() {
    var i, link, id, target, first;
    first = true;
    for (i = 0; (link = document.links[i]); i++) {
        if (/\btoggle\b/.exec(link.className)) {
            id = link.href.split('#')[1];
            target = document.getElementById(id);
            et_toggleElements[et_toggleElements.length] = target;
            if (first) {
                first = false;
            } else {
                target.style.display = 'none';
            }
            link.onclick = et_toggle;
        }
    }
}

function et_toggle(e) {
    /* Adapted from http://www.quirksmode.org/js/events_properties.html */
    if (typeof e == 'undefined') {
        var e = window.event;
    }
    var source;
    if (typeof e.target != 'undefined') {
        source = e.target;
    } else if (typeof e.srcElement != 'undefined') {
        source = e.srcElement;
    } else {
        return true;
    }
    /* For most browsers, targ would now be a link element; Safari however
       returns a text node so we need to check the node type to make sure */
    if (source.nodeType == 3) {
        source = source.parentNode;
    }
    var id = source.href.split('#')[1];
    var elem;
    for (var i = 0; (elem = et_toggleElements[i]); i++) {
        if (elem.id != id) {
            elem.style.display = 'none';
        } else {
            elem.style.display = 'block';
        }
    }
    return false;
}

/* Thanks to Scott Andrew */
function addEvent(obj, evType, fn){
    if (obj.addEventListener) {
        obj.addEventListener(evType, fn, true);
        return true;
    } else if (obj.attachEvent) {
        var r = obj.attachEvent("on"+evType, fn);
        return r;
    } else {
	    return false;
    }
}


/* Simon Willison's Sitepoint form code (http://www.sitepoint.com/article/1259) - relies on Scott Andrew's addEvent function above */

/* addEvent(window, 'load', function() { 
 document.getElementById('myfield').focus() 
}); 
*/

function getLabelForId(id) {
    var label, labels = document.getElementsByTagName('label');
    for (var i = 0; (label = labels[i]); i++) {
        if (label.htmlFor == id) {
            return label;
        }
    }
    return false;
}

addEvent(window, 'load', function() { 
 var input, textarea; 
 var inputs = document.getElementsByTagName('input'); 
 for (var i = 0; (input = inputs[i]); i++) { 
   addEvent(input, 'focus', oninputfocus); 
   addEvent(input, 'blur', oninputblur); 
 } 
 var textareas = document.getElementsByTagName('textarea'); 
 for (var i = 0; (textarea = textareas[i]); i++) { 
   addEvent(textarea, 'focus', oninputfocus); 
   addEvent(textarea, 'blur', oninputblur); 
 } 
}); 
function oninputfocus(e) { 
 /* Cookie-cutter code to find the source of the event */ 
 if (typeof e == 'undefined') { 
   var e = window.event; 
 } 
 var source; 
 if (typeof e.target != 'undefined') { 
    source = e.target; 
 } else if (typeof e.srcElement != 'undefined') { 
    source = e.srcElement; 
 } else { 
   return; 
 } 
 /* End cookie-cutter code */ 
 /* Uncomment to style */ 
source.style.border='1px solid #ee2222';

} 
function oninputblur(e) { 
 /* Cookie-cutter code to find the source of the event */ 
 if (typeof e == 'undefined') { 
   var e = window.event; 
 } 
 var source; 
 if (typeof e.target != 'undefined') { 
    source = e.target; 
 } else if (typeof e.srcElement != 'undefined') { 
    source = e.srcElement; 
 } else { 
   return; 
 } 
 /* End cookie-cutter code */ 
source.style.border='1px solid #eceeee';
}

/* End */

/*	Dynamic Heading Generator
    By Stewart Rosenberger 
    http://www.stewartspeak.com/headings/

	This script searches through a web page for specific or general elements
	and replaces them with dynamically generated images, in conjunction with
	a server-side script.
*/

function com_stewartspeak_replacement() {

replaceSelector("h2","http://www.shorewalker.com/noindex/scripts/heading.php",true);
var testURL = "../../noindex/images/furniture/spacer.png" ;

var doNotPrintImages = false;
var printerCSS = "replacement-print.css";

var hideFlicker = false;
var hideFlickerCSS = "replacement-screen.css";
var hideFlickerTimeout = 1000;




/* ---------------------------------------------------------------------------
    For basic usage, you should not need to edit anything below this comment.
    If you need to further customize this script's abilities, make sure
	you're familiar with Javascript. And grab a soda or something.
*/

var items;
var imageLoaded = false;
var documentLoaded = false;

function replaceSelector(selector,url,wordwrap)
{
	if(typeof items == "undefined")
		items = new Array();

	items[items.length] = {selector: selector, url: url, wordwrap: wordwrap};
}

if(hideFlicker)
{		
	document.write('<link id="hide-flicker" rel="stylesheet" media="screen" href="' + hideFlickerCSS + '" />');		
	window.flickerCheck = function()
	{
		if(!imageLoaded)
			setStyleSheetState('hide-flicker',false);
	};
	setTimeout('window.flickerCheck();',hideFlickerTimeout)
}

if(doNotPrintImages)
	document.write('<link id="print-text" rel="stylesheet" media="print" href="' + printerCSS + '" />');

var test = new Image();
test.onload = function() { imageLoaded = true; if(documentLoaded) replacement(); };
test.src = testURL + "?date=" + (new Date()).getTime();

addLoadHandler(function(){ documentLoaded = true; if(imageLoaded) replacement(); });


function documentLoad()
{
	documentLoaded = true;
	if(imageLoaded)
		replacement();
}

function replacement()
{
	for(var i=0;i<items.length;i++)
	{
		var elements = getElementsBySelector(items[i].selector);
		if(elements.length > 0) for(var j=0;j<elements.length;j++)
		{
			if(!elements[j])
				continue ;
		
			var text = extractText(elements[j]);
    		while(elements[j].hasChildNodes())
				elements[j].removeChild(elements[j].firstChild);

			var tokens = items[i].wordwrap ? text.split(' ') : [text] ;
			for(var k=0;k<tokens.length;k++)
			{
				var url = items[i].url + "?text="+escape(tokens[k]+' ')+"&selector="+escape(items[i].selector);
				var image = document.createElement("img");
				image.className = "replacement";
				image.alt = tokens[k] ;
				image.src = url;
				elements[j].appendChild(image);
			}

			if(doNotPrintImages)
			{
				var span = document.createElement("span");
				span.style.display = 'none';
				span.className = "print-text";
				span.appendChild(document.createTextNode(text));
				elements[j].appendChild(span);
			}
		}
	}

	if(hideFlicker)
		setStyleSheetState('hide-flicker',false);
}

function addLoadHandler(handler)
{
	if(window.addEventListener)
	{
		window.addEventListener("load",handler,false);
	}
	else if(window.attachEvent)
	{
		window.attachEvent("onload",handler);
	}
	else if(window.onload)
	{
		var oldHandler = window.onload;
		window.onload = function piggyback()
		{
			oldHandler();
			handler();
		};
	}
	else
	{
		window.onload = handler;
	}
}

function setStyleSheetState(id,enabled) 
{
	var sheet = document.getElementById(id);
	if(sheet)
		sheet.disabled = (!enabled);
}

function extractText(element)
{
	if(typeof element == "string")
		return element;
	else if(typeof element == "undefined")
		return element;
	else if(element.innerText)
		return element.innerText;

	var text = "";
	var kids = element.childNodes;
	for(var i=0;i<kids.length;i++)
	{
		if(kids[i].nodeType == 1)
		text += extractText(kids[i]);
		else if(kids[i].nodeType == 3)
		text += kids[i].nodeValue;
	}

	return text;
}

/*
	Finds elements on page that match a given CSS selector rule. Some
	complicated rules are not compatible.
	Based on Simon Willison's excellent "getElementsBySelector" function.
	Original code (with comments and description):
		http://simon.incutio.com/archive/2003/03/25/getElementsBySelector
*/
function getElementsBySelector(selector)
{
	var tokens = selector.split(' ');
	var currentContext = new Array(document);
	for(var i=0;i<tokens.length;i++)
	{
		token = tokens[i].replace(/^\s+/,'').replace(/\s+$/,'');
		if(token.indexOf('#') > -1)
		{
			var bits = token.split('#');
			var tagName = bits[0];
			var id = bits[1];
			var element = document.getElementById(id);
			if(tagName && element.nodeName.toLowerCase() != tagName)
				return new Array();
			currentContext = new Array(element);
			continue;
		}

		if(token.indexOf('.') > -1)
		{
			var bits = token.split('.');
			var tagName = bits[0];
			var className = bits[1];
			if(!tagName)
				tagName = '*';

			var found = new Array;
			var foundCount = 0;
			for(var h=0;h<currentContext.length;h++)
			{
				var elements;
				if(tagName == '*')
					elements = currentContext[h].all ? currentContext[h].all : currentContext[h].getElementsByTagName('*');
				else
					elements = currentContext[h].getElementsByTagName(tagName);

				for(var j=0;j<elements.length;j++)
					found[foundCount++] = elements[j];
			}

			currentContext = new Array;
			var currentContextIndex = 0;
			for(var k=0;k<found.length;k++)
			{
				if(found[k].className && found[k].className.match(new RegExp('\\b'+className+'\\b')))
					currentContext[currentContextIndex++] = found[k];
			}

			continue;
	    }

		if(token.match(/^(\w*)\[(\w+)([=~\|\^\$\*]?)=?"?([^\]"]*)"?\]$/))
		{
			var tagName = RegExp.$1;
			var attrName = RegExp.$2;
			var attrOperator = RegExp.$3;
			var attrValue = RegExp.$4;
			if(!tagName)
				tagName = '*';

			var found = new Array;
			var foundCount = 0;
			for(var h=0;h<currentContext.length;h++)
			{
				var elements;
	        	if(tagName == '*')
					elements = currentContext[h].all ? currentContext[h].all : currentContext[h].getElementsByTagName('*');
				else
					elements = currentContext[h].getElementsByTagName(tagName);

				for(var j=0;j<elements.length;j++)
					found[foundCount++] = elements[j];
			}

			currentContext = new Array;
			var currentContextIndex = 0;
			var checkFunction;
			switch(attrOperator)
			{
				case '=':
					checkFunction = function(e) { return (e.getAttribute(attrName) == attrValue); };
					break;
				case '~':
					checkFunction = function(e) { return (e.getAttribute(attrName).match(new RegExp('\\b'+attrValue+'\\b'))); };
					break;
				case '|':
					checkFunction = function(e) { return (e.getAttribute(attrName).match(new RegExp('^'+attrValue+'-?'))); };
					break;
				case '^':
					checkFunction = function(e) { return (e.getAttribute(attrName).indexOf(attrValue) == 0); };
					break;
				case '$':
					checkFunction = function(e) { return (e.getAttribute(attrName).lastIndexOf(attrValue) == e.getAttribute(attrName).length - attrValue.length); };
					break;
				case '*':
					checkFunction = function(e) { return (e.getAttribute(attrName).indexOf(attrValue) > -1); };
					break;
				default :
					checkFunction = function(e) { return e.getAttribute(attrName); };
			}

			currentContext = new Array;
			var currentContextIndex = 0;
			for(var k=0;k<found.length;k++)
			{
				if(checkFunction(found[k]))
					currentContext[currentContextIndex++] = found[k];
			}

			continue;
		}

		tagName = token;
		var found = new Array;
		var foundCount = 0;
		for(var h=0;h<currentContext.length;h++)
		{
			var elements = currentContext[h].getElementsByTagName(tagName);
			for(var j=0;j<elements.length; j++)
				found[foundCount++] = elements[j];
		}

		currentContext = found;
	}

	return currentContext;
}


}// end of scope, execute code
if(document.createElement && document.getElementsByTagName && !navigator.userAgent.match(/opera\/?6/i))
	com_stewartspeak_replacement();
