
//SAP Flash JavaScript Routines...
//10.16.07 (Last Edit: 6.18.09 - sapMediaPlayer_V2 functions)
//Vince


/**
 * SWFObject v1.5: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
 *
 * SWFObject is (c) 2007 Geoff Stearns and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 */
if(typeof deconcept=="undefined"){var deconcept=new Object();}if(typeof deconcept.util=="undefined"){deconcept.util=new Object();}if(typeof deconcept.SWFObjectUtil=="undefined"){deconcept.SWFObjectUtil=new Object();}deconcept.SWFObject=function(_1,id,w,h,_5,c,_7,_8,_9,_a){if(!document.getElementById){return;}this.DETECT_KEY=_a?_a:"detectflash";this.skipDetect=deconcept.util.getRequestParameter(this.DETECT_KEY);this.params=new Object();this.variables=new Object();this.attributes=new Array();if(_1){this.setAttribute("swf",_1);}if(id){this.setAttribute("id",id);}if(w){this.setAttribute("width",w);}if(h){this.setAttribute("height",h);}if(_5){this.setAttribute("version",new deconcept.PlayerVersion(_5.toString().split(".")));}this.installedVer=deconcept.SWFObjectUtil.getPlayerVersion();if(!window.opera&&document.all&&this.installedVer.major>7){deconcept.SWFObject.doPrepUnload=true;}if(c){this.addParam("bgcolor",c);}var q=_7?_7:"high";this.addParam("quality",q);this.setAttribute("useExpressInstall",false);this.setAttribute("doExpressInstall",false);var _c=(_8)?_8:window.location;this.setAttribute("xiRedirectUrl",_c);this.setAttribute("redirectUrl","");if(_9){this.setAttribute("redirectUrl",_9);}};deconcept.SWFObject.prototype={useExpressInstall:function(_d){this.xiSWFPath=!_d?"expressinstall.swf":_d;this.setAttribute("useExpressInstall",true);},setAttribute:function(_e,_f){this.attributes[_e]=_f;},getAttribute:function(_10){return this.attributes[_10];},addParam:function(_11,_12){this.params[_11]=_12;},getParams:function(){return this.params;},addVariable:function(_13,_14){this.variables[_13]=_14;},getVariable:function(_15){return this.variables[_15];},getVariables:function(){return this.variables;},getVariablePairs:function(){var _16=new Array();var key;var _18=this.getVariables();for(key in _18){_16[_16.length]=key+"="+_18[key];}return _16;},getSWFHTML:function(){var _19="";if(navigator.plugins&&navigator.mimeTypes&&navigator.mimeTypes.length){if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","PlugIn");this.setAttribute("swf",this.xiSWFPath);}_19="<embed type=\"application/x-shockwave-flash\" src=\""+this.getAttribute("swf")+"\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+this.getAttribute("style")+"\"";_19+=" id=\""+this.getAttribute("id")+"\" name=\""+this.getAttribute("id")+"\" ";var _1a=this.getParams();for(var key in _1a){_19+=[key]+"=\""+_1a[key]+"\" ";}var _1c=this.getVariablePairs().join("&");if(_1c.length>0){_19+="flashvars=\""+_1c+"\"";}_19+="/>";}else{if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","ActiveX");this.setAttribute("swf",this.xiSWFPath);}_19="<object id=\""+this.getAttribute("id")+"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+this.getAttribute("style")+"\">";_19+="<param name=\"movie\" value=\""+this.getAttribute("swf")+"\" />";var _1d=this.getParams();for(var key in _1d){_19+="<param name=\""+key+"\" value=\""+_1d[key]+"\" />";}var _1f=this.getVariablePairs().join("&");if(_1f.length>0){_19+="<param name=\"flashvars\" value=\""+_1f+"\" />";}_19+="</object>";}return _19;},write:function(_20){if(this.getAttribute("useExpressInstall")){var _21=new deconcept.PlayerVersion([6,0,65]);if(this.installedVer.versionIsValid(_21)&&!this.installedVer.versionIsValid(this.getAttribute("version"))){this.setAttribute("doExpressInstall",true);this.addVariable("MMredirectURL",escape(this.getAttribute("xiRedirectUrl")));document.title=document.title.slice(0,47)+" - Flash Player Installation";this.addVariable("MMdoctitle",document.title);}}if(this.skipDetect||this.getAttribute("doExpressInstall")||this.installedVer.versionIsValid(this.getAttribute("version"))){var n=(typeof _20=="string")?document.getElementById(_20):_20;n.innerHTML=this.getSWFHTML();return true;}else{if(this.getAttribute("redirectUrl")!=""){document.location.replace(this.getAttribute("redirectUrl"));}}return false;}};deconcept.SWFObjectUtil.getPlayerVersion=function(){var _23=new deconcept.PlayerVersion([0,0,0]);if(navigator.plugins&&navigator.mimeTypes.length){var x=navigator.plugins["Shockwave Flash"];if(x&&x.description){_23=new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/,"").replace(/(\s+r|\s+b[0-9]+)/,".").split("."));}}else{if(navigator.userAgent&&navigator.userAgent.indexOf("Windows CE")>=0){var axo=1;var _26=3;while(axo){try{_26++;axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+_26);_23=new deconcept.PlayerVersion([_26,0,0]);}catch(e){axo=null;}}}else{try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");}catch(e){try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");_23=new deconcept.PlayerVersion([6,0,21]);axo.AllowScriptAccess="always";}catch(e){if(_23.major==6){return _23;}}try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");}catch(e){}}if(axo!=null){_23=new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));}}}return _23;};deconcept.PlayerVersion=function(_29){this.major=_29[0]!=null?parseInt(_29[0]):0;this.minor=_29[1]!=null?parseInt(_29[1]):0;this.rev=_29[2]!=null?parseInt(_29[2]):0;};deconcept.PlayerVersion.prototype.versionIsValid=function(fv){if(this.major<fv.major){return false;}if(this.major>fv.major){return true;}if(this.minor<fv.minor){return false;}if(this.minor>fv.minor){return true;}if(this.rev<fv.rev){return false;}return true;};deconcept.util={getRequestParameter:function(_2b){var q=document.location.search||document.location.hash;if(_2b==null){return q;}if(q){var _2d=q.substring(1).split("&");for(var i=0;i<_2d.length;i++){if(_2d[i].substring(0,_2d[i].indexOf("="))==_2b){return _2d[i].substring((_2d[i].indexOf("=")+1));}}}return "";}};deconcept.SWFObjectUtil.cleanupSWFs=function(){var _2f=document.getElementsByTagName("OBJECT");for(var i=_2f.length-1;i>=0;i--){_2f[i].style.display="none";for(var x in _2f[i]){if(typeof _2f[i][x]=="function"){_2f[i][x]=function(){};}}}};if(deconcept.SWFObject.doPrepUnload){if(!deconcept.unloadSet){deconcept.SWFObjectUtil.prepUnload=function(){__flash_unloadHandler=function(){};__flash_savedUnloadHandler=function(){};window.attachEvent("onunload",deconcept.SWFObjectUtil.cleanupSWFs);};window.attachEvent("onbeforeunload",deconcept.SWFObjectUtil.prepUnload);deconcept.unloadSet=true;}}if(!document.getElementById&&document.all){document.getElementById=function(id){return document.all[id];};}var getQueryParamValue=deconcept.util.getRequestParameter;var FlashObject=deconcept.SWFObject;var SWFObject=deconcept.SWFObject;




