//GET DOM
var isDHTML = 0;
var isID = 0;
var isAll = 0;
var isLayers = 0;

if (document.getElementById) {isID = 1; isDHTML = 1;}
else {
if (document.all) {isAll = 1; isDHTML = 1;}
else {
browserVersion = parseInt(navigator.appVersion);
if ((navigator.appName.indexOf('Netscape') != -1) && (browserVersion == 4)) {isLayers = 1; isDHTML = 1;}
}}

function getDOM(objectID,withStyle) {
	if (withStyle == 1) {
		if (isID) { return (document.getElementById(objectID).style) ; }
		else { 
			if (isAll) { return (document.all[objectID].style); }
		else {
			if (isLayers) { return (document.layers[objectID]); }
		};}
	}
	else {
		if (isID) { return (document.getElementById(objectID)) ; }
		else { 
			if (isAll) { return (document.all[objectID]); }
		else {
			if (isLayers) { return (document.layers[objectID]); }
		};}
	}
}


//GLOBAL JS
var isHREF = false; //this is used to override a goTo event when the user clicks directly on a link (protects against double posts)

function z() {
    isHREF = false;
}

function goTo(url, target) {
    if (!isHREF) {
        if (target != '_self') {
            window.open(url);          
        } else {
            window.location.href = url;
        }
    }
}

function x(url) {
    goTo(url, '_self');
}

function focusLogin() {
    document.login.username.focus();
}

function popWindowSize(inLink, inWidth, inHeight) {
    window.open(inLink, "_blank", "status=no,toolbar=no,scrollbars=yes,width=" + inWidth + ",height=" + inHeight);
}

function confirmIt(message) {
    var bYes=confirm(message);
    
    if (bYes)
        return true ;
    else
        return false ;
}


//TOP NAV JS
var menuTop = 45;
var menuPos_X = 400;

var domSMenu = null;
var oldDomSMenu = null;
var timer = 0;
var lDelay = 2;
var lCount=0;
var pause = 100; //100

//nav over
function vox_a(td, menuNum) {
    menuCellOn(td);
    popMenu(menuNum);
}

//nav out
function vox_b(td) {
    menuCellOff(td);
    timer=1;
    delayHide();
}

//menu cell over
function vox_c(td) {
    timer=2;
    vox_y(td);
}

//menu cell out
function vox_d(td) {
    timer=2;
    vox_z(td);
}

//menu cell out (from <a>)
function vox_e() {
    timer=1;
    delayHide();
}

//menu cell click (from <a>)
function vox_f() {
    isHREF = true;
    timer=0;
    delayHide();
}


function vox_g(td) {
    timer=1;
    vox_z(td);
}

function vox_h(td) {
    timer=1;
    delayHide();
    vox_z(td);
}

function vox_i(link, target) {
    timer=0;
    delayHide();
    goTo(link, target);
}


function vox_k() {
    timer=2;
}


function vox_y(td) {
    if (td != null) {
        topColorOn(td);
    }
}

function vox_z(td) {
    if (td != null) {
        topColorOff(td);
    }
}



function topColorOn(myobj)
{
    if(document.getElementById || (document.all && !(document.getElementById)))
    {
        myobj.style.backgroundColor="#ffffff";
    }
}

function topColorOff(myobj)
{
    if(document.getElementById || (document.all && !(document.getElementById)))
    {
        myobj.style.backgroundColor="#eeeeee";
    }
}


function popMenu(menuNum)
{
    //window.status='popped';

	if (isDHTML) //browser supports DHTML
	{
                // Defines the DOMs	of the menu objects
		var idMenu = 'ivr_nav';
		var domMenu = getDOM(idMenu, 0);

		var idMenuOpt = 'ivr_nav' + menuNum;
		var domMenuOpt = getDOM(idMenuOpt, 0);		

		var idSMenu = 'ivr_menu' + menuNum;
		var domSMenu = getDOM(idSMenu, 1);

		// Sets the previous menu's visibility to hidden
		timer=2;
		if (oldDomSMenu && (oldDomSMenu != domSMenu))
		{
			oldDomSMenu.visibility = 'hidden'; 
			oldDomSMenu.zIndex = '0';
			lCount=0;
		}

		// Defines the positions of the sub-menus
		if (isID || isAll)
		{
                       // var menuPos_X = (domMenu.offsetLeft) + (domMenuOpt.offsetLeft) + 3;
			//var menuPos_Y = (domMenu.offsetTop) + (domMenu.offsetHeight) -1;
		}
		if (isLayers)
		{
			//var menuPos_X = document.layers[idMenu].layers[idMenuOpt].pageX;
			//var menuPos_Y = domMenu.pageY + domMenu.clip.height;
		}

		// Positions and shows the menu
		if (oldDomSMenu != domSMenu)
		{
			//domSMenu.left = menuPos_X;
			//domSMenu.top = menuPos_Y;
			domSMenu.zIndex = '100';
			oldDomSMenu = domSMenu;
                        domSMenu.visibility = 'visible';
		}
		else // Resets oldDom if it is the same as the current DOM
		{
			// why?  oldDomSMenu = null;
		}
	}
	else // Returns a 'null' value for non-DHTML Browsers 
	{
		return null;
	}
}

function topNavColorOn(td){
if(document.getElementById||(document.all && !(document.getElementById))){
td.style.backgroundColor="#ffffff";
}
}

function topNavColorOff(td){
if(document.getElementById||(document.all && !(document.getElementById))){
td.style.backgroundColor="#eeeeee";
}
}


