var SpecialDay = 1;
var ColorBackground = "ffffcc";
var ColorSpecialDay = "red";
var ColorToday = "green";
var ColorEvent = "blue";
var showAltDate = false;
var showHolidays = false;
var showAltHoly = false;
var showMsgBox = true;
var showMini = false;
var showNav = true;
var showImages = true;
var showLinks = true;
var msgBoxColor = "#ffffff";
var navColor = "#ffff99";
var imageAlign = "left";
var imageScale = 100;
var altAlign = true;
var DefaultFormat = "custom";
var DateFontSize = 5;
var AltDateFormat = "<font color=#999999 size=1>|</font>";
var MonthFormat = "<font size=" + DateFontSize + "><b>|</b></font>";
var AltMonthFormat = "<br><font color=#999999 size=" + DateFontSize / 2 + ">|</font>";
var HolidayFormat = "<font color=#999999 size=2><b><center>|</center></b></font>";
var AltHolyFormat = "<font  size=2><b><center>|</center></b></font>";
var DefaultLayerFormat = "<font size=2>|</font>";
var defaultMsgBox = "<p>You <u>must</u> register with NCALL prior to attending these classes. Please call (302) 678-9400.</p>";
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) {
    this.description = $h;
    if ($k) this.link = $k;
    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) { AddEvent(Date, $q, "", "", $r, Image, $s, $t, "", ""); }
