<!-- Begin
function window_onload() {
   if(document.forms["search"] != null || document.forms["addEvent"] != null || document.forms["editEvent"] != null) { 
   // only load categories and locations if there's a search form or a addEvent form or an editEvent form
      if(document.forms[0].category != null) { // make sure that there's a category field
	// load the categories into the category menu
	for(i= 0; i < categoriesArr.length; i++) { 
		document.forms[0].category.options[i]= categoriesArr[i]; 
		if(document.forms[0].category.options[i].value == catSelected)
			document.forms[0].category.options[i].selected= true; 
	} 

	// truncate the list if there are more options 
	document.forms[0].category.options.length= categoriesArr.length; 
      }
      
	//window.alert("changing locations..."); 
      if(document.forms[0].location != null) {	// make sure that there's a location field
	// load the locations into the location menu
	for(i= 0; i < locationsArr.length; i++) { 
		document.forms[0].location.options[i]= locationsArr[i];
		if(document.forms[0].location.options[i].value == locSelected)
			document.forms[0].location.options[i].selected= true;  
	} 
	// truncate the list if there are more options 
	document.forms[0].location.options.length= locationsArr.length; 
      }
   }
   if(document.forms["addEvent"] != null) {
	updateRepeatFields(); 
   }
   
   // load an image into the rotImage
   //if(images.length > 0)
   	//document.rotImage.src= "/events/newsite/images/rotImages/"+images[0]; 	
   //else document.rotImage.src= "";  	
   
	// rotate the image
	setTimeout("switchImage()", 3000);

	//window.alert("anything"); 	 
}
// select the location from the location menu with the value value
//function selectLocation() 

function switchImage() { 
	//window.alert("gonna switch some images now"); 
//	window.alert("current image: " + document.rotImage.src); 
	do { 
		imgNumber= Math.floor(Math.random()*images.length);
		newimage= "/events/images/rotImages/"+images[imgNumber];
	 } 

	while (document.rotImage.src == newimage); 
		
 	
	document.rotImage.src=  newimage; 
	
	if(isSupportedBrowser()) { 
		//window.alert("gonna change the caption"); 
		// change the caption
		caption.innerHTML= captions[imgNumber]; 
	}
	setTimeout("switchImage()", 3000);  
}

function goQuickSearch() { 
	// get keyword 
	var keyword= document.forms['quicksearch'].keyword.value; 
    var regexp1= new RegExp("^[a-zA-Z]+$"); 
	
    if(regexp1.exec(keyword))
      window.location.href="index.php?mode=qsearch&keyword="+keyword; 
    else 
      window.alert("Please use one word (alphanumeric characters and no spaces)."); 	
} 
function openEventDetail(htmlStr) { 
	var detailWin= window.open("", "detailWin", "width=600,height=650,scrollbars=yes");
	detailWin.document.open(); 
	detailWin.document.write("<html>"); 
	detailWin.document.write("<link rel='stylesheet' href='/events/css/layout.css' type='text/css'>"); 
	detailWin.document.write("<body>"); 
	detailWin.document.write(htmlStr);
	detailWin.document.write("<br /><br /><center><a href='#' onclick='window.close()'>Close Window</a></center>");  
	detailWin.document.write("</body>"); 
	detailWin.document.write("</html>"); 
	detailWin.document.close(); 
}

function openEventDetail_no(id, title, date, time, location, room, speaker, speakerAffil, 
			description, eurl, sponsor, cname, cphone, cemail, category)
{
	var detailWin= new window.open("", "detailWin"); 
	detailWin.document.open();
	detailWin.document.write("<div>"); 
	detailWin.document.write("<input type=\"hidden\" name=\"id\" value=\"+id+\">"); 
	detailWin.document.write("<p class=\"pageTitle\">Event Details</p>"); 
	detailWin.document.write("<table width=\"100%\" border=\"1\">"); 
	detailWin.document.write("<tr><td colspan=\"2\"><p class=\"eventTitle\">"+title+"</p></td></tr> "); 
	detailWin.document.write("<tr><td><p class=\"fieldName\">Date:</p></td>"); 
	detailWin.document.write("<td><p class=\"fieldContent\">"+date+"</p></td></tr>"); 
	detailWin.document.write("<tr><td><p class=\"fieldName\">Time:</p></td>"); 
	detailWin.document.write("<td><p class=\"fieldContent\">"+time+"</p></td></tr>"); 
	detailWin.document.write("<tr><td><p class=\"fieldName\">Location:</p></td>"); 
	detailWin.document.write("<td><p class=\"fieldContent\">"+location+"</p></td></tr>"); 
	detailWin.document.write("<tr><td><p class=\"fieldName\">Room:</p></td>"); 
	detailWin.document.write("<td><p class=\"fieldContent\">"+room+"</p></td></tr>"); 
	detailWin.document.write("<tr><td><p class=\"fieldName\">Speaker:</p></td>"); 
	detailWin.document.write("<td><p class=\"fieldContent\">"+speaker+"</p></td></tr>"); 
	detailWin.document.write("<tr><td><p class=\"fieldName\">Speaker Affiliation:</p></td>"); 
	detailWin.document.write("<td><p class=\"fieldContent\">"+speakerAffil+"</p></td></tr>"); 
	detailWin.document.write("<tr><td><p class=\"fieldName\">Description:</p></td>"); 
	detailWin.document.write("<td><blockquote class=\"fieldContent\">"+description+"</blockquote></td></tr>"); 
	detailWin.document.write("<tr><td><p class=\"fieldName\">Event URL:</p></td>"); 
	detailWin.document.write("<td><p class=\"fieldContent\"><a href=\""+eurl+"\">"+eurl+"</a></p></td></tr>"); 
	detailWin.document.write("<tr><td><p class=\"fieldName\">Open To:</p></td>"); 
	detailWin.document.write("<td><p class=\"fieldContent\">Students,Faculty,Staff</p></td></tr>"); 
	detailWin.document.write("<tr><td><p class=\"fieldName\">Sponsor:</p></td>");
	detailWin.document.write("<td><p class=\"fieldContent\">"+sponsor+"</p></td></tr>");  
	detailWin.document.write("<tr><td><p class=\"fieldName\">Contact Name:</p></td>");  
	detailWin.document.write("<td><p class=\"fieldContent\">"+cname+"</p></td></tr>");  
	detailWin.document.write("<tr><td><p class=\"fieldName\">Contact Phone:</p></td>");  
	detailWin.document.write("<td><p class=\"fieldContent\">"+cphone+"</p></td></tr>");  
	detailWin.document.write("<tr><td><p class=\"fieldName\">Contact Email:</p></td>"); 
	detailWin.document.write("<td><p class=\"fieldContent\">"+cemail+"</p></td></tr>");
	detailWin.document.write("<tr><td><p class=\"fieldName\">Event Type:</p></td>");
	detailWin.document.write("<td><p class=\"fieldContent\">"+category+"</p></td></tr>");
	detailWin.document.write("</table>"); 
	detailWin.document.write("</div>"); 
	detailWin.document.close(); 	
}

