// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var IE = document.all?true:false

// If NS -- that is, !IE -- then set up for mouse capture
//if (!IE) document.captureEvents(Event.MOUSEMOVE)

// Set-up to use getMouseXY function onMouseMove
//document.onmousemove = getMouseXY;

// Temporary variables to hold mouse x-y pos.s
var tempX = 0;
var tempY = 0;
var helpMsg="";
var width=0;
var displayHelp=false;
var displayed = false;
var helpLoaded = false;
var lastUpdate = "window";

// Main function to retrieve mouse x-y pos.s

function getMouseXY(e) {
	if (IE) { // grab the x-y pos.s if browser is IE
		tempX = event.clientX ;
		tempY = event.clientY ;
	} else {  // grab the x-y pos.s if browser is NS
		tempX = e.pageX;
		tempY = e.pageY;
	}
	
	//adjust for scroll position
	var x,y;
	if (self.pageYOffset) // all except Explorer
	{
		x = self.pageXOffset;
		y = self.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop)
		// Explorer 6 Strict
	{
		x = document.documentElement.scrollLeft;
		y = document.documentElement.scrollTop;
		
		tempX += x;
		tempY += y;
	}
	else if (document.body) // all other Explorers
	{
		x = document.body.scrollLeft;
		y = document.body.scrollTop;
		
		tempX += x;
		tempY += y;
	}
	
	lastUpdate = "window";
	doMouseActions();
}

function doMouseActions()
{		
	//if lastUpdate == "frame" we need to adjust be offset of iframe
	//do that by looking at the 1x1 above it (should be in center, so horizOffset=xpos-780/2
	if(lastUpdate=="frame")
	{
		if (document.getElementById)
		{
			tempY += document.getElementById("frameTop").offsetTop + 1;
			tempX += document.getElementById("frameTop").offsetLeft - 780/2 -1;
		}
		else if (document.all)
		{
			tempY += document.all.frameTop.offsetTop;
			tempX += document.all.frameTop.offsetLeft - 780/2;
		}
	}
	
	// catch possible negative values in NS4
	if (tempX < 0){tempX = 0}
	if (tempY < 0){tempY = 0}
	
	var helpHeight = 0;
	var helpWidth = 0;
	
	var docheight = 0, docwidth = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		docwidth = window.innerWidth;
		docheight = window.innerHeight;
	} else if( document.documentElement &&
		( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		docwidth = document.documentElement.clientWidth;
		docheight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		docwidth = document.body.clientWidth;
		docheight = document.body.clientHeight;
	}
	
	if(displayHelp)
	{
		doDisplayHelp(docheight, docwidth);
		doDisplayHelpBlanket();
	}
	else
	{
		//hide help
		if(helpLoaded)
		{
			var help = gethelpobj();
			help.width = width + "px";
			help.top = -1000 + "px";
			help.left = -1000 + "px";
			
			var helpBlanket = gethelpblanketobj();
			helpBlanket.width = width + "px";
			helpBlanket.top = -1000 + "px";
			helpBlanket.left = -1000 + "px";
		}
	}
	return true
}

