domData.flag = false; // stops menus from being triggered until page is loaded.
var mCurr = false; // says mouse is roaming, not on a global menu at all
var mTrigger = false; // says no "trigger" button is shown
var mNumAll = 0; // Number of menus

mNames = new Array(); // names of menus

// Method to get current scrolling
domData.scrollX = getScrollX; // method to get X offset
domData.scrollY = getScrollY; // method to get Y offset

// Track Mouse Position
var x, y;



// BEGIN Initialize DHTML Objects and start event capture
function init() {
	if (!domData.isOther) {
		createObjects(); // Function that creates DHTML objects
		if (mNumAll > 0) {
			for (var i = 0; i < mNumAll; i++) {
				initMenus(mNames[i]); // Initialize the menu bounds for the menus
			}
			domData.flag = true;
			if (domData.isNN6Up) { 
				document.body.addEventListener("mousemove", whereAmI, true);
			} 
			document.onmousemove = whereAmI; 

		}
	}	
} // END init()



// Popup Window Function
function popup(fname,wname,wwidth,wheight) {

	var newwin = window.open("",wname,"toolbar=no,directories=no,menubar=yes,scrollbars=yes,width=" + wwidth + ",height=" + wheight + ",left=10,top=10,resizable=yes");
	newwin.location = fname;
	newwin.focus();
	return;

}




// initMenus function to initialize menus 
function initMenus(mName) {
	var obj = theObjs[mName];
	obj.x1 = obj.objGetLeft() - 5; // 5 pixel slop
	obj.y1 = obj.objGetTop() - 5; // 25 pixel slop at top 
	obj.x2 = obj.objGetLeft() + obj.objGetWidth(); // Shadow is enough slop
	obj.y2 = obj.objGetTop() + obj.objGetHeight(); // Shadow is enough slop
} // END initMenus()



// BEGIN whereAmI function to track mousemoving
function whereAmI(e) {

	if (domData.isNN6Up) { 
		x = e.clientX + domData.scrollX();
		y = e.clientY + domData.scrollY();;
	} else if (domData.isIE4Up) { 
		x = event.clientX + domData.scrollX(); 
		y = event.clientY + domData.scrollY(); 
	}

	if (!mCurr) { return; }

	var obj = theObjs[mCurr];

	if ((x < obj.x1) || (x > obj.x2) || (y < obj.y1) || (y > obj.y2)) { 
		if (mTrigger == false) {
			mCurr = false;
			menuOff('none'); // Turn off all menus
		} else {
			obj = theObjs[mTrigger];
			if ((x < obj.x1) || (x > obj.x2) || (y < obj.y1) || (y > obj.y2)) { 
				mCurr = false;
				mTrigger = false;
				menuOff('none'); // Turn off all menus
			}
		}
	}
			
} // END whereAmI function



// BEGIN function to turn on menu (and turn off others)
function menuOn(menu, trigger) {
	if (!domData.flag) { return; }
	if (mCurr == menu) { return; }
	
	mCurr = menu;
	menuOff(mCurr); // Turn off Non-current menus
	var obj = theObjs[mCurr];
	obj.objShow();
	
	if (!trigger) { return; }
	mTrigger = trigger;
	obj = theObjs[mTrigger];
	obj.objShow();

} // End MenuOn(menu)
	


// BEGIN Hide All Menus
function menuOff(except) {
	for (var i = 0; i < mNumAll; i++) { 
		if (mNames[i] != except) { 
			var obj = theObjs[mNames[i]];
			obj.objHide(); 
		}
	}
} // END menuOff(except) 



// BEGIN getScrollX function that assigns scrollX method to domData to get current X offset of page
function getScrollX() {

	if (domData.isIE6) { return document.all.canvas.scrollLeft; 
	} else if (domData.isIE4Up) { return document.body.scrollLeft; 
	} else if (domData.isNN6Up) { return window.pageXOffset; }

} // END getScrollX



// BEGIN getScrollY function that assigns scrollY method to domData to get current Y offset of page
function getScrollY() {

	if (domData.isIE6) { return document.all.canvas.scrollTop; 
	} else if (domData.isIE4Up) { return document.body.scrollTop; 
	} else if (domData.isNN6Up) { return window.pageYOffset; }

} // END getScrollY