function AddEvent(Date, $q, Layer, $u, $r, Image, $s, $t, $v, $w) {
    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); $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() {
    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 = "<p>For directions to our various locations, please see our <a href=http://www.ncall.org/contact.htm>contact</a> page.</p>";
    AddMsgBox(0, defaultMsgBox); AddMsgBox(0, $P); $I = $a.getDate(); $J = $a.getMonth() + 1; initCal($J); mo = $F; yr = $G; yearmonth = $H;
    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) + '">&lt; ' + $Z[PrevMonth(mo)] + '</a>';
        if (yearmonth < LastMonth) $S += '<a class="navlink" href="' + thispage + '?' + NextYearMonth(yearmonth) + '"> ' + $Z[NextMonth(mo)] + ' &gt;</a>';
    };
    parseFormat(MonthFormat); $x = "<TABLE width=625px BORDER=2 BGCOLOR=" + ColorBackground + "><TR BORDER=0 BGCOLOR=" + navColor + ">";
    $x += "<TD ALIGN=CENTER BGCOLOR=" + navColor + ">" + $R + "</TD>"; $x += "<TD ALIGN=CENTER COLSPAN=5>" + $D + $Z[mo] + " " + yr + $E;
    if (showAltDate) { parseFormat(AltMonthFormat); $T = getAltMonth(1, mo, yr, $M); $x += $D + ($T ? $T : "") + $E; };
    $x += "</TD><TD ALIGN=CENTER BGCOLOR=" + navColor + ">" + $S + "</TD></TR>"; document.write($x); document.write("<TR BGCOLOR=" + navColor + ">");
    for (var i = 1; i <= 7; i++) { document.write("<TD ALIGN=CENTER WIDTH=14%><FONT SIZE=4>" + $O[i] + "</FONT></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 BGCOLOR=" + ColorBackground + ">"); MiniMonth(PrevYearMonth(yearmonth)); }
                    else { document.write("<TD>&nbsp;"); } 
                }
                else if (showMsgBox && i == 2) {
                    $U = $K - 1; document.write("<TD BGCOLOR=" + navColor + " COLSPAN=" + $U + ">&nbsp;"); 
                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 BGCOLOR=" + ColorBackground + ">"); MiniMonth(NextYearMonth(yearmonth)); } 
                else { document.write("<TD>&nbsp;"); } }
                else if (showMsgBox && i == ($Q + 1)) {
                    $U = 6 - $Q; document.write("<TD BGCOLOR=" + navColor + " COLSPAN=" + $U + ">&nbsp;"); 
                DoMsgBox(yearmonth, $U); }
                else if (!showMsgBox) { document.write("<TD>&nbsp;"); }; document.write("</TD>");
            }
            else { document.write("<TD VALIGN=TOP>"); 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) + '">&lt; ' + $Z[PrevMonth(mo)] + '</a>';
        if (yearmonth < LastMonth) $S += '<a class="navlink" href="' + thispage + '?' + NextYearMonth(yearmonth) + '"> ' + $Z[NextMonth(mo)] + ' &gt;</a>';
        $x = "<TR BGCOLOR=" + navColor + "><TD ALIGN=CENTER BGCOLOR=" + navColor + ">" + $R + "</TD>";
        $x += "<TD colspan=5 align=center valign=middle><FORM>";
        $x += '<h4>Jump to month:</h4>&nbsp;&nbsp;';
        document.write($x);
        BuildSelectionList(yearmonth, thispage);
        $x = "</FORM></TD><TD ALIGN=CENTER BGCOLOR=" + navColor + ">" + $S + "</TD>";
        document.write($x + "</TR>");
        if ($d > 1) {
            document.write("<TR BGCOLOR=" + navColor + "><TD colspan=7 align=center>");
            ChooseLayers(yearmonth, thispage); document.write("</TD></TR>");
        } 
    };
    document.write("</TABLE>");
};
function ShowDate(yr, mo, dy, $V, $W, $X) {
    var $Y, $Z, $x, event; $x = "<TABLE><TR VALIGN=TOP><TD ALIGN=LEFT WIDTH=10% HEIGHT=50px>"; $x += "<FONT SIZE=" + DateFontSize; $Z = false;
    if ((mo == $W) && (dy == $X)) { $x += " COLOR=" + ColorToday; $Z = true; }
    else if ($V == SpecialDay) { $x += " COLOR=" + ColorSpecialDay; $Z = true; }; $Y = (((yr * 100) + mo) * 100) + dy;
    if ($g[$Y]) {
        if (!$Z) $x += " COLOR=" + ColorEvent;
    }; $x += "><B>" + dy + (dy < 10 ? "&nbsp;" : "") + "&nbsp;</B></FONT></TD>"; document.write($x);
    if (showAltDate) { $00 = getAltDate(dy, mo, yr); parseFormat(AltDateFormat); document.write("<TD ALIGN=RIGHT>" + $D + $00 + $E + "</TD>"); };
    document.write("</TR></TABLE>");
    if (showAltHoly) {
        $x = getAltHoly(dy, mo, yr);
        if ($x) { parseFormat(AltHolyFormat); document.write($D + $x + $E + "<BR>"); } 
    };
    if (showHolidays) {
        $x = holidays(dy, mo, yr);
        if ($x) { parseFormat(HolidayFormat); document.write($D + $x + $E + "<BR>"); } 
    }; $01 = 0; for (j in $g[$Y]) {
        ev = $g[$Y][j]; $x = "";
        if ($b[ev.layer].show == "true") {
            $x += (j > 0 ? "<br>" : "");
            if (ev.image && showImages) {
                if (ev.align) { $o = ev.align; }
                else if (altAlign && $01 > 0) { $o = ($02 == "left" ? "right" : "left"); }
                else { $o = imageAlign; };
                $x += '<img src="' + ev.image + (ev.width ? '"  width="' + ev.width * imageScale / 100 : '') + (ev.height ? '" height="' + ev.height * imageScale / 100 : '') + (ev.alt ? '" alt="' + 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 += $D + (ev.link && showLinks ? "<a class=\"eventlink\" href=" + ev.link + ">" + ev.description + "</a>" : ev.description) + $E + "<br>";
    }
    else { }; document.write("<FONT SIZE=1>" + $x + "</FONT>");
} 
};
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=20 COLS=75 WRAP=VIRTUAL>";
    $x += '"Subject","Start Date","Start Time","End Date","End Time","All day event","Description","Show time as","Location"\n';
    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 + "\n");
            }
            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) {
    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("<b><tt><Font Size=2><div align=center>&nbsp;" + $Z[mo] + "</div></font>");
    $0b = "<font size=1>&nbsp;<u>";
    for (d in $0z) { $0b += "&nbsp;" + $0z[d] + "&nbsp;"; };
    document.write($0b, "</u>"); dy = 1;
    while (dy <= $M) {
        $0b = "<br>";
        for (var i = 1; i <= 7; i++) {
            if (dy == 1 && i <= $K) { $0b += "&nbsp;&nbsp;&nbsp;"; }
            else if (dy > $M) { break; }
            else { $0b += "&nbsp;" + (dy < 10 ? "&nbsp;" : "") + dy; dy++; } 
        };
        document.write($0b);
    }; document.write("</font></tt></b>");
};
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) {
    var $0g, $0h; $0g = $0f.selectedIndex; $0h = $0f.form.jumpmonth[$0g].value; document.location = thispage + "?" + $0h;
};
function BuildSelectionList($0i, thispage) {
    var mo, yr, yearmonth; yearmonth = FirstMonth; $x = "<select name=\"jumpmonth\" size=1 onchange=\"JumpTo(this,'" + thispage + "')\">";
    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>");
}
function DoMsgBox(yearmonth, $U) {
    if ($f[yearmonth]) {
        for (j in $f[yearmonth]) {
            $0k = $f[yearmonth][j];
            if (!$0k.shown) {
                if (!$0k.minspan || $0k.minspan <= $U) {
                    $x = "<table border=2 bgcolor=" + msgBoxColor + " align=center>";
                    $x += "<TR><TD>" + $0k.message + "</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=2 bgcolor=" + msgBoxColor + " align=center>";
                    $x += "<TR><TD>" + $0k.message + "</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"><b>Filter Events:</b>&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 : ""); }


