/* 1 May 2009 [GF] ========= common.js ======== used on all pages =========== */

var topNav = '<table width="1100" border="0" cellspacing="0" cellpadding="0" bgcolor="#140E8D" align="left"><tr>'
	+ '<td class="center"><a href="index.html" class="button">Home</a></td>'
	+ '<td class="center"><a href="Faculty.html" class="button">Faculty</a></td>'
	+ '<td class="center"><a href="Events.html" class="button"> Events</a></td>'
	/*+ '<td class="center"><a href="seminars.html" class="button">Seminars</a></td>'*/
	+ '<td class="center"><a href="Major_Minor.html" class="button">Major/Minor</a></td>'
	+ '<td class="center"><a href="Courses.html" class="button">Courses</a></td>'
	+ '<td class="center"><a href="Videos.html" class="button">Video Library</a></td>'
	+ '<td class="center"><a href="Student_Orgs.html" class="button">Student Organizations</a></td>'
	+ '<td class="center"><a href="Contact.html" class="button">Contact Us</a></td>'
	+ '<td class="center"><a href="Resources.html" class="button">Resources</a></td>'
+ '</tr></table><br clear="all">';

var banner = '<table cellpadding="0" cellspacing="0" border="0" width="1100" align="left">'
	+ '<tr><td style="width:800px; height:72px; background-image:url(images/lals_banner_800.jpg);"></td>'
		+ '<form method="get" action="http://www.google.com/search">'
				+ '<td bgcolor="#0E0A69" width="200"><br>'
					+ '<input name="ie" value="iso-8859-1" type="hidden">'
					+ '<input name="oe" value="iso-8859-1" type="hidden">'
					+ '<input name="domains" value="http://www.sas.upenn.edu/lals/" type="hidden">'
					+ '<input name="sitesearch" value="http://www.sas.upenn.edu/lals/" type="hidden">'
					+ '<input id="searchbutton" name="btnG" value="search" type="HIDDEN">'
					+ '<input name="q" class="small" id="small" title="Search Box" dir="ltr" size="15" maxlength="60" value=""'
					+ 'style="height: 1.1em;" type="HIDDEN" lang="nl">&nbsp;'
			+ ' &nbsp; </td>'
				+ '</form>'
	+ '<td bgcolor="#0E0A69"><br><a href="http://www.uPenn.edu" target="_blank"><img src="images/UPenn_logo.jpg" alt="UPenn" border="0"></a>&nbsp;&nbsp;</td>'
	+ '</tr></table><br clear="all">'; 

var today = new Date();
var Page = document.title.split(":")[0];
var pageFooter	=  '<div id="footer">'
	+ '© ' + today.getFullYear() 
	+ ' Latin American &amp; Latino Studies Program | 375 Cohen Hall | 249 S. 36th Street | Philadelphia, PA. 19104-6304'
	+ ' &nbsp; &nbsp; <a style="color:silver;" href="Administration.html">Administration</a>'
	+ '<img src="http://www.GFarnsworth.com/home/Hitcounter.cfm?site=LALS&Page=' + Page + '" width="1" height="1" border="0">'	
	+ '</div> ';

var editing=false; // check for editing and set flag
if(location.search)
	{if(location.search=='?LALSAdmin')	editing=true};
//alert(location.search);alert(editing);

