//*****************************************************************************************
//
// JavaScript File
//
// Name:         FlashPaceholder.js
// Description:  List of java script functions used by FlashPlaceholder control.
//
//*****************************************************************************************
//
// FUNCTIONS
//
// Name:         DetectBrowser 
// Description:  Detects browser if flash-enabled.
// Accepts:      None
// Returns:      None
//
// Name:         detectPlugin 
// Description:  Detects browser if flash-enabled.
// Accepts:      None
// Returns:      None
//
// Name:         isCMSAuthoringMode
// Description:  Determines the mode of the page ---
//				 whether in authoring or in presentation mode.
// Accepts:      None
// Returns:      Boolean - Returns true when the page is in authoring mode.
//
// Name:         DisplayMainSection
// Description:  Sets visibility of flash section to TRUE if plugin is found,
//				 otherwise the NonFlash section will be displayed.
// Accepts:      String
// Returns:      None
//*****************************************************************************************
//
// REVISION HISTORY
//
// Date Created: 07/10/2006
// Author:       DAV
//
// DATE		  BY	 SIR NO		 DESCRIPTION
// 04/11/07   JVG				 Removed functions not applicable to Careers application.
// 12/17/07   LAB    SIR-1090	 Remove "ViewType=Flash" from URLs of Flash Pages
// 12/28/07	  JVG				 Added DisplayMainSection(blnIsFlashFile) function 
//								 for Plain Template 
// 02/05/08	  SGS	 SIR-1045	 Genesis: Flash 
// 03/19/08   MLAB   SIR-1117	 Genesis: Homepage 5
// 01/15/09	  RPSD	 RMT 142	 Banner Template Change - Adding Flash Right hand side
//*****************************************************************************************

var detectableWithVB = false;

function DetectBrowser()
{

	//use the detectPlugin function for Flash plugins
	pluginFound = detectPlugin('Shockwave','Flash'); 
	
	// if not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB)
    {
		pluginFound = detectActiveXControl('ShockwaveFlash.ShockwaveFlash.1');		
    }
    
    var isEditingMode = isCMSAuthoringMode();
    
    if(!pluginFound && !isEditingMode)
    {		
		//Hides the FlashSection row for Homepage 5 Template
		if(document.getElementById("FlashSection"))
        {
			document.getElementById("FlashSection").style.display="none";
		}

		//Hides the FlashSpacer row for the Homepage 5 Template                    
        if(document.getElementById("FlashSpacer"))
        {
			document.getElementById("FlashSpacer").style.display="none";
        }
	   
	    //Hides the FlashSection row for the Homepage 3 Template
	    if(document.getElementById("HomePage3New_FlashSection"))
        {
			document.getElementById("HomePage3New_FlashSection").style.display="none";
		}
        
        //Hides the FlashSpacer row for the Homepage 3 Template            
        if(document.getElementById("HomePage3New_FlashSpacer"))
        {
			document.getElementById("HomePage3New_FlashSpacer").style.display="none";
        }
	}
	
	if(!pluginFound)
	{
		//Hides the RelatedArticleFlashSection row 
		if(document.getElementById("RelatedArticleFlashSection"))
        {
			document.getElementById("RelatedArticleFlashSection").style.display="none";
		}
		
		//Hides the row containing the flash attachment in the Homepage Advanced template 
		if(document.getElementById("trHomepageFlashSection"))
        {
			document.getElementById("trHomepageFlashSection").style.display="none";
		}
		
		//Hides the row containing the flash object in the Global Right Nav section of the Banner template 
		if(document.getElementById("GlobalRightNavFlashSection"))
		{
			document.getElementById("GlobalRightNavFlashSection").style.display="none";
		}
		
		//Shows the row containing the image for flash accessibility in the Global Right Nav section
		//of the Banner template 
		if(document.getElementById("GlobalRightNavFlashImageSection"))
		{
			document.getElementById("GlobalRightNavFlashImageSection").style.display="block";
		}
	}
}