function topNavSubMenuColorOn(td){
if(document.getElementById||(document.all && !(document.getElementById))){
td.style.backgroundColor="#99ccff";
}
}

function topNavSubMenuColorOff(td){
if(document.getElementById||(document.all && !(document.getElementById))){
td.style.backgroundColor="#bddcfa";
}
}

function menuCellOn(td){
    if(document.getElementById||(document.all && !(document.getElementById))){
        td.style.backgroundColor="#eeeeee";
    }
}

function menuCellOff(td){
    if(document.getElementById||(document.all && !(document.getElementById))){
        td.style.backgroundColor=""; //#ffcccc";
    }
}

function delayHide()
{
    //window.status='timer=' + timer;

	// Checks to see if there is a menu showing and whether 
	// the global variable 'timer' has been set to 0
	
    if ((oldDomSMenu) && (timer == 0))
    {
        // Hides the old menu, resets menu conditions, 
        // and stops the function running
        oldDomSMenu.visibility = 'hidden'; 
        oldDomSMenu.zIndex = '0';
        oldDomSMenu = null;
        lCount=0; 

        //window.status='hidden';

        return false;
    }

	// Interupts the function if another menu is opened
    if (timer == 2)
    {
		lCount=0; return false;
	}

	// Repeats the function adding 1 to lCount each time until 
	// lCount is equal to lDelay and then sets 't' to 0 so that 
	// the menu will hide when it runs again
    if (timer == 1)
    {
        lCount = lCount + 1;
        if (lDelay <= lCount)
        {
            timer=0;
            lCount = 0;
        }
        
        if (lDelay >= lCount)
        {
            setTimeout('delayHide(' + timer + ')', pause);
            //window.status += "o";
        }
    }
}

//TOOLTIPS
function showToolTip(IDName, evt, inPosX)
{
	if (isDHTML) //browser supports DHTML 
	{
		var tipDOM = getDOM(IDName + 'Tip', 0);
		var tipDOMStyle = getDOM(IDName + 'Tip', 1);
		var posX = getXCoord(evt);
		var posY = getYCoord(evt);
		var scrollX = getXScroll();
		var scrollY = getYScroll();
		var windowWidth;
		var windowHeight;
		var tooltipWidth;
		var tooltipHeight;

		//get tooltip width
		if (tipDOM.offsetWidth != null)
			tooltipWidth = tipDOM.offsetWidth;
		else if (tipDOM.clip.width != null)
			tooltipWidth = tipDOM.clip.width;

		//get tooltip height
		if (tipDOM.offsetHeight != null)
			tooltipHeight = tipDOM.offsetHeight;
		else if (tipDOM.clip.Height != null)
			tooltipHeight = tipDOM.clip.Height;

		//getWindowWidth
		if (window.innerWidth != null)
			windowWidth = window.innerWidth;
		else if (document.body.clientWidth != null)
			windowWidth = document.body.clientWidth;
		windowWidth -= 20;


		//getWindowHeight
		if (window.innerHeight != null)
			windowHeight = window.innerHeight;
		else if (document.body.clientHeight != null)
			windowHeight = document.body.clientHeight;

		if (((windowWidth < posX + tooltipWidth + 10) && isAll ) || ((windowWidth < posX - scrollX + tooltipWidth + 10) && !isAll ))
			posX = posX - tooltipWidth - 20;
		else
			posX = posX + 20;

		if (((windowHeight < posY + tooltipHeight + 20) && isAll ) || ((windowHeight < posY - scrollY + tooltipHeight + 20) && !isAll ))
			posY = posY - tooltipHeight - 20;
		else
			posY = posY + 20;
			
			
		if (inPosX > 0)
			posX = inPosX;
			
		if (tipDOMStyle.left != null)
		{
			tipDOMStyle.left = posX;
			tipDOMStyle.top = posY;

                        //alert("left");
		}
		
		if (tipDOMStyle.pixelLeft != null)
		{
			if(!(inPosX > 0))
				posX += scrollX;
			
			tipDOMStyle.pixelLeft = posX;
			tipDOMStyle.pixelTop = posY + scrollY;

                        //alert("pixelLeft");
		}
		
		if (tipDOMStyle.offsetLeft != null)
		{
			tipDOMStyle.offsetLeft = posX;
			tipDOMStyle.offsetTop = posY;
                        
                        //alert("offsetLeft");
		}

                //window.status="posX=" + posX;
		
		tipDOMStyle.visibility = 'visible';
		tipDOMStyle.zIndex = '1000';
	}
	else
	{
		return null;
	}
}

function hideToolTip(IDName)
{
	if (isDHTML)
	{
		var tipDOMStyle = getDOM(IDName + 'Tip', 1);
		tipDOMStyle.visibility = 'hidden';
		tipDOMStyle.zIndex = '-1';
	}
}

function getXCoord(evt)
{
	if (evt.x)
		return evt.x;
	else if (evt.pageX)
		return evt.pageX;
}

function getYCoord(evt)
{
	if (evt.y)
		return evt.y;
	else if (evt.pageY)
		return evt.pageY; 
}

function getXScroll()
{
	if (document.body.scrollLeft != null)
		return document.body.scrollLeft;
	else if (window.pageXOffset != null)
		return window.pageXOffset;
}

function getYScroll()
{
	if (document.body.scrollTop != null)
		return document.body.scrollTop;
	else if (window.pageYOffset != null)
		return window.pageYOffset;
}
