var noofdays = 1;
var NO_OF_DAYS = 0;

//Added by Vijay default _a variable set as global
var _a;
function SetDiv(id) {
    _a = id;
    //alert(_a);
}

//Modified
var currentDate;
function positionInfo(_1) {
    var _2 = _1;
    this.getElementLeft = getElementLeft;
    function getElementLeft() {
        var x = 0;
        var _6;
        if (typeof (_2) == "object") {
            _6 = _2;
        } else {
            _6 = document.getElementById(_2);
        }
        return parseInt(_6.offsetLeft);
    }
    this.getElementWidth = getElementWidth;
    function getElementWidth() {
        var _6;
        if (typeof (_2) == "object") {
            _6 = _2;
        } else {
            _6 = document.getElementById(_2);
        }
        return parseInt(_6.offsetWidth);
    }
    this.getElementRight = getElementRight;
    function getElementRight() {
        return getElementLeft(_2) + getElementWidth(_2);
    }
    this.getElementTop = getElementTop;
    function getElementTop(_7) {
        var y = 0;
        if (_7.offsetParent) {
            while (_7 != null) {
                y += _7.offsetTop;
                _7 = _7.offsetParent;
            }
        } else {
            if (_7.y) {
                y += _7.y;
            }
        }
        y -= 155;
        return parseInt(y);
    }
    this.getElementHeight = getElementHeight;
    function getElementHeight() {
        var _9;
        if (typeof (_2) == "object") {
            _9 = _2;
        } else {
            _9 = document.getElementById(_2);
        }
        return parseInt(_9.offsetHeight);
    }
    this.getElementBottom = getElementBottom;
    function getElementBottom() {
        return getElementTop(_2) + getElementHeight(_2);
    }
}

