// JavaScript Document
// global variables for timeout and for current menu
var t=false,current;

function SetupMenu() {
   items=document.getElementsByTagName("li");
   for (i=0; i<items.length; i++) {
      if (items[i].className != "appTabs") continue;
      //set up event handlers
      thelink=findChild(items[i],"A");
      thelink.onmouseover=ShowMenu;
      thelink.onmouseout=StartTimer;
      //is there a submenu?
      if (ul=findChild(items[i],"UL")) {
         ul.style.display="none";
		 ul.onmouseover=ResetTimer;
		 ul.onmouseout=StartTimer;
         //for (j=0; j<ul.childNodes.length; j++) {
            //ul.childNodes[j].onmouseover=ResetTimer;
            //ul.childNodes[j].onmouseout=StartTimer;
         //}
      }
   }
   if (startTab) ShowStartMenu(startTab);
   if (startSubLink) HighlightSubLink(startSubLink);
}

// find the first child object of a particular type
function findChild(obj,tag) {
   cn = obj.childNodes;
   for (k=0; k<cn.length; k++) {
     if (cn[k].nodeName==tag) return cn[k];
   }
   return false;
}

function ShowStartMenu(theMenu) {
	theObj=document.getElementById(theMenu);
	theObj.className="activeTab";
	ul = findChild(theObj,"UL");
	if (!ul) return;
	ul.style.display="block";
   	ul.className="activeSub";
}

function HighlightSubLink(whatSubLink) {
	wSL=document.getElementById(whatSubLink);
	wSL.style.color="#002D4B";
	wSL.style.fontWeight="bold";
}

function HideStartMenu(theMenu) {
	theObj=document.getElementById(theMenu);
	theObj.className="nonActiveTab";
	ul = findChild(theObj,"UL");
	if (!ul) return;
	ul.style.display="none";
}

function ShowMenu(e) {
   if (!e) var e = window.event;
   // which link was the mouse over?
   thislink = (e.target) ? e.target: e.srcElement;
   ResetTimer();
   // hide the previous menu, if any
   if (current) HideMenu(current);
   if (startTab) HideStartMenu(startTab);
   // we want the LI, not the link
   thislink = thislink.parentNode;
   current=thislink;
   thislink.className="activeTab";
   // find the submenu, if any
   ul = findChild(thislink,"UL");
   if (!ul) return;
   ul.style.display="block";
   ul.className="activeSub";
	
}

function HideMenu(thelink) {
	if (thelink) {
	thelink.className="nonActiveTab";
   // find the submenu, if any
   ul = findChild(thelink,"UL");
   if (!ul) return;
   ul.style.display="none";
	}
}

function ResetTimer() {
   if (t) window.clearTimeout(t);
}

function StartTimer() {
   t = window.setTimeout("HideMenu(current),ShowStartMenu(startTab)",500);
}

// Set up the menu when the page loads
//window.onload=SetupMenu;

function UserErrorAlert2(theHeading, theErrorMessage, friendly) {
	$('#Error_Message_Box h3 a').click ( function(ev) {
		ev.preventDefault();
		$('#Error_Message_Box').hide("slow");						   
	});	
	
	if(friendly == true) {
		$("#Error_Message_Box p").addClass('Friendly');
	}
	
	$('#Error_Message_Box h1').html(theHeading);
	$('#Error_Message_Box p').html(theErrorMessage);
	$('#Error_Message_Box').show("slow");
}

//add matt friendly could still use friendly confirm in inbox
function UserErrorAlert(theHeading, theErrorMessage, friendly, mattfriendly) {
	$('#Error_Message_Box h3 a').click ( function(ev) {
		ev.preventDefault();
		$('#Error_Message_Box').hide("slow");						   
	});	
	
	if(friendly == true) {
		$("#Error_Message_Box").addClass('Friendly');
	}
	if(mattfriendly == true) {
		$("#Error_Message_Box").addClass('MattFriendly');	
	}
	$('#Error_Message_Box h1').html(theHeading);
	$('#Error_Message_Box p').html(theErrorMessage);
	$('#Error_Message_Box').modal({
			closeHTML:"<a href='#' title='Close' class='modal-close'>x</a>",
			position: ["20%",],
			overlayId:'UserYesNo-overlay',
			close:true,
			onShow: function (dialog) {
					$('#Error_Message_Box h3 a').click ( function(ev) {
						ev.preventDefault();
						$.modal.close();						   
					});
					
					}	
	});
}


function UserYesNo(message, callback) {
	$('#UserYesNo').modal({
		closeHTML:"<a href='#' title='Close' class='modal-close'>x</a>",
		position: ["20%",],
		overlayId:'UserYesNo-overlay',
		containerId:'UserYesNo-container', 
		close:true,
		minHeight:[150],
		onShow: function (dialog) {
			$('.uyn_message', dialog.data[0]).append(message);

			// if the user clicks "yes"
			$('.yes', dialog.data[0]).click(function () {
				// call the callback
				if ($.isFunction(callback)) {
					callback.apply();
				}
				// close the dialog
				$.modal.close();
				//return true;
			});
		}
	});
} 
//IE has no indexOf
if(!Array.indexOf){
	    Array.prototype.indexOf = function(obj){
	        for(var i=0; i<this.length; i++){
	            if(this[i]==obj){
	                return i;
	            }
	        }
	        return -1;
	    }
	}



