//**************************************************************************
// FILENAME: $Workfile: utils.js $
// DESCRIPTION:  Common utility file of javascript functions
//
// AUTHOR: $Author: Jprucha $
// CREATED:  2/14/06
// LAST MODIFIED: $Modtime: 7/26/06 8:14a $
// FILE VERSION:  $Revision: 2 $
// 
// 
// Copyright (C) 2005 Molecular, Inc.
// 343 Arsenal Street, Watertown MA 02139
// 617-218-6500
//***************************************************************************


/*

This method attempts to write a cookie to see if cookies and javascript are enabled.
If cookies are not enabled but JavaScript is enabled then users will get an alert indicating
that Cookies must be enabled.

If both cookies and javascript are disabled the "cookieexists" hidden form value will remain false.  This
hidden form value needs to be checked in the server code.  If it is false the server code should redirect
to an error page.

*/
function checkCookieAndJavaScript(currentForm)
{
	/* check for a cookie */
	if (document.cookie == "") 
	{
		/* if a cookie is not found - alert user -
		change cookieexists field value to false */
		alert("COOKIES need to be enabled!");

		/* If the user has Cookies disabled an alert will let him know 
		that cookies need to be enabled to log on.*/ 

		currentForm.cookieexists.value ="false";  
	}
	else
	{
		/* this sets the value to true and nothing else will happen,
		the user will be able to log on*/
		currentForm.cookieexists.value ="true";
	}
}

// Generic function that will load the returned xml into a document object model.
// This is browser independant for IE and Mozilla.
function LoadXmlString(response)
{
	var returnedXml = response.value;
	var xmlDoc = null;

	// For Mozilla based browsers
	if (document.implementation && document.implementation.createDocument)
	{
		// This extends the document object for Mozilla type browsers.
		// Allows for the loading of an XML document using a string.
		Document.prototype.loadXML = function(XmlString) 
									{
										// parse the string to a new doc   
										var xmlDoc = (new DOMParser()).parseFromString(XmlString, "text/xml");
												
										// remove all initial children
										while (this.hasChildNodes())
											this.removeChild(this.lastChild);
													
										// insert and import nodes
										for (var x = 0; x < xmlDoc.childNodes.length; x++) 
										{
											this.appendChild(this.importNode(xmlDoc.childNodes[x], true));
										}
									};
									
		xmlDoc = document.implementation.createDocument("", "addressDoc", null);
		xmlDoc.async = "false";
		xmlDoc.loadXML(returnedXml);
	}
	// For IE based browsers
	else if (window.ActiveXObject)
	{
		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async = "false";
		xmlDoc.loadXML(returnedXml);		
 	}
	else
	{
		alert('Your browser can\'t handle this script');
		return xmlDoc;
	}
	
	return xmlDoc;
}

/* Set a cookie to be sure that one exists.
   Note that this is outside the function*/
document.cookie = 'killme' + escape('nothing')
// -->

// Browser Detect code
<!--
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();
// -->
