//Needed to reference objects across browser types.
var isW3C = (document.getElementById) ? true : false;
var isAll = (document.all) ? true : false;

function hide(id){

var elem = (isW3C) ? document.getElementById(id) : ((isAll) ? document.all[id] : null);
    if (elem) {
        elem.style.visibility = 'hidden';
    }
}

function show(id){
var elem = (isW3C) ? document.getElementById(id) : ((isAll) ? document.all[id] : null);
    if (elem) {
        elem.style.visibility = 'visible';
    }
}

function imageSwap(id, imageURL) {
var elem = (isW3C) ? document.getElementById(id) : ((isAll) ? document.all[id] : null);
    if (elem) {
        elem.src = imageURL;
    }
}

function over(id, color){
var elem = (isW3C) ? document.getElementById(id) : ((isAll) ? document.all[id] : null);
    if (elem) {
        elem.style.background = 'color';
    }
}

function out(id){
var elem = (isW3C) ? document.getElementById(id) : ((isAll) ? document.all[id] : null);
    if (elem) {
        elem.style.background = 'transparent';
    }
}

var Timer; //Variant to set the Timeout to

//This function returns true if the browser is Netscape 4.x
function UseLayers()
{
	if(navigator.appName == "Microsoft Internet Explorer")
	{
		return false;	
	}
 	else
 	{
		if(Number(String(navigator.appVersion).substring(0,1)) == 5) return false;
		else return true;
	}
}

function ShowMenu()
{

	if(Timer) clearTimeout(Timer);

	if(UseLayers())
	{
		for(i=0; i<document.layers.length; i++)
		{
			document.layers[i].visibility = "hidden";
		}

		for(n=0; n<arguments.length; n++)
		{
			eval("document." + arguments[n]).visibility = "visible";
			
		}
	}
	else
	{
		var cDivs = document.body.getElementsByTagName("div");

		for(i=0; i<cDivs.length; i++)
		{

			var sID = new String(cDivs[i].id);

			//Make sure the selected DIV is part of the menu system and not some other DIV used elsewhere on the site

			if (sID.substring(0,3) == "men")
			{
				//document.getElementById(cDivs[i].id).style.display="none";
				document.getElementById(cDivs[i].id).style.visibility="hidden";
				
				if (is_nav6 || is_opera)
				{
					if (document.getElementById("flashLayer") != null)
						document.getElementById("flashLayer").style.visibility="visible";
				}
			}
		}

		for(n=0; n<arguments.length; n++)
		{

			//document.getElementById(arguments[n]).style.visibility="visible";
			document.getElementById(arguments[n]).style.visibility="visible";
			//document.getElementById(arguments[n]).style.display="block";
			
			if (is_nav6 || is_opera)
			{
				if (document.getElementById("flashLayer") != null)
					document.getElementById("flashLayer").style.visibility="hidden";
			}
		}
	}
}



function HideMenu()
{
	Timer = setTimeout("ShowMenu()", 500);
}

var popupWin;

function openPopup(url, width, height)
{
	
	if (popupWin != null)
	{
		popupWin.close();
		
	}
	popupWin = window.open(url,"popupWin","width=" + width + ", height=" + height);
	popupWin.focus();
}

var discountWin;
var mainWin = window.opener;
function OpenDiscountWindow()
{
	if (discountWin != null)
	{
		discountWin.close();
	
	}
	
	discountWin = window.open("discount.php","discountWin","width=550, height=570, status=yes, toolbar=no");
	
	if (discountWin.opener != null)
	{
		discountWin.opener.focus();
	}

}



function DiscountCartRedirect()
{
	if ((mainWin != null) && (mainWin.closed != true))
	{
		mainWin.location.href = "http://store.breathrx.com/cart.php";
	}
	else
	{
		mainWin = null;
		mainWin = window.open("http://store.breathrx.com/cart.php");
	}
	
	this.close();

}

function MainWindowRedirect(url)
{
	if ((mainWin != null) && (mainWin.closed != true))
	{
		mainWin.location.href = url;
	}
	else
	{
		mainWin = null;
		mainWin = window.open(url);
	}
	
	this.close();

}
