// JavaScript Document

//Function to add onload events.
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
	window.onload = func;
  } else {
	window.onload = function() {
	  oldonload();
	  func();
	}
  }
}

//Function to unload loaded events.
function addUnLoadEvent(func) {
	var oldonunload = window.onunload;
	if (typeof window.onunload != 'function') {
	  window.onunload = func;
	} else {
	  window.onunload = function() {
		oldonunload();
		func();
	  }
	}
}



//Script to detect browser
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: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			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.userAgent,
			   subString: "iPhone",
			   identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();



//To use this pop-up code you must use the required css.
function showTop(popUpElementId,screenOverlayElementId) {
	// for IE6.0    
	if ((BrowserDetect.browser == "Explorer") && (BrowserDetect.version<7)) {          
	  if (document.body.clientHeight > document.documentElement.clientHeight ) {     
		document.getElementById(screenOverlayElementId).style.height = document.body.clientHeight;
	  } else {
		document.getElementById(screenOverlayElementId).style.height = document.documentElement.clientHeight;
	  }
	  
	  if (document.body.clientWidth > document.documentElement.clientWidth ) {     
		document.getElementById(screenOverlayElementId).style.width = document.body.clientWidth;
	  } else {
		document.getElementById(screenOverlayElementId).style.width = document.documentElement.clientWidth;
	  }
	}

		//Show the background overlay and topbox...
		document.getElementById(screenOverlayElementId).style.visibility = 'visible';
		if (document.getElementById(popUpElementId)) {
			document.getElementById(popUpElementId).style.display = 'block';
			verticallyCenter(popUpElementId);
		}
	}  	

	function closeTop(popUpElementId,screenOverlayElementId)	{
		//Hide the overlay and tobox...
		document.getElementById(screenOverlayElementId).style.visibility = 'hidden';
		if (document.getElementById(popUpElementId)) {
			document.getElementById(popUpElementId).style.display = 'none';
		}
	}     
  
  function viewportSize(side) {
	var viewportWidth;
	var viewportHeight;
 
	// for standards compliant browsers (mozilla/netscape/opera/IE7)     
	if (typeof window.innerWidth != 'undefined') {
	  viewportWidth = window.innerWidth,
	  viewportHeight = window.innerHeight
	}        
	// IE6 in standards compliant mode (i.e. with a valid doctype)    
	else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
	 viewportWidth = document.documentElement.clientWidth,
	 viewportHeight = document.documentElement.clientHeight
	}        
	// older versions of IE
	else {
	 viewportWidth = document.getElementsByTagName('body')[0].clientWidth,
	 viewportHeight = document.getElementsByTagName('body')[0].clientHeight
	}  

	return (side == 'width' ? viewportWidth : viewportHeight);
  } 

  window.onresize = function() {
		var popUpElementId;
		verticallyCenter(popUpElementId);
	};
  
  function verticallyCenter(id) {
		if (document.getElementById(id)) {
			var elementHeight=document.getElementById(id).offsetHeight;
			var elementWidth=document.getElementById(id).offsetWidth;
		
			document.getElementById(id).style.top = (viewportSize('height')-elementHeight)/2+"px";
			document.getElementById(id).style.left = (viewportSize('width')-elementWidth)/2+"px";
		}
  }
  
//Standard Dreamwaever jump box 
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
