/********************************************************
Set of Global JavaScript functions to be used
troughout GOLD!

Jason Pearce, v1.0, 02/9/2004
********************************************************/

function focusErrorHandler() {
event.srcElement.className='errorActive';
event.srcElement.onfocus='';
event.srcElement.onkeydown=unfocusErrorHandler;
event.srcElement.onblur=unfocusErrorHandler;
}

function unfocusErrorHandler() {
event.srcElement.className='textbox';
event.srcElement.onkeydown='';
event.srcElement.onblur='';
}


// focus on a field

function focusField(field)
{
   switch(field.type) 
   {
      case "text" :
      case "textarea" :
      case "password" :
        field.onfocus=focusErrorHandler;
      	field.focus();
      	break; 
      case "select-one" :
      case "select-multiple" :
      case "radio" :
      case "checkbox" :
      	field.focus();
      	break; 
      default :
		field[0].focus();      
        break;
   }
}

 
// ################
//gets a field's value

function fieldIsChecked(field) {
return ('Yes'==getFieldValue(field));
}

function fieldIsNotChecked(field) {
return ('No'==getFieldValue(field));
}


function getDisplayedFieldValue(field)
{
   switch(field.type)
   {
      case "text" :
      case "textarea" :
      case "password" :
      case "hidden" :
         return field.value;

      case "select-one" :
         var i = field.selectedIndex;
         if (i == -1)   return "";
         else   return (field.options[i].text == "") ? field.options[i].value : field.options[i].text;

      case "select-multiple" :
         var allChecked = new Array();
         for(i = 0; i < field.options.length; i++)
            if(field.options[i].selected)
               allChecked[allChecked.length] = (field.options[i].text == "") ? field.options[i].value : field.options[i].text;
         return allChecked;

      case "button" :
      case "reset" :
      case "submit" :
         return "";

      case "radio" :
      case "checkbox" :
         if (field.checked) { return field.value; } else { return ""; }
      default :
         if(field[0].type == "radio")
         {
            for (i = 0; i < field.length; i++)
               if (field[i].checked)
                  return field[i].value;

            return "";
         }
         else if(field[0].type == "checkbox")
         {
            var allChecked = new Array();
            for(i = 0; i < field.length; i++)
               if(field[i].checked)
                  allChecked[allChecked.length] = field[i].value;

            return allChecked;
         }
         else
            var str = "";
            for (x in field) { str += x + "\n"; }
      //      alert("I couldn't figure out what type this field is...\n\n" + field.name + ": ???\n\n\n" + str + "\n\nlength = " + field.length);
         break;
   }
   
   return "";
}



function getFieldValue(field)
{
   switch(field.type)
   {
      case "text" :
      case "textarea" :
      case "password" :
      case "hidden" :
         return field.value;

      case "select-one" :
         var i = field.selectedIndex;
         if (i == -1)   return "";
         else   return (field.options[i].value == "") ? field.options[i].text : field.options[i].value;

      case "select-multiple" :
         var allChecked = new Array();
         for(i = 0; i < field.options.length; i++)
            if(field.options[i].selected)
               allChecked[allChecked.length] = (field.options[i].value == "") ? field.options[i].text : field.options[i].value;
         return allChecked;

      case "button" :
      case "reset" :
      case "submit" :
         return "";

      case "radio" :
      case "checkbox" :
         if (field.checked) { return field.value; } else { return ""; }
      default :
         if(field[0].type == "radio")
         {
            for (i = 0; i < field.length; i++)
               if (field[i].checked)
                  return field[i].value;

            return "";
         }
         else if(field[0].type == "checkbox")
         {
            var allChecked = new Array();
            for(i = 0; i < field.length; i++)
               if(field[i].checked)
                  allChecked[allChecked.length] = field[i].value;

            return allChecked;
         }
         else
            var str = "";
            for (x in field) { str += x + "\n"; }
      //      alert("I couldn't figure out what type this field is...\n\n" + field.name + ": ???\n\n\n" + str + "\n\nlength = " + field.length);
         break;
   }
   
   return "";
}

 
//radio functions

function getSelectedRadio(buttonGroup) {
   // returns the array number of the selected radio button or -1 if no button is selected
   if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            return i
         }
      }
   } else {
      if (buttonGroup.checked) { return 0; } // if the one button is checked, return zero
   }
   // if we get to this point, no radio button is selected
   return -1;
} // Ends the "getSelectedRadio" function

function getSelectedRadioValue(buttonGroup) {
   // returns the value of the selected radio button or "" if no button is selected
   var i = getSelectedRadio(buttonGroup);
   if (i == -1) {
      return "";
   } else {
      if (buttonGroup[i]) { // Make sure the button group is an array (not just one button)
         return buttonGroup[i].value;
      } else { // The button group is just the one button, and it is checked
         return buttonGroup.value;
      }
   }
} // Ends the "getSelectedRadioValue" function 
 
 
// ###################
//sets the value of a combo box
function setComboValue(obj,value) {
	var o=obj.options;
	for(var i=0;i<o.length;i++){
			if(o[i].value==value){ 
				o[i].selected=true;
			}
	}
}
 