var weekend = [0,6];
var weekendColor = "#e0e0e0";
var fontface = "Verdana";
var fontsize = 2;

var gNow = new Date();
var ggWinCal;
isNav = (navigator.appName.indexOf("Netscape") != -1) ? true : false;
isIE = (navigator.appName.indexOf("Microsoft") != -1) ? true : false;

Calendar.Months = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"];

// Non-Leap year Month days..
Calendar.DOMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
// Leap year Month days..
Calendar.lDOMonth = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

function Calendar(p_item, p_WinCal, p_month, p_year, p_format) {
	if ((p_month == null) && (p_year == null))	return;

	if (p_WinCal == null)
		this.gWinCal = ggWinCal;
	else
		this.gWinCal = p_WinCal;
	
	if (p_month == null) {
		this.gMonthName = null;
		this.gMonth = null;
		this.gYearly = true;
	} else {
		this.gMonthName = Calendar.get_month(p_month);
		this.gMonth = new Number(p_month);
		this.gYearly = false;
	}

	this.gYear = p_year;
	this.gFormat = p_format;
	this.gBGColor = "white";
	this.gFGColor = "black";
	this.gTextColor = "black";
	this.gHeaderColor = "black";
	this.gReturnItem = p_item;
}

Calendar.get_month = Calendar_get_month;
Calendar.get_daysofmonth = Calendar_get_daysofmonth;
Calendar.calc_month_year = Calendar_calc_month_year;
Calendar.print = Calendar_print;

function Calendar_get_month(monthNo) {
	return Calendar.Months[monthNo];
}

function Calendar_get_daysofmonth(monthNo, p_year) {
	/* 
	Check for leap year ..
	1.Years evenly divisible by four are normally leap years, except for... 
	2.Years also evenly divisible by 100 are not leap years, except for... 
	3.Years also evenly divisible by 400 are leap years. 
	*/
	if ((p_year % 4) == 0) {
		if ((p_year % 100) == 0 && (p_year % 400) != 0)
			return Calendar.DOMonth[monthNo];
	
		return Calendar.lDOMonth[monthNo];
	} else
		return Calendar.DOMonth[monthNo];
}

function Calendar_calc_month_year(p_Month, p_Year, incr) {
	/* 
	Will return an 1-D array with 1st element being the calculated month 
	and second being the calculated year 
	after applying the month increment/decrement as specified by 'incr' parameter.
	'incr' will normally have 1/-1 to navigate thru the months.
	*/
	var ret_arr = new Array();
	
	if (incr == -1) {
		// B A C K W A R D
		if (p_Month == 0) {
			ret_arr[0] = 11;
			ret_arr[1] = parseInt(p_Year) - 1;
		}
		else {
			ret_arr[0] = parseInt(p_Month) - 1;
			ret_arr[1] = parseInt(p_Year);
		}
	} else if (incr == 1) {
		// F O R W A R D
		if (p_Month == 11) {
			ret_arr[0] = 0;
			ret_arr[1] = parseInt(p_Year) + 1;
		}
		else {
			ret_arr[0] = parseInt(p_Month) + 1;
			ret_arr[1] = parseInt(p_Year);
		}
	}
	
	return ret_arr;
}

function Calendar_print() {
	ggWinCal.print();
}

function Calendar_calc_month_year(p_Month, p_Year, incr) {
	/* 
	Will return an 1-D array with 1st element being the calculated month 
	and second being the calculated year 
	after applying the month increment/decrement as specified by 'incr' parameter.
	'incr' will normally have 1/-1 to navigate thru the months.
	*/
	var ret_arr = new Array();
	
	if (incr == -1) {
		// B A C K W A R D
		if (p_Month == 0) {
			ret_arr[0] = 11;
			ret_arr[1] = parseInt(p_Year) - 1;
		}
		else {
			ret_arr[0] = parseInt(p_Month) - 1;
			ret_arr[1] = parseInt(p_Year);
		}
	} else if (incr == 1) {
		// F O R W A R D
		if (p_Month == 11) {
			ret_arr[0] = 0;
			ret_arr[1] = parseInt(p_Year) + 1;
		}
		else {
			ret_arr[0] = parseInt(p_Month) + 1;
			ret_arr[1] = parseInt(p_Year);
		}
	}
	
	return ret_arr;
}

// This is for compatibility with Navigator 3, we have to create and discard one object before the prototype object exists.
new Calendar();

Calendar.prototype.getMonthlyCalendarCode = function() {
	var vCode = "";
	var vHeader_Code = "";
	var vData_Code = "";
	
	// Begin Table Drawing code here..
	vCode = vCode + "<TABLE BORDER=1 BGCOLOR=\"" + this.gBGColor + "\">";
	
	vHeader_Code = this.cal_header();
	vData_Code = this.cal_data();
	vCode = vCode + vHeader_Code + vData_Code;
	
	vCode = vCode + "</TABLE>";
	
	return vCode;
}

