/*_------------------------------ REFRESH WINDOW ---------------------------------*/
function refresh()
{
    window.location.reload( false );
}
/*_------------------------------ COLLAPSABLE ITEMS ---------------------------------*/
function expand(id)
{
	if (document.getElementById(id+"_content").style.display == 'none'){
		document.getElementById(id+"_content").style.display='block';
		document.getElementById(id+"_link").setAttribute((document.all ? "className" : "class"), "collapse");
	}else{
		document.getElementById(id+"_content").style.display='none';
		document.getElementById(id+"_link").setAttribute((document.all ? "className" : "class"), "expand");
	}
	document.getElementById("contentLeft").style.height = "100%";
}
/*_------------------------------ ALIGN COLUMNS ---------------------------------*/
function alignColumns()
{
	// ensures that columns are even.
	var h1 = document.getElementById("contentRight").offsetHeight;
	var h2 = document.getElementById("contentLeft").offsetHeight;
	if (h1 > h2){
		var hMax = h1;
	}else{
		var hMax = h2;
	}
	document.getElementById("contentRight").style.height = hMax+"px";
	document.getElementById("contentLeft").style.height = hMax+"px";
}
// for flash elements that need to be fullscreen
function resize_Handler()
{
	var topPadding = 41;
	if(document.location.toString().indexOf('wizard') !== -1){
		topPadding = 0;
	}
	if(document.all){
		$('flash').style.width = document.body.clientWidth;
		$('flash').style.height = document.body.clientHeight-topPadding;
	}else{
		$('flash').style.width = window.innerWidth;
		$('flash').style.height = window.innerHeight-topPadding;
	}
}
/*_------------------------------ ACCOUNT WINDOW ---------------------------------*/
function showAccount()
{
	document.getElementById('accountWindow').style.display = "block";
}
function hideAccount()
{
	document.getElementById('accountWindow').style.display = "none";
}
/*_------------------------------ NEW APP WINDOW ---------------------------------*/

function launchApp(url,swfID) 
{
	var w = screen.width-15;
	var h = screen.height-90;
	var xPos = (screen.width-w)/2;
	var yPos = (screen.height-h)/2;
	var newWin = window.open(url,'app','fullscreen=no,menubar=no,location=no,toolbar=no,resizable=yes,status=no,width='+w+',height='+h+',left='+xPos+',top='+yPos+'');
	if( !newWin ){
		document.getElementById(swfID).openWindowFromSwf(url);
	}else{
		if(typeof(newWin)!='undefined' && !newWin.closed) {
			newWin.blur();
		}else {
			var newWin = window.open(url,'app','fullscreen=no,menubar=no,location=no,toolbar=no,resizable=yes,status=no,width='+w+',height='+h+',left='+xPos+',top='+yPos+'');
		}
		// Just in case width and height are ignored
		//newWin.resizeTo(w, h);
		// Just in case left and top are ignored
		//alert(xPos+", "+yPos);
		newWin.moveTo(xPos, yPos);
		newWin.focus();
	}
	return false;
}
/*_------------------------------ GET URL VARIABLES ---------------------------------*/
function getURLVar(urlVarName)
{
	//divide the URL in half at the '?'
	var urlHalves = String(document.location).split('?');
	var urlVarValue = '';
	if(urlHalves[1]){
		//load all the name/value pairs into an array
		var urlVars = urlHalves[1].split('&');
		//loop over the list, and find the specified url variable
		for(i=0; i<=(urlVars.length); i++){
			if(urlVars[i]){
				//load the name/value pair into an array
				var urlVarPair = urlVars[i].split('=');
				if (urlVarPair[0] && urlVarPair[0] == urlVarName) {
					//I found a variable that matches, load it's value into the return variable
					urlVarValue = urlVarPair[1];
				}
			}
		}
	}
	return urlVarValue;   
}
/*_------------------------------ ALERT WINDOW ON EXIT ---------------------------------*/
var needToConfirm = false;
var confirmExitMessage = "";

window.onbeforeunload = confirmExit;
function confirmExit()
{
	if (needToConfirm){
		return confirmExitMessage;
	}
}
function enableConfirmExit(msg)
{
	confirmExitMessage = msg;
	needToConfirm = true;	
}
function disableConfirmExit()
{
	needToConfirm = false;
}
/*_------------------------------ LOGOUT ---------------------------------*/
function logout()
{
	var info = "action=userLogout";
	// send to php
	sendReq("/resources/php/ajax.php","LogoutStatus(req.responseText)",info);
}

function LogoutStatus(status){
	refresh();	
}
/*_------------------------------ FIX BUTTON ALIGNMENTS ---------------------------------*/
function buttonFix(btn){
	btn.getOffsetParent().setStyle({width:btn.getWidth()+10+'px'});
}
document.observe("dom:loaded", function() {
  // initially hide all containers for tab content
  $$('ul.button').each(function(s){ buttonFix(s); });
});
/*_------------------------------ BROWSER DETECTION ---------------------------------*/
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();
//alert(BrowserDetect.browser+" - "+BrowserDetect.OS);
/*_------------------------------ FIX FIREFOX FOCUS ---------------------------------*/
// there is a bug with FF and OSX 10.6 that causes mouse events not to fire until browser loses and regains fucus after a filebrowser appears from filereference.browse
function fixFocus()
{
	if(BrowserDetect.browser == "Firefox" && BrowserDetect.OS == "Mac"){
		var newWin = window.open("",'fix','fullscreen=no,menubar=no,location=no,toolbar=no,resizable=no,status=no,width=50,height=50');
		newWin.focus();
		newWin.close();
	}
}