var submitCount = 0;
var uTimeOutId;
var hTimeOutId;
var onNav;
var navObject;
var overNav;
var urlResults;
var selTimeOutId;
var showMMTimeOutId;
var gotMenuMap = 0;
var loadingMM = 0;
var mmHideTimeOutId;
var mm_x;
var mm_y;
var mm_h;
var mm_w;

var IE = document.all?true:false;
var tempX = 0;
var tempY = 0;
function getMouseXY(e) 
{
	if (IE) { // grab the x-y pos.s if browser is IE
		tempX = event.clientX + document.body.scrollLeft;
		tempY = event.clientY + document.body.scrollTop;
	}
	else {  // grab the x-y pos.s if browser is NS
		tempX = e.pageX;
		tempY = e.pageY;
	}  
}

navHover = function() 
{
o2 = document.getElementById("menuMapContents");

if(o2)
{
mm_x = getObjectLeft(o2) + 1;
mm_y = getObjectTop(o2) + 1;
mm_w = getObjectWidth(o2) - 1;
mm_h = getObjectHeight(o2) - 1;
}

   // only load these things if menus are in play
   if(document.getElementById)
   {
   valid = document.getElementById("popNav");
   if(valid)
   {
		valid = document.getElementById("popNav");
		if(valid)
		{
			o1 = document.getElementById("inPopNavTrigger");
			if(o1)
			{
				o1.onmouseover=function() 
				{
					if(this.className == "inPopNav")	
					{
						this.className+=" navHover";
					}
				}
				
				o1.onmouseout=function() 
				{
					if(onSubNav == 'fileManager')
					{					
						getMouseXY();
	                                        x = getObjectLeft(o2) + 1;	
        	                                y = getObjectTop(o2) + 1;
                	                        w = getObjectWidth(o2) - 1;
                        	                h = getObjectHeight(o2) - 1;

						if(tempX < mm_x || tempX > (mm_x + mm_w))
						{
							this.className=this.className.replace(new RegExp(" navHover\\b"), "");
						}
						else
						{
							if(tempY < mm_y || tempY > (mm_y + mm_h))
							{
								this.className=this.className.replace(new RegExp(" navHover\\b"), "");
							}
						}
					}
					else
					{
						this.className=this.className.replace(new RegExp(" navHover\\b"), "");
					}
				}
			}
			
			o2 = document.getElementById("menuMapContents");
			if(o2)
			{
				o2.onmouseover=function() {
					if(this.className == "inPopNav")
					{
						this.className+=" navHover";
						hideSelects();
					}
				}
				
				o2.onmouseout=function() 
				{
					if(mm_x < 0)
					{
						mm_x = getObjectLeft(o2) + 1;
						mm_y = getObjectTop(o2) + 1;
						mm_w = getObjectWidth(o2) - 1;
						mm_h = getObjectHeight(o2) - 1;
					}
					if(onSubNav == 'fileManager' || onSubNav == 'customNav') 
					{
						getMouseXY();
						x = getObjectLeft(o2) + 1;
	                                        y = getObjectTop(o2) + 1;
        	                                w = getObjectWidth(o2) - 1;
                	                        h = getObjectHeight(o2) - 1;

						if(tempX < mm_x || tempX > (mm_x + mm_w))
						{
							this.className=this.className.replace(new RegExp(" navHover\\b"), "");
							showSelects();
						}
						else
						{
							if(tempY < mm_y || tempY > (mm_y + mm_h))
							{
								this.className=this.className.replace(new RegExp(" navHover\\b"), "");
						showSelects();	
							}	
						}
					}
					else
					{
						showSelects();
					}
			}
		}
	}
   }
	
	var dropItems = document.getElementsByName("dropNav");
	
	for (var i=0; i<dropItems.length; i++) {
		navItems = dropItems[i].getElementsByTagName("li");
		for(var j=0; j<navItems.length; j++)
		{
			navItems[j].onmouseover=function() {
				this.className+=" navHover";
			}
			navItems[j].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" navHover\\b"), "");
			}		
		}
	}
	
	
	var boxItems = document.getElementsByTagName("li");
	if(boxItems)
	{
		for(var i=0; i<boxItems.length; i++)
		{
			if(boxItems[i].className == "popBoxTriggerItem")
			{
				boxItems[i].onmouseover=function() {
					this.className+=" navHover";
				}
				boxItems[i].onmouseout=function() {
					this.className=this.className.replace(new RegExp(" navHover\\b"), "");
				}
			}
		}
	}
    }
}


if (window.attachEvent) window.attachEvent("onload", navHover);


