﻿// JScript File

function getObj2(objID) {
    if (document.getElementById) { return document.getElementById(objID); }
    else if (document.all) { return document.all[objID]; }
    else if (document.layers) { return document.layers[objID]; }
}

function checkClick2(e) {
    e ? evt = e : evt = event;
    CSE = evt.target ? evt.target : evt.srcElement;
    if (getObj2('fc2'))
        if (!isChild2(CSE, getObj2('fc2'))) {
        getObj2('fc2').style.display = 'none';
    }
}

function isChild2(s, d) {
    while (s) {
        if (s == d)
            return true;
        s = s.parentNode;
    }
    return false;
}

function Left2(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;
}

function Top2(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;
}

document.write('<table id="fc2" style="position:absolute;border-collapse:collapse;background:#FFFFFF;border:1px solid #ABABAB;display:none" cellpadding=2>');
document.write('<tr style=" background:url(./_ui/images/clndrbg.jpg); height:20px;"><td style="cursor:pointer; background:url(./_ui/Images/arrowLeft.gif);background-repeat:no-repeat;background-position: 5px 5px;" onclick="csubm2()"></td><td colspan=5 id="mns2" align="center" style="font:bold 12px Arial; Color:black; padding-top: 3px;"></td><td align="right" style="cursor:pointer; background:url(./_ui/Images/arrowRight.gif);background-repeat:no-repeat;background-position: 10px 5px;" onclick="caddm2()"></td></tr>');
document.write('<tr class="DaysOfWeek_WebBlue"><td class="DaysOfWeek_WebBlue" align=center style="font:12px Arial">S</td><td class="DaysOfWeek_WebBlue" align=center style="font:12px Arial">M</td><td align=center style="font:12px Arial" class="DaysOfWeek_WebBlue">T</td><td align=center style="font:12px Arial" class="DaysOfWeek_WebBlue">W</td><td align=center style="font:12px Arial" class="DaysOfWeek_WebBlue">T</td><td align=center style="font:12px Arial" class="DaysOfWeek_WebBlue">F</td><td align=center style="font:12px Arial" class="DaysOfWeek_WebBlue">S</td></tr>');
for (var kkk = 1; kkk <= 6; kkk++) {
    document.write('<tr>');
    for (var tt2 = 1; tt2 <= 7; tt2++) {
        num2 = 7 * (kkk - 1) - (-tt2);
        document.write('<td id="dateBox' + num2 + '" style="width:24px;height:18px">&nbsp;</td>');
    }
    document.write('</tr>');
}
document.write('</table>');

document.all ? document.attachEvent('onclick', checkClick2) : document.addEventListener('click', checkClick2, false);


// Calendar script
var now2 = new Date;
var sccm2 = now2.getMonth();
var sccy2 = now2.getFullYear();
var ccm2 = now2.getMonth();
var ccy2 = now2.getFullYear();

var updobj2;
function lcs1(ielem2) {
    updobj2 = ielem2;
    getObj2('fc2').style.left = Left2(ielem2);
    getObj2('fc2').style.top = Top2(ielem2) + ielem2.offsetHeight;
    getObj2('fc2').style.display = '';
    //getObj2('ddlDropOffTime').style.display= 'none';

    // First check date is valid
    curdt = ielem2.value;
    curdtarr = curdt.split('/');
    isdt = true;
    for (var k = 0; k < curdtarr.length; k++) {
        if (isNaN(curdtarr[k]))
            isdt = false;
    }
    if (isdt & (curdtarr.length == 3)) {
        ccm2 = curdtarr[1] - 1;
        ccy2 = curdtarr[2];
        prepcalendar2(curdtarr[0], curdtarr[1] - 1, curdtarr[2]);
    }

}

function evtTgt2(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;
}
function EvtObj2(e) { if (!e) e = window.event; return e; }
function cs_over2(e) {
    evtTgt2(EvtObj2(e)).style.background = '#D3EDF6';
}
function cs_out2(e) {
    evtTgt2(EvtObj2(e)).style.background = '#FFFFFF';
}
function cs_click2(e) {
    //    alert(evtTgt2(EvtObj2(e)).id.substring(2,evtTgt2(EvtObj2(e)).id.length));
    updobj2.value = calvalarr2[evtTgt2(EvtObj2(e)).id.substring(7, evtTgt2(EvtObj2(e)).id.length)];
    getObj2('fc2').style.display = 'none';
    getObj2('ddlDropOffTime').style.display = 'inline';
}

var mn2 = new Array('JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC');
var mnn2 = new Array('31', '28', '31', '30', '31', '30', '31', '31', '30', '31', '30', '31');
var mnl2 = new Array('31', '29', '31', '30', '31', '30', '31', '31', '30', '31', '30', '31');
var calvalarr2 = new Array(42);

function f_cps2(obj) {
    obj.style.background = '#FFFFFF';
    obj.style.font = '10px Arial';
    obj.style.color = '#333333';
    obj.style.textAlign = 'center';
    obj.style.textDecoration = 'none';
    obj.style.border = '1px solid #cccccc';
    obj.style.cursor = 'pointer';
}

function f_cpps2(obj) {
    obj.style.background = '#FFFFFF';
    obj.style.font = '10px Arial';
    obj.style.color = '#CCCCCC';
    obj.style.textAlign = 'center';
    obj.style.textDecoration = 'line-through';
    obj.style.border = '1px solid #cccccc';
    obj.style.cursor = 'default';
}

