var mstrBillboardImageFolder = '/_RMVirtual/media/downloads/';
var mstrBillboardHeight = 315;
var mstrBillboardWidth = 415;
var mnumStaticBillboardImageDisplayed;
if (browserName == 'IE') {
	document.write('<style type="text/css">h1, h2, h3 {overflow: hidden} .headernav {margin: 0 3px 0 0} * html .headernav {margin: 1px 2px 0 0} .headerlinks input {margin: -4px 1px -5px 1px; vertical-align: middle} .flashbillboard li {margin: 0; padding: 2px 6px 3px 10px} li.flashmenuon {margin: 0 0 0 -1px; padding: 6px 7px 7px 9px} .shop li img {margin: 5px 0 0 0}</style>')
} else if (browserName == 'OP') {
	document.write('<style type="text/css">body {font-size: 85%} .headerlinks input {margin: -2px 3px -2px 5px} .search {padding: 2px 2px 2px 5px} select, .searchbox {vertical-align: middle; margin: 0 1px 0 1px; padding: 2px; border: 1px solid #3767ad} .button {margin: 0 0 0 2px; vertical-align: middle}</style>')
} else if (browserName == 'SA') {
	document.write('<style type="text/css">.flashbillboard a {padding: 10px 0}</style>')
	if (OS == 'Apple')
	{
		document.write('<style type="text/css">body {font-size: 75%} .headerlinks input {margin: 2px 3px 0 5px} .search select {font-size: 1em; width: 11em} .flashbillboard ul {margin: 283px 10px 0 8px} .flashbillboard li {margin: 0 0 0 -4px} li.flashmenuon {margin: 0 0 0 -5px} .leftcolumn ul, .shop ul {padding: 3px 0 3px 1px} .leftcolumn li, .shop li {line-height: 155%} .infoads p {padding: 4px 6px} .companynews li {padding: 0 2px 7px 3px}</style>')
	}
}

function logDynamicBillboadImageDisplay(pstrData) {
	aData = pstrData.split('|');
	setBillboadImageWACustomVars(aData[0], aData[1], aData[2]);
}
function displayStaticBillboardImage(pstrCaption, pstrHyperLink, pstrSRC, pstrFlashVersionRequired, pstrAlternativeSRC, pnumBillboardImage) {
			
	pnumBillboardImage = Number(pnumBillboardImage);
	var bPageLoaded = (mnumStaticBillboardImageDisplayed != null);
			
	if (!bPageLoaded || mnumStaticBillboardImageDisplayed != pnumBillboardImage) {

		if (pstrSRC.substring(pstrSRC.length - 4).toLowerCase() == '.swf') {
			setFlashMovieAsElementInnerHTML('billboard',
											pstrSRC,
											pstrFlashVersionRequired,
											pstrAlternativeSRC,
											mstrBillboardHeight,
											mstrBillboardWidth, 
											'',
											'',
											pstrHyperLink, 
											pstrCaption,
											'',
											'',
											'',
											'opaque')
		} else {
			document.getElementById('billboard').innerHTML = '<a href=' + pstrHyperLink + '><img src="' + pstrSRC + '" height="' + mstrBillboardHeight + '" width="' + mstrBillboardWidth + '" alt="' + pstrCaption + ' " title="' + pstrCaption + ' " /></a>';
		}


		if (browserJavascript >= '1.3') {
			setBillboadImageWACustomVars(pstrCaption, pstrHyperLink, pstrSRC, bPageLoaded);
		}
		if (bPageLoaded) {
			if (mnumStaticBillboardImageDisplayed == 1) {
				document.getElementById('billboardimage' + mnumStaticBillboardImageDisplayed).className = 'firstflashmenuitem';
			} else {
				document.getElementById('billboardimage' + mnumStaticBillboardImageDisplayed).className = '';
			}
		}
				
		document.getElementById('billboardimage' + pnumBillboardImage).className = 'flashmenuon';
		mnumStaticBillboardImageDisplayed = pnumBillboardImage;
		
				
	}
			
}
			
function setBillboadImageWACustomVars(pstrCaption, pstrHyperLink, pstrSRC, pbLog) {
	
	if (pbLog == null) {
		pbLog = true;
	}
	if (browserJavascript >= '1.3') {
		setWACustomVars('RMComHomeBillboardImageCaption', pstrCaption , false, false);
		setWACustomVars('RMComHomeBillboardImageHyperLink', pstrHyperLink , false, false);
		setWACustomVars('RMComHomeBillboardImageSRC', pstrSRC , pbLog, pbLog);
	}			
}
			
