//*******************************************************************************
//*       CREATE CALENDAR UTILITY - VERSION 2.5.18 - June 20, 2003              *
//*       HTTP://CCUWEB.OMNI-TS.COM                                             *
//*******************************************************************************

// ********* creating today's date hyperlink ************************************

function todaysDate(sd1,sd2,sd3,sep,loc,arr,ext)
	{
	today= new Date();
	month = today.getMonth();
	month = month + 1;
	year = today.getFullYear();
	day = today.getDate();
	
	var shortdate1 = returndateformat(sd1,arr);
	var shortdate2 = returndateformat(sd2,arr);
	var shortdate3 = returndateformat(sd3,arr);

	if (month < 10)
		{
		HyperLinkText = ("<a class=Arrow href=\"../" + loc + "/" + year + "_0" + month + ext + "\">" +shortdate1+sep+shortdate2+sep+shortdate3+"</a>");
		}
	else
		{
		HyperLinkText = ("<a class=Arrow href=\"../" + loc + "/" + year + "_" + month + ext + "\">" +shortdate1+sep+shortdate2+sep+shortdate3+"</a>");
		}

	document.write(HyperLinkText);
	}

function returndateformat(sd,arr)
	{

	today= new Date();
	month = today.getMonth();
	month = month + 1;
	year = today.getFullYear();
	day = today.getDate();

	switch(sd)
		{
		case 'M':
			{
			var dateformat = month;
			break;			
			}
		case 'MM':
			{
			if (month < 10)
				{
				var dateformat = '0' + month;
				}
			else
				{
				var dateformat = month;
				}
			break;			
			}
		case 'MMM':
			{
			var dateformat = arr[month-1];
			break;			
			}

		case 'd':
			{
			var dateformat = day
			break;			
			}
		case 'dd':
			{
			if(day<10)
				{
				var dateformat = '0' + day;
				}
			else
				{
				var dateformat = day;
				}
			break;			
			}

		case 'yy':
			{
			var subyear = year.toString();
			var dateformat=subyear.substring(2,4);
			break;			
			}
		case 'yyyy':
			{
			var dateformat = year;
			break;			
			}
	
		}
	return 	dateformat;
	}	

//********************************************************************************************************************




function writecheckboxes(checkboxnum,i)
	{
	if (checkboxnum==0) 
		{			
	        document.write("<input onclick=\"togglecheckboxes(" +i+ ")\" type=\"checkbox\" ID=\"C"+checkboxnum+"\" value=\"ON\">");
	        }
	 else
	       	{
		document.write("<input onclick=\"togglecheckbox(" +i+ ")\" type=\"checkbox\" ID=\"C"+checkboxnum+"\" value=\"ON\">");
		}
	}



function togglecheckboxes(i)
	{
	main=eval("document.checkboxform.C0");
	if (main.checked==true)
		{	
		for (var j = 1; j <= i; j++) 
			{
			box = eval("document.checkboxform.C" + j); 
			box.checked = true;
   			}
   		}	
	else
		{	
		for (var j = 1; j <=i; j++) 
			{
			box = eval("document.checkboxform.C" + j); 
			box.checked = false;
   			}
   		} 
   	togglecheckbox(i)  			
	}

		
function togglecheckbox(i)
	{
	var strEntry = "";
		
	for (var j= 1; j<=i; j++)
		{
		box = eval("document.checkboxform.C" + j);
		if (box.checked == true)
			{
			strEntry = strEntry + '|' + j 
			}
		else
			{
			document.checkboxform.C0.checked = false
			}
		}
	document.checkboxform.txtEntryNum.value = strEntry;
	}



//------------------------------------------------------------------------------------------------



/*******************************************************************************
	Popup Window openers
*******************************************************************************/

var winReference = null;


// Open a window at a given position on the screen
function openPositionedWindow(url, name, width, height, x, y, status, scrollbars, moreProperties, openerName) {
	
	// ie4.5 mac - windows are 2 pixels too short; if a statusbar is used, the window will be an additional 15 pixels short
	var agent = navigator.userAgent.toLowerCase();
	if (agent.indexOf("mac")!=-1 && agent.indexOf("msie") != -1 && agent.indexOf("msie 5.0")==-1) {
		height += 2;
		if (status) height += 15;
	}

	// Adjust width if scrollbars are used (pc places scrollbars inside the content area; mac outside) 
	width += (scrollbars != '' && scrollbars != null && agent.indexOf("mac") == -1) ? 16 : 0;

	var properties = 'width=' + width + ',height=' + height + ',screenX=' + x + ',screenY=' + y + ',left=' + x + ',top=' + y + ((status) ? ',status' : '') + ',scrollbars' + ((scrollbars) ? '' : '=no') + ((moreProperties) ? ',' + moreProperties : '');

	var reference = openWindow(url, name, properties, openerName);
	
	// resize window in ie if we can resize in ns; very messy
	// commented out because openPositionedWindow() doesn't set the resizable attribute
	// left in for reference
	/*if (resizable && agent.indexOf("msie") != -1) {
		if (agent.indexOf("mac") != -1) {
			height += (status) ? 15 : 2;
			if (parseFloat(navigator.appVersion) > 5) width -= 11;
		}
		else {
			height += (status) ? 49 : 31;
			width += 13;
		}
		setTimeout('if (reference != null && !reference.closed) reference.resizeTo(' + width + ',' + height + ');', 150);
	}*/

	return reference;
}