//SWF Form Fix - solves the External Interface calls within a FORM tag in IE:
//
//Add this line to the END of SWFobject (after so.write("flashcontent"); ):
//
//SWFFormFix("myFlashObject");

SWFFormFixAuto = function(){
	if(navigator.appName.toLowerCase() != "microsoft internet explorer")return true;
	var objects = document.getElementsByTagName("object");
	if(objects.length == 0) return true;
	for(i=0;i<objects.length;i++){
		// here's all the objects on the page, now lets find the flash objects
		if(objects[i].classid == "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"){
			// this is a flash movie, apply the fix
			window[objects[i].id] = objects[i];
		}
	}
	var out = '';
	return true;
}
SWFFormFix = function(swfname){
	if(navigator.appName.toLowerCase() != "microsoft internet explorer")return false;
	var testnodename = "SWFFormFixTESTER";
	document.write('<div id="'+testnodename+'" onclick="SWFFormFixCallback(this,\''+swfname+'\');return false;" style="display:none">&nbsp;</div>');
	document.getElementById(testnodename).onclick();
}
SWFFormFixCallback = function (obj,swfname){
	var path = document;
	var error = false;
	var testnode = obj;
	while(obj = obj.parentNode){
		if(obj.nodeName.toLowerCase() == "form"){
			if(obj.name != undefined && obj.name != null && obj.name.length > 0){
				path = path.forms[obj.name];
			}else{
				alert("Error: one of your forms does not have a name!");
				error = true;
			}
		}
	}
	testnode.parentNode.removeChild(testnode);
	if(error) return false;
	window[swfname]=path[swfname];
	return true;
}



