var deadlinedate=new Array;
var deadlineitem=new Array;
var deadlinewho=new Array;


footnote=[""]; 


//Prospective Students----------------------------------------------
footnote.push("The university is <i>not</i> accepting applications for Spring semester.  Prospective students must apply for Fall."); 

deadlinedate.push("10/1/2011")
deadlineitem.push("Application deadline")
deadlinewho.push("Spring 2012 Applicants")

deadlinedate.push("10/31/2011")
deadlineitem.push("Documents supporting applicaitons must be received")
deadlinewho.push("Spring 2012 Applicants")

deadlinedate.push("11/30/2011")
deadlineitem.push("Decisions regarding applications will be announced")
deadlinewho.push("Spring 2012 Applicants")

deadlinedate.push("4/1/2012")
deadlineitem.push("Application deadline")
deadlinewho.push("Fall 2012 Applicants")

deadlinedate.push("4/16/2011")
deadlineitem.push("Documents supporting applicaitons must be received")
deadlinewho.push("Fall 2012 Applicants")



//December 2011 graduates----------------------------------------------
footnote.push(""); 

deadlinedate.push("4/1/2011")
deadlineitem.push("<a href=http://www.sjsu.edu/gape/docs/candidacy.pdf>Departmental Request for Candidacy Form</a>")
deadlinewho.push("December 2011 graduates")

deadlinedate.push("9/14/2011")
deadlineitem.push("(*projected due date) <a href=http://www.sjsu.edu/gape/docs/award_degree.pdf>Application for Award of Master's Degree</a>")
deadlinewho.push("December 2011 graduates")

deadlinedate.push("10/31/2011")
deadlineitem.push("Plan A Thesis for review to <a href=http://www.sjsu.edu/gradstudies/thesis/index.htm>Graduate Studies and Research</a>")
deadlinewho.push("December 2011 graduates")

deadlinedate.push("1/13/2011")
deadlineitem.push("Plan A Thesis for binding to <a href=http://www.sjsu.edu/gradstudies/thesis/index.htm>Graduate Studies and Research</a>")
deadlinewho.push("December 2011 graduates")

//May 2012 graduates----------------------------------------------
footnote.push(""); 


deadlinedate.push("10/01/2011")
deadlineitem.push("<a href=http://www.sjsu.edu/gape/docs/candidacy.pdf>Departmental Request for Candidacy Form</a>")
deadlinewho.push("May 2011 graduates")

deadlinedate.push("2/16/2012")
deadlineitem.push("<a href=http://www.sjsu.edu/gape/docs/award_degree.pdf>Application for Award of Master's Degree</a>")
deadlinewho.push("May 2011 graduates")

deadlinedate.push("4/5/2012")
deadlineitem.push("Plan A Thesis for review to <a href=http://www.sjsu.edu/gradstudies/thesis/index.htm>Graduate Studies and Research</a>")
deadlinewho.push("May 2011 graduates")

deadlinedate.push("6/15/2012")
deadlineitem.push("Plan A Thesis for binding to <a href=http://www.sjsu.edu/gradstudies/thesis/index.htm>Graduate Studies and Research</a>")
deadlinewho.push("May 2011 graduates")

//August 2012 graduates----------------------------------------------
footnote.push(""); 


deadlinedate.push("2/12/2012")
deadlineitem.push("<a href=http://www.sjsu.edu/gape/docs/candidacy.pdf>Departmental Request for Candidacy Form</a>")
deadlinewho.push("August 2011 graduates")

deadlinedate.push("6/7/2012")
deadlineitem.push("<a href=http://www.sjsu.edu/gape/docs/award_degree.pdf>Application for Award of Master's Degree</a>")
deadlinewho.push("August 2011 graduates")

deadlinedate.push("7/1/2012")
deadlineitem.push("Plan A Thesis for review to <a href=http://www.sjsu.edu/gradstudies/thesis/index.htm>Graduate Studies and Research</a>")
deadlinewho.push("August 2011 graduates")