function billboardImageMouseOver(pnumBillboardImage) {
	if (pnumBillboardImage != mnumStaticBillboardImageDisplayed) {
		if (pnumBillboardImage == 1) {
			document.getElementById('billboardimage1').className = 'firstflashmenuitem flashmenuon';
		} else {
			document.getElementById('billboardimage' + pnumBillboardImage).className = 'flashmenuon';
		}
	}
}

function billboardImageMouseOut(pnumBillboardImage) {
	if (pnumBillboardImage != mnumStaticBillboardImageDisplayed) {
		if (pnumBillboardImage == 1) {
			document.getElementById('billboardimage1').className = 'firstflashmenuitem';
		} else {
			document.getElementById('billboardimage' + pnumBillboardImage).className = '';
		}
	}
}

    // convert to upper case
    function ucase(pvString) {
    return getString(pvString).toUpperCase();
    }
    
    
    
    
 var mbFlashDetected = false;
var mbFlash2Installed = false;
var mbFlash3Installed = false;
var mbFlash4Installed = false;
var mbFlash5Installed = false;
var mbFlash6Installed = false;
var mbFlash7Installed = false;
var mbFlash8Installed = false;
var mbFlash9Installed = false;
var mbFlash10Installed = false;
var mbFlash11Installed = false;
var mnumFlashVersionInstalled;


function detectFlashVersionInstalled() {

	// Gecko/Firefox and Opera masquerade as IE, so need to check
	var agent = navigator.userAgent.toLowerCase();
	var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
	var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;		
	var isOpera = (agent.indexOf("opera") != -1);
	var isGecko = (agent.indexOf("gecko") != -1);
	var isAol   = (agent.indexOf("aol") != -1);
	var isFirefox = (agent.indexOf("firefox") != -1);
	var flashVersion = 0;
	var isOldFormatVersion;
	var flashDescription;
	
	if (!mbFlashDetected) {
		if(isIE && isWin && !isOpera && !isGecko && !isFirefox)
		{
			document.write('<scr' + 'ipt language=vbscript type=text/vbscript\> \n');
			document.write('on error resume next \n');
			document.write('mbFlash2Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.2"))) \n');
			document.write('mbFlash3Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.3"))) \n');
			document.write('mbFlash4Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.4"))) \n');
			document.write('mbFlash5Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5"))) \n');  
			document.write('mbFlash6Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6"))) \n');  
			document.write('mbFlash7Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.7"))) \n');
			document.write('mbFlash8Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.8"))) \n');
			document.write('mbFlash9Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.9"))) \n');
			document.write('mbFlash10Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.10"))) \n');
			document.write('mbFlash11Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.11"))) \n');
			document.write('<\/scr' + 'ipt\> \n');

			for (var i = 2; i <= 11; i++) 
			{  
				if (eval("mbFlash" + i + "Installed") == true) {
					mnumFlashVersionInstalled = i;
				}
			}
			if (mnumFlashVersionInstalled > 0){}
			else
			{
			    mnumFlashVersionInstalled=0;
			}
		}
		else 
		{
			// non IE sniffer
			if (navigator.plugins)
			{
				if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"])
				{
					isOldFormatVersion = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
					flashDescription = navigator.plugins["Shockwave Flash" + isOldFormatVersion].description;
					mnumFlashVersionInstalled = parseInt(flashDescription.substring(16));
				}								
			}
				
			// msntv sniffer
			if (navigator.userAgent.indexOf("WebTV") != -1){
				mnumFlashVersionInstalled = 4;
			}
		}
		mbFlashDetected = true;
	}

}

function playFlashMovie(pstrMovieUrl, pstrRequiredVersion, pstrAlternativeImageUrl, pstrMovieHeight, pstrMovieWidth, pstrMovieBaseURL, pstrBackgroundColor, pstrAlternativeImageHyperlink, pstrAlternativeImageDescription, pstrLoop, pstrFlashVars, pstrObjectID, pstrWindowMode, pstrAlternativeImageHeight, pstrAlternativeImageWidth) {

	document.write(getFlashMovieHTML(pstrMovieUrl, pstrRequiredVersion, pstrAlternativeImageUrl, pstrMovieHeight, pstrMovieWidth, pstrMovieBaseURL, pstrBackgroundColor, pstrAlternativeImageHyperlink, pstrAlternativeImageDescription, pstrLoop, pstrFlashVars, pstrObjectID, pstrWindowMode, pstrAlternativeImageHeight, pstrAlternativeImageWidth));

}

