//This the version running as of 3/26/2010
//Modify schedule format using new displayCourse() routine renamed old routine displayCourseOld()

var n=0;
months=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
//define functions
function setSubject(){
	var Name;
	var Subject;
	Name=document.forms.Form10.elements['name'].value;
	Subject=Name+ " : Registration/Information Form";
	document.forms.Form10.elements['subject'].value=Subject;
}
function BuildMonthlySchedule(){
	schId = "divS"+whichMonth;
	formId="form"+whichMonth;
	tableId="table"+whichMonth;
	scheduleTitle="Essential Holistics Calendar for "+months[whichMonth]+" 2011";
	//generate html
	line0="<div name='"+ schId +"' id='"+schId+"' style='visibility:hidden;position:absolute;top:185px;height:420px;overflow:auto;left:400px;width:625px;'>";
	line1="<form name='"+ formId +"' id='"+formId+"' style='background-color:azure;border:1px solid black;width:600px;'>";
	line2="<table id='tableId' style='border:2px solid black;width:600px;font-size:11px;'><thead><tr><th colspan=3>" + scheduleTitle + "</th>";

	var calendar=calendars[whichMonth];
	if (calendar=="n/a"){
		line3="</tr>";
	}else
	{
		line3=	"<th colspan=3> <a href='http://www.essentialHolistics.com/files/" +calendar+ "' target='_blank'>Download Calender</a></th></tr>";
	}
	line4="<th>Date/Time</th><th>Title/Practitioner</th><th>Venue/Contact</th><th>Amount/Comment</th><th>Select</th></tr></thead><tbody>";
	
	document.write(line0,line1,line2,line3,line4);
	
	//display courses scheduled for this month
	var nc=nl[whichMonth];
	var i;
	for (i=0;i<nc;i++){
		courseList[whichMonth][i].displayCourse(i);
	}
	//Finish this months schedule
	document.write("</table></form></div>");

}
function getDirections(venue){
	var directions = "";
/*
        if (venue == "Groh Well Health Center, Merrick")
	{
		directions="http://maps.yahoo.com/py/maps.py?Pyt=Tmap&addr=389 Merrick Avenue&csz=Merrick, NY 11566190&Get+Map=Get+Map"
	}
	if (venue == "Om Sweet Om Yoga, Pt. Washington")
	{
		directions="http://maps.yahoo.com/py/maps.py?Pyt=Tmap&addr=37 Avenue A&csz=Port Washington, NY 11050&Get+Map=Get+Map"
	}
	if (venue == "Yoga For Life,Setauket")
	{
		directions="http://maps.yahoo.com/py/maps.py?Pyt=Tmap&addr=190 N Belle Meade Road&csz=Setauket, NY 11733&Get+Map=Get+Map"
	}
	if (venue == "Manorville Center")
	{
		directions="http://maps.yahoo.com/py/maps.py?Pyt=Tmap&addr=1 Marilyn Street&csz=Manorville, NY 11949&Get+Map=Get+Map"
	}
	if (venue == "TRS Professional Suites NY,NY")
	{
		directions="http://maps.yahoo.com/py/maps.py?Pyt=Tmap&addr=44 East 32nd Street&csz=New York, NY 10016-5508&Get+Map=Get+Map"
	}
	if (venue == "The Center for Self Growth")
	{
		directions="http://www.thecenterforselfgrowth.com/contact.htm"
	}
	if (venue == "Edgar Cayce's ARE NYC")
	{
		directions="http://maps.yahoo.com/py/maps.py?Pyt=Tmap&addr=241 West 30th Street&csz=New York, NY 10001&Get+Map=Get+Map"
	}
*/
	return directions;
}

function displayCourse(i){
	cbName="cb"+whichMonth+i;
	var title;
	var direct;
        var directions;
        if(this.hyperlink == ""){
		title=this.title;
	}
	else
	{
		var ext=this.hyperlink.substring(this.hyperlink.indexOf(".")+1,this.hyperlink.length);
		if (ext=="html"){
			title= "<a href='http://www.essentialHolistics.com/" + this.hyperlink + "' target='_blank'>" + this.title + "</a>";
		}
		else
		{
			title= "<a href='http://www.essentialHolistics.com/files/" + this.hyperlink + "' target='_blank'>" + this.title + "</a>";
		}
	}
	directions=getDirections(this.venue);
	if (directions == "")
        {
                direct = "";
        }
        else
        {
                direct="<a href='" + directions + "' target='_blank'>" + this.venue + "</a>";
        }
	now=new Date();
	today=now.getDate();
	var cColor=this.color;
	var comment=this.comment;
	if(this.comment==""){	
		cColor=this.bcolor;
		comment="--------------";
	}
	line1="<tr style='text-align:center;background-color:"+this.bcolor+";'>"+
		"<td style='border:2px solid black;color:" +this.color+ ";'>"+ this.date +"</td>"+
		"<td style='border:2px solid black;color:" +this.color+ ";'>"+title +"     </td>"+
		"<td style='border:2px solid black;color:" +this.color+ ";'>"+direct +"    </td>"+
		"<td style='border:2px solid black;color:" +this.color+ ";'>"+this.amount+"</td>";

	if(this.ctype=="OnGoing" || this.ctype=="Comment")
	{
	   	if(this.ctype=="OnGoing")
		{
			line2="<td style='background-color:azure'>"+
	        	"<input style='margin-left:12px;' id='" + cbName + "' type='checkbox' unchecked onClick='checkState();'>"+
                	"</td></tr>";
		}
		else
		{
	   		line2="<td style='background-color:azure'>"+
                  	"<input style='visibility:hidden;margin-left:12px;' id='" + cbName + "' type='checkbox' unchecked onClick='checkState();'>"+
                  	"</td></tr>";
		}
	}
	else
	{
		if((whichMonth==now.getMonth() && parseInt(this.date.substring(7,10)) >= today) || (whichMonth > now.getMonth()) )
		{	
	   		line2="<td style='background-color:azure'>"+
	         	"<input style='margin-left:12px;' id='" + cbName + "' type='checkbox' unchecked onClick='checkState();'>"+
                 	"</td></tr>";
		}
		else
		{
	   		line2="<td style='background-color:azure'>"+
                  	"<input style='visibility:hidden;margin-left:12px;' id='" + cbName + "' type='checkbox' unchecked onClick='checkState();'>"+
                  	"</td></tr>";
		}
	}
	line3="<tr style='text-align:center;background-color:"+this.bcolor+";'>"+
		"<td style='border:2px solid black;color:"+this.color+";'>"+ this.time + "     </td>"+
		"<td style='border:2px solid black;color:"+this.color+";'>"+this.practitioner+"</td>"+
		"<td style='border:2px solid black;color:"+this.color+";'>"+this.contact+"     </td>"+
		"<td colspan=2 style='border:2px solid black;color:"+cColor+";'>"+comment+"    </td></tr>";
	document.write(line1,line2,line3);
}

