var lr = "right"
var mydate= new Date();
var DOM = mydate.getDate();
var M = mydate.getMonth();
M++;
var DOW= mydate.getDay();
//Monday=1
var monthNames = new Array(
     "January",
     "February",
     "March",
     "April",
     "May",
     "June",
     "July",
     "August",
     "September",
     "October",
     "November",
     "December"
)
var cookieKey = "calendarEmail";

function checkOn(boxObj, title, venue, timeString, cost, dateString, CalendarID)
{
     // get state of checkbox
     var askForAddress = true;
     var checkstate = boxObj.checked;

     // read cookie
     theCookie = document.cookie;

     // if no e-mail, ask for it
     if (theCookie.length >0 && theCookie.indexOf(cookieKey) >= 0) {
          i = theCookie.indexOf(cookieKey)
          i += cookieKey.length +1
          j = theCookie.indexOf(";",i-1)
          if (j>1) { len = j-i } else { len = 1000 }
          calendarEmail = theCookie.substr(i,len)
          if (calendarEmail != "") {
               askForAddress = false;
          }
     }
     // if e-mail set, open window with URL
     if (askForAddress) {
          calendarEmail = prompt ("Movie Habit can send you an e-mail reminder the day of the show for any event on this calendar. Please enter your e-mail address",''     )

          if (calendarEmail == "" || calendarEmail==null) {
               boxObj.checked=false;
               return false;
          } else {
		  }
          // expiration for cookie
          var mydate = new Date();
          var mon = mydate.getMonth();
          mon ++;
          var DOW = mydate.getDate();
          var yr = mydate.getYear();
          if (yr<1900){
               yr += 1900;
          }
          yr ++;
          var expire = mon + "/" + DOW + "/" + yr;
          expireObj = new Date(expire)
          expire = expireObj.toGMTString();
          document.cookie = cookieKey + "=" + calendarEmail+ ";expires="+expire;

     }

     // open window with the url
     var popurl="http://www.moviehabit.com/calendar/setreminder.php"
     popurl += "?title=" + escape (title);
     popurl += "&venue=" + escape (venue);
     popurl += "&timestring=" + escape (timeString);
     popurl += "&coststring=" + escape (cost);
     popurl += "&email=" + escape(calendarEmail);
     popurl += "&datestring=" + escape(dateString);
     popurl += "&adding=" + checkstate;
	 popurl += "&checkid=" + boxObj.name;
	 popurl += "&CalendarID=" + CalendarID;

winpops=window.open(popurl,"moviehabitpop","width=100,height=100,scrollbars,resizable,")
//     winpops.focus();
}

function initialize() {

	var calendarEmail = "";
	// read cookie
	theCookie = document.cookie;

	// if no e-mail, ask for it
	if (theCookie.length >0 && theCookie.indexOf(cookieKey) >= 0) {
    	 i = theCookie.indexOf(cookieKey)
	     i += cookieKey.length +1
	     j = theCookie.indexOf(";",i-1)
	     if (j>1) { len = j-i } else { len = 1000 }
	     calendarEmail = theCookie.substr(i,len)
	}

	if (calendarEmail != "" ) {

	     var popurl="http://www.moviehabit.com/calendar/getreminders.php"
	     popurl += "?email=" + escape(calendarEmail);

		winpops=window.open(popurl,"moviehabitpop","width=100,height=100,scrollbars,resizable,")

	}
}
function setCheck(idString) {
	eval ("document.form1." + idString + ".checked = true");
}