function toggleMenu(menuId, buttonId, onImg, offImg)
{
	var mnu;
	var btn;
	
	mnu = document.getElementById(menuId);
	btn = document.getElementById(buttonId);
	
	
	if (mnu != null && btn != null)
	{
		var state = parseInt(btn.getAttribute('menuState'));
		switch (state)
		{
			case 2:
				mnu.style.display = 'none';
				btn.src = offImg;
				btn.setAttribute('menuState',0);
				break;
			default:
				mnu.style.display = '';
				btn.src = onImg;
				btn.setAttribute('menuState',2);
		}
	}
}
function toggleButton(buttonId, onImg, offImg, action)
{
	var btn = document.getElementById(buttonId);
	if (btn != null)
	{
		var state = parseInt(btn.getAttribute('menuState'));
		switch (state)
		{
			case 0:		// Not expanded, not highlighted
				if (action == "over")
				{
					btn.src = onImg;
					btn.setAttribute('menuState',1);
				}
				break;
			case 1:		// Not expanded, hightlighted
				btn.src = offImg;
				btn.setAttribute('menuState',0);
				break;
			case 2:
				// do nothing
				break;
		}
	}
}

//the following functions are used by the physician transactions
function OpenLink(strURL)
{
	window.open(strURL, '', 'toolbar=yes, scrollbars=yes, resizable=yes, height=485, width=700,left=20,top=20');
}

function OpenLinkWithBars(strURL)
{
	window.open(strURL, '', 'toolbar=yes, status=yes, location=yes, scrollbars=yes, resizable=yes, height=485, width=700,left=20,top=20');
}

function OpenLocation(strURL)
{ //open the link without opening a new window
	window.location.href=strURL, '', 'toolbar=yes, scrollbars=yes, resizable=yes, height=485, width=700,left=20,top=20';
	return;
}

function ProvConnectURL(strURL)
{//determine the server to point to based on where the user is entering the
 //site from
	var strHostname;
	var strProtocol;
	var strNewURL;
	
	strHostname = document.location.hostname;
	strProtocol = document.location.protocol;
	//parse out the protocol to only return http: or https:
	strProtocol = strProtocol.substr(0,strProtocol.indexOf(":") + 1);

	//build the new URL
	strNewURL = strProtocol + "//" + strHostname + strURL;
	window.open(strNewURL, '', 'toolbar=yes, scrollbars=yes, location=yes, resizable=yes, height=485, width=700,left=20,top=20');
	return;
}
//end of provider scripts

// Change the style of the left menu item as the mouse leaves
function sideMenuOut(menuCell)
{
	if (menuCell)
	{
		menuCell.style.backgroundColor='';
		if (menuCell.nextSibling)
		{
			menuCell.nextSibling.style.backgroundColor='';
		}
	}
}
// Change the style of the left menu item as the mouse enters
function sideMenuOver(menuCell)
{ 
	if (menuCell)
	{
		menuCell.style.backgroundColor='#ffffff';
		if (menuCell.nextSibling)
		{
			menuCell.nextSibling.style.backgroundColor='#ffffff';
		}
	}
}

function EmployerConnectURL(strURL)
{//determine the server to point to based on where the user is entering the
 //site from
	var strHostname;
	var strProtocol;
	var strNewURL;

	if (document.location.hostname.indexOf("optimahealth.com") == -1)
		//did not find the string optimahealth.com
		{
			strHostname = 'bi.sentara.com';
		}
		else {
			strHostname = 'bi.optimahealth.com';
		}
	strProtocol = document.location.protocol;
	//parse out the protocol to only return http: or https:
	strProtocol = strProtocol.substr(0,strProtocol.indexOf(":") + 1);

	//build the new URL
	strNewURL = strProtocol + "//" + strHostname + strURL;
	window.open(strNewURL, '', 'toolbar=yes, scrollbars=yes, location=yes, resizable=yes, height=485, width=700,left=20,top=20');
	return;
}
//end of employer scripts

//<summary>
//  Function OpenNewPopUpWindow --- Opens Link in New Window
//<summary/>
//<history>
//  [RLBANKS] 12/11/07 -- CREATED
function OpenNewPopupWindow(strURL)
{
  popupWin = window.open(strURL,'open_window', 'menubar, toolbar, location, directories, status, scrollbars, resizable, dependent, width=640, height=480, left=0, top=0')
}

//<summary>
//  Function OpenNewPopUpWindow --- Opens Link in New Window
//<summary/>
//<history>
//  [RLBANKS] 12/11/07 -- CREATED
function OpenNewFullPopupWindow(strURL)
{
  popupWin = window.open(strURL,'open_window', 'menubar=1,resizable=1,toolbar=1,scrollbars,titlebar=1,top=0,left=0,width=' + (window.screen.availWidth-12)+',height=' + (window.screen.availHeight-107)+',screenX=0,screenY=0,top=0,left=0')
}
