//Deadline is the last day that anyone can register for the class.
//Deadline format is mm-dd-yyyy
function enroll(deadline, classurl){
	var ptwzenlogin = getCookie('ptwzenlogin');
  var arr = new Array();
  arr = deadline.split('-');

  var endDate = new Date();
  endDate.setDate(arr[1]);
  endDate.setMonth(parseInt(arr[0], 10)-1);
  endDate.setFullYear(arr[2]);

  var today = new Date();

  if(endDate >= today){
		if(ptwzenlogin == 'true'){
    	window.location = classurl;
		}else{
			setCookie('ptwzenredirect', classurl, '', '/', 'www.picturetheweb.com');
			window.location = 'https://www.picturetheweb.com/ptw/store/index.php?main_page=login';
		}
  }else{
    alert("The deadline to enroll in this class was " + endDate.toDateString() +".");
  }

}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}

function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