var nn4 = (document.layers) ? true : false
var ie = (document.all) ? true : false
var dom = (document.getElementById && !document.all) ? true : false


function getLayer(id){
	return browser(id);	
}

function browser(id){
  if(nn4) {
	  path = document.layers[id]
  }
  else if(ie) {
	  path = document.all[id]
	  bonus = 0;
  }
  else {
	  path = document.getElementById(id)
	  bonus = 3;
  }
return path  //return the path to the css layer depending on which browser is looking at the page
}



function rescaleFlash(id, fwidth, fheight) {
	var layer = browser(id) // get browser specific path to block element
	if (fheight > -1) {
		if(nn4){
			layer.height = fheight + bonus;
		}
		else{
			layer.style.height = fheight + bonus;
		}
		document[id].height = fheight + bonus;
	}
	if (fwidth > -1) {
		if(nn4){
			layer.width = fwidth;
		}
		else{
			layer.style.width = fwidth;
		}
		document[id].width = fwidth;
	}
}


function thisMovie(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName]
    }
    else {
        return document[movieName]
    }
}


function getMyColor(elementName)
{
	//return now if id not found
	if(document.getElementById(elementName) == null)
	{
		return null
	}
	var getColorName = document.getElementById(elementName).className;
	var findExact = ".Font"+getColorName;
	var ss = document.styleSheets[0];
	var rules = ss.cssRules?ss.cssRules:ss.rules;
	for(var i = 0; i < rules.length; i++)
	{
		var rule = rules[i];
		if(rule.selectorText == findExact)
		{
			var color = rule.style.color;
			if(color)
			{
				return color;
			}
		}
	}
}

function getMyColor2(colorScheme)
{
	var getColorName = colorScheme;
	var findExact = ".Font"+getColorName;
	var ss = document.styleSheets[0];
	var rules = ss.cssRules?ss.cssRules:ss.rules;
	for(var i = 0; i < rules.length; i++)
	{
		var rule = rules[i];
		if(rule.selectorText == findExact)
		{
			var color = rule.style.color;
		if(color)
			{
				return color;
			}
		}
	}
}



//ADDITIONS: 3.11.09 ***********************************************************8

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();



function browserWindowSize() {
	//gets browserWindowSize for all IEs and FFs.
	
	//browserWindowSize()[0] = width
	//browserWindowSize()[1] = height
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	return [ myWidth, myHeight ];
}




function hideTheLayer(theLayer, doWhat) {
	var fLayer = getLayer(theLayer);
	if(nn4){
		//For Netscrape
		fLayer.style.visibility = doWhat;
	} else {
		//FireFox and IE
		fLayer.style.visibility = doWhat;
	}
}




//SAP Media Player JavaScript for DHTML controls...
//02.23.09
//Vince

var playerType = "sap";
var iemove = "";

function ie6layerSet() {
	//This must be called on Body onLoad...  resets the layer for IE6
	if ((BrowserDetect.browser == "Explorer" && BrowserDetect.version == 6)) {
		//set the layer to absolute for IE6 
		var fLayer = getLayer('mp_flashSpace');
		fLayer.style.position = "absolute";
		
		//Set interval for IE6 to move the layer 
		iemove = window.setInterval(move_box, 200);
	}	
}


function move_box() {
	//half the layer height as offset is the top of the screen.
	//add half the browserWindowSize minus the layer height and it's centered
   var offset = ((392 / 2) + ((browserWindowSize()[1] - 392) / 2)); 
   var fLayer = getLayer('mp_flashSpace');
   fLayer.style.top = (document.documentElement.scrollTop + offset) + 'px';
}


function getHeight() {
	if (BrowserDetect.browser == "Explorer") {
		//alert(document.documentElement.scrollHeight);
		return(document.documentElement.scrollHeight);
	} else {
		return(document.body.scrollHeight);
	}

	//document.documentElement.offsetHeight
	//document.documentElement.scrollHeight
	//document.body.scrollHeight
}
	

