//********************************************************************
//*  BEGIN ADMINISTRATOR DEFINED SETTINGS AND DOCUMENTATION SECTION  *
//********************************************************************
//
// This file contains the scripting code necessary to properly display
// the menutop file. It should be called in each page via the 
// menutop.asp file
//
//
//********************************************************************
//*   END ADMINISTRATOR DEFINED SETTINGS AND DOCUMENTATION SECTION   *
//********************************************************************



////////////////////////////////////////////////
// END HIDE MENUS SCRIPTS
//
// This will hide the nav menus
//
////////////////////////////////////////////////

function hideAll_LeftNav()
{
// This is a placeholder for the function that is in the leftnav
// to avoid an error msg in case the leftnav does not contain it.
}

// ###############################################################
// ###############################################################
// ###############################################################
// THIS FUNCTION MUST BE EDITED TO REMOVE REFERENCES TO THE tmt_showhideAll_old SCRIPT
// ###############################################################
// ###############################################################
// ###############################################################
function tmt_showhideAll(tempVar){
// This is a fix to allow the leftnavs to use the new function name
hideAllMenus(tempVar);
tmt_showhideAll_old(tempVar);
}


function hideAllMenus(c){
// This hides the menu layers specifically
MM_showHideLayers('bb','','hide','sb','','hide','bk','','hide','fb','','hide','cl','','hide','faq','','hide','form','','hide','tool','','hide');

// Hide the menu layers in the LeftNav
// Do not hide the layers again if this function has been called by the leftnav
   if (c != "leftnav")
   {
      hideAll_LeftNav()
   }
} // end hideAllMenus() function

////////////////////////////////////////////////
// END HIDE MENUS SCRIPTS
////////////////////////////////////////////////




////////////////////////////////////////////////
// BEGIN SEARCH BOX ROUTINES
//
// This will handle the results when the user
// clicks in the search box.
//
////////////////////////////////////////////////

function selectSearchbox(formElement)
{
   if (formElement.value.toLowerCase() == "search ams.com" || formElement.value == " ")
   {
      formElement.value = "";
   }
   else 
      formElement.select();
}

function leaveSearchbox(formElement)
{
   if (formElement.value == "" || formElement.value == " ")
   {
      formElement.value = "Search ams.com";
   }
}

////////////////////////////////////////////////
// END SEARCH BOX ROUTINES
////////////////////////////////////////////////




////////////////////////////////////////////////
// BEGIN DREAMWEAVER SUPPORT ROUTINES
//
// These functions are added by Dreamweaver
//
////////////////////////////////////////////////


function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

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_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

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];}
}

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_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;
}

////////////////////////////////////////////////
// END DREAMWEAVER SUPPORT ROUTINES
////////////////////////////////////////////////














// OLD SCRIPT CODE TO REMOVE AFTER SITE UPGRADE PB: 2-2-2004
//#######################################################################################
//#######################################################################################
//#######################################################################################
//#######################################################################################
//#######################################################################################
//#######################################################################################
//#######################################################################################
//#######################################################################################
//#######################################################################################
//#######################################################################################



//********************************************************************
//*  BEGIN ADMINISTRATOR DEFINED SETTINGS AND DOCUMENTATION SECTION  *
//********************************************************************

// The following page variables set where the browser is sent
// after completing the flash check. Set these to be equal
// to the location/page names of the pages.

// namecookie sets the name of the cookie stored on the user's hard drive.
// Can be modified but not necessary. Changing will result in all users 
// flash enabled browsers being forcd to see the flash anim again.
        var namecookie = "AMSflash_10-18-02";
								
// 7. This sets the days for the cookie to expire and should
// be modified to equal a decent period of time. If you want to test the cookie
// you can set the days to ".000347" which will equal about 30 seconds
//
   var expireDays = 30;

// flash/html cookie set the contents for the cookies 
// dependent on the user's browser. Does not need to
// be modified.
        var flashcookie     = "flash";
        var htmlcookie      = "html";
        var resetCookieNow  = "reset";

// Error Message for users with cookies disabled
//        strNoCookies    = "Please enable cookies in your browser to see avoid seeing the flash animation autmatically."

//********************************************************************
//*   END ADMINISTRATOR DEFINED SETTINGS AND DOCUMENTATION SECTION   *
//********************************************************************


