var SpecialDay=1;

var ColorBackground="#62B1C8";
var ColorSpecialDay="colorSpecialDay";
var ColorToday="colorToday";
var ColorEvent="colorEvent";
var ColorMiniMonth="colorMiniMonth";
var ColorEventToday = "colorEventToday";
var ColorEventSpecialDay = "colorEventSpecialDay";

var showAltDate=false;
var showHolidays=false;
var showAltHoly=false;
var showMsgBox=true;
var showMini=true;
var showNav=true;
var showImages=true;
var showLinks=true;

var msgBoxColor="messagebox";
var navColor="#B0D8E3";

var imageAlign="left";
var imageScale=100;
var altAlign=true;
var DefaultFormat="custom";
var ExportPage="";
var PrintPage="";
var DateFontSize=5;
var AltDateFormat="";
var MonthFormat="";
var AltMonthFormat="";
var HolidayFormat="<center>|</center>";
var AltHolyFormat="<center>|</center>";
var DefaultLayerFormat="";
var defaultMsgBox="";
var $a=new Date();
var FirstMonth=GetFullYear($a)*100+1;
var LastMonth=FirstMonth+11;
var $b=new Array;
var $z="|";
var $d=0;
var $e=false;
var $f=new Array;
var $g=new Array;


function Event($h,$i,$j,$k,$l,$m,$n,$o,$p,$desc,$time) {
	this.description=$h;
	if($k)this.link=$k;
	// let's add some new parameters...
	if($desc)this.desc=$desc;
	if($time)this.timeslot=$time;
	if($l) {
		this.image=$l;
		if($m)this.width=$m;
		if($n)this.height=$n;
		if($o)this.align=$o;
		if($p)this.alt=$p;
	}
	this.layer=($i?$i:"default");
	if($j) {
		if(CheckFormat($j))this.format=$j;
	}
}

function DefineEvent(Date,$q,$r,Image,$s,$t,$desc,$time) {
	AddEvent(Date,$q,"","",$r,Image,$s,$t,"right","",$desc,$time);
}

function AddEvent(Date,$q,Layer,$u,$r,Image,$s,$t,$v,$w,$desc,$time) {
	var i;
	if(!$g[Date])$g[Date]=new Array;
	i=$g[Date].length;
	$g[Date][i]=new Event($q,Layer,$u,$r,Image,$s,$t,$v,$w,$desc,$time);
	$x=Math.floor(Date/100);
	if($x<FirstMonth)FirstMonth=$x;
	if($x>LastMonth)LastMonth=$x;
	if(Layer&&!$b[Layer])DefineLayer(Layer);
}

function Layer($j,$y) {
	if($j) {
	if($j.indexOf("|")>0) {
	this.format=$j;
	}else {
	alert("Invalid Calendar Format String: "+$j);
	}}else {
	this.format=DefaultLayerFormat;
	};
	this.show=($y=="false"?"false":"true");
}

function DefineLayer($z,$A,$B) {
	$b[$z]=new Layer($A,$B);
	$d++;
}

function arr() {
	for(var n=0;
	n<arr.arguments.length;
	n++) {
	this[n+1]=arr.arguments[n];
	}
}

var $Z=new arr("January","February","March","April","May","June","July","August","September","October","November","December");
var cookieName="layerCalendar";
var $D,$E,$x,$F,$G,$H;

