/* Function for the Scholarship Calculator */
function ShowResult()
{
	var form = document.forms[0];
	var score = 0;
	var GAP = 0;

	if ( form.ACT.value != '' && (form.MathSAT.value != '' || form.VerbSAT.value != '') )
	{
		alert("Please enter values in the SAT fields or the ACT fields but not both");
	}

	if ( form.ACT.value != '' ) {
		// Calculate based on ACT
		var ACT = form.ACT.value;
		GPA = form.GPA2.value;

		if ( isNaN(ACT) || ACT>36 || ACT<0 ) {
			alert("ACT Score must be a number between 0 and 36");
			form.ACT.focus();
			return;
		}

		if ( isNaN(GPA) || GPA<0 || GPA>100 )
		{
			alert("GPA must be between 0 and 100");
			form.GPA2.focus();
		}

		score = 2.7778 * parseInt(ACT) + parseInt(GPA);
	}
	else {
		// calculate based on SAT
		GPA = form.GPA1.value;
		var math = form.MathSAT.value;
		var verb = form.VerbSAT.value;

		if ( isNaN(math) || math>800 || math<200 ) {
			alert("Math SAT Score must be a number between 200 and 800");
			form.MathSAT.focus();
			return;
		}


		if ( isNaN(verb) || verb>800 || verb<200 ) {
			alert("Verbal SAT Score must be a number between 200 and 800");
			form.VerbSAT.focus();
			return;
		}


		if ( isNaN(GPA) || GPA<0 || GPA>100 )
		{
			alert("GPA must be between 0 and 100");
			form.GPA1.focus();
		}

		score = (0.0625 * (parseInt(math)+parseInt(verb))) + parseInt(GPA);
	}

	var amount;
	var name;

	if ( score >= 163 ) {
		amount = "16000";
		name = "President's Scholarship";
	} else if ( score >= 150 ) {
		amount = "14000";
		name = "Academic Scholarship";
	} else if ( score >= 139 ) {
		amount = "12000";
		name = "Dean's Scholarship";
	} else {
		amount = "6000";
		name = "St. Angela Award";
	}

	document.getElementById('SCHOLARSHIP_NAME').innerHTML = name;
	document.getElementById('SCHOLARSHIP_NAME_2').innerHTML = name;
	document.getElementById('SCHOLARSHIP_NAME_3').innerHTML = name;
	document.getElementById('SCHOLARSHIP_VALUE').innerHTML = '$' + amount.toString();
	document.getElementById('SCHOLARSHIP_VALUE_2').innerHTML = '$' + amount.toString();
	document.getElementById('SCHOLARSHIP_PER_YEAR').innerHTML = '$' + (amount/4).toString();
	document.getElementById('SCHOLARSHIP_PER_YEAR_2').innerHTML = '$' + (amount/4).toString();
	document.getElementById('SCHOLARSHIP_GPA').innerHTML = GPA;
	
	var div = document.getElementById('Question');
	div.style.display = 'none';
	var div = document.getElementById('Result');
	div.style.display = 'inline';

}

function ShowSiteMap() {
    var win = radopen(webSiteRoot + "pages/SiteMap.aspx", "radMediaWindow");
    win.setSize(400, 600);
    win.center();
}

function ShowCriticalNews() {
    var win = radopen(webSiteRoot + "pages/CriticalNews.aspx", "rwCriticalNews");
    win.setSize(400, 300);
    win.center();
}

function resizeScrollableContainer() {
    var headerHeight = 228 // better would be figurin out which elements to use as offsetContainers
    var leftColumn = document.getElementById('leftColumn');  // this is the region containing the menu items
    var mainBodyContainer = document.getElementById('MainBodyRegion'); // this is the main body area
    var scrollableContainer = document.getElementById('ScrollableBodyCopy'); // the region we want to scroll
    if (mainBodyContainer != null && scrollableContainer != null && leftColumn != null) 
    {
        if ( leftColumn.clientHeight > mainBodyContainer.clientHeight ) 
        {
            scrollableContainer.style.height = scrollableContainer.clientHeight + (leftColumn.clientHeight - mainBodyContainer.clientHeight) + "px";
            return true;
        }
    return false;
    }
}

