/*****************************************************
cs_BCO.js  ver 1.9

Copyright information:
	Copyright  2005 Medianet, All Rights Reserved.

	No part of this file or the associated licensing and documentation
	should be construed as a commitment on the part of Medianet.

    The information in this document is proprietary and subject to
	strict confidentiality and non-disclosure clause by Medianet,
	Inc. 2005.

Description:
	this script uses Browser Component Objects to easily
	detect, install and upgrade the WIC Companion.  this
	script file is not a requirement for using the BCOs.
*/

////////////////////////////////////////////////////////////////////////////
//Version of the Companion that should be used.  strIEActiveVersion is for
//You can find the version by right clicking on iecompanion.exe, selecting
//properties, and selecting version.
var strIEActiveVersion = "3.4.1.14";

////////////////////////////////////////////////////////////////////////////
//File location
//   This is where the files in the cs directory are located.  This should
//   be a complete URL starting with "http://".
//
//   Example: "http://www.myhost.com/cs/"
//
var filelocation = "/files/pages/";

////////////////////////////////////////////////////////////////////////////
//Installation Window Height and Width
//   These variables control the width and height of the install pages.
//   If you customize the install pages you may need to adjust these sizes
//
//   * strInstallHeight = Height of the page
//   * strInstallWidth = Width of the page
var strQueueHeight = "290";
var strQueueWidth = "400";

////////////////////////////////////////////////////////////////////////////
//Installation Window Height and Width
//   These variables control the width and height of the install pages.
//   If you customize the install pages you may need to adjust these sizes
//
//   * strInstallHeight = Height of the page
//   * strInstallWidth = Width of the page
var strInstallHeight = "230";
var strInstallWidth = "640";

var strUpgradeHeight = "300";


////////////////////////////////////////////////////////////////////////////
//Browser Incompatability
//   These variables control what the client sees when the WIC Companion is
//   not compatable with their browser.  The options are to pop up a message
//   box or redirect to another URL.  The pop up message is the default.
//
//   * redirectOnBrowserIncompatable = value of "true" will redirect instead
//        of poping the message
//   * strBrowserIncompatableMessage = browser incompatability message
//   * strBrowserIncompatableURL = browser incompatability redirect URL
var redirectOnBrowserIncompatable = true;
var strBrowserIncompatableMessage = "Sorry, your browser is not compatible.";
var strBrowserIncompatableURL = "https://cg.medianet.dk/Download/Web-Call.xpi";

////////////////////////////////////////////////////////////////////////////
//Operating System Incompatability
//   These variables control what the client sees when the WIC Companion is
//   not compatable with their operating system.  The options are to pop up
//   a message box or redirect to another URL.  The pop up message is the
//   default.
//
//   * redirectOnOSIncompatable = value of "true" will redirect instead of
//        poping the message
//   * strOSIncompatableMessage = browser incompatability message
//   * strOSIncompatableURL = browser incompatability redirect URL
var redirectOnOSIncompatable = false;
var strOSIncompatableMessage = "Sorry, WIC functionality is only available for Microsoft Windows.";
var strOSIncompatableURL = "http://www.medianetinnovations.com/WIC/";

////////////////////////////////////////////////////////////////////////////
//Cancelation Message
//   This message appears in a Yes/No box if the client rejects the download
//   of the WIC Companion.  This message is customizable.  At the end of the
//   message the box ads the line "Are you sure you want to cancel?  Click
//   Yes to cancel.  Click No to try again."
//
//   * strCancelMessage = message recieved when rejecting the download
var strCancelMessage = "Installation of the WIC Companion is required to continue the conference.";


///////////////////////////////////////////////////////////////////////////
//                    No editing required past this line.                //
///////////////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////
//Auto Call
//  If the URL has "?CallNow" at the end this will
//  place a call on page entry.
var myvariable = ( new String( document.location.search ) ).replace( "?", "" );
if (myvariable == "CallNow")
{
	window.setTimeout( 'launchcall();', 2000 );
}

function launchcall()
{
		if (navigator.platform.indexOf("Win32") >= 0 )  //Makes sure platform is Windows
		{
			if (navigator.appName=="Microsoft Internet Explorer"&&parseInt(navigator.appVersion)>=4&&navigator.appVersion.indexOf("MSN") <= 0)  //Checks for IE 4+ and makes sure it's not MSN browser
			{
				iecheck();
			}
			else if (navigator.appName=="Netscape")  //Checks for NS
			{

				//alert(strBrowserIncompatableMessage);
				window.location=strBrowserIncompatableURL;
			}
			else
			{
				if ( ! redirectOnBrowserIncompatable)
				{
					alert(strBrowserIncompatableMessage);
				}
				else
				{
					window.location=strBrowserIncompatableURL;
				}
			}
		}
		else
		{
			if ( ! redirectOnOSIncompatable)
			{
				alert(strOSIncompatableMessage);
			}
			else
			{
				window.location=strOSIncompatableURL;
			}
		}
}