// Open a window at the center of the screen
function openCenteredWindow(url, name, width, height, status, scrollbars, moreProperties, openerName) {
	var x = 0;
	var y = 0;
	if (screen) x = (screen.availWidth - width) / 2;
	if (screen) y = (screen.availHeight - height) / 2;
	if (!status) status == '';
	if (!openerName) openerName == '';

	var reference = openPositionedWindow(url, name, width, height, x, y, status, scrollbars, moreProperties, openerName);
	return reference;
}	


// Core utility function that actually creates the window and gives focus to it
function openWindow(url, name, properties, openerName) {

	// ie4.x pc can't give focus to windows containing documents from a different domain
	// in this case, initially load a local interstisial page to allow focussing before loading final url
	var agent = navigator.userAgent.toLowerCase();
	if (agent.indexOf("msie") != -1 && parseInt(navigator.appVersion) == 4 && agent.indexOf("msie 5") == -1 && agent.indexOf("msie5") == -1 && agent.indexOf("win") != -1 && url.indexOf('http://') == 0) {
		winReference = window.open('about:blank', name, properties);
		
		setTimeout('if (winReference && !winReference.closed) winReference.location.replace("' + url + '")', 300);
	}
	else {
		winReference = window.open(url, name, properties);
	}

	// ie doesn't like giving focus immediately (to new window in 4.5 on mac; to existing ones in 5 on pc)
	setTimeout('if (winReference && !winReference.closed) winReference.focus()', 200);
	
	if (openerName) self.name = openerName;
	return winReference;
}


/*******************************************************************************
	Modal Dialog controls
*******************************************************************************/

// Close a dialog
// Call from onunload event handler of any page that can create a dialog
function closeDialog(dialog) {
	if (dialog && dialog.closed != true) dialog.close();
}


// Close parent popup
// Call from onload event handler of any page that could be created from a dialog
function closeParentDialog() {
	if (top.opener && isWindowPopup(top.opener)) {
		root = top.opener.top.opener;
		top.opener.close();
		top.opener = root;
	}
}


// Check if a window is a popup
function isWindowPopup(win) {
	return ((win.opener) ? true : false);
}


function openCalendar(url) {
	return openCenteredWindow(url,'', 583,390);
}


/**********************************************************************************
	One MOnth View
**********************************************************************************/

function mo(fileExt,type,date,position,entry,arrE)
	{		
	if (today_fulldate == month + "_" + date + "_" + year)	
	  {
	  var classname = 'bgc';
	  }  
	else
	  {
	  var classname = 'bgf';
	  }
					
	switch(position)
		{
						
		case 0:
			{
			document.write("<tr height=80 valign=top><td class=" + classname + " width = 103>");
			break;
			}
			
		case 1:
			{
			document.write("<td class=" + classname + " width = 103>");
			break;			
			}
			
		case 2:
			{
			document.write("<td class=" + classname + " width = 103>");
			break;			
			}
		}
	
	switch(type)
		{
		case 0:
			{
			document.write("<table width=100% cellspacing=0 cellpadding=3>");
			document.write("<tr><td>");
			document.write("<font class=txtDate>" + date + "</font>");				
			document.write("</FONT></td></tr></table>");	
			break;
			}
		
		case 1:
			{
			
			document.write("<table width=100% cellspacing=0 cellpadding=3>");
			document.write("<tr><td><FONT class=txtDate COLOR=\"#111111\">");
							
			if (entry==1)
				{				
				if (date < 10)
					{
					if (month < 10)
						{                               
						document.write("<a href=\"../day/" + year + "_0" + month + "_0" + date + fileExt + "\">" + date + "</a>");
						}
					else
						{
						document.write("<a href=\"../day/" + year + "_" + month + "_0" + date + fileExt + "\">" + date + "</a>");						
						}
					}
				else
					{
					if (month <10)
						{
						document.write("<a href=\"../day/" + year + "_0" + month + "_" + date + fileExt + "\">" + date + "</a>");					
						}
					else
						{
						document.write("<a href=\"../day/" + year + "_" + month + "_" + date + fileExt + "\">" + date + "</a>");					
						}						
					}
				}
			else
				{
				document.write(date)
				}
				
			document.write("</FONT></td></tr></table>");			
			
			if(entry==1)
				{
				var arrEntries = arrE.split("%|%")

				for(count=0;count<=arrEntries.length-1;count++)
					{
					createEntry(arrEntries[count],fileExt);
					}		
				}
				
			break;
			}			
		}

	//closing
	switch(position)
		{
		case 0:
			{
			document.write("</td>");
			break;
			}
			
		case 1:
			{
			document.write("</td>");
			break;			
			}
			
		case 2:
			{
			document.write("</td></tr>");
			break;			
			}
		}		
	}
	
