// JavaScript Document

function flashProcessContent(index){
	var checkCookie=readCookie('loanTarget');
	if(!(checkCookie)){
		processContent(index);	
	}
}

function processContent(index) {
	clearTimeout(timeOut);
	var g=index;
	var h=$(index);
	var checkValue=g.replace(/Link/g,'');
	h.parentNode.parentNode.className=h.parentNode.className.replace(/openned/g,'');
	if (checkValue == currentContent) {
		closeContent(checkValue);
	} else {
		h.parentNode.parentNode.className+=' openned';
		if(currentContent!='none'){
			var f=$(currentContent+"Link");
			f.parentNode.parentNode.className=f.parentNode.parentNode.className.replace(/openned/g,'');
			closeContent(currentContent);
		}
		openContent(checkValue);
	}
}

function openContent(index){
	Effect.BlindDown(index,{duration:.4});
	currentContent=index;
	writeCookie('loanTarget',index);
}

function closeContent(index){
	Effect.BlindUp(index,{duration:.4});
	currentContent="none";
	writeCookie('loanTarget','none');
}

function showMenu(index){
	moveBack(currentSignIn);
	$(index).style.display='block';
	currentSignIn=index;
}

function initializeTitles(index){
	var f=$(index);
	if(f){
		for (var i=0;i<f.length;i++){
			if (f[i].title){
				var idName;
				if(f[i].id){
					idName=f[i].id;	
				} else {
					idName="id"+titleCount;
					f[i].id=idName;
				}
				titleMessage[idName]=f[i].title;
				f[i].title='';
				titleCount++;
			}
		}
	}
}

function showTitle(index,method){
	var target='titleBox';
	var data=titleMessage[index.id];
	if(method=='show'){
		t=setTimeout("move('"+target+"','"+index.id+"','"+data+"')",750);
	} else {
		clearTimeout(t);
		moveBack(target);
	}
}

function move(div,index,data){
	moveBack(div);
	var topPosition=yMousePos+15;
	var leftPosition=xMousePos+15;
	var e=$(div);
	var f=$(index);
	e.style.top=topPosition+'px';
	e.style.left=leftPosition+'px';
	f.focus();
	if(div=='floatDiv'){
		fillContent(div,data);
	} else {
		e.innerHTML=data;
	}
	e.style.display='block';
}

function moveBack(div){
	$(div).style.display='none';
}

addLoadEvent(function(){
  if (document.layers) { // Netscape
    document.captureEvents(Event.MOUSEMOVE);
    document.onmousemove = captureMousePosition;
  } else if (document.all) { // Internet Explorer
    document.onmousemove = captureMousePosition;
  } else if (document.getElementById) { // Netcsape 6
    document.onmousemove = captureMousePosition;
  }
});

// Global variables
xMousePos = 0; // Horizontal position of the mouse on the screen
yMousePos = 0; // Vertical position of the mouse on the screen
xMousePosMax = 0; // Width of the page
yMousePosMax = 0; // Height of the page

function captureMousePosition(e) {
    if (document.layers) {
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    } else if (document.all) {
        xMousePos = window.event.x+document.body.scrollLeft;
        yMousePos = window.event.y+document.body.scrollTop;
        xMousePosMax = document.body.clientWidth+document.body.scrollLeft;
        yMousePosMax = document.body.clientHeight+document.body.scrollTop;
    } else if (document.getElementById) {
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    }
}

function sortByDate(a, b) {
    var x = a.sortDate;
    var y = b.sortDate;
    return ((x < y) ? -1 : ((x > y) ? 1 : 0));
}

function openPortalChild(childURL,width,height,params) {
	if(height == undefined)height = screen.height * .7;
	if(width == undefined)width = (screen.width * .7);
	if(params == undefined)params = "left=100,status=yes,titlebar=yes,scrollbars=yes,resizable=yes,toolbar=yes";
	portalChild = window.open(childURL, "portalChild", "width=" + width  + ",height=" + height + "," + params);
}

function degradeHomePage(){
	$('portalSwitch').href="#";
	$('portalSwitch').target="_self";
	var tempClass=document.getElementById('studentSignIn').className.replace(/hide/g,'');
	document.getElementById('studentSignIn').className=tempClass;
	var f=getElementsByClassName('loanList');
	for (var i=0;i<f.length;i++){
		f[i].style.display='block';	
	}
	document.getElementById('quickLink').style.display='inline';
	var g=getElementsByClassName('bLink');
	for (var j=0;j<g.length;j++){
		g[j].href="#";
	}							 
}

function showList(list,method){
	var f=document.getElementById(list);
	var cssMethod;
	if(method=='show'){
		cssMethod='block';
		if(fakeWindow=='none'){
			if(window.addEventListener) {
				window.addEventListener("mouseup",launchHide,true);
			} else if (window.attachEvent) {
				document.getElementById('wrapper').attachEvent("onmouseup",launchHide);
			}
		}
		fakeWindow=list;
	} else {
		cssMethod='none';
	}
	f.style.display=cssMethod;
}

function hoverShow(index,method){
	var cssMethod;
	if(method=='show'){
		cssMethod='hoverSelect';
	} else {
		cssMethod='';
	}
	index.className=cssMethod;
}

function launchHide(){
	var watchTimer=setTimeout(stopWatch,150);
}

function stopWatch(){
	var f=document.getElementById(fakeWindow);
	if(f){
		f.style.display='none';
	}
	if(window.removeEventListener) {
		window.removeEventListener("mouseup",launchHide,true);
	} else if (window.attachEvent) {
		document.getElementById('wrapper').detachEvent("onmouseup",launchHide);
	}
	fakeWindow='none';
}

function hitCounter(index){
	var urlIndex='/links/';
	if(index=='javascript'){
		urlIndex+='hm_javascript.htm';
	} else if (index=='accountAccess'){
		urlIndex+='hm_js_account_access.htm';
	} else if (index=='schoolLogin'){
		urlIndex+='hm_js_school_login.htm';
	} else if (index=='calendarOffsite'){
		urlIndex+='hm_calendar_offsite.htm';
	} else if (index=='calendarDetail'){
		urlIndex+='hm_calendar_detail.htm';
	} else if (index=='helpfulTool'){
		urlIndex+='hm_helpful_tool.htm';	
	} else if (index=='newsletter'){
		urlIndex+='hm_js_newsletter.htm';
	} else if (index=='schoolMessage'){
		urlIndex+='hm_js_school_messages.htm';
	} else if (index=='schoolPassword'){
		urlIndex+='hm_js_school_password.htm';
	}
	if(urlIndex.length>6){
		var e=document.getElementById('counter');
		e.src=urlIndex;
	}
}

function reformatInput(index){
	var f=document.getElementById(index.id);
	f.style.fontStyle="normal";
	f.style.color="black";
}

function unformatInput(index){
	var f=document.getElementById(index.id);
	if (f.value=='for students/borrowers'){
		f.style.fontStyle="italic";
		f.style.color="#999999";
	}
}

function focusField(index){
	document.getElementById(index).focus();	
}