/* --- Swazz Javascript Calendar ---
/* --- v 1.0 3rd November 2006
By Oliver Bryant
http://calendar.swazz.org */

Date.prototype.getWeek = function() {
    var year = this.getFullYear();
    var newYear = new Date(year,0,1);
    var modDay = newYear.getDay();
    if (modDay == 0) modDay=6; else modDay--;
    var daynum = ((Date.UTC(year,this.getMonth(),this.getDate(),0,0,0) - Date.UTC(year,0,1,0,0,0)) /1000/60/60/24) + 1;

    if (modDay < 4 ) {
        var weeknum = Math.floor((daynum+modDay-1)/7)+1;
    } else {
        var weeknum = Math.floor((daynum+modDay-1)/7);
        if (weeknum == 0) {
            year--;
            var prevNewYear = new Date(year,0,1);
            var prevmodDay = prevNewYear.getDay();
            if (prevmodDay == 0) prevmodDay = 6; else prevmodDay--;
            if (prevmodDay < 4) weeknum = 53; else weeknum = 52;
        }
    }

    return + weeknum;
}

var dualMonthSwazz = {
    now: null,
    sccm: null,
    sccy: null,
    ccm: null,
    ccy: null,
    updobj: null,
    left: null,
    top: null,
    mnn: null,
    mnl: null,
    activeCal: null,
    calvalarr: null,
    calobjarr: null,
    delay: null,
    dy: null,
    mn: null,
    g_PopupIFrame: null,

    init: function() {
        this.now = new Date;
        this.sccm = this.now.getMonth();
        this.sccy = this.now.getFullYear();
        this.ccm = this.now.getMonth();
        this.ccy = this.now.getFullYear();
        this.updobj = new Array(2);
        this.updobj[0] = new Array(2);
        this.updobj[1] = new Array(2);

        /* THESE should already be set!! if not define default values */
        this.delay = window.delay ? delay : 3;
        this.minDayDiff = window.minDayDiff ? minDayDiff : 0;
        this.tripLength = window.tripLength ? tripLength : 7;
        this.printWeek = window.printWeek ? printWeek : false;
        this.yoffset = window.yoffset ? yoffset : 0;
        this.dy = window.dy ? dy : new Array('M', 'T', 'W', 'T', 'F', 'S', 'S');
        this.mn = window.mn ? mn : new Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');

        this.mnn = new Array('31', '28', '31', '30', '31', '30', '31', '31', '30', '31', '30', '31');
        this.mnl = new Array('31', '29', '31', '30', '31', '30', '31', '31', '30', '31', '30', '31');

        this.calvalarr = new Array(2);
        this.calvalarr[0] = new Array(42);
        this.calvalarr[1] = new Array(42);
        this.calobjarr = new Array(2);
        this.calobjarr[0] = new Array(42);
        this.calobjarr[1] = new Array(42);
        this.weekobjarr = new Array(2);
        this.weekobjarr[0] = new Array(6);
        this.weekobjarr[1] = new Array(6);

        document.write('<table id="dswazz" class="fc_container" style="display:none">');
        document.write('<tr><td class="fc_container_td">');
        document.write('<table class="fc"><tr>');
        if (this.printWeek) document.write('<td class="fc_element fc_week_title"  onclick="dualMonthSwazz.csubm(0)">&nbsp;</td>');
        document.write('<td class="fc_element fc_title" onclick="dualMonthSwazz.csubm(0)"><div class="fc_element fc_subm"></div></td><td id="mns0" class="fc_element fc_title" colspan=5 align="center"></td><td class="fc_element fc_title" align="right" ></td></tr><tr>');
        if (this.printWeek) document.write('<td class="fc_element fc_week_dayOfWeek">&nbsp;</td>');
        document.write('<td class="fc_element fc_dayOfWeek">' + this.dy[0] + '</td><td class="fc_element fc_dayOfWeek">' + this.dy[1] + '</td><td class="fc_element fc_dayOfWeek">' + this.dy[2] + '</td><td class="fc_element fc_dayOfWeek">' + this.dy[3] + '</td><td class="fc_element fc_dayOfWeek">' + this.dy[4] + '</td><td class="fc_element fc_dayOfWeek">' + this.dy[5] + '</td><td class="fc_element fc_dayOfWeek">' + this.dy[6] + '</td></tr>');

        for (var kk = 1; kk <= 6; kk++) {
            document.write('<tr>');
            if (this.printWeek) document.write('<td id="w0' + kk + '" class="fc_element fc_weekNo">.</td>');
            for (var tt = 1; tt <= 7; tt++) {
                num = 7 * (kk - 1) - (-tt);
                document.write('<td id="vd0' + num + '" class="fc_element">&nbsp;</td>');
                this.calobjarr[0][num] = this.getObj("vd0" + num);
            }
            document.write('</tr>');
        }
        document.write('</table>');

        document.write('</td><td>');

        document.write('<table class="fc"><tr>');
        if (this.printWeek) document.write('<td class="fc_element fc_week_title">&nbsp;</td>');
        document.write('<td class="fc_element fc_title" ></td><td id="mns1" class="fc_element fc_title" colspan=5 align="center"></td><td class="fc_element fc_title" align="right" onclick="dualMonthSwazz.caddm(1)"><div class="fc_element fc_addm"></div></td></tr><tr>');
        if (this.printWeek) document.write('<td class="fc_element fc_week_dayOfWeek">&nbsp;</td>');
        document.write('<td class="fc_element fc_dayOfWeek">' + this.dy[0] + '</td><td class="fc_element fc_dayOfWeek">' + this.dy[1] + '</td><td class="fc_element fc_dayOfWeek">' + this.dy[2] + '</td><td class="fc_element fc_dayOfWeek">' + this.dy[3] + '</td><td class="fc_element fc_dayOfWeek">' + this.dy[4] + '</td><td class="fc_element fc_dayOfWeek">' + this.dy[5] + '</td><td class="fc_element fc_dayOfWeek">' + this.dy[6] + '</td></tr>');

        for (var kk = 1; kk <= 6; kk++) {
            document.write('<tr>');
            if (this.printWeek) document.write('<td id="w1' + kk + '" class="fc_element fc_weekNo">.</td>');
            for (var tt = 1; tt <= 7; tt++) {
                num = 7 * (kk - 1) - (-tt);
                document.write('<td id="vd1' + num + '" class="fc_element">&nbsp;</td>');
                this.calobjarr[1][num] = this.getObj("vd1" + num);
            }
            document.write('</tr>');
        }
        document.write('</table>');
        document.write('</td></tr>');
        document.write('</table>');

        var ptr = this;
        var chkClick = function(ev) { ptr.checkClick(ev, ptr) };
        document.all ? document.attachEvent('onclick', chkClick) : document.addEventListener('click', chkClick, false);
        //document.all?document.attachEvent('onclick',this.checkClick):document.addEventListener('click',this.checkClick,false); //DEPRECATED
    },

    // day selected
    prepcalendar: function(hd, cm, cy, calNo) {
        if (cm > 11) {
            cy = parseInt(parseInt(cy) + (cm / 11));
            cm = cm % 12;
        }

        var cd, sd, td, htd, dip, obj, marr;
        this.now = new Date();
        sd = this.now.getDate(); // sd = now
        td = new Date();
        td.setFullYear(cy, cm, 1);
        //        td.setDate(1);
        //        td.setFullYear(cy);
        //        td.setMonth(cm);
        cd = (td.getDay() + 6) % 7; // shift so monday is first day, not sunday
        this.getObj('mns' + calNo).innerHTML = this.mn[cm] + ' ' + cy;
        marr = ((cy % 4) == 0) ? this.mnl : this.mnn;

        if (this.printWeek) {
            var weekNo = td.getWeek();
            for (var d = 1; d < 7; d++) {
                if (this.weekobjarr[calNo][d] == null) {
                    this.weekobjarr[calNo][d] = document.getElementById("w" + calNo + d);
                }
                this.weekobjarr[calNo][d].innerHTML = weekNo + d - 1;
            }
        }

        for (var d = 1; d <= 42; d++) { // d = counter (1-42)
            obj = this.calobjarr[calNo][d];
            this.f_cps(obj);
            if ((d >= (cd - (-1))) && (d <= cd - (-marr[cm]))) {
                this.calvalarr[calNo][d] = '' + (d - cd) + '/' + (cm - (-1)) + '/' + cy;
                obj.innerHTML = d - cd;
            } else {
                this.calvalarr[calNo][d] = '';
                obj.innerHTML = '&nbsp;';
            }
            this.setCss(obj, this);
        }
    },

    setCss: function(obj, ptr) {
        var ptr = this;
        var click0 = function(ev) { ptr.cs_click0(ev, ptr) };
        var click1 = function(ev) { ptr.cs_click1(ev, ptr) };
        var cs_over = function(ev) { ptr.cs_over(ev, ptr) };
        var cs_out = function(ev) { ptr.cs_out(ev, ptr) };

        var date1 = ptr.getElementDate(0, ptr);
        var date2 = ptr.getElementDate(1, ptr);

        var calNo = obj.id.substring(2, 3);
        //alert(calNo);

        var strDate = ptr.calvalarr[calNo][obj.id.substring(3, obj.id.length)];
        var arrDate = strDate.split('/');

        var date = new Date(0, 0, 0, 0, 0, 0);
        date.setFullYear(arrDate[2], (arrDate[1] - 1), arrDate[0]);

        var datetemp = new Date((new Date).getFullYear(),(new Date).getMonth(), (new Date).getDate(),0,0,0);
        datetemp.setDate(datetemp.getDate() + this.delay);

        if (calNo == 0) {
            obj.onclick = click0;
        } else {
            obj.onclick = click1;
        }
        obj.onmouseover = cs_over;
        obj.onmouseout = cs_out;

        //alert("date:\n" + date + "\n\ndatetemp:\n" + datetemp);
        
        if (date < datetemp) {
            obj.onclick = null;
            obj.onmouseover = null;
            obj.onmouseout = null;
            obj.className = 'fc_element fc_datePast';
        } else if (date.getDate() == date1.getDate() && date.getMonth() == date1.getMonth() && date.getFullYear == date1.getFullYear) {
            obj.className = 'fc_element fc_date1';
        } else if (date.getDate() == date2.getDate() && date.getMonth() == date2.getMonth() && date.getFullYear == date2.getFullYear) {
            obj.className = 'fc_element fc_date2';
        } else if (date < date1) {
            obj.className = 'fc_element fc_dateBefore';
        } else if (date > date2) {
            obj.className = 'fc_element fc_dateAfter';
        } else {
            obj.className = 'fc_element fc_dateRegular';
        }
        //alert("date1:" + date1 + "\ndate2:" + date2 + "\nstrdate: "+strDate+"\ndate:" + date);
    },

    f_cps: function(obj) {
        obj.className = 'fc_element fc_dateRegular';
    },
    f_cpps: function(obj) {
        obj.className = 'fc_element fc_datePast';
    },
    f_hds: function(obj) {
        obj.className = 'fc_element fc_dateHighlighted';
    },

    lcs: function(ielem1, ielem2, calNo) {
        var curdtarr, isdt;
        this.activeCal = calNo;

        if (this.updobj[0][0] == null) {
            this.updobj[0][0] = this.getObj(ielem1);
            this.updobj[1][0] = this.getObj(ielem2);
        }

        // First check date is valid
        curdtarr = this.updobj[calNo][0].value.split('/');
        isdt = true;
        for (var k = 0; k < curdtarr.length; k++) {
            if (isNaN(curdtarr[k]))
                isdt = false;
        }

        //use the date from the textbox to fill the calendar
        if (isdt & (curdtarr.length == 3)) {
            this.ccm = curdtarr[1] - 1;
            this.ccy = curdtarr[2];
            this.prepcalendar(curdtarr[0], curdtarr[1] - 1, curdtarr[2], 0);
            this.prepcalendar(curdtarr[0], curdtarr[1], curdtarr[2], 1);
        } else {
            this.prepcalendar('', this.ccm, this.ccy, 0);
            this.prepcalendar('', (this.ccm + 1), this.ccy, 1);
        }

        this.ShowPopupDiv('dswazz', this.Left(this.updobj[calNo][0]), this.Top(this.updobj[calNo][0]) + this.updobj[calNo][0].offsetHeight);
    },

    // dayDD as dd, monthDD as mm/yy
    ddlcs: function(dayDD1, monthDD1, dayDD2, monthDD2, calNo) {
        var curdtarr;
        if (this.updobj[0][0] == null) {
            this.updobj[0][0] = this.getObj(dayDD1);
            this.updobj[0][1] = this.getObj(monthDD1);
            this.updobj[1][0] = this.getObj(dayDD2);
            this.updobj[1][1] = this.getObj(monthDD2);
        }

        this.activeCal = calNo;

        curdtarr = this.updobj[calNo][1].options[this.updobj[calNo][1].selectedIndex].value.split('/');

        /*      if ( curdtarr[0]-1 == this.ccm && curdtarr[1] == this.ccy ) {
        this.prepcalendar(this.updobj[0][0].options[this.updobj[0][0].selectedIndex].value,curdtarr[0]-1,curdtarr[1]);//use date from dropdowns 3(3)
        } else {
        this.prepcalendar('',this.ccm,this.ccy);
        }
        */
        if (isNaN(this.updobj[calNo][0].options[this.updobj[calNo][0].selectedIndex].value) == false && isNaN(curdtarr[0] - 1) == false && isNaN(curdtarr[1]) == false) {
            this.ccm = curdtarr[0] - 1;  //use date from dropdowns 1(3)
            this.ccy = curdtarr[1];  //use date from dropdowns 2(3)
            this.prepcalendar(this.updobj[calNo][0].options[this.updobj[calNo][0].selectedIndex].value, curdtarr[0] - 1, curdtarr[1], 0);  //use date from dropdowns 3(3)
            this.prepcalendar(this.updobj[calNo][0].options[this.updobj[calNo][0].selectedIndex].value, curdtarr[0], curdtarr[1], 1);
        } else {
            this.prepcalendar('', this.ccm, this.ccy, 0);
            this.prepcalendar('', (this.ccm + 1), this.ccy, 1);
        }

        this.ShowPopupDiv('dswazz', this.Left(this.updobj[calNo][0]), this.Top(this.updobj[calNo][0]) + this.updobj[calNo][0].offsetHeight);
    },

    IsIE: function() {
        return (navigator.appName == "Microsoft Internet Explorer");
    },
    HidePopupDiv: function(divID) {
        var divPopup;
        divPopup = this.getObj(divID);
        divPopup.style.display = 'none';

        if (this.IsIE() && this.g_PopupIFrame) {
            document.body.removeChild(this.g_PopupIFrame);
            this.g_PopupIFrame = null;
        }
    },
    ShowPopupDiv: function(divID, left, top) {
        var divPopup = this.getObj(divID);
        top = top + this.yoffset;
        divPopup.style.left = left + "px";
        divPopup.style.top = top + "px";

        if (!this.IsIE()) {
            //Just display the div
            divPopup.style.display = '';
            return;
        }
        if (this.g_PopupIFrame) {
            this.HidePopupDiv(divID);
        }

        //Increase default zIndex of div by 1, so that DIV appears before IFrame
        divPopup.style.zIndex = divPopup.style.zIndex + 1;
        divPopup.style.display = '';

        var iFrame = document.createElement("IFRAME");
        iFrame.setAttribute("src", "");
        //Match IFrame position with divPopup
        iFrame.style.position = "absolute";
        iFrame.style.left = left + 'px';
        iFrame.style.top = top + 'px';
        iFrame.style.width = divPopup.offsetWidth + 'px';
        iFrame.style.height = divPopup.offsetHeight + 'px';

        document.body.appendChild(iFrame);

        //Store iFrame in global variable, so it can get removed when divPopup is hidden 
        this.g_PopupIFrame = iFrame;
        divPopup.style.display = '';
    },

    selectValue: function(val, dd) {
        for (var i = 0; i < dd.length; i++) {
            if (dd[i].value == val) {
                dd.selectedIndex = i;
                return 1;
            }
        }
        return 0;
    },
    isChild: function(s, d) {
        while (s) {
            if (s == d)
                return true;
            s = s.parentNode;
        }
        return false;
    },

    caddm: function() {
        marr = ((this.ccy % 4) == 0) ? this.mnl : this.mnn;
        this.ccm += 1;
        if (this.ccm >= 12) {
            this.ccm = 0;
            this.ccy++;
        }
        this.cdayf();
        this.prepcalendar('', this.ccm, this.ccy, 0);
        this.prepcalendar('', (this.ccm + 1), this.ccy, 1);
    },
    csubm: function() {
        marr = ((this.ccy % 4) == 0) ? this.mnl : this.mnn;
        this.ccm -= 1;
        if (this.ccm < 0) {
            this.ccm = 11;
            this.ccy--;
        }
        this.cdayf();
        this.prepcalendar('', this.ccm, this.ccy, 0);
        this.prepcalendar('', (this.ccm + 1), this.ccy, 1);
    },
    cdayf: function() {
        if ((this.ccy > this.sccy) | ((this.ccy == this.sccy) && (this.ccm >= this.sccm)))
            return;
        else {
            this.ccy = this.sccy;
            this.ccm = this.sccm;
        }
    },
    Left: function(obj) {
        var curleft = 0;
        if (obj.offsetParent) {
            while (obj.offsetParent) {
                curleft += obj.offsetLeft
                obj = obj.offsetParent;
            }
        }
        else if (obj.x)
            curleft += obj.x;
        return curleft;
    },

    Top: function(obj) {
        var curtop = 0;
        if (obj.offsetParent) {
            while (obj.offsetParent) {
                curtop += obj.offsetTop
                obj = obj.offsetParent;
            }
        }
        else if (obj.y)
            curtop += obj.y;
        return curtop;
    },

    checkClick: function(e, ptr) {
        var obj = ptr.getObj('dswazz');
        e ? evt = e : evt = event;
        CSE = evt.target ? evt.target : evt.srcElement;
        if (obj) {
            if (!ptr.isChild(CSE, obj)) {
                ptr.HidePopupDiv('dswazz');
            }
        }
    },
    cs_over: function(e, ptr) {
        if (ptr.evtTgt(ptr.EvtObj(e)).className == 'fc_element fc_dateHighlighted') {
            return;
        } else {
            ptr.evtTgt(ptr.EvtObj(e)).className = 'fc_element fc_mouseOver';
        }
    },
    cs_out: function(e, ptr) {
        if (ptr.evtTgt(ptr.EvtObj(e)).className == 'fc_element fc_dateHighlighted') {
            return;
        } else {
            ptr.evtTgt(ptr.EvtObj(e)).className = 'fc_element fc_dateRegular';
            ptr.setCss(ptr.evtTgt(ptr.EvtObj(e)), ptr);
        }
    },
    cs_click0: function(e, ptr) {
        var curdtarr;
        var otherCal = (ptr.activeCal == 0) ? 1 : 0;

        if (ptr.updobj[0][0].length > 3) {
            var date1 = new Date();
            var date2 = new Date();
            var date = ptr.calvalarr[0][ptr.evtTgt(ptr.EvtObj(e)).id.substring(3, ptr.evtTgt(ptr.EvtObj(e)).id.length)];

            curdtarr = date.split('/');
            ptr.selectValue((curdtarr[0]), ptr.updobj[ptr.activeCal][0]);
            ptr.selectValue((curdtarr[1] + "/" + curdtarr[2]), ptr.updobj[ptr.activeCal][1]);

            curdtarr = ptr.updobj[0][1].value.split('/');
            date1.setFullYear(curdtarr[1], (curdtarr[0] - 1), ptr.updobj[0][0].value);

            curdtarr = ptr.updobj[1][1].value.split('/');
            date2.setFullYear(curdtarr[1], (curdtarr[0] - 1), (parseInt(ptr.updobj[1][0].value) - parseInt(ptr.minDayDiff)));

            if (date1 > date2) {
                var newDate = new Date();
                if (ptr.activeCal == 0) {
                    newDate.setFullYear(date1.getFullYear(), date1.getMonth(), (date1.getDate() + ptr.tripLength));
                } else {
                    newDate.setFullYear(date2.getFullYear(), date2.getMonth(), (date2.getDate() - ptr.tripLength));
                    date1 = new Date;
                    date1.setDate(date1.getDate() + ptr.delay);
                    if (newDate < date1) {
                        newDate = date1;
                    }
                }
                ptr.selectValue(newDate.getDate(), ptr.updobj[otherCal][0]);
                ptr.selectValue(((newDate.getMonth() + 1) + "/" + newDate.getFullYear()), ptr.updobj[otherCal][1]);
            }

        } else {
            var date1 = new Date(0, 0, 0, 0, 0, 0);
            var date2 = new Date(0, 0, 0, 0, 0, 0);
            ptr.updobj[ptr.activeCal][0].value = ptr.calvalarr[0][ptr.evtTgt(ptr.EvtObj(e)).id.substring(3, ptr.evtTgt(ptr.EvtObj(e)).id.length)];

            curdtarr = ptr.updobj[0][0].value.split('/');
            date1.setFullYear(curdtarr[2], (curdtarr[1] - 1), curdtarr[0]);

            curdtarr = ptr.updobj[1][0].value.split('/');
            date2.setFullYear(curdtarr[2], (curdtarr[1] - 1), (parseInt(curdtarr[0]) - parseInt(ptr.minDayDiff)));

            if (date1 > date2) {
                var newDate = new Date();
                if (ptr.activeCal == 0) {
                    newDate.setFullYear(date1.getFullYear(), date1.getMonth(), (date1.getDate() + ptr.tripLength));
                } else {
                    newDate.setFullYear(date2.getFullYear(), date2.getMonth(), (date2.getDate() - ptr.tripLength));

                    date1 = new Date;
                    date1.setDate(date1.getDate() + ptr.delay);
                    if (newDate < date1) {
                        newDate = date1;
                    }
                }
                ptr.updobj[otherCal][0].value = newDate.getDate() + "/" + (newDate.getMonth() + 1) + "/" + newDate.getFullYear();
            }
        }
        ptr.HidePopupDiv('dswazz');
    },
    cs_click1: function(e, ptr) {
        var curdtarr;
        var otherCal = (ptr.activeCal == 0) ? 1 : 0;

        if (ptr.updobj[1][0].length > 3) {
            var date1 = new Date();
            var date2 = new Date();
            var date = ptr.calvalarr[1][ptr.evtTgt(ptr.EvtObj(e)).id.substring(3, ptr.evtTgt(ptr.EvtObj(e)).id.length)];

            curdtarr = date.split('/');
            ptr.selectValue((curdtarr[0]), ptr.updobj[ptr.activeCal][0]);
            ptr.selectValue((curdtarr[1] + "/" + curdtarr[2]), ptr.updobj[ptr.activeCal][1]);

            curdtarr = ptr.updobj[0][1].value.split('/');
            date1.setFullYear(curdtarr[1], (curdtarr[0] - 1), (parseInt(ptr.updobj[0][0].value) + parseInt(ptr.minDayDiff)));

            curdtarr = ptr.updobj[1][1].value.split('/');
            date2.setFullYear(curdtarr[1], (curdtarr[0] - 1), ptr.updobj[1][0].value);

            if (date1 > date2) {
                var newDate = new Date();
                if (ptr.activeCal == 0) {
                    newDate.setFullYear(date1.getFullYear(), date1.getMonth(), (date1.getDate() + ptr.tripLength));
                } else {
                    newDate.setFullYear(date2.getFullYear(), date2.getMonth(), (date2.getDate() - ptr.tripLength));

                    date1 = new Date;
                    date1.setDate(date1.getDate() + this.delay);
                    if (newDate < date1) {
                        newDate = date1;
                    }
                }
                ptr.selectValue(newDate.getDate(), ptr.updobj[otherCal][0]);
                ptr.selectValue(((newDate.getMonth() + 1) + "/" + newDate.getFullYear()), ptr.updobj[otherCal][1]);
            }

        } else {
            var date1 = new Date(0, 0, 0, 0, 0, 0);
            var date2 = new Date(0, 0, 0, 0, 0, 0);
            ptr.updobj[ptr.activeCal][0].value = ptr.calvalarr[1][ptr.evtTgt(ptr.EvtObj(e)).id.substring(3, ptr.evtTgt(ptr.EvtObj(e)).id.length)];

            curdtarr = ptr.updobj[0][0].value.split('/');
            date1.setFullYear(curdtarr[2], (curdtarr[1] - 1), (parseInt(curdtarr[0]) + parseInt(ptr.minDayDiff)));

            curdtarr = ptr.updobj[1][0].value.split('/');
            date2.setFullYear(curdtarr[2], curdtarr[1] - 1, curdtarr[0])

            if (date1 > date2) {
                var newDate = new Date();
                if (ptr.activeCal == 0) {
                    newDate.setFullYear(date1.getFullYear(), date1.getMonth(), (date1.getDate() + ptr.tripLength));
                } else {
                    newDate.setFullYear(date2.getFullYear(), date2.getMonth(), (date2.getDate() - ptr.tripLength));

                    date1 = new Date;
                    date1.setDate(date1.getDate() + this.delay);
                    if (newDate < date1) {
                        newDate = date1;
                    }
                }
                ptr.updobj[otherCal][0].value = newDate.getDate() + "/" + (newDate.getMonth() + 1) + "/" + newDate.getFullYear();
            }
        }
        ptr.HidePopupDiv('dswazz');
    },
    getElementDate: function(cal, ptr) {
        var curdtarr;
        var returnDate = null;

        if (ptr.updobj[1][0].length > 3) {
            curdtarr = ptr.updobj[cal][1].value.split('/');
            returnDate = new Date(curdtarr[1], (curdtarr[0] - 1), (parseInt(ptr.updobj[cal][0].value) + parseInt(ptr.minDayDiff)));
        } else {
            curdtarr = ptr.updobj[cal][0].value.split('/');
            returnDate = new Date(curdtarr[2], (curdtarr[1] - 1), curdtarr[0]);
        }
        return returnDate;
    },
    setElementDate: function(cal, ptr, newDate) {
        if (ptr.updobj[cal][0].length > 3) {
            ptr.selectValue(newDate.getDate(), ptr.updobj[cal][0]);
            ptr.selectValue(((newDate.getMonth() + 1) + "/" + newDate.getFullYear()), ptr.updobj[cal][1]);
        } else {
            ptr.updobj[cal][0].value = newDate.getDate() + "/" + (newDate.getMonth() + 1) + "/" + newDate.getFullYear();
        }
    },

    EvtObj: function(e) {
        if (!e)
            e = window.event;
        return e;
    },
    evtTgt: function(e) {
        var el;
        if (e.target)
            el = e.target;
        else if (e.srcElement)
            el = e.srcElement;
        if (el.nodeType == 3)
            el = el.parentNode; // defeat Safari bug
        return el;
    },
    getObj: function(objID) {
        if (document.getElementById) {
            return document.getElementById(objID);
        } else if (document.all) {
            return document.all[objID];
        } else if (document.layers) {
            return document.layers[objID];
        }
    }
}
dualMonthSwazz.init();
