// all code specifically for bcframeset

// onresize commented out to see if loading issue while resizing are still occuring in Toronto
// Continue to looking for reason of this code line here.
//window.onresize = memorizeWindow;
	/*
	 for ie screenLeft & screenTop are the x, y points of content window
	 go to x=0, y=0 to be able to find out the size of toolbars and left border
	*/

var ieOffSetX = 0; // size of IE toobars include upper border
var TBLRieOffSetX = 0; // size of taskbar if located at left or right of the screen
var TBTBieOffSetY = 0; // size of the taskbar if located at top or bottom of screen
var ieOffSetY = 0; // size of left border
var statusBarHeight = 0; // size of the statusbar
var taskBarStatus = 0; // 1 = taskbar on left or right - 2 = taskbar on top or bottom

var newX = 0;
var newY = 0;
var newWidth = 0;
var newHeight = 0;

var winCONSOLE = undefined;
var bArchive = true, bwinConsoleOpened = false;

var initBCFretries=0;

//
//
//	IPHONE SPECIFIC FUNCTIONS
//

// THIS FUNCTION WILL BE CALLED ONLY IF PHONEGAP IS USED
// Aim is to dynamically load the phonegap.js and gapcallback.js libraries in the frameset document

function createJsNode ( head, jsfile)
{
if(head) {
	var node = document.createElement('script');
	if(node) {
		node.setAttribute('language','javascript');
		node.setAttribute('type','text/javascript');
		node.setAttribute('charset', 'utf-8');
		node.setAttribute('src',jsfile);
		//node.onload = 
		head.appendChild(node);
		}
	}
}

function loadPhoneGapLib()
{
var docHead = document.getElementsByTagName('head').item(0);
if(docHead)
	{
	createJsNode ( docHead, "phonegap.js");
	createJsNode ( docHead, "gapcallback.js");
	}
}


function initIphoneFrameset()
{
addEventListener("load", function() { setTimeout(updateIphoneLayout, 0); }, false);
return 'rows = "416"';
}

// if true enables code that will auto hide iphone safari url bar 
var bHideUrlBar = true;
// iphone current width & height
var iPhoneCurrentWidth=0,iPhoneCurrentFrameHeight=0; 

var IPHONE_LAYOUT_UPDATE_TIMER = 500; 	// time in ms at which code will periodically update iphone layout to hide navigation bar if needed

function setUrlBarAutoHideEnabledStatus ( enabled )
{
bHideUrlBar = enabled;
}
           

function updateIphoneLayout()
{
if(window.innerWidth != iPhoneCurrentWidth)
    {
    iPhoneCurrentWidth = window.innerWidth;
    var orient = iPhoneCurrentWidth == 320 ? "profile" : "landscape";
    if(document && document.body) document.body.setAttribute("orient", orient);
    }
if(bHideUrlBar) {
	var iH = window.innerHeight, ctl = null;
	if(self) ctl = self.control;

	if(iPhoneCurrentFrameHeight != iH) {
		iPhoneCurrentFrameHeight = iH;
		// height = 396 is when green active phone call bar is present
		// height = 396 is when only safari url bar is hidden and not active phone call ~ full screen mode
		if(ctl && ((iH == 396) || (iH == 416))) {
			if(ctl.gDisplay) {
				ctl.gDisplay.resizeWanted = true;
				ctl.gDisplay.resize();
				}
			}
		}
	// hide help button on "i will dial in" pane if not enough space (green bar present)...
	if(ctl) {
		var el = ctl.document.getElementById('DIhelpButton');
		if(el && el.style) {
			
			if(iPhoneCurrentFrameHeight == 396) el.style.visibility = "hidden";
			else {
				var eldiv = ctl.document.getElementById('IphoneVoicePanelDialInDiv');
				if(eldiv && eldiv.style && (eldiv.style.visibility == "visible")) el.style.visibility = "visible";
				else el.style.visibility = "hidden";
				}
			}
		}
	// Auto hide iphone safari url bar..
	window.scrollTo(0,1);
	}
}


// Event handler for iPhone only...