// set searchFocus variable to toggle whether or not to focus on the search box
var searchFocus = "false";

// This flag is set to false if the user has seen the flash
var displayflashcookie = "";










// This flag is set to false if the user has seen the flash
//        displayflashcookie    = "true";

// This sets the time for the cookie to expire and should
// be modified to equal a decent period of time.
//
// creates an instance of the Date object (do not modify)
   var expireTime = new Date();
// cookie expires in one week (actually, 7 days)
// 365 days in a year
// 24 hours in a day
// 60 minutes in an hour
// 60 seconds in a minute
// 1000 milliseconds in a second
//
// Example: expireTime.setTime(expireTime.getTime() + 365 * 24 * 60 * 60 * 1000);
//    expireTime.setTime(expireTime.getTime() + 20 * 1000);
   expireTime.setTime(expireTime.getTime() + expireDays * 24 * 60 * 60 * 1000);



// set the new cookie The following is an example, now is the expiration
// time, determined above.
// setCookie(namecookie, "flash" , now);
function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}


// name - name of the desired cookie
// * return string containing value of specified cookie or null if cookie does not exist
function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

function detectflash(){
// This detects for flash and sets the cookie state. It does not handle redirection of the browser.
        noautoinstall = "http://active.macromedia.com/flash2/cabs/swflash.cab#version=4,0,0,0"

        if(navigator.appName == "Microsoft Internet Explorer" && 
                (navigator.appVersion.indexOf("Mac") != -1 || 
                 navigator.appVersion.indexOf("3.1") != -1)){
                        noautoinstall = "true";
        }

        if (navigator.appName == "Microsoft Internet Explorer" && noautoinstall != "true"){
// Here, we set the cookie state to flash.
         setCookie(namecookie, flashcookie , expireTime);
// This flag is set to false if the user has seen the flash
        displayflashcookie    = "true";
         }
        else if(navigator.plugins){
                if(navigator.plugins["Shockwave Flash"]){
// Here, we set the cookie state to flash
         setCookie(namecookie, flashcookie , expireTime);
// This flag is set to false if the user has seen the flash
        displayflashcookie    = "true";
                }
                else if(navigator.plugins["Shockwave Flash 2.0"]){
// Here, we set the cookie state to html
         setCookie(namecookie, htmlcookie , expireTime);
// This flag is set to false if the user has seen the flash
        displayflashcookie    = "false";
                }
                else{
// Here, we set the cookie state to html
        setCookie(namecookie, "reset" , expireTime);
        displayflashcookie    = "false";
                }
        }
}

function noCookies(){
// Display an error message if cookies are disabled on the browser
  //alert(strNoCookies);
		}

// Run resetflash to reset the cookie and redisplay the flash
function resetFlash()
   {
// This will reset the cookie to the replay trigger and refresh the page
   setCookie(namecookie, resetCookieNow);
   displayflashcookie    = "true";
   location.reload();

/* - pending ID tag in flash object
// Rewind Flash
	if (navigator.appName=="Netscape")
	{document.flashMovieName.Rewind()}
	else
	{window.flashMovieName.Rewind()}	

// Play Flash Movie
   if (navigator.appName=="Netscape"||navigator.platform=="MacPPC")
	{document.flashMovieName.Play()}
	else
	{window.flashMovieName.Play()}
*/
   } // end resetFlash() function


/*
This page will detect whether or not the browser has been here before via a stored cookie. 

If yes flash cookie, no flash animation is displayed.

If no cookie, it checks if it is using flash.

If No Flash, no flash animation is displayed.

If Yes Flash, flash animation is displayed.
*/