function Calendar(val) {
	var $I,$J,yr,mo,dy,$K,yearmonth,$L,$M,$N;
	var $O=new arr("Sun","Mon","Tue","Wed","Thu","Fri","Sat");
	var thispage=window.location.pathname;
	var $P="";
	AddMsgBox(0,defaultMsgBox);
	AddMsgBox(0,$P);
	$I=$a.getDate();
	$J=$a.getMonth()+1;
	initCal($J);
	mo=$F;
	yr=$G;
	yearmonth=$H;
	if (isNaN(NextYearMonth(yearmonth))) {
		var $Q=new Date();
		yr=GetFullYear($Q);
		yearmonth=(yr*100)+mo;
	}
	getLayersVisible();
	$L=new Date($Z[mo]+" 1,"+yr);
	$K=$L.getDay();
	$M=NumDaysIn(mo,yr);
	$Q=1+($K+$M-1)%7;
	$R=$S="&nbsp;";
	if(showNav) {
		if(yearmonth>FirstMonth)$R='<a class="navlink" href="'+thispage+'?'+PrevYearMonth(yearmonth)+'&pageid='+val+'">&laquo;View '+$Z[PrevMonth(mo)]+'</a>';
		$S+='<a class="navlink" href="'+thispage+'?'+NextYearMonth(yearmonth)+'&pageid='+val+'">View '+$Z[NextMonth(mo)]+'&raquo;</a>';
	};
	parseFormat(MonthFormat);
	$x="<form><table border=\"0\" cellpadding=\"0\" cellspacing=\"1\" class=\"calendar\">";
	$x+="<tr>";
	$x+="<td class=\"calendarnav\">"+$R+"</td>";
	$x+="<td class=\"monthname\" colspan=\"5\">"+$D+$Z[mo]+" "+yr+$E;
	if(showAltDate == true) {
		parseFormat(AltMonthFormat);
		$T=""; //getAltMonth(1,mo,yr,$M);
		$x+=$D+($T?$T:"")+$E;
	};
	$x+="</td>";
	$x+="<td class=\"calendarnav\">"+$S+"</td></tr>";
	document.write($x);
	document.write("<tr>");
	for(var i=1; i<=7; i++) {
		document.write("<td class=\"days\" width=\"14%\">"+$O[i]+"</td>");
	};
	dy=1;
	document.write("</tr><tr>");
	while(dy<=$M) {
		for(var i=1; i<=7; i++) {
			if(dy==1&&i<=$K) {
				if(i==1) {
					if(showMini) {
						document.write("<td class=\""+ColorMiniMonth+"\">");
						MiniMonth(PrevYearMonth(yearmonth));
					} else {
						document.write("<td>&nbsp;");
					}
				} else if(showMsgBox&&i==2) {
					$U=$K-1;
					document.write("<td class=\""+msgBoxColor+"\" colspan=\""+$U+"\">");
					DoMsgBox(yearmonth,$U);
				} else if(!showMsgBox) {
					document.write("<td>&nbsp;");
				};
				document.write("</td>");
			} else if(dy>$M) {
				if(i==7) {
					if(showMini) {
						document.write("<td class=\""+ColorMiniMonth+"\">");
						MiniMonth(NextYearMonth(yearmonth));
					} else {
						document.write("<td>&nbsp;");
					}
				} else if(showMsgBox&&i==($Q+1)) {
					$U=6-$Q;
					document.write("<td class=\""+msgBoxColor+"\" colspan=\""+$U+"\">");
					DoMsgBox(yearmonth,$U);
				} else if(!showMsgBox) {
					document.write("<td>&nbsp;");
				};
				document.write("</td>");
			} else {
				ShowDate(yr,mo,dy,i,$J,$I);
				document.write("</td>");
				dy++;
			}
		};
		document.write("</tr>");
	};
	if(showNav) {
		$R=$S="&nbsp;";
		if(yearmonth>FirstMonth)$R='<a class="navlink" href="'+thispage+'?'+PrevYearMonth(yearmonth)+'&pageid='+val+'">&laquo;View '+$Z[PrevMonth(mo)]+'</a>';
		$S+='<a class="navlink" href="'+thispage+'?'+NextYearMonth(yearmonth)+'&pageid='+val+'">View '+$Z[NextMonth(mo)]+'&raquo;</a>';
		$x="<tr>";
		$x+="<td class=\"calendarnav\">"+$R+"</td>";
		$x+="<td colspan=\"5\" class=\"calendarnav\" nowrap=\"nowrap\">";
		if(ExportPage)$x+='<a class="navlink" href="'+ExportPage+'?'+yearmonth+'">Export Events Displayed</a>&nbsp;&nbsp;|&nbsp;&nbsp;';
		$x+='Jump to month:&nbsp;&nbsp;';
		document.write($x);
		BuildSelectionList(yearmonth,thispage,val);
		//document.write(yearmonth+", "+thispage);
		if(PrintPage)document.write('&nbsp;&nbsp;|&nbsp;&nbsp;<a class="navlink" href="'+PrintPage+'?'+yearmonth+'">Print-friendly</a>');
		$x="</td>";
		$x+="<td class=\"calendarnav\">"+$S+"</td>";
		document.write($x+"</tr>");
		if($d>1) {
			document.write("<tr><td colspan=\"7\" class=\"calendarnav\">");
			ChooseLayers(yearmonth,thispage);
			document.write("</td></tr>");
		}
	};
	document.write("</table></form>");
}