window.onorientationchange  = function() {
var event = null;
if(arguments.length > 0) event = arguments[0];
var control = null, content = null, display = null;
if(self) {
	if(self.control) control = self.control;
	if(self.content) content = self.content;
	}
if(control && control.gDisplay) display = control.gDisplay;

if(event && control && content && display) {
	if(display.ContentFrameVisible)
		{
		// content frame currently visible
		if(top && (top.orientation == 0)) {
			// reset warning message as we moved back to portrait mode
			if(content.gblandscapeModeWarningDisplayed == true) content.landscapeModeWarning(false);
			// and auto switch to control frame as requested by click on toggle icon
			if(content.gbToggleLSClick == true) {
				content.gbToggleLSClick = false;
				display.ShowCurrentFrame();
				}
			else { window.scrollTo(0,1); }
			}
		else { window.scrollTo(0,1); }
		}
	else {
		// control frame currently visible
		if(top && top.orientation != 0) {
			// landscape mode => not supported on control frame => display content frame
			display.ShowCurrentFrame();
			}
		}
	}
};


//
//
//	END OF IPHONE SPECIFIC FUNCTIONS
//



function initBCF()
{
// if Internet explorer is used
if (window.screenLeft && window.screenTop)
	{
	try
		{
		window.moveTo(0,0);
		window.resizeTo(screen.availWidth,screen.availHeight);
		ieOffSetX = window.screenLeft;
		ieOffSetY = window.screenTop;

		if (screen.availWidth < screen.width)
			{
			// Task bar should be located at left or right of the screen
			TBLRieOffSetX = (screen.width - screen.availWidth);
			taskBarStatus = 1;
			}
		if (screen.availHeight < screen.height)
			{
			// Task bar should be located at top or bottom the screen
			TBTBieOffSetY = (screen.height - screen.availHeight);
			taskBarStatus = 2;
			}

		// To correct the bug of IE 6 that is not able to fit avail height and avail width
		// with taskbar, the case of taskbar on the left is managed.
		if (taskBarStatus == 1)
			{
			// if UA_IE6 = 512
			if (gClientUserAgent & 512)
				window.moveTo(TBLRieOffSetX,0);
			else
				window.moveTo(0,0);
			}
		else if (taskBarStatus == 2)
			{
			window.moveTo(0,0);
			}
		window.resizeTo(screen.availWidth,screen.availHeight);
		}
	catch(err)
		{
		initBCFretries++;
		if(initBCFretries < 4)	setTimeout('initBCF()',500);
		}
	}
}


function coordinatesXY(coordinates)
{
if (coordinates && (coordinates == "x" || coordinates == "y"))
	{
	if  (window.screenLeft && window.screenTop)
		{
		if (coordinates == "x")
			{
			if (taskBarStatus == 1)
				{
				if (gClientUserAgent & 2) // IE7
					return (window.screenLeft);
				else
					return (window.screenLeft - ieOffSetX);
				}
			return (window.screenLeft - ieOffSetX);
			}
		else if (coordinates == "y")
			{
			return (window.screenTop - ieOffSetY);
			}
		}

	if (window.screenX && window.screenY)
		{
		if (coordinates == "x")
			return  window.screenX;
		else if (coordinates == "y")
			return  window.screenY;
		}
	}
}


function windowSize(widthHeight)
{
if (widthHeight && (widthHeight == "w" || widthHeight == "h"))
	{
	if (window.outerWidth && window.outerHeight)
		{
		if (widthHeight == "w")
		return window.outerWidth;
		else if (widthHeight == "h")
		return window.outerHeight;
		}

	if (document.documentElement && (document.documentElement && document.documentElement.clientHeight))
		{
		if (widthHeight == "w")
			{
			if (taskBarStatus == 1)
				{
				if (gClientUserAgent & 2) // IE7
					return (document.documentElement.clientWidth+ieOffSetX*3);
				else
					return (document.documentElement.clientWidth+(ieOffSetX*3));
				}

			return (document.documentElement.clientWidth+(ieOffSetX*3));

			}
		else if (widthHeight == "h")
			{
			if (isPopupEnabled())
				{
				// if UA_IE7 = 2
				if (gClientUserAgent & 2)
					return (document.documentElement.clientHeight+statusBarHeight+ieOffSetY);
				else
					return (document.documentElement.clientHeight+ieOffSetY+(ieOffSetX*2));
				}
			else
				{
				return (document.documentElement.clientHeight+statusBarHeight+ieOffSetY);
				}
			}
		}
	}
}


