// Flash Version Detector  v1.0
// Ken Haynes

// This is one method of detecting flash in a Netscape or other gecko based browser
function getFlashPluginVersion() 
{ 
  var version = { 
        major: -1, 
        minor: -1, 
        installed: false,
        scriptable: false
      };

  // first check to see if flash is even installed.
  if(!navigator.mimeTypes["application/x-shockwave-flash"])
	return version;
  
  // now check to see if it's enabled.
  var plugin = navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin; 

  if (!plugin) // the mimeTypes array does not exist or not enabled
    return version;

  version.installed = true;

  var description = plugin.description; 
  
  // use RegExp to obtain the relevant version strings 
  // obtain an array of size 2 with version information
  
  var versionArray = description.match(/[\d.]+/g); 
  
  if (!versionArray)
  {
    return version;
  }

  if (versionArray.length >= 1 && !isNaN(versionArray[0]))
  {
    version.major = parseFloat(versionArray[0]);
  }

  if (versionArray.length >= 2 && !isNaN(versionArray[1]))
  {
    version.minor = parseFloat(versionArray[1]);
  }
    
  if (version.major < 6 || navigator.product != 'Gecko')
  {
    return version;
  }

  if (version.major > 6 || version.minor >= 47)
  {
    version.scriptable = true;
  }

  return version;
} // end getFlashPluginVersion



function identifyFlash() 
{ 

  // This is called for Netscape or Gecko based browsers
  var NSflashversion = getFlashPluginVersion();

  if (!NSflashversion.installed)
    return -1;
  else
	  return NSflashversion.major;
  
}// end identify flash



function getEbusAgtID(LocaleID)
{

	switch(LocaleID.toLowerCase())
	{
	case 'en':
		return '13453274';
	case 'es-cr':
		return '13479025';
	case 'ru-ru':
		return '13453274';
	case 'he-il':
		return '13839072';
	case 'ar-jo':
		return '13839064';	
	case 'ko-kr':
		return '14013618';
	default:
		return '13453274';
	}
}


/*
Purpose:To generate object tag for SR Flash tool
Input:	Ebus Agent ID (CPM), 
		student Class Account ID, 
		Project Name, 
		Locale ID (in this case, should be the MCMS locale channel, e.g "en")
History:
Name		Date			Comments
------------------------------------
May Tee		03/02/05		Created to support MCMS
*/
function SRInstallTool(ClassAcctID, ProjectName, LocaleID)
{

	var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
	var EbusAgtID = getEbusAgtID(LocaleID);
	
	if (InternetExplorer)
	{
		document.write('<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '); 
		document.write('codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" '); 
		document.write('WIDTH="740" HEIGHT="600" '); 
		document.write('ID="SeeingReason" ALIGN="" VIEWASTEXT>'); 
		document.write('<PARAM NAME=movie VALUE="/FlashTools/SeeingReason/Components/SeeingReason.swf">'); 
		document.write('<PARAM NAME=FlashVars value="txtAssignmentID=&txtAgentID=' + EbusAgtID);
		document.write('&txtImagePath=/common/'+ LocaleID + '/Images/Flash/SR&txtClassAcctID=' + ClassAcctID);
		document.write('&txtLoadScript=/FlashTools/SeeingReason/DataIO/SRFlashLoad.aspx');
		document.write('&txtSaveScript=/FlashTools/SeeingReason/DataIO/SRFlashSave.aspx');
		document.write('&txtPrintScript=/FlashTools/SeeingReason/DataIO/SRPrintIO.aspx');
		document.write('&txtIsDemo=true&txtProjectName=' + escape(ProjectName) + '&sLocaleID=' + LocaleID + '&DebugFlag=false&txtDocInfo=">'); 
		document.write('<PARAM NAME=quality VALUE="high">'); 
		document.write('<PARAM NAME=bgcolor VALUE="#FFFFFF">'); 
		document.write('<PARAM NAME=docInfo VALUE="">'); 
		document.write('<table width=700 height=150><tr><td valign=middle align=center><font class="body">The Macromedia Flash player failed to load.<BR>'); 
		document.write('Please go to <a href=http://www.macromedia.com/go/getflashplayer>http://www.macromedia.com/go/getflashplayer</a> to reinstall the Flash player.<BR>If you are unsuccessful in reinstalling the Flash player, you may be on a network that prohibits you from downloading software due to the network policies. Often the only person who can authorize and facilitate downloading plug-ins is the network administrator. Please contact the network administrator for further assistance with installing Flash.</font></td></tr></table>'); 
		document.write('</OBJECT>');
	}
	else
	{
		var FlashVersion = identifyFlash(); 
		if(FlashVersion>6) { 
			document.write('<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '); 
			document.write('codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" '); 
			document.write('WIDTH="740" HEIGHT="600" '); 
			document.write('ID="SeeingReason" ALIGN="" VIEWASTEXT>'); 
			document.write('<PARAM NAME=movie VALUE="/FlashTools/SeeingReason/Components/SeeingReason.swf">'); 
			document.write('<PARAM NAME=FlashVars value="txtAssignmentID=&txtAgentID=' + EbusAgtID);
			document.write('&txtImagePath=/common/' + LocaleID + '/Images/Flash/SR&txtClassAcctID=' + ClassAcctID);
			document.write('&txtLoadScript=/FlashTools/SeeingReason/DataIO/SRFlashLoad.aspx');
			document.write('&txtSaveScript=/FlashTools/SeeingReason/DataIO/SRFlashSave.aspx');
			document.write('&txtPrintScript=/FlashTools/SeeingReason/DataIO/SRPrintIO.aspx');
			document.write('&txtIsDemo=true&txtProjectName=' + escape(ProjectName) + '&sLocaleID=' + LocaleID + '&DebugFlag=false&txtDocInfo=">'); 
			document.write('<PARAM NAME=quality VALUE="high">'); 
			document.write('<PARAM NAME=bgcolor VALUE="#FFFFFF">'); 
			document.write('<PARAM NAME=docInfo VALUE="">'); 
			document.write('<EMBED src="/FlashTools/SeeingReason/Components/SeeingReason.swf?');
			document.write('txtAssignmentID=&txtAgentID=' + EbusAgtID + '&txtImagePath=/common/' + LocaleID + '/Images/Flash/SR');
			document.write('&txtClassAcctID=' + ClassAcctID + '&txtLoadScript=/FlashTools/SeeingReason/DataIO/SRFlashLoad.aspx');
			document.write('&txtSaveScript=/FlashTools/SeeingReason/DataIO/SRFlashSave.aspx');
			document.write('&txtPrintScript=/FlashTools/SeeingReason/DataIO/SRPrintIO.aspx');
			document.write('&txtIsDemo=true&txtProjectName=' + escape(ProjectName) + '&sLocaleID=' + LocaleID + '&DebugFlag=false&txtDocInfo=" quality=high bgcolor=#FFFFFF '); 
			document.write('WIDTH="740" HEIGHT="600" '); 
			document.write('NAME="SeeingReason" swLiveConnect="true" ALIGN="" '); 
			document.write('TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">'); 
			document.write('</EMBED>'); 
			document.write('</OBJECT>'); 
		} 
		else 
		{ 
			document.write('<table width=700 height=600><tr><td valign=middle align=center><font class="srText">The Macromedia Flash player failed to load.<BR>Please go to <a href=http://www.macromedia.com/go/getflashplayer>http://www.macromedia.com/go/getflashplayer</a> to reinstall the Flash player.<BR>If you are unsuccessful in reinstalling the Flash player, you may be on a network that prohibits you from downloading software due to the network policies. Often the only person who can authorize and facilitate downloading plug-ins is the network administrator. Please contact the network administrator for further assistance with installing Flash.</font></td></tr></table>'); 
		}	
	
	}
}



