///////////////////////////////////////////////////////////////////////////////////////////////////////
//events 1.1
//Curtis Kipple ckipple@ksu.edu
//written September 18, 2004
//modified March 8, 2005 to allow a cgi script to easily modify the array
//
//This script was written for KSU's Campus Crusade's website
//It allows a fairly simple way to enter events and then allows scripts to call its functions,
//returning html coding for the events pages on the Crusade website
//
//THE ONLY PART THAT SHOULD BE ALTERED ON A REGULAR BASIS IS THE eventInformation() FUNCTION!!! (bottom)
//You will call the schedule(option) function on the webpage.	
//
//If this script is usefull to anyone else, please feel free to use and/or alter it.
//Please keep a reference of my name however on your script.  (Please indulge my egocentric tendencies)
////////////////////////////////////////////////////////////////////////////////////////////////////////

//object of eventItems
function eventItem(title, location, month, day, hours, minutes, year, monthEnd, dayEnd, hoursEnd, minutesEnd, yearEnd, exp, description)
{
this.title = title;
this.location = location;
this.date = new Date(year, month -1, day, hours, minutes);
this.ends = new Date(yearEnd, monthEnd -1, dayEnd, hoursEnd, minutesEnd);
this.expires = new Date(this.ends.valueOf()+exp*3600000);
this.description = description;
}

//used in sorting eventItem array
function sortByDate(a, b)
{
var x1 = a.date.valueOf();
var y1 = b.date.valueOf();
return ((x1 < y1) ? -1 : ((x1 > y1) ? 1 : 0));
}