// This block of code triggers the necessary browser checks.
// All blocks run the check for flash to make sure that the 
// cookie is updated with the latest browser info.
function checkflashCookie()
{
// Check to see if cookies are enabled on this browser
// Set a cookie then check to see if it's contents are stored
setCookie("hasCookie", "yes" , expireTime);
   if(getCookie("hasCookie") != null) 
   {   
      // There is an html cookie so the browser has been here before
      // This will hide the flash home page
      if(getCookie(namecookie) == htmlcookie) {
         displayflashcookie    = "false";
      
      // Check for flash to see if they have updated their browser since they were last here
      detectflash();
      
      // Check to see if the cookie is still set to HMTL after the new check,
      // If it isn't keep going and display Flash in the next routine
         if(getCookie(namecookie) == htmlcookie) {
            displayflashcookie    = "false";
         }
      }

      // There is a flash cookie so the browser has been here before
      // This will hide the flash home page
      if(getCookie(namecookie) == flashcookie) {
         displayflashcookie    = "false";
         return;
      }

      // There is no cookie so this is the browser's first visit OR
      // The cookie has been reset (the flash has been replayed
      // This will Check for flash -> Set the cookie -> Send them to the Intro page
      if(getCookie(namecookie) == null || getCookie(namecookie) == resetCookieNow) {
      // Run Detect flash to store a cookie with their flash state
         detectflash();
      
      // Check the results of detectflash to determine whether or not the flash should be displayed
        if(getCookie(namecookie) == flashcookie) {
         displayflashcookie    = "first";
      	}
        if(getCookie(namecookie) == htmlcookie) {
         displayflashcookie    = "false";
      	}
      }
   }
} // end checkflashCookie() function





// This determines which browser is being used
var ie4 = (document.all && !document.getElementById);
var ie5 = (document.all && document.getElementById);
var ns4 = (document.layers);
var ns6 = (!document.all && document.getElementById);
// flashlayer name to hide/show
var flashlayerName = "flashlayer";
// Stores the boolean for whether or not there is a flash layer
var hasflashlayer;

/*
// ## REMOVED DUE TO CODE BEING IN TOP PORTION
function hideAll_LeftNav()
{
// This is a placeholder for the function that is in the leftnav
// just in case the leftnav does not contain it.
}
*/

function tmt_showhideAll_old(c){
// This hides the menu layers specifically
MM_showHideLayers('AboutAMS','','hide','Industries','','hide','Services','','hide','Knowhow','','hide','Customers','','hide','GlobalAMS','','hide');

// Hide the menu layers in the LeftNav
// Do not hide the layers again if this function has been called by the leftnav
   if (c != "leftnav")
   {
      hideAll_LeftNav()
   }


// This section handles the dynamic display of the table used to cap the top of the body.

   if (ie4) 
   {
      if (document.all['bodyTopTable'] && document.all[flashlayerName])
         {
            hasflashlayer = "true";
            document.all['bodyTopTable'].outerHTML = "";
         }
   } // end ie4

   if (ie5) 
   {
      if (document.getElementById('bodyTopTable') && document.getElementById(flashlayerName))
         {
            hasflashlayer = "true";
            document.getElementById('bodyTopTable').outerHTML = "";
         }
   } // end ie 5

   if (ns6) 
   {
      if (document.getElementById('bodyTopTable') && document.getElementById(flashlayerName))
         {
            hasflashlayer = "true";
            document.getElementById('bodyTopTableNS').innerHTML = "";
         }
   } // end netscape 6

   if (ns4) 
   {

// To work with Netscape, Flash document needs an empty layer with flashlayer in it.
/*
<layer id="flashlayerNS"><layer>
*/
      if (document.layers[flashlayerName+"NS"])
      {
         hasflashlayer = "true";
         x = document.layers['bodyTopTableNS'];
         tempNSText = "";
         x.document.open();
         x.document.write(tempNSText);
         x.document.close();
      }

   } // end netscape

if (!(ie4) && !(ie5) && !(ns4) && !(ns6)) 
// Cannot determine broswer, so try to hide the layer anyways.
   {
      if (document.getElementById('bodyTopTableNS') && document.getElementById(flashlayerName))
         {
            hasflashlayer = "true";
            document.getElementById('bodyTopTableNS').outerHTML = "";
         }
   } // end no broswer found

 



   if (hasflashlayer == "true")
// Show or hide the flash layer depending on earlier parameters
   {

//         alert ('displayflashcookie = "' + displayflashcookie + '"');
   // Check if they've seen the flash already.
      if (displayflashcookie == "")
      {
         checkflashCookie();
      }
   
      if (c == "hideflashlayer" || displayflashcookie == "false")
         {MM_showHideLayers(flashlayerName,'','hide');}
      else 
         {MM_showHideLayers(flashlayerName,'','show');}
   }
} // end tmt_showhideAll() function