function showMediaPlayer() {
		
	//Show the 2 layers
	hideTheLayer('mp_flashSpace', 'visible');
	hideTheLayer('theDiv', 'visible');
	
	//Set the height of the gray div to the size of the page
	var fLayer = getLayer('theDiv');
	fLayer.style.height = getHeight() + 'px';
	
	if (arguments[0] != true) { // optional Paramter - true/false - "Is not SWF"
		//Start the interval to activate flash
		der = setInterval(playIt, 200);
	}
}


function alloyHide(theData) {	
	hideTheLayer('mp_flashSpace', 'hidden');
	hideTheLayer('theDiv', 'hidden');
	removeDiv();
}

function divClose() {
	//Call the remoteClose ExternalInterface Function in Flash.
	thisMovie("sapMediaPlayer").remoteClose(); 
}


function playIt(){
	
	thisMovie("sapMediaPlayer").startItUp(); 
	clearInterval(der);
}


//Required for JS calls to control the player...
function mediaPlayerRemoteCall(movieName, callType, rangeStart, rangeEnd) {
	if (callType == "playpause") {
		thisMovie(movieName).mediaPlayerRemoteCall(callType, "", "");
	} else if (callType == "setRange") {
		thisMovie(movieName).mediaPlayerRemoteCall(callType, rangeStart, rangeEnd);
	} else if (callType == "seekTo") {
		thisMovie(movieName).mediaPlayerRemoteCall(callType, rangeStart, "");
	} else {
		//Do nothing, improper JS call...
	}
}




function writeDHTMLlayer(theXMLlocation, playerType, swfWidth, swfHeight, pathToSwf, originalPath) {	
	
	flashDataDiv = arguments[6]; // optional Paramter
	
	theLayerCode = "";
	swfWidthINT = parseInt(swfWidth);
	swfHeightINT = parseInt(swfHeight);

	//make the DIVs - Layers...
	theLayerCode += '<div id="theDiv" onclick="divClose();" style="cursor: pointer;">&nbsp;</div>';
	
	theLayerCode += '<div id="mp_flashSpace"><div id="mediaPlayerLayer">';
	
	//No Flash Content HTML below...
	theLayerCode += '<table width="' + swfWidthINT + '" border="1" cellpadding="5" bordercolor="#698797" bgcolor="#FFFFFF"><tr><td height="' + swfHeightINT + '" valign="middle">'
	theLayerCode += '<table width="' + (swfWidthINT - 40) + '" border="0" align="center"><tr><td>'
	theLayerCode += '<p class="nf_style2">Missing Or Older Version of Adobe\'s Flash Player Detected</span></p>'
	theLayerCode += '<p><span class="nf_style1">You do not have the Adobe Flash Player needed to view this SAP Video. Please download it by following this <a href="http://get.adobe.com/flashplayer" target="_blank">link</a>.<br/>If you prefer, please follow the links on this page to save this SAP Video in the format of your choice. </span> </p>';
	theLayerCode += '<p class="nf_style1"><a href="JavaScript:alloyHide(\'nothing\');">Click here</a> to close this window.</p>'
	theLayerCode += '</td></tr></table>';
	theLayerCode += '</td></tr></table>';
	
	
	theLayerCode += '</div></div>';
	
	//Set the Styles
	theLayerCode += '<style type="text/css">';
	
	theLayerCode +='#theDiv {position:absolute;opacity: .8;-moz-opacity: .8;top: 0px;left: 0px;filter: alpha(opacity=80);height: 100%;width: 100%;background-color: #333333;z-index: 33;visibility: hidden;}';
	theLayerCode += '#mp_flashSpace {position:fixed;top: 50%;left: 50%;margin-top: -' + swfHeightINT/2 + 'px; /*set to a negative number 1/2 of height*/ margin-left: -' + swfWidthINT/2 + 'px; /*set to a negative number 1/2 of width*/ background-color: #FFFFFF; padding:0px; z-index: 34; visibility: hidden; width:' + swfWidthINT + 'px;}'
	theLayerCode += '#mediaPlayerLayer { width:100%; height:100%;}';
	theLayerCode += '.nf_style1 {font-family: Arial, Helvetica, sans-serif;	font-size: 12px;}';
	theLayerCode += '.nf_style2 {font-family: Arial, Helvetica, sans-serif;	color: #698797;	font-size: 19px; font-style: bold; font-weight: bold;}';
	
	theLayerCode += '</style>';
	
	

	//Below, this doesn't work:
	//document.getElementsByTagName('body').item(0).innerHTML+=theLayerCode;
	
	//This is the proper method to insert the code
	var myElement = document.createElement('div');
	myElement.id = "newMediaPlayerLayer";
	myElement.innerHTML = theLayerCode;
	document.getElementsByTagName('body').item(0).appendChild(myElement);
	
	
	
	//IE Style Fixes
	var fLayer = getLayer('mp_flashSpace');
	
	fLayer.style.left = "50%";
	fLayer.style.marginLeft = "-" + swfWidthINT/2 + "px";
	fLayer.width = swfWidthINT + "px";

	//start the IE 6 fix horizontal scroll.
	ie6layerSet();
		

	//SWF Object 1.5 Embed Code	
	//swfName = "sapMediaPlayer.swf?rdm=" + Math.random()*9999; //Attempting to prevent the same SWF from loading
	if (pathToSwf == "/") {
		swfName = "/global/swf/sapMediaPlayer_V2.swf"
	} else {
		swfName = pathToSwf + "global/swf/sapMediaPlayer.swf"
	}
	//alert("pathToSwf: " + pathToSwf);
	//alert("theXMLlocation: " + theXMLlocation);
	//alert("originalPath: " + originalPath);
	
	
	flashObjectName = "sapMediaPlayer";
	var fo = new SWFObject(swfName, flashObjectName, swfWidth, swfHeight, "9.0.115", "#FFFFFF");
	
	fo.addVariable("coName", playerType);
	fo.addVariable("dhtml", "true");
	
	
	if (flashDataDiv == undefined || flashDataDiv == "") {
		fo.addVariable("xmlFile", theXMLlocation);
	} else {
		//it's xHTML
		fo.addVariable("theXHTMLloc", theXMLlocation);
		fo.addVariable("flashDataDiv", flashDataDiv);
	}
	fo.addVariable("originalPath", originalPath);
	
	if (playerType == "demoTemp") {
		//fo.addVariable("videoWidth", "800");
		//fo.addVariable("videoHeight", "500");
		fo.addVariable("videoWidth", swfWidth - 32);
		fo.addVariable("videoHeight", swfHeight - 32);
	} else {
		fo.addVariable("videoWidth", "640");
		fo.addVariable("videoHeight", "360");
	}
	
	fo.addParam("allowFullScreen", "true");
	fo.addParam("wmode", "false");
	fo.addParam("swfliveconnect", true);
	
	fo.write("mediaPlayerLayer");
	//SWFFormFix(flashObjectName);

	showMediaPlayer();
	
}


