//global.js

window.onload = function(){
	set_height();
	setTargetBlank();
	form_focus();
} 

//--------------------------------------------------------------------------------------------------

function set_height(){
	try{
		if(document.getElementById("main").offsetHeight < document.getElementById("nav").offsetHeight){
			document.getElementById("main").style.height = document.getElementById("nav").offsetHeight + "px";
		}
	}
	catch(er){
		
	}
}

//--------------------------------------------------------------------------------------------------

function form_focus(){
	try{
		if(document.forms[0].id == "login-form"){
			document.forms[0].elements["email"].focus();
		}else if(document.forms[0].id == "register-form"){
			document.forms[0].elements["fname"].focus();
		}else if(document.forms[0].id == "password-form"){
			document.forms[0].elements["email"].focus();
		}else if(document.forms[0].id == "friend-form"){
			document.forms[0].elements["to_name"].focus();
		}
	}
	catch(er){ }
}

//--------------------------------------------------------------------------------------------------

//Browser Detection/Redirection
detect();
function detect(){
	var userAgent = navigator.userAgent;
	//KEEP OUT: IE 5.0, IE 5.5, NN 7.x
	if(userAgent.indexOf("MSIE 5.0") != -1 || userAgent.indexOf("MSIE 5.5") != -1 || userAgent.indexOf("Netscape/7") != -1 ){
		//alert("Unsupported Browser: \n" + userAgent);
		location.href = "upgrade/index.html";
	}
}

//--------------------------------------------------------------------------------------------------

//open centered popup
function openPopup(URL, ident, width, height, scrolling){

	var startX = ((screen.availWidth - width)/2);
	var startY = ((screen.availHeight - height)/2);		
	var options = "height=" + height + ",width=" + width + ",left=" + startX + ",top=" + startY + ",screenX=" + startX + ",screenY=" + startY + ",directories=no,location=no,menubar=no,resizable=no,noresize,scrollbars="+scrolling+",status=no,titlebar=no,toolbar=no";
	var objWindow = window.open(URL, ident, options);
	objWindow.focus();
	
}

//--------------------------------------------------------------------------------------------------

//standards-compliant target="_blank" functionality
function setTargetBlank() {
	if (document.getElementsByTagName){
		var arrAnchors = document.getElementsByTagName("a");
		for (var i=0; i<arrAnchors.length; i++) {
			var anchor = arrAnchors[i];
			if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "blank"){
				anchor.target = "_blank";
			}
		}
	}
} 

//--------------------------------------------------------------------------------------------------

//open glossary term
function glossary(term){
	openPopup('archive_glossary.php?term=' + term, 'glossary_win', 597, 290, 'no');
}