/*****************************************************
	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 = "1.2.0.50";

var strQueueWidth = '400';
var strQueueHeight = '400';
var strInstallWidth = '600';
var strInstallHeight = '450';

///////////////////////////////////////////////////////////////////////////
//                    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);
			}
			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("Medianet.IECompanion.CompanionHelper")\n' +
		'Err1 = Err.Number\n' +
		'IECVersion = IEC.Version\n' +
		'If Err1 = 429 Then\n' +
'Set oWin = Window.Open("'+urlGetWIC+'", "GetCompanion", "width="+ strInstallWidth +",height="+ strInstallHeight +",toolbar=no,status=yes,menubar=no,location=no,directories=no,scrollbars=yes,resizable=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("'+urlUpgradeWIC+'", "GetCompanion", "width="+ strInstallWidth +",height="+ strInstallHeight +",toolbar=no,status=yes,menubar=no,location=no,directories=no,scrollbars=yes,resizable=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("Medianet.IECompanion.CompanionHelper")\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(urlGetWIC+"?"+ strActiveVersion +"", "GetCompanion2", "width="+ strInstallWidth +",height="+ strInstallHeight +",toolbar=no,status=yes,menubar=no,location=no,directories=no,resizable=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(urlAOLCheck,"AOL","width="+ strInstallWidth +",height="+ strInstallHeight +",toolbar=no,status=yes,menubar=no,location=no,directories=no,resizable=yes");
	}
	else  
	{
		try
        {
            if( navigator.appName=="Microsoft Internet Explorer"&&parseInt(navigator.appVersion)>=4 )
    		{
    			var gcs_componentFinder = new ActiveXObject("Medianet.IECompanion.ComponentFinder");
    		}
    		else
    		{
    			var gcs_componentFinder = document.gcs_componentFinderLayer.document.embeds[ "gcs_componentFinder" ];
    		}
        }
        catch(e)
        {
            
        }
	
		//alert("Before DownloadSubscribersList");
		gcs_componentFinder.DownloadSubscribersList();
		//alert("After DownloadSubscribersList");
		var ID = proxyGet( gcs_componentFinder.MyId );
		if( ID )
		{
			//alert("Before findMyCallButton");
			var Button = gcs_componentFinder.findMyCallButton(ID);
			//alert("After findMyCallButton");
			if( Button )
			{
				Button.CallNow();
			}
			else
			{
				if( --SetupAttempts > 0 )
				{
					gcs_componentFinder = null;
					ID = null;
					Button = null;
					window.setTimeout( 'CallNow();', 500 );
				}
				else
				{
					callfail();
				}
			}
		}
		else
		{
			callfail();
		}
	}
}


////////////////////////////////////////////////////
//callfail
//	Pops a generic failure box if call failed.
function callfail()
{
	window.open(urlWICFail ,"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=yes");	
}