/*
Purpose:To generate object tag for VR Flash tool
Input:	Ebus Agent ID (CPM), 
		student Class Account ID, 
		Project Name, 
		Locale ID (in this case, should be the MCMS locale channel, e.g "en")
History:
Name		Date			Comments
------------------------------------
May Tee		03/02/05		Created to support MCMS
*/
function VRInstallTool(ClassAcctID, ProjectName, LocaleID)
{

	var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
	var EbusAgtID = getEbusAgtID(LocaleID);
	
	if (InternetExplorer)
	{
		//IE
		document.write('<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '); 
		document.write('codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" '); 
		document.write('WIDTH="740" HEIGHT="600" '); 
		document.write('id="VisualRanking" ALIGN="" VIEWASTEXT >'); 
		document.write('<PARAM NAME=movie VALUE="/FlashTools/VisualRanking/Components/rank.swf?ServerFullPath=/FlashTools/VisualRanking/DataIO/VRDataIO.aspx&ProjectID=&AssignmentID=&strClassAcctID=' + ClassAcctID + '&strProjectName=' + ProjectName + '&AgentID=' + EbusAgtID + '&ImagePath=/common/' + LocaleID + '/Images/Flash/VR&PrintID=NO&sLocaleID=' + LocaleID + '&DebugFlag=false&CompTeam=">'); 
		document.write('<PARAM NAME=quality VALUE=high>');
		document.write('<PARAM NAME=bgcolor VALUE=#FFFFFF>');
		document.write('<PARAM NAME=MENU VALUE=false>');
		document.write('<table width=700 height=150><tr><td valign=middle align=center><font class="body">The Macromedia Flash player failed to load.<BR>'); 
		document.write('Please go to <a href=http://www.macromedia.com/go/getflashplayer>http://www.macromedia.com/go/getflashplayer</a> to reinstall the Flash player.<BR>If you are unsuccessful in reinstalling the Flash player, you may be on a network that prohibits you from downloading software due to the network policies. Often the only person who can authorize and facilitate downloading plug-ins is the network administrator. Please contact the network administrator for further assistance with installing Flash.</font></td></tr></table>'); 
		document.write('</OBJECT>');
	}
	else
	{
		//Other browsers - NS
		var FlashVersion = identifyFlash(); 
		if(FlashVersion>6) 
		{ 
			document.write('<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" WIDTH="740" HEIGHT="600" id="VisualRanking" ALIGN="" VIEWASTEXT >'); 
			document.write('<PARAM NAME=movie VALUE="/FlashTools/VisualRanking/Components/rank.swf?ServerFullPath=/FlashTools/VisualRanking/DataIO/VRDataIO.aspx&ProjectID=&AssignmentID=&strClassAcctID=' + ClassAcctID + '&strProjectName=' + ProjectName + '&AgentID=' + EbusAgtID + '&ImagePath=/common/' + LocaleID + '/Images/Flash/VR&PrintID=NO&sLocaleID=' + LocaleID + '&DebugFlag=false&CompTeam=">'); 
			document.write('<PARAM NAME=quality VALUE=high>'); 
			document.write('<PARAM NAME=bgcolor VALUE=#FFFFFF>'); 
			document.write('<PARAM NAME=MENU VALUE=false>'); 
			document.write('<EMBED src="/FlashTools/VisualRanking/Components/rank.swf?ServerFullPath=/FlashTools/VisualRanking/DataIO/VRDataIO.aspx&ProjectID=&AssignmentID=&strClassAcctID=' + ClassAcctID + '&strProjectName=' + ProjectName + '&AgentID=' + EbusAgtID + '&ImagePath=/common/' + LocaleID + '/Images/Flash/VR&PrintID=NO&sLocaleID=' + LocaleID + '&DebugFlag=false&CompTeam=" NAME=VisualRanking  quality=high bgcolor=#FFFFFF menu=false WIDTH="740" HEIGHT="600" TYPE="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></EMBED>'); 
			document.write('</OBJECT>'); 
		} 
		else 
		{ 
			document.write('<table width=700 height=600><tr><td valign=middle align=center><font class="srText">The Macromedia Flash player failed to load.<BR>Please go to <a href=http://www.macromedia.com/go/getflashplayer>http://www.macromedia.com/go/getflashplayer</a> to reinstall the Flash player.<BR>If you are unsuccessful in reinstalling the Flash player, you may be on a network that prohibits you from downloading software due to the network policies. Often the only person who can authorize and facilitate downloading plug-ins is the network administrator. Please contact the network administrator for further assistance with installing Flash.</font></td></tr></table>'); 
		}

	}
	
	
}