// used to list the faculty ============================
function listFaculty() 
{
		//facultyList.sort(nocaseCompare); // sort by surname, firstname
			if(editing) document.write('<tr><th>(<a href="FacultyEdit.html?ID=new"><b>Add new faculty</b></a>)</th></tr>'); // special editing link
		for(f=0;f<facultyList.length;f++)
		{
			fPerson = facultyList[f];
			fNam2 = fPerson.split("|")[0];
			fNam1 = fPerson.split("|")[1];
			fArea = fPerson.split("|")[2];
			fSite = fPerson.split("|")[3]; 
			fMail = fPerson.split("|")[4];
			fFone = fPerson.split("|")[5];
			fAddr = fPerson.split("|")[6];
			ProfId= fPerson.split("|")[7];
			if(fNam2!='TBA' && fNam2!='Staff')
			{
				document.write('<tr><td>&nbsp;</td></tr>');
				document.write('<tr><td><a href="http://' + fSite + '" target="_blank"><b>' + fNam1 + ' ' + fNam2 
					+ '</b></a>');
				if(editing) document.write(' &nbsp; (<a href="FacultyEdit.html?ID=' + ProfId + '"><b>edit</b></a>)'); // special editing link
				document.write('</td></tr>');
				if(fArea) document.write('<tr><td>' + fArea + '</td></tr>');
				document.write('<tr><td>');
				if(fAddr) document.write(fAddr + ' &nbsp; ');
				if(fFone) document.write(fFone);
				document.write('</tr>');
				if(fMail) document.write('<tr><td>' + fMail + '</td></tr>');
			}
		};
};

 // used to list the Courses ===========================
function listCourses(limitValu)
{
		if(editing) 
			document.write('<tr><th>(<a href="CourseEdit.html?ID=new"><b>Add new Course</b></a>)</th></tr>'); // special editing link
		var term = '';
		for(f=0;f<courseList.length;f++)
		{
			fCourse = courseList[f];
			
			fNumb = fCourse.split("|")[0].toString(); if(fNumb.split(".")[0].length==2)fNumb='0'+fNumb;
			fName = fCourse.split("|")[1];
			fTerm = fCourse.split("|")[2];
			fCros = fCourse.split("|")[3];
			fText = fCourse.split("|")[4]; 
			fLocn = fCourse.split("|")[5];
			fTime = fCourse.split("|")[6];
			fSect = fCourse.split("|")[7];
			fProf2 = fCourse.split("|")[8];
			fProf1 = fCourse.split("|")[9];
			fProfW = fCourse.split("|")[10];
			fcId   = fCourse.split("|")[11];
			fpId   = fCourse.split("|")[12];
			fClus  = fCourse.split("|")[13];
			fDist  = fCourse.split("|")[14];
			NClus  = fCourse.split("|")[15];
			NDist  = fCourse.split("|")[16];
			
			 // limits 
			if( (!limitValu) || (limitValu==fTerm.split(" ")[0]) || (limitValu==NClus)  || (limitValu==NDist) )
			{ 
				document.write('<tr><td>&nbsp;</td></tr>');
				// Course Number
				document.write('<tr><td colspan=2><b style="color:#990000;">' + fNumb + ' ' + fName	+ '</b> &nbsp; &nbsp;');
				// professor website
				if(fProfW) document.write('<a href="http://' + fProfW + '" target="_blank">');
				// professor
				document.write(fProf1 + ' ' + fProf2.split(",")[0]);		document.write('</a>');
				
				// special editing link
				if(editing) document.write(' &nbsp; (<a href="CourseEdit.html?ID=' + fcId + '"><b>edit</b></a>)');
				
				// Section Title
				if(fSect > '$') document.write('<tr><td colspan=2><b>Section:</b> ' + fSect + '</td></tr>');
				//Cross Listing
				if(fCros) document.write('<tr><td colspan=2><b>Cross Listing:</b> ' + fCros + '</td></tr>');
				//term
				if(fTerm > '$') 
						document.write('<tr><td colspan=2><b>' + fTerm + ': ' + fTime +' '+ fLocn + '</b></td></tr>');
				//Dist Rqmt
				if(fDist)document.write('<tr><td colspan=2><b>Distribution Area:</b> ' + fDist + '</td></tr>');
				//LALS Cluster
				if(fClus)document.write('<tr><td colspan=2><b>LALS Cluster:</b> ' + fClus + '</td></tr>');
				//Description
				if(fText > '$') document.write('<tr><td colspan=2 style="padding-top:5px;">' + fText + '</td></tr>');
			}; // limits 
		};
};

// used for faculty sort 
function nocaseCompare(a,b) 
{return (a.toUpperCase() > b.toUpperCase())
};