function ShowDate(yr,mo,dy,$V,$W,$X) {
	var $Y,$Z,$x,event;
	$Z=false;
	if((mo==$W)&&(dy==$X)) {
		// today's color
		$x="<td valign=\"top\" class=\""+ColorToday+"\">";
		/*
		$x="<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"  class=\""+ColorToday+"\">";
		$x+="<tr valign=\"top\">";
		$x+="<td height=\"45\" align=\"left\" width=\"10%\"><b>";
		*/
		$Z=true;
	} else if($V==SpecialDay) {
		// special day's color
		$x="<td valign=\"top\" class=\""+ColorSpecialDay+"\">";
		/*
		$x="<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"  class=\""+ColorSpecialDay+"\">";
		$x+="<tr valign=\"top\">";
		$x+="<td height=\"45\" align=\"left\" width=\"10%\"><b>";
		*/
		$Z=true;
	};
	$Y=(((yr*100)+mo)*100)+dy;
	if($g[$Y]) {
		// event's color
		if(!$Z) $x="<td valign=\"top\" class=\""+ColorEvent+"\">";
		else if((mo==$W)&&(dy==$X)) $x="<td valign=\"top\" class=\""+ColorEventToday+"\">";
		else if($V==SpecialDay) $x="<td valign=\"top\" class=\""+ColorEventSpecialDay+"\">";	
		else $x="<td valign=\"top\" class=\""+ColorEvent+"\">";
		
		/*
		if(!$Z)$x="<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\""+ColorEvent+"\">";
		else if((mo==$W)&&(dy==$X)) $x="<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\""+ColorEventToday+"\">";
		else if($V==SpecialDay) $x="<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\""+ColorEventSpecialDay+"\">";		
		else $x="<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\""+ColorEvent+"\">";
		$x+="<tr valign=\"top\">";
		$x+="<td height=\"45\" align=\"left\" width=\"10%\"><b>";
		*/
	} else if(!$Z) {
		$x="<td valign=\"top\" class=\"datecell\">";
		/*
		$x="<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"  class=\"colorDay\">";
		$x+="<tr valign=\"top\">";
		$x+="<td height=\"45\" align=\"left\" width=\"10%\"><b>";
		*/
	}
	$x+="<span style=\"padding-bottom:22px;\">"+dy+(dy<10?"&nbsp;":"")+"&nbsp;</span>";
	document.write($x);
	if(showAltDate == true) {
		$00=getAltDate(dy,mo,yr);
		parseFormat(AltDateFormat);
		document.write($D+$00+$E);
		//document.write("<td align=\"right\"></td>");
	};
	//document.write("</b></td><td height=\"45\">");
	$01=0;
	var minty = false;
	for(j in $g[$Y]) {
		ev=$g[$Y][j];
		$x="";
		if($b[ev.layer].show=="true") {
			//$x+=(j>0?"</td></tr><tr><td></td><td>":"");
			$x+=(j>0?"<hr width=\"85%\" color=\"#666666\" />":"");
			if(ev.image&&showImages&&j<1) {
				if(ev.align) {
					$o=ev.align;
				} else if(altAlign&&$01>0) {
					$o=($02=="left"?"right":"left");
				} else {
					$o=imageAlign;
				};
				$o="right";
				$x+='<img src="'+ev.image+(ev.width?'" width="'+ev.width*imageScale/100:'')+(ev.height?'" height="'+ev.height*imageScale/100:'')+(ev.alt?'" title="'+ev.alt:'')+'" align="'+$o+'" valign="top" />';
				$02=$o;
				$01++;
			}
			
			$j="";
			if(ev.format=="layer") {
				$j=$b[ev.layer].format;
			} else if(ev.format=="custom") {
				$j="";
			} else if(ev.format) {
				if(CheckFormat(ev.format))$j=ev.format;
			} else if(DefaultFormat=="layer") {
				$j=$b[ev.layer].format;
			};
			parseFormat($j);
			
			$x+="<div>";
			$x+=(j<1?"<br clear=\"all\" />":"");
			$x+=$D+(ev.link&&showLinks?"<b><a class=\"eventlink\" href=\""+ev.link+"\" target=\"_new\">"+ev.description+"</a>":ev.description)+$E+"</b><br />";
			$x+="<span class=\"eventDescription\">"+ev.desc+"<br />";
			$x+="<b><i>"+ev.timeslot+"</i></b></span>";
			$x+="</div>";
		}
		document.write($x);
		minty = true;
	}
	/*
	if (!minty) document.write("</td></tr><tr><td colspan=\"2\" valign=\"top\" height=\"45\">");
	else document.write("</td></tr><tr><td colspan=\"2\" valign=\"top\">");
	*/
	document.write("<br />");
	
	if(showAltHoly) {
		$x=getAltHoly(dy,mo,yr);
		if($x) {
			parseFormat(AltHolyFormat);
			if (!minty) document.write("<b>"+$D+$x+$E+"</b><br />");
			else document.write("<hr noshade width=\"75%\" /><b>"+$D+$x+$E+"</b><br />");
			minty = true;
		}
	};
	if(showHolidays) {
		$x=holidays(dy,mo,yr);
		if($x) {
			parseFormat(HolidayFormat);
			if (!minty) document.write("<b>"+$D+$x+$E+"</b><br />");
			else document.write("<hr noshade width=\"75%\" /><b>"+$D+$x+$E+"</b><br />");
			minty = true;
		}
	};
	if (!minty) document.write("<img border=\"0\" width=\"1\" height=\"85\" src=\"./images/space01.gif\" />");
	//document.write("</td></tr></table>");
}

