// This is the external js to manage netmeeting functions (c) Neil Smith @ fresh-toast  Core : 7/6/2001 Mods to 10/5/2002
// Rationalised functions 10/05/02
// Added Netscape 4 support 15-17/02/02
// All rights reserved <c> N Smith 2001-2
window.offScreenBuffering=true;
var rpStarted=false;
var user=new Object();
user.from="Netmeeting Site User";
user.fromemail="Your Email Here";
user.isContactable=false;
user.canContact=false;
user.override=false;
user.incall=false;
window.defaultStatus="Fresh-Toast NetMeeting conference server (c) Neil Smith 2001";
var callType="directory";
var clientAddr="neil@fresh-toast.com";
var tz=new Date();
var myTz=-tz.getTimezoneOffset()/60;
var callTzOffSet=myTz;
var MyTzOffSet=myTz;
// Reference to users timezone
var callTzInCall="Time : ";
var readyImg=new Array(2);
readyImg[0]=new Array(5);
readyImg[1]=new Array(5);
imgPath='/netmeeting/images/';
readyImg[0][0]='NMPanel6_08.jpg'; // Ready
readyImg[0][1]='NMPanel6_08_01.jpg'; // Calling
readyImg[0][2]='NMPanel6_08_02.jpg'; // In call
readyImg[0][3]='NMPanel6_08_03.jpg'; // Hang up
readyImg[0][4]='NMPanel6_08.jpg'; // Playing vid

readyImg[1][0]='NMPanel6_ready.jpg'; // Ready
readyImg[1][1]='NMPanel6_calling.jpg'; // Calling
readyImg[1][2]='NMPanel6_incall.jpg'; // In call
readyImg[1][3]='NMPanel6_hangup.jpg'; // Hang up
readyImg[0][4]='NMPanel6_08.jpg'; // Playing vid

function showState(which) {
if (document.all) {
	document.images['NMPanel6_08'].src=imgPath+readyImg[0][which];
	}
if (document.layers) {
	document.images['NMPanel6_08'].src=imgPath+readyImg[1][which];
	}
}

function timer() {
var t=new Array(3);
time_now=new Date();
time_now.setHours(time_now.getHours()-(myTz-callTzOffSet));
// MyTzOffset now flipped between local and remote times.
t[0]=time_now.getHours();
t[1]=time_now.getMinutes();
t[2]=time_now.getSeconds();

for (i=0; i<3; i++) {
t[i]=(t[i]<10)?"0"+t[i]:t[i];
}
if (document.all || document.getElementByID) {
document.all.tmLayer.innerText=callTzInCall+t[0]+"."+t[1]+":"+t[2];
	}
if (document.layers) {
document.layers["tmLayer"].document.open();
document.layers["tmLayer"].document.writeln("<p class='vidboxtext'>"+callTzInCall+"<br>"+t[0]+"."+t[1]+":"+t[2]+"</p>");
document.layers["tmLayer"].document.close();
	}
if (queryNM()) {
	callTzInCall="Remote : ";
//	callTzOffSet=callTzOffSet;
	var temp=showHide(true);
// Interlock - Changed  false to true, 040502
	if (user.incall==false) {
	showState(2);
	}}
	else {
	callTzInCall="Time : ";
	callTzOffSet=myTz;
// Reset to local timezone
	showState(0);	
	var temp=showHide(false);
	}
temp=setTimeout("timer()","1000");
}

//Preload images
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function showStatus(count) {
// Cycle every second until readystate changes or 30 seconds elapsed before 
// grabbing image. Fudge for Netscrape - allow 30 seconds from client load.
var count=count+1;
if (document.all && document.all.NetMeeting.readyState==4) {
	document.images["cnstatus"].src="/netmeeting/frameset/client_reachable.php";
	clearTimeout(myTimeout);
	return;
	}
if (document.layers && navigator.plugins["Esker ActiveX Plug-in"] && window["DataWindow"] || count>60) {
	showHide(queryNM());
	document.layers["connectLayer"].document.open();
	document.layers["connectLayer"].document.writeln('<img src="/netmeeting/frameset/client_reachable.php" width="24" height="24" border="0" alt="Shows if netmeeting can be called by other users">');
	document.layers["connectLayer"].document.close();
	clearTimeout(myTimeout);
	return;
	}
var myTimeout=setTimeout("showStatus('"+count+"')",1000);
}

function TransferConfInfo(mailAddr) {
// Grab uname email and ICQ ID from ICQ form window when opened.
var confInfo=new Object();
clientNum="emailconf.php?"+mailAddr;
confinfo=window.open(clientNum,"mail","width=350,height=350,resize=no,scrollbars=no");
}

function TransferICQInfo(clientNum) {
// Grab uname email and ICQ ID from ICQ form window when opened.
var icqalert=new Object();
clientNum="icqcaller.html?"+clientNum;
icqalert=window.open(clientNum,"new","width=350,height=200,resize=no,scrollbars=no");
}