/**********************************************************************************
SUPPORT FOR Non-Ascii based Project Names
***********************************************************************************/
function SRInstallToolByID(ClassAcctID, AssignmentID, LocaleID)
{

	var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
	var EbusAgtID = getEbusAgtID(LocaleID);
	

	if (InternetExplorer)
	{
		document.write('<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '); 
		document.write('codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" '); 
		document.write('WIDTH="740" HEIGHT="600" '); 
		document.write('ID="SeeingReason" ALIGN="" VIEWASTEXT>'); 
		document.write('<PARAM NAME=movie VALUE="/FlashTools/SeeingReason/Components/SeeingReason.swf">'); 
		document.write('<PARAM NAME=FlashVars value="txtAssignmentID=' + AssignmentID + '&txtAgentID=' + EbusAgtID);
		document.write('&txtImagePath=/common/'+ LocaleID + '/Images/Flash/SR&txtClassAcctID=' + ClassAcctID);
		document.write('&txtLoadScript=/FlashTools/SeeingReason/DataIO/SRFlashLoad.aspx');
		document.write('&txtSaveScript=/FlashTools/SeeingReason/DataIO/SRFlashSave.aspx');
		document.write('&txtPrintScript=/FlashTools/SeeingReason/DataIO/SRPrintIO.aspx');
		document.write('&txtIsDemo=true&txtProjectName=&sLocaleID=' + LocaleID + '&DebugFlag=true&txtDocInfo=">'); 
		document.write('<PARAM NAME=quality VALUE="high">'); 
		document.write('<PARAM NAME=bgcolor VALUE="#FFFFFF">'); 
		document.write('<PARAM NAME=docInfo VALUE="">'); 
		document.write('<table width=700 height=150><tr><td valign=middle align=center><font class="body">The Macromedia Flash player failed to load.<BR>'); 
		document.write('Please go to <a href=http://www.macromedia.com/go/getflashplayer>http://www.macromedia.com/go/getflashplayer</a> to reinstall the Flash player.<BR>If you are unsuccessful in reinstalling the Flash player, you may be on a network that prohibits you from downloading software due to the network policies. Often the only person who can authorize and facilitate downloading plug-ins is the network administrator. Please contact the network administrator for further assistance with installing Flash.</font></td></tr></table>'); 
		document.write('</OBJECT>');
	}
	else
	{
		var FlashVersion = identifyFlash(); 
		if(FlashVersion>6) { 
			document.write('<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '); 
			document.write('codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" '); 
			document.write('WIDTH="740" HEIGHT="600" '); 
			document.write('ID="SeeingReason" ALIGN="" VIEWASTEXT>'); 
			document.write('<PARAM NAME=movie VALUE="/FlashTools/SeeingReason/Components/SeeingReason.swf">'); 
			document.write('<PARAM NAME=FlashVars value="txtAssignmentID=' + AssignmentID + '&txtAgentID=' + EbusAgtID);
			document.write('&txtImagePath=/common/' + LocaleID + '/Images/Flash/SR&txtClassAcctID=' + ClassAcctID);
			document.write('&txtLoadScript=/FlashTools/SeeingReason/DataIO/SRFlashLoad.aspx');
			document.write('&txtSaveScript=/FlashTools/SeeingReason/DataIO/SRFlashSave.aspx');
			document.write('&txtPrintScript=/FlashTools/SeeingReason/DataIO/SRPrintIO.aspx');
			document.write('&txtIsDemo=true&txtProjectName=' + escape(AssignmentID) + '&sLocaleID=' + LocaleID + '&DebugFlag=false&txtDocInfo=">'); 
			document.write('<PARAM NAME=quality VALUE="high">'); 
			document.write('<PARAM NAME=bgcolor VALUE="#FFFFFF">'); 
			document.write('<PARAM NAME=docInfo VALUE="">'); 
			document.write('<EMBED src="/FlashTools/SeeingReason/Components/SeeingReason.swf?');
			document.write('txtAssignmentID=' + AssignmentID + '&txtAgentID=' + EbusAgtID + '&txtImagePath=/common/' + LocaleID + '/Images/Flash/SR');
			document.write('&txtClassAcctID=' + ClassAcctID + '&txtLoadScript=/FlashTools/SeeingReason/DataIO/SRFlashLoad.aspx');
			document.write('&txtSaveScript=/FlashTools/SeeingReason/DataIO/SRFlashSave.aspx');
			document.write('&txtPrintScript=/FlashTools/SeeingReason/DataIO/SRPrintIO.aspx');
			document.write('&txtIsDemo=true&txtProjectName=' + escape(AssignmentID) + '&sLocaleID=' + LocaleID + '&DebugFlag=false&txtDocInfo=" quality=high bgcolor=#FFFFFF '); 
			document.write('WIDTH="740" HEIGHT="600" '); 
			document.write('NAME="SeeingReason" swLiveConnect="true" ALIGN="" '); 
			document.write('TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">'); 
			document.write('</EMBED>'); 
			document.write('</OBJECT>'); 
		} 
		else 
		{ 
			document.write('<table width=700 height=600><tr><td valign=middle align=center><font class="srText">The Macromedia Flash player failed to load.<BR>Please go to <a href=http://www.macromedia.com/go/getflashplayer>http://www.macromedia.com/go/getflashplayer</a> to reinstall the Flash player.<BR>If you are unsuccessful in reinstalling the Flash player, you may be on a network that prohibits you from downloading software due to the network policies. Often the only person who can authorize and facilitate downloading plug-ins is the network administrator. Please contact the network administrator for further assistance with installing Flash.</font></td></tr></table>'); 
		}	
	
	}
}



