function writeMailTo(u,d){
	if(!d)d="magellanfoundation.org";
	document.write('<a href="mailto:'+u+'@'+d+'">'+u+'@'+d+'</a>');
}

var aNavImg=new Array;
function rollover(oImg){
	strImgSrc=oImg.src;
	strImgOverSrc=strImgSrc.replace('_off','_over');
	oImg.src=strImgOverSrc;
	//alert('over ' + oImg.src)
}
function rolloff(oImg){
	strImgSrc=oImg.src;
	strImgOffSrc=strImgSrc.replace('_over','_off');
	oImg.src=strImgOffSrc;	
	//alert('off '+oImg.src)
}				
function attachRollovers(){
	if(document.getElementById){
		var oNavDiv=document.getElementById('nav');
		if(document.getElementsByTagName){
			aNavImg=oNavDiv.getElementsByTagName('img');				
			if(aNavImg && aNavImg.length > 0){
				for(i=0;i<aNavImg.length;i++){
					var strCurrImgSrc=aNavImg[i].src;
					var shouldAttachRollover=(strCurrImgSrc.indexOf('_off')!=-1);
					if(shouldAttachRollover){
						//preload
						oThisOverImg=new Image();
						oThisOverImg.src=strCurrImgSrc.replace('_off','_over');							
						//attach behaviors
						aNavImg[i].onmouseover=function(){rollover(this)};
						aNavImg[i].onmouseout=function(){rolloff(this)};
					}
				}
			}
		}
	}
}

function equalizeColumnHeights(){
	if(document.getElementById('contentcontainer')){
		var nContentHeight=getElementHeight('contentcontainer');
		var oSubmitButt=document.getElementById('submitButton');
		if(oSubmitButt){
			var aOButtPos=findPos(oSubmitButt);
			var nButtonBottomHeight=(getElementHeight(oSubmitButt)+aOButtPos[1]);
			if(nContentHeight < nButtonBottomHeight)nContentHeight=nButtonBottomHeight+10;
		}
		var nNavHeight=getElementHeight('nav');
		var nMinContentHeight=640;
		//alert('B4:\ncontentheight='+nContentHeight+'\nnavheight='+nNavHeight);
		if(nContentHeight != nNavHeight || nContentHeight<nMinContentHeight){
			nTallestHeight=(nContentHeight > nNavHeight)?nContentHeight:nNavHeight;
			if(nTallestHeight<nMinContentHeight)nTallestHeight=nMinContentHeight;
			setElementProperty('contentcontainer', 'height', (nTallestHeight-62)+'px');
			setElementProperty('nav', 'height', nTallestHeight+'px');
		}
		//alert('AFTER: contentheight='+nContentHeight+'\nnavheight='+nNavHeight);
	}
}

function initpage(){
	equalizeColumnHeights();
	attachRollovers();
	if(document.location.href.indexOf("http://")==0){
		//alert('tooltips on?');
		//window.setTimeout("hovertipInit", 1);
	}
}

$(document).ready(function() {initpage();});

function displaySSLInfo(){
	var oSslInfoDiv=document.getElementById('sslinfo');
	var oSslLogoDiv=document.getElementById('certlogo');
	if(oSslInfoDiv)if(oSslInfoDiv.style)oSslInfoDiv.style.display='block';
	//$(oSslInfoDiv).fadeIn("fast",function(){ alert("Animation Done."); });
	if(oSslLogoDiv)if(oSslLogoDiv.style)oSslLogoDiv.style.backgroundColor='white';
}
function hideSSLInfo(){
	var oSslInfoDiv=document.getElementById('sslinfo');
	var oSslLogoDiv=document.getElementById('certlogo');
	if(oSslInfoDiv)if(oSslInfoDiv.style)oSslInfoDiv.style.display='none';
	if(oSslLogoDiv)if(oSslLogoDiv.style)oSslLogoDiv.style.backgroundColor='transparent';
}

/*utils*/
function launchExternal(winUrl,winName){
	if(winUrl.indexOf("schoolbenchmarking")!=-1)
		var winFeatures="width=850,height=500,location=1,scrollbars=1,menubar=1,toolbar=1,resizable=1";
	else
		var winFeatures="width=740,height=500,location=1,scrollbars=1,menubar=1,toolbar=1,resizable=1";
	generalOpenWin(winUrl,winName,winFeatures);
}
function generalOpenWin(winUrl,winName,winFeatures){
	var newWin=window.open(winUrl,winName,winFeatures);
	if (window.focus)newWin.focus();		
}

function getElementHeight(p_elm){
	var elm;
	if(typeof(p_elm) == "object"){
		elm = p_elm;
	} else {
		elm = document.getElementById(p_elm);
	}
	return parseInt(elm.offsetHeight);
}
/* Return the px distances from bottom border of the element to border top of the window */
function getElementBottom(p_elm){
	return getElementTop(p_elm) + getElementHeight(p_elm);
}

/* Return a style property of the elemnt , it return null if does not exist */
function getElementProperty(p_elm, p_property){
	var elm = null;
	if(typeof(p_elm) == "object"){
		elm = p_elm;
	} else {
		elm = document.getElementById(p_elm);
	}
	if (elm != null){
		if(elm.style){
			elm = elm.style;
			if(elm[p_property]){
				return elm[p_property];
			} else {
				return null;
			}
		} else {
			return null;
		}
	}
}

/* Set a property of style type of the element */
function setElementProperty(p_elm, p_property, p_value){
	var elm = null;
	if(typeof(p_elm) == "object"){
		elm = p_elm;
	} else {
		elm = document.getElementById(p_elm);
	}
	if((elm != null) && (elm.style != null)){
		elm = elm.style;
		elm[ p_property ] = p_value;
	}
}


/* Find the true position */
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}



/*  Listener-age */
function AttachEvent(elementObj, eventName, eventHandlerFunctionName){
	if (elementObj.addEventListener) { // Non-IE browsers
		elementObj.addEventListener(eventName, eventHandlerFunctionName, false);		
	} else if (elementObj.attachEvent) { // IE 6+
		elementObj.attachEvent('on' + eventName, eventHandlerFunctionName);
	} else { // Older browsers 
		var currentEventHandler = elementObj['on' + eventName];
		if (currentEventHandler == null){
			elementObj['on' + eventName] = eventHandlerFunctionName;
		} else {
			elementObj['on' + eventName] = function(e) { currentEventHandler(e); eventHandlerFunctionName(e); }
		}
	}
}



// @eventArgs is an interface of type Event: http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-Event
/*
function Load_EventHandler(eventArgs){
  alert("here");
}

AttachEvent(window, "load", Load_EventHandler);
*/