/*  calendar.js - 03/07/2008
 *
 *  <script type="text/javascript" src="calendar.js"></script>
 *
 *  Popup Calendar that supports date selection and entry on Web pages.
 *
 *  This script requires the subdirectory "images.cal/" which contains:
 *  "cal.htm" displays a "Calendar Window" (invoked by "calendars.js").
 *  "cal.js" manages the "Calendar Window" (invoked by "cal.htm").
 *  "cal" prefixed images; 36 total, 28 of which are unique calendars.
 *  "cal_gifs.htm" displays the "cal" prefixed images via a Web page.
 *
 *  Following is an example of its usage within a <form> on a Web page:
 *
 *  <input type="text" id="aDate" size="10" maxlength="10" value="">
 *  <a href="javascript:cal("aDate",0)">
 *  <img src="images.cal/calendar.gif" border="0" width="23" height="20"
 *   name="cal0" alt="Calendar" alt="" title="Click for calendar!"
 *   align="absmiddle"></a> &nbsp; <small>(MM/DD/YYYY)</small>
 */

function cal(name,anum) {
    if (!document.getElementById) {
        alert("Your browser does not support the popup calendar.");
        return;
    }
    window.dateField = eval("document.getElementById('" + name + "')");
    window.dateImage = eval("document.cal" + anum);
    window.dateImage.src = "images.cal/calendan.gif";
    var cal_E = document.getElementById(name);
    var cal_X = cal_getElementAbsPosX(cal_E) + 80;
    var cal_Y = cal_getElementAbsPosY(cal_E) + 80;
    var cal_Z = "screenX="+cal_X+",screenY="+cal_Y+",left="+cal_X+",top="+cal_Y;
    window.open("images.cal/cal.htm","cal","width=210,height=250"+cal_Z);
}

function cal_getElementAbsPosX(el) {
    var dx = 0;
    if (el.offsetParent) {
        dx = el.offsetLeft + 8;
        while (el = el.offsetParent) {
            dx += el.offsetLeft;
        }
    }
    return dx;
}

function cal_getElementAbsPosY(el) {
    var dy = 0;
    if (el.offsetParent) {
        dy = el.offsetTop + el.offsetHeight / 2;
        while (el = el.offsetParent) {
            dy += el.offsetTop;
        }
    }
    return dy;
}