function DisplayMainSection(blnIsFlashFile, blnFlashError)
{
	//Check for Flash plugins.
	pluginFound = detectPlugin('Shockwave','Flash'); 
	var isEditingMode = isCMSAuthoringMode();	
	
	// If not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB)
    {
		pluginFound = detectActiveXControl('ShockwaveFlash.ShockwaveFlash.1');		
    }
    
	//If plugin is found and posting is in presentation mode, display Flash section 
	//otherwise hide flash section and display nonflash section.	
	if(pluginFound && !isEditingMode)
    {		
		//Displays flash section and hides nonflash section 
		//if flash file is valid.
		if(blnIsFlashFile == 'true')
		{	
			//This will always display valid flash attachments
			if (document.getElementById("trFlashAttachment") != null)
			{
				document.getElementById("trFlashAttachment").style.display="block";
			}
				
			//This will always hide nonflash section if there's 
			//a valid flash attachment				
			if (document.getElementById("trNonFlashImage") != null)
			{
				document.getElementById("trNonFlashImage").style.display="none";			
			}	
			
			//This will always hide nonflash error section in  
			//presentation mode if there's a valid flash attachment
			if (document.getElementById("trNonFlashErrorMessage") != null)
			{
				document.getElementById("trNonFlashErrorMessage").style.display="none";			
			}
			
			//This will display flash dimension error message in presentation mode
			// for invalid flash dimensions
			if(blnFlashError=='true')
			{
				if (document.getElementById("trFlashErrorMessage") != null)
				{
					document.getElementById("trFlashErrorMessage").style.display="block";	
				}
				
				if (document.getElementById("trNonFlashErrorMessage") != null)
				{
					//This will always display NONFlash error message when the page
					//is in authoring reedit mode
					if (window.location.href.indexOf('WBCMODE=AuthoringReedit') != -1)
					{
						document.getElementById("trNonFlashErrorMessage").style.display="block";
					}
					else
					{
					document.getElementById("trNonFlashErrorMessage").style.display="none";		
					}
				}		
			}					
		}	
	}	
	
	//This will always display Flash section and error message in authoring mode
	if(isEditingMode)
	{
		if (document.getElementById("trFlashAttachment") != null)
		{
			document.getElementById("trFlashAttachment").style.display="block";
		}	
		
		if (document.getElementById("trFlashErrorMessage") != null)
		{
			//This will always display the error message of invalid flash dimensions
			//in authorins mode (reedit)
			if(blnIsFlashFile == 'true' && blnFlashError == 'true')
			{
				document.getElementById("trFlashErrorMessage").style.display="block";	
			}
			else
			{
				document.getElementById("trFlashErrorMessage").style.display="none";	
			}
		}
	}		
}

function isCMSAuthoringMode()
{
	if (window.location.href.indexOf('WBCMODE=AuthoringNew') != -1 || window.location.href.indexOf('WBCMODE=AuthoringReedit') != -1)
	{
		return true;
	}
	else
	{
		return false;
	}				
}

function detectPlugin() {
    // allow for multiple checks in a single pass
    var daPlugins = detectPlugin.arguments;
    // consider pluginFound to be false until proven true
    var pluginFound = false;
    // if plugins array is there and not fake
    if (navigator.plugins && navigator.plugins.length > 0) 
    {
		var pluginsArrayLength = navigator.plugins.length;
		// iterate plugins
		for (pluginsArrayCounter=0; pluginsArrayCounter < pluginsArrayLength; pluginsArrayCounter++ )
		 {
			// loop through all desired names and check each against the current plugin name
			var numFound = 0;
			for(namesCounter=0; namesCounter < daPlugins.length; namesCounter++) 
			{
				// if desired plugin name is found in either plugin name or description
				if( (navigator.plugins[pluginsArrayCounter].name.indexOf(daPlugins[namesCounter]) >= 0) || 
				(navigator.plugins[pluginsArrayCounter].description.indexOf(daPlugins[namesCounter]) >= 0) ) 
				{
					// this name was found
					numFound++;
				}   
			}
	    // if the number we found matches the total number provided then we were successful
	    if(numFound == daPlugins.length)
			 {
				pluginFound = true;				
				break;
			 }
		}
    }
    return pluginFound;
}


// VBScript to detect plugins for IE browsers
if ((navigator.userAgent.indexOf('MSIE') != -1) && (navigator.userAgent.indexOf('Win') != -1)) {
    document.writeln('<script language="VBscript">');

    document.writeln('\'do a one-time test for a version of VBScript that can handle this code');
    document.writeln('detectableWithVB = False');
    document.writeln('If ScriptEngineMajorVersion >= 2 then');
    document.writeln('  detectableWithVB = True');
    document.writeln('End If');

    document.writeln('\'this next function will detect most plugins');
    document.writeln('Function detectActiveXControl(activeXControlName)');
    document.writeln('  on error resume next');
    document.writeln('  detectActiveXControl = False');
    document.writeln('  If detectableWithVB Then');
    document.writeln('     detectActiveXControl = IsObject(CreateObject(activeXControlName))');
    document.writeln('  End If');
    document.writeln('End Function');    

    document.writeln('</scr' + 'ipt>');
}

function AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}

function AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
  var str = '<object ';
  for (var i in objAttrs)
    str += i + '="' + objAttrs[i] + '" ';
  str += '>';
  for (var i in params)
    str += '<param name="' + i + '" value="' + params[i] + '" /> ';
  str += '<embed ';
  for (var i in embedAttrs)
    str += i + '="' + embedAttrs[i] + '" ';
  str += ' ></embed></object>';

  document.write(str);
}

function PlayFlash(){
	var ret = 
	AC_GetArgs
	(  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
	, "application/x-shockwave-flash", ""
	); 
	AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);	
}

function AC_SW_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
     , null
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    

    switch (currArg){	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":	
        args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblClick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "id":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}