// ###################3
//sets the value of a combo box
function setRadioValue(obj,value) {
	for(var i=0;i<obj.length;i++){
			if(obj[i].value==value){
				obj[i].checked=true;
			}
	}
} 
 
 
// #############################################################################
// Used to change the text of the status bar
function MM_displayStatusMsg(msgStr) { //v1.0
  status=msgStr;
  document.MM_returnValue = true;
}
 // #############################################################################

 
// #############################################################################
// Used to disable links for the Printer-Friendly Page
 function cancelLink () {
  return false;
}

function disableLinks() {
var allLinks = document.links;
 
for(i=0;i<allLinks.length;i++){
	if (allLinks[i].id!="printLink" && allLinks[i].id!="closeLink") {
    	allLinks[i].onclick=cancelLink;
    }
  }
}
// #############################################################################

// #############################################################################
// Used to open up a new window
/*popupWindow is called from a link to open up a popup window
Format of link: <a href="/signingin.html" onClick="popupWindow(this.href,'SignIn','width=400,height=400,toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=no',1,2,2);return document.MM_returnValue">Link goes here</a> */

function popupWindow(){//v1.44
var v1=arguments,v2=v1[2].split(","),v3=(v1.length>3)?v1[3]:false,v4=(v1.length>4)?parseInt(v1[4]):0,v5=(v1.length>5)?parseInt(v1[5]):0,v6,v7=0,v8,v9,v10,v11,v12,v13,v14,v15,v16;v11=new Array("width,left,"+v4,"height,top,"+v5);for (i=0;i<v11.length;i++){v12=v11[i].split(",");l_iTarget=parseInt(v12[2]);if (l_iTarget>1||v1[2].indexOf("%")>-1){v13=eval("screen."+v12[0]);for (v6=0;v6<v2.length;v6++){v10=v2[v6].split("=");if (v10[0]==v12[0]){v14=parseInt(v10[1]);if (v10[1].indexOf("%")>-1){v14=(v14/100)*v13;v2[v6]=v12[0]+"="+v14;}}if (v10[0]==v12[1]){v16=parseInt(v10[1]);v15=v6;}}if (l_iTarget==2){v7=(v13-v14)/2;v15=v2.length;}else if (l_iTarget==3){v7=v13-v14-v16;}v2[v15]=v12[1]+"="+v7;}}v8=v2.join(",");v9=window.open(v1[0],v1[1],v8);if (v3){v9.focus();}document.MM_returnValue=false;return v9;}
// #############################################################################

// #############################################################################
// A-Z Jump Menu

var majorRiskArray=[];
var minorRiskArray=[];

function addToArray(riskArray,letter,el) {
newObject={};
newObject.id=letter;
newObject.element=el;
riskArray[riskArray.length]=newObject;
}

function goToMajorRiskLetter(letter) {
var idStr='majorRiskSelectorLetter_'+letter;

for (var i=0;i<majorRiskArray.length;i++) {
	if (majorRiskArray[i].id==idStr) {
	//alert(majorRiskArray[i].element.style);
		majorRiskArray[i].element.style.display='block';
	}
	else {
		majorRiskArray[i].element.style.display='none';
	}
}
}

function goToMinorRiskLetter(letter) {
var idStr='minorRiskSelectorLetter_'+letter;

for (var i=0;i<minorRiskArray.length;i++) {
	if (minorRiskArray[i].id==idStr) {
	//alert(majorRiskArray[i].element.style);
		minorRiskArray[i].element.style.display='block';
	}
	else {
		minorRiskArray[i].element.style.display='none';
	}
}
}


// #############################################################################

// #############################################################################
// Displays the Live CLock
 
function MM_displayStatusMsg(msgStr) { //v1.0
  status=msgStr;
  document.MM_returnValue = true;
}

function MakeArrayday(size) {
this.length = size;
for(var i = 1; i <= size; i++) {
this[i] = "";
}
return this;
}
function MakeArraymonth(size) {
this.length = size;
for(var i = 1; i <= size; i++) {
this[i] = "";
}
return this;
}
function funClock() {
if (!document.layers && !document.all)
return;
var runTime = new Date();
var hours = runTime.getHours();
var minutes = runTime.getMinutes();
var seconds = runTime.getSeconds();
var dn = "AM";
if (hours >= 12) {
dn = "PM";
hours = hours - 12;
}
if (hours == 0) {
hours = 12;
}
if (minutes <= 9) {
minutes = "0" + minutes;
}
if (seconds <= 9) {
seconds = "0" + seconds;
}
movingtime = ""+ hours + ":" + minutes + " " + dn + "";
if (document.layers) {
document.layers.clock.document.write(movingtime);
document.layers.clock.document.close();
}
else if (document.all) {
clock.innerHTML = movingtime;
}
setTimeout("funClock()", 1000)
}
// #############################################################################

