<!--
/******************************************************************************
$Workfile: svgViewer.js $
$Revision: 12 $
$Author: Nfeller $

Checks client for appropriate version of svg viewer.

Copyright © 2004 OSIsoft, Inc. All rights reserved.
Unpublished - rights reserved under the copyright law of the United States.
USE OF A COPYRIGHT NOTICE IS PRECAUTIONARY ONLY AND DOES NOT
IMPLY PUBLICATION OR DISCLOSURE.
THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE SECRETS OF OSIsoft, Inc. USE, DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF OSIsoft, Inc.
RESTRICTED RIGHTS LEGEND
Use, duplication, or disclosure by the Government is subject to restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in Technical Data and Computer Software clause at DFARS 252.227.7013

OSIsoft, Inc.
777 Davis St., San Leandro CA 94577
*******************************************************************************/
// JScript source code

var isViewerAvailable = true;
function isSVGControlInstalled() {
	return  ((new ActiveXObject("Adobe.SVGCtl") == null) ? false : true)
}
function getBrowser()
{
var agt=navigator.userAgent.toLowerCase();
var v_maj=parseInt(navigator.appVersion);
var v_min=parseFloat(navigator.appVersion);
is_nav=((agt.indexOf('mozilla')!=-1)&&(agt.indexOf('spoofer')==-1)&&
	(agt.indexOf('compatible')==-1)&&(agt.indexOf('opera')==-1)&&
	(agt.indexOf('webtv')==-1));
is_nav3=(is_nav&&(v_maj==3));
is_nav4up=(is_nav&&(v_maj>=4));
is_nav407up=(is_nav&&(v_min>=4.07));
is_nav408up=(is_nav&&(v_min>=4.08));
is_ie=(agt.indexOf("msie")!=-1);
is_ie3=(is_ie&&(v_maj<4));
is_ie4=(is_ie&&(v_maj==4)&&(agt.indexOf("msie 5.0")==-1));
is_ie4up=(is_ie&&(v_maj>=4));
is_ie5=(is_ie&&(v_maj==4)&&(agt.indexOf("msie 5.0")!=-1)); 
is_ie5up=(is_ie&&!is_ie3&&!is_ie4);
is_win=((agt.indexOf("win")!=-1)||(agt.indexOf("16bit")!=-1));
is_win95=((agt.indexOf("win95")!=-1)||(agt.indexOf("windows 95")!=-1));
is_win98=((agt.indexOf("win98")!=-1)||(agt.indexOf("windows 98")!=-1));
is_winnt=((agt.indexOf("winnt")!=-1)||(agt.indexOf("windows nt")!=-1));
is_win32=(is_win95||is_winnt||is_win98||
	((v_maj>=4)&&(navigator.platform=="Win32"))||
	(agt.indexOf("win32")!=-1)||(agt.indexOf("32bit")!=-1));
is_mac=(agt.indexOf("mac")!=-1);
is_macPPC=(is_mac&&((agt.indexOf("ppc")!=-1)||(agt.indexOf("powerpc")!=-1)));
}

function setCookie(name, value, expires, path, domain, secure) {
var curCookie=name+"="+escape(value)+
	((expires)?"; expires="+expires.toGMTString():"")+
	((path)?"; path="+path:"")+
	((domain)?"; domain="+domain:"")+
	((secure)?"; secure":"");
document.cookie=curCookie;
}

// returns null if cookie not found
function getCookie(name) {
var dc=document.cookie;
var prefix=name+"=";
var begin=dc.indexOf("; "+prefix);
if(begin==-1) {
	begin=dc.indexOf(prefix);
	if(begin!=0)
		return null;
	}
else
	begin+=2;
var end=document.cookie.indexOf(";",begin);
if(end==-1)
end=dc.length;
return unescape(dc.substring(begin+prefix.length,end));
}

function deleteCookie(name, path, domain) {
if(getCookie(name))
	document.cookie=name+"="+((path)?"; path="+path:"")+
	((domain)?"; domain="+domain:"")+"; expires=Thu, 01-Jan-70 00:00:01 GMT";
}

