
function stopRKey(evt) { 
  var evt = (evt) ? evt : ((event) ? event : null); 
  var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null); 
  if ((evt.keyCode == 13) && (node.type=="text"))  {return false;} 
} 

document.onkeypress = stopRKey; 

function noenter() { return stopRKey; }

var newwindow = '';

 

//hides email links from bots and spammers
function eMailLink(a, b, c, linktext, support) 
{
  var d = linktext;
  var l = "&#109;&#97;&#"+"105;&#108;&#116;&#111;"+"&#58;"+a+"&"+"#"+"6"+(6-2)+";";
  if (b) l=l+b;
  else l=l+"nafa&#46;ca";
  l=l+"?body=From page: "+window.location.href+"&#13;";
  if (c) l=l+"&subject="+c;

  //if linktext = href then the code is in an anchor tag and need to change location
  if (d=="href") { 
   window.location.replace(l);
  }
  else {
   document.write("<a href=\""+l+"\">");
   if (d) document.write(d); 
   else document.write("email");
   document.write ("<\/a>");
   }
}



function debug(t) { if (helpwin) writewin (t); }


function popitup(popurl,popname)
{	if (!newwindow.closed && newwindow.location)
	{  newwindow.location.href = url;
	}
	else
	{  newwindow=window.open(popurl,popname,'height=450, width=780, screenX=10, screeny=6, status=yes, resizable=yes, moveable=yes');
	   if (!newwindow.opener) newwindow.opener = self;
	}
	//if (window.focus) {newwindow.focus()}
	//return false;
}

//---------- 
var IE = (document.all);
var ua = navigator.userAgent.toLowerCase();
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);
var is_nav  = (ua.indexOf("mozilla")!=-1) && (ua.indexOf("compatible") == -1);
var is_nav4 = (is_nav && (is_major < 5));
if (is_nav) { delayms = 10; };
var is_safari = (document.all)

//active menu based on directory in the url
var active_menu;

//---------- animation timer settings -------------------------------
// delay ms for each step in animation (lower is faster)
var delayms = 10; //delay for each step
var delayStartMs = 600; //pause before starting to open on mouseover
var delayCloseMs = 600; //ms wait until close on mouseout
var hMax=22; var wMax=740; var wUnit="px"; var hUnit="px"; 
var wInc=wMax/hMax; 
var hInc=1; 
var xInc=wInc/2+1;

var xPos=(wMax/2); 

//array for background color transition on open and close
var bg = new Array ("#005595", "#005595", "#1d5d9a", "#1d5d9a", "#30659f", "#3e6da4",
                    "#4c76aa", "#4c76aa", "#597fb0", "#597fb0", "#6589b6", "#6589b6", 
			  "#7094be", "#7094be", "#7ca0c4", "#7ca0c4", "#88abcb", "#88abcb", 
			  "#96b9d3", "#a2c6db", "#b1d5e4", "#bfe6ee", "#bfe6ee", "#bfe6ee", 
			  "#bfe6ee", "#bfe6ee", "#bfe6ee", "#bfe6ee", "#bfe6ee", "#bfe6ee");
var bg_x = 0;


//---------- animation timers variables
//amenu is the animated menu 
//variables for size/position of submenu and amount to make it grow each step
var h, w;
var myWidth, myHeight, xOffset;

var amenu=""; var abut="";
var atimerID = null; var atimerRunning = false;

//---------- routines to set timeouts animation timers
function aTimerOpen() { atimerRunning = true; atimerID = setTimeout ("AnimateOpen();", delayms); }
function aTimerClose() { atimerRunning = true; atimerID = setTimeout ("AnimateClose();", 2); }
function aTurnOffTimer() { if (atimerRunning) { clearTimeout(atimerID); atimerRunning=false; } }


//---------- animation timers - routines ---------------------------------

function HideMenus() {//remove all but active menu
  if (amenu!=null && amenu!=active_menu) 
    { MM_showHideLayers(amenu,"","hide"); 
      abut.className = ""; //reset style of mouseover button
    }
  amenu=""; //no current animated menu
}