deadlinedate.push("9/15/2012")
deadlineitem.push("Plan A Thesis for binding to <a href=http://www.sjsu.edu/gradstudies/thesis/index.htm>Graduate Studies and Research</a>")
deadlinewho.push("August 2011 graduates")


//Other deaadlines----------------------------------------------

deadlinedate.push("2/6/2012")
deadlineitem.push("Last Day to Drop Courses Without an Entry on Student's Permanent Record")
deadlinewho.push("all")

deadlinedate.push("2/13/2012")
deadlineitem.push("Last Day to Add Courses & Register Late")
deadlinewho.push("all")

deadlinedate.push("9/4/2012")
deadlineitem.push("Last Day to Drop Courses Without an Entry on Student's Permanent Record")
deadlinewho.push("all")

deadlinedate.push("9/11/2012")
deadlineitem.push("Last Day to Add Courses & Register Late")
deadlinewho.push("all")

deadlinedate.push("2/4/2013")
deadlineitem.push("Last Day to Drop Courses Without an Entry on Student's Permanent Record")
deadlinewho.push("all")

deadlinedate.push("2/11/2013")
deadlineitem.push("Last Day to Add Courses & Register Late")
deadlinewho.push("all")

deadlinedate.push("9/3/2013")
deadlineitem.push("Last Day to Drop Courses Without an Entry on Student's Permanent Record")
deadlinewho.push("all")

deadlinedate.push("9/10/2013")
deadlineitem.push("Last Day to Add Courses & Register Late")
deadlinewho.push("all")

deadlinedate.push("2/4/2014")
deadlineitem.push("Last Day to Drop Courses Without an Entry on Student's Permanent Record")
deadlinewho.push("all")

deadlinedate.push("2/11/2014")
deadlineitem.push("Last Day to Add Courses & Register Late")
deadlinewho.push("all")



//deadlinedate.push("")
//deadlineitem.push("")
//deadlinewho.push("")

// list categrories from the deadlinewho array with duplicate entries removed
categories=['anyone'];
for(var i=0;i<deadlinewho.length;i++){
	if (deadlinewho[i]!=""){
		isIn=0
		for(var j=0;j<categories.length;j++){
			if(deadlinewho[i]==categories[j]){
				isIn=1
			}
		}
		if(isIn==0){
			if (deadlinewho[i]!="all"){
				categories.push(deadlinewho[i])
			}	
		}
	}
}


//display events in order
var max_days_to_show=360;
var max_days_to_show_normal=90;
var max_days_to_hilite=7;
var allevents='';
eventcategory=new Array;
expiredeventcategory=new Array;
for(var j=0;j<categories.length;j++){
	eventcategory[j]= '<p>';
	expiredeventcategory[j]= '<p>';
}

for (num = 0; num < 99; num++){
	if (deadlinedate[num]!=undefined) {
		var datearray=deadlinedate[num].split('/');
		var thedateobject=new Date();
		var todayobject=new Date();
		thedateobject.setFullYear(datearray[2],datearray[0]-1,datearray[1]);
		thedateobject.setHours(17);
		var daysuntil=(thedateobject-todayobject)/(1000*60*60*24);
		
		//Write out expired deadlines
		if ( (daysuntil<0)) {
			var thisevent = '<font color=grey>' + deadlinedate[num] + 	': ' + deadlineitem[num] + ' (for ' + deadlinewho[num] + ')</font><p>';			 
			for(var j=1;j<categories.length;j++){
				if(deadlinewho[num]==categories[j]){
					expiredeventcategory[j]=expiredeventcategory[j] + ' ' + thisevent
				}
				if(deadlinewho[num]=="all"){
					if (categories[j].match("Applicants")==null)
					{
						expiredeventcategory[j]=expiredeventcategory[j] + ' ' + thisevent
					};
				}
			}
			expiredeventcategory[0]= expiredeventcategory[0] + ' ' +  thisevent;
		};
	}
}