////////////////////////////////////////////////////
//Queue Height/Width Modification
//  The Companion queue pages are sligtly smaller than
//  the sizes they are set to.  The following changes
//  are to compensate for this.
//strQueueHeight = strQueueHeight - 32;
//strQueueWidth = strQueueWidth - 12;

////////////////////////////////////////////////////
//IE Check
//  Checks the IE Browser for the WIC Companion and
//  if it is the correct version
function iecheck()
{
	var VBSbody =   'Dim IEC\n' +
			'Dim Err1\n' +
			'On Error Resume Next\n' +
			'Set IEC = CreateObject("WICAddon.WICInformation")\n' +			'Err1 = Err.Number\n' +
			'IECVersion = IEC.Version\n' +
			'If Err1 = 429 Then\n' +
	'Set oWin = Window.Open(""+ filelocation +"download_wic.php", "GetCompanion", "width="+ strInstallWidth +",height="+ strInstallHeight +",toolbar=no,status=yes,menubar=no,location=no,directories=no,resizable=no,scrollbars=yes")\n' +
			'Else\n' +
			'	IF IEC.Version >= strIEActiveVersion Then\n' +
			'		Set IEC = Nothing\n' +
			'		Set Err1 = Nothing\n' +
			'		Set IECVersion = Nothing\n' +
			'		CallNow()\n' +
			'	Else\n' +
			'		Set IEC = Nothing\n' +
			'		Set Err1 = Nothing\n' +
			'		Set IECVersion = Nothing\n' +
	'Set oWin = Window.Open(""+ filelocation +"upgrade_wic.php", "GetCompanion", "width="+ strInstallWidth +",height="+ strUpgradeHeight +",toolbar=no,status=yes,menubar=no,location=no,directories=no,resizable=no,scrollbars=yes")\n' +
			'	End If\n' +
			'End If\n'
	window.execScript( VBSbody , 'vbscript' );
}

////////////////////////////////////////////////////
//IE Check2
//  Checks to make sure the client installed the
//  Companion.  This function is called from
//  getiecompanion.htm and upgrade.htm.
function iecheck2()
{
oWin.close();
var VBSbody2 =  'Dim IEC\n' +
				'Dim Err1\n' +
				'Dim answer\n' +
				'On Error Resume Next\n' +
				'Set IEC = CreateObject("WICAddon.WICInformation")\n' +				'Err1 = Err.Number\n' +
				'If Err1 = 429 Then\n' +
				'   answer = MsgBox (""+ strCancelMessage & VbCrlf & VbCrlf & "Are you sure you want to cancel?  Click ""Yes"" to cancel.  Click ""No"" to try again.", vbYesNo, "Conference Cancel")\n ' +
				'   If answer = vbNo Then\n' +
				'      Set oWin = Window.Open(""+ filelocation +"download_wic.php?"+ strActiveVersion +"", "GetCompanion2", "width="+ strInstallWidth +",height="+ strInstallHeight +",toolbar=no,status=yes,menubar=no,location=no,directories=no,resizable=no,scrollbars=yes")\n' +
				'   End If\n' +
				'Else\n' +
				'	Set IEC = Nothing\n' +
				'	Set Err1 = Nothing\n' +
				'	CallNow()\n' +
				'End If\n'
window.execScript( VBSbody2 , 'vbscript' );
}

////////////////////////////////////////////////////
//proxyGet
//	Hides NS/IE diffs for fetching object properties
function proxyGet( obj )
{
	var v = obj;
	if( navigator.appName=="Netscape"&&parseInt(navigator.appVersion)==4 )
	{
		v = v();
	}

	return v;
}

////////////////////////////////////////////////////
//CallNow
//	Initiate a new conference
var SetupAttempts = 10;			//number of seconds to wait after install before attempting to call
function CallNow()
{
	var agt=navigator.userAgent.toLowerCase();
	var is_aol   = (agt.indexOf("aol") != -1);
	if (is_aol)
	{
		window.open(""+ filelocation +"aolcheck.htm","AOL","width="+ strInstallWidth +",height="+ strInstallHeight +",toolbar=no,status=yes,menubar=no,location=no,directories=no,resizable=yes");
	}
	else
	{
		window.location = "https://webcallcmd/1BD35934-4780-4712-AE2C-A4C484F06617/makecall";
	}
}


////////////////////////////////////////////////////
//callfail
//	Pops a generic failure box if call failed.
function callfail()
{
	window.open(""+ filelocation +"fail.htm","Fail","width="+ strQueueWidth +",height="+ strQueueHeight +",top="+ (screen.height-strQueueHeight)/2 +",left="+ (screen.width-strQueueWidth)/2 +",toolbar=no,status=no,menubar=no,location=no,directories=no,resizable=no");
}

function callfailie7()
{
	window.open(""+ filelocation +"fail_ie7.htm","Fail","width="+ strQueueWidth +",height="+ strQueueHeight +",top="+ (screen.height-strQueueHeight)/2 +",left="+ (screen.width-strQueueWidth)/2 +",toolbar=no,status=no,menubar=no,location=no,directories=no,resizable=no");
}
