//***********************************************************************************************
//	version of the last dlls of Surf and Call
//***********************************************************************************************
var VerMaj  = 5; 
var VerMin  = 0; 
var VerBld  = 243; 
var VerSbB  = 0; 




//***********************************************************************************************

var sVerStr = VerMaj+ "." +VerMin+ "." +VerBld+ "." +VerSbB;		// The following parameters holds the SNC version string at MSIE.
var VT_PLUGIN_NAME    = "Netscape Plugin for VocalTec Surf&Call";		// Next string is the 'Product Name' of the Netscape plugin's version info.

//***********************************************************************************************


var ie = (GetBrowser() == "MSIE") ? true:false;
var ns = !(ie);

//***********************************************************************************************
//	variables for creating a button
//***********************************************************************************************
	var ButtonX;
	var ButtonY;
	var ButtonIP;
	var ButtonName;
	var ButtonDest;
	var ButtonBGColor;
	var ButtonShown = "true";



//***********************************************************************************************
//  Function Name : checkVersionIE
//  description   : check and return the current version of SnC in MSIE
//  return(Void)  : version - string value.
//  Remark        : Using a writen VBScript function that constructs the version string
//***********************************************************************************************
if (ie) {
	document.writeln("<SC"+"RIPT Language=VBScript>");
	document.writeln("    function SnCVersion");
	document.writeln("        On Error Resume Next  ");
	document.writeln("        Set snc = CreateObject(\"SnCAX.SnCAX.1\")  ");
	document.writeln("        Set a = 0");
	document.writeln("        If snc is Nothing Then");
	document.writeln("            SnCVersion=0");
	document.writeln("        Else");
	document.writeln("            SnCVersion=snc.MajorVersion&chr(46)&snc.MinorVersion&chr(46)&snc.BuildVersion&chr(46)&snc.SubBuildVersion");
	document.writeln("            Set snc = nothing");
	document.writeln("        End If");
	document.writeln("    end function");
	document.writeln("</SC"+"RIPT>");
}
function checkVersionIE()
{
	myversion = SnCVersion();
	// previous versions of Snc return undefined
	if (myversion == null)
		myversion = 0;
	return myversion;
}
//***********************************************************************************************



//***********************************************************************************************
//  Function Name : GetBrowser 
//  description   : Get the browser name.
//  return(String): "Netscape3","Netscape4","MSIE","BROWSER_NOT_SUPPORTED";
//***********************************************************************************************
function GetBrowser()
{
    // Get the browser name
    BrowserName = navigator.appName;
    BrowserVersion = parseInt(navigator.appVersion);
    Browser = "BROWSER_NOT_SUPPORTED";
    
    if (BrowserName == "Netscape")
        Browser = "NETSCAPE";
    else if (BrowserName == "Microsoft Internet Explorer")
        Browser = "MSIE";
    return Browser;
}




//***********************************************************************************************
//  Function Name : checkVersion
//  description   : compare current version to last version, and returns a string of the file to download
//  return(Void)  : download file - string value.
//  Remark        : returns an empty string if current version is up to date.
//***********************************************************************************************
function checkVersion()
{
	Loc = window.location+"";
	if (Loc.indexOf("VTSnCSetupOK")!=-1)
		return false;		//in case I've installed the newest version already, but netscape can't see it
	if (ie) v = checkVersionIE();
	if (ns) v = checkVersionNS();
	SncNeedToUGr = !compareVersion(v,sVerStr)
	if (SncNeedToUGr) {
		return true;
	}
	else {
		return false;
	}
}



//***********************************************************************************************
//  Function Name : checkVersionNS
//  description   : check and return the current version of SnC in Netscape
//  return(Void)  : version - string value.
//***********************************************************************************************
function checkVersionNS()
{
	navigator.plugins.refresh(false);
	plugin = navigator.plugins[VT_PLUGIN_NAME];
	if (plugin != null) 
	{
		description   = new String(plugin.description);
		versionIndex  = description.lastIndexOf(' ')+1;
		versionString = description.substring(versionIndex, description.length);
		curVersion = versionString.split(".")
		curVerMaj = new Number(curVersion[0]); 
		curVerMin = new Number(curVersion[1]); 
		curVerRev = new Number(curVersion[2]); 
		curVerBld = new Number(curVersion[3]);
		myversion = curVerMaj + "." + curVerMin + "." + curVerRev + "." + curVerBld
		return(myversion)
	}
	else return(0);
}
//***********************************************************************************************




//***********************************************************************************************
//  Function Name : CompareVerNum, compareVersion 
//  description   : Compare two versions of the object (fromObj - from the user's installed Object)
//  return(Void)  : true , false.
//***********************************************************************************************
function compareVersion(fromObj,fromPage)
{
	ok = true
	if (fromObj == "0") ok = false;
	else {
		arrObj = fromObj.split(".")
		arrServ = fromPage.split(".")
		NeedToUpgrade = CompareVerNum(arrObj[0],arrObj[1],arrObj[2],arrObj[3],arrServ[0],arrServ[1],arrServ[2],arrServ[3]);
		if (NeedToUpgrade) ok = false;
	}
	return(ok)
}