function createEntry(entry,fileExt)
	{
	var e = eval(entry);
	var arre = e.split("|");
	
	var tooltip = "title=\"";
	tooltip = tooltip + "Subj:&#9;" + arre[6];
	
	//Adding Source to Tooltip
	if (arre[10]==1)
		{
		tooltip = tooltip + "&#10;" + "Src:&#9;" + arre[9];
		}

	//Adding Date to Tooltip
	if (arre[1].length!=0)
		{
		if (arre[1]!=arre[2])
			{		
			tooltip = tooltip + "&#10;" + "Date:&#9;" + arre[1] + "-" + arre[2];
			}
		else
			{
			tooltip = tooltip + "&#10;" +  "Date:&#9;" + arre[1];
			}
		}

	//Adding Time to Tooltip
	if (arre[3].length!=0)
		{				
		tooltip = tooltip + "&#10;" + "Time:&#9;" + arre[3] + "-" + arre[4];
		}
	
	//Adding Place to Tooltip
	if (arre[5].length!=0)
		{
		tooltip = tooltip + "&#10;" + "Place:&#9;" + arre[5];	
		}
		
	//Adding Message to ToolTip
	if (arre[7].length!=0)
		{		
		tooltip = tooltip + "&#10;" + "Msg:&#9;" + arre[7];
		}
	
	tooltip = tooltip + "\""
	
	document.write("<div class=txtEntry><font class=vsmtext>");

	if (arre[0]=='APPOINTMENT')
		{
		document.write(arre[3] + "&nbsp;");
		}

	//var e1 = "type|startdate|enddate|1p|endtime|place|meeting|message|GUID|desc name|0"
	// 0 = type
	// 1 = startdate 
	// 2 = enddate
	// 3 = starttime
	// 4 = endtime 
	// 5 = place
	// 6 = subject 
	// 7 = message
	// 8 = GUID
	// 9 = desc name
	// 10= blnAbbreviation
	// 11= Abbreviation

	if (arre[10]==0)
		{ 
		var subject = arre[6];
		}
	else
		{
		var subject = arre[11] + "-" + arre[6];
		}

	document.write("</font><A class=onemonthviewHL " + tooltip + " onclick=\"openCalendar(this.href); return false;\" href=\"../../entries/" + arre[8] + fileExt + "\">"+subject+"</A></div>");
	}

/**********************************************************************************
	Month for List View
**********************************************************************************/

function ml(fileExt,type,date,position,entry,arrE)
	{

	//opening
			
			if (today_fulldate == month + "_" + date + "_" + year)
				{
				var classname = 'bgc';
				}
			else
				{
				//var classname = 'bgf';
				}
					
	switch(position)
		{
						
		case 0:
			{
			//document.write("<tr height=25 valign=top><td class=" + classname + " width = 25 >");
			document.write("<tr height=25 valign=top><td width = 25 >");
			break;
			}
			
		case 1:
			{
			//document.write("<td class=" + classname + " width = 25>");
			document.write("<td width = 25>");			
			break;			
			}
			
		case 2:
			{
			//document.write("<td class=" + classname + " width = 25>");
			document.write("<td width = 25>");
			break;			
			}
		}
	
	switch(type)
		{
		case 0: // no date
			{
			document.write("<table width=100% cellspacing=0 cellpadding=3>");
			document.write("<tr align=center><td >");
			document.write("<font class=txtDate>&nbsp;</font>");				
			document.write("</td></tr></table>");	

			break;
			}
		
		case 1: // date
			{
			
			document.write("<table width=100% cellspacing=0 cellpadding=3>");
			document.write("<tr><td align=center><FONT class=txtDate COLOR=\"#111111\">");
							
			if (entry==1)
				{				
				if (date < 10)
					{
					if (month < 10)
						{                               
						document.write("<a href=\"../day/" + year + "_0" + month + "_0" + date + fileExt + "\">" + date + "</a>");
						}
					else
						{
						document.write("<a href=\"../day/" + year + "_" + month + "_0" + date + fileExt + "\">" + date + "</a>");						
						}
					}
				else
					{
					if (month <10)
						{
						document.write("<a href=\"../day/" + year + "_0" + month + "_" + date + fileExt + "\">" + date + "</a>");					
						}
					else
						{
						document.write("<a href=\"../day/" + year + "_" + month + "_" + date + fileExt + "\">" + date + "</a>");					
						}						
					}
				}
			else
				{
				document.write(date)
				}
				
			document.write("</FONT></td></tr></table>");			
				
			break;
			}			
		}

	//closing
	switch(position)
		{
		case 0:
			{
			document.write("</td>");
			break;
			}
			
		case 1:
			{
			document.write("</td>");
			break;			
			}
			
		case 2:
			{
			document.write("</td></tr>");
			break;			
			}
		}		
	}