function removeDiv() {
	//Remove the Interval for IE 6 if it's running.
	if (BrowserDetect.browser == "Explorer" && BrowserDetect.version == 6) {	
		clearInterval(iemove); //Clear the IE6 Interval
	}
	//Remove The DIV from the bottom of the body's HTML
	var swfDiv = getLayer('newMediaPlayerLayer');
	document.getElementsByTagName('body').item(0).removeChild(swfDiv);
	
}


function pToSWF(loc) {
	var theURL = window.location + ""; //need the +"" to convert it into a string...
	tempArray2 = theURL.split("/");
	totalNumOfSlashes = (tempArray2.length - 1);
	pathUp = totalNumOfSlashes - 3;
	
	var pathToSwf = "";
	//var originalPath = "";
	
	for (q=0; q<pathUp; q++){
		pathToSwf += "../";	
	}	
	return pathToSwf;
}


function pLocation(pageLocation) {
	//this is the url rewritten with teh URL located in window.location. Need for load balancing (www vs. www12)
	tempArray = window.location.toString().split("/"); //tempArray[2] is the actual domain...
	tempArray2 = pageLocation.split("/");

	rebuild ="";
	
	for (q=0; q<tempArray2.length; q++){
		if (q != 2) {
			rebuild += tempArray2[q];
		} else {
			rebuild += tempArray[2];
		}
		
		if (q <  tempArray2.length - 1) {
			rebuild += "/";
		}
	}

	return rebuild;
}


function isInLinePlaying(isIt) {
	if (isIt == "true") {
		inLinePlaying = true;
	} else {
		inLinePlaying = false;
	}
}