Calendar.prototype.show = function() {
	var vCode = "";
	
	this.gWinCal.document.open();

	// Setup the page...
	this.wwrite("<html>");
	this.wwrite("<head><title>Calendar</title>");
	this.wwrite("</head>");

	this.wwrite("<body " + 
		"link=\"" + this.gLinkColor + "\" " + 
		"vlink=\"" + this.gLinkColor + "\" " +
		"alink=\"" + this.gLinkColor + "\" " +
		"text=\"" + this.gTextColor + "\">");
	this.wwriteA("<FONT FACE='" + fontface + "' SIZE=2><B>");
	this.wwriteA(this.gMonthName + " " + this.gYear);
	this.wwriteA("</B><BR>");

	// Show navigation buttons
	var prevMMYYYY = Calendar.calc_month_year(this.gMonth, this.gYear, -1);
	var prevMM = prevMMYYYY[0];
	var prevYYYY = prevMMYYYY[1];

	var nextMMYYYY = Calendar.calc_month_year(this.gMonth, this.gYear, 1);
	var nextMM = nextMMYYYY[0];
	var nextYYYY = nextMMYYYY[1];
	
	this.wwrite("<TABLE WIDTH='100%' BORDER=1 CELLSPACING=0 CELLPADDING=0 BGCOLOR='#e0e0e0'><TR><TD ALIGN=center>");
	this.wwrite("[<A HREF=\"" +
		"javascript:window.opener.Build(" + 
		"'" + this.gReturnItem + "', '" + this.gMonth + "', '" + (parseInt(this.gYear)-1) + "', '" + this.gFormat + "'" +
		");" +
		"\"><<<\/A>]</TD><TD ALIGN=center>");
	this.wwrite("[<A HREF=\"" +
		"javascript:window.opener.Build(" + 
		"'" + this.gReturnItem + "', '" + prevMM + "', '" + prevYYYY + "', '" + this.gFormat + "'" +
		");" +
		"\"><<\/A>]</TD><TD ALIGN=center>");
	this.wwrite("</TD><TD ALIGN=center>");
	this.wwrite("[<A HREF=\"" +
		"javascript:window.opener.Build(" + 
		"'" + this.gReturnItem + "', '" + nextMM + "', '" + nextYYYY + "', '" + this.gFormat + "'" +
		");" +
		"\">><\/A>]</TD><TD ALIGN=center>");
	this.wwrite("[<A HREF=\"" +
		"javascript:window.opener.Build(" + 
		"'" + this.gReturnItem + "', '" + this.gMonth + "', '" + (parseInt(this.gYear)+1) + "', '" + this.gFormat + "'" +
		");" +
		"\">>><\/A>]</TD></TR></TABLE><BR>");

	// Get the complete calendar code for the month..
	vCode = this.getMonthlyCalendarCode();
	this.wwrite(vCode);

	this.wwrite("</font></body></html>");
	this.gWinCal.document.close();
}

Calendar.prototype.showY = function() {
	var vCode = "";
	var i;
	var vr, vc, vx, vy;		// Row, Column, X-coord, Y-coord
	var vxf = 285;			// X-Factor
	var vyf = 200;			// Y-Factor
	var vxm = 10;			// X-margin
	var vym;				// Y-margin
	if (isIE)	vym = 75;
	else if (isNav)	vym = 25;
	
	this.gWinCal.document.open();

	this.wwrite("<html>");
	this.wwrite("<head><title>Calendar</title>");
	this.wwrite("<style type='text/css'>\n<!--");
	for (i=0; i<12; i++) {
		vc = i % 3;
		if (i>=0 && i<= 2)	vr = 0;
		if (i>=3 && i<= 5)	vr = 1;
		if (i>=6 && i<= 8)	vr = 2;
		if (i>=9 && i<= 11)	vr = 3;
		
		vx = parseInt(vxf * vc) + vxm;
		vy = parseInt(vyf * vr) + vym;

		this.wwrite(".lclass" + i + " {position:absolute;top:" + vy + ";left:" + vx + ";}");
	}
	this.wwrite("-->\n</style>");
	this.wwrite("</head>");

	this.wwrite("<body " + 
		"link=\"" + this.gLinkColor + "\" " + 
		"vlink=\"" + this.gLinkColor + "\" " +
		"alink=\"" + this.gLinkColor + "\" " +
		"text=\"" + this.gTextColor + "\">");
	this.wwrite("<FONT FACE='" + fontface + "' SIZE=2><B>");
	this.wwrite("Year : " + this.gYear);
	this.wwrite("</B><BR>");

	// Show navigation buttons
	var prevYYYY = parseInt(this.gYear) - 1;
	var nextYYYY = parseInt(this.gYear) + 1;
	
	this.wwrite("<TABLE WIDTH='100%' BORDER=1 CELLSPACING=0 CELLPADDING=0 BGCOLOR='#e0e0e0'><TR><TD ALIGN=center>");
	this.wwrite("[<A HREF=\"" +
		"javascript:window.opener.Build(" + 
		"'" + this.gReturnItem + "', null, '" + prevYYYY + "', '" + this.gFormat + "'" +
		");" +
		"\" alt='Prev Year'><<<\/A>]</TD><TD ALIGN=center>");
	this.wwrite("[<A HREF=\"javascript:window.print();\">Print</A>]</TD><TD ALIGN=center>");
	this.wwrite("[<A HREF=\"" +
		"javascript:window.opener.Build(" + 
		"'" + this.gReturnItem + "', null, '" + nextYYYY + "', '" + this.gFormat + "'" +
		");" +
		"\">>><\/A>]</TD></TR></TABLE><BR>");

	// Get the complete calendar code for each month..
	var j;
	for (i=11; i>=0; i--) {
		if (isIE)
			this.wwrite("<DIV ID=\"layer" + i + "\" CLASS=\"lclass" + i + "\">");
		else if (isNav)
			this.wwrite("<LAYER ID=\"layer" + i + "\" CLASS=\"lclass" + i + "\">");

		this.gMonth = i;
		this.gMonthName = Calendar.get_month(this.gMonth);
		vCode = this.getMonthlyCalendarCode();
		this.wwrite(this.gMonthName + "/" + this.gYear + "<BR>");
		this.wwrite(vCode);

		if (isIE)
			this.wwrite("</DIV>");
		else if (isNav)
			this.wwrite("</LAYER>");
	}

	this.wwrite("</font><BR></body></html>");
	this.gWinCal.document.close();
}