function CalendarControl() {
    if (_a == null)
        _a = "CalendarControl1";
    var _b = "";
    var _c = 0;
    var _d = 0;
    var _e = 0;
    var _f = 0;
    var _10 = 0;
    var _11 = 0;
    var _12 = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
    var _13 = null;
    function clearDates() {
        _c = 0;
        _d = 0;
        _e = 0;
        _f = 0;
        _10 = 0;
        _11 = 0;
    }
    function getProperty(_14) {
        var _15 = _a;
        var elm = null;
        if (typeof (_15) == "object") {
            elm = _15;
        } else {
            elm = document.getElementById(_15);
        }
        if (elm != null) {
            if (elm.style) {
                elm = elm.style;
                if (elm[_14]) {
                    return elm[_14];
                } else {
                    return null;
                }
            } else {
                return null;
            }
        }
    }
    function setElementProperty(_17, _18, _19) {
        var _1a = _19;
        var elm = null;
        if (typeof (_1a) == "object") {
            elm = _1a;
        } else {
            elm = document.getElementById(_1a);
        }
        if ((elm != null) && (elm.style != null)) {
            elm = elm.style;
            elm[_17] = _18;
        }
    }
    function setProperty(_1c, _1d) {
        setElementProperty(_1c, _1d, _a);
    }
    function getDaysInMonth(_1e, _1f) {
        return [31, ((!(_1e % 4) && ((_1e % 100) || !(_1e % 400))) ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][_1f - 1];
    }
    function getDayOfWeek(_20, _21, day) {
        var _23 = new Date(_20, _21 - 1, day);
        return _23.getDay();
    }
    this.setDate = setDate;
    function setDate(_24, _25, day) {
        var jmonth = _25;
        if (_13) {
            if (_25 < 10) {
                _25 = "0" + _25;
            }
            if (day < 10) {
                day = "0" + day;
            }
            var _27 = day + "/" + _25 + "/" + _24;
            document.forms[0].month.value = jmonth;
            document.forms[0].day.value = day;
            document.forms[0].year.value = _24;
            _13.value = _27;
            hide();
        }
        return;
    }
    this.changeMonth = changeMonth;
    function changeMonth(_28, _29) {
        _d += _28;
        _e = 0;
        if (_d > 12) {
            _d = 1;
            _c++;
        } else {
            if (_d < 1) {
                _d = 12;
                _c--;
            }
        }
        calendar = document.getElementById(_a);
        calendar.innerHTML = calendarDrawTable(_29);
    }
    this.changeYear = changeYear;
    function changeYear(_2a) {
        _c += _2a;
        _e = 0;
        calendar = document.getElementById(_a);
        calendar.innerHTML = calendarDrawTable();
    }
    function getCurrentYear() {

        var _2b = new Date(currentDate);
        _2b = new Date(_2b.getTime() + NO_OF_DAYS * 24 * 60 * 60 * 1000);
        var _2c = _2b.getYear();
        if (_2c < 1900) {
            _2c += 1900;
        }
        return _2c;
    }
    function getCurrentMonth() {
        var _2d = new Date(currentDate);
        _2d = new Date(_2d.getTime() + NO_OF_DAYS * 24 * 60 * 60 * 1000);
        return _2d.getMonth() + 1;
    }
    function getCurrentDay() {
        var _2e = new Date(currentDate);
        _2e = new Date(_2e.getTime() + NO_OF_DAYS * 24 * 60 * 60 * 1000);

        return _2e.getDate(currentDate);
    }
    function calendarDrawTable(_2f) {
        var _30 = 1;
        var _31 = 0;
        var _32 = getDayOfWeek(_c, _d, _30);
        if (_32 == 0) {
            _32 = 6;
        } else {
            _32 = _32 - 1;
        }
        var _33 = getDaysInMonth(_c, _d);
        var _34 = null;
        var _35 = new Date(currentDate);
        _35 = new Date(_35.getTime() + NO_OF_DAYS * 24 * 60 * 60 * 1000);
        var _36 = new Date(currentDate);
        var _37 = "";
        var _38;
        if (typeof (_2f) != "object") {
            _2f = $(_2f);
        }
        if ((_37 != "") && (_37 != "dd/mm/yyyy")) {
            _38 = new Date(currentDate);
            var _39 = _37.split("index.html");
            var day = parseInt(_39[0], 10);
            var _3b = parseInt(_39[1], 10);
            var _3c = parseInt(_39[2], 10);

            _38.setFullYear(_3c, _3b - 1, day);
        } else {
            _38 = "";
        }
        _36.setFullYear(_c, _d - 1, _30);
        var _3d = "";
        if ((_d > (_35.getMonth() + 1)) || (_c > _35.getFullYear())) {
            _3d += "<div class='cal_control' id='calBody' style='text-align:right;'><a class='cal_control' href='javascript:void(0)' onclick='changeCalendarControlMonth(-1,\"" + _2f.getAttribute("id") + "\");return false'>Previous month</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='javascript:hideCalendarControl();'><img style='vertical-align:middle;' border='0' src='cal-files/close.gif' vspace='2 alt='Close'/></a></div>";
        } else {
            _3d += "<div class='cal_control' style='text-align:right;'><a href='javascript:hideCalendarControl();'><img style='vertical-align:middle;' border='0' src='cal-files/close.gif' vspace='2' alt='Close' /></a></div>";
        }
        _3d = _3d + "<table cellspacing='0' cellpadding='0' border='0' bordercolor='#000000' align='center'>";
        _3d = _3d + " <tr><td colspan='7' class='title'>" + _12[_d - 1] + " " + _c + "</td>";
        _3d = _3d + "</tr>";
        _3d = _3d + "<tr><th>M</th><th>T</th><th>W</th><th>T</th><th>F</th><th>S</th><th>S</th></tr>";
        for (var _3e = 0; _3e < 6; _3e++) {
            _3d = _3d + "<tr>";
            for (var _3f = 0; _3f < 7; _3f++) {
                if (_3e == 0 && _32 == _3f) {
                    _31 = 1;
                } else {
                    if (_31 == 1 && _30 > _33) {
                        _31 = 0;
                    }
                }
                if (_31) {
                    if (_30 == _11 && _c == _f && _d == _10) {
                        _34 = "current";
                        if (_3f == 5 || _3f == 6) {
                            _34 = "weekend " + _34;
                        } else {
                            _34 = "weekday " + _34;
                        }
                    } else {
                        if (_3f == 5 || _3f == 6) {
                            _34 = "weekend";
                        } else {
                            _34 = "weekday";
                        }
                    }
                    _36.setFullYear(_c, _d - 1, _30);
                    var _40 = compareDates(_36, _35);
                    var days = getDateDifference1(_36, _35);
                    var _41;
                    if (_38 != "") {
                        _41 = compareDates(_36, _38);
                    } else {
                        _41 = "";
                    }
                    //alert("_40"+_40+"  _41"+41);
                    if (_40 == 1 || days > 730) {           //Default days=92 modified 730 :::Vijay;
                        //	alert("1");
                        _3d = _3d + "<td class='" + _34 + " past_date'>" + _30 + "</td>";
                    } else {
                        if ((_38 != "") && (_41 == 1) && (Element.hasClassName(_2f, "second"))) {
                            _3d = _3d + "<td class='" + _34 + " past_date'>" + _30 + "</td>";
                        } else {
                            if ((!(Element.hasClassName(_2f, "second")) && (_40 <= 0)) || (Element.hasClassName(_2f, "second") && _41 <= 0)) {
                                _3d = _3d + "<td class='" + _34 + "'><a  class='cal_dates' href=\"#\" onclick=\"setCalendarControlDate(" + _c + "," + _d + "," + _30 + ");return false\">" + _30 + "</a></td>";
                            }
                        }
                    }
                    _30++;
                    noofdays++;
                } else {
                    _3d = _3d + "<td class='empty'>&nbsp;</td>";
                }
            }
            _3d = _3d + "</tr>";
        }
        _3d = _3d + "</table>";
        _30 = 1;
        _31 = 0;
        var _42 = 0;
        var _43 = 0;
        if (_d == 12) {
            _42 = 1;
            _43 = _c + 1;
        } else {
            _42 = _d + 1;
            _43 = _c;
        }
        _32 = getDayOfWeek(_43, _42, _30);
        if (_32 == 0) {
            _32 = 6;
        } else {
            _32 = _32 - 1;
        }
        _33 = getDaysInMonth(_43, _42);

        _3d += "<table cellspacing='0' cellpadding='0' border='0'>";
        _3d = _3d + "  <tr><td colspan='7' class='title'>" + _12[_42 - 1] + " " + _43 + "</td></tr>";
        _3d = _3d + "<tr><th>M</th><th>T</th><th>W</th><th>T</th><th>F</th><th>S</th><th>S</th></tr>";
        for (var _3e = 0; _3e < 6; _3e++) {

            _3d = _3d + "<tr>";

            for (var _3f = 0; _3f < 7; _3f++) {
                if (_3e == 0 && _32 == _3f) {
                    _31 = 1;
                } else {
                    if (_31 == 1 && _30 > _33) {
                        _31 = 0;
                    }
                }
                if (_31) {
                    if (_30 == _11 && _43 == _f && _42 == _10) {
                        _34 = "current";
                        if (_3f == 5 || _3f == 6) {
                            _34 = "weekend " + _34;
                        } else {
                            _34 = "weekday " + _34;
                        }
                    } else {
                        if (_3f == 5 || _3f == 6) {
                            _34 = "weekend";
                        } else {
                            _34 = "weekday";
                        }
                    }
                    _36.setFullYear(_43, _42 - 1, _30);

                    _40 = compareDates(_36, _35);
                    days = getDateDifference1(_36, _35);
                    _41 = "";
                    if (_38 != "") {
                        _41 = compareDates(_36, _38);
                    } else {
                        _41 = "";
                    }

                    //alert("sssss"+_34);

                    if (_40 == 1 || days > 730) {                   //Default days=92 modified 730 :::Vijay;

                        _3d = _3d + "<td class='" + _34 + " past_date'>" + _30 + "</td>";
                    } else {
                        if ((_38 != "") && (_41 == 1) && (Element.hasClassName(_2f, "second"))) {
                            _3d = _3d + "<td class='" + _34 + " past_date'>" + _30 + "</td>";
                        }
                        else {
                            if ((!(Element.hasClassName(_2f, "second")) && (_40 <= 0)) || (Element.hasClassName(_2f, "second") && _41 <= 0)) {
                                _3d = _3d + "<td class='" + _34 + "'><a class='cal_dates' href=\"#\" onclick=\"javascript:setCalendarControlDate(" + _43 + "," + _42 + "," + _30 + ");return false\">" + _30 + "</a></td>";
                            }
                        }
                    }
                    _30++;
                    noofdays++;
                } else {
                    _3d = _3d + "<td class='empty'>&nbsp;</td>";
                }
            }
            _3d = _3d + "</tr>";
        }
        _3d = _3d + "</table>";
        _3d = _3d + "<div class='cal_control'><a class='cal_control' href='javascript:void();' onclick='changeCalendarControlMonth(1,\"" + _2f.getAttribute("id") + "\");return false'>Next month</a></div>";
        //alert("asdfasdfas"+_3d);
        return _3d;
    }
    this.show = show;
    function show(_44, num) {
        if (_13 == _44) {
            return;
        } else {
            _13 = _44;
        }
        if (_13) {
            try {
                if (_13.value != "dd/mm/yyyy") {
                    var _46 = _13.value.split("index.html");
                    _10 = parseInt(_46[1], 10);
                    _11 = parseInt(_46[0], 10);
                    _f = parseInt(_46[2], 10);
                }
                var _47;
            }
            catch (e) {
                alert("Please enter the date in the valid format: dd/mm/yyyy");
            }
        }
        if (!(_f && _10 && _11)) {
            _10 = getCurrentMonth();
            _11 = getCurrentDay();
            _f = getCurrentYear();
        }
        if (("" + _f).length < 4) {
            _f = 2000 + parseInt(_f);
        }
        _d = _10;
        _e = _11;
        _c = _f;
        if (document.getElementById) {
            calendar = document.getElementById(_a);
            calendar.innerHTML = calendarDrawTable(_44);
            setElementProperty("display", "block", "CalendarControlIFrame");
            setProperty("display", "block");
            var _48 = new positionInfo(_13);
            var _49 = new positionInfo(_a);
            var x = _48.getElementLeft(num);
            var y = _48.getElementBottom(num);

            //if (navigator.appName.indexOf("Microsoft Internet Explorer") > (-1)) {

                //setProperty("left", x + "px");
                //setProperty("top", y + "px");
            //}
            //else {
                //setProperty("left", 225 + "px");
                //setProperty("top", 185 + "px");
            //}
            setElementProperty("left", x + "px", "CalendarControlIFrame");
            setElementProperty("top", y + "px", "CalendarControlIFrame");
            setElementProperty("width", _49.getElementWidth() + "px", "CalendarControlIFrame");
            setElementProperty("height", _49.getElementHeight() + "px", "CalendarControlIFrame");
        }
    }
    this.hide = hide;
    function hide() {
        if (_13) {
            //setting the focue event starts for quick book link
            for (i = 0; i < document.forms[0].elements.length; i++) {
                if (document.forms[0].elements != null && document.forms[0].elements[i].name == "classCode") {
                    //alert('parv'+i+ ' '+document.forms[0].elements[i].type);
                    if (document.forms[0].elements[i].type != "hidden")
                        document.forms[0].elements[i].focus();
                    break;
                }
            }
            //setting the focu event ends for quick book link
            setProperty("display", "none");
            setElementProperty("display", "none", "CalendarControlIFrame");
            _13 = null;
        }

    }
}

var calendarControl = new CalendarControl();

function showCalendarControl(_4c, num) {

    calendarControl.show(_4c, num);
}
function hideCalendarControl() {
    calendarControl.hide();
}
function setCalendarControlDate(_4e, _4f, day) {
    //alert("parv ");
    calendarControl.setDate(_4e, _4f, day);
}
function changeCalendarControlYear(_51) {
    calendarControl.changeYear(_51);
}
function changeCalendarControlMonth(_52, _53) {
    calendarControl.changeMonth(_52, _53);
}
function closeCal(e) {
    if ($("CalendarControl").style.display == "block") {
        var _55 = 0;
        if (!e) {
            var e = window.event;
        }
        if (e.target) {
            _55 = e.target;
        } else {
            if (e.srcElement) {
                _55 = e.srcElement;
            }
        }
        if (_55.nodeType == 3) {
            _55 = _55.parentNode;
        }
        var _56;
        _56 = _55.className;
        var tag = _55.tagName;
        if (!Element.hasClassName(_55, "cal_control") && !Element.hasClassName(_55, "cal_dates")) {
            hideCalendarControl();
        }
    }
}
var browser = navigator.appName;
if (browser.indexOf("Microsoft") != -1) {
    //document.write("<iframe id='CalendarControlIFrame'src='javascript:false;' height=0 width=0 left=0 top=0  frameBorder='0' scrolling='no'></iframe>");
}
function getDateDifference1(journeyDate1, currentDate1) {
    journeyDate = new Date(journeyDate1.toGMTString());
    currentDate = new Date(currentDate1.toGMTString());

    Yearjn = takeYear1(journeyDate);
    Monthjn = journeyDate.getMonth();
    Dayjn = journeyDate.getDate(currentDate);
    Modjn = (Date.UTC(Yearjn, Monthjn, Dayjn, 0, 0, 0)) / 86400000;

    Yearcur = takeYear1(currentDate);
    Monthcur = currentDate.getMonth();
    Daycur = currentDate.getDate(currentDate);
    Modcur = (Date.UTC(Yearcur, Monthcur, Daycur, 0, 0, 0)) / 86400000;

    daysago = Math.floor(Modjn - Modcur);
    return daysago;

    //return Math.floor((journeyDate.getTime()-currentDate.getTime())/(24000*3600));
}
function takeYear1(theDate) {
    x = theDate.getYear();
    var y = x % 100;
    y += (y < 38) ? 2000 : 1900;
    return y;
}
function compareDates(_40, _41) {
    if (_40.getYear() < _41.getYear()) {
        return 1;
    } else {
        if ((_40.getYear() == _41.getYear()) && (_40.getMonth() < _41.getMonth())) {
            return 1;
        } else {
            if ((_40.getYear() == _41.getYear()) && (_40.getMonth() == _41.getMonth()) && (_40.getDate(currentDate) < _41.getDate(currentDate))) {
                return 1;
            } else {
                if (_40.getDate(currentDate) == _41.getDate(currentDate) && _40.getMonth() == _41.getMonth() && _40.getYear() == _41.getYear()) {
                    return 0;
                } else {

                    return -1;
                }
            }
        }
    }
}
function stringToDate(_39) {
    var day = _39.substring(0, _39.indexOf("index.html"));
    var _3b = _39.substring(_39.indexOf("index.html") + 1, _39.indexOf("index.html", _39.indexOf("index.html") + 1));
    var _3c = _39.substring(_39.indexOf("index.html", _39.indexOf("index.html") + 1) + 1, _39.length);
    if (_3c.length == 2) {
        _3c = "20" + _3c;
    }
    var _3d = new Date(currentDate);
    _3d.setFullYear(parseInt(_3c, 10), parseInt(_3b, 10) - 1, parseInt(day, 10));
    return _3d;
}


function datePast(_3e, _3f) {
    if (stringToDate(_3f) > stringToDate(_3e)) {
        return true;
    } else {
        return false;
    }
}


