// ***************
// start date code
d = new Array("Sun", "Mon", "Tues", "Wed", "Thur", "Fri", "Sat");
m = new Array("Jan.", "Feb.", "Mar.", "Apr.", "May", "June", "July", "Aug.", "Sept.", "Oct.", "Nov.", "Dec.");

today	= new Date();
day		= today.getDate();
year	= today.getYear();
hour	= today.getHours();
minutes	= today.getMinutes();

if (year < 2000)    
	year = year + 1900; 

end = "th";
if (day==1 || day==21 || day==31) end="st";
if (day==2 || day==22) end="nd";
if (day==3 || day==23) end="rd";
day += end;

if(minutes<10)
	minutes="0" + minutes;
	
if(hour<12)
{
	x="am"
	if(hour==0)
		hour=hour+12;
}
else if(hour>11)
{
	x="pm";
	hour=hour%12;
	if(hour==0)
	hour=hour+12;
}
// end of date code 


// **************
// start images code    
var image_path = "http://w3.fiu.edu/irdata/images";

var image_list = new Array(image_path+'header_opie_on60.gif', image_path+'header_about_on60.gif', image_path+'header_alc_on60.gif', image_path+'header_accred_on60.gif',
image_path+'header_data_on60.gif', image_path+'header_fb_on60.gif', image_path+'header_eval_on60.gif', image_path+'header_ps_on60.gif',
image_path+'header_pr_on60.gif', image_path+'header_sus_on60.gif', image_path+'header_plan_on60.gif', image_path+'header_az_on60.gif');


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=image_list;
		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_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];}
}

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_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);


// ***************
// start code for reports forms

var expanded;
var help_expanded;
var div_3_visibility;

// create the arrays with the text and values for the second and third drop downs
var enroll_list		= new Array('Headcount','headcount','FTE/FSCH','fsch');
var degree_list		= new Array('Term','term','Academic Year','acad_year');
var retention_list	= new Array('Retention 1','retention_1','Retention 2','retention_2');
var employee_list	= new Array('Employee 1','employee_1','Employee 2','employee_2');
var fsch_list		= new Array('Term','term','Academic Year','acad_year');

var second_drop_options		= new Array();
second_drop_options['enrollment']	= enroll_list;
second_drop_options['degrees']		= degree_list;
//second_drop_options['retention']	= retention_list;
//second_drop_options['employees']	= employee_list;

var third_drop_options		= new Array();
third_drop_options['fsch']	= fsch_list;
var nw;

function loadOptions( selected_value, p )
{ 
	// get the appropiate element and div that is going to be modified
	var drop_down = document.getElementById('report_type_'+p);
	var div = document.getElementById('report_type_div_'+p);
	
	// get the appropriate option values
	var list;
	list = ( p == 2 ) ? second_drop_options[selected_value] : third_drop_options[selected_value];
	
	if( list == null || list.length == 0 )
	{
		// this code will clear the list
		div.className = "invisible_elem";
		drop_down.options.length = 0;
		if( div.id == 'report_type_div_3' )
			div_3_visibility = 'invisible_elem';
	}
	else
	{
		// this code will populate the list
		j=0;
		for( i=0 ; i < list.length; i+=2 )
		{
			if( div.id == 'report_type_div_3' && help_expanded )
				div_3_visibility = 'visible_elem';
			else
				div.className = "visible_elem";
			drop_down.options[j] = new Option( list[i], list[i+1] );
			document.getElementById("next_part_button").disabled = false;
			j++;
				
		}
	}
}

function loadurl( form_submitted, new_window, show_in_progress ) {
	try {
			xmlhttp = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
	}
	catch (e) { /* do nothing */ }
	
	// determine what script is going to be called by checking the values selected from the drop downs	
	var dest;
	dest = document.getElementById("report_type_1").value + "_" + document.getElementById("report_type_2").value;
	if( document.getElementById("report_type_3").value )
		dest += "_" + document.getElementById("report_type_3").value;
	dest += "_form.asp";
		
	xmlhttp.onreadystatechange = triggered;
	nw = new_window;
	
	// create the query string to be passed to the script to be executed
	// this could be the values selected in the criteria form, or the values of the hidden fields when selecting the back button 
	var query = '';
	if( form_submitted )
	{
		var form = document.getElementById("criteria_form"); 
		if( form )
		{ 
			for( i=0; i<form.elements.length; i++ )
			{ query += form.elements[i].name + "=" + encodeURI(form.elements[i].value) + "&"; }
		
			if( new_window )
				query += "new_window=true"
		}
		if( show_in_progress )
			document.getElementById("part_2_div").innerHTML = "In Progress <br> <img src='http://w3.fiu.edu/irdata/images/in_progress1.gif' border='0'>";
	}
		
	xmlhttp.open('POST', "http://w3.fiu.edu/irdata/Portal/Criteria_Forms/"+dest, true);
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	xmlhttp.send(query);						
}
	