Calendar.prototype.wwrite = function(wtext) {
	this.gWinCal.document.writeln(wtext);
}

Calendar.prototype.wwriteA = function(wtext) {
	this.gWinCal.document.write(wtext);
}

Calendar.prototype.cal_header = function() {
	var vCode = "";
	
	vCode = vCode + "<TR>";
	vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Sun</B></FONT></TD>";
	vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Mon</B></FONT></TD>";
	vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Tue</B></FONT></TD>";
	vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Wed</B></FONT></TD>";
	vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Thu</B></FONT></TD>";
	vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Fri</B></FONT></TD>";
	vCode = vCode + "<TD WIDTH='16%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Sat</B></FONT></TD>";
	vCode = vCode + "</TR>";
	
	return vCode;
}

Calendar.prototype.cal_data = function() {
	var vDate = new Date();
	vDate.setDate(1);
	vDate.setMonth(this.gMonth);
	vDate.setFullYear(this.gYear);

	var vFirstDay=vDate.getDay();
	var vDay=1;
	var vLastDay=Calendar.get_daysofmonth(this.gMonth, this.gYear);
	var vOnLastDay=0;
	var vCode = "";

	/*
	Get day for the 1st of the requested month/year..
	Place as many blank cells before the 1st day of the month as necessary. 
	*/

	vCode = vCode + "<TR>";
	for (i=0; i<vFirstDay; i++) {
		vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(i) + "><FONT SIZE='2' FACE='" + fontface + "'> </FONT></TD>";
	}

	// Write rest of the 1st week
	for (j=vFirstDay; j<7; j++) {
		vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j) + "><FONT SIZE='2' FACE='" + fontface + "'>" + 
			"<A HREF='#' " + 
				"onClick=\"self.opener.document." + this.gReturnItem + ".value='" + 
				this.format_data(vDay) + 
				"';window.close();self.opener.updateRepeatFields();\">" + 
				this.format_day(vDay) + 
			"</A>" + 
			"</FONT></TD>";
		vDay=vDay + 1;
	}
	vCode = vCode + "</TR>";

	// Write the rest of the weeks
	for (k=2; k<7; k++) {
		vCode = vCode + "<TR>";

		for (j=0; j<7; j++) {
			vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j) + "><FONT SIZE='2' FACE='" + fontface + "'>" + 
				"<A HREF='#' " + 
					"onClick=\"self.opener.document." + this.gReturnItem + ".value='" + 
					this.format_data(vDay) + 
					"';window.close();self.opener.updateRepeatFields();\">" + 
				this.format_day(vDay) + 
				"</A>" + 
				"</FONT></TD>";
			vDay=vDay + 1;

			if (vDay > vLastDay) {
				vOnLastDay = 1;
				break;
			}
		}

		if (j == 6)
			vCode = vCode + "</TR>";
		if (vOnLastDay == 1)
			break;
	}
	
	// Fill up the rest of last week with proper blanks, so that we get proper square blocks
	for (m=1; m<(7-j); m++) {
		if (this.gYearly)
			vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j+m) + 
			"><FONT SIZE='2' FACE='" + fontface + "' COLOR='gray'> </FONT></TD>";
		else
			vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j+m) + 
			"><FONT SIZE='2' FACE='" + fontface + "' COLOR='gray'>" + m + "</FONT></TD>";
	}
	
	return vCode;
}

Calendar.prototype.format_day = function(vday) {
	var vNowDay = gNow.getDate();
	var vNowMonth = gNow.getMonth();
	var vNowYear = gNow.getFullYear();

	if (vday == vNowDay && this.gMonth == vNowMonth && this.gYear == vNowYear)
		return ("<FONT COLOR=\"RED\"><B>" + vday + "</B></FONT>");
	else
		return (vday);
}

Calendar.prototype.write_weekend_string = function(vday) {
	var i;

	// Return special formatting for the weekend day.
	for (i=0; i<weekend.length; i++) {
		if (vday == weekend[i])
			return (" BGCOLOR=\"" + weekendColor + "\"");
	}
	
	return "";
}

Calendar.prototype.format_data = function(p_day) {
	var vData;
	var vMonth = 1 + this.gMonth;
	vMonth = (vMonth.toString().length < 2) ? "0" + vMonth : vMonth;
	var vMon = Calendar.get_month(this.gMonth).substr(0,3).toUpperCase();
	var vFMon = Calendar.get_month(this.gMonth).toUpperCase();
	var vY4 = new String(this.gYear);
	var vY2 = new String(this.gYear.substr(2,2));
	var vDD = (p_day.toString().length < 2) ? "0" + p_day : p_day;

	switch (this.gFormat) {
		case "MM\/DD\/YYYY" :
			vData = vMonth + "\/" + vDD + "\/" + vY4;
			break;
		case "MM\/DD\/YY" :
			vData = vMonth + "\/" + vDD + "\/" + vY2;
			break;
		case "MM-DD-YYYY" :
			vData = vMonth + "-" + vDD + "-" + vY4;
			break;
		case "MM-DD-YY" :
			vData = vMonth + "-" + vDD + "-" + vY2;
			break;

		case "DD\/MON\/YYYY" :
			vData = vDD + "\/" + vMon + "\/" + vY4;
			break;
		case "DD\/MON\/YY" :
			vData = vDD + "\/" + vMon + "\/" + vY2;
			break;
		case "DD-MON-YYYY" :
			vData = vDD + "-" + vMon + "-" + vY4;
			break;
		case "DD-MON-YY" :
			vData = vDD + "-" + vMon + "-" + vY2;
			break;

		case "DD\/MONTH\/YYYY" :
			vData = vDD + "\/" + vFMon + "\/" + vY4;
			break;
		case "DD\/MONTH\/YY" :
			vData = vDD + "\/" + vFMon + "\/" + vY2;
			break;
		case "DD-MONTH-YYYY" :
			vData = vDD + "-" + vFMon + "-" + vY4;
			break;
		case "DD-MONTH-YY" :
			vData = vDD + "-" + vFMon + "-" + vY2;
			break;

		case "DD\/MM\/YYYY" :
			vData = vDD + "\/" + vMonth + "\/" + vY4;
			break;
		case "DD\/MM\/YY" :
			vData = vDD + "\/" + vMonth + "\/" + vY2;
			break;
		case "DD-MM-YYYY" :
			vData = vDD + "-" + vMonth + "-" + vY4;
			break;
		case "DD-MM-YY" :
			vData = vDD + "-" + vMonth + "-" + vY2;
			break;

		default :
			vData = vMonth + "\/" + vDD + "\/" + vY4;
	}

	return vData;
}