/**********************************************************************************
SUPPORT FOR Non-Ascii based Project Names
***********************************************************************************/
function VRInstallToolByID(ClassAcctID, AssignmentID, LocaleID)
{


	var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
	var EbusAgtID = getEbusAgtID(LocaleID);
		
	
	if (InternetExplorer)
	{
		//IE
		document.write('<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '); 
		document.write('codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" '); 
		document.write('WIDTH="740" HEIGHT="600" '); 
		document.write('id="VisualRanking" ALIGN="" VIEWASTEXT >'); 
		document.write('<PARAM NAME=movie VALUE="/FlashTools/VisualRanking/Components/rank.swf?ServerFullPath=/FlashTools/VisualRanking/DataIO/VRDataIO.aspx&ProjectID=' + ClassAcctID + '&AssignmentID=' + AssignmentID + '&strClassAcctID=' + ClassAcctID + '&strProjectName=&AgentID=' + EbusAgtID + '&ImagePath=/common/' + LocaleID + '/Images/Flash/VR&PrintID=NO&sLocaleID=' + LocaleID + '&DebugFlag=false&CompTeam=">'); 
		document.write('<PARAM NAME=quality VALUE=high>');
		document.write('<PARAM NAME=bgcolor VALUE=#FFFFFF>');
		document.write('<PARAM NAME=MENU VALUE=false>');
		document.write('<table width=700 height=150><tr><td valign=middle align=center><font class="body">The Macromedia Flash player failed to load.<BR>'); 
		document.write('Please go to <a href=http://www.macromedia.com/go/getflashplayer>http://www.macromedia.com/go/getflashplayer</a> to reinstall the Flash player.<BR>If you are unsuccessful in reinstalling the Flash player, you may be on a network that prohibits you from downloading software due to the network policies. Often the only person who can authorize and facilitate downloading plug-ins is the network administrator. Please contact the network administrator for further assistance with installing Flash.</font></td></tr></table>'); 
		document.write('</OBJECT>');
	}
	else
	{
		//Other browsers - NS
		var FlashVersion = identifyFlash(); 
		if(FlashVersion>6) 
		{ 
			document.write('<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" WIDTH="740" HEIGHT="600" id="VisualRanking" ALIGN="" VIEWASTEXT >'); 
			document.write('<PARAM NAME=movie VALUE="/FlashTools/VisualRanking/Components/rank.swf?ServerFullPath=/FlashTools/VisualRanking/DataIO/VRDataIO.aspx&ProjectID=&AssignmentID=' + AssignmentID + '&strClassAcctID=' + ClassAcctID + '&strProjectName=&AgentID=' + EbusAgtID + '&ImagePath=/common/' + LocaleID + '/Images/Flash/VR&PrintID=NO&sLocaleID=' + LocaleID + '&DebugFlag=false&CompTeam=">'); 
			document.write('<PARAM NAME=quality VALUE=high>'); 
			document.write('<PARAM NAME=bgcolor VALUE=#FFFFFF>'); 
			document.write('<PARAM NAME=MENU VALUE=false>'); 
			document.write('<EMBED src="/FlashTools/VisualRanking/Components/rank.swf?ServerFullPath=/FlashTools/VisualRanking/DataIO/VRDataIO.aspx&ProjectID=' + ClassAcctID + '&AssignmentID=' + AssignmentID + '&strClassAcctID=' + ClassAcctID + '&strProjectName=&AgentID=' + EbusAgtID + '&ImagePath=/common/' + LocaleID + '/Images/Flash/VR&PrintID=NO&sLocaleID=' + LocaleID + '&DebugFlag=false&CompTeam=" NAME=VisualRanking  quality=high bgcolor=#FFFFFF menu=false WIDTH="740" HEIGHT="600" TYPE="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></EMBED>'); 
			document.write('</OBJECT>'); 
		} 
		else 
		{ 
			document.write('<table width=700 height=600><tr><td valign=middle align=center><font class="srText">The Macromedia Flash player failed to load.<BR>Please go to <a href=http://www.macromedia.com/go/getflashplayer>http://www.macromedia.com/go/getflashplayer</a> to reinstall the Flash player.<BR>If you are unsuccessful in reinstalling the Flash player, you may be on a network that prohibits you from downloading software due to the network policies. Often the only person who can authorize and facilitate downloading plug-ins is the network administrator. Please contact the network administrator for further assistance with installing Flash.</font></td></tr></table>'); 
		}

	}
	
	
}

