function openPDFlayer(pdfLocation, pdfWidth, pdfHeight) {
	
	theLayerCode = "";
	swfWidthINT = parseInt(pdfWidth);
	swfHeightINT = parseInt(pdfHeight);

	//make the DIVs - Layers...
	theLayerCode += '<div id="theDiv" onclick="alloyHide(123);" style="cursor: pointer;">&nbsp;</div>';
	
	theLayerCode += '<div id="mp_flashSpace"><div id="mediaPlayerLayer">';
	
		//No Flash Content HTML below...
	theLayerCode += '<table width="' + swfWidthINT + '" border="1" cellpadding="5" bordercolor="#698797" bgcolor="#FFFFFF"><tr><td height="' + swfHeightINT + '" valign="middle">'
	theLayerCode += '<table width="' + (swfWidthINT - 40) + '" border="0" align="center"><tr><td>'
	theLayerCode += '<embed style="z-index: -1;" id=jmcPDF" src="http://www.adobe.com/products/acrobat/pdfs/pdfaccess.pdf" width="' + swfWidthINT + '" height="' + swfHeightINT + '"></embed>'
theLayerCode += '<center><p class="nf_style1"><a href="" onclick="alloyHide(123);return false;" class="nf_style1">Click Here</a> to close this window.</p></center>';
	theLayerCode += '</td></tr></table>';
	theLayerCode += '</td></tr></table>';
	
	
	theLayerCode += '</div></div>';
	
	//Set the Styles
	theLayerCode += '<style type="text/css">';
	
	theLayerCode +='#theDiv {position:absolute;opacity: .8;-moz-opacity: .8;top: 0px;left: 0px;filter: alpha(opacity=80);height: 100%;width: 100%;background-color: #333333;z-index: 33;visibility: hidden;}';
	theLayerCode += '#mp_flashSpace {position:fixed;top: 50%;left: 50%;margin-top: -' + swfHeightINT/2 + 'px; /*set to a negative number 1/2 of height*/ margin-left: -' + swfWidthINT/2 + 'px; /*set to a negative number 1/2 of width*/ background-color: #FFFFFF; padding:0px; z-index: 34; visibility: hidden; width:' + swfWidthINT + 'px;}'
	theLayerCode += '#mediaPlayerLayer { width:100%; height:100%;}';
	theLayerCode += '.nf_style1 {font-family: Arial, Helvetica, sans-serif;	color: #000000; font-size: 12px;}';
	
	theLayerCode += '</style>';
	
	//This is the proper method to insert the code
	var myElement = document.createElement('div');
	myElement.id = "newMediaPlayerLayer";
	myElement.innerHTML = theLayerCode;
	document.getElementsByTagName('body').item(0).appendChild(myElement);
	
	
	showMediaPlayer(true);
	
	//  <embed style="z-index: -1;" id=jmcPDF" src="http://www.adobe.com/products/acrobat/pdfs/pdfaccess.pdf" width="500" height="375"></embed>
}


function openMediaPlayer(dataLocation, mediaType, parameters) {

	//Parse Paramters
	var parsedParm = new Array();
	
	var params = parameters.split(',');
	for (var i=0; i<params.length; i++) {
		var pos = params[i].indexOf('=');
		if (pos > 0) {
			var key = params[i].substring(0,pos);
			var val = params[i].substring(pos+1);
			parsedParm[key] = val;
		}
	}
		
	optionOne = "";
	optionTwo = "";
	optionThree = "";
	
	if (mediaType == "newWin_XML") {
		//Open New Window and load XML
		
		optionOne += '/demos/mmov/mediaPlayerMaster_01.html?xml_Location=' + dataLocation + '&swf_height=' + parsedParm['height'] + '&swf_width=' + parsedParm['width'];
		
		
		optionTwo += "mediaPlayerWindow";
		
		optionThree += "width=" + parsedParm['width'] + ",height=" + parsedParm['height'];

		//Seek To Options
		if (parsedParm['seekTo']) {
			optionOne += "&seekTo=" + parsedParm['seekTo'];
		}
		
		//Mark Range Options
		if (parsedParm['markRange']) {
			optionOne += "&markRange=" + parsedParm['markRange'];
		}
		
		//Pop Open the Window:
		window.open(optionOne, optionTwo, optionThree);
		
	} else if (mediaType == "dhtml_XML") {
		
		playerType = "demoTemp"; 
		
		swfWidth = parseInt(parsedParm['width']) + 32; //16 pixel border 'round the edge...
		swfHeight = parseInt(parsedParm['height']) + 32;
		
		pathToSwf = "/"; //Mark for V2
		originalPath = ""; //V2 does not need orginal paths... all paths should be 'root absolute'.
		
		//Write the DHTML Layer:
		writeDHTMLlayer(dataLocation, playerType, swfWidth, swfHeight, pathToSwf, originalPath);
		
	} else if (mediaType == "newWin_XHTML") {
				
		flashDataDiv = parsedParm['flashDataDiv'];
		
		optionOne += '/demos/mmov/mediaPlayerMaster_01.html?theXHTMLloc=' + dataLocation + '&flashDataDiv=' + flashDataDiv + '&swf_height=' + parsedParm['height'] + '&swf_width=' + parsedParm['width'];
		
		optionTwo += "mediaPlayerWindow";
		
		optionThree += "width=" + parsedParm['width'] + ",height=" + parsedParm['height'];

		//Seek To Options
		if (parsedParm['seekTo']) {
			optionOne += "&seekTo=" + parsedParm['seekTo'];
		}
		
		//Mark Range Options
		if (parsedParm['markRange']) {
			optionOne += "&markRange=" + parsedParm['markRange'];
		}
		
		//Pop Open the Window:
		window.open(optionOne, optionTwo, optionThree);

	} else if (mediaType == "dhtml_XHTML") {
		
		playerType = "demoTemp"; 
		flashDataDiv = parsedParm['flashDataDiv'];
		
		swfWidth = parseInt(parsedParm['width']) + 32; //16 pixel border 'round the edge...
		swfHeight = parseInt(parsedParm['height']) + 32;
		
		pathToSwf = "/"; //Mark for V2
		originalPath = ""; //V2 does not need orginal paths... all paths should be 'root absolute'.
		
		//Write the DHTML Layer:
		writeDHTMLlayer(dataLocation, playerType, swfWidth, swfHeight, pathToSwf, originalPath, flashDataDiv);
		
	} else if (mediaType == "dhtml_PDF") {	
		
		openPDFlayer(dataLocation, parsedParm['width'], parsedParm['height']);
		
	} else {
		
	
	}
	
	
}