function Build(p_item, p_month, p_year, p_format) {
	var p_WinCal = ggWinCal;
	gCal = new Calendar(p_item, p_WinCal, p_month, p_year, p_format);

	// Customize your Calendar here..
	gCal.gBGColor="white";
	gCal.gLinkColor="black";
	gCal.gTextColor="black";
	gCal.gHeaderColor="darkgreen";

	// Choose appropriate show function
	if (gCal.gYearly)	gCal.showY();
	else	gCal.show();
}

function show_calendar() {
	/* 
		p_month : 0-11 for Jan-Dec; 12 for All Months.
		p_year	: 4-digit year
		p_format: Date format (mm/dd/yyyy, dd/mm/yy, ...)
		p_item	: Return Item.
	*/

	p_item = arguments[0];
	if (arguments[1] == null)
		p_month = new String(gNow.getMonth());
	else
		p_month = arguments[1];
	if (arguments[2] == "" || arguments[2] == null)
		p_year = new String(gNow.getFullYear().toString());
	else
		p_year = arguments[2];
	if (arguments[3] == null)
		p_format = "MM/DD/YYYY";
	else
		p_format = arguments[3];

	vWinCal = window.open("", "Calendar", 
		"width=250,height=250,status=no,resizable=no,top=200,left=200");
	vWinCal.opener = self;
	ggWinCal = vWinCal;

	Build(p_item, p_month, p_year, p_format);
}
/*
Yearly Calendar Code Starts here
*/
function show_yearly_calendar(p_item, p_year, p_format) {
	// Load the defaults..
	if (p_year == null || p_year == "")
		p_year = new String(gNow.getFullYear().toString());
	if (p_format == null || p_format == "")
		p_format = "MM/DD/YYYY";

	var vWinCal = window.open("", "Calendar", "scrollbars=yes");
	vWinCal.opener = self;
	ggWinCal = vWinCal;

	Build(p_item, null, p_year, p_format);
}

// return year is a leap year
function isLeapYear (year)
{
   if (((year % 4)==0) && ((year % 100)!=0) || ((year % 400)==0))
      return (true);
   else
      return (false);
}

// get the number of days of the provided month in the provided year
function getDaysOfMonth (month, year)
{
   var days;
   if (month==1 || month==3 || month==5 || month==7 || month==8 || month==10 || month==12)
      days=31;
   else if (month==4 || month==6 || month==9 || month==11) days=30;
   else if (month==2)
   {
      if (isLeapYear(year)) days=29;
      else days=28;
   }
   return (days);
}