function CompareVerNum(a1,a2,a3,a4,b1,b2,b3,b4)
{
	upgrade = true;
	if (parseInt(a1) >= parseInt(b1)) {
		if (parseInt(a2) >= parseInt(b2)) {
			if (parseInt(a3) >= parseInt(b3)) {
				if (parseInt(a4) >= parseInt(b4)) {
					upgrade = false;
				}
			}
		}
	}
	return upgrade;
}
//***********************************************************************************************



//***********************************************************************************************
//  Function Name : GetPlatform 
//  description   : Get the OS platform.
//  return(Void)  : "Win32" , "Other".
//  Remark        : I'm using this function because the "navigator.platform" object returns "Undefined" for Msie3.0
//***********************************************************************************************
function GetPlatform()
{
    // See whether the platform is Win32 or not
    Platform = "Other";
    var agt=navigator.userAgent.toLowerCase();
    if ((agt.indexOf("win95")!=-1) || (agt.indexOf("windows 95")!=-1) ||
        (agt.indexOf("win98")!=-1) || (agt.indexOf("windows 98")!=-1) ||
        (agt.indexOf("winnt")!=-1) || (agt.indexOf("windows nt")!=-1) ||
        (agt.indexOf("win32")!=-1) || (agt.indexOf("32bit")!=-1))
        Platform = "Win32";
    // Return it
    return Platform;
}

//***********************************************************************************************







//***********************************************************************************************
//  Function Name : loadLoaderApplet 
//  description   : Write into document an applet tag to load the loader applet
//  return(Void)  : None. 
//***********************************************************************************************
function loadLoaderApplet(What2Download)
{
	document.write("<APPLET");
	document.write("	code='vocaltec.loader.Loader.class'");
	document.write("	codebase='"+CodeBase+"'");
	document.write("	name=Loader");
	document.write("	id=Loader");
	document.write("	archive='Loader.jar'");
	document.write("	height=0");
	document.write("	width=0");
	document.write("	mayscript");
	document.write("	VIEWASTEXT>");
	document.write("	<param name='cabbase' value='Loader.cab'>");
	document.write("	<param name='DEBUG' value='true'>");
	document.write("	<param name='Modules' value='"+What2Download+"'>");
	document.write("	<param name='msg0' value='An error occured while trying to execute the file.'>");
	document.write("	<param name='msg1' value='An error occured while trying to access the system properties.'>");
	document.write("	<param name='msg2' value='The File VTSnC.exe could not be found.'>");
	document.write("	<param name='msg3' value='An error occured while loading the file.'>");
	document.write("	<param name='msg4' value='An error occured while trying to close the file.'>");
	document.write("	<param name='msg5' value='The file has been successfuly downloaded!'>");
	document.write("	<param name='msg6' value='The downloaded file is corrupted!'>");
	document.write("	<param name='msg7' value='Error! Permission to file system denied by user.'>");
	document.write("	<param name='msg8' value='Unknown exception while enabling privilege.'>");
	document.write("</APPLET>");
}
//***********************************************************************************************


//**************** Functions called by the Loader applet ****************************************

//***********************************************************************************************
//  Function Name : OnFinish 
//  description   : called by the Loader applet. 
//  return(Void)  : None. 
//***********************************************************************************************
function OnFinish(str)
{
	opener.navigator.plugins.refresh(false);
	opener.reload();
	self.close();
}

//***********************************************************************************************
//  Function Name : OnDownload
//  description   : called by the Loader applet. recieves as a parameter the progress in precentages
//  return(Void)  : None. 
//***********************************************************************************************
function OnDownload(str)
{
	window.status=str;
}


//***********************************************************************************************
//  Function Name : loadLoaderApplet 
//  description   : Write into document an applet tag to load the loader applet
//  return(Void)  : None. 
//***********************************************************************************************
function OnError(str)
{
	alert("error in downloading: "+str);
}

//***********************************************************************************************




//***********************************************************************************************
//  Function Name : reload() 
//  description   : called by a sub-window, after the download and setup, refreshes the current page
//					so the button will be visible.
//  return(Void)  : None.
//***********************************************************************************************
function reload(){
	newLoc=window.location+"";
	pos=newLoc.indexOf("?");
	if (pos==-1) 
		newLoc=newLoc+"?VTSnCSetupOK";
	else 
		newLoc=newLoc+"&VTSnCSetupOK";
	window.location.href=newLoc;
}



//***********************************************************************************************
//  Function Name : UpgradeSnC 
//  description   : check current version if exists, and updates or installs if nessecery.
//  return(Void)  : None.
//***********************************************************************************************
function UpgradeSnC()
{
	var file2download="";
	browser = GetBrowser();
	if (ie)
		file2download = MSIE_SncFile;
	else
		file2download = Netscape_SncFile;
	loadLoaderApplet(file2download);
}
//***********************************************************************************************