// #############################################################################
// Swaps image files for mouseover events
// <a href="index.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('grp_ImageName','','Bookmark_a.gif',1)"><img src="Bookmark_u.gif" alt="Bookmark page's by clicking here." name="grp_ImageName" width="113" height="17" border="0"></a>
//<img src="Bookmark_u.gif" alt="Bookmark page's by clicking here." name="grp_ImageName" width="113" height="17" border="0">
//<a href="index.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('grp_ImageName','','Bookmark_a.gif',1)">Link Here</a>

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
// #############################################################################

// #############################################################################
// hideCalendar
var isIE = false;
var isOther = false;
var isNS4 = false;
var isNS6 = false;
if(document.getElementById)
{
	if(!document.all)
	{
		isNS6=true;
	}
	if(document.all)
	{
		isIE=true;
	}
}
else
{
	if(document.layers)
	{
		isNS4=true;
	}
	else
	{
		isOther=true;
	}
}


function aLs(layerID)
{
var returnLayer;
	if(isIE)
	{
		returnLayer = eval("document.all." + layerID + ".style");
	}
	if(isNS6)
	{
		returnLayer = eval("document.getElementById('" + layerID + "').style");
	}
	if(isNS4)
	{
		returnLayer = eval("document." + layerID);
	}
	if(isOther)
	{
		returnLayer = "null";
		alert("-[Error]-\nDue to your browser you will probably not\nbe able to view all of the following page\nas it was designed to be viewed. We regret\nthis error sincerely.");
	}
return returnLayer;
}



function HideShow(ID)
{
	if((aLs(ID).visibility == "visible") || (aLs(ID).visibility == ""))
	{
		aLs(ID).visibility = "hidden";
	}
	else if(aLs(ID).visibility == "hidden")
	{
		aLs(ID).visibility = "visible";
	}
}
// #############################################################################


// #############################################################################
// Expands or collapses the section
function ExpandCollapseSection(ID)
{
	if(aLs(ID).height == "")
	{
		aLs(ID).height = "100%";
	}
	else if(aLs(ID).height == "100%")
	{
		aLs(ID).height = "";
	}
}
// #############################################################################



var clicks = 0;
function ChangeText(obj, originalText, clickText)
{
	if(clicks == 0)
	{
		obj.innerHTML = clickText;
		clicks = 1;
	}
	else
	{
		obj.innerHTML = originalText;
		clicks = 0;
	}	
}





// #############################################################################
// Shows the current date
function currentLongDate() { 
var d, dt, day, m, x, y, z; 
var x = new Array("Sunday", "Monday", "Tuesday", "Wednesday"); 
var x = x.concat("Thursday", "Friday", "Saturday"); 
var z = new Array("Jan", "Feb", "March", "April", "May", "June"); 
var z = z.concat("July", "Aug", "Sept", "Oct", "Nov", "Dec"); 
d = new Date(); 
m = d.getMonth(); 
dt = d.getDate(); 
y = d.getFullYear(); 
day = d.getDay(); 
document.write(z[m] + " " + dt + ", " + y); 
} 

function currentDayOfWeek() { 
var d, dt, day, m, x, y, z; 
var x = new Array("Sunday", "Monday", "Tuesday", "Wednesday"); 
var x = x.concat("Thursday", "Friday", "Saturday"); 
var z = new Array("Jan", "Feb", "March", "April", "May", "June"); 
var z = z.concat("July", "Aug", "Sept", "Oct", "Nov", "Dec"); 
d = new Date(); 
m = d.getMonth(); 
dt = d.getDate(); 
y = d.getFullYear(); 
day = d.getDay(); 
document.write(x[day]); 
} 

function currentDay() { 
var d, dt, day, m, x, y, z; 
var x = new Array("Sunday", "Monday", "Tuesday", "Wednesday"); 
var x = x.concat("Thursday", "Friday", "Saturday"); 
var z = new Array("Jan", "Feb", "March", "April", "May", "June"); 
var z = z.concat("July", "Aug", "Sept", "Oct", "Nov", "Dec"); 
d = new Date(); 
m = d.getMonth(); 
dt = d.getDate(); 
y = d.getFullYear(); 
day = d.getDay(); 
document.write(dt); 
}
// #############################################################################



// Show Help Window
function helpWindow(mylink, windowname, popW, popH, scroll, resize){ 
if (! window.focus)return true;
var href;
if (typeof(mylink) == 'string')
   href=mylink;
else
   href=mylink.href;
var popW=217;
var popH=(screen.height - 60);
var scroll='yes';
var resize='yes';
var winleft=(screen.width - popW) - 10;
var winUp = 0;
winProp = 'width='+popW+',height='+popH+',left='+winleft+',top='+winUp+',scrollbars='+scroll+',resizeable='+resize+'';
Win = window.open(href,windowname,winProp);
if (parseInt(navigator.appVersion) >=4){Win.window.focus();}
}

