// common functions for 60-270 second project
// has to be loaded first

var cookieSetup  = "alj270_setup";   // initial 'a' puts the cookie at the top in a alpha sort, lj is my initials

function cookieSet(cName, val, days) { // typicaly I will use 7 or 14 days for this project  
  if (parseInt(days)) {                // 0 will set a temporary cookie          
    var date = new Date();
    date.setTime(date.getTime() + (days * 86400000));  // seconds in a day
    var expireDate = "; expires=" + date.toGMTString();
  }
  else var expireDate = "";
  document.cookie = cName + "=" + val + expireDate + "; path=/";
}

function cookieGet(cName) {
  var results = document.cookie.match (cName + '=(.*?)(;|$)' );  // shades of regular expression searches
  return results ? results[1] : null;
}

//function cookieDel (cName) {
//  document.cookie = cName + "=del;expires=Mon, 01-Jan-2000 00:00:00 GMT";
//}

//function cookieDel(cName) {
//  createCookie(cName,"",-1);
//}


function setUp() {
  var colour = 'blue-on-yelow';     // the defaults if no cookie is found
  var hStyle = 'sans';	
	var bStyle  = 'serif';
	
  var str = cookieGet(cookieSetup);   
	if (str) { 
		var ar = new Array();
    ar = str.split(':');
	  colour = ar[0];
    hStyle = ar[1];	
	  bStyle  = ar[2];
	} 
	document.writeln("<link rel=\"stylesheet\"  href=\"css/" + colour + ".css\"      type=\"text/css\" title=\"prefered\" />");
	document.writeln("<link rel=\"stylesheet\"  href=\"css/head-" + hStyle + ".css\" type=\"text/css\" title=\"prefered\" />");
	document.writeln("<link rel=\"stylesheet\"  href=\"css/body-" + bStyle + ".css\" type=\"text/css\" title=\"prefered\" />");
}		

function pad(i) {  // add leading 0 if missing iin a date string   used by record-1 .. 5 
  var str = (i < 10) ? "0" + i : i;
  return "" + str;
}


function getDateStr() {
  var d = new Date();  //  get time as 6 char str hhmmss
  var str = pad(d.getHours()) + pad(d.getMinutes()) + pad(d.getSeconds()); 
  
  return str;
}