// ======== used for date sort =======
function doCompare(a,b) 
{
	var d1 = new Date(a.split('/')[0]);
	var d2 = new Date(b.split('/')[0]);
	return (d1.getTime() >= d2.getTime() );
};

// used to list events between two dates ======
function listEvents(date1,date2) 
{
		eventList.sort(doCompare); // sort by date
		if(new Date(date2) > today)	
			{ document.write('<tr><th colspan="2">Future Events');
				if(editing)document.write(' &nbsp; (<a href="EventEdit.html?id=new">New Event</a>)');
				document.write('</th></tr>');
			}
		else
			document.write('<tr><th colspan="2"><br><hr>' + new Date(date1).getFullYear() + ' Events<hr></th></tr>');
		var nEvents=0;
		for(ev=0;ev<eventList.length;ev++)
		{ 
			var evList=eventList[ev];
			evDate		=	evList.split('|')[0];
			evName		=	evList.split('|')[1];
			evSpeaker	=	evList.split('|')[2];
			evHost		=	evList.split('|')[3];
			evPlace		=	evList.split('|')[4];
			evText		=	evList.split('|')[5];
			evSponsor	=	evList.split('|')[6];
			evImage		=	evList.split('|')[7];
			evID			=	evList.split('|')[8];

			if(evDate){	var when = new Date(evDate.split("/")[0]);}
			else {var when = new Date('1/1/2009');};
			
			if(when >= new Date(date1) && when <= new Date(date2) )
			{
				nEvents++;
				if(evImage)
					{document.write('<tr><td colspan="2">&nbsp;</td><td rowspan="6"><img src="images/' + evImage + '"></td></tr>');};
				document.write('<tr><td colspan="2" class="evName">' + evName );
				if(editing) // special editing link
					{document.write(' (<a href="EventEdit.html?id=' + evID + '"><b>Edit</b></a>)</td></tr>');}
				else document.write('</td></tr>');
				document.write('<tr><td align="right"><b>When:</b>&nbsp;</td><td>' 
					+ when.toLocaleString().split(",")[0] + ', ' 
					+ when.toLocaleString().split(",")[1] + ', ' 
					+ when.toLocaleString().split(",")[2].slice(0,5) + ' ' );
					if(new Date(date2) > today)	document.write(evDate.split("/")[1]);
					document.write('</td></tr>');
				if(evSpeaker)	document.write('<tr><td align="right"><b>Who:</b>&nbsp;</td>		<td>' + evSpeaker + '</td></tr>');
				if((evPlace)&& ( new Date(date2) > today) )		document.write('<tr><td align="right"><b>Where:</b>&nbsp;</td>	<td>' + evPlace 	+ '</td></tr>');
				if(evText) 		document.write('<tr><td align="right"><b>What:</b>&nbsp;</td>		<td>' + evText 		+ '</td></tr>');
				if(evHost) 		document.write('<tr><td align="right"><b>Host:</b>&nbsp;</td>		<td>' + evHost 		+ '</td></tr>');
				if(evSponsor) document.write('<tr><td colspan="2">Co-sponsored by ' + evSponsor	+ '</td></tr>');
			}; //end if
		}; //end for
		if(nEvents==0)document.write('<tr><th colspan="2">None</th></tr>');
}; // end listEvents


function editStart() // used by all editing pages to collect authorization
{
		document.write('<tr><th colspan="2" style="color:#990000;">'
			+ 'This page is for authorized users only.<br>'
			+ 'All other attempts to use this page will be recorded	by IP address '
			+ 'but will have no effect on the data.<br><br>'
			+ '</th></tr>');
		document.write('<tr><th align="right">Authorization Code: </th>'
			+ '<td><input type="password" name="Authorization" value="" size="50"><br><br></td></tr>');
};