// Close New Popup Window
function Lvl_P2P(url,closeIt,delay){ //ver1.0 4LevelWebs
    opener.location.href = url;
	if (closeIt == true)setTimeout('self.close()',delay);
}

// Close and Refresh Parent Window
function closeRefresh() {  
    opener.contentFRM.location.reload(true);
}
function onloadRefresh() {  
    window.location.reload();
}


// #############################################################################
// Used to open up side Help Pane
function PopupWindow ()
{
	if (window.PopupWindowInstance != null)
		{
		window.alert("You may create only one PopupWindow object on a page.");
		return null;
		}
	window.PopupWindowInstance = this;
	this.ShowSideHelp = PopupWindow_ShowSideHelp;
	this.CloseSideHelp = PopupWindow_CloseSideHelp;
	this.ShowWithTimeout = PopupWindow_ShowWithTimeout;
	this.DialogWithTimeout = PopupWindow_DialogWithTimeout;
	this.windowRef = null;
}

function PopupWindow_ShowSideHelp (sHelpURL, cxHelpWidth)
{
	if ((window.SideHelpWindow == null) || (window.SideHelpWindow == false))
		{
		var _tempLeft;
		var _tempTop;
		var _tempWidth;
		var _tempHeight;
		
		_tempLeft = window.screenLeft;
		_tempTop = window.screenTop;
		window.moveTo(_tempLeft, _tempTop);
		this._saveLeft = _tempLeft - (window.screenLeft - _tempLeft);
		this._saveTop = _tempTop - (window.screenTop - _tempTop);
		window.moveTo(this._saveLeft, this._saveTop);
		
		_tempWidth = window.document.body.clientWidth;
		_tempHeight = window.document.body.clientHeight;
		window.resizeTo(_tempWidth, _tempHeight);
		this._saveWidth = _tempWidth + (_tempWidth - window.document.body.clientWidth);
		this._saveHeight = _tempHeight + (_tempHeight - window.document.body.clientHeight);
		window.resizeTo(this._saveWidth, this._saveHeight);
		
		window.moveTo(0,0);
		window.resizeTo(screen.availWidth - cxHelpWidth, screen.availHeight);
		window.SideHelpWindow = window.open(sHelpURL, "PopupWindowHelp", "left=" + (screen.availWidth - cxHelpWidth).toString() + ",top=0,width=" + cxHelpWidth.toString() + ",height=" + screen.availHeight.toString());
		window.SideHelpWindowCloseCheckTimer = window.setInterval(PopupWindow_CheckForClose, 200);
		}
	else
		{
		window.open(sHelpURL, "PopupWindowHelp");
		}
}

function PopupWindow_CheckForClose()
{
	if (window.SideHelpWindow.closed)
	{
		PopupWindow_CloseSideHelp();
		window.clearInterval(SideHelpWindowCloseCheckTimer);
		window.SideHelpWindowCloseCheckTimer = null;
	}
}

function PopupWindow_CloseSideHelp ()
{
	if (window.SideHelpWindow != null)
		{
		window.clearInterval(SideHelpWindowCloseCheckTimer);
		window.SideHelpWindowCloseCheckTimer = null;
		window.SideHelpWindow.close();
		window.SideHelpWindow = null;
		var pw = window.PopupWindowInstance;
		window.moveTo(pw._saveLeft, pw._saveTop);
		window.resizeTo(pw._saveWidth, pw._saveHeight);
		}
}

function PopupWindow_ShowWithTimeout (sHelpURL, nTimeoutSeconds, cxWidth, cyHeight, bAutoCenter, xPosition, yPosition)
{
	if (this.windowRef != null)
		{
		window.alert("You already have a popup window showing. You can show only one timed popup window at a time.");
		return false;
		}
	var sDefaultFeatures = ""; // "directories=no;location=no;menubar=no;scrollbars=no;status=no;toolbar=no;";
	var xWindowPos;
	var yWindowPos;
	var sFeatures;
	if (bAutoCenter)
		{
		var xScreenCenter = Math.floor(screen.availWidth / 2);
		var yScreenCenter = Math.floor(screen.availHeight / 2);
		xWindowPos = xScreenCenter - Math.floor(cxWidth / 2);
		yWindowPos = yScreenCenter - Math.floor(cyHeight / 2);
		sFeatures = sDefaultFeatures + "left=" + xWindowPos.toString() + ",top=" + yWindowPos.toString() + ",width=" + cxWidth.toString() + ",height=" + cyHeight.toString();
		}
	else
		{
		xWindowPos = xPosition;
		yWindowPos = yPosition;
		sFeatures = sDefaultFeatures + "left=" + xWindowPos.toString() + ",top=" + yWindowPos.toString() + ",width=" + cxWidth.toString() + ",height=" + cyHeight.toString();
		}
	this.windowRef = window.open(sHelpURL, "_blank", sFeatures, false);
	window.setTimeout(Popupwindow_ClosePopup, nTimeoutSeconds * 1000);
}