// -----------------------------------------------------------
// Univeral method for javascript->flash setvariable
// -----------------------------------------------------------

/*
 *	Modified from original MLAB version (MLAB_flash_setvariables.js)
 *	Ben Loh, Inquirium LLC
 *	
 *	Removed "escape()" function in flashquery.
 *	We're assuming that flashquery is already URL-safe.
 *	The reason for this is that by the time flashquery is received by setFlashVariables, it's already been passed around a few times
 *	in javascript, and needed to be encoded (both encodeURIComponent, and a custom encoding of the single quote character)
 */
 
/* -----------------------------------------------------------
----------Supporting Browsers----------
PC:
IE 5 and higher
Netscape 6 and higher
Moz/Firebird all
Opera 7 and higher

Mac OSX:
IE 5.2
Safari all
Netscape 6 and higher
Moz/Firebird/Camino all
Opera 6 and higher

Linux:
Konqueror assumed
----------------------------------------------------------- */



// -----------------------------------------------------------
// Detection snippet from http://www.dithered.com/javascript/browser_detect/index.html
// -----------------------------------------------------------
var ua        = navigator.userAgent.toLowerCase(); 
var is_pc_ie  = ( (ua.indexOf('msie') != -1 ) && ( ua.indexOf('win') != -1 ) && ( ua.indexOf('opera') == -1 ) && ( ua.indexOf('webtv') == -1 ) );



/* -----------------------------------------------------------
function setFlashVariables(movieid, flashquery)

movieid: id of object tag, name of movieid passed in through FlashVars
flashquery: querystring of values to set. example( var1=foo&var2=bar )
----------------------------------------------------------- */
function setFlashVariables(movieid, jsTextInput, jsTextInputEvent){
	var i,values;
/*	Removed pc_ie-specific function, and try using the gateway method for all browsers.
	This was breaking in IE6 b/c the Flash app wasn't doing the polling anymore.
	if(is_pc_ie){
		var chunk = flashquery.split("&");
		for(i in chunk){
			values = chunk[i].split("=");
			document[movieid].SetVariable(values[0],values[1]);
		}
	}else{ */
		var divcontainer = "flash_setvariables_"+movieid;
		if(!document.getElementById(divcontainer)){
			var divholder = document.createElement("div");
			divholder.id = divcontainer;
			document.body.appendChild(divholder);
		}
		document.getElementById(divcontainer).innerHTML = "";
		var divinfo = "<embed src='/flashtools/showingevidence/components/gateway.swf' FlashVars='lc="+movieid+"&jsTextInput="+jsTextInput+"&jsTextInputEvent="+jsTextInputEvent+"' width='0' height='0' type='application/x-shockwave-flash'></embed>";
		document.getElementById(divcontainer).innerHTML = divinfo;
//	}
}





/*
 *	Showing Evidence HTML Form Javascript for RTL Languages
 *
 *	Ben Loh / ben@inquirium.net / Inquirium
 *	6/27/2005
 *
 *	These functions are used by createForm.php to encode data and send it
 *	to the parent window and Flash.
 *
 */
 
 
/******************************************************************************
 *	
 *	SE's Custom Encoding Functions
 *
 *	Ben Loh / ben@inquirium.net / Inquirium
 *
 *	These functions are necessary to address flawed browser support for
 *	encoding text.
 *
 *****************************************************************************/
