function alterAction(thisForm)
{
	var newLink = document.createElement("a");
	newLink.href = thisForm.action;
  debug("Action was " + newLink.href);
	alterLink(newLink);
	debug("Action is " + newLink);
	thisForm.action = newLink.href;
		return true;
}

function alterLink(newLink) 
{
  var apps    = "apps.nlm.nih.gov";
  var appsqa  = "appsqa.nlm.nih.gov";
  var appsdev = "wwwcfdev.nlm.nih.gov";

  var lhostname = location.hostname.toLowerCase();

	if(lhostname == "www.nlm.nih.gov" || lhostname == apps) {
	  // From production server.
		debug("on production");
		newSearch = "returnHref=" + location.href;
		newLink.hostname = apps;
		setReturnPath(newLink);
		debug("New URL is " + newLink.href);
		return true;
	}
	
//	if(newLink.hostname.search(/apps/i) == -1) {
//	link isn't a ColdFusion link, return right away
//		debug("not processing a non-apps link" + newLink.href);
//		return true;
//	}

  //
	// On development or QA environment. 
	// Try to alter ColdFusion URL to go to appropriate server.
	//
  debug("checking request (hostname = " + newLink.hostname + ", protocol = " + newLink.protocol
				+ ", pathname = " + newLink.pathname 
				+ ") from (hostname = " + lhostname + ", protocol = " + location.protocol
				+ ", pathname = " + location.pathname + ")"
				);

  if(typeof(baseColdFusionHost) != "undefined") {
		debug("cf");
		// Already on a CF server. Use the same base URL
		newLink.host = baseColdFusionHost;
		newLink.pathname = newLink.pathname.replace(/\blocallegends\//, baseColdFusionPath);
		setReturnPath(newLink);
    		
  } else if(lhostname == "wwwqa.nlm.nih.gov") {
		debug("qa");
		// In QA, use QA CF server
		newLink.hostname = appsqa;
		newLink.pathname = newLink.pathname.replace(/\blocallegends\//, "/locallegends/10/");
		
	} else if(lhostname == "wwwdev.nlm.nih.gov") {
		debug("dev");
    // In Development, use CF STAGING
    newLink.hostname = appsdev;
		newLink.pathname = newLink.pathname.replace(/.*\blocallegends\//, "/TS/locallegends/10/STAGING/");
		
  } else if(location.pathname.search("luedtket") > -1) {
		debug("luedtket");
		// User hack to test development against my workarea
		newLink.hostname = appsdev;
		newLink.pathname = 
			  newLink.pathname.replace(/.*\blocallegends\//, "/TS/locallegends/10/WORKAREA/luedtket/");
		setReturnPath(newLink);
		
  } else if(location.pathname.search("wchurch") > -1) {
		debug("wchurch");
		// User hack to test development against my workarea
		newLink.hostname = appsdev;
		newLink.pathname = 
			  newLink.pathname.replace(/.*\blocallegends\//, "/TS/locallegends/10/WORKAREA/wchurch/");
		setReturnPath(newLink);
		
  } else if(lhostname.search(/teamsite/) > -1) {
		debug("teamsite");
		// All the other workareas go to the Development server
 		newLink.hostname = appsdev;
 	  newLink.pathname = newLink.pathname.replace(/.*\blocallegends\//, "/locallegends/10/");
		setReturnPath(newLink);
  }
	
	debug("New URL is " + newLink.href);
	
	return true;
}


function setReturnPath(newLink) 
{
  var newSearch;
  var sresults;
  
	if(location.search) {
		debug("Checking location.search");
		sresults = location.search.match(/\breturnHref=[^&]+/);
	}
	
	if(sresults && sresults.length > 0) {
		// Use the current return HREF
		newSearch = sresults[0];

  } else if(location.host.search("teamsite") > -1) {
		// Determine return HREF from teamsite workarea
		debug("location is teamsite");
		var hresults = location.href.match(/.*\/locallegends\//);
		debug("hresults.length = " + hresults.length);
//		newSearch = "returnHref=" + hresults[0];
		newSearch = "returnHref=" + location.href;
		debug("hresults.value = " + location.href);
		
  } else {
		newSearch = "returnHref=" + location.href;
		debug("hresults.value = " + location.href);
	}
	
	if(newSearch) {
		debug("Adding to query: " + newSearch); 
	  newLink.search = (newLink.search ? (newLink.search + "&") : "?") + newSearch; 
	}
}


function debug(msg) 
{
  // alert(msg);
}


// ********************************************************************
// Macromedia supplied functions:
// ********************************************************************
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_nbGroup(event, grpName) { //v6.0
var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])?args[i+1] : img.MM_up);
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) { img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    nbArr = document[grpName];
    if (nbArr) for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
      nbArr[nbArr.length] = img;
  } }
}


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_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_openBrWindow(URL) 
{ //v2.0
 if (navigator.appVersion.indexOf("Win") >= 0)
 {
  slates = window.open(URL,"video",config="height=530,width=400,left=20,screenx=20,top=20,screeny=20,menubar=yes,toolbar=no,status=yes,location=no,resizable=yes,scrollbars=yes");
 }
 else
 {
  slates = window.open(URL,"video",config="height=530,width=400,left=0,screenx=0,top=20,screeny=0,menubar=yes,toolbar=no,status=yes,location=no,resizable=yes,scrollbars=yes");
 }
 slates.focus();
}

function transcriptWindow(TRANSCRIPT)
{
 var transcript = window.open(TRANSCRIPT,"transcript",config="left=430,screenx=0,top=20,screeny=0,height=530,width=370,menubar=yes,toolbar=no,status=yes,location=no,resizable=yes,scrollbars=yes");
 if (transcript==null) // Detect pop-up blocker
 {
	alert('The transcript pop-up window cannot open.\n\nPlease make sure you allow pop-up windows at this site!');
 }
 else
 {
	transcript.focus();
 }
}

function closeWin()
{
self.close();
}
function openHelp()
{
 help = window.open("/exhibition/locallegends/videoHelp.html","help",config="left=20,screenx=20,top=20,screeny=20,height=500,width=750,menubar=yes,toolbar=no,status=yes,location=no,resizable=yes,scrollbars=yes");
 help.focus();
}

function openSlate(URL)
{
 if (navigator.appVersion.indexOf("Win") >= 0)
 {
  slates = window.open(URL,"video",config="height=530,width=400,left=20,screenx=20,top=20,screeny=20,menubar=yes,toolbar=no,status=yes,location=no,resizable=yes,scrollbars=yes");
 }
 else
 {
  slates = window.open(URL,"video",config="height=530,width=400,left=0,screenx=0,top=20,screeny=0,menubar=yes,toolbar=no,status=yes,location=no,resizable=yes,scrollbars=yes");
 }
 slates.focus();
}

var Stop ="n";
function StopPlay()
{
 if (Stop == "y")
  {
 document.WinMedia.Play();
 document.PlayStop.src="/images/StopButton.jpg";
 if (navigator.appName.substring(0,8) != "Netscape")
 {
  document.images["PlayStop"].src="/images/StopButton_down.jpg";
 }
 Stop = "n";
 }
 else
 {
 document.WinMedia.Pause();
 document.PlayStop.src="/images/PlayButton.jpg";
 if (navigator.appName.substring(0,8) != "Netscape")
 {
 document.images["PlayStop"].src="/images/PlayButton_down.jpg";
 }
 Stop = "y";
 }
}
function Rewind()
{
 document.WinMedia.Stop();
 document.WinMedia.Play();
 document.PlayStop.src="/images/StopButton.jpg";
 Stop = "n";
}

function myPrint() {
    if (window.print) {
        if (confirm("Print Page?")) {
            window.print();
        }
    }
}

function goto_URL(object) {
  window.location.href =
    object.options[object.selectedIndex].value;
  return false;
}