for (daynum=0; daynum< max_days_to_show; daynum++) {
	//document.write(daynum + ' ');
	for (num = 0; num < 99; num++){
	    if (deadlinedate[num]!=undefined) {
			var datearray=deadlinedate[num].split('/');
			var thedateobject=new Date();
			var todayobject=new Date();
			thedateobject.setFullYear(datearray[2],datearray[0]-1,datearray[1]);
			thedateobject.setHours(17);
			var daysuntil=(thedateobject-todayobject)/(1000*60*60*24);			
			
			//
			if(daysuntil>=daynum){
				if(daysuntil<(daynum+1)){
					if(daynum< max_days_to_hilite){	
						var thisevent = '<font color=black><b>' + deadlinedate[num] + 	':</b> ' + deadlineitem[num] + ' (for ' + deadlinewho[num] + ')</font><p>';
					} else if(daynum< max_days_to_show_normal){	
						var thisevent =  deadlinedate[num] + 	': ' + deadlineitem[num] + ' (for ' + deadlinewho[num] + ')<p>';
					} else {
						var thisevent = '<span style="FONT-SIZE: 9pt; COLOR: #999999;">' + deadlinedate[num] + 	': ' + deadlineitem[num] + ' (for ' + deadlinewho[num] + ')</span><p>';
					}
					for(var j=1;j<categories.length;j++){
						if(deadlinewho[num]==categories[j]){
							eventcategory[j]=eventcategory[j] + ' ' + thisevent
						}
						if(deadlinewho[num]=="all"){
							if (categories[j].match("Applicants")==null)
							{
								eventcategory[j]=eventcategory[j] + ' ' + thisevent
							};
						}
					}
					eventcategory[0]= eventcategory[0] + ' ' +  thisevent;
				} 				
			}
			
    	}   	
    	
	}
}

// Make a drop down list from the categories
document.write('<form name=filter id="filter">');
document.write('<a href="http://www.sjsu.edu/provost/Academic_Calendars/">SJSU academic calendar</a> and official deadlines <a href="http://www.sjsu.edu/gape/current_students/deadlines/">for currrent students</a> and for <a href="http://www.sjsu.edu/gape/prospective_students/deadlines/index.htm">prospective students</a> is posted by grad studies and summarized here for');
//document.write(' <select id="graddate" size="1" onchange="javascript: for(var j=0;j< categories.length;j++){if(document.getElementById(\'graddate\').value==categories[j]){document.getElementById(\'message\').innerHTML=eventcategory[j];document.getElementById(\'footnote\').innerHTML=footnote[j];			}};">');
document.write(' <select id="graddate" size="1" onchange="update();">');


for (catnum = 0; catnum < categories.length; catnum++){
	document.write('<option value="'+ categories[catnum] +'">'+ categories[catnum] +'</option>');
 }
document.write('</select>');
document.write('<br><input type="checkbox" name="showold" value="yes" onchange="update();"/>Show expired deadlines');


document.write('</form>');
document.write('<div id="expired" style="font-size:8pt"></div>');
document.write('<div id=message >'+eventcategory[0]+'</div>');
document.write('<div id=footnote style="font-size: 10pt; font-color: #555555;">'+footnote[0]+'</div>');


//update display when the selection menu is changed
//var filtermenu=document.getElementById("graddate")
//filtermenu.onchange=function(){ 
//	for(var j=0;j<categories.length;j++){			
//		if(filtermenu.value==categories[j]){
//			document.getElementById("message").innerHTML=eventcategory[j];
//			document.getElementById("footnote").innerHTML=footnote[j];			
//		}
//	}
//}

function update(){
	for(var j=0;j< categories.length;j++){
		if(document.getElementById('graddate').value==categories[j]){
			if (document.filter.showold.checked) {
				document.getElementById('expired').innerHTML=expiredeventcategory[j] +"<hr>";
			} else {
				document.getElementById('expired').innerHTML="";
			};
			document.getElementById('message').innerHTML=eventcategory[j];
			document.getElementById('footnote').innerHTML=footnote[j];	
		}
	};


};



