dataChanged=false;
IE = false; /* this will get reset in pagetemplate if IE is detected */

function getInsideWindowWidth()
{
	if (window.innerWidth){
		return innerWidth;
	} else if (document.body && document.body.clientWidth){
		return document.body.clientWidth;
	}
	return 0;
}

function hide(objectID)
{
	domStyle = findDOM(objectID,1);
	if (domStyle)
	domStyle.visibility = 'hidden';
	domStyle.display = 'none';
}

function show(objectID)
{
	domStyle = findDOM(objectID,1);
	if (domStyle)
	domStyle.visibility = 'visible';
	domStyle.display = 'block';
	
}
/***********************************************************
*
*	CODE TO RECORD THE POSITION OF THE MOUSE
*
************************************************************/
if (document.layers) { // Netscape
    document.captureEvents(Event.MOUSEMOVE);
    document.onmousemove = captureMousePosition;
} else if (document.all) { // Internet Explorer
    document.onmousemove = captureMousePosition;
} else if (document.getElementById) { // Netcsape 6
    document.onmousemove = captureMousePosition;
}
// Global variables
var mX = 0; // Horizontal position of the mouse on the screen
var mY = 0; // Vertical position of the mouse on the screen
var mXMax = 0; // Width of the page
var mYMax = 0; // Height of the page
var mYOffset=0;
var mXOffset=0;

function captureMousePosition(e) {
    if (document.layers) {
        // When the page scrolls in Netscape, the event's mouse position
        // reflects the absolute position on the screen. innerHight/Width
        // is the position from the top/left of the screen that the user is
        // looking at. pageX/YOffset is the amount that the user has 
        // scrolled into the page. So the values will be in relation to
        // each other as the total offsets into the page, no matter if
        // the user has scrolled or not.
        mX = e.pageX;
        mY = e.pageY;
        mXMax = window.innerWidth;
        mYMax = window.innerHeight;
      	mYOffset = window.pageYOffset;
      	mXOffset = window.pageXOffset;
    } else if (document.all) {
        // When the page scrolls in IE, the event's mouse position 
        // reflects the position from the top/left of the screen the 
        // user is looking at. scrollLeft/Top is the amount the user
        // has scrolled into the page. scrollWidth/Height is the height/
        // width of the current page the user is looking at. So, to be
        // consistent with Netscape (above), add the scroll offsets to
        // both so we end up with an absolute value on the page, no 
        // matter if the user has scrolled or not.
        var content=findDOM('content',0);
        if (content)
        {
	        mYOffset = content.scrollTop;
	        mXOffset = content.scrollLeft;
    	}
  	    mX = window.event.x+mXOffset;
        mY = window.event.y+mYOffset;
        mXMax = document.body.scrollWidth;
        mYMax = document.body.scrollHeight;
    } else if (document.getElementById) {
        // Netscape 6 behaves the same as Netscape 4 in this regard 
        mX = e.pageX;
        mY = e.pageY;
        mXMax = window.innerWidth;
        mYMax = window.innerHeight;
   	    mYOffset = window.pageYOffset;
   	    mXOffset = window.pageXOffset;
    }
//	window.status = "xMousePos=" + mX + ", yMousePos=" + mY + ", xMousePosMax=" + mXMax + ", yMousePosMax=" + mYMax + ", Xoffset=" + mXOffset + ", Yoffset=" + mYOffset;
}


/***********************************************************
*
*	SCROLLING BANNER CODE
*
************************************************************/
var myMsg="";
var pos=530;

function scrollMsg()
{
	document.write("<div id='scrollBar'><div id='scrollText'><span class='scrollBar'>"+myMsg+"</span></div></div>");
	scroller=findDOM('scrollText',1);
	setInterval('scrollit(scroller)',10);
}

function scrollit(scroller)
{
	if (pos > -420)
	{
		scroller.left=pos--;
	}
	else
	{
		pos=530;
	}
}