// if date1 > date2 return 1 
// if date1 == date2 return 0 
// if date1 < date2 return -1
function compareDates (date1, date2) {
    var unixdate1= date1.getTime();
    var unixdate2= date2.getTime();

    if (unixdate1 > unixdate2) return 1;
    else if (unixdate1 == unixdate2) return 0;
    else return -1;
}
function updateRepeatFields() {
	if(document.forms["addEvent"] != null) { // only update if addEventForm is there
	//window.alert("changed!"); 
	// get form
	var form= document.forms[0]; 

	// get repeat option selected value
	var roption= form.roption.options.selectedIndex; 
	roption= form.roption.options[roption].value; 
	
	// get edate and endon fields, and parse them into a Date objects, so that we can print them
	var edate= form.edate.value; 
	var endon= form.endon.value; 

	//window.alert(edateStr);  
	
	var date= new Date(edate);
	var edate= new Date(endon); 
	
	//var testdate= new Date("05/22/2003"); 
	//window.alert("the chosen date: " + date);  
	
	var year= isNaN(date.getFullYear()) ? "????" : date.getFullYear(); 
	var month= isNaN(date.getMonth()+1) ? "??" : date.getMonth()+1; 
	var day= isNaN(date.getDate()) ? "??" : date.getDate(); 
	var dateStr= month+"/"+day+"/"+year; 

	var year= isNaN(edate.getFullYear()) ? "????" : edate.getFullYear();
	var month= isNaN(edate.getMonth()+1) ? "??" : edate.getMonth()+1; 
	var day= isNaN(edate.getDate()) ? "??" : edate.getDate(); 
	var edateStr= month+"/"+day+"/"+year; 
		
	// note changes are made according to what browser we are using
	switch(roption) {
		case "None":		
		if(isSupportedBrowser()) { 
			document.getElementById('reveryField').style.visibility= "hidden"; 
			document.getElementById('reveryContent').style.visibility= "hidden"; 
			document.getElementById('rdaysField').style.visibility= "hidden"; 
			document.getElementById('rdaysContent').style.visibility= "hidden"; 
			document.getElementById('rbyField').style.visibility= "hidden"; 
			document.getElementById('rbyContent').style.visibility= "hidden"; 
			document.getElementById('endonField').style.visibility= "hidden"; 
			document.getElementById('endonContent').style.visibility= "hidden"; 
			rmessage.innerHTML= "The event occurs on " + dateStr + " and does not repeat."; 
 		}
		
		break; 
		case "Daily": 
		// get revery field
		var revery= isNaN(parseInt(form.revery.value)) ? "?" : parseInt(form.revery.value);
 		//window.alert("revery" + revery); 
	
		if(isSupportedBrowser()) {
			document.getElementById('reveryField').style.visibility= "visible"; 
			document.getElementById('reveryContent').style.visibility= "visible"; 
			document.getElementById('rdaysField').style.visibility= "hidden"; 
			document.getElementById('rdaysContent').style.visibility= "hidden"; 
			document.getElementById('rbyField').style.visibility= "hidden"; 
			document.getElementById('rbyContent').style.visibility= "hidden"; 
			document.getElementById('endonField').style.visibility= "visible"; 
			document.getElementById('endonContent').style.visibility= "visible";
			if(revery == 1) 
			rmessage.innerHTML= "The event occurs on " + dateStr + " and repeats every day, until "+ edateStr +".";
			else if(revery == 2) 
			rmessage.innerHTML= "The event occurs on " + dateStr + " and repeats every other day, until "+ edateStr +".";
			else    
			rmessage.innerHTML= "The event occurs on " + dateStr + " and repeats every " + revery + " days, until "+ edateStr + ".";  
		}

		break; 
		case "Weekly":
		// get revery field
		var revery= isNaN(parseInt(form.revery.value)) ? "?" : parseInt(form.revery.value);
 		// get rdays field - only care about selected days
		rdays= new Array(); 
		for(var i= 0; i < form.elements["rdays[]"].options.length; i++) {
			//window.alert("checking ... " + form.elements["rdays[]"].options[i].value); 
			if(form.elements["rdays[]"].options[i].selected) { 
				//window.alert(form.elements["rdays[]"].options[i].value + "selected!"); 
				rdays[rdays.length]= form.elements["rdays[]"].options[i].value;
			}   
		} 
		if(rdays.length > 1) { 
			rdays[rdays.length-1]= "and " + rdays[rdays.length-1];  
			rdays= rdays.join(", "); 
		} 
		else if (rdays.length == 1) 
			rdays= rdays[0]; 

		else rdays= "?"; 
		// window.alert("rdays: " + rdays); 

		if(isSupportedBrowser()) {
			document.getElementById('reveryField').style.visibility= "visible"; 
			document.getElementById('reveryContent').style.visibility= "visible"; 
			document.getElementById('rdaysField').style.visibility= "visible"; 
			document.getElementById('rdaysContent').style.visibility= "visible"; 
			document.getElementById('rbyField').style.visibility= "hidden"; 
			document.getElementById('rbyContent').style.visibility= "hidden"; 
			document.getElementById('endonField').style.visibility= "visible"; 
			document.getElementById('endonContent').style.visibility= "visible"; 
			if(revery == 1) 
			rmessage.innerHTML= "The event occurs on " + dateStr + " and repeats every week on " + rdays + ", until "+ edateStr+".";
			else if(revery == 2) 
			rmessage.innerHTML= "The event occurs on " + dateStr + " and repeats every other week on " + rdays + ", until "+ edateStr + ".";
			else    
			rmessage.innerHTML= "The event occurs on " + dateStr + " and repeats every " + revery + " weeks on " + rdays + ", until "+edateStr+"."; 
		}
		break; 
		case "Monthly": 
		// get revery field
		var revery= isNaN(parseInt(form.revery.value)) ? "?" : parseInt(form.revery.value);
		// get rby field
		var rby= form.rby.value; 
		var index= getWeekDayIndex(date); 
 		var indexArr= new Array("1st", "2nd", "3rd", "4th", "5th"); 
		var weekArr= new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"); 

		var nthDay= ""; 
		var weekDay= ""; 
		var nthDate= ""; 

		if(index == 4) nthDay= "last"; 
		else if(index != -1) nthDay= indexArr[index];
		else nthDay= "?"; 
			
		if(!isNaN(date.getDay())) weekDay= weekArr[date.getDay()];  	
		else weekDay= "?th"; 

		if(!isNaN(date.getDate())) { 
			nthDate= date.getDate();
			switch(nthDate) {
				case 1: nthDate= "1st"; break; 
				case 2: nthDate= "2nd"; break; 
				case 3: nthDate= "3rd"; break; 
				case 30: nthDate= "30th (or the last day)"; break; 
				case 31: nthDate= "31st (or the last day)"; break; 
				default: nthDate= nthDate+"th"; break; 
			} 
		} 
		else nthDate= "?th";  
			

		if(isSupportedBrowser()) {
			document.getElementById('reveryField').style.visibility= "visible"; 
			document.getElementById('reveryContent').style.visibility= "visible"; 
			document.getElementById('rdaysField').style.visibility= "hidden"; 
			document.getElementById('rdaysContent').style.visibility= "hidden"; 
			document.getElementById('rbyField').style.visibility= "visible"; 
			document.getElementById('rbyContent').style.visibility= "visible"; 
			document.getElementById('endonField').style.visibility= "visible"; 
			document.getElementById('endonContent').style.visibility= "visible";
			
			var byStr= ""; 
			if(rby == "Date") byStr= "the " + nthDate + " of every month"; 
			else byStr= "the " + nthDay + " " + weekDay + " of every month";  

			if(revery == 1) 
			rmessage.innerHTML= "The event occurs on " + dateStr + " and repeats every month on " + byStr + ", until "+ edateStr+".";
			else if(revery == 2) 
			rmessage.innerHTML= "The event occurs on " + dateStr + " and repeats every other month on " + byStr + ", until "+ edateStr + ".";
			else    
			rmessage.innerHTML= "The event occurs on " + dateStr + " and repeats every " + revery + " months on " + byStr + ", until "+edateStr+"."; 

		}
		break; 
		case "Yearly": 
		// get revery field
		var revery= isNaN(parseInt(form.revery.value)) ? "?" : parseInt(form.revery.value);
 
		if(isSupportedBrowser()) {
			document.getElementById('reveryField').style.visibility= "visible"; 
			document.getElementById('reveryContent').style.visibility= "visible"; 
			document.getElementById('rdaysField').style.visibility= "hidden"; 
			document.getElementById('rdaysContent').style.visibility= "hidden"; 
			document.getElementById('rbyField').style.visibility= "hidden"; 
			document.getElementById('rbyContent').style.visibility= "hidden"; 
			document.getElementById('endonField').style.visibility= "visible"; 
			document.getElementById('endonContent').style.visibility= "visible";
			if(revery == 1) 
			rmessage.innerHTML= "The event occurs on " + dateStr + " and repeats every year, until "+ edateStr +".";
			else if(revery == 2) 
			rmessage.innerHTML= "The event occurs on " + dateStr + " and repeats every other year, until "+ edateStr +".";
			else    
			rmessage.innerHTML= "The event occurs on " + dateStr + " and repeats every " + revery + " years, until "+ edateStr + ".";   
		}
		break; 
		default: 
	}
 }
} 