//function called by webpage
//option 1-prints only basics and only events daysToShow from now
//option 2-prints all information for events expiration has not expired
function schedule(option)
{  var daysToShow = 7;
  var list = eventInformation().sort(sortByDate);
  var length = list.length;
  var dateNow = new Date();

  if(option==1)
  {  var j = 0;
     while(j < length)
     {  if(list[j].expires.valueOf() >= dateNow.valueOf() && (list[j].date.valueOf() <= (dateNow.valueOf() + 86400000*daysToShow)))
	  {  var a = list[j].date.toDateString();
	     var c = a.lastIndexOf(' ');
	     var w2 = a.substring(0,c);
	     var b = list[j].date.toLocaleTimeString();
	     var x2 = list[j].date.getHours();
	     var z2 = "AM";
	     if(x2 == 12) z2 = "PM";
	     if(x2 > 12)
	     {  x2-=12;
		  z2 = "PM";
	     }
	     if(x2 == 0) x2=12;
	     c  = list[j].date.getMinutes();
	     if(c>10) y2 = c + " ";
	     if(c<10) y2 = "0" + c + " ";
	     document.write("<i><b>" + list[j].title + "</b><br>" + list[j].location + "</i>");
           if(list[j].location !="") document.write("<br>");
	     document.write(w2);
	     if(!((x2 == 12) && (z2 =="AM") && (y2 == "01 "))) document.write(", " + x2 + ":" + y2 + z2);
	     document.write("<br><br>");
	   }
         j++;
     }
  }
  if(option==2)
  {  var j = 0;
     while(j < length)
     {  if(list[j].expires.valueOf() >= dateNow.valueOf())
	  {  var a = list[j].date.toLocaleDateString();
	     var c = a.lastIndexOf(' ');
	     var w2 = a.substring(0,c -1);
	     var b = list[j].date.toLocaleTimeString();
	     var x2 = list[j].date.getHours();
	     var z2 = "AM";
	     if(x2 == 12) z2 = "PM";
	     if(x2 > 12)
	     {  x2-=12;
		  z2 = "PM";
	     }
	     if(x2 == 0) x2=12;
	     c  = list[j].date.getMinutes();
	     if(c>10) y2 = c + " ";
	     if(c<10) y2 = "0" + c + " ";
	     document.write("<i><b>&nbsp;&nbsp;&nbsp;>" + list[j].title +
					"</b><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" +
					list[j].location + "</i>");
	     if(list[j].location !="") document.write("<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
	     document.write(w2);
	     if(!((x2 == 12) && (z2 =="AM") && (y2 == 1))) document.write(", " + x2 + ":" + y2 + z2);
	     var a = list[j].ends.toLocaleDateString();
	     var c = a.lastIndexOf(' ');
	     var w2 = a.substring(0,c -1);
	     var b = list[j].ends.toLocaleTimeString();
	     var x2 = list[j].ends.getHours();
	     var z2 = "AM";
	     if(x2 == 12) z2 = "PM";
	     if(x2 > 12)
	     {  x2-=12;
		  z2 = "PM";
	     }
	     if(x2 == 0) x2=12;
	     c  = list[j].ends.getMinutes();
	     if(c>10) y2 = c + " ";
	     if(c<10) y2 = "0" + c + " ";
	     if(list[j].date.getMonth() != list[j].ends.getMonth() || list[j].date.getDate() != list[j].ends.getDate() ) document.write(" - " + w2);
	     if(!((x2 == 12) && (z2 =="AM") && (y2 == 1)))
	     { if(list[j].date.getMonth() == list[j].ends.getMonth() && list[j].date.getDate() == list[j].ends.getDate() )document.write(" - ");
		 else document.write(", ");
		 document.write(x2 + ":" + y2 + z2);
	     }

          if(list[j].description != "") document.write("<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + list[j].description);
	    { document.write("<br><br>"); }
	    }
          j++;
      }
   }
}

//This function sets up the information array that the other functions use.
//you need to fill out it out like such...
//		information = new Array(new eventItem(a,b,c,d,e,f,g,h,i, j, k, l, m, n), new eventItem(a,....i))
//a=title of the event				b=location of the event				c=month(1-12) start
//d=day(1-31) start				e=hour of event (0-23) start			f=minutes of event (0-59) start
//g=year start					h=month(1-12) end					i=day(1-31) end
//j=hour of event (0-23) end			k=minutes of event (0-59) end			l=year end
//m=hours it remains listed after end	n=description of event
//
//if title, location or description are "" they will not be printed.  If hour is 0 and minutes 1, time will not be printed
//
function eventInformation()
{
information = new Array(
new eventItem("Cru", "Union Little Theatre", 1, 19, 20, 0, 2006, 1, 19, 0, 1, 2006, 23, "Our Weekly Meeting")	//Submitted by ckipple on Tue Jan 17 11:06:09 2006
,new eventItem("Cru", "Union Little Theatre", 1, 26, 20, 0, 2006, 1, 26, 0, 1, 2006, 23, "Weekly Meeting")	//Submitted by ckipple on Tue Jan 17 11:10:38 2006
,new eventItem("Cru", "Union Little Theatre", 2, 2, 20, 0, 2006, 2, 2, 0, 1, 2006, 23, "Our Weekly Meeting")	//Submitted by ckipple on Tue Jan 17 11:12:46 2006
,new eventItem("Cru", "Union Little Theatre", 2, 9, 20, 0, 2006, 2, 9, 0, 1, 2006, 23, "Weekly Meeting")	//Submitted by ckipple on Tue Jan 17 11:16:37 2006

,new eventItem("Cru", "Union Little Theatre", 2, 16, 20, 0, 2006, 2, 16, 0, 1, 2006, 23, "Our Weekly Meeting")	//Submitted by ckipple on Tue Jan 17 11:18:53 2006

,new eventItem("M 412", "Union 209", 1, 22, 16, 0, 2006, 1, 22, 18, 0, 2006, 2, "Leadership Meeting--All Leaders, the whole time")
	//Submitted by ckipple on Thu Jan 19 07:17:36 2006

,new eventItem("Weekly Prayer", "Union-Ice Cream Shop", 1, 26, 8, 30, 2006, 1, 26, 0, 1, 2006, 9, "Come join us in fun times and prayer!  Don't miss it.")	//Submitted by rachel3 on Wed Jan 25 23:54:19 2006

,new eventItem("Weekly Prayer", "Union-Ice Cream Shop", 1, 27, 12, 30, 2006, 1, 27, 0, 1, 2005, 9, "Did you miss prayer on Thursday?  Come grab some lunch and join in a good time of prayer and fellowship w/friends!")	//Submitted by rachel3 on Wed Jan 25 23:56:08 2006

,new eventItem("Weekly Prayer", "Union-Ice Cream Shop", 2, 2, 8, 30, 2006, 2, 2, 0, 1, 2006, 9, "Oh wow! you really must come!  God reveals His most precious secrets when we listen to Him! Come offer up prayers to God because of His MANY blessings!")	//Submitted by rachel3 on Mon Jan 30 21:15:54 2006

,new eventItem("Weekly Prayer", "Union-Ice Cream Shop", 2, 3, 12, 30, 2006, 2, 3, 0, 1, 2006, 9, "Spent time with God lately?  Here's your chance! ")	//Submitted by rachel3 on Mon Jan 30 21:17:11 2006

,new eventItem("Weekly Prayer (prayer o'rama)", "Union-Ice Cream Shop", 2, 9, 8, 30, 2006, 2, 9, 0, 1, 2006, 9, "Come pray with us!")	//Submitted by rachel3 on Mon Jan 30 21:18:23 2006

,new eventItem("Weekly Prayer", "Union-Ice Cream Shoppe", 2, 10, 12, 30, 2006, 2, 10, 0, 1, 2006, 9, "Need some accountability, prayer, or a hug?  Then come join in prayer with friends!  God will work, it'll be exciting!")	//Submitted by rachel3 on Mon Jan 30 21:20:02 2006

,new eventItem("Weekly Prayer", "Union-Ice Cream Shoppe", 2, 16, 8, 30, 2006, 2, 16, 0, 1, 2006, 9, "Come pray with us!")	//Submitted by rachel3 on Mon Jan 30 21:21:25 2006

,new eventItem("Weekly Prayer", "Union-Ice Cream Shoppe", 2, 17, 12, 30, 2006, 2, 17, 0, 1, 2006, 9, "Come pray with us!!")	//Submitted by rachel3 on Mon Jan 30 21:22:00 2006

,new eventItem("Weekly Prayer", "Union-Ice Cream Shoppe", 2, 23, 8, 30, 2006, 2, 23, 0, 1, 2006, 9, "Come pray with us!  It's a blast, and stretching, but in a good way. ")	//Submitted by rachel3 on Mon Jan 30 21:23:20 2006

,new eventItem("Weekly Prayer", "Union-Ice Cream shoppe", 2, 24, 12, 30, 2006, 2, 24, 0, 1, 2006, 9, "God craves you're prayers! Don't hold back today, come join us in fellowship and prayer!")	//Submitted by rachel3 on Mon Jan 30 21:24:24 2006

,new eventItem("Story of the Soul", "International Student Center", 2, 12, 18, 30, 2006, 2, 12, 0, 1, 2006, 22, "Discussion topic- Guilt")	//Submitted by gmk703 on Thu Feb  9 15:05:00 2006

,new eventItem("Swing Dance!", "Union Station", 2, 24, 19, 0, 2006, 2, 24, 21, 30, 2006, 2, "Come swing dance with your friends")
	//Submitted by kstiles on Mon Feb 13 16:02:02 2006

,new eventItem("Dodgeball", "Basketball courts by Kramer", 3, 3, 17, 0, 2006, 3, 3, 0, 1, 2006, 22, "If you can dodge a wrench, you can dodge a ball")	//Submitted by kstiles on Mon Feb 13 16:03:50 2006

,new eventItem("Evangelism Training", "Grace Baptist Church", 2, 18, 8, 45, 2006, 2, 18, 12, 0, 2006, 2, "Come Learn about God's heart for evangelism")
	//Submitted by ckipple on Mon Feb 13 22:33:20 2006

,new eventItem("H.I.S. Annual Spring Friendship Banquet", "Pottorf Hall, CiCo Park (west on Kimbal Ave, left on Avery Ave., follow the signs)", 3, 11, 18, 0, 2006, 3, 11, 20, 30, 2006, 2, "Banquet (provided by area churches), international music (Japanese Yosakoi Dance Club), and guest speaker (Georges Boujakly from Lebanon - shares his testimony).  No charge.  Bring an international friend!")
	//Submitted by stucken on Wed Feb 15 15:14:18 2006

,new eventItem("Weekly Meeting", "Union Little Theatre", 2, 23, 20, 0, 2006, 2, 23, 0, 1, 2006, 23, "Come worship with us!")	//Submitted by ckipple on Mon Feb 20 13:21:25 2006

,new eventItem("Photo Scavenger Hunt", "Meet in North Food Court area", 3, 9, 0, 1, 2006, 3, 9, 0, 1, 2006, 24, "Please bring your digital cameras to the meeting")	//Submitted by kstiles on Mon Feb 27 23:23:25 2006

,new eventItem("Women's Retreat", "Grace Baptist Church", 3, 10, 18, 30, 2006, 3, 11, 12, 0, 2006, 2, "")
	//Submitted by gmk703 on Tue Feb 28 22:27:20 2006

,new eventItem("Weekly Prayer", " Union-Ice Cream Shop", 3, 9, 8, 30, 2006, 3, 9, 0, 1, 2006, 9, "Prayer is GRAND!! come see...")	//Submitted by rachel3 on Mon Mar  6 21:17:45 2006

,new eventItem("Weekly Prayer", "Union-Ice Cream Shop", 3, 10, 12, 30, 2006, 3, 10, 0, 1, 2006, 9, "Prayer is FANTASTIC....come see it again!")	//Submitted by rachel3 on Mon Mar  6 21:18:58 2006

,new eventItem("Weekly Prayer", "Union-Ice Cream Shop", 3, 16, 8, 30, 2006, 3, 16, 0, 1, 2006, 9, "Fun times in prayer, a challenge to wake up, but worth it.")	//Submitted by rachel3 on Mon Mar  6 21:19:56 2006

,new eventItem("Weekly Prayer", " Union-Ice Cream Shop", 3, 17, 12, 30, 2006, 3, 17, 0, 1, 2006, 9, "Happy St. Patrick's day prayer funness.")	//Submitted by rachel3 on Mon Mar  6 21:20:54 2006

,new eventItem("Weekly Prayer", "Union-Ice Cream Shop", 3, 30, 8, 30, 2006, 3, 30, 0, 1, 2006, 9, "Back to school, back to prayer")	//Submitted by rachel3 on Mon Mar  6 21:21:44 2006

,new eventItem("Weekly Prayer", "Union-Ice Cream Shop", 3, 31, 12, 30, 2006, 3, 31, 0, 1, 2006, 9, "Prayer=good, that's good math")	//Submitted by rachel3 on Mon Mar  6 21:22:41 2006

,new eventItem("Sunrise Prayer", "Top of the World- directions will be emailed...", 3, 16, 6, 15, 2006, 3, 16, 0, 1, 2006, 9, "Wake up real early and see and feel the glory of God, embrace Him in prayer!")	//Submitted by rachel3 on Mon Mar  6 21:25:24 2006

,new eventItem("Prayer Walk", "Meet in Union Courtyard", 4, 7, 18, 30, 2006, 4, 7, 0, 1, 2006, 21, "Walk the campus and pray for buildings, departments, students, professors, etc...pray for your campus.")	//Submitted by rachel3 on Mon Mar  6 21:28:03 2006

,new eventItem("Sunrise Prayer (Round 2)", "Top of the World - directions will be emailed out", 4, 22, 0, 1, 2006, 4, 22, 0, 1, 2006, 9, "Rise and shine! It's Earth day, and thus, a great morning to wake up and praise God for everything beneath our feet...and above our heads, etc..!")	//Submitted by rachel3 on Mon Mar  6 21:29:56 2006

,new eventItem("Jesus Film ", "Bluemount", 4, 9, 15, 0, 2006, 4, 9, 0, 1, 2006, 20, "")	//Submitted by gmk703 on Tue Mar 14 14:34:00 2006

,new eventItem("Weekly Meeting", "Union Little Theatre", 3, 30, 20, 0, 2006, 3, 30, 0, 1, 2006, 23, "Come join us!")	//Submitted by ckipple on Thu Mar 30 15:42:59 2006

,new eventItem("Weekly Prayer", "Union-Ice Cream Shop", 4, 6, 8, 30, 2006, 4, 6, 0, 1, 2006, 9, "Good times...")	//Submitted by rachel3 on Sat Apr  1 17:09:09 2006

,new eventItem("Weekly Prayer", "Union-Ice Cream Shop", 4, 7, 12, 30, 2006, 4, 7, 0, 1, 2006, 9, "Does God feel far away right now?  Well, He's there, so open your ears, your mouth, and your heart.")	//Submitted by rachel3 on Sat Apr  1 17:10:41 2006

,new eventItem("Weekly Prayer", "Union-Ice Cream Shop", 4, 13, 8, 30, 2006, 4, 13, 0, 1, 2006, 9, "Come pray with us!")	//Submitted by rachel3 on Sat Apr  1 17:11:24 2006

,new eventItem("Weekly Prayer", "Union-Ice Cream Shop", 4, 14, 12, 30, 2006, 4, 14, 0, 1, 2006, 9, "Come join in fellowship and prayer! yipee!")	//Submitted by rachel3 on Sat Apr  1 17:12:40 2006

,new eventItem("Weekly Prayer", "Union-Ice Cream Shop", 4, 20, 8, 30, 2006, 4, 20, 0, 1, 2006, 9, "Come pray with us, it rocks, and God likes to talk and listen, because He's wonderful...and perfect....and really awesome.  ")	//Submitted by rachel3 on Sat Apr  1 17:13:49 2006

,new eventItem("Weekly Prayer", "Union-Ice Cream Shop", 4, 21, 12, 30, 2006, 4, 21, 0, 1, 2006, 9, "Come pray with us!")	//Submitted by rachel3 on Sat Apr  1 17:14:34 2006

,new eventItem("Weekly Prayer", "Union-Ice Cream Shop", 4, 27, 8, 30, 2006, 4, 27, 0, 1, 2006, 9, "Come pray with us!")	//Submitted by rachel3 on Sat Apr  1 17:15:23 2006

,new eventItem("Weekly Prayer", "Union-Ice Cream Shop", 4, 28, 12, 30, 2006, 4, 28, 0, 1, 2006, 9, "Feel the spiritual ache-y-ness?  Try talking with God, He's there 24/7 and He loves you.")	//Submitted by rachel3 on Sat Apr  1 17:16:59 2006

,new eventItem("Weekly Meeting", "Union Little Theatre", 4, 6, 20, 0, 2006, 4, 6, 0, 1, 2006, 22, "Come worship with us!")	//Submitted by ckipple on Sun Apr  2 21:39:37 2006

,new eventItem("Cru", "Union Ballroom", 5, 4, 20, 0, 2006, 5, 4, 0, 1, 2006, 23, "Our last Cru meeting and Senior send-off")	//Submitted by ckipple on Sat Apr 29 03:13:42 2006

,new eventItem("Cru Weekly Meeting", "Union Little Theatre", 8, 24, 20, 0, 2006, 8, 24, 0, 1, 2006, 23, "Come join all of us at our weekly meeting.")	//Submitted by ckipple on Sat Aug 19 17:26:45 2006

,new eventItem("Cru Afternight", "Scavenger Hunt", 4, 1, 21, 30, 2006, 4, 1, 22, 30, 2006, 2, "Come join us for fun after our first Cru meeting")
	//Submitted by ckipple on Sat Aug 19 17:28:02 2006

,new eventItem("M 4:12", "TBA", 8, 27, 16, 0, 2006, 8, 27, 18, 0, 2006, 2, "Leaders Meeting")
	//Submitted by ckipple on Sat Aug 19 17:30:40 2006

,new eventItem("Party in the Park", "City Park", 8, 26, 15, 0, 2006, 8, 26, 19, 0, 2006, 2, "Freshment--come hang with us!")
	//Submitted by ckipple on Sat Aug 19 17:32:07 2006

,new eventItem("Cru Afternight", "Scavenger Hunt", 8, 24, 21, 30, 2006, 8, 24, 0, 1, 2006, 25, "Come have fun with us after Cru")	//Submitted by ckipple on Thu Aug 24 09:17:42 2006

,new eventItem("Prayer Meeting", "Union 203", 9, 1, 12, 30, 2006, 9, 1, 0, 1, 2006, 9, "Join in some mighty fine prayer with a mighty fine God.  ")	//Submitted by rachel3 on Mon Aug 28 17:01:46 2006

,new eventItem("Prayer Meeting", "Union 206", 9, 5, 16, 30, 2006, 9, 5, 0, 1, 2006, 9, "Prayer is fun, you should come")	//Submitted by rachel3 on Mon Aug 28 17:03:49 2006

,new eventItem("Cru", "Union Little Theatre", 8, 23, 20, 0, 2007, 8, 23, 0, 1, 2007, 23, "Come Join us!!")	//Submitted by ckipple on Thu Aug 16 20:25:18 2007

,new eventItem("Fall Getaway--Refresh", "Salina, KS", 9, 28, 18, 30, 2007, 9, 30, 12, 0, 2007, 2, "Come Join us in a time of refreshing")
	//Submitted by ckipple on Thu Aug 16 20:28:14 2007

,new eventItem("FSK Assembly Party", "Coorts' House", 8, 19, 16, 0, 2007, 8, 19, 0, 1, 2007, 20, "Come catch up with friends while we assembly FSKs")	//Submitted by ckipple on Thu Aug 16 20:31:10 2007

,new eventItem("Cru", "Union Little Theatre", 8, 30, 20, 0, 2007, 8, 30, 0, 1, 2007, 23, "Come Join us in worship and fellowship")	//Submitted by admin on Thu Aug 16 20:35:41 2007

);
return information;
}