function triggered() 
{
	//this function gets executed when the server replies after the xmlhttp request is sent in the loadurl function
	if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200))
	{
		if( nw )
		{
			// display the results in a new window
			open_window = window.open('Report_Portal.asp','newwin',"height=450, width=400,toolbar=no,scrollbars=yes,resizable=yes,menubar=no");
			output = '<html><head><title>Report</title>';
			output += "<link rel='stylesheet' href='http://w3.fiu.edu/irdata/CSS/portal.css' type='text/css'>";
			output += "</head><body bgcolor='#FFFFEF'>"+ xmlhttp.responseText +"</body></html>";
			open_window.document.write(output);
			open_window.document.close()	
		}
		else
		{
			// display the results in the same window
			document.getElementById("part_2_div").innerHTML = xmlhttp.responseText;
		}
	}
}
	
	
function positionElement( parent_elem, elem )
{
	if( !parent_elem )
		return;
	else
	{
		var x = 0;
		var y = 0;
		while( parent_elem != null )
		{
			x += parent_elem.offsetLeft;
			y += parent_elem.offsetTop;
			parent_elem = parent_elem.offsetParent; 
		}
		
		if( elem.id == "report_help" )	
			elem.style.left = ( elem.offsetWidth > 50 ) ? x-290 : x;
		else
			elem.style.left = x;
		elem.style.top = y;
	}
}

		
function showHelpPanel()
{
	var elem = document.getElementById('report_help');
	var left = elem.offsetLeft;
	var div_3 = document.getElementById('report_type_div_3');
		
	if( help_expanded )
	{	// collapse		
		elem.innerHTML = '<img src="http://w3.fiu.edu/irdata/images/help3.gif" onClick="showHelpPanel();">';
		//new Rico.Effect.SizeAndPosition( elem, x, y, width, height, milliseconds, steps, options );
		new Rico.Effect.SizeAndPosition( 'report_help', (left+292), null, 41, 33, 250, 30, null );
		elem.style.border="";
		help_expanded = false;
		// restore the report_type_div_3 element's className
		div_3.className = div_3_visibility;
	}
	else
	{	// expand help 
		var html_content =	'<TABLE border="0" width="325">';
		html_content +=		'  <TR>';
		html_content +=		'    <TD colspan="2" class="small_text"><B>Note:</B> To close this help, select the <B><I>HELP</I></B> button again.</TD>';
		html_content +=		'    <TD><img src="http://w3.fiu.edu/irdata/images/help3.gif" onClick="showHelpPanel();"></TD>';
		html_content +=		'  </TR>';
		html_content +=		'  <TR>';
		html_content +=		'    <TD align="right" valign="top"><img src="http://w3.fiu.edu/irdata/images/bullet.gif"></TD>';
		html_content +=		'    <TD class="small_text" colspan="2">In <B>Part 1</B> of this page, you select the type of report that you are looking for by making selections from the drop down lists.</TD>';
		html_content +=		'  </TR>';
		html_content +=		'  <TR>';
		html_content +=		'    <TD align="right" valign="top"><img src="http://w3.fiu.edu/irdata/images/bullet.gif"></TD>';
		html_content +=		'    <TD class="small_text" colspan="2">Once you are done selecting the type of report that you want, you can press the <B><I>Next</I></B> button. The <B>Part 2</B> panel should expand.</TD>';
		html_content +=		'  </TR>';
		html_content +=		'  <TR>';
		html_content +=		'    <TD align="right" valign="top"><img src="http://w3.fiu.edu/irdata/images/bullet.gif"></TD>';
		html_content +=		'    <TD class="small_text" colspan="2">In <B>Part 2</B> of the page, you may select the criteria by which you want to narrow the results.</TD>';
		html_content +=		'  </TR>';
		html_content +=		'  <TR>';
		html_content +=		'    <TD align="right" valign="top"><img src="http://w3.fiu.edu/irdata/images/bullet.gif"></TD>';
		html_content +=		'    <TD class="small_text" colspan="2">After you are done making your selections, you may select the <B><I>Get Report</I></B> button to have the results displayed in the same window.</TD>';
		html_content +=		'  </TR>';
		html_content +=		'  <TR>';
		html_content +=		'    <TD align="right" valign="top"><img src="http://w3.fiu.edu/irdata/images/bullet.gif"></TD>';
		html_content +=		'    <TD class="small_text" colspan="2">The <B><I>Get Report in a new Window</I></B> button will show the results in a separate window, but only if you do not have popups blocked in your browser settings.</TD>';
		html_content +=		'  </TR>';
		html_content +=		'  <TR>';
		html_content +=		'    <TD align="right" valign="top"><img src="http://w3.fiu.edu/irdata/images/bullet.gif"></TD>';
		html_content +=		'    <TD class="small_text" colspan="2">The <B><I>Reset</I></B> button will set all the drop downs to the values they had the last time the page was loaded.</TD>';
		html_content +=		'  </TR>';
		html_content +=		'  <TR>';
		html_content +=		'    <TD align="right" valign="top"><img src="http://w3.fiu.edu/irdata/images/bullet.gif"></TD>';
		html_content +=		'    <TD class="small_text" colspan="2">When the results are displayed, you have the option of viewing them in an excel file which you can save in your computer. </TD>';
		html_content +=		'  </TR>';
		html_content +=		'  <TR height="1">';
		html_content +=		'    <TD width="15" height="1"><img src="http://w3.fiu.edu/irdata/images/spacer.gif" width="15" height="1"></TD>';
		html_content +=		'    <TD width="269" height="1"><img src="http://w3.fiu.edu/irdata/images/spacer.gif" width="249" height="1"></TD>';
		html_content +=		'    <TD width="41" height="1"><img src="http://w3.fiu.edu/irdata/images/spacer.gif" width="41" height="1"></TD>';
		html_content +=		'  </TR>';
		html_content +=		'</TABLE>';
		
		// save the className of the report_type_div_3 element before hiding it, so that it can be restored when the help is collapsed.
		// hide the report_type_div_3 element, so that it doesn't show throught the help div (z-index doesn't work in IE).
		div_3_visibility = div_3.className;
		div_3.className = 'invisible_elem';
		
		elem.style.border="solid 2px #E7AE5A";
		new Rico.Effect.SizeAndPosition( 'report_help', (left-292), null, 340, 330, 250, 10, null );
		elem.innerHTML = html_content;
		help_expanded = true;
	}
}