function openBrWindow(theURL, winName, theSize) {

	
	theURLarray = theURL.split("?");
	theTempArray = theURLarray[0].split("/");
	//theHTMLpage = theURLarray[0].substring(theURLarray[0].length,theURLarray[0].length-18);
	theHTMLpage = theTempArray[theTempArray.length - 1];

	
	if (theHTMLpage == "presentation_2.htm") {
		//a video using the old video player... use the DHTML sap_mediaPlayer_v2 version:
		
			tempArray = theURLarray[1].split("&");
			tempArray2 = tempArray[1].split("=");
			xml_Location = tempArray2[1];
		
		
		pathToSwf = pToSWF(theURL);				
		
		if (winName == "newWin") {
			//Replacing the old player - No left Side Data
			swfWidth = "672";
			swfHeight = "392";	
			playerType = "noData";
		} else {
			swfWidth = "972";
			swfHeight = "392";	
			playerType = "sap";
		}
		
		
		
		pageLocation = pLocation(theURLarray[0].substring(0,theURLarray[0].search('/presentation_2.htm'))); //Take the page location, remove the /presentation_2.htm
		
		xml_Location = pageLocation + "/" + xml_Location; //And the pageLocation to the xml_Location for absolute URL
		originalPath = pageLocation;
		
		//Pause inLine Player If Needed
		if (thisMovie("sapMediaPlayer_top")) {
			
			if (inLinePlaying == true) {
				thisMovie("sapMediaPlayer_top").remotePause(); 
				inLinePlaying = false;
			}
		
		}
		
		writeDHTMLlayer(xml_Location, playerType, swfWidth, swfHeight, pathToSwf, originalPath);
	
	} else if (theHTMLpage == "demoPlayMaster2.html") {
		//Demo Player...
		
		//Get the Width and Height of the video...
		tempArray = theSize.split(",");
		tempArray2 = tempArray[0].split("=");
		theWidth = tempArray2[1];
		tempArray2 = tempArray[1].split("=");
		theHeight = tempArray2[1];
		
		//Get the XML location...
		tempArray = theURLarray[1].split("&");
		tempArray2 = tempArray[1].split("=");
		xml_Location = tempArray2[1];
		
		//Find the relative path to the SWF. (/global/swf/)
		pathToSwf = pToSWF(theURL);
		
		
		swfWidth = parseInt(theWidth) + 32; //16 pixel border 'round the edge...
		swfHeight = parseInt(theHeight) + 32;	
		playerType = "demoTemp";
		
		
		pageLocation = pLocation(theURLarray[0].substring(0,theURLarray[0].search('/demoPlayMaster2.html'))); //Take the page location, remove the /demoPlayMaster2.html
				
		
		xml_Location = pageLocation + "/" + xml_Location; //And the pageLocation to the xml_Location for absolute URL
		originalPath = pageLocation;
		
		//Pause inLine Player If Needed
		if (thisMovie("sapMediaPlayer_top")) {
			
			if (inLinePlaying == true) {
				thisMovie("sapMediaPlayer_top").remotePause(); 
				inLinePlaying = false;
			}
		
		}
		
		
		writeDHTMLlayer(xml_Location, playerType, swfWidth, swfHeight, pathToSwf, originalPath);
		
	
	} else {
		//NOT a video... use old openBRWindow code:
		window.open(theURL,winName,theSize);		
	}
	
}