/***********************************************************
*
*	DROP-DOWN MENU CODE
*
************************************************************/
var totalDiv = 0;
var timer=0;
var highlightcolor;
var bgcolor;
var clearcontent;
var onclick;
var clicked=0;
function hideSelects()
{
	var select = document.getElementsByTagName("SELECT");
	for (var i=0;i < select.length; i++)
	{
		select[i].style.visibility = 'hidden';
	}
}
function showSelects()
{
	var select = document.getElementsByTagName("Select");
	for (var i=0;i < select.length; i++)
	{
		select[i].style.visibility = 'visible';
	}

}
function itemClicked(submenu)
{
	clicked=1;
	showSubmenu(submenu);
}
function itemOver(menu,item)
{
	// Stop all timers
	if (timer) clearTimeout(timer);

	// Clear any menus greater than this one
	closeFrom(menu+1);
	
	if (menu)
	{
		div = "item"+item;
		setBackgroundColor(div, highlightcolor);
	}
}
function showSubmenu(submenu)
{
	if (onclick && !clicked) return;
	if (submenu)
	{
		div="menu"+submenu;
		show(div);
		if (clearcontent) hideSelects();
	}
}

function itemOut(item)
{
	timer=setTimeout("closeAll()",250);
	
	div = "item"+item;
	setBackgroundColor(div, bgcolor);
}

function closeAll()
{
	closeFrom(1);
	showSelects();
	clicked=0;
}

function closeFrom(start)
{
	for (i=start;i<totalDiv;i++)
	{
		div="menu"+i;
		hide(div);	
	}
}

function setBackgroundColor(objectID, color)
{
	domStyle = findDOM(objectID,1);
	if (domStyle)
	{
		domStyle.backgroundColor = color;
	}
}


/***********************************************************
*
*	POP-UP MENU CODE
*
************************************************************/
var poptimer=0;
var backgroundTimer=0;
var popIdString='';
var lastrow=0;
var curmenu=0;

function popItemOver(div)
{
	if (poptimer) clearTimeout(poptimer);
	if (backgroundTimer) clearTimeout(backgroundTimer);
	setBackgroundColor(div,highlightcolor);
}
function popItemOut(div,pmenu)
{
	if (curmenu) poptimer=setTimeout("menuhide(curmenu)",250);
	backgroundTimer=setTimeout("setBackgroundColor(lastrow,'transparent')",250);
	setBackgroundColor(div,bgcolor);
}
function popItemClick(action)
{
	window.location=action+"&id="+popIdString;
}

function tableMenuOver(row,idstring, height, pmenu)
{
	menuhide(curmenu);
	if (poptimer) clearTimeout(poptimer);
	if (lastrow) setBackgroundColor(lastrow,'transparent');
	var offset = (IE) ? 30: 0; // Allow for fact that menu is fixed in firefox at 30px high.
	setBackgroundColor(row,highlightcolor);
	popIdString=idstring;
	var popMenu=findDOM(pmenu,1);
	var topPos = Math.max(mYOffset - offset + 30,mY - height - offset);
	if (popMenu)
	{
		popMenu.left=mX+10;
		popMenu.top=topPos;
	}
	show(pmenu);
	curmenu=pmenu;
}


function tableMenuOut(row,pmenu)
{
	lastrow=row;
	backgroundTimer=setTimeout("setBackgroundColor(lastrow,'transparent')",250);
	if (curmenu) poptimer=setTimeout("menuhide(curmenu)",250);
}
function menuhide(menu)
{
	if (menu) hide(menu);
	curmenu=0;
}

function popUp(w, tx, wd, ht, rs, sb, posx, posy, mb)
{
//	alert('opening ' + w + ']');
	var newwindow;
	var options = '';
	options += (wd) ? "width="+wd : "";
	options += (ht) ? ((options) ? ", height="+ht : "height="+ht) : "";
	options += (rs) ? ((options) ? ", resizable="+rs : "resizable="+rs) : "";
	options += (sb) ? ((options) ? ", scrollbars="+sb : "scrollbars="+sb) : "";
	options += (posx) ? ((options) ? ", screenX="+posx : "screenX="+posx) : "";
	options += (posy) ? ((options) ? ", screenY="+posy : "screenY="+posy) : "";
	options += (mb) ? ((options) ? ", menubar="+mb : "menubar="+mb) : "";
	newwindow = window.open(w,tx,options);
	newwindow.focus();
}
/***********************************************************
*
*	TOOL-TIP CODE
*
************************************************************/
var tooltipTimer=0;
var tooltip=0;