function exportCal() {
	var $I,$J,yr,mo,dy,$K,yearmonth,$M;
	$I=$a.getDate();
	$J=$a.getMonth()+1;
	initCal($J);
	mo=$F;
	yr=$G;
	yearmonth=$H;
	getLayersVisible();
	$M=NumDaysIn(mo,yr);
	$x="<textarea name=\"txt\"  rows=\"10\" cols=\"50\" wrap=\"virtual\">";
	$x+='"Subject","Start Date","Start Time","End Date","End Time","All day event","Description","Show time as","Location"';
	document.write($x);
	for(dy=1; dy<=$M; dy++) {
		$Y=(((yr*100)+mo)*100)+dy;
		$03=mo+"/"+dy+"/"+yr;
		for(j in $g[$Y]) {
			ev=$g[$Y][j];
			if($b[ev.layer].show=="true") {
				$x=qw(ev.description)+","+qw($03)+",,,,"+qw("true")+",,"+qw("3")+","+qw("CalendarScript");
				if(ev.description)document.write($x+"");
			} else {
			}
		}
	};
	document.write("</textarea>");
}

function getLayersVisible() {
	$04=cookieName+"|";
	$05=unescape(document.cookie);
	$06=$05.indexOf($04);
	if($06>=0) {
	$06+=$04.length;
	$07=$05.indexOf(";");
	if($07==-1)$07=$05.length;
	var $08=$05.substring($06,$07).split("|");
	for(i=0;
	i<$08.length;
	i++) {
	$07=$08[i].indexOf("=");
	name=$08[i].substring(0,$07);
	$09=$08[i].substring($07+1,$08[i].length);
	if($b[name])$b[name].show=$09;
	}}};