function fixDate(date) {
var base=new Date(0);
var skew=base.getTime();
if(skew>0)
	date.setTime(date.getTime()-skew);
}

// 21461 - use javascript variable for svgviewer root
var svgInstallBase=svgInfoPage + "viewer/install/";
var svgInstallPage=svgInstallBase+"auto/";
var svgDownloadPage=svgInstallBase;

var checkIntervalDays=30;
var firstSVG=true; // Ask only once per page even without cookies

function getSVGInstallPage() {
	// return svgInstallPage+"?"+location;   // adobe
	return svgInstallPage;					 // us
}

function getCheckInterval() {
return checkIntervalDays*24*60*60*1000;
}

// The value of the cookie is '0'. We need some value, but it doesn't matter what.
// We set the cookie for the entire site by specifying the path '/'.
// We could include something from adobe.com and set the cookie for that site.
// This would enable only asking once no matter how many sites a user encounters
// with SVG.
function setSVGCookie() {
if(getCheckInterval()>0) {
	var expires=new Date();
	fixDate(expires); // NN2/Mac bug
	expires.setTime(expires.getTime()+getCheckInterval());
	setCookie('SVGCheck','0',expires,'/')
	}
}

function isSVGPluginInstalled() {
return (navigator.mimeTypes["image/svg"]&&navigator.mimeTypes["image/svg"].enabledPlugin!=null)||
       (navigator.mimeTypes["image/svg-xml"]&&navigator.mimeTypes["image/svg-xml"].enabledPlugin!=null);
}

function checkSVGViewer() {
	window.askForSVGViewer=false;
	try
	{
		if(window.svgInstalled)
			return;
		getBrowser();
		if(is_win32 && is_ie4up) {
			window.svgViewerAvailable=true;
			window.svgInstalled=isSVGControlInstalled();
			if(!window.svgInstalled)
				window.askForSVGViewer=true;
			}
		else if((is_win32 && is_nav4up) || (is_macPPC && is_nav407up)) {
			window.svgViewerAvailable=true;
			window.svgInstalled=isSVGPluginInstalled();
			if(!window.svgInstalled&&is_nav408up&&navigator.javaEnabled())
				window.askForSVGViewer=true;
			}
		else if(is_macPPC && is_ie5up)
			window.svgViewerAvailable=true;
	}
	catch(e)
	{
		window.askForSVGViewer=true;
	}	
}

function getSVGViewer() {
	if(confirm('The Adobe SVG Viewer is not installed. Download now?'))
	{
		location=getSVGInstallPage();
	}
	else
	{
		isViewerAvailable = false;
		return true;
	}	
}

function checkAndGetSVGViewer() {
	checkSVGViewer();

	if(window.askForSVGViewer) {
		return getSVGViewer();
//		return false;
	}
	return true;	
}

function checkViewerVersion(VersionString) {
	// expect VersionString to look like: "Adobe; 3.0"
	var wIndex;
	var sVersion;
	
	wIndex = VersionString.search(";");
	if (wIndex!=-1) {
		sVersion = VersionString.slice(wIndex+1);
		if (sVersion.valueOf() >= 3) return true;			
	}
	if(confirm(msgAdobeVer))
		location=getSVGInstallPage();
	
	return false;
}

function emitSVG(embedAttrs) {
if(window.svgInstalled)
	document.writeln('<embed '+embedAttrs+'>');
else if(window.askForSVGViewer)	{
	if(navigator.appName=='Netscape') {
		document.writeln('<p>' + msgNeedViewer);
		document.writeln('<a href="'+getSVGInstallPage()+'">' + msgClickHere + '</a></p>');
		}
	else
		document.writeln('<embed '+embedAttrs+' pluginspage="'+getSVGInstallPage()+'">');
	}
else if(window.svgViewerAvailable)
	document.writeln('<embed '+embedAttrs+' pluginspage="'+svgDownloadPage+'">');
else {
	document.writeln('<p>'+ msgNoViewer);
	document.writeln('<a href="'+svgInfoPage+'">' + msgClickHere + '</a></p>');
	}
}
-->