function setFlashMovieAsElementInnerHTML(pstrTargetElementID, pstrMovieUrl, pstrRequiredVersion, pstrAlternativeImageUrl, pstrMovieHeight, pstrMovieWidth, pstrMovieBaseURL, pstrBackgroundColor, pstrAlternativeImageHyperlink, pstrAlternativeImageDescription, pstrLoop, pstrFlashVars, pstrObjectID, pstrWindowMode, pstrAlternativeImageHeight, pstrAlternativeImageWidth) {
	document.getElementById(pstrTargetElementID).innerHTML = getFlashMovieHTML(pstrMovieUrl, pstrRequiredVersion, pstrAlternativeImageUrl, pstrMovieHeight, pstrMovieWidth, pstrMovieBaseURL, pstrBackgroundColor, pstrAlternativeImageHyperlink, pstrAlternativeImageDescription, pstrLoop, pstrFlashVars, pstrObjectID, pstrWindowMode, pstrAlternativeImageHeight, pstrAlternativeImageWidth);
}

function getFlashMovieHTML(pstrMovieUrl, pstrRequiredVersion, pstrAlternativeImageUrl, pstrMovieHeight, pstrMovieWidth, pstrMovieBaseURL, pstrBackgroundColor, pstrAlternativeImageHyperlink, pstrAlternativeImageDescription, pstrLoop, pstrFlashVars, pstrObjectID, pstrWindowMode, pstrAlternativeImageHeight, pstrAlternativeImageWidth) {

	var flashMovie;
	var alternateContent;
	var strObjectIDHTML = '';
	
	detectFlashVersionInstalled();
	
	pstrAlternativeImageHyperlink = CSafeStr(pstrAlternativeImageHyperlink);
	pstrAlternativeImageDescription = CSafeStr(pstrAlternativeImageDescription);
	pstrAlternativeImageHeight = CSafeStr(pstrAlternativeImageHeight, pstrMovieHeight);
	pstrAlternativeImageWidth = CSafeStr(pstrAlternativeImageWidth, pstrMovieWidth);

	if (mnumFlashVersionInstalled >= pstrRequiredVersion) {
		
		pstrBackgroundColor = CSafeStr(pstrBackgroundColor, '#FFFFFF');
		pstrMovieBaseURL = CSafeStr(pstrMovieBaseURL);
		pstrLoop = CSafeStr(pstrLoop, 'false');
		pstrFlashVars = CSafeStr(pstrFlashVars);
		pstrObjectID = CSafeStr(pstrObjectID);
		pstrWindowMode = CSafeStr(pstrWindowMode, 'window');
		if (pstrObjectID != '') {
			strObjectIDHTML = 'id="' + pstrObjectID + '" ';
		}
		
		flashMovie = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ' + strObjectIDHTML
						+ 'width="' + pstrMovieWidth + '" height="' + pstrMovieHeight + '" '
						+ ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">'
						+ '<param name="movie" value="' + pstrMovieUrl + '" />'
						+ '<param name="base" value="' + pstrMovieBaseURL + '" />'
						+ '<param name="quality" value="high" />'
						+ '<param name="loop" value="' + pstrLoop + '" />'
						+ '<param name="bgcolor" value="' + pstrBackgroundColor + '" />'
						+ '<param name="menu" value="false" />'
						+ '<param name="scale" value="noscale" />'
						+ '<param name="flashvars" value="' + pstrFlashVars + '" />'
						+ '<param name="wmode" value="' + pstrWindowMode + '" />'
						+ '<embed src="' + pstrMovieUrl + '" '
						+ 'base="' + pstrMovieBaseURL + '" '
						+ 'quality="high" '
						+ 'loop="' + pstrLoop + '" '
						+ 'bgcolor="' + pstrBackgroundColor + '" '
						+ 'width="' + pstrMovieWidth + '" '
						+ 'height="' + pstrMovieHeight + '" '
						+ 'menu="false" '
						+ 'scale="noscale" '
						+ 'type="application/x-shockwave-flash" '
						+ 'flashvars="' + pstrFlashVars + '" '
						+ 'wmode="' + pstrWindowMode + '" '
						+ 'pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">'
						+ '<\/embed>'
						+ '<\/object>';		
														
		return flashMovie;
	} 
	else 
	{  	
		if (pstrAlternativeImageHyperlink != '')
		{			
			alternateContent = '<a href=' + pstrAlternativeImageHyperlink + '><img src="' + pstrAlternativeImageUrl + '" class="flashrequiredimage" height="' + pstrAlternativeImageHeight + '" width="' + pstrAlternativeImageWidth + '" alt="' + pstrAlternativeImageDescription + ' " title="' + pstrAlternativeImageDescription + ' " /></a>';
			
		}
		else
		{
			alternateContent = '<a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash"><img src="' + pstrAlternativeImageUrl + '" class="flashrequiredimage" height="' + pstrAlternativeImageHeight + '" width="' + pstrAlternativeImageWidth + '" alt="This page requires Adobe Flash Player version ' + pstrRequiredVersion + ' or higher - Get the latest version now..." /></a>';
		}

		return alternateContent;
	}


}

