XBrowserAddHandler(window,'load', onLoadHandler );

function onLoadHandler() {
	MM_preloadImages('_images/icons-profile.jpg','_images/icons-discussion.jpg');
	if(document.getElementById('loginForm')) {
		document.getElementById('directoryLink').onclick  = showLogin;
		document.getElementById('profileLink').onclick    = showLogin;
		//document.getElementById('discussionLink').onclick = showLogin;
		document.getElementById('classNotesLink').onclick = showLogin;
		document.getElementById('arwLink').onclick = showLogin;
		document.getElementById('loginForm').onsubmit     = validateForm;
	}
}

// Show Login: 
function showLogin(e) {
	
	// disable on click handler for this element
	this.onclick =null;
	// Get the Form Element w/ the 'loginForm' id, wherever it is in the document.
	var loginForm = document.getElementById('loginForm');	
	// The link destirnation is saved in the form urlRedirect hidden field 
	// (to forward the user where he wanted to go once the authentication is ok)
	document.getElementById('urlRedirect').value = this.href;
	// Keep a reference on the form's parent element 
	var parentNode = loginForm.parentNode;
	// Detach the Form Element from its parent (to move it around)
	var newForm = parentNode.removeChild(loginForm);	
	// The form is hidden by default. Make it visible
	newForm.style.display='block';
	// 'this' refers to the element clicked. Normaly a A element. We hide it. 
	this.style.display='none'; 
	// We now insert the previously detached form next to the A
	this.parentNode.appendChild(newForm);	
	// Remember the parent ? If that parents happend to be part of the navigation too (a LI), 
	// we show the (previously hidden) image (its firstchild, remember?).
	if(parentNode.tagName=='LI') {
		parentNode.getElementsByTagName('a')[0].style.display='block';
		// restore onclick handle
		parentNode.getElementsByTagName('a')[0].onclick = showLogin;
	}
	// stop the link from actually executing.
	return false; 
}


function validateForm(e) {
	
}

function XBrowserAddHandler(target,eventName,handlerName) {
	if(!target) return;
	if (target.addEventListener) { 
		target.addEventListener(eventName, function(e){eval(handlerName)(e);}, false);
	} else if (target.attachEvent) { 
		target.attachEvent("on" + eventName, function(e){eval(handlerName)(e);});
		} else { 
		var originalHandler = target["on" + eventName]; 
		if (originalHandler) { 
		  target["on" + eventName] = function(e){originalHandler(e);eval(handlerName)(e);}; 
		} else { 
		  target["on" + eventName] = eval(handlerName); 
		} 
	} 
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