function subNavOver(id)
{
	if(uTimeOutId)
          {
                clearTimeout(uTimeOutId);
                uTimeOutId = "";
          }
}

function subNavNotOver(id)
{
	uhlNav(id);
}

function hlNav(id)
{
	if(hTimeOutId)
	{
		clearTimeout(hTimeOutId);
		hTimeOutId = "";
	}
	hTimeOutId = setTimeout("hlNavNow('" + id + "')", 100);
}

function hlNavNow(id)
{
	if(overNav != "")
        {
   	  uhlNavNow(overNav);
	  if(uTimeOutId)
          {
          	clearTimeout(uTimeOutId);
		uTimeOutId = "";
	  }
        }
	if(id == onNav)
	{
	 	return;
	}	

	if(hTimeOutId)
	{
		clearTimeout(hTimeOutId);
		hTimeOutId = "";
	}

        var nobj = document.getElementById("topNav_" + id);
        if(nobj)
        {
		nobj.className = "offTabOver";
        }
	var idnum = tabList[id];

        // var lobj = document.getElementById("tabLabel_" + id);
	var lobj = document.getElementById("tabLabel_" + idnum);	
        if(lobj)
        {
		// lobj.className = "offTabOver";
		lobj.className = "menuLabel_offTab";	
        }
        var oobj = document.getElementById("subNav_" + onNav);
	if(oobj)
	{
	oobj.className = oobj.className.replace(new RegExp(" subbarover\\b"), " subbarnotover");
	}
        var sobj = document.getElementById("subNav_" + id);
	if(sobj)
	{
	sobj.className = sobj.className.replace(new RegExp(" subbarnotover\\b"), " subbarover");
	}
	overNav = id;
}

function uhlNav(id)
{
	if(hTimeOutId)
	{
		clearTimeout(hTimeOutId);
		hTimeOutId = "";
	}
	else
	{
 	       uTimeOutId = setTimeout("uhlNavNow('" + id + "')", 750);
	}
}

function uhlNavNow(id)
{
	if(id == onNav)
	{
	 	return;
	}	

        var nobj = document.getElementById("topNav_" + id);
        if(nobj)
        {
                if(id != onNav)
                {
			nobj.className = "offTab";
			var lobj = document.getElementById("tabLabel_" + id);
			if(lobj)
			{
			   lobj.className = "offTab";
			}
                }
	        var oobj = document.getElementById("subNav_" + onNav);
		if(oobj)
		{
			oobj.className = oobj.className.replace(new RegExp(" subbarnotover\\b"), " subbarover");
		}
        	var sobj = document.getElementById("subNav_" + id);
		if(sobj)
		{
			sobj.className = sobj.className.replace(new RegExp(" subbarover\\b"), " subbarnotover");
		}
        }
	overNav = "";
}

function hitUrl(url)
{
	var client = new HTTPClient();
        client.init(url)
        client.asyncGET();
}

function collapser(id, set, sp, menu)
{
	var obj = document.getElementById("collapse_" + id);
	if(obj)
	{
		if(obj.style.display == "none")
		{
	      		obj.style.display = "block";
			var iObj = document.getElementById("img_" + id);
			if(iObj)
			{
				iObj.src = "/cobrand/" + sp + "/images/arrow_down.gif";
			}
			if(set)
			{
				if(menu)
					script = '/home/home/menuPref.cgi?pID=' + id + '&pCase=on&pMenuSet=' + menu;
				else
					script = '/home/home/setPref.cgi?pVar=collapse_' + id + '&pVal=0';
				hitUrl(script);
			}
		}
		else
		{
		      obj.style.display = "none";
		      var iObj = document.getElementById("img_" + id);
		      if(iObj)
		      {
			iObj.src = "/cobrand/" + sp + "/images/arrow_right.gif";
		      }
			if(set)
			{
				if(menu)
					script = '/home/home/menuPref.cgi?pID=' + id + '&pCase=off&pMenuSet=' + menu;
				else
					script = '/home/home/setPref.cgi?pVar=collapse_' + id + '&pVal=1';
				hitUrl(script);
			}
		}	
	}
}

function imageSwap(id, src)
{
	if (document.getElementById)
	{
	   document.getElementById(id).src = src;
	}
}


var checkMailStatus = {
  onLoad: function(data)
  {
	if(data > 0)
        {
		newMail(data);	
        }
  }
}


// for web mail icon display/update
function makeSound(which)
{
	if (document.getElementById)
	{
		soundContainer = document.getElementById('wmsounds');
		if(soundContainer)
		{
			soundContainer.innerHTML = "<embed hidden=\"true\" src=\"/sounds/" + which + "\" autostart=\"true\"/>";
		}
	}
} // makeSound

