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;
}
/* MM_preloadImages() - to be used to preload mouseover images for the top navigation */
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];}}
}
/* MM_findObj(n, d) - used by the swap function utilities */
function MM_findObj(n, d) { //v3.0
  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); return x;
}
/* MM_swapImage() - to be used to load hover images in menu */
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];}
}

/* LoadVarSizedWin - creates a window with specified height and width. If there is an existing window opened using this function, the new URL called will be opened on the same window */	
function LoadVarSizedWin(vURL, vwidth, vheight){
	try {
		var win_newwin = null;		
		if (!win_newwin) {
			win_newwin = window.open(vURL, 'win_newwin', 'width=' + vwidth+ ',height=' + vheight+ ',status=yes,resizable=yes,scrollbars=yes');
		}
		win_newwin.focus();	
    } catch (e) {}
}

/* LoadVarSizedWinNew - creates a window with specified height and width. If there is an existing window opened using this function, the new URL called will be opened on a new window */	
function LoadVarSizedWinNew(vURL, vwin_newwin, vwidth, vheight){
	try {
		vwin_newwin = window.open(vURL, vwin_newwin, 'width=' + vwidth+ ',height=' + vheight+ ',status=yes,resizable=yes,scrollbars=yes,toolbar=no,location=no,menubar=no');
		vwin_newwin.focus();		
	} catch (e) {}
}	

/* LoadNewVarSizedWin - creates a NEW window with specified height and width with tool, url and menu bars */
function LoadNewVarSizedWin(vURL, vwindowname, vwidth, vheight){
	try {
		vwindowname = window.open(vURL, vwindowname, 'width=' + vwidth+ ',height=' + vheight+ ',status=yes,resizable=yes,scrollbars=yes,toolbar=yes,location=yes,menubar=yes');
		vwindowname.focus();		
	} catch (e) {}
}			

function LoadSupportWin(call_type){
	try {
		var win_support; 
		win_support = window.open('https://'+ document.ugt_server_var + "/"+ call_type, 'win_support', 'height=450,width=662,status=no,resizable=yes,scrollbars=yes');
		win_support.focus();
	} catch (e) {}
}		

function LoadModalWindow(url, vheight, vwidth){
	try {
		var windowTop = new Array();
		windowTop.opener = top;					
		window.showModalDialog(url, windowTop, 'dialogHeight:' + vheight+ 'px;dialogWidth:' + vwidth+ 'px;center:yes; help:no; status:no; resizable:no;');
	} catch (e) {}
}		

function getElementPosition(elemID) {
	
   var offsetTrail = document.getElementById(elemID);
   var offsetLeft = 0;
   var offsetTop = 0;
   
   // loop to the top    
   while (offsetTrail) {
       offsetLeft += offsetTrail.offsetLeft;
       offsetTop += offsetTrail.offsetTop;
       offsetTrail = offsetTrail.offsetParent;
   }
   
   if (navigator.userAgent.indexOf("Mac") != -1 && 
       typeof document.body.leftMargin != "undefined") {
       offsetLeft += document.body.leftMargin;
       offsetTop += document.body.topMargin;
   }
   return {left:offsetLeft, top:offsetTop};
}

////////////////////////////////////////////////////////////////////////////////
// Application functions
////////////////////////////////////////////////////////////////////////////////

function hidePopupAnswer(divID) {
	
	objDiv = document.getElementById(divID); 	
	objDiv.style.display = "none"; 	
	var shadow = document.getElementById('popupshadow');
	var pointer = document.getElementById('pointer');
	var pointerImg = document.getElementById('pointerImg');
	var pointerShadow = document.getElementById('pointerShadow');
	
	shadow.style.display = "none";
	pointer.style.display = "none";
	pointerShadow.style.display = "none";
	
}

