/* cookie.js
 * Sets and reads cookies in Javascript
 * 
 * Source:
 * http://www.quirksmode.org/js/cookies.html
 * License:
 * http://www.quirksmode.org/about/copyright.html
 * 
 */

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

/* This original function (obviously) did not come from the above source.
 * 
 * It calls functions that are found in load.js (which should have
 * been loaded prior to this file.)
 */

function getSchedule(containerid) {
	var day = readCookie('1224lecture');
	if (day == 'Monday' || day == 'Tuesday' || day == 'Wednesday' || day == 'Thursday')
		{loadcal('pages/schedules-'+day+'.html',containerid,'Schedules&#8211;'+day);
/* CHANGEME (only for testing): 
 * 
 * The four numbers in the parentheses are the starting and ending
 * days of the semester, in the format:
 * 			starting month, starting day, ending month, ending day
 * 
 * Example:  
 * 
 * Fall 2009:   calendar(8, 24, 12, 14, day);  
 *
 *		 calendar(8, 24, 12, 14, day);
 */ 
		} 
	else
	 	{load('pages/schedules.html',containerid,'Schedules');} 
}

/* Function get_param
 * 
 * Source: http://www.netlobo.com/url_query_string_javascript.html
 *  
 */

function get_param ( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

/* original function
 */

function indexOnload ()
{
	var page=get_param("page");
	/* We're doing this the long way to 
	 * whitelist good pages instead of just passing
	 * whatever data comes through without checking
	 * it.
	 */
	switch (page)
	{
		case 'contract':
			load('pages/contract.html','content','Course Contract');
			break;
		case 'schedule':
			load('pages/schedule.html','content','Schedule');
			break;
		case 'contact':
			load('pages/contact.html','content','Contact Heath');
			break;
		case 'documents':
			load('pages/documents.html','content','Course Documents');
			break;
		case 'assignments':
			load('pages/assignments.html','content','Assignments Guide');
			break;
		default:
			document.getElementById('subheader').innerHTML='Course Homepage';
			break;
	}	
}		
			