// define some constants
var MSIE= "Internet Explorer"; 
var OTHER= "Other"; 
var IE4PLUS= "4.0+"; 

// string getBrowserName() - return one of the constants above
function getBrowserName() {
	var browser= navigator.appName; 

	// search for internet explorer
	if(browser.indexOf("Microsoft") >= 0) 
		return MSIE; 	
	
	// else return other
	return OTHER;     
}
// for msie, if browser version is >= 4, return IE4PLUS
// otherwise return OTHER
function getBrowserVersion() {
	var browser= getBrowserName();  
	var browserVersion; 
	if(browser == MSIE) { 	
		browserVersion= navigator.userAgent; 
		findIndex= browserVersion.indexOf("MSIE") + 5; 
		browserVersion= parseInt(browserVersion.substring(findIndex, findIndex+1)); 
		//window.alert(browserVersion); 
		return browserVersion >= 4 ? IE4PLUS : OTHER;  
	}
	return OTHER; 	
}   
// bool isSupportedBrowser() - return true if we have "the right browser". This will 
// let us know if we can use "fancy" scripting or not with CSS. If it's not 
// a supported browser, disable the "fancy" scripting so that we get no error. 
// For now, a "supported" browser is only Internet Explorer 4+. 
// Note that other JavaScripting is still enabled for other browsers
function isSupportedBrowser() {
	var browserName= getBrowserName(); 
	var browserVersion= getBrowserVersion(); 

	// browser is supported if browserName==MSIE and browserVersion==IE4PLUS
	
	return (browserName==MSIE && browserVersion==IE4PLUS); 
}

// Date getFirstWeekDay (int weekday, Date date)
// return the first occurrence of weekday in the month
// note that weekday is an week-day index - 0 - Sunday, 1 - Monday, etc. 
function getFirstWeekDay(date) {  
	// go to the first of the month that date is in
	//window.alert("the date is " + date); 
	//window.alert(date.getFullYear());
 
	var firstOfMonth= new Date(date.getFullYear(), date.getMonth(), 1, date.getHours(), date.getMinutes(), date.getSeconds()); 
	// window.alert("first of month: " + firstOfMonth); 

	//window.alert(firstOfMonth.getFullYear());
	//firstOfMonth.setYear(2010); 
	//window.alert("now first of monht: " + firstOfMonth);  
	
	//get the day the first of month falls on
	var firstOfMonthWeekDay= firstOfMonth.getDay(); 
	
	// get the day the date falls on
	var weekday= date.getDay(); 

	// get the offset
	var offset= weekday - firstOfMonthWeekDay; 

	// if offset < 0, go to next weekday, not the previous one
	// else add the offset number of days to get to the first occurrence of weekday
	var daysToAdd= offset < 0 ? (offset + 7) : offset; 

	return new Date(firstOfMonth.getFullYear(), firstOfMonth.getMonth(), (firstOfMonth.getDate() + daysToAdd), firstOfMonth.getHours(), firstOfMonth.getMinutes(), firstOfMonth.getSeconds()); 
 
}

// int getWeekDayIndex (int weekday, date)
// return the index of this weekday in relation to the other weekdays of the month
// index mapping: 0 -> 1st, 1 -> 2nd, etc.
// for example, if this is the third tuesday of the month, return 2
function getWeekDayIndex(date) {
	if(!isValidDate(date)) return -1; 
	var weekday= date.getDay(); 
	var datePtr= getFirstWeekDay(date).getTime(); // start at the first occurence of the weekday

	var index= 0; 
	// move along the month until we hit this occurrence of the weekday
	while(datePtr < date.getTime()) { 
		// increase date by one week, and index by 1
		datePtr+= 7*24*3600*1000; // 7 days per week, 24 hrs per day, 3600 secs per hour, 1000 secons per miliseoncs 	
		index++;
	}  
	return index; 
} 

function isValidDate(date) { 
	return !isNaN(date.getFullYear()) && !isNaN(date.getMonth()) && !isNaN(date.getDate()) && !isNaN(date.getHours())  && !isNaN(date.getMinutes()) && !isNaN(date.getSeconds()); 
} 

function changeDays(menuToChange) {
         // window.alert("youre changing: " + menuToChange.name);
         // decide whether youre changing the start date or end date
         var tochange= (menuToChange.name.search("start") >= 0) ? "start" : "end";

         var yearIndex= document.forms[0].elements[tochange + "Year"].options.selectedIndex;
         var year= parseInt(document.forms[0].elements[tochange + "Year"].options[yearIndex].value);

         var monthIndex= document.forms[0].elements[tochange + "Month"].options.selectedIndex;
         var month= parseInt(document.forms[0].elements[tochange + "Month"].options[monthIndex].value);

         var numdays= getDaysOfMonth(month, year);

         writeDays(tochange, numdays);

}
function writeDays(tochange, numdays) {
    var previousDayIndex= parseInt(document.forms[0].elements[tochange + "Day"].options.selectedIndex);

    var i;
    for( i = 0; i < numdays; i++ ) {

      var newOptionArray= new Array();
       document.forms[0].elements[tochange + "Day"].options[i]= new Option(i+1, i+1);

    }

    document.forms[0].elements[tochange + "Day"].options.length= numdays;

    if((previousDayIndex + 1)  > numdays)
      document.forms[0].elements[tochange + "Day"].options[numdays-1].selected= true;
    else
      document.forms[0].elements[tochange + "Day"].options[previousDayIndex].selected= true;

}

