/*
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

	BROWSER FUNCTIONS
	version 2.0.1 - 2008-08-04
	
	TRMI - PLAZA ADMIN - Gaurdian Toll Collection System
	
-----------------------------------------------------------------------------------------------------------------------------

	DEPENDENCIES: MooTools - version 1.11               
	copyright 2007 | Valerio Proietti | http://mootools.net/
	MIT-style license | http://www.opensource.org/licenses/mit-license.php
	
-----------------------------------------------------------------------------------------------------------------------------

	:: squarehead design studio   -  845.331.1953 | www.squarehead.com | sbliss@squarehead.com
	
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*/





/* 	pop-up window, ceneterd with no features
---------------------------------------------------------------------------------------------------------------------------*/

function centerPop(pageurl,popwidth,popheight){
	
// --------> find x and y to center on screen
	var screenWidth=window.screen.width;
	var screenHeight=window.screen.height;
	var xPosition=(screenWidth/2)-((popwidth)/2);
	var yPosition=(screenHeight/2)-((popheight)/2);
	
// --------> Clientside	function: http://www.clientcide.com/docs/Browser/Popup
	var centeredPopup = new Browser.Popup(pageurl,{
	  width: popwidth,
	  height: popheight,
	  x: xPosition,
	  y: yPosition
	});
}


/* 	browser detection functions

	BrowserDetect.OS = platform
	BrowserDetect.browser = browser application name
	BrowserDetect.version = browser version number
---------------------------------------------------------------------------------------------------------------------------*/

// --------> Used by the Login screen - set cases accordingly
function checkBrowser(){
	messageRequiremnts = " <strong>To assure the best possible user experience we suggest that you use a more compliant browser, either <a href='http://www.mozilla.com'>Firefox</a> or <a href='http://www.apple.com/safari'>Safari</a>.</strong>"
	var b = BrowserDetect.browser;
	var v = BrowserDetect.version;
	switch (b)
	{
	case "Safari":
	  action = "ok";
	  break;
	case "Firefox":
	  action = "ok";
	  break;
	case "Explorer":
	  action = "bad";
	  break;
	default:
	  action = "bad";
	}
	if(action == "ok"){
		$('badBrowser').dispose();
	} else {
		//$('goodBrowser').remove();
	if(v == "6"){
		document.write("<p>We are sorry, but <strong>"+b+" "+v+"</strong> is not supported by this application and you may experience problems.");
	} else if(v == "7") {
		document.write("<p><strong>"+b+" "+v+"</strong> is not the preferred browser for this application.");
	}
		document.write(messageRequiremnts+"</p>");
	}
}

// --------> used by the developer page to build browser info table
function browserVersion(){	
	document.write("<table class='browserdata'>");
	document.write("<tr><th colspan=3 class='browserdata_head'>detected browser</th></tr>");
	document.write("<tr><th width='80'>platform</th><th width='80'>browser</th><th>version</th></tr>");
	document.write("<tr><td>"+BrowserDetect.OS+"</td><td>"+BrowserDetect.browser+"</td><td>"+BrowserDetect.version+"</td></tr>");
	document.write("</table>");
}

// --------> this is the browser detect function - from: http://www.quirksmode.org/js/detect.html 
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.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			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"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// 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();