function AnimateClose() { 
  aTurnOffTimer();
  var obj;
  h=h-hInc; w=w-wInc; xPos=xPos+xInc;
  if (w<0) w=0; if (h<0) h=0; if (xPos>350) xPos=350; 
  if (amenu!=null && amenu!=active_menu) 
  { if ((obj=MM_findObj(amenu))!=null) { 
    obj.style.width=w+wUnit;
    obj.style.height=h+hUnit;
    obj.style.left=xPos+"px";
    bg_x=bg_x-1;
    obj.style.background = bg[bg_x];
  }
  if(h==0) { 
	HideMenus(); 
  }
  else aTimerClose(); 
  }
}

function AnimateOpen() { 
  //do not animate for IE on the mac.
  //if ((ua.indexOf("MSIE")=0) || (ua.indexOf("Macintosh")=0)) 
  var obj; 
  h=h+hInc; w=w+wInc; xPos=Math.round(xPos-xInc);
  if (w>wMax) w=wMax;
  if (xPos<0) xPos=0; 
  if (h>hMax) h=hMax; 
  if ((obj=MM_findObj(amenu))!=null) { 
    if (h==hInc) { MM_showHideLayers(amenu,"","show");
    obj.className = "submenuHover";
    }
    obj.style.height=h+hUnit; 
    obj.style.width=w+wUnit; 
    abut.style.backgroundColor = bg[bg_x];
    obj.style.backgroundColor = bg[bg_x++];
    obj.style.left=xPos+"px";
    if(h>hMax/2) abut.className = "mbhover"; //after half way open set the menu button to the hover style
  }
  if(h<hMax) aTimerOpen(); //if not at the horizontal max then make it grow more
  else abut.style.backgroundColor = ""; 
}

var p_m, p_but, p_mouseX, showTimerID


//run on mouseover of primary menu buttons to animate the showing of the submenu
//problem that when a menu item is hovered over and mouse touches another main menu item the submenu dissapears even if the mouse moves into the submenu
//mouseover on the submenu runs turnofftimer which should keep the current menu and stop the delay timer

function ShowMenu(newMenu,newBut) { //debug('<li>show menu: '+newMenu);
  //added delay to ensure hover over the button before showing the menu 
  //on mouseout the timer is stopped and the the menu does not appear
  if (is_nav4 == true) return (false); 
  p_m = newMenu; p_but = newBut; //alert(newMenu );
  if(IE) { p_mouseX = (event.clientX-20); } //record mouse position for menu positioning
  showTimerID = setTimeout ("ShowMenuNow();", delayStartMs);
}


function ShowMenuNow() {//on mouseover after the delay to start the animation process
  if (is_nav4 == true) return (false); 
  TurnOffTimer(); aTurnOffTimer();
  //active_menu is current one for the URL
  //amenu is the current animated menu 
  //p_m is the menu being moused-over
  if (active_menu==p_m) { AnimateClose(); } //mouse is over the the current menu item for the url - hide the hovering menu
  else 
    if (p_m==amenu) { //mouse is still over the menu being openned - continue the animation 
      if (h<hMax) { AnimateOpen(); }
    } 
    else { //mouse is over a new menu - reset the animation process
      HideMenus();  
      //set active menu and reset size to 0
      abut=p_but; amenu=p_m; h=0; w=0; bg_x=0; xPos=wMax/2;
      if(IE&&xOffset&&p_mouseX) { //alert (p_mouseX); 
	xPos = ((p_mouseX + document.body.scrollLeft) - xOffset);
	xInc = (xPos/(hMax/hInc)+2);
	}
      //start animation of menu
      AnimateOpen();	
  }
}

function ResetMenus() {//on page load
  window.status = 'Welcome to NAFA';
  //if (is_nav == true) return (false);  
  window.status = active_menu;
//  if (active_menu) setMenuItem (); 
  SetHeight();   
  return (true);
}

