var isIE;
var isIE6;
var displayTableCell;

function getInternetExplorerVersion() {
/* Returns the version of Windows Internet Explorer or a -1
(indicating the use of another browser).*/
   var rv = -1; /* Return value assumes failure. (ml> A healthy assumption when dealing with MS) */
   if (navigator.appName == 'Microsoft Internet Explorer')
   {
      var ua = navigator.userAgent;
      var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
      if (re.exec(ua) != null)
         rv = parseFloat( RegExp.$1 );
   }
   return rv;
}

function slideOpen (sId, finalHeight) {
	var slidingElement = document.getElementById(sId);
	slidingElement.style.height = '1px';
	var actualHeight = 2;
	$(sId).style.display = 'block';
	var slideInt = setInterval(function () {
		while (actualHeight < finalHeight ) {
			slidingElement.style.height = actualHeight + 'px';
			actualHeight++;
		}
		clearInterval(slideInt);
	}, 500);
};

function slideClose (sId) {
	var slidingElement = document.getElementById(sId);
	var actualHeight = slidingElement.offsetHeight;
	var slideCloseInt = setInterval(function () {
		while (actualHeight >= 1 ) {
			slidingElement.style.height = actualHeight + 'px';
			actualHeight--;
		}
		$(sId).style.display = 'none';
		clearInterval(slideCloseInt);
	}, 500);
};

function validateForm () {
	var errBuffer = '';
	if ($('mib') && $('mib').value != '') {
		return false;
	}
	var oForm = document.forms['contact'];
	var email = oForm.email.value;
	if (email == '') {
		errBuffer += 'Please fill in your email address.\n';
	}
	else {
		var regX = /^[a-zA-Z0-9\.\+\-\_]*@[a-z0-9\.\+\-\_]*\.[a-z\.]{2,10}$/i;
		if (!regX.test(email)) {
			errBuffer += 'Email address is not valid\n';
		}
	}
	if (errBuffer != '') {
		alert (errBuffer);
		return false;
	}
}

function init() {
	if ($('fourth_nav')) {
		var menuItems = $('fourth_nav').getElement('ul');
		menuItems.className = 'promoList';
		var scrtiptHTML = menuItems.getElement('script').innerHTML;
		var menuItemsHTML = '';
		menuItems.getElements('li').each(function (listItem) {
			var rawTitle = listItem.getElement('a').innerHTML;
			var tmpArray = rawTitle.split('^');
			listItem.getElement('a').innerHTML = tmpArray[0];
			listItem.getElement('img').src += tmpArray[1];
			listItem.getElement('p.desc').innerHTML = tmpArray[2];
		});
		$('fourth_nav').style.visibility = 'visible';
	}	
	var ieVersion = getInternetExplorerVersion();
	if (ieVersion == 6.0) {
		var topMenuItems = $('navAndSearch').getElements('li');
		topMenuItems.each(function (listItem) {
			if (listItem.getElement('ul')) {
				listItem.onmouseover = function() {
					this.getElement('ul').style.display = 'block';
				};
				listItem.onmouseout = function() {
					this.getElement('ul').style.display = 'none';
				};
			}
		});
		if($('ie6Detector')) {
			$('ie6Detector').innerHTML = '<p><img src="/v/vspfiles/templates/DuplicateZen/images/close.gif" id="closeIe6Detector" width="16px height="16px" alt="close" title="close" /><a href="http://www.microsoft.com/windows/internet-explorer/default.aspx" target="_blank">Internet Explorer is missing updates required to view this site. Click here to update... </a></p>';
			try {
				slideOpen('ie6Detector', 15);
			}
			catch (e) {
				alert(e);
			}
			$('ie6Detector').onmouseover = function () {
				$('closeIe6Detector').src = '/v/vspfiles/templates/DuplicateZen/images/close-over.gif';
				$('closeIe6Detector').style.backgroundColor = '#3399ff';
				$('ie6Detector').style.backgroundColor = '#3399ff';
				$('ie6Detector').style.color = '#ffffff';
			}
			$('ie6Detector').onmouseout = function () {
				$('closeIe6Detector').src = '/v/vspfiles/templates/DuplicateZen/images/close.gif';
				$('closeIe6Detector').style.backgroundColor = '#FFFFE1';
				$('ie6Detector').style.backgroundColor = '#FFFFE1';
				$('ie6Detector').style.color = '#000000';
			}
			$('closeIe6Detector').onclick = function() {
				slideClose('ie6Detector');
			}
		}
	}
	if (ieVersion < 8.0 && ieVersion > -1) {
		displayTableCell = 'block';
	}
	else {
		displayTableCell = 'table-cell';
	}
	if ($('display_cart_summary')) {
		try {
			var cartTxt = $('display_cart_summary').getElement('div').innerHTML;
			var totalProducts = cartTxt.replace (/^.*contains\s?/gi,'');
			totalProducts = totalProducts.replace (/items.*$/,'');
			/*
			var totalProducts = cartTxt.replace (/^.*contains\s?/gi,'');
			totalProducts = totalProducts.replace (/items.*$/,'');
			if (totalProducts.indexOf('empty') > -1) {
				totalProducts = 0;
			}
			if (totalProducts != '' && totalProducts != '0') {
				$('totalProducts').innerHTML = "(" + (totalProducts) + " items)";
			}
			*/
		}
		catch(e) {};
	}
	if (location.href.toLowerCase().indexOf('default.asp') > -1) {
		location = 'http://' + location.host;
	} else if (location.pathname != '/' && location.pathname != '/default.asp' && location.pathname.indexOf('52.htm') < 0 && location.pathname.toLowerCase() != '/shoppingcart.asp'  && location.pathname != '/one-page-checkout.asp') {
		$('nav_menu').style.display = displayTableCell;
		$('right_panel').style.display = displayTableCell;
		$('content_area').style.width = '585px';
	}
	if ('/shoppingcart.asp' == location.pathname.toLowerCase() || '/one-page-checkout.asp' == location.pathname.toLowerCase()) {
		$('header_nav').style.display = 'none';
		$('navAndSearch').style.display = 'none';
		$('footer').style.display = 'none';
	}
	try {
		var breadCrumbHTML = $('content_area').getElement('b').innerHTML;
		breadCrumbHTML = breadCrumbHTML.replace (/You are here:/gi,'');
		breadCrumbHTML = breadCrumbHTML.replace (/\^.*</gi,'<');
		$('content_area').getElement('b').innerHTML = breadCrumbHTML;
	}
	catch(e) {};
	/* Add to my registry init:*/
	
}

window.onload = init;