function toolTipFieldOver(text, edge, offset, yoffset)
{
	if (tooltipTimer) clearTimeout(tooltipTimer);
	var toolTip=findDOM('tooltip',0);
	yoffset -= (IE) ? mYOffset : 0;
	var bottomPos = mYMax - mY + offset - yoffset;
	if (toolTip)
	{
		toolTip.style.right = null;
		toolTip.style.left = null;
		if (edge == 'left')
		{
			toolTip.style.left = mX + 30 + offset;
		}
		else
		{
			toolTip.style.right = mXMax - mX + 30 + offset;
		}
		toolTip.style.bottom=bottomPos;
		toolTip.innerHTML = text;
	}
	show('tooltip');
	tooltip=1;
}
function toolTipFieldOut()
{
	if (tooltip) tooltipTimer=setTimeout("tooltiphide()",250);
}
function toolTipOver()
{
	if (tooltipTimer) clearTimeout(tooltipTimer);
}
function toolTipOut()
{
	if (tooltip) tooltipTimer=setTimeout("tooltiphide()",250);
}
function tooltiphide()
{
	hide('tooltip');
	tooltip=0;
}

/***********************************************************
*
*	SHORTCUT MENU CODE
*
************************************************************/
var contextOn = 0;
var contextTimer = 0;
function showContextMenu()
{
	if (contextTimer) clearTimeout(contextTimer);
	show('contextMenu');
	contextOn = 1;
}

function hideContextMenu()
{
	hide('contextMenu');
	contextOn = 0;
}
function contextBarOut()
{
	if (contextOn) contextTimer=setTimeout("hideContextMenu()",250);
}
function contextItemOver(div)
{
	if (contextTimer) clearTimeout(contextTimer);
	setBackgroundColor(div,highlightcolor);
}
function contextItemOut(div)
{
	if (contextOn) contextTimer=setTimeout("hideContextMenu()",250);
	setBackgroundColor(div,bgcolor);
}
function contextItemClick(action)
{
	window.location=action;
}
/***********************************************************
*
*	Checking id user wishes to save before leaving
*
************************************************************/
function Logout()
{
	if (dataChanged)
	{
		dataChanged=false;
		if (confirm("Are you sure you want to Log Out without saving ?  Select OK to continue without saving or Cancel to go back and save the data."))
		{
			window.location="Login.php?action=Logout";
		}
		else
		{
			var f=findDOM('fieldForm');
			if (f)
			{
				var c = findDOM('cancel');
				if (c)
				{
					c.value='true';
				}
				f.submit();
			}
		}
	}
	else
	{
		if (confirm("Are you sure you want to Log Out ?"))
		{	
			window.location="Login.php?action=Logout";
		}

	}
}
function checkSubmit()
{
	if (dataChanged)
	{
		checkSave();
	}
}
function checkSave()
{
	if (!confirm("Are you sure you want to leave without saving ?  Select OK to continue without saving or Cancel to go back and save the data."))
	{
		dataChanged=false;
		var f=findDOM('fieldForm');
		if (f)
		{
			var c = findDOM('cancel');
			if (c)
			{
				c.value='true';
			}
			f.submit();
		}
	}
}
function setDataChanged(val)
{
	dataChanged = val;
}

function goTo(w,t)
{
	if (confirm(t))
	{ 
		window.location= w;
	}
}
function submitForm(form)
{
	var af=findDOM(form,0);
	if (af)
	{
		if (af.onsubmit) af.onsubmit();
		af.submit();
	}
}
function checkSubmitOK(form,t)
{
	if (confirm(t))
	{
		submitForm(form);
	}
}