function course(code,title,practitioner,venue,date,time,comment,amount,contact,hyperlink,ctype) {
   n++;
   this.code=code;
   this.title = title;
   this.practitioner = practitioner;
   this.venue = venue;
   this.date = date;
   this.time = time;
   this.comment=comment;
   this.amount = amount;
   this.contact=contact;
   this.hyperlink=hyperlink;
 
   this.color="black";
   if(mod(n)!=0){
	this.bcolor="lightblue";
   }
   else
   {
   	this.bcolor="pink"
   }   
   this.ctype = ctype;
   if(ctype=="OnGoing"){
	this.bcolor="white";
   }
   this.displayCourse = displayCourse;   
}
function showMonth(){
	//show present month on contact form
	newMonth=document.forms.Form10.elements['monthList'].selectedIndex;
	var schId = "divS" + whichMonth;
	
	//hide old schedule
	var divs = document.getElementById(schId);
	divs.style.visibility = "hidden";
	
	//show new schedule
	var schId = "divS" + newMonth;
	var divs = document.getElementById(schId);
	divs.style.visibility = "visible";

	//set which month
	whichMonth = newMonth;

	//change link for download on contact form
	divf=document.getElementById("contactDwnLoad");
	divf.innerHTML="";
	var calendar=calendars[whichMonth];
	if (calendar!="n/a"){
		divf.innerHTML="<a href='http://www.essentialHolistics.com/files/" +calendar+ "' target='_blank'>DOWNLOAD SCHEDULE</a>";
	}
}
function mod(x){
	var y=Math.floor(x/2)*2;
	if ((y-x)==0){return(0);} else {return(1);}
}
function displaySchedule(){
	var i;
	for (i=0;i<12;i++){
		whichMonth=i;
		BuildMonthlySchedule();
	}
	//show sched for this month
	now = new Date();
	whichMonth = now.getMonth();
	document.forms.Form10.elements['monthList'].value=whichMonth+1;
	var schId = "divS" + whichMonth;
	var divs = document.getElementById(schId);
	divs.style.visibility="visible";

	divf=document.getElementById("contactDwnLoad");
	divf.innerHTML="";
	var calendar=calendars[whichMonth];
	if (calendar!="n/a"){
		divf.innerHTML="<a href='http://www.essentialHolistics.com/files/" +calendar+ "' target='_blank'>Download Calender</a>";
	}
	
}
function checkState(){
	var crlf=String.fromCharCode(11)+String.fromCharCode(10);
	var message=" ";
	var k=0;
	var selected=0;
	var nc = nl[whichMonth];
	for (i=0;i<nc;i++){
		cbid="cb"+whichMonth+i;
		if(document.getElementById(cbid).checked){
			if(k == 0)message="I am interested and would like to register or get more information on the following:"+crlf;
			k++;
			message= message + "   "+courseList[whichMonth][i].code + "-" +courseList[whichMonth][i].title + " given/starting on " + courseList[whichMonth][i].date + " @ " + courseList[whichMonth][i].time+crlf;
	    	}
	}
	document.forms.Form10.elements['comments'].value=message;
}
function clearSelections(){
	var nc = nl[whichMonth];
	for (i=0;i<nc;i++){
		cbid="cb"+whichMonth+i;
		document.getElementById(cbid).checked=false;
	}
	document.forms.Form10.elements['comments'].value='';
}

var newwin;
function printScheduleX(){
   schId = "divS"+whichMonth;
   str=document.getElementById(schId).innerHTML;
   newwin=window.open('','printwin','left=100,top=100,scrollbars=yes,width=600,height=600')
   newwin.document.open();
   newwin.document.write('<html><head><style type="text/css">p{text-align:center;font-weight:600;}body{padding:20px;background-color:#ffffff;font-family:verdana,tahoma,sans-serif;font-size:10pt;}ul{margin-top:30px;}</style></head>');
   newwin.document.write('<title>Print Page</title>\n')
   newwin.document.write('</HEAD>\n')
   newwin.document.write('<BODY>\n')
   newwin.document.write(str)
   newwin.document.write('<hr />');
   newwin.document.write('<input type="button" value="Close" onClick="window.close();">')
   newwin.document.close();
   newwin.print();
}