function PopupWindow_DialogWithTimeout (sHelpURL, nTimeoutSeconds, cxWidth, cyHeight, bAutoCenter, xPosition, yPosition)
{
	if (this.windowRef != null)
		{
		window.alert("You already have a popup window showing. You can show only one timed popup window at a time.");
		return false;
		}
	var sFeatures = new String();
	if (bAutoCenter)
		{
		sFeatures = sFeatures.concat("center:yes");
		sFeatures = sFeatures.concat(",dialogWidth:" + cxWidth.toString());
		sFeatures = sFeatures.concat(",dialogHeight:" + cyHeight.toString());
		}
	else
		{
		sFeatures = sFeatures.concat("center:no");
		sFeatures = sFeatures.concat(",dialogWidth:" + cxWidth.toString());
		sFeatures = sFeatures.concat(",dialogHeight:" + cyHeight.toString());
		sFeatures = sFeatures.concat(",dialogLeft:" + xPosition.toString());
		sFeatures = sFeatures.concat(",dialogTop:" + yPosition.toString());
		}
	this.windowRef = window.showModelessDialog(sHelpURL, null, sFeatures);
	window.setTimeout(Popupwindow_ClosePopup, nTimeoutSeconds * 1000);
}

function Popupwindow_ClosePopup ()
{
	var pw = window.PopupWindowInstance;
	if (pw.windowRef != null)
		{
		pw.windowRef.close();
		pw.windowRef = null;
		}
}

var popWin = new PopupWindow();
function ShowSideHelp (url)
{
	popWin.ShowSideHelp(url, 200);
}
// #############################################################################

// #############################################################################
// Toolbar MouseOver Functions - Used in Secure Messaging
function MO(e)
{ 
if (!e)
var e=window.event;
var S=e.srcElement;
while (S.tagName!="TD")
{S=S.parentElement;}
S.className="T";
}
function MU(e)
{
if (!e)
var e=window.event;
var S=e.srcElement;
while (S.tagName!="TD")
{S=S.parentElement;}
S.className="P";
}
// #############################################################################

// #############################################################################
// <DIV> Flyout Menus

var userAgent = navigator.userAgent.toLowerCase();
var is_opera  = (userAgent.indexOf('opera') != -1);
var is_saf    = ((userAgent.indexOf('safari') != -1) || (navigator.vendor == "Apple Computer, Inc."));
var is_webtv  = (userAgent.indexOf('webtv') != -1);
var is_ie     = ((userAgent.indexOf('msie') != -1) && (!is_opera) && (!is_saf) && (!is_webtv));
var is_ie4    = ((is_ie) && (userAgent.indexOf("msie 4.") != -1));
var is_moz    = ((navigator.product == 'Gecko') && (!is_saf));
var is_kon    = (userAgent.indexOf('konqueror') != -1);
var is_ns     = ((userAgent.indexOf('compatible') == -1) && (userAgent.indexOf('mozilla') != -1) && (!is_opera) && (!is_webtv) && (!is_saf));
var is_ns4    = ((is_ns) && (parseInt(navigator.appVersion) == 4));


var vbDOMtype = '';
if (document.getElementById)
{
	vbDOMtype = "std";
}
else if (document.all)
{
	vbDOMtype = "ie4";
}
else if (document.layers)
{
	vbDOMtype = "ns4";
}


var vBobjects = new Array();

function fetch_object(idname, forcefetch)
{
	if (forcefetch || typeof(vBobjects[idname]) == "undefined")
	{
		switch (vbDOMtype)
		{
			case "std":
			{
				vBobjects[idname] = document.getElementById(idname);
			}
			break;

			case "ie4":
			{
				vBobjects[idname] = document.all[idname];
			}
			break;

			case "ns4":
			{
				vBobjects[idname] = document.layers[idname];
			}
			break;
		}
	}
	return vBobjects[idname];
}


var showHide_divPopups = false;
function showHide_div(controlid, nowrite, datefield)
{
	if (showHide_divPopups)
	{
		showHide_divRegister(controlid, nowrite, datefield);
	}
}


function showHide_divInit()
{
	if (is_webtv)
	{
		return true;
	}
	switch (vbDOMtype)
	{
		case "std": imgs = document.getElementsByTagName("img"); break;
		case "ie4": imgs = document.all.tags("img");             break;
		default:    imgs = false;                                break;
	}
	if (imgs)
	{
		// set 'title' tags for image elements
		for (var i = 0; i < imgs.length; i++)
		{
			if (!imgs[i].title && imgs[i].alt != "")
			{
				imgs[i].title = imgs[i].alt;
			}
		}
	}

	if (showHide_divPopups && vbmenu_registered.length > 0)
	{
		for (i in vbmenu_registered)
		{
			vbmenu_init(vbmenu_registered[i]);
		}

	//	document.onclick = vbmenu_close;
	}
	return true;
}