//highlight submenu item which matches current url to look like a tab
//optional parameter is the url in cases where there are third level menus on the page (wild fur shipping)
function setMenuItem(url) {
  i = active_menu; //alert(i); 
  var mhref;
  if (url) { u=url; }
  else {
    if (obj=MM_findObj('pagemenu')) {
        if (subm = obj.src) u = subm.substr(1,subm.lastIndexOf('/')+1);
	//alert (obj.src);
    }
    else { u = document.location.search; u=u.substr(1); //current page url from address bar
	if (u.indexOf("page=") > 0) u = u.substr(u.indexOf("page=")+5);
	if (u.indexOf("&") > 0) u = u.substr(1,u.indexOf("&")-1);
    } //alert(u);
  } 
  if (obj=MM_findObj(i)) {
      for (l in obj.childNodes )
        if (obj.childNodes[l].href) { 
	  mhref=obj.childNodes[l].href; //alert(u+" | "+mhref);
          if (mhref.indexOf(u)>0) {
	        obj.childNodes[l].className = 'submenutab';
	        obj.childNodes[l].href = '#';
		return(true);
          }
        }
    }
   //else { window.status = "Cannot find "+i }
}

//menu display timers
var closeTimerID = null;
var closeTimerRunning = false;

function TurnOnTimer(t) { //on mouseout of any menu item - delay until close
  if(showTimerID) clearTimeout(showTimerID);
  if(!closeTimerRunning){ //only create a new timer if one is not already present - multiple timers caused problems
	closeTimerRunning=true; 
	closeTimerID=setTimeout("xPos=0;AnimateClose();",(t) ? t : delayCloseMs);
  }
}

function TurnOffTimer() { if(showTimerID) clearTimeout(showTimerID);
  if (closeTimerRunning) { clearTimeout(closeTimerID); closeTimerRunning = false; }
} 


function SetHeight()
{ if (is_nav4 == true) return (false);

//stop resizing the page
return (false);

  var obj;
  var px = document.layers || window.opera ? "" : "px";
  if ((obj=MM_findObj("textbox"))!=null) {
 
  //Non-IE
  if( typeof( window.innerWidth ) == "number" ) {
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } 
  //IE 6+ in "standards compliant mode"
  //avoid setting scrollbar for firefox
  else if( document.documentElement &&
      ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;

    obj.style.scrollbarArrowColor = '#963'; 
    obj.style.scrollbarBaseColor = '#d6cdbc'; 
    obj.style.scrollbarShadowColor = '#d6cdbc'; 
    obj.style.scrollbarHighlightColor = '#d6cdbc';
    obj.style.scrollbar3dlightColor = '#fff'; 
    obj.style.scrollbar3ddarkColor = '#fff'; 
    obj.style.scrollbarDarkShadowColor = '#fff';
    obj.style.scrollbarTrackColor = '#fff'; 
  }
  //IE 4 compatible
  else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
    IE = 1;
  }

  if (myHeight==null) myHeight=350;
     //adjust for safari
     if (ua.indexOf("Safari")>0) myHeight=myHeight-40; 
     obj.style.height = myHeight-122 + px;
     if (IE&&myWidth>0) xOffset = (myWidth-750)/2;

  }

}

//not in use right now
//changes background image on top menu based on the section
function setBackgroundImage (gif) {
  var id, imageURL;
  id="mainmenu";
  imageURL = "/images/sliced/images/" + gif + ".gif"
  if (document.layers)
    document[id].background.src = imageURL == 'none' ? null : imageURL;
  else if (document.all)
    document.all[id].style.backgroundImage = imageURL == 'none' ? 'none' 
: 'url(' + imageURL + ')';
  else if (document.getElementById)
    document.getElementById(id).style.backgroundImage = imageURL == 
'none' ? 'none' : 'url(' + imageURL + ')';
}


//window.onresize = ResetMenus();