function editButtons(ID)
{
	document.write('<tr><td>&nbsp;</td><td align="center">'
				+	'<input type="submit" name="Go" value="Cancel (no changes)" '
					+	'style="color:#990000;background-color:#FFFFFF;font-weight:bold;"> '
				+	'&nbsp; &nbsp; ');
	if(ID=="new")
		document.write('<input type="submit" name="Go" value="Add" '
					+	'style="color:#FFFFFF;background-color:#006600;font-weight:bold;">'
				+ '</td></tr></form>');
	else
		document.write('<input type="submit" name="Go" value="Change" '
					+	'style="color:#FFFFFF;background-color:#006600;font-weight:bold;">'
				+	'&nbsp; &nbsp; '
				+	'<input type="submit" name="Go" value="Delete" '
					+	'style="color:#FFFFFF;background-color:#990000;font-weight:bold;" '
					+	'onClick="return confirm(\'Are you sure you want to delete this item?\');">'
				+ '</td></tr></form>');
};

// ===== used to list a single course on the editing form ===========
function courseItem(thisCourse,item) // line on editing form
{
			itemValue		=	thisCourse.split('|')[item];
			switch (item)
			{
			/* courseNo */		  case   0: itemName = "courseNo"; 		break   
			/* courseName */		case   1: itemName = "courseName"; 	break   
			/* courseTerm */		case   2: itemName = "Term"; 				break   
			/* courseCross */		case   3: itemName = "crossListing";break   
			/* courseText */		case   4: itemName = "Text"; 				break   
			/* courseLocation */case   5: itemName = "Room"; 				break   
			/* courseTime */		case   6: itemName = "Time"; 				break   
			/* SectionName */		case   7: itemName = "Section"; 		break   
			/* Surname */				case   8: itemName = "Instructor2"; break   
			/* FirstName */			case   9: itemName = "Instructor1";	break
			/* Website */				case  10: itemName = "profWebsite"; break   
			/* courseID */			case  11: itemName = "courseID"; 		break   
			/* ProfId */				case  12: itemName = "ProfId"; 			break   
			/* Cluster */				case  13: itemName = "LALSCluster"; break   
			/* Dist Rqmt */			case  14: itemName = "SASDistRqmt"; break   
			/* LALS_ClusterID         15  */
			/* SAS_SectorID           16 */
			};
			if(item==0) 
				{	itemValue = itemValue.toString(); 
					if(itemValue.split(".")[0].length==2)itemValue='0'+itemValue;
					document.write('<tr><th align="right">Course: </th>');
					document.write('<td><input type="text" style="text-align:right;" name="courseNo" value="' 
							+ itemValue.split(".")[0] + '" size="5">');
					document.write('&nbsp; <input type="text" name="courseName" value="' 
							+ thisCourse.split('|')[1] + '" size="90"></td></tr>');
					if(itemValue.split(".").length==2) // if it has a section
					{
						document.write('<tr><th align="right">Section: </th>');
						document.write('<td><input type="text" style="text-align:right;" name="sectionNo" value="' 
							+ itemValue.split(".")[1] + '" size="5">');
						document.write('&nbsp; <input type="text" name="sectionName" value="' 
							+ thisCourse.split('|')[7] + '" size="90"></td></tr>');
					};
				};

			if( (item<7) && (item>1) )
				{	
					document.write('<tr><th align="right">' + itemName + ': </th>');
					if(item!=4)
						document.write('<td><input type="text" name="' + itemName + '" value="' 
							+ itemValue + '" size="100"></td></tr>')
					else
						document.write('<td><textarea name="' + itemName + '" cols="80" rows="6">'
							+ itemValue + '</textarea></td></tr>')
					;
				};
			if(item==8) // professor
				{	
					document.write('<tr><th align="right">Instructor:</th><td>');
					document.write('<select name="ProfID" style="width:20em;">');
					for(p=0;p<facultyList.length;p++)
						{
							document.write('<option value="' + facultyList[p].split("|")[7] + '" ' );
							if( facultyList[p].split("|")[7] == thisCourse.split("|")[12] ) document.write(' SELECTED ');
							document.write('>' + facultyList[p].split("|")[1] + ' ' + facultyList[p].split("|")[0].split(",")[0] + '</option>');
						};
					document.write('</select></td></tr>');
				};
						 
			if(item==13) // LALS cluster
				{	
					var clusterID = thisCourse.split('|')[15];
					document.write('<tr><th align="right">LALS Cluster: </th>');
					document.write('<td><select name="clusterID" style="width:250px;">' 
						+ '<option value="0">none</option>') ;
					for(cl=0;cl<clusterList.length;cl++)
						{
							var cluID = clusterList[cl].split('|')[0];
							var cluNm = clusterList[cl].split('|')[1];
							document.write('<option value="' + cluID + '"');
								if(clusterID==cluID) document.write(' selected ');
							document.write('>' + cluNm + '</option>');		
						};
					document.write('</select></td></tr>')
				};
						 
			if(item==14) // SAS Sector
				{	
					var sectorID = thisCourse.split('|')[16];
					document.write('<tr><th align="right">SAS Sector: </th>');
					document.write('<td><select name="sectorID" style="width:250px;">'
						+ '<option value="0">none</option>') ;
					for(s=0;s<sectorList.length;s++)
						{
							var secID = sectorList[s].split('|')[0];
							var secNm = sectorList[s].split('|')[1];
							document.write('<option value="' + secID + '" ' );
								if(sectorID==secID) document.write(' selected ');
							document.write('>' + secNm + '</option>');		
						};
					document.write('</select></td></tr>')
				};

			if(item==11) // courseId				
				{	
					document.write('<input type="hidden" name="' + itemName + '" value="' + itemValue + '">')
				};
};