function GetScrollPos()
{
	if( typeof( window.innerWidth ) == 'number' ) {
	//Non-IE
		return window.pageYOffset;
	} else if( document.documentElement &&
		( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		return document.documentElement.scrollTop;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		return document.body.scrollTop;
	}
	return 0;
}

function doDisplayHelp(docheight, docwidth)
{
	var help = gethelpobj();
	help.width = width + "px";
	helpHeight = gethelpheight();
	helpWidth = gethelpwidth();
	
	if(!displayed)
	{
		var helpTxt = document.getElementById("helpText");
		helpTxt.innerHTML = helpMsg;
		displayed = true;
	}
	
	//little bit of logic to decide where to put help..
	var scrollPos = GetScrollPos();
	
	if(tempY + helpHeight - scrollPos <= (docheight - 50) )
	{
		help.top = (tempY + 25) + "px";
	}
	else
	{
		help.top = (tempY - helpHeight - 25) + "px";
	}
	
	if(tempX - helpWidth / 2 > 0)
	{
		if(tempX + helpWidth / 2 < docwidth - 30)
		{
			help.left = (tempX - helpWidth / 2) + "px";
		}
		else
		{
			help.left = (docwidth - 30 - helpWidth) + "px";
		}
	}
	else
	{
		help.left = "0px";
	}
}

function doDisplayHelpBlanket()
{
	var help = gethelpblanketobj();
	help.width = gethelpwidth() + 5 + "px";
	help.height = gethelpheight() + 5 + "px";
	help.top = gethelpobj().top;
	help.left = gethelpobj().left;
}

function hideHelp()
{
	doHideHelp();
}

function doHideHelp()
{
	displayHelp = false;
	displayed = false;
}

function showHelpE(msg, helpWidth)
{
	helpMsg = msg;
	displayHelp = true;
	width = helpWidth;
}

function resizeContentFrame(h)
{
	if (document.getElementById)
		document.getElementById("contentFrame").height = h;
	else if (document.all)
		document.all.contentFrame.height = h;
	
	//hide the loading notice
	if (document.getElementById)
		document.getElementById("loadingNotice").style.top = -1000;
	else if (document.all)
		document.all.loadingNotice.style.top = -1000;
}

function askAQuestion()
{
	resizeQuestionFrame();
}

function setScrollPos(p)
{
	if( typeof( window.innerWidth ) == 'number' ) {
	//Non-IE
		window.pageYOffset = p;
	} else if( document.documentElement &&
		( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		document.documentElement.scrollTop = p;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		document.body.scrollTop = p;
	}
}

function resizeQuestionFrame()
{
	var h = 300;
	
	var th = 0;
	th = Math.floor(h/15);
	for(var i=0; th<h; i++)
	{
		th += Math.floor((h-th)/15) + 1;
		setTimeout('doQResize(' + th + ')', 30*i);
	}
	
	//scroll to top of page so they can type in the question
	if(IE)
	setScrollPos(0);
}

function doQResize(h)
{
	if (document.getElementById)
		document.getElementById("questionFrame").style.height = h + "px";
	else if (document.all)
		document.all.questionFrame.style.height = h + "px";
}

function hideQuestionFrame(h)
{
	if (document.getElementById)
		document.getElementById("questionFrame").style.height = "0px";
	else if (document.all)
		document.all.questionFrame.style.height = "0px";
}

function showHelp(desc)
{
	helpMsg = desc;
	displayHelp = true;
	//width = 250;
}

function gethelpobj(){
	if (document.getElementById)
		return document.getElementById("helpTable").style
	else if (document.all)
		return document.all.helpTable.style
}

function gethelpblanketobj(){
	if (document.getElementById)
		return document.getElementById("helpBlanket").style
	else if (document.all)
		return document.all.helpBlanket.style
}

function gethelpheight(){
	if (document.getElementById)
	{
		return findPosY(document.getElementById("helpBottom")) - findPosY(document.getElementById("helpTop"));
	}
	else if (document.all)
	{
		return findPosY(document.all.helpBottom) - findPosY(document.all.helpTop);
	}
}

function gethelpwidth(){
	if (document.getElementById)
	{
		return findPosX(document.getElementById("helpRight")) - findPosX(document.getElementById("helpTop"));
	}
	else if (document.all)
	{
		return findPosX(document.all.helpRight) - findPosX(document.all.helpTop);
	}
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function addToFavorites()
{
	if (window.external)
	{
		window.external.AddFavorite(location.href,document.title)
	}
	else
	{ 
		alert("Sorry! Your browser doesn't support this function.");
	}
}

function PrintNotice()
{
	alert("Please use the printer friendly version of the page to print this page");
}


//son of a suckerfish JS
sfHover = function() 
{ 
		if(document.getElementById("MainMenu"))
		{
    var sfEls = document.getElementById("MainMenu").getElementsByTagName("li"); 
    for (var i=0; i<sfEls.length; i++) 
    { 
        sfEls[i].onmouseover=function() 
            { this.className+=" sfhover"; } 
        sfEls[i].onmouseout=function() 
            { this.className=this.className.replace(new RegExp(" sfhover\\b"), ""); } 
    } 
    }
    if(document.getElementById("offers"))
    {
    var sfEls = document.getElementById("offers").getElementsByTagName("li"); 
    for (var i=0; i<sfEls.length; i++) 
    { 
        sfEls[i].onmouseover=function() 
            { this.className+=" sfhover"; } 
        sfEls[i].onmouseout=function() 
            { this.className=this.className.replace(new RegExp(" sfhover\\b"), ""); } 
    }
    } 
} 
if (window.attachEvent) window.attachEvent("onload", sfHover);