/* 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 OpenMediaFile( mediaID )
{
    var win = radopen(webSiteRoot + "ShowMedia.aspx?type=radwindow&MediaID=" + mediaID, "radMediaWindow");
    win.set_title("OpenMedia Title");
    win.set_status("OpenMedia Status");
}

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;
    }
}

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_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_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];}
}


/* 
* 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();
}