function f_hds2(obj) {
    obj.style.background = '#A7DAEF';
    obj.style.font = 'bold 10px Arial';
    obj.style.color = '#333333';
    obj.style.textAlign = 'center';
    obj.style.border = '1px solid #cccccc';
    obj.style.cursor = 'pointer';
}

// day selected
function prepcalendar2(hd, cm, cy) {
    now = new Date();
    sd = now.getDate();
    td = new Date();
    td.setDate(1);
    td.setFullYear(cy);
    td.setMonth(cm);
    cd = td.getDay();
    getObj2('mns2').innerHTML = mn2[cm] + ' ' + cy;
    marr = ((cy % 4) == 0) ? mnl2 : mnn2;
    for (var d = 1; d <= 42; d++) {
        f_cps2(getObj2('dateBox' + parseInt(d)));
        if ((d >= (cd - (-1))) && (d <= cd - (-marr[cm]))) {
            dip = ((d - cd < sd) && (cm == sccm2) && (cy == sccy2));
            htd = ((hd != '') && (d - cd == hd));
            if (dip)
                f_cpps2(getObj2('dateBox' + parseInt(d)));
            else if (htd)
                f_hds2(getObj2('dateBox' + parseInt(d)));
            else
                f_cps2(getObj2('dateBox' + parseInt(d)));

            getObj2('dateBox' + parseInt(d)).onmouseover = (dip) ? null : cs_over2;
            getObj2('dateBox' + parseInt(d)).onmouseout = (dip) ? null : cs_out2;
            getObj2('dateBox' + parseInt(d)).onclick = (dip) ? null : cs_click2;

            getObj2('dateBox' + parseInt(d)).innerHTML = d - cd;
            calvalarr2[d] = '' + (d - cd) + '/' + (cm - (-1)) + '/' + cy;
        }
        else {
            getObj2('dateBox' + d).innerHTML = '&nbsp;';
            getObj2('dateBox' + parseInt(d)).onmouseover = null;
            getObj2('dateBox' + parseInt(d)).onmouseout = null;
            getObj2('dateBox' + parseInt(d)).style.cursor = 'default';
        }
    }

    HidePrevMonthImage2();
}

function HidePrevMonthImage2() {
    var d = new Date()
    currentDate = d.toDateString();
    var splitDate = currentDate.split(" ");
    var splitSelectedDate = getObj2('mns2').innerHTML.split(" ");
    //	document.write (splitSelectedDate[0].toLowerCase());
    //	document.write (splitDate[1].toLowerCase());

    if (splitSelectedDate[0].toLowerCase() == splitDate[1].toLowerCase()) {
        //PreMonth2
        //document.getElementById("PreMonth2").style.visibility = 'hidden'; 

    }
    else {
        //document.getElementById("PreMonth2").style.visibility = 'visible'; 
    }

}

prepcalendar2('', ccm2, ccy2);
//getObj2('fc2'+cc).style.visibility='hidden';

function caddm2() {
    marr = ((ccy2 % 4) == 0) ? mnl2 : mnn2;

    ccm2 += 1;
    if (ccm2 >= 12) {
        ccm2 = 0;
        ccy2++;
    }
    cdayf2();
    prepcalendar2('', ccm2, ccy2);
}

function csubm2() {
    marr = ((ccy2 % 4) == 0) ? mnl2 : mnn2;

    ccm2 -= 1;
    if (ccm2 < 0) {
        ccm2 = 11;
        ccy2--;
    }
    cdayf2();
    prepcalendar2('', ccm2, ccy2);
}

function cdayf2() {
    if ((ccy2 > sccy2) | ((ccy2 == sccy2) && (ccm2 >= sccm2)))
        return;
    else {
        ccy2 = sccy2;
        ccm2 = sccm2;
        //cfd2=scfd;
        cfd = "";
    }
}

function ShowCalendar2(txtBoxName) {
    var txtBox = document.getElementById(txtBoxName);
    lcs1(txtBox);
}


function setDropOffValue2() {

    var pickupDate = document.getElementById("pickupDateTime").value;
    var DropOffDate = new Date();
    var splitPickup = pickupDate.split("/")
    DropOffDate.setDate(splitPickup[0]);
    DropOffDate.setMonth(splitPickup[1] - 1);
    DropOffDate.setFullYear(splitPickup[2]);
    DropOffDate.setDate(DropOffDate.getDate() + 1);
    var month1 = DropOffDate.getMonth() + 1;
    document.getElementById("DropOffDateTime").value = DropOffDate.getDate() + "/" + month1 + "/" + DropOffDate.getFullYear();

    curdt = document.getElementById("DropOffDateTime").value;
    curdtarr = curdt.split('/');
    for (var k = 0; k < curdtarr.length; k++) {
        if (isNaN(curdtarr[k])) {
            document.getElementById("DropOffDateTime").value = "dd/mm/yy";
        }
    }
}



//vb. 28-aug-2009: position the calendar object properly when in IE mode.
function MoveMe(sID) {
    var oCal = document.getElementById(sID);
    if (oCal) {
        var oBrowser = navigator.userAgent.toLowerCase();
        if (oBrowser.indexOf("msie") != -1) {
            oCal.style.left = parseInt(oCal.offsetLeft) - 140;
            oCal.style.top = parseInt(oCal.offsetTop) + 1;
        }
    }
}