function startPing()
{
	ping = parseInt(ping);
	newMailCount = parseInt(newMailCount);

	if (window.setInterval)
		if (ping && (newMailCount == 0))
		{
			pingInterval = window.setInterval('checkForNewMail()', 1000*60*ping);
		}

	if (newMailCount != 0 && typeof(newMailDispatch) != 'undefined')
				newMailDispatch();
} // startPing

function stopPing()
{
	if (window.setInterval && window.clearInterval)
		if (ping)
			window.clearInterval(pingInterval);
} // stopPing

function checkForNewMail()
{
	if (document.getElementById)
	{
		mailIcon = document.getElementById('mailStatus');
		if (mailIcon)
		{
			url = "/home/nos/chkm.cgi"; 
			var client = new HTTPClient();
			client.init(url)		
			client.asyncGET(newMail);
		}
	}
} // function checkForNewMail

function myEncode(str)
{
	if (escape)
		return escape(str);
	else
		return encodeURI(str);
} // function myEncode


var newMail = {
  onLoad: function(data)
  {
		if (data.match(/[^0-9\s]/)) {
			stopPing();
		}
		else if(parseInt(data) > 0)
		{
			var src = '/cobrand/' + signupPath + '/images/newMail.gif';	
			imageSwap('mailStatus', src);

			if(pingAlert != 'none')
				makeSound(pingAlert);
			stopPing();
			if (typeof(newMailDispatch) != 'undefined')
				newMailDispatch(data);
		}
		else {
			if (typeof(newMailDispatch) != 'undefined')
				newMailDispatch();
		}
  },

  onError: function() {
		stopPing();
  }
} 

function hideIt(id)
{
        obj = document.getElementById(id);
        if(obj)
        {
                obj.style.display = 'none';
        }
}


// old commonlib-2 functions
var submitCount = 0;


function startSiteBuilder(url)
{
        window.open(url, "templates", "toolbar,scrollbars,resizable,width=640,height=480");
}


function startMiva(url)
{
        window.open(url, "miva", "toolbar,scrollbars,status,resizable,width=750,height=550");
}

function startCompose(to, script)
{
	if (!to)
		to = '';
	if (!script)
		script = '/home/apps/mail/mbox_compose.cgi';
	wobj = window.open(script + '?pFolder=&pTo=' + encodeURI(to), '_blank', 'status=yes,menu=yes,scrollbars=yes,resizable=yes,width=750,height=520');
	wobj.focus();	

	return false;
} // function startCompose

function tabMenu_startIM()
{
	// open window with now content to see if it is already opened
	var opts = "";
	if (/MSIE 6\.\d+;/.test(navigator.userAgent))
		opts = "width=296,height=640,toolbar=no,status=no,scrollbars=no,resizable=yes,menubar=no,location=yes,directories=no,left=40,top=40";
	else
		opts = "width=296,height=640,toolbar=no,status=no,scrollbars=no,resizable=yes,menubar=no,directories=no,left=40,top=40";

	var wobj = window.open("", "_gatewayIM", opts);

	if (wobj)
	{
		if (!/\/home\/im\/imclient\.cgi$/.test(wobj.location))
			wobj.location = "/home/im/imclient.cgi";
		wobj.focus();
	}
}

function tabMenu_handlePreLogout()
{
	tabMenu_logOutIM();
}

function tabMenu_logOutIM()
{
	var wobj = window.open("", "_gatewayIM", 'width=296,height=640,toolbar=no,status=no,scrollbars=no,resizable=yes,menubar=no,directories=no,left=40,top=40');

	if (wobj)
	{
		if (/\/home\/im\/imclient\.cgi$/.test(wobj.location))
		{
			wobj.logOutIM();
		}
		else
		{
			wobj.close();
		}
	}
}

function jumpTo(dest, baseurl)
{
        var x;
        x = dest.options[dest.selectedIndex].value;
        if (baseurl)
        {
           location.href=baseurl+x;
        }
        else
        {
           location.href=x;
        }
}

function jumpToUrl(url)
{
	location.href = url;
}

function submitOnce()
{
        if (submitCount == 0)
        {
                submitCount++;
                return true;
        }
        else
        {
                return false;
        }
}

function hideSelects()
{
        if(selTimeOutId)
        {
                clearTimeout(selTimeOutId);
                selTimeOutId = "";
        }
	hideSelectsNow();
}

