var popup = null;
var subMenu = null;
var menu = null;

function SubHeaderOver(obj)
{
	if (obj.className.indexOf("Over") < 0)
		obj.className += "Over";
}

function SubHeaderOut(obj)
{
	if (obj.className.indexOf("Over") >= 0)
		obj.className = obj.className.substring(0, obj.className.length-4);
}

function HeaderOver(obj)
{
	ResetSubmenu();

	if (obj.className == "mainlinkon")
		obj.style.backgroundColor = "#C01328";
	else
		obj.style.backgroundColor = "#D34E4B";

	if (document.getElementById(obj.id + "SubMenu"))
	{
		menu = obj;
		subMenu = document.getElementById(obj.id + "SubMenu");
		subMenu.style.visibility = "visible";
	} 
}

function HeaderOut(obj)
{
	if (ResetSubmenu(obj.id))
	{
		obj.style.backgroundColor = "";
	}
}

function ResetSubmenu(sExceptFor)
{
	if (subMenu)
	{
		if (sExceptFor)
		{
			if (subMenu.id == sExceptFor + "SubMenu")
				return false;
		}
		subMenu.style.visibility = "";
		if (menu)
			menu.style.backgroundColor = "";
	}
	else
	{
		if (menu)
			menu.style.backgroundColor = "";
	}
	return true;
}

function ColHover(obj, nCol, bOnOff)
{
	sBGColor = (nCol == 4) ? "#FCEFEB" : "#ECECEC"
	tBody = obj.parentNode.parentNode
	nPos = nCol;
	for (nNode = 0; nNode < obj.parentNode.childNodes.length; nNode++)
	{
		if (obj.parentNode.childNodes[nNode] == obj)
		{
			nPos = nNode;
			break;
		}
	}
	for (nRow = 0; nRow < tBody.childNodes.length; nRow++)
	{
		tr = tBody.childNodes[nRow];
		if (tr.childNodes.length > nPos)
		{
			tr.childNodes[nPos].style.backgroundColor = bOnOff ? sBGColor : "";
			if (tr.childNodes[nPos].className == "HomeCellRightBottom")
				tr.childNodes[nPos].style.backgroundImage = bOnOff ? "url(\"images/pinkquote2.gif\")" : "url(\"images/pinkquote.gif\")";
		}
	}
/*
	if (nCol == 3)
	{
		tBody.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.style.backgroundImage = bOnOff ? "none" : "";
	}
*/
	ResetSubmenu();
}

function OnBG(obj, bOnOff)
{
	obj.style.backgroundColor = bOnOff ? "#FFFFFF" : "";
}

// Get event source
function GetSource(event)
{
	if (event.srcElement)
		return event.srcElement;
	if (event.target)
		return event.target;
	return null;
}

// Get object
function GetObjByName(name)
{
	if (document[name])
		return document[name];
	else if (document.all)
		return document.all[name];
	return document.getElementById(name);
}

// Replace image
function RepImg(name, url)
{
	obj = GetObjByName(name);
	obj.src = url;
}

function RollOver(name)
{
	obj = GetObjByName(name);
	sUrl = obj.src;
	obj.src = sUrl.substring(0, sUrl.length-5) + "2" + sUrl.substring(sUrl.length-4, sUrl.length)
	if (obj.src.indexOf("huge-btn") >= 0)
	{
		obj = GetObjByName(name + "Text");
		if (obj)
			obj.style.top = "7px";
	}
}

function RollOut(name)
{
	obj = GetObjByName(name);
	sUrl = obj.src;
	obj.src = sUrl.substring(0, sUrl.length-5) + "1" + sUrl.substring(sUrl.length-4, sUrl.length)
	if (obj.src.indexOf("huge-btn") >= 0)
	{
		obj = GetObjByName(name + "Text");
		if (obj)
			obj.style.top = "6px";
	}
}

// Popup a URL
function Pop(url, nWidth, nHeight)
{
	if (!nWidth)
		nWidth = 630;
	if (!nHeight)
		nHeight = 500;
	popup = window.open(url, "CogniviewPopup", "directories=no, fullscreen=no, width=" + nWidth + ", height=" + nHeight + ", location=no, menubar=no, toolbar=no, scrollbars=yes", false);
	popup.focus();
}

// Popup an image in a new popup window
function PopImage(url, nWidth, nHeight)
{
	if (!nWidth)
		nWidth = 700;
	if (!nHeight)
		nHeight = 500;

	if (popup)
		popup.close();
	popup = window.open("about:blank", "CogniviewPopup", "directories=no, fullscreen=no, width=" + (nWidth + 40) + ", height=" + (nHeight + 50) + ", location=no, menubar=no, toolbar=no, scrollbars=yes", false);
	popup.document.write("<html><head><title>CogniView</title></head><body><center><img width=\"" + nWidth + "\" height=\"" + nHeight + "\" src=\"" + url + "\" /><br /><a href=\"javascript:window.close()\">Return to product tour</a></center></body></html>");
	popup.focus();
}

var sending = false;
function SendEmail()
{
	if (sending)
	{
		alert("Sending");
		return;
	}
	// validate
	if (document.FormEmail.email.value.indexOf("@") == -1)
	{
		alert("Please enter your e-mail address");
		document.FormEmail.email.focus();
		return;
	}
	if (document.FormEmail.email.value.length < 4)
	{
		alert("Please enter your e-mail address");
		document.FormEmail.email.focus();
		return;
	}
	if (document.FormEmail.message.value.length < 2)
	{
		alert("Please enter your message");
		document.FormEmail.message.focus();
		return;
	}

	sending = true;
	document.FormEmail.submit();
}

function FinishedSending(bSuccess, sMessage)
{
	sending = false;
	if (bSuccess)
	{
		document.FormEmail.SendBtn.disabled = true;
	}
	alert(sMessage);
}

function ShowLeftbarClosed(obj)
{
	var tBody = obj.parentNode.parentNode;
	for (nNode = 0; nNode < tBody.childNodes.length; nNode++)
	{
		var tr = tBody.childNodes[nNode];
		if ((tr.tagName == "TR") && (tr.className.indexOf("LeftBarPanelClosed") >= 0))
		{
			if (tr.style.display == "")
				tr.style.display = "inline";
			else
				tr.style.display = "";
		}
	}
}