// ===== used to list a single faculty person on the editing form ===========
function facultyItem(thisPerson,item)
{
			itemValue		=	thisPerson.split('|')[item];
			switch (item)
			{
				case 0: itemName = "Surname";		break
				case 1: itemName = "FirstName";		break
				case 2: itemName = "Area";			break
				case 3: itemName = "Website";		break
				case 4: itemName = "Email";		break
				case 5: itemName = "Telephone";		break
				case 6: itemName = "Address";		break
				case 7: itemName = "ProfID";		break
			};
			if(item<7)
				{	
					document.write('<tr><th align="right">' + itemName + ': </th>');
					document.write('<td><input type="text" name="Item_' + item + '" value="' 
						+ itemValue + '" size="100"></td></tr>')
				}
			else				
				{	document.write('<td><input type="hidden" name="Item_' + item + '" value="' 
						+ itemValue + '" size="10"></td></tr>')
				};
	
};

// ===== used to list a single event item on the editing form ===========
function eventItem(thisEvent,item)
{
			itemValue		=	thisEvent.split('|')[item];
			switch (item)
			{
				case 0: itemName = "evDate";		break
				case 1: itemName = "evName";		break
				case 2: itemName = "evSpeaker";	break
				case 3: itemName = "evHost";		break
				case 4: itemName = "evPlace";		break
				case 5: itemName = "evText";		break
				case 6: itemName = "evSponsor";	break
				case 7: itemName = "evImage";		break
				case 8: itemName = "evID";			break
			};
			document.write('<tr><th align="right">' + itemName.slice(2,9) + ': </th>');
				if(item==0) // date & time
				{	
					var itemDate = new Date(itemValue.split("/")[0]).toString().slice(4,15);
					var itemTime = itemValue.split("/")[1]
					if(thisEvent=="|||||||||") {itemDate="";itemTime="";};
					document.write('<td><input type="text" name="' +itemName+ '" value="' + itemDate + '" size="20">'
						+ ' at <input type="text" name="evTime" value="' + itemTime + '" size="20"></td>');
				}
				else // uses textarea if more than 90 chars 
					if(itemValue.length>90)
					{	document.write('<td><textarea name="' +itemName+ '" cols="80" rows="4">' 
						+ itemValue + '</textarea></td>');}
					else
					document.write('<td><input type="text" name="' +itemName+ '" value="' + itemValue + '" size="100"></td>');;
			document.write('</tr>');
};


