/* dfunctn.js
	This JavaScript file holds diary runctions */
	
var D_date, ColInd, popWin;					// Global Variables
var Cl_Def = new Array("dleftU","dleftU","dhol","dWend");
var DayArray = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
var monarray = new Array ("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
function DEvents(EDate,ColInd,Desc,DTitle,FDesc)
   {
	this.EDate = new Date(EDate.split("/")[2],EDate.split("/")[1]-1,EDate.split("/")[0]);
//	this.ColInd = ColInd;
	if (ColInd)
	   {this.ColInd = ColInd}
	else
	   {this.ColInd=DefActCol}
	this.Desc = Desc;
	this.DTitle  = DTitle;
	this.FDesc= FDesc;
	return;
   }

function NiceDate(N_Date)
   {
	
	return DayArray[N_Date.getDay()]+", "+N_Date.getDate()+" "+monarray[N_Date.getMonth()]+", "+N_Date.getFullYear();
   }

function CreateMonth()
   {

	if (Math.floor(D_date)==Math.floor(EventList[i].EDate))
	   {
//		document.write('<td class="'+Cl_Def[EventList[i].ColInd]+'">');
		document.write('<td class=dleftU bgcolor="'+EventList[i].ColInd+'">');
		if (EventList[i].DTitle || EventList[i].FDesc)
		   {
		    document.write('<A class="nul" HREF="" TITLE="');
		    document.write(EventList[i].DTitle+'"');
		    if (EventList[i].FDesc)
		   	{
			pict="";
			popParams="'"+EventList[i].FDesc+"','"+pict+"','"+D_date.getDay()+"','"+D_date+"'";
			document.write('onClick="popWindow('+popParams+');return false"');
		   	}
			else
		   	{ document.write('onClick="return false";') 
		   	}
		    document.write('>'+D_date.getDate()+'<BR>'+EventList[i].Desc+'</A>');
		   }
		else
			{ document.write(EventList[i].DTitle+D_date.getDate()+'<BR>'+EventList[i].Desc);
			}
		document.write('</td>');
//		ColInd=EventList[i].ColInd;
		i++;
	   }
	 else if (D_date.getDay()==0 || D_date.getDay()==6)
	   {	document.write('<td class="dwend" bgcolor='+wendcol+'>'+D_date.getDate()+'</td>');   }
//	 else if (ColInd)
//	   {	document.write('<td class="dhol">'+D_date.getDate()+'</td>');    }
	 else
	   {	document.write('<td class="dleft" bgcolor='+defcol+'>'+D_date.getDate()+'</td>');   }

	if (D_date.getDay()==6)
	   {
		document.write('</tr>');
	   }

	D_date.setDate(D_date.getDate()+1);

	if (D_date.getDate()!=1 && D_date.getDay()==0)
	   {
		document.write('<tr height="60">');
	   }
	if (D_date.getDate()!=1) { CreateMonth(); } 	// loop around to output month
   }
   

function CreateDiary()
   {
	var end_date = new Date(end_year,end_month,1);
	var monthsArray = new Array ("JANUARY","FEBRUARY","MARCH","APRIL","MAY","JUNE","JULY","AUGUST","SEPTEMBER","OCTOBER","NOVEMBER","DECEMBER");
	var i1, pict, popParams;
	var today = new Date();
	
//	D_date = new Date(start_year,start_month-1,1);
	D_date = new Date(today.getFullYear(),today.getMonth(),1);
	i=0;

	while (D_date > EventList[i].EDate)	    // this ensures there are no events before
	   {	i++;   }			    // the start date

	while (D_date < end_date)		    // loop around until end date
	 {
	  document.write('<tr height="60" id='+D_date.getFullYear()+D_date.getMonth()+'>');
	  if (diarylist)
	     {  document.write('<td class="diarytop"><a href='+diarylist+' title="Printer friendly copy" target=prt><img border=0 src=../images/printf.gif></a></td>'); }
	  else
	     {  document.write('<td class="diarytop">&nbsp</td>');   }
	  document.write('<td colspan="5" class="diarytop"><b>');
	  document.write(monthsArray[D_date.getMonth()]+' '+D_date.getFullYear());
	  document.write('</b><BR><Span style="font-size:75%">Point your mouse at a highlighted day for any extra information</Span>');
	  document.write('</b></td><td class="diarytop"><b><a href="#'+today.getFullYear()+today.getMonth()+'" class="today">Jump to Current Month</a></b></td></tr>');
	  document.write('<tr height="50"><td width="14%" class="dleft" bgcolor='+defcol+'><b>Sunday</b></td><td width="14%" class="dleft" bgcolor='+defcol+'><p><b>Monday</b></p></td><td width="14%" class="dleft" bgcolor='+defcol+'><b>Tuesday</b></td><td width="14%" class="dleft" bgcolor='+defcol+'><b>Wednesday</b></td><td width="14%" class="dleft" bgcolor='+defcol+'><b>Thursday</b></td><td width="14%" class="dleft" bgcolor='+defcol+'><b>Friday</b></td><td width="14%" class="dleft" bgcolor='+defcol+'><b>Saturday</b></td></tr><tr height="60">');

	  i1=0; 

	  while (D_date.getDate()==1 && i1<D_date.getDay())
	   {					    // Write null date lines at start of month
		document.write('<td class="dleft" bgcolor='+defcol+'>&nbsp;</td>');
		i1++;
	   }

	CreateMonth();  


	if (D_date.getDay()!=0)			    // Write null date lines at end of month
	   {
		for (i1=D_date.getDay(); i1<7; i1++)
		   {
			document.write('<td class="dleft" bgcolor='+defcol+'>&nbsp;</td>');
		   }
	   }

	 }					    // Loop back until date equals end date
    }
 
function popWindow(Details,Picture,Day,I_Date)
   {

	if (Day>2)
 	  { 
	 popWin=window.open("","p1","width=400,height=500,left=20,top=20,screenX=20,screenY=20,scrollbars");
	  }
 	else
 	  { 
       popWin=window.open("","p1","width=400,height=500,left=380,top=20,screenX=380,screenY=20,scrollbars");
	  }

 	popWin.document.write("<HTML><HEAD><TITLE>Event Details</TITLE></HEAD>");
 	popWin.document.write("<BODY BGCOLOR='lightyellow' TEXT='darkblue'>");
 	if (Picture != "")
 	  { popWin.document.write("<IMG SRC="+Picture+" ALIGN=right>");}
 	popWin.document.write("<FONT FACE='arial'>");
	popWin.document.write("<B>"+NiceDate(new Date(I_Date)));
	popWin.document.write("<BR><BR></B></FONT>");
 	popWin.document.write("<FONT FACE='comic sans ms'>");
 	popWin.document.write(Details);
	popWin.document.write("<P><A HREF='' onClick='window.close();return false'><IMG SRC=../images/closebutton.gif ALIGN=right></A></P>");
 	popWin.document.write("</FONT></BODY></HTML>");
	popWin.document.close();
	popWin.focus();
 	return;
   }