//	Returns a string that is safe to pass within a SetFlashVar call
function encodeJSsafe( s ) {
	if (browser.isIE5x) {
		var s = encodeURIComponentNew(s)		// encodeURIComponents doesn't work on IE5.0
	} else {	
		var s = encodeURIComponent(s)
	}
	return encodeURIComponentExtra( s )
}
//	Encodes things that encodeURIComponents misses
function encodeURIComponentExtra( s ) {
	s = encodeQuote(s)
	s = encodeEqual(s)
	//MT 09/26/05: Added to remove extra carriage return.
	s = s.replace(/%0A/g, "")
	return s
}
//	Encodes single quotes (because encodeURIComponents doesn't encode single quotes)
function encodeQuote( s ) {
	return s.replace(/'/g,"%27")
}
//	Encodes equal signs (because encodeURIComponents doesn't encode equal signs)
function encodeEqual( s ) {
	return s.replace(/=/g,"%3D")
}



/******************************************************************************
 *	
 *	Javascript to Flash Functions
 *
 *	Ben Loh / ben@inquirium.net / Inquirium
 *
 *	These functions handle the communication between Javascript and Flash
 *
 *****************************************************************************/	
//	Use the parent window's SetFlashVar function to send the data to Flash
//	Need to do our custom encode of the string to make sure it makes it intact 
//	to the parent window.
//	@param	string		event = 'btn_ok' or 'btn_cancel'
//	NOTE: Make sure "opener" is set when this window is created, because support
//	for opener is not universal (IE on Mac doesn't support this).
function SetParentFlashVar(event) {
	//	truncate before encoding, because truncating encoded text is problematic.
	var jsTextInput				= document.forms[0].inputField.value;
	var truncatedJsTextInput	= jsTextInput.substr( 0, 2048);
	var encodedInputValue		= encodeJSsafe( truncatedJsTextInput )
	opener.SetFlashVar(encodedInputValue, event)
}


//	Used when the user clicks on the OK or Cancel buttons
//  to tell the HandleOnClose handler not to fire.
var doHandleClose = true

//	Buttons should call this function
function SendAndClose(event) {
	SetParentFlashVar(event)
	doHandleClose = false
	CloseWindow()
}
//	Handle someone clicking on the window's close button
function HandleOnClose() {
	if (doHandleClose) {
		SetParentFlashVar( 'window_close_btn' )
	}
}
//
function CloseWindow() {
	window.close()
}

/******************************************************************************
 *	
 *	Public Domain / Licensed Encoding Functions
 *
 *	These functions are needed by our custom encoding functions
 *
 *****************************************************************************/	

/*	
 *	Converts URL-encodes UTF8 strings.
 *
 *	[BL: This is needed for IE5 b/c encodeURIComponents() is not supported.
 *	and escape() does not work w/ UTF8.]
*/
/* From http://www.worldtimzone.com/res/encode/ */
/* ***************************
** Most of this code was kindly 
** provided to me by
** Andrew Clover (and at doxdesk dot com)
** http://and.doxdesk.com/ 
** in response to my plea in my blog at 
** http://worldtimzone.com/blog/date/2002/09/24
** It was unclear whether he created it.
*/
function utf8(wide) {
  var c, s;
  var enc = "";
  var i = 0;
  while(i<wide.length) {
    c= wide.charCodeAt(i++);
    // handle UTF-16 surrogates
    if (c>=0xDC00 && c<0xE000) continue;
    if (c>=0xD800 && c<0xDC00) {
      if (i>=wide.length) continue;
      s= wide.charCodeAt(i++);
      if (s<0xDC00 || c>=0xDE00) continue;
      c= ((c-0xD800)<<10)+(s-0xDC00)+0x10000;
    }
    // output value
    if (c<0x80) enc += String.fromCharCode(c);
    else if (c<0x800) enc += String.fromCharCode(0xC0+(c>>6),0x80+(c&0x3F));
    else if (c<0x10000) enc += String.fromCharCode(0xE0+(c>>12),0x80+(c>>6&0x3F),0x80+(c&0x3F));
    else enc += String.fromCharCode(0xF0+(c>>18),0x80+(c>>12&0x3F),0x80+(c>>6&0x3F),0x80+(c&0x3F));
  }
  return enc;
}

var hexchars = "0123456789ABCDEF";

function toHex(n) {
  return hexchars.charAt(n>>4)+hexchars.charAt(n & 0xF);
}

var okURIchars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-";

function encodeURIComponentNew(s) {
  var s = utf8(s);
  var c;
  var enc = "";
  for (var i= 0; i<s.length; i++) {
    if (okURIchars.indexOf(s.charAt(i))==-1)
      enc += "%"+toHex(s.charCodeAt(i));
    else
      enc += s.charAt(i);
  }
  return enc;
}



/******************************************************************************
 *	
 *	General Utilities
 *
 *	Ben Loh / ben@inquirium.net / Inquirium
 *
 *	These functions are needed by the encoding functions
 *
 *****************************************************************************/	
// Browser Detect  v2.1.6
// documentation: http://www.dithered.com/javascript/browser_detect/index.html
// license: http://creativecommons.org/licenses/by/1.0/
// code by Chris Nott (chris[at]dithered[dot]com)

function BrowserDetect() {
   var ua = navigator.userAgent.toLowerCase(); 

   // browser engine name
   this.isGecko       = (ua.indexOf('gecko') != -1 && ua.indexOf('safari') == -1);
   this.isAppleWebKit = (ua.indexOf('applewebkit') != -1);

   // browser name
   this.isKonqueror   = (ua.indexOf('konqueror') != -1); 
   this.isSafari      = (ua.indexOf('safari') != - 1);
   this.isOmniweb     = (ua.indexOf('omniweb') != - 1);
   this.isOpera       = (ua.indexOf('opera') != -1); 
   this.isIcab        = (ua.indexOf('icab') != -1); 
   this.isAol         = (ua.indexOf('aol') != -1); 
   this.isIE          = (ua.indexOf('msie') != -1 && !this.isOpera && (ua.indexOf('webtv') == -1) ); 
   this.isMozilla     = (this.isGecko && ua.indexOf('gecko/') + 14 == ua.length);
   this.isFirebird    = (ua.indexOf('firebird/') != -1);
   this.isNS          = ( (this.isGecko) ? (ua.indexOf('netscape') != -1) : ( (ua.indexOf('mozilla') != -1) && !this.isOpera && !this.isSafari && (ua.indexOf('spoofer') == -1) && (ua.indexOf('compatible') == -1) && (ua.indexOf('webtv') == -1) && (ua.indexOf('hotjava') == -1) ) );
   
   // spoofing and compatible browsers
   this.isIECompatible = ( (ua.indexOf('msie') != -1) && !this.isIE);
   this.isNSCompatible = ( (ua.indexOf('mozilla') != -1) && !this.isNS && !this.isMozilla);
   
   // rendering engine versions
   this.geckoVersion = ( (this.isGecko) ? ua.substring( (ua.lastIndexOf('gecko/') + 6), (ua.lastIndexOf('gecko/') + 14) ) : -1 );
   this.equivalentMozilla = ( (this.isGecko) ? parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) ) : -1 );
   this.appleWebKitVersion = ( (this.isAppleWebKit) ? parseFloat( ua.substring( ua.indexOf('applewebkit/') + 12) ) : -1 );
   
   // browser version
   this.versionMinor = parseFloat(navigator.appVersion); 
   
   // correct version number
   if (this.isGecko && !this.isMozilla) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('/', ua.indexOf('gecko/') + 6) + 1 ) );
   }
   else if (this.isMozilla) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) );
   }
   else if (this.isIE && this.versionMinor >= 4) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('msie ') + 5 ) );
   }
   else if (this.isKonqueror) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('konqueror/') + 10 ) );
   }
   else if (this.isSafari) {
      this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('safari/') + 7 ) );
   }
   else if (this.isOmniweb) {
      this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('omniweb/') + 8 ) );
   }
   else if (this.isOpera) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('opera') + 6 ) );
   }
   else if (this.isIcab) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('icab') + 5 ) );
   }
   
   this.versionMajor = parseInt(this.versionMinor); 
   
   // dom support
   this.isDOM1 = (document.getElementById);
   this.isDOM2Event = (document.addEventListener && document.removeEventListener);
   
   // css compatibility mode
   this.mode = document.compatMode ? document.compatMode : 'BackCompat';

   // platform
   this.isWin    = (ua.indexOf('win') != -1);
   this.isWin32  = (this.isWin && ( ua.indexOf('95') != -1 || ua.indexOf('98') != -1 || ua.indexOf('nt') != -1 || ua.indexOf('win32') != -1 || ua.indexOf('32bit') != -1 || ua.indexOf('xp') != -1) );
   this.isMac    = (ua.indexOf('mac') != -1);
   this.isUnix   = (ua.indexOf('unix') != -1 || ua.indexOf('sunos') != -1 || ua.indexOf('bsd') != -1 || ua.indexOf('x11') != -1)
   this.isLinux  = (ua.indexOf('linux') != -1);
   
   // specific browser shortcuts
   this.isNS4x = (this.isNS && this.versionMajor == 4);
   this.isNS40x = (this.isNS4x && this.versionMinor < 4.5);
   this.isNS47x = (this.isNS4x && this.versionMinor >= 4.7);
   this.isNS4up = (this.isNS && this.versionMinor >= 4);
   this.isNS6x = (this.isNS && this.versionMajor == 6);
   this.isNS6up = (this.isNS && this.versionMajor >= 6);
   this.isNS7x = (this.isNS && this.versionMajor == 7);
   this.isNS7up = (this.isNS && this.versionMajor >= 7);
   
   this.isIE4x = (this.isIE && this.versionMajor == 4);
   this.isIE4up = (this.isIE && this.versionMajor >= 4);
   this.isIE5x = (this.isIE && this.versionMajor == 5);
   this.isIE55 = (this.isIE && this.versionMinor == 5.5);
   this.isIE5up = (this.isIE && this.versionMajor >= 5);
   this.isIE6x = (this.isIE && this.versionMajor == 6);
   this.isIE6up = (this.isIE && this.versionMajor >= 6);
   
   this.isIE4xMac = (this.isIE4x && this.isMac);
}
var browser = new BrowserDetect();









	function OpenFormWin( formWinURL, winName, winParams ) {
		if (IsShowingEvidenceReport(formWinURL))
		{
			winParams=winParams + ', scrollbars=1, resizable=1';
		}
		newWin = window.open( formWinURL,'form_win',winParams)
		if (!newWin.opener) { newWin.opener = window }
	}
	
	function IsShowingEvidenceReport(formWinURL)
	{
		if ((formWinURL.indexOf('SEPrintDataIO')!=-1)
			||(formWinURL.indexOf('SETeamPrintDataIO')!=-1))
		{
			return true;
		}
		return false;
	}
		
	function SetFlashVar( jsTextInput, jsTextInputEvent ) {
		setFlashVariables( 'se', jsTextInput, jsTextInputEvent )
	}

