function toggleBox(szDivID, iState) // 1 visible, 0 hidden
{
   var obj = document.layers ? document.layers[szDivID] :
   document.getElementById ?  document.getElementById(szDivID).style :
   document.all[szDivID].style;
   obj.display = document.layers ? (iState ? "block" : "none") :
   (iState ? "block" : "none");
}

// AJAX REPLACE TEXT FUNCTIONS
function replaceText(el, text) {
  if (el != null) {
    clearText(el);
    var newNode = document.createTextNode(text);
    el.appendChild(newNode);
  }
}
			
function clearText(el) {
  if (el != null) {
    if (el.childNodes) {
      for (var i = 0; i < el.childNodes.length; i++) {
        var childNode = el.childNodes[i];
        el.removeChild(childNode);
      }
    }
  }
}

/* Used in Store Locator */
function findStores(){
	var zip = document.getElementById('custZip').value;

	if(zip !=null && zip.length >4){
		document.getElementById('StoreLocatorForm').submit();
	}
	replaceText(document.getElementById('storeError'),'zip error.');
}

// SETS THE FOOTER TO BOTTOM OF PAGE 
var FOOTER_NAME		= 'Footer';
var CONTENT_NAME	= 'Main';
var FOOTER_HEIGHT	= 80;

function getWindowHeight() {
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
	
	}else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
	
		}else {
			if (document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}

/* Updates footer with remainder of winHt - contentHt.*/
function setFooter() {
	if (document.getElementById) {
		var windowHeight = getWindowHeight();
		if (windowHeight > 0) {
			var contentHeight = document.getElementById(CONTENT_NAME).offsetHeight;
			var footerElement = document.getElementById(FOOTER_NAME);
				
			var footerHeight  = windowHeight - contentHeight;
			
			if (windowHeight - (contentHeight + FOOTER_HEIGHT) >= 0) {
				footerElement.style.height = footerHeight +'px';
			}else {
				footerElement.style.height = FOOTER_HEIGHT +'px';
			}
		}
	}
}

window.onload = function() {
	if(document.getElementById(FOOTER_NAME))
		setFooter();
}

window.onresize = function() {
	if(document.getElementById(FOOTER_NAME))
		setFooter();
}
// END OF SETTING THE FOOTER TO BOTTOM OF PAGE 