/* 
* Scan all the news section blocks. If they are larger than 100 then resize down to 100 
* if they are a good size then leave them alone but delete the contents of the next div
* which contains the readme block
*/
function ResizeNewsSections() {
	var div = document.getElementById('newsBox');
	var divList = div.getElementsByTagName('div');
	for( var i=0; i<divList.length; ++i ) {
		var el = divList[i];
		if ( el.className == 'newsBoxCopy' ) {
		    if (el.clientHeight > 105) {
		        el.style.height = "105px";
		    }
		    else {
		        // clear out the read more
		        for (var j = i + 1; j < divList.length; ++j) {
		            if (divList[j].className == 'readMore') {
		                divList[j].innerHTML = "";
		                break;
		            }
		        }
		    }
		}
    }
}

// Show the big news box and fill the contents with the specified div.
// Make sure the newsBoxCopy in the copy is not shrunk in height
function ShowBigNews(divId) {
	var el = document.getElementById(divId);
	document.getElementById("BIGNEWSBOX").style.display="inline";
	var target = document.getElementById("BIGNEWSCONTENT")
	target.innerHTML = el.innerHTML;
	var divList = target.getElementsByTagName('div');
	for (var i = 0; i < divList.length; ++i) {
	    if (divList[i].className == 'newsBoxCopy') {
	        divList[i].style.height = "";
	        
	        // Replace the thumb image with the real one 
            var imgList = divList[i].getElementsByTagName('img');
            for (var j = 0; j < imgList.length; ++j) {
                imgList[j].src = imgList[j].src.replace("\/thumb\/", "\/");
            }
    
	        break;
	    }
	}
}

// Make the Bix News Box disappear
function HideBigNews() {
	document.getElementById("BIGNEWSBOX").style.display="none";
}

function SiteSearch() {
    var srcForm = document.forms["cse-search-box"];
    srcForm.q.value = document.forms[0].topSearchText.value;
    srcForm.action = webSiteRoot + "AboutCNR/SearchResults";
    srcForm.submit();
}

/* Quicklinks javascript */
var qlTimeout = null;
function showQuickLinksMenu (ev) {
	clearQuickLinksHideTimer();
	//get the position of the placeholder element
	var qlpos = $("#qlLink").offset();  
	var qlheight = $("#qlLink").height() + 10;
	//show the menu directly over the placeholder
	$("#divQuickLinks").css( { "left": (qlpos.left - 34) + "px", "top":(qlpos.top + qlheight) + "px" } );
	$("#divQuickLinks").show();
}

function clearQuickLinksHideTimer()
{
	clearTimeout(qlTimeout);
}

function hideQuickLinksMenu (ev) {
	qlTimeout = setTimeout('$("#divQuickLinks").hide()', 1000);
}
/* End Quicklinks stuff */

/* Scrollable area */
var _scroll_container1;
var _scroll_content1;
var _scroll_hidden1;	// # of pixels hidden by the container
var _scroll_container2;
var _scroll_content2;
var _scroll_hidden2;	// # of pixels hidden by the container

function setScrollerDimensions1(container_i, content_i) {
	_scroll_container1 = getObjectHeight(container_i);
	_scroll_content1 = getObjectHeight(content_i);
	_scroll_hidden1 = _scroll_content1 - _scroll_container1;
}

function setScrollerDimensions2(container_i, content_i) {
	_scroll_container2 = getObjectHeight(container_i);
	_scroll_content2 = getObjectHeight(content_i);
	_scroll_hidden2 = _scroll_content2 - _scroll_container2;
}

$(document).ready(function(){
	// Add quicklinks functions
	if (get_object('qlLink') != null)
	{
		$("#qlLink").mouseover(showQuickLinksMenu);
		$("#qlLink").mouseleave(hideQuickLinksMenu);
		$("#divQuickLinks").mouseenter(clearQuickLinksHideTimer).mouseleave(hideQuickLinksMenu);
	}
}); 