function do_an_e(eventobj)
{
	if (!eventobj || is_ie)
	{
		window.event.returnValue = false;
		window.event.cancelBubble = true;
		return window.event;
	}
	else
	{
		eventobj.stopPropagation();
		eventobj.preventDefault();
		return eventobj;
	}
}



var showHide_divPopups = true;
var vbmenu_registered = new Array();
var vbmenu_initialized = new Array();
var vbmenu_activemenus = new Array();
var vbmenu_currentactive = false;
var slidetimer = false;
var vbmenu_opensteps = 10;
var vbmenu_doslide = true;
var vbmenu_dofade = false; // can be very slow
var vbmenu_datefields = new Array();


function e_by_gum(eventobj)
{
	if (!eventobj || is_ie)
	{
		window.event.cancelBubble = true;
		return window.event;
	}
	else
	{
		if (eventobj.target.type == 'submit')
		{
			// naughty safari
			eventobj.target.form.submit();
		}
		eventobj.stopPropagation();
		return eventobj;
	}
}


function fetch_object_posleft(elm)
{
	var left = elm.offsetLeft;
	while((elm = elm.offsetParent) != null)
	{
		left += elm.offsetLeft;
	}
	return left;
}


function fetch_object_postop(elm)
{
	var top = elm.offsetTop;
	while((elm = elm.offsetParent) != null)
	{
		top += elm.offsetTop;
	}
	return top;
}


function showHide_divRegister(controlid, nowrite, datefield)
{
	if (document.getElementsByTagName)
	{
		controlobj = fetch_object(controlid);
		if (controlobj)
		{			
			if (datefield)
			{
				vbmenu_datefields[controlid] = datefield;
			}
			
			vbmenu_registered[vbmenu_registered.length] = controlid;
			
			if (!nowrite)
			{
				document.write('<img src="/images/spacer.gif" alt="" border="0" />');
			}
			return true;
		}
	}
	
	return false;
}


function vbmenu_getmenuid(controlid)
{
	dotpos = controlid.indexOf(".");
	if (dotpos != -1)
	{
		return controlid.substr(0, dotpos);
	}
	else
	{
		return controlid;
	}
}


function vbmenu_eventhandler_mouseover(e)
{
	e = do_an_e(e);
	vbmenu_hover(this);
}


function vbmenu_eventhandler_click(e)
{
	e = do_an_e(e);
	vbmenu_open(this);
}


function vbmenu_close()
{
	if (vbmenu_currentactive)
	{
		for (key in vbmenu_activemenus)
		{
			fetch_object(vbmenu_getmenuid(key) + "_menu").style.display = "none";
			vbmenu_activemenus[key] = false;
		}
	}
	vbmenu_currentactive = false;
	
	if (slidetimer)
	{
		clearTimeout(slidetimer);
		slidetimer = false;
	}
	
	if (is_ie)
	{
		selects = document.getElementsByTagName("select");
		for (var i = 0; i < selects.length; i++)
		{
			selects[i].style.visibility = "visible";
		}
	}
}


function vbmenu_hover(elm)
{
	for (key in vbmenu_activemenus)
	{
		if (vbmenu_activemenus[key] == true && key != elm.id)
		{
			vbmenu_open(elm);
			return;
		}
	}
}


function vbmenu_overlap(selectobj, m)
{
	s = new Array();
	s['L'] = fetch_object_posleft(selectobj);
	s['T'] = fetch_object_postop(selectobj);	
	s['R'] = s['L'] + selectobj.offsetWidth;
	s['B'] = s['T'] + selectobj.offsetHeight;
	
	if (s['L'] >= m['L'] && s['L'] <= m['R'] && ((s['T'] >= m['T'] && s['T'] <= m['B']) || (s['B'] >= m['T'] && s['B'] <= m['B']))) { return true; }
	else if (s['R'] >= m['L'] && s['R'] <= m['R'] && ((s['T'] >= m['T'] && s['T'] <= m['B']) || (s['B'] >= m['T'] && s['B'] <= m['B']))) { return true; }
	else if (s['B'] >= m['T'] && s['T'] <= m['B'] && ((s['L'] >= m['L'] && s['L'] <= m['R']) || (s['R'] >= m['R'] && s['R'] <= m['R']))) { return true; }
	else if (m['B'] >= s['T'] && m['T'] <= s['B'] && ((m['L'] >= s['L'] && m['L'] <= s['R']) || (m['R'] >= s['R'] && m['R'] <= s['R']))) { return true; }
	else { return false; }
}