function initCal($J) {
	if(!$b["default"])DefineLayer("default",DefaultLayerFormat);
	mo=$J;
	yr=GetFullYear($a);
	yearmonth=(yr*100)+mo;
	if(location.search.length>1) {
	yearmonth=parseInt(location.search.substring(1,location.search.length));
	if((""+yearmonth).length==6) {
	mo=yearmonth%100;
	yr=(yearmonth-mo)/100;
	}}if(yearmonth<FirstMonth) {
	mo=FirstMonth%100;
	yr=(FirstMonth-mo)/100;
	yearmonth=FirstMonth;
	};
	if(yearmonth>LastMonth) {
	mo=LastMonth%100;
	yr=(LastMonth-mo)/100;
	yearmonth=LastMonth;
	}$F=mo;
	$G=yr;
	$H=yearmonth;
}

function qw($0a) {
	return "&quot;"+$0a+"&quot;";
}

function MiniMonth(yearmonth) {
	if (isNaN(yearmonth)) {
		var $Q=new Date();
		yr=GetFullYear($Q);
		yearmonth=(yr*100)+mo - 1;
	}
	var $L,$K,$M,$0b;
	var $0z=new arr("S","M","T","W","T","F","S");
	mo=yearmonth%100;
	yr=(yearmonth-mo)/100;
	$L=new Date($Z[mo]+" 1,"+yr);
	$K=$L.getDay();
	$M=NumDaysIn(mo,yr);
	document.write("<div class=\"minimonthdiv\">"+$Z[mo]+"<br />");
	$0b="<table align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";
	$0b+="<tr>";
	for(d in $0z) {
		$0b+="<th class=\"minimonthdays\">"+$0z[d]+"</th>";
	}
	$0b+="</tr>";
	$0b+="<tr><td class=\"1pxbar\" colspan=\"7\" height=\"1\" bgcolor=\"#000000\"></td></tr>";
	document.write($0b);
	dy=1;
	while(dy<=$M) {
		$0b="<tr>";
		for(var i=1; i<=7; i++) {
			if(dy==1&&i<=$K) {
				$0b+="<td class=\"minimonthcell\"></td>";
			} else if(dy>$M) {
				break;
			} else {
				$0b+="<td class=\"minimonthcell\">"+(dy<10?"":"")+dy+"</td>";
				dy++;
			}
		};
		$0b+="</tr>";
		document.write($0b);
	};
	document.write("</table></div>");
}

function NumDaysIn(mo,yr) {
	if(mo==4||mo==6||mo==9||mo==11)return 30;
	else if((mo==2)&&LeapYear(yr))return 29;
	else if(mo==2)return 28;
	else return 31;
}

function LeapYear(yr) {
	return((yr%4==0&&yr%100!=0)||yr%400==0?true:false);
}

function GetFullYear(d) {
	var yr=d.getYear();
	return(yr<1000?yr+1900:yr);
}

function PrevMonth($0d) {
	return($0d==1?12:$0d-1);
}

function NextMonth($0d) {
	return($0d==12?1:$0d+1);
}

function PrevYearMonth($0e) {
	return($0e%100==1?$0e-100+11:$0e-1);
}

function NextYearMonth($0e) {
	return($0e%100==12?$0e-11+100:$0e+1);
}

function JumpTo($0f,thispage,val) {
	var $0g,$0h;
	$0g=$0f.selectedIndex;
	$0h=$0f.form.jumpmonth[$0g].value;
	document.location=thispage+"?"+$0h+"&pageid="+val;
}

function BuildSelectionList($0i,thispage,val) {
	var mo,yr,yearmonth;
	yearmonth=FirstMonth;
	$x="<select name=\"jumpmonth\" size=1 onchange=\"JumpTo(this,'" + thispage + "','" + val + "')\">";
	while(yearmonth<=LastMonth) {
	mo=yearmonth%100;
	yr=(yearmonth-mo)/100;
	$0j=(yearmonth==$0i?" selected":"");
	$x+="<option value="+yearmonth+$0j+">"+$Z[mo]+" "+yr;
	yearmonth=NextYearMonth(yearmonth);
	}document.write($x+"</select>");
	//document.write(thispage);
}