/*
Purpose:To generate object tag for SE Flash tool
Input:	AssignmentID, 
		Locale ID (in this case, should be the MCMS locale channel, e.g "en")
History:
Name		Date			Comments
------------------------------------
May Tee		06/01/05		Created to support MCMS
*/
function SEInstallTool(AssignmentID, LocaleID, VersionID)
{

	var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
	var sHostName = new String(location.hostname);
	
	var sSimplified = '';
	
	//Tool Version 1 = standard, 2 = simplified
	if (VersionID == 2) sSimplified = '.viewSimple';
	
	
	if (InternetExplorer)
	{
		//IE
		document.write('<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ');  
		document.write('codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" ');  
		document.write('WIDTH="740" HEIGHT="500" ');  
		document.write('id="ProveIt" ALIGN="middle" VIEWASTEXT > ');
		document.write('<PARAM NAME=movie VALUE="http://' + sHostName + '/FlashTools/ShowingEvidence/Components/se_rtl.swf"> ');
		document.write('<PARAM NAME=FlashVars value="Demo=true&LocaleID=' + LocaleID + '&SessionFlags=sessionView' + sSimplified + '&AssignmentID=' + AssignmentID + '&UserName=&AutoSave=180&PrinterURL=http://' + sHostName + '/FlashTools/ShowingEvidence/DataIO/SETeamPrintDataIO.aspx&ServerURL=http://' + sHostName + '/FlashTools/ShowingEvidence/DataIO/SETeamDataIO.aspx&LoadingPrompt=Loading...&FormInputURL=http://' + sHostName + '/FlashTools/ShowingEvidence/DataIO/SERTLCreateForm.aspx&movieid=se" /> ');
		document.write('<PARAM NAME=allowScriptAccess value=sameDomain /> ');
		document.write('<PARAM NAME=quality VALUE=high> ');
		document.write('<PARAM NAME=scale value="noscale"> ');
		document.write('<PARAM NAME=salign value="t"> ');
		document.write('<PARAM NAME=bgcolor VALUE=#FFFFFF> ');
		document.write('<PARAM NAME=MENU VALUE=false> ');
		document.write('<table width=740 height=150><tr><td valign=middle align=center><font class="srText">The Macromedia Flash player failed to load.<BR>Please go to <a href=http://www.macromedia.com/go/getflashplayer>http://www.macromedia.com/go/getflashplayer</a> to reinstall the Flash player.<BR>If you are unsuccessful in reinstalling the Flash player, you may be on a network that prohibits you from downloading software due to the network policies. Often the only person who can authorize and facilitate downloading plug-ins is the network administrator. Please contact the network administrator for further assistance with installing Flash.</font></td></tr></table> ');
		document.write('</OBJECT>');
	
	}
	else
	{
		//Other browsers - NS
		var FlashVersion = identifyFlash(); 
		if(FlashVersion>6) 
		{ 
			document.write('<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" WIDTH="740" HEIGHT="500" id="ProveIt" ALIGN="" VIEWASTEXT >'); 
			document.write('<PARAM NAME=movie VALUE="http://' + sHostName + '/FlashTools/ShowingEvidence/Components/se_rtl.swf">'); 
			document.write('<PARAM NAME=FlashVars value="Demo=true&LocaleID=' + LocaleID + '&SessionFlags=sessionView' + sSimplified + '&AssignmentID=' + AssignmentID + '&UserName=&AutoSave=180&PrinterURL=http://' + sHostName + '/FlashTools/ShowingEvidence/DataIO/SETeamPrintDataIO.aspx&ServerURL=http://' + sHostName + '/FlashTools/ShowingEvidence/DataIO/SETeamDataIO.aspx&LoadingPrompt=Loading...&FormInputURL=http://' + sHostName + '/FlashTools/ShowingEvidence/DataIO/SERTLCreateForm.aspx&movieid=se" />'); 
			document.write('<PARAM NAME=allowScriptAccess value=sameDomain />'); 
			document.write('<PARAM NAME=quality VALUE=high>'); 
			document.write('<PARAM NAME=scale value="noscale">'); 
			document.write('<PARAM NAME=bgcolor VALUE=#FFFFFF>'); 
			document.write('<PARAM NAME=MENU VALUE=false>'); 
			document.write('<EMBED src="http://' + sHostName + '/FlashTools/ShowingEvidence/Components/se_rtl.swf" NAME="ProveIt" quality="high" bgcolor="#FFFFFF" menu="false" scale="noscale" salign="t" allowScriptAccess="sameDomain" FlashVars="&LocaleID=' + LocaleID + '&SessionFlags=sessionView&AssignmentID=' + AssignmentID + '&UserName=&AutoSave=180&PrinterURL=http://' + sHostName + '/FlashTools/ShowingEvidence/DataIO/SETeamPrintDataIO.aspx&ServerURL=http://' + sHostName + '/FlashTools/ShowingEvidence/DataIO/SETeamDataIO.aspx&LoadingPrompt=Loading...&FormInputURL=http://' + sHostName + '/FlashTools/ShowingEvidence/DataIO/SERTLCreateForm.aspx&movieid=se" WIDTH="740" HEIGHT="500" TYPE="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></EMBED>'); 
			document.write('</OBJECT>'); 
		} 
		else 
		{ 
			document.write('<table width=740 height=150><tr><td valign=middle align=center><font class="srText">The Macromedia Flash player failed to load.<BR>Please go to <a href=http://www.macromedia.com/go/getflashplayer>http://www.macromedia.com/go/getflashplayer</a> to reinstall the Flash player.<BR>If you are unsuccessful in reinstalling the Flash player, you may be on a network that prohibits you from downloading software due to the network policies. Often the only person who can authorize and facilitate downloading plug-ins is the network administrator. Please contact the network administrator for further assistance with installing Flash.</font></td></tr></table>'); 
		}

	}
	
	
}