function CSafeStr(pstrStringToConvert, pstrDefault) {
	if (pstrDefault == null) {
		pstrDefault = '';
	}
	if (pstrStringToConvert == null || pstrStringToConvert == '') {
		return pstrDefault;
	} else {
		return pstrStringToConvert
	}
}

var mbShowFlash;
function ShowFlash(pnumFlashVersion)
    {   
        if (mnumFlashVersionInstalled >= pnumFlashVersion && browserName != 'SA') 
        {
           mbShowFlash = true;
         }
         else
         {
            mbShowFlash = false;
         }
    }
    
var mbShowBannerFlash;
function ShowBannerFlash(pbFlashAvailable,pstrFlashVersion)
{
    if (pbFlashAvailable == true && mnumFlashVersionInstalled >= pstrFlashVersion && browserName != 'SA')
    {
        mbShowBannerFlash = true;
    }
    else
    {
        mbShowBannerFlash = false;
    }    
}

function EncodeURL(pstrURL)
{
    var strURL = pstrURL.replace(' ', '%20');
    return strURL.replace('&#163;','%A3');
}

strSearchText = '';

// Non-Internal search	
function submitWHSearch(pbRMCOM, pbUseHTTPS) {
	var strSearchString;
	var strProtocolAndWebSitename;

	//Reg Expr for matching technical article
	reContentRef = /^(mta|tec|prd|dwn|nws|mpr)\d{4}/i;
	
	if (pbUseHTTPS == null) {
		strProtocolAndWebSitename = '';
	} else if (pbUseHTTPS == true) {
		strProtocolAndWebSitename = 'https://' + window.location.hostname;
	} else {
		strProtocolAndWebSitename = 'http://' + window.location.hostname;
	}	
	
	// Support VAE, if search looks like a technical article content ref, open it.
	if (checkWHSearch(pbRMCOM))	{
		if(pbRMCOM) {
			strSearchString = document.frmWHSearchForm.elements['inpSearchCriteria'].value;
		}
		else {
			strSearchString = document.frmWHSearchForm.elements['inpSearchString'].value;
		}
        
		if(reContentRef.test(strSearchString)) {
			window.open(strProtocolAndWebSitename + '/_RMVirtual/Includes/CSRedirect.asp?nav=0&cref=' + strSearchString, "", "scrollbars=Yes, resizable=Yes, toolbar=Yes, menubar=Yes, location=no, directories=no, width=670,height=500,left=40,top=40");			
			return false;
		}
		else if (document.frmWHSearchForm.inpSector && document.frmWHSearchForm.inpSector.options[document.frmWHSearchForm.inpSector.selectedIndex].text == 'Shop') {
	
	        // Shop is not a sector, so submit to shop search directly
	        document.frmWHSearchForm.action = strProtocolAndWebSitename + 
	                                          strPortalRmShop + '/range.aspx?srcurl=/rmcomhome.aspx&search=' + 
	                                          escape(strSearchString);
			document.frmWHSearchForm.submit();
        }
        else {
			if (document.frmWHSearchForm.inpSector && document.frmWHSearchForm.inpSector.options[document.frmWHSearchForm.inpSector.selectedIndex].text == 'Support') {
				document.frmWHSearchForm.inpSearchString.value = strSearchString;
				document.frmWHSearchForm.action = strProtocolAndWebSitename + '/Support/KnowledgeLibrary.asp';
			}
			document.frmWHSearchForm.submit();
		}
	}
	else { 
	    return false
	}
}

function checkWHSearch(pbRMCOM) 
{
	if (pbRMCOM == true) 
	{
		// use inpSearchCriteria	
		if (document.frmWHSearchForm.inpSector && document.frmWHSearchForm.inpSector.options[document.frmWHSearchForm.inpSector.selectedIndex].text.charAt(0) == '-')
		{
			alert('Please select an area of the site to search within.');
			return false;
		}
		if (document.frmWHSearchForm.inpCategory && document.frmWHSearchForm.inpCategory.options[document.frmWHSearchForm.inpCategory.selectedIndex].text.charAt(0) == '-')
		{
			alert('Please select a part of this area to search within.');
			return false;
		}
		if ((document.frmWHSearchForm.elements['inpSearchCriteria'].value == strSearchText) ||
		    (document.frmWHSearchForm.elements['inpSearchCriteria'].value == ''))
		{
			alert('Please input your search criteria.');
			return false;
		}
		else
		{
			return true;
		}
	}
	else 
	{
		if ((document.frmWHSearchForm.elements['inpSearchString'].value == strSearchText) ||
		    (document.frmWHSearchForm.elements['inpSearchString'].value == ''))
		{
			alert('Please input your search criteria.');
			return false;
		}
		else
		{
			return true;
		}	
	}
}