function DoMsgBox(yearmonth,$U) {
	var newMessage = defaultMsgBox;
	var $1="Host your own Herb Wise Party! <a href=\"http://www.herbwise.net/index.php?pageid=192\">Contact us</a> for more info.";
	
	var $2="Host your own Herb Wise Party! <a href=\"http://www.herbwise.net/index.php?pageid=192\">Contact us</a> for more info.";
	
	var $3="Host your own Herb Wise Party! <a href=\"http://www.herbwise.net/index.php?pageid=192\">Contact us</a> for more info.";
	
	var $4="Host your own Herb Wise Party! <a href=\"http://www.herbwise.net/index.php?pageid=192\">Contact us</a> for more info.";
	
	var $5="Host your own Herb Wise Party! <a href=\"http://www.herbwise.net/index.php?pageid=192\">Contact us</a> for more info.";
	
	var $6="Host your own Herb Wise Party! <a href=\"http://www.herbwise.net/index.php?pageid=192\">Contact us</a> for more info.";
	
	if ($U == 1) newMessage=$1;
	if ($U == 2) newMessage=$2;
	if ($U == 3) newMessage=$3;
	if ($U == 4) newMessage=$4;
	if ($U == 5) newMessage=$5;
	if ($U == 6) newMessage=$6;
	
	if($f[yearmonth]) {
	for(j in $f[yearmonth]) {
	$0k=$f[yearmonth][j];
	if(!$0k.shown) {
	if(!$0k.minspan||$0k.minspan<=$U) {
	$x="<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class="+msgBoxColor+" align=\"center\" class=\"messagebox\">";
	$x+="<tr><td>"+newMessage+"</td></tr></table>";
	document.write($x);
	$0k.shown=true;
	return;
	}}}}if($f[0]) {
	for(j in $f[0]) {
	$0k=$f[0][j];
	if(!$0k.shown) {
	if(!$0k.minspan||$0k.minspan<=$U) {
	$x="<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class="+msgBoxColor+" align=\"center\" class=\"messagebox\">";
	$x+="<tr><td>"+newMessage+"</td></tr></table>";
	document.write($x);
	$0k.shown=true;
	return;
	}}}}
}

function escramVal(j,k) {
	var a,b,c,d,e;
	a='<a href=\"mai';
	c='\">';
	a+='lto:';
	b=j+'@';
	e='</a>';
	b+=k;
	d=b;
	return(a+b+c+d+e);
}

function parseFormat($j) {
	$D=$E="";
	if($j) {
	var $07=$j.indexOf("|");
	if($07>0) {
	$D=$j.substring(0,$07);
	$E=$j.substring(1+$07,$j.length);
	}}
}

function CheckFormat(String) {
	var $0l;
	$0l=(String=="layer"||String=="custom"||String.indexOf("|")>0);
	if(!$0l)alert("Invalid Calendar Format String: "+String);
	return $0l;
}

function MsgBox($0m,$0n,$0o) {
	this.message=$0m;
	this.minspan=($0n?$0n:1);
	if($0o)this.maxspan=$0o;
}

function AddMsgBox(yearmonth,$0m,$0n,$0o) {
	var i;
	if(!$f[yearmonth])$f[yearmonth]=new Array;
	i=$f[yearmonth].length;
	$f[yearmonth][i]=new MsgBox($0m,$0n,$0o);
}

function ChooseLayers(yearmonth,thispage) {
	var i,$0p;
	$x='<form name="layerform">Filter Events:&nbsp;';
	for(i in $b) {
	if(i!="default") {
	$0p=($b[i].show=="true"?" checked":"");
	parseFormat($b[i].format);
	$x+=$D+'<input type="checkbox" name="'+i+'" value="'+i+'"'+$0p+' onClick="ChangeLayer(\''+i+'\')">'+i+"&nbsp;"+$E;
	}}
	$x+='&nbsp;<input type="button" name="ApplyChanges" value="Apply Changes"'+'onClick="ApplyLayerChange(\'' + thispage + '\',\'' + yearmonth + '\')">';
	document.write($x+"</form>");
}

function ChangeLayer($i) {
	$e=true;
	$b[$i].show=document.layerform[$i].checked;
}

function ApplyLayerChange(thispage,yearmonth) {
	$e=false;
	$05=cookieName;
	for($i in $b) {
	if($i!="default") {
	$05+="|"+$i+"="+$b[$i].show;
	}}document.cookie=escape($05);
	document.location=thispage+(yearmonth?"?"+yearmonth:"");
	}