function hideSelectsNow()
{
    if(window.attachEvent)
    {
	for(var i = 0; i < document.forms.length; i++)
        	for(var e = 0; e < document.forms[i].length; e++)
                	if(document.forms[i].elements[e].tagName == "SELECT")
			{ 
				document.forms[i].elements[e].style.visibility="hidden"; 
			}
	if(onSubNav)
	{
		if(onNav == "calendar")
		{
			ob = document.getElementById('timesAndEventsContainer');
			if(ob)
			{
				ob.style.zIndex = -1; 	
			}
		}
	}
    }
}

function showSelects()
{
        if(selTimeOutId)
        {
		return;
        }
        selTimeOutId = setTimeout("showSelectsNow()", 100);
}

function showSelectsNow()
{
    if(window.attachEvent)
    {
	for(var i = 0; i < document.forms.length; i++)
        	for(var e = 0; e < document.forms[i].length; e++)
                	if(document.forms[i].elements[e].tagName == "SELECT")
			{ 
				document.forms[i].elements[e].style.visibility="visible"; 
			}
	if(onSubNav)
	{
		if(onNav == "calendar")
		{
			ob = document.getElementById('timesAndEventsContainer');
			if(ob)
			{
				ob.style.zIndex=1; 	
			}
		}
	}
    }
    selTimeOutId = "";
}

function falsify()
{
	return;
}

function showMenuMap()
{
       if(showMMTimeOutId)
       {
                return;
       }
       showMMTimeOutId = setTimeout("showMenuMapNow()", 150);
}

function showMenuMapNow()
{
   if(!gotMenuMap && !loadingMM)
   {
        loadingMM = 1;
	var client = new HTTPClient();
	var url = '/home/home/getMenuMap.cgi';
	url += "?onNav=" + onNav;
	client.init(url);		
	client.asyncGET(getMenuMap);	
   }  
}

function hideMenuMap()
{
   if(showMMTimeOutId)
	clearTimeout(showMMTimeOutId);
   showMMTimeOutId = '';
   loadingMM = 0;
}

var getMenuMap = {
  onLoad: function(data)
  {
	if(data)
	{
		mmid = document.getElementById('menuMapContents');
		if(mmid)	
		{
			gotMenuMap = 1;
			mmid.innerHTML = data;
		}
	}
	loadingMM = 0;
  },

  onError: function() {
	gotMenuMap = 0;
	loadingMM = 0;
  }

}; 

function hideIt(id)
{
        obj = document.getElementById(id);
        if(obj)
        {
                obj.style.display = 'none';
        }
}

function setTabPref(menuSet, tabId, add)
{
	var action;
	if(add)
	{
		action = 'add';
		var iid = 'tabPref_' + tabId;	
		hideIt(iid);
	}
	else
	{
		action = 'remove';
		if(onNav != tabId)
		{
			hideIt('topNav_' + tabId);
			hideIt('subNav_' + tabId);
		}
	}
	var url = '/home/home/setPref.cgi?pType=list&pMin=1&pMax=10&pAction=' + action + '&pVar=menu.' + menuSet + '.customTabs&pVal=' + tabId;
	hitUrl(url);
	return(false);
}

function kbpop(url, wid)
{
	if(!wid)
	{
		wid = "mainHelp";
	}
	window.name = "main";
        wobj = window.open(url, wid, "scrollbars,resizable,width=800,height=450");
	wobj.focus();
	return(false);
}     

function noEnter()
{
	return !(window.event && window.event.keyCode == 13); 
}		

function addShadows()
{
	var offset = 3;
	var layers = 3;
	var foundTables = 0;
	var tables = document.getElementsByTagName("table");
	for(i=1; i <= tables.length; i++)
	{
		if(tables[i] && tables[i].className)
		{
			aclass = tables[i].className;
		}
		else
		{
			aclass = '';
		}
		if(aclass == 'border metraShadow')
		{
			foundTables++;
			tobj = tables[i];
		        currentTop = getObjectTop(tables[i]);	
		        currentHeight = getObjectHeight(tables[i]) - 1;
		        currentLeft = getObjectLeft(tables[i]);	
		        currentWidth = getObjectWidth(tables[i]);
			
			for(j=1; j<=layers; j++)
			{
				sobj1 = document.getElementById('tableShadow' + foundTables + j);
			        if(sobj1)
				{
				sobj1.className = 'metraShadow' + j;
				sobj1.style.position = 'absolute';
				sobj1.style.visibility = 'visible';
				sobj1.style.zIndex = '-' + j;
				sobj1.style.left = currentLeft + offset + foundTables + j;
				sobj1.style.top = currentTop + offset + foundTables + j - 20;
				sobj1.style.width = currentWidth;
				sobj1.style.height = currentHeight;
				}
			}
		}
	}
}