function isLeapYear (year)
{
   if (((year % 4)==0) && ((year % 100)!=0) || ((year % 400)==0))
      return (true);
   else
      return (false);
}

function getDaysOfMonth (month, year)
{
   var days;
   if (month==1 || month==3 || month==5 || month==7 || month==8 || month==10 || month==12)
      days=31;
   else if (month==4 || month==6 || month==9 || month==11) days=30;
   else if (month==2)
   {
      if (isLeapYear(year)) days=29;
      else days=28;
   }
   return (days);
}

function compareDates (date1, date2) {
    var unixdate1= date1.getTime();
    var unixdate2= date2.getTime();

    if (unixdate1 > unixdate2) return 1;
    else if (unixdate1 == unixdate2) return 0;
    else return -1;
}
function changeEndDate() {
	//window.alert("changed!"); 
      var startYear= document.forms[0].startYear.options.selectedIndex;
      var startYear= parseInt(document.forms[0].startYear.options[startYear].value);
	 //window.alert("start Year" + startYear); 

      var startMonth= document.forms[0].startMonth.options.selectedIndex;
      var startMonth= parseInt(document.forms[0].startMonth.options[startMonth].value) - 1;

      var startDay= document.forms[0].startDay.options.selectedIndex;
      var startDay= parseInt(document.forms[0].startDay.options[startDay].value);


      var endYear= document.forms[0].endYear.options.selectedIndex;
      var endYear= parseInt(document.forms[0].endYear.options[endYear].value);
	//window.alert("end Year" + endYear); 

      var endMonth= document.forms[0].endMonth.options.selectedIndex;
      var endMonth= parseInt(document.forms[0].endMonth.options[endMonth].value) - 1;
	//window.alert("end Month" + endMonth); 

      var endDay= document.forms[0].endDay.options.selectedIndex;
      var endDay= parseInt(document.forms[0].endDay.options[endDay].value);


      // pick any values for hour and minute
       var hour= 1; var minute= 0;

      var startDate= new Date(startYear, startMonth, startDay, hour, minute, 0);
      var endDate= new Date(endYear, endMonth, endDay, hour, minute, 0);

      var datecompare= compareDates(startDate, endDate);
	  //window.alert(startDate); 
	  //window.alert(endDate); 
	  
//window.alert(datecompare); 
      if(datecompare == 1) {
         document.forms[0].elements["endYear"].options.selectedIndex=
                      document.forms[0].elements["startYear"].options.selectedIndex;
         document.forms[0].elements["endMonth"].options.selectedIndex=
                      document.forms[0].elements["startMonth"].options.selectedIndex;
         document.forms[0].elements["endDay"].options.selectedIndex=
                      document.forms[0].elements["startDay"].options.selectedIndex;
      }
}
function changeOtherTime(thisMenu) {
	// select the search by time option
		
	
     var thisMenuName= (thisMenu.name.search("start") >= 0) ? "start" : "end";
     var tochange= (thisMenu.name.search("start") >= 0) ? "end" : "start";

    // get start time indeces
    var startHourIndex= document.forms[0].startHour.options.selectedIndex;
    var startMinuteIndex= document.forms[0].startMinute.options.selectedIndex;
    var startAmpmIndex= document.forms[0].startAmpm.options.selectedIndex;


    // get end time indeces
    var endHourIndex= document.forms[0].endHour.options.selectedIndex;
    var endMinuteIndex= document.forms[0].endMinute.options.selectedIndex;
    var endAmpmIndex= document.forms[0].endAmpm.options.selectedIndex;


    // get start time values
    var startHour= parseInt(document.forms[0].startHour.options[startHourIndex].value);
    var startMinute= parseInt(document.forms[0].startMinute.options[startMinuteIndex].value);
    var startAmpm= document.forms[0].startAmpm.options[startAmpmIndex].value;

    // get end time values
    var endHour= parseInt(document.forms[0].endHour.options[endHourIndex].value);
    var endMinute= parseInt(document.forms[0].endMinute.options[endMinuteIndex].value);
    var endAmpm= document.forms[0].endAmpm.options[endAmpmIndex].value;


    // check for am/pm
    if (startAmpm == "pm" && startHour < 12) {
       startHour+= 12;
    }
    else if (startAmpm == "am" && startHour == 12) {
       startHour-= 12;
    }
    if (endAmpm == "pm" && endHour < 12) {
        endHour+= 12;
    }
    else if (endAmpm == "am" && endHour == 12) {
        endHour-= 12;
    }

    // pick any values for date
    var year= 2000, month= 0, day= 1;

    var startTime= new Date(year, month, day, startHour, startMinute, 0);
    var endTime= new Date(year, month, day, endHour, endMinute, 0);

    var datecompare= compareDates(startTime, endTime);

  if(datecompare == 1) {
         document.forms[0].elements[tochange + "Hour"].options.selectedIndex=
                      document.forms[0].elements[thisMenuName + "Hour"].options.selectedIndex;
         document.forms[0].elements[tochange + "Minute"].options.selectedIndex=
                      document.forms[0].elements[thisMenuName + "Minute"].options.selectedIndex;
         document.forms[0].elements[tochange + "Ampm"].options.selectedIndex=
                      document.forms[0].elements[thisMenuName + "Ampm"].options.selectedIndex;
  }
}

// End -->   
