/*
* ps_BrowserRoutines.js
* 1/10/01
* Copyright (c) 2001 max mail. all rights reserved.
*/

function Check_Browser_Caps() {
	var browserOK = true;
	var errMsg = "The following features are required by this restricted site." + "\n" +
								"However, the feature\(s\) listed below are not set correctly." + "\n\n";
	var browserCaps = new Array(new Array('Cookie', true, 'The browser must accept cookies \(to prevent repetitious entry of passwords\).'),
															new Array('Screen Resolution', true, 'The screen resolution must be at least 800x600 pixels.'),
															new Array('Browser Version', true, 'The browser version must be at least version 4.0'));

	// set cookie to test if cookies are enabled
	document.cookie = "PASTestCookie=proactive cookie test";

	// flag corresponding bits in browserCaps if Get_Cookie() doesn't return cookie
	// flag browserOK if err detected
	if (Get_Cookie('PASTestCookie')) {
		//window.alert("found cookie... deleting...");
		Delete_Cookie('PASTestCookie');
		}
		else {
			//window.alert("no cookie");
			browserCaps[0][1]=false;		// row 0, column 1 corresponds to cookie
			browserOK = false;					// flag browserOK to display errMsg
			}
	// query screen resolution
	if (window.screen.width < 800 || window.screen.height < 600) {
		browserCaps[1][1] = false;
		browserOK = false;
	}

	// query browser version
	if (parseInt(navigator.appVersion) < 4) {
		browserCaps[2][1] = false;
		browserOK = false;
	}

	// parse array 4 err flags and display condition to user
	if (!browserOK) {
		for (i = 0; i < browserCaps.length; i++) {
			if (!browserCaps[i][1])
				errMsg += browserCaps[i][2] + "\n"
		}// for

		window.alert(errMsg);
	}//if (browserOK)

	/*
	window.alert("appVersion: " + parseInt(navigator.appVersion) + "\n" +
								"width    : " + window.screen.width + "\n" +
								"height   : " + window.screen.height + "\n" +
								"platform : " + window.navigator.platform);*/

}//Check_Browser_Caps


/*****************************************************************
	this function retrieves the cookie passed as an argument
	if unsuccesfull, it returns null, otherwise returns cookie value
*****************************************************************/
function Get_Cookie(name) {
	var start = document.cookie.indexOf(name + "=");
	var len = start + name.length + 1;
	if ((!start) && (name != document.cookie.substring(0, name.length))) return null;
	if (start == -1) return null;
	var end = document.cookie.indexOf(";", len);
	if (end == -1) end = document.cookie.length;
	return unescape(document.cookie.substring(len,end));
}//Get_Cookie(name)


/*************************************************************
	this function deletes the cookie passed to it as an argument
	if the cookie exists. path/domain arguments are optional
**************************************************************/
function Delete_Cookie(name, path, domain) {
	if (Get_Cookie(name)){
		document.cookie = name + "=" +
		( (path) ? ";path=" + path : "") +
		( (domain) ? ";domain=" + domain : "") +
		";expires=Thu, 01-Jan-1970 00:00:01 GMT";
	}// (Get_Cookie(name))

}//Delete_Cookie