function vbmenu_open(elm)
{
	openmenu = vbmenu_currentactive;
	
	vbmenu_close();
	
	if (openmenu == elm.id)
	{
		// clicked element was the control for the currently open menu - exit
		return false;
	}
	
	// get the id of the menu to be opened
	menuid = vbmenu_getmenuid(elm.id) + "_menu";	
	menuobj = fetch_object(menuid);
	
	if (vbmenu_datefields[elm.id])
	{
		force_right_slide = true;
		fetch_object(elm.id + "_output").innerHTML = fetch_object(vbmenu_datefields[elm.id]).value;
	}
	else
	{
		force_right_slide = false
	}
	
	vbmenu_activemenus[elm.id] = true;
	vbmenu_currentactive = elm.id;
	
	// get menu position
	leftpx = fetch_object_posleft(elm);
	toppx = fetch_object_postop(elm) + elm.offsetHeight;
	
	// un-hide menu	
	menuobj.style.display = "";
	
	// attempt to keep menu on screen
	if (force_right_slide || (leftpx + menuobj.offsetWidth) >= document.body.clientWidth)
	{
		leftpx = leftpx + elm.offsetWidth - menuobj.offsetWidth;
		slidedir = "right";
	}
	else
	{
		slidedir = "left";
	}

	// shuffle the IE menus a bit
	if (is_ie)
	{
		leftpx += (slidedir == "left") ? -2 : 2;
	}
	
	// set menu position
	menuobj.style.left = leftpx + "px";
	menuobj.style.top = toppx + "px";
	
	if (is_ie)
	{	
		menuarea = {
			"L" : leftpx,
			"T" : toppx,
			"R" : leftpx + menuobj.offsetWidth,
			"B" : toppx + menuobj.offsetHeight
		};		
		selects = document.getElementsByTagName("select");
		for (var i = 0; i < selects.length; i++)
		{
			if (vbmenu_overlap(selects[i], menuarea))
			{
				selects[i].style.visibility = "hidden";
			}
		}
	}

	// slide menus open (internet explorer only)
	if (vbmenu_doslide && !is_opera && !is_ie4)
	{
		if (vbmenu_dofade && is_ie)
		{
			menuobj.filters.item('DXImageTransform.Microsoft.alpha').opacity = 0;
		}
		
		intervalX = Math.ceil(menuobj.offsetWidth / vbmenu_opensteps);
		intervalY = Math.ceil(menuobj.offsetHeight / vbmenu_opensteps);
		
		if (slidedir == "left")
		{
			menuobj.style.clip = "rect(auto, 0px, 0px, auto)";
			vbmenu_slide_left(menuid, intervalX, intervalY, 0, 0, 0);
		}
		else
		{
			menuobj.style.clip = "rect(auto, auto, 0px, " + (menuobj.offsetWidth) + "px)";
			vbmenu_slide_right(menuid, intervalX, intervalY, menuobj.offsetWidth, 0, 0);
		}
	}
	
	return false;
}


function vbmenu_slide_left(menuid, intervalX, intervalY, clipX, clipY, opacity)
{
	menuobj = fetch_object(menuid);
	
	if (clipX < menuobj.offsetWidth || clipY < menuobj.offsetHeight)
	{
		if (vbmenu_dofade && is_ie)
		{
			opacity += 10;
			menuobj.filters.item('DXImageTransform.Microsoft.alpha').opacity = opacity;
		}
		clipX += intervalX;
		clipY += intervalY;
		menuobj.style.clip = "rect(auto, " + clipX + "px, " + clipY + "px, auto)";
		slidetimer = setTimeout("vbmenu_slide_left('" + menuid + "', " + intervalX + ", " + intervalY + ", " + clipX + ", " + clipY + ", " + opacity + ");", 0);
	}
	else
	{
		clearTimeout(slidetimer);
	}
}


function vbmenu_hand_pointer(obj)
{
	try
	{
		obj.style.cursor = "pointer";
	}
	catch(e)
	{
		obj.style.cursor = "hand";
	}
}