function memorizeWindow(arg)
{
newX = coordinatesXY("x");
newY = coordinatesXY("y");
if (arg=="display")
	{
	if (window.screenLeft && window.screenTop)
		{
		window.moveTo(0,0);
		ieOffSetY = window.screenTop;
		window.moveTo(newX,newY);
		}
	}
newX = coordinatesXY("x");
newY = coordinatesXY("y",arg);
newWidth = windowSize("w");
newHeight = windowSize("h");

newX = (newX == undefined) ? correctBugIe6FxLinux() : newX;
}


function correctBugIe6FxLinux()
{
newX = 0;
newY = 0;
newWidth = screen.availWidth;
newHeight = screen.availHeight;
return true;
}


function openWinConsole()
{
if(bwinConsoleOpened == true) return;
bwinConsoleOpened = true;
winCONSOLE = null;
//@@@ APBC-MERGE, code for different console window path
var path = '/bc/winconsole.html';	;
if(bArchive) path = './winconsole.html?player=1';
winCONSOLE = window.open(path, 'BCwinConsole', "height=600,width=800,status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=no");;
}

// For start.html to get the lang parameter CR 24366
function GetLang()
{
	var args = new URLParamObj();
	args.Init();
	var l = args.GetParam('lang');
	delete args;
	return (l != null)?l:"en";
}

function loadComplete()
{
checkDomain(2);
var u,sSearch = "",sProtocol = "http://",uiUrl = "./indexframes.html";

// getting query string from doc url
u = document.location;
if(u)
	{
	sSearch = u.search;
	sProtocol = u.protocol + "//";
	}
if(sSearch == "") { alert('Invalid client start URL!'); return; }


var args = new URLParamObj();
args.Init();

var bWinConsole = args.GetParam('winconsole');
if(args.GetParam('player') == undefined) bArchive = false;

if(bWinConsole == 1) openWinConsole();

if(args.GetParam('tdulevel') == undefined)
	sSearch += '&tdulevel=0';
if(args.GetParam('loglevel') == undefined)
	sSearch += '&loglevel=2';

//@@@ APBC-MERGE START
if(bArchive == false)
	{
	// code for fullscreen managment
	sBi = args.GetParam('bi');
	if (sBi != "")
		{
		oBrowser = new browserId();
		if (oBrowser.Init(sBi) == null)
			{
			delete oBrowser;
			oBrowser = null;
			alert('Mandatory URL bi query string parameter is missing!');
			return;
			}
		}

	if(args.GetParam('debug') == '1')
		uiUrl = "./debug.html";
	}
//@@@ APBC-MERGE END

gClientUserAgent = getClientUserAgent();

initBCF();

// if Internet explorer is used
	if (window.screenLeft && window.screenTop)
		statusBarHeight = (screen.height-(document.documentElement.clientHeight + ieOffSetY + TBTBieOffSetY));

memorizeWindow();
// end of code for fullscreen managment


// building client UI url on conference server and add content server name to query string
uiUrl = uiUrl + sSearch;

delete args;

// loading client UI into control frame
if(!window.opera && document.frames)
	{
	document.frames['control'].location = uiUrl;
	document.frames['content'].location.reload();
	}
else
	{
	if(document.getElementById)
		{
		var f=document.getElementById('control');
		if(f) f.src = uiUrl;
		f=document.getElementById('content');
		if(f && f.location && f.location.reload) f.location.reload();
		}
	}
}

// CR 25882 Fix for IE6
function frmsetResize()
{
if(isIE6())
	{
	if(top && top.content && top.content.updateIframeSize)
		{
		var w,h;
		if (self.innerHeight) // all except Explorer
			{
			w = self.innerWidth;
			h = self.innerHeight;
			}
		else if (document.documentElement && document.documentElement.clientHeight)
			// Explorer 6 Strict Mode
			{
			w = document.documentElement.clientWidth;
			h = document.documentElement.clientHeight;
			}
		else if (document.body) // other Explorers
			{
			w = document.body.clientWidth;
			h = document.body.clientHeight;
			}
		top.content.updateIframeSize( w - CONTROL_FRAME_WIDTH, h);
		}
	}
}