function TransferCallInfo(clientAddr,callType,dirname,tzid) {
if ( isPlayerStarted()) {
	if (confirm("You are playing a video. Click OK to stop the\nvideo and place a call, or Cancel to ignore")) {
	document.all.video1.DoStop();
	document.all.LayerRP.style.visibility="hidden";
	document.all.LayerRP.innerHTML="";
	var temp=showHide(false);
	} else {
	return;
	}
}

callTzOffSet=tzid;
// Cid determines call type IN/CU/NM
if (parent.infowindow.user.conf_pref==1) {
	var transStr=new String();
	var calltoVal=clientAddr;
	var calling=queryNM();
	if (calling) {endCall()}
	showState(1);
// Calling image
	calltoVal=(dirname==""?"":dirname+"/")+calltoVal;
	transStr="callto:"+calltoVal+"+type="+callType+"+av=true+data=true+secure=false";
	if (document.all) {
		document.all.NetMeeting.CallTo(transStr);
		}
	if (document.layers) { window["NetMeeting"].activeX.capsule.B(window["NetMeeting"],"CallTo",transStr)
		}
// ***DO NOT DELETE - required for normal operation.
	calling=queryNM(); // Check if we are connected yet
	if (calling)
	{
		var temp=showHide(true); // Make sure video window is visible
		showState(2);
		user.incall=false;
		callTzInCall="Remote : ";	
// Display status, change to remote timezone when in a NM call
	}
	else {
		var temp=showHide(false);
		showState(0);
}}
else if (parent.infowindow.user.conf_pref==2) {
if (document.all) {
	var calltoVal=clientAddr;
confinfo=window.open("/netmeeting/cu/323file.php?"+calltoVal,"in","width=150,height=150,left=100,top=100,resize=no,scrollbars=no,menu=no,location=no");
	}
	else {
	alert("Sorry, Intel phone support is currently only available on PC using IE4\nor above. Please change your preference setting to netmeeting\nin the profile area.");}
}
else if (parent.infowindow.user.conf_pref==3) {
if (document.all) {
	var calltoVal=clientAddr;
confinfo=window.open("/netmeeting/cu/"+calltoVal+"/index.cu","cu","width=150,height=150,left=100,top=100,resize=no,scrollbars=no,menu=no,location=no");
	}
	else {
	alert("Sorry, CuSeeMe support is currently only available on PC using IE4\nor above. Please change your preference setting to netmeeting\nin the profile area.");}
	}
else if (parent.infowindow.user.conf_pref==5) {
	var calltoVal=clientAddr;
confinfo=window.open("portrait://"+calltoVal,"po","width=150,height=150,left=100,top=100,resize=no,scrollbars=no,menu=no,location=no");
	}
// End function
}

function openLocalWin() {
if (document.all) {
window.open("/netmeeting/frameset/myvidblock.html","mylocalvid","width=260,height=200,left=400,top=300,scrollbars=no,menu=no,location=no");
	}
if (document.layers) {
window.open("/netmeeting/frameset/myvidblockNN.html","mylocalvid","width=260,height=200,left=400,top=300,scrollbars=no,menu=no,location=no");
	}
}

function endCall() {
calling=queryNM();
if (calling) {
	if (confirm('You are currently in a call - are you sure you want to hang up?')) {
	if (document.layers) {
	window["NetMeeting"].activeX.capsule.A(window["NetMeeting"],"LeaveConference");
		}
	if (document.all) {
	document.all.NetMeeting.LeaveConference();
		}
// All browsers		
	var callTzOffSet=myTz;
	user.override=false;
	user.incall=false;
	var temp=showHide(false);
	showState(0);
	}		
}
showState(0);
return true;
}

function showHide(show) {
// Show code
if (document.all) {
	document.all.LayerNM.style.visibility=(show || user.override)?"visible":"hidden";
	document.all.RemoteWindow.style.visibility=(show || user.override)?"hidden":"visible";
	}
if (document.layers && window["DataWindow"]) { // Mod image 1st
	document.images["NMPanel6_06"].src=(show?"/netmeeting/images/spacer.gif":"/netmeeting/images/NMPanel6_06.jpg");
	window["DataWindow"].visibility="visible";
	document.layers["Layer2"].visibility="visible";
	document.layers["Layer1"].visibility=(show || user.override)?"visible":"hidden";
// Refresh plugin visibility cause it keeps on blanking out :-(	
	}
}
// End showhide


function handleHangup(state) {
// Allows hangup if in conference and shows / hides hangup button.
if (queryNM()) {
switch(state) {
	case 0:
{endCall();showState(0);user.incall=false;user.override=false;return true;}
// Hangup - image no longer handled by hangup call but by timer 040502
	case 1:
{showState(3);user.incall=true;return true;}
// Mouse Over - interlock to hold hangup btn from resetting
	case 2:
{showState(2);user.incall=false;return true;} // Calling image
	}
}
else {
showState(0);user.incall=false;
	}
}

function queryNM() {
// Query netmeeting...
if (document.all) {
	return (document.all.NetMeeting.isInConference()==1);
	}
if (document.layers ) {
// Prev. had to show window in NN for NM to be active - changed to 
// DataWindow - corrected bug where NM would show for NN if 
// mouseover triggers detection of call status NGS 260302
	document.layers["Layer2"].visibility="visible";
	if	(window["DataWindow"]) {
// Check if we have instantiated NM yet	
	window["DataWindow"].visibility="visible";
	return 0+window["DataWindow"].activeX.capsule.A(window["DataWindow"],"IsInConference")	
		}
	}
}

function isPlayerStarted() {
if (window.video1==undefined) {
	return false; 
	} else {	
	return (window.video1.readyState==4);
	}
}

function nmUndock() {
if (document.layers) {
	window["NetMeeting"].activeX.capsule.A(window["NetMeeting"],"UnDock")
}
if (document.all) {
	return (document.all.NetMeeting.UnDock())
 }
}
 
// End of file.