function showPopupAnswer(divID, hrefID, setWidth){
	// close all other answers popups 
	var collDiv = document.getElementsByTagName("DIV"); 
	var strID = new String(); 
	
	for (i=0; i < collDiv.length; i++) {
		
		if (typeof collDiv[i].id != "undefined") {
			strID = collDiv[i].id; 
		}
		else {
			strID = ""; 
		}
		
		if ((strID.indexOf("ans") != -1) && (typeof collDiv[i].style.display != "undefined") && (collDiv[i].style.display == "block")) {
			collDiv[i].style.display = "none";
		} 
	}
	
	//get elements.
	var shadow = document.getElementById('popupshadow');
	var pointer = document.getElementById('pointer');
	var pointerImg = document.getElementById('pointerImg');
	var pointerShadow = document.getElementById('pointerShadow');

	thelink = document.getElementById(hrefID);
	popupBox = document.getElementById(divID); 
	
	//width is an optional argument
	if(setWidth){
	 popupBox.style.width = setWidth+'px';
	}
	else {
	 popupBox.style.width = '210px';
	}
	
	//adjust shadow location for Firefox 
	var IE = document.all?true:false;
	var fireFoxAdj = 0;
	if(!IE){ fireFoxAdj = 5; }
	
	if(popupBox.style.display == "block"){
		popupBox.style.display = "none";
		shadow.style.display = "none";
		pointer.style.display = "none";
		pointerShadow.style.display = "none";
	}
	else {
	//first size the shadow
		popupBox.style.display = "block";
		shadow.style.display = "block";
		pointer.style.display = "block";
		pointerShadow.style.display = "block";
	
		var popup_wdth = popupBox.clientWidth;
		var popup_ht = popupBox.clientHeight;
		
		shadow.style.width = eval(popup_wdth + 14)+'px';
		shadow.style.height = eval(popup_ht + 14)+'px';

		var linkPos = new Object(); 
		linkPos = getElementPosition(hrefID);
		
		//var link_tp = thelink.offsetTop;
		var link_tp = linkPos.top;
		//var link_lft = thelink.offsetLeft;
		var link_lft = linkPos.left;
		var link_wdth = thelink.offsetWidth;
		
		var pointer_wdth = pointerImg.width;
		//setting the left edge of the popup
		var setLeft = link_lft + link_wdth + pointer_wdth - 9;

		var body_wdth = document.body.clientWidth;
		var body_ht = document.body.clientHeight;
		var pointing = 'left'; //be default the popup is to the right of the link, pointing left
		var pointVert = 'up';  //by defautl the popup arrow is pointing up
		
		//switch popup to the left if link is too close to right edge of page 
		//OR if it is too close to the left		
		//originally body_wdth -- changed to 500 to force displaying to the left
		if((500 < (setLeft + popup_wdth + pointer_wdth + 4)) && (link_lft > 280)){
			setLeft = link_lft - popup_wdth - pointer_wdth - 10;
			pointing = 'right';
		} else { pointing = 'left'};
		var halfHeight = popup_ht/2;
		var halfHeight = Math.round(halfHeight);
		
		var setTop = link_tp - halfHeight;
		if ((setTop + popup_ht) > body_ht){
				setTop = link_tp - popup_ht + 10;//keep popup bottom above the bottom of the frame
				pointVert = 'down'; //since we are at the bottom edge of the frame, point the arrow down to the link
		}
		if (setTop < 105) setTop = 105; //keep popup top below the top of the frame		
		
		var setLeftShad = setLeft-7;
		var setTopShad = setTop-7;
		popupBox.style.left = setLeft+'px';
		popupBox.style.top = setTop+'px';
		shadow.style.left = setLeftShad+fireFoxAdj+'px';
		shadow.style.top = setTopShad + fireFoxAdj+'px';
		
		//position pointer 
		var pointer_top = link_tp+7;
		var pointer_left;
		var pointer_shadow_left_offset = -7;
		var pointer_shadow_top_offset = -7;;
		if (pointing == 'right'){
			if(pointVert == 'up'){
				pointer_left = setLeft + popup_wdth -1; //left edge of popup + width of popup -1;
				pointerImg.src = "images/popup/popup_rt_wedge_up_white.gif";
				pointerShadow.src = "images/popup/popup_rt_wedge_up_black.gif";
				pointer_shadow_left_offset = -5;
				pointer_shadow_top_offset = -5;
			}
			else {//right down
				pointer_left = setLeft + popup_wdth -1; //left edge of popup + width of popup -1;
				pointerImg.src = "images/popup/popup_rt_wedge_down_white.gif";
				pointerShadow.src = "images/popup/popup_rt_wedge_down_black.gif";
				pointer_top = link_tp - pointerImg.height;
				pointer_shadow_left_offset = -11;
				pointer_shadow_top_offset = -26;
			}
		}
		else { //pointing left
			if(pointVert == 'up'){
				pointer_left = setLeft - pointer_wdth + 1; //left edge of poput - width of image + 1
				pointerImg.src = "images/popup/popup_lft_wedge_up_white.gif";
				pointerShadow.src = "images/popup/popup_lft_wedge_up_black.gif";
				pointer_shadow_left_offset = -6;
				pointer_shadow_top_offset = -5;
			}
			else { //left down
				pointer_left = setLeft - pointer_wdth + 1; //left edge of poput - width of image + 1
				pointerImg.src = "images/popup/popup_lft_wedge_down_white.gif";
				pointerShadow.src = "images/popup/popup_lft_wedge_down_black.gif";
				pointer_top = link_tp - pointerImg.height;
				pointer_shadow_left_offset = -15;
				pointer_shadow_top_offset = -25;
			}
		}
		pointer.style.left = pointer_left+'px';
		pointer.style.top = pointer_top+'px';		
		pointerShadow.style.left = eval(pointer_left + pointer_shadow_left_offset + fireFoxAdj)+'px';
		pointerShadow.style.top = eval(pointer_top + pointer_shadow_top_offset + fireFoxAdj)+'px';
		pointerShadow.style.width = eval(pointerImg.width + 16) + 'px';
		pointerShadow.style.height = eval(pointerImg.height + 28) + 'px';
	}
}