// Main Javasciript file, basic functions and main int.

////////////////////////////////////////////////////////////////////
/// Basic functions;

var isDOM = (document.getElementById ? true : false);
var isIE4 = ((document.all && !isDOM) ? true : false);
var isNS4 = (document.layers ? true : false);
var isIE = (navigator.appName=="Microsoft Internet Explorer" ? true:false);
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != 1)? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != 1)? true : false;

function getRef(id) 
{
	if (isDOM) return document.getElementById(id);
	if (isIE4) return document.all[id];
	if (isNS4) return document.layers[id];
}
document.getRef=getRef;

function getSty(id) 
{
	return (isNS4 ? getRef(id) : getRef(id).style);
}

document.getSty=getSty;

function getObjSty(obj)
{
	return (isNS4 ? obj : obj.style);
}

//////////////////////////////////////////////////////////////////
/// Cookie functions; (  by Bill Dortch of hIdaho Design. );
function getCookieVal (offset) 
{
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1) 
	{
		endstr = document.cookie.length;
	}
	return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) 
{
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) 
	{
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg) {
			return getCookieVal (j);
	}
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) 
		{
			break;
		}
	}
	return null;
}

function SetCookie (name,value,expires,path,domain,secure) 
{
	document.cookie = name + "=" + escape (value) +
		((expires) ? "; expires=" + expires.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");
}

function DeleteCookie (name,path,domain) 
{
	if (ZsTreeView_GetCookie(name)) 
	{
		document.cookie = name + "=" +
			((path) ? "; path=" + path : "") +
			((domain) ? "; domain=" + domain : "") +
			"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}
/////////////////////////////////////////////////////////////////
//// array functions
		function Contains(str,ar)
		{
			for (var i=0;i<ar.length;i++)
			{
				if (ar[i]==str)
				{
					return i;
				}
			}
			return -1;
		}


////////////////// flash detection... 

function JSGetSwfVer()
{
	// NS/Opera version >= 3 check for Flash plugin in plugin array
	if (navigator.plugins != null && navigator.plugins.length > 0) 
	{
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["ShockwaveFlash"])
		{
			var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
			var flashDescription = navigator.plugins["Shockwave Flash" +swVer2].description;
			descArray = flashDescription.split(" ");
			tempArrayMajor = descArray[2].split(".");
			versionMajor = tempArrayMajor[0];
			versionMinor = tempArrayMajor[1];
			if ( descArray[3] != "" ) 
			{
				tempArrayMinor = descArray[3].split("r");
			}
			else
			{
				tempArrayMinor = descArray[4].split("r");
			}
			versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
			flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
		} 
		else 
		{	
			flashVer = 1;
		}
	}
	// MSN/WebTV 2.6 supports Flash 4
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != 1)
			flashVer = 4;
	// WebTV 2.5 supports Flash 3
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != 1)
			flashVer = 3;
	// older WebTV supports Flash 2
	else if (navigator.userAgent.toLowerCase().indexOf("webtv") != 1)
			flashVer = 2;
	// Can't detect in all other cases
	else 
	{
		flashVer = 1;
	}
	return flashVer;
}