var inLinePlayerControls = {
	
	init: function () {
		this.isInlinePlaying = false;
		this.playingInlineSWF = "";
	},
	
	setPlaying: function(swfObj) {
		this.isInlinePlaying = true;
		this.playingInlineSWF = swfObj;
		//alert ('setPlaying: ' + swfObj);
	},
	
	setPaused: function(swfObj) {
		this.isInlinePlaying = false;
		this.playingInlineSWF = "";
	},
	
	checkAndPause: function(swfObj) {
		if(this.isInlinePlaying == true && this.playingInlineSWF != swfObj) {
			//alert ('this is currnetly playing: ' + this.playingInlineSWF);
			this.pauseSWF(this.playingInlineSWF);
		}
	},
	
	pauseSWF: function(swfObj) {
		mediaPlayerRemoteCall(swfObj, 'playpause');
	}
}


inLinePlayerControls.init();
//inLinePlayerControls.setPlaying(swfObj)
//inLinePlayerControls.checkAndPause(swfObj)
//inLinePlayerControls.setPaused(swfObj)

function noFlicker(layerName) {
	tempLayer = getLayer(layerName);
	tempLayer.setAttribute("class", "mediaPlayer_invisible");
	tempLayer.className = "mediaPlayer_invisible";
}

function mediaPlayerBuilder() {
	
		topLayer = arguments[0];
		flashLayer = arguments[1];
		flashObjectName = arguments[2];
		flashDataDiv = arguments[3];
		swfWidth = arguments[4];
		swfHeight = arguments[5];
		dataLocation = arguments[6];
		pauseAtStart = arguments[7];
		pauseImage = arguments[8];
		
	
		theXHTMLloc = dataLocation;
		swfName = "/global/swf/sapMediaPlayer_V2.swf"
		playerType = "inLine";
		
		var fo = new SWFObject(swfName, flashObjectName, swfWidth, swfHeight, "9.0.115", "#FFFFFF");
		
		fo.addVariable("coName", playerType);
		fo.addVariable("dhtml", "false");
		
		fo.addVariable("flashObjectName", flashObjectName);
		fo.addVariable("videoWidth", swfWidth);
		fo.addVariable("videoHeight", swfHeight);
		
		fo.addVariable("theXHTMLloc", theXHTMLloc);
		fo.addVariable("flashDataDiv", flashDataDiv);
		
		if (pauseAtStart) {
			if (pauseAtStart == "true") {
				fo.addVariable("pauseAtStart", "true");
			}
		}
		
		if (pauseImage) {
			if (pauseImage != null) {
				fo.addVariable("pauseImage", pauseImage);
			}
		}
		
		
		//&markRange=00:30-00:60
		markRange = qsParm['markRange'];
		if (markRange) {
			fo.addVariable("markRange", "true");
			theRange = markRange.split('-');
			fo.addVariable("rangeStart", theRange[0]);
			fo.addVariable("rangeEnd", theRange[1]);
		}
		
		seekTo = qsParm['seekTo'];
		if (seekTo) {
			fo.addVariable("seekTo", "true");
			fo.addVariable("seekRangeStart", seekTo);
		}

		
		fo.addParam("allowFullScreen", "true");
		fo.addParam("wmode", "transparent");
		fo.addParam("swfliveconnect", true);
		
		fo.write(flashLayer);
		
		SWFFormFix(flashObjectName);
		
		
		var anc = getLayer(topLayer);
		if(anc != null)
		{
			var swf = getLayer(flashLayer);
			if(swf != null)
			{
				//FLash Exists. Display the Content.
				swf.className = "mediaPlayer_visible";
			} else {
				//No flashSpace Div...
			}
		} else {
			//No FlashContent Div...
		}
}