function vbmenu_init(controlid)
{
	menuid = vbmenu_getmenuid(controlid) + "_menu";
	menuobj = fetch_object(menuid);
	
	if (document.getElementsByTagName && menuobj)
	{

		controlobj = fetch_object(controlid);
		vbmenu_hand_pointer(controlobj);
		controlobj.unselectable = true;
		controlobj.onclick = vbmenu_eventhandler_click;
		controlobj.onmouseover = vbmenu_eventhandler_mouseover;
		

		if (vbmenu_initialized[menuid])
		{
			return;
		}
		

		popupobj = fetch_object(menuid);
		popupobj.style.display = "none";
		popupobj.style.position = "absolute";
		popupobj.style.left = "0px";
		popupobj.style.top = "0px";
		popupobj.onclick = e_by_gum;
		

		tables = popupobj.getElementsByTagName("table");
		if (tables.length > 0)
		{
			tables[0].width = "";
		}
		

		if (is_ie)
		{		
			popupobj.style.filter += "progid:DXImageTransform.Microsoft.alpha(enabled=1,opacity=100)";
			popupobj.style.filter += "progid:DXImageTransform.Microsoft.shadow(direction=135,color=#8E8E8E,strength=3)";
		}
		

		tds = popupobj.getElementsByTagName("td");
		for (var i = 0; i < tds.length; i++)
		{			
			if (tds[i].className == "vbmenu_option")
			{
				tds[i].style.cursor = "default";
				if (tds[i].title == "nohilite")
				{
					tds[i].title = "";
				}
				else
				{
					tds[i].onmouseover = vbmenu_switch_option_bg;
					tds[i].onmouseout = vbmenu_switch_option_bg;
					tds[i].onclick = vbmenu_navtolink;
					

					if (!is_saf && !is_kon)
					{
						try
						{
							links = tds[i].getElementsByTagName("a");
							for (var j = 0; j < links.length; j++)
							{
								if (!links[j].onclick)
								{
									links[j].onclick = e_by_gum;
								}
							}
						}
						catch(e)
						{
							
						}
					}
				}
			}
			else if (is_moz)
			{
				tds[i].onmouseover = moz_rclick;
				tds[i].onmouseout = moz_rclick;
			}
		}
		
		vbmenu_initialized[menuid] = true;
	}
}

function returnfalse()
{
	return false;
}

function moz_rclick(e)
{
	if (e.type == 'mouseover')
	{
		document.onclick = '';
	}
	else
	{
		document.onclick = vbmenu_close;
	}
}
// #############################################################################

// #############################################################################
// Highlight table cell - Used on the flyout menus
var gObj,gHex,timer;
function NN_tr_start(obj,hex,type){
	var isMoz = parseInt(navigator.appVersion) >= 5 && navigator.appName == 'Netscape' ? true : false;
	if (type == 'fade' && !isMoz){gHex=hex;gObj=obj;NN_tr_fadeIn();
	} else { obj.style.backgroundColor=hex;}
	obj.style.cursor='hand';
}
 
function NN_tr_fadeIn(){
	var cntr=0,pObj=gObj.style.backgroundColor;
	var r = parseInt(gHex.substring(1,3),16),g = parseInt(gHex.substring(3,5),16), b = parseInt(gHex.substring(5,7),16);
	var rr = parseInt(pObj.substring(1,3),16),gg = parseInt(pObj.substring(3,5),16),bb = parseInt(pObj.substring(5,7),16);
		if (r!=rr){if(rr<r){rr++;}else{rr--;}}else{cntr++;}
		if (g!=gg){if(gg<g){gg++;}else{gg--;}}else{cntr++;}
		if (b!=bb){if(bb<b){bb++;}else{bb--;}}else{cntr++;}
	rr=rr.toString(16);gg=gg.toString(16);bb=bb.toString(16);
	rr=rr.length==1?'0'+rr:rr;gg=gg.length==1?'0'+gg:gg;bb=bb.length==1?'0'+bb:bb;
	gObj.style.backgroundColor='#'+rr.toUpperCase()+gg.toUpperCase()+bb.toUpperCase();
	if (cntr!=3){timer=setTimeout('NN_tr_fadeIn()',1);}
}

function NN_tr_reset(obj,hex){
	obj.style.backgroundColor=hex;clearTimeout(timer);  
} 
 
var gObj,gHex,timer;
function NN_tr_start(obj,hex,type){ 
	var isMoz = parseInt(navigator.appVersion) >= 5 && navigator.appName == 'Netscape' ? true : false;
	if (type == 'fade' && !isMoz){gHex=hex;gObj=obj;NN_tr_fadeIn();
	} else { obj.style.backgroundColor=hex;}
	obj.style.cursor='hand';
}
  
function NN_tr_fadeIn(){ 
	var cntr=0,pObj=gObj.style.backgroundColor;
	var r = parseInt(gHex.substring(1,3),16),g = parseInt(gHex.substring(3,5),16), b = parseInt(gHex.substring(5,7),16);
	var rr = parseInt(pObj.substring(1,3),16),gg = parseInt(pObj.substring(3,5),16),bb = parseInt(pObj.substring(5,7),16);
		if (r!=rr){if(rr<r){rr++;}else{rr--;}}else{cntr++;}
		if (g!=gg){if(gg<g){gg++;}else{gg--;}}else{cntr++;}
		if (b!=bb){if(bb<b){bb++;}else{bb--;}}else{cntr++;}
	rr=rr.toString(16);gg=gg.toString(16);bb=bb.toString(16);
	rr=rr.length==1?'0'+rr:rr;gg=gg.length==1?'0'+gg:gg;bb=bb.length==1?'0'+bb:bb;
	gObj.style.backgroundColor='#'+rr.toUpperCase()+gg.toUpperCase()+bb.toUpperCase();
	if (cntr!=3){timer=setTimeout('NN_tr_fadeIn()',1);}
}
  
function NN_tr_reset(obj,hex){ 
	obj.style.backgroundColor=hex;clearTimeout(timer);
}
// #############################################################################