//************************************************************************
//FileName:	egflash.js
//Description:	Provides functionality to display Flash animations
//              in a popup window and pass parameters to it.
//
//************************************************************************

function IsNS6orGreater()
//Return whether the browser is Netscape 6 or greater
{
var NS6gt = false;

//Check to see if using Netscape 6 or greater
if (navigator.appName == 'Netscape')
{
	if(parseFloat(navigator.appVersion) >= 5)
		NS6gt = true;
}

return NS6gt;
}

function leftTrim(str)
// PURPOSE: Remove leading blanks from our string.
// IN: str - the string we want to leftTrim
// RETVAL: An leftTrimmed string!

{
  var whitespace = new String(" \t\n\r");
  var s = new String(str);

  if (whitespace.indexOf(s.charAt(0)) != -1) 
  {
    // We have a string with leading blank(s)...

    var j=0, i = s.length;

    // Iterate from the far left of string until we
    // don't have any more whitespace...
    while (j < i && whitespace.indexOf(s.charAt(j)) != -1) j++;


    // Get the substring from the first non-whitespace
    // character to the end of the string...
    s = s.substring(j, i);
  }

  return s;
}


function rightTrim(str)
// PURPOSE: Remove trailing blanks from our string.
// IN: str - the string we want to rightTrim
// RETVAL: An rightTrimmed string!

{
  // We don't want to trip JUST spaces, but also tabs,
  // line feeds, etc.  Add anything else you want to
  // "trim" here in Whitespace
  var whitespace = new String(" \t\n\r");

  var s = new String(str);

  if (whitespace.indexOf(s.charAt(s.length-1)) != -1) 
  {
    // We have a string with trailing blank(s)...
    var i = s.length - 1;       // Get length of string

    // Iterate from the far right of string until we
    // don't have any more whitespace...
    while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
      i--;

    // Get the substring from the front of the string to
    // where the last non-whitespace character is...
    s = s.substring(0, i+1);
  }

  return s;
}



function trim(str)
// PURPOSE: Remove trailing and leading blanks from our string.
// IN: str - the string we want to trim
// RETVAL: A trimmed string!
{
  return rightTrim(leftTrim(str));
}


function inStr(iStart, strSearch, charSearchFor)
// Returns the first location a substring (SearchForStr)
// was found in the string str.  (If the character is not
// found, -1 is returned.)
                          
{
	
	for (i=iStart; i < String(strSearch).length+1; i++)
	{
	    if (charSearchFor == mid(strSearch, i, String(charSearchFor).length))
	    {
			return i;
	    }
	}
	return 0;
}


function mid(str, start, len)
// IN: str - the string we are LEFTing
//     start - our string's starting position (0 based!!)
//     len - how many characters from start we want to get
//
// returns the substring from start to start+len

{
 
  var sRetVal = "";
   
  if (!len || len==0) len=String(str).length;
  
  // Make sure start and len are within proper bounds
  if (start < 0 || len < 0) return "";

  var iEnd;
  var iLen = String(str).length;
  
  if (start + len > iLen)
    iEnd = iLen;
  else
    iEnd = start + len-1;
   
  sRetVal = String(str).substring(start-1,iEnd);
  return sRetVal;
}

function IsNumeric(sText)
{
  var ValidChars = "0123456789.";
  var IsNumber=true;
  var Char;
 
  for (i = 0; i < sText.length && IsNumber == true; i++) 
  { 
    Char = sText.charAt(i); 
    if (ValidChars.indexOf(Char) == -1) 
    {
      IsNumber = false;
    }
  }
  return IsNumber;
}



function writeBaseRef()
{
  var sPath = getBaseRef();
  document.write('<base href="'+sPath+'" />');
}

function getBaseRef()
{
  var index = sGetAppIndex();
  var sPath = BuildFullPath(as_FlashFile[index]);

  if ((sPath.lastIndexOf(":\\")>0) && !(sPath.toUpperCase().lastIndexOf("file:")>0))
  {
    sPath = "file:///"+sPath;
  }
    
  return sPath.substr(0, sPath.lastIndexOf("/")+1);
}

function sGetQueryString()
{
  var sQueryString = ""+document.location;
  sQueryString = unescape(sQueryString);
  var iQueryPos = inStr(1, sQueryString, '?');
  sQueryString = sQueryString.substring(iQueryPos, sQueryString.length);
  return sQueryString;	
}


function writeFlash(sFilename)
{

  sFilename = trim(sFilename.substr(sFilename.lastIndexOf("/")+1, sFilename.length));
  var sParams = sGetQueryString();
  
  if (!sHolder)
  {
    var sHolder = 'slot';
  }
 
  var sNewString = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"' 
                   + ' codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0"'
                   + ' id="oFlash" width="100%" height="100%" align="middle">'
                   + '<param name="allowScriptAccess" value="always" />'				  
                   + '<param name="FlashVars" value="'+sParams+'" />'
                   + '<param name="movie" value="'+sFilename+'" />'
                   + '<param name="quality" value="high" />'
                   + '<embed src="'+sFilename+'" FlashVars="'+sParams+'" quality="high"' 
                   + ' width="100%" height="100%" menu="false" swLiveConnect=true id="oFlash" name="oFlash" align="middle"'
                   + ' allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'
                   + '</object>';

    if (IsNS6orGreater())
    {
      oLayer = window.document.getElementById(sHolder);
    
      if (oLayer)
      {
        sNewString = '<embed src="'+sFilename +'" FlashVars="'+sParams+'" quality="high"'
                 + ' width="100%" height="100%" menu="false" swLiveConnect=true id="oFlash" name="oFlash" align="middle"'
                 + ' allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
    
        oLayer.innerHTML=sNewString;
        document.oFlash.play();
      }
    } 
    else if (document.all)
    {
      document.all(sHolder).innerHTML=sNewString;
    }
    else
    {
      window.document.getElementById(sHolder).innerHTML=sNewString;
      if ((document.oFlash) && (document.oFlash.play))
      {
        document.oFlash.play();
      }
    }
}
