/* ====================================================
//
// Client side date script utilities.
//
=====================================================*/
// Page released 2007-07-18

function date_onmousewheel(x) {
    if (event.srcElement.id == document.activeElement.getAttribute('id')) {
        if (ValidDate(x.value)) {
            x.value = configureDate(x.value);
            if (event.wheelDelta >= 120) {
                x.value = addDays(x.value, 1);
            } else if (event.wheelDelta <= -120) {
                x.value = addDays(x.value, -1);
            }
        }
        return false;
    }
}

function dateDiff(interval, date1, date2) {

    if (typeof (date1) == "string") {
        date1 = new Date(date1);
    }
    if (typeof (date2) == "string") {
        date2 = new Date(date2);
    }

    switch (interval) {
        case "d":
            date1.setHours(0);
            date1.setMinutes(0);
            date1.setSeconds(0);
            date1.setMilliseconds(0);

            date2.setHours(0);
            date2.setMinutes(0);
            date2.setSeconds(0);
            date2.setMilliseconds(0);

            var days = (date2.valueOf() - date1.valueOf()) / 86400000;
            return parseInt(format(days, 0));
            break;

        case "h":
            date1.setMinutes(0);
            date1.setSeconds(0);
            date1.setMilliseconds(0);

            date2.setMinutes(0);
            date2.setSeconds(0);
            date2.setMilliseconds(0);

            return (date2.valueOf() - date1.valueOf()) / 3600000;
            break;

        case "n":
            date1.setSeconds(0);
            date1.setMilliseconds(0);

            date2.setSeconds(0);
            date2.setMilliseconds(0);

            return (date2.valueOf() - date1.valueOf()) / 60000;
            break;
        case "s":

            date1.setMilliseconds(0);

            date2.setMilliseconds(0);

            return (date2.valueOf() - date1.valueOf()) / 1000;
            break;
    }
}

//Pass the formatDate function either a date or time.  Currently will not accept a date-time field.
//Expects the date or time to already be validated.
function formatDate(varDate, strFormat) {
    var strNewDate = "";
    var strSubFormat;

    if (varDate == null || varDate.length == 0) {
        return varDate;
    }

    strSubFormat = strFormat.substr(0, 1);
    for (var i = 1; i < strFormat.length; i++) {
        if (strFormat.substr(i, 1) != strFormat.substr(i - 1, 1)) {
            strNewDate += getDatePart(varDate, strSubFormat, strFormat);
            strSubFormat = strFormat.substr(i, 1);
        } else {
            strSubFormat += strFormat.substr(i, 1);
        }
    }
    strNewDate += getDatePart(varDate, strSubFormat, strFormat);

    return strNewDate;
}

function getDatePart(varDate, strFormat, strFullFormat) {
    var x;

    switch (strFormat) {
        case "h": 
            x = parseInt(getHours(varDate), 10);
            if (strFullFormat.indexOf("t") > -1 && x > 12) {
                return (x - 12).toString();
            } else if (strFullFormat.indexOf("t") > -1 && x == 0) {
                return "12";
            } else {
                return x.toString();
            }
            break;
        case "hh": 
            x = parseInt(getHours(varDate), 10);
            if (strFullFormat.indexOf("t") > -1 && x > 12) {
                x -= 12;
            } else if (strFullFormat.indexOf("t") > -1 && x == 0) {
                return "12";
            }
            if (x < 10)
                return "0" + x.toString();
            else
                return x.toString();
            break;
        case "n":
            return parseInt(getMinutes(varDate), 10).toString();
            break;
        case "nn":
            x = parseInt(getMinutes(varDate), 10);
            if (x < 10)
                return "0" + x.toString();
            else
                return x.toString();
            break;
        case "s":
            return parseInt(getSeconds(varDate), 10).toString();
            break;
        case "ss":
            x = parseInt(getSeconds(varDate), 10);
            if (x < 10)
                return "0" + x.toString();
            else
                return x.toString();
            break;
        case "t":
            x = parseInt(getHours(varDate), 10);
            if (x >= 12) {
                return "p";
            } else {
                return "a";
            }
            break;
        case "tt":
            x = parseInt(getHours(varDate), 10);
            if (x >= 12 || varDate.indexOf("PM") > 0) {
                return "PM";
            } else {
                return "AM";
            }
            break;
        case "d":
            return parseInt(getDate(varDate), 10).toString();
            break;
        case "dd":
            x = parseInt(getDate(varDate), 10);
            if (x < 10)
                return "0" + x.toString();
            else
                return x.toString();
            break;
        case "ddd":
            return getDayName(getDay(varDate), true);
            break;
        case "dddd":
            return getDayName(getDay(varDate), false);
            break;
        case "m":
            return parseInt(getMonth(varDate), 10).toString();
            break;
        case "mm":
            x = parseInt(getMonth(varDate), 10);
            if (x < 10)
                return "0" + x.toString();
            else
                return x.toString();
            break;
        case "mmm":
            return getMonthName(getMonth(varDate), true);
            break;
        case "mmmm":
            return getMonthName(getMonth(varDate), false);
            break;
        case "yy":
            return getYear(varDate).toString().substr(2, 2);
            break;
        case "yyyy":
            return getYear(varDate);
            break;
        case "w":
            return getDay(varDate);
            break;
        case "ww":
            return getWeek(varDate);
            break;
        default:
            return strFormat;
    }
}

function addDays(varDate, daysToAdd) {
    var dt = new Date(varDate);
    dt.setDate(dt.getDate() + daysToAdd);
    return dt.getDate() + " " + getMonthName(dt.getMonth() + 1) + " " + dt.getFullYear();
}

function addMonths(varDate, monthsToAdd) {
    var dt = new Date(varDate);
    dt.setMonth(dt.getMonth() + monthsToAdd);
    return dt.getDate() + " " + getMonthName(dt.getMonth() + 1) + " " + dt.getFullYear();
}

function addYears(varDate, yearsToAdd) {
    var dt = new Date(varDate);
    dt.setYear(dt.getFullYear() + yearsToAdd);
    return dt.getDate() + " " + getMonthName(dt.getMonth() + 1) + " " + dt.getFullYear();
}

function month_onblur(x, blnAbbreviate) {

    if (x.value.length == 0) {
        return false;
    }

    if (isNaN(x.value)) {

        if (x.value.length >= 3) {
            // check the text entered to see if valid month
            var month = getMonthNumber(x.value);

            if (month != -1) {
                x.value = getMonthName(month, blnAbbreviate);
                return true;
            }
        }
    } else {
        // check to see if number entered is a valid month and return the valid month name
        var month = parseInt(x.value);

        if (month >= 1 && month <= 12) {
            x.value = getMonthName(month, blnAbbreviate);
            return true;
        }
    }

    alert("Invalid month entered.\n\nYou can enter the month in any of the following formats;\n\n1 to 12\njan to dec\njanuary to december.");
    x.focus();
    x.select();
    return false;
}

function date_onblur(x, strFormat) {
    if (x.value != "") {
        if (typeof (strFormat) == "undefined")
            strFormat = "d mmmm yyyy";

        if (x.value.toUpperCase() == "T") {
            x.value = formatDate(getCurrentDate(), strFormat);
            return true;
        } else if (x.value.toUpperCase() == "Y") {
            x.value = formatDate(addDays(getCurrentDate(), -1), strFormat);
            return true;
        } else if (ValidDate(x.value)) {
            x.value = formatDate(configureDate(x.value), strFormat);
            return true;
        } else {
            alert("Invalid Date");
            x.focus();
            x.select();
        }
    }
    return false;
}

function time_onblur(x, strFormat) {
    if (x.value != "") {
        // use default time format if not specified
        if (typeof (strFormat) == "undefined")
            strFormat = "hh:nn:ss";
        // use current time if code used
        if (x.value.toUpperCase() == "N" || x.value.toUpperCase() == "T") {
            x.value = formatDate(getCurrentTime(), strFormat);
            return true;
        }

        x.value = x.value.replace(/[.]+/g, ":");

        // add separator if not supplied
        if ((x.value.length > 2) && (x.value.lastIndexOf(":") == -1)) {
            x.value = x.value.substring(0, x.value.length - 2) + ':' + x.value.substring(x.value.length - 2, x.value.length);
        }
        // validate time
        if (ValidTime(x.value)) {
            x.value = formatDate(myTime(x.value), strFormat);
            return true;
        }
        // deal with error
        alert("Invalid Time");
        x.focus();
        x.select();
    }
    return false;
}
function shorttime_onblur(x) {
    return time_onblur(x, "hh:nn");
}

function datetime_onblur(x) {
    if (x.value != "") {

        //get date part.
        var datebreak = x.value.lastIndexOf(' ');

        if (datebreak == -1)
            datebreak = x.value.length;

        var datepart = x.value.slice(0, datebreak);
        var timepart = x.value.slice(datebreak + 1);

        if (datepart.length > 0 && timepart.length == 0)
            timepart = getCurrentTime();

        if (ValidDate(datepart)) {

            if (ValidTime(timepart)) {
                x.value = myDate(datepart) + " " + myTime(timepart);
                return true;
            }
            else {
                alert("Invalid Time");
                x.focus();
                x.select();
            }

        } else {
            alert("Invalid Date");
            x.focus();
            x.select();
        }

    }

    return false;
}

function getCurrentUTCDateTime() {
    var dt = new Date();
    return dt.getUTCDate() + " " + getMonthName(dt.getUTCMonth() + 1) + " " + dt.getUTCFullYear() + " " + myTime(dt.getUTCHours() + ":" + dt.getUTCMinutes() + ":" + dt.getUTCSeconds());
}

function getCurrentUTCDate() {
    var dt = new Date();
    return dt.getUTCDate() + " " + getMonthName(dt.getUTCMonth() + 1) + " " + dt.getUTCFullYear();
}


function getCurrentDateTime() {
    var dt = new Date();
    return dt.getDate() + " " + getMonthName(dt.getMonth() + 1) + " " + dt.getFullYear() + " " + myTime(dt.getHours() + ":" + dt.getMinutes() + ":" + dt.getSeconds());
}

function getCurrentDate() {
    var dt = new Date();
    return dt.getDate() + " " + getMonthName(dt.getMonth() + 1) + " " + dt.getFullYear();
}

function getCurrentTime() {
    var dt = new Date();
    return myTime(dt.getHours() + ":" + dt.getMinutes() + ":" + dt.getSeconds());
}

function myLongDate(varDate) {
    if (varDate == "null" || varDate == null || varDate == "")
        return varDate;

    varDate = configureDate(varDate);

    return getDayName(getDay(varDate)) + ", " + getDate(varDate) + " " + getMonthName(getMonth(varDate)) + " " + getYear(varDate);
}

function myDate(varDate) {
    if (varDate == "null" || varDate == null || varDate == "")
        return varDate;

    varDate = configureDate(varDate);

    return getDate(varDate) + " " + getMonthName(getMonth(varDate)) + " " + getYear(varDate);
}

function myMedDate(varDate) {
    if (varDate == "null" || varDate == null || varDate == "")
        return varDate;

    varDate = configureDate(varDate);

    return getDate(varDate) + " " + getMonthName(getMonth(varDate), true) + " " + getYear(varDate);
}

function myShortDate(varDate) {
    if (varDate == "null" || varDate == null || varDate == "")
        return varDate;

    varDate = configureDate(varDate);

    return getDate(varDate) + "/" + getMonth(varDate) + "/" + getYear(varDate);
}

function myTime(varDate) {
    var h, m, s;

    if (varDate == "null" || varDate == null || varDate == "")
        return varDate;

    varDate = configureTime(varDate);

    h = getHours(varDate);
    if (h.length < 2)
        h = "0" + h;

    m = getMinutes(varDate);
    if (m.length == 0)
        m = "00";
    else if (m.length < 2)
        m = "0" + m;

    s = getSeconds(varDate);
    if (s.length < 2)
        s = "0" + s;

    return h + ":" + m + ":" + s;
}

function myShortTime(varDate) {
    var h, m, s;

    if (varDate == "null" || varDate == null || varDate == "")
        return varDate;

    varDate = configureTime(varDate);

    h = getHours(varDate);
    if (h.length < 2)
        h = "0" + h;

    m = getMinutes(varDate);
    if (m.length == 0)
        m = "00";
    else if (m.length < 2)
        m = "0" + m;

    return h + ":" + m;
}

function getWeekNo(varDate, blnAbbreviate) {
    var y;
    var w;
    var m;
    var weekNo;

    varDate = configureDate(varDate);

    y = getYear(varDate);
    m = getMonth(varDate);
    w = getWeek(varDate);

    switch (w) {
        case 1:
            if (m == 12)
                y = y + 1;
            break;
        case 52, 53:
            if (m == 1)
                y = y - 1;
            break;
    }

    weekNo = (y * 100) + w;
    weekNo = weekNo.toString();

    if (blnAbbreviate)
        return weekNo.substring(4, 6);
    else
        return weekNo;
}

function configureDateTime(varDate) {
    var datePart;
    var timePart;
    var dateBreak;

    dateBreak = varDate.lastIndexOf(' ');

    if (dateBreak == -1) {
        dateBreak = varDate.length;
    }

    datePart = varDate.slice(0, dateBreak);
    timePart = varDate.slice(dateBreak + 1);

    return configureDate(datePart) + " " + configureTime(timePart);
}

function configureDate(varDate) {

    varDate = varDate.replace(/[-\.\/ ]+/g, " ");

    if (varDate.length == 6 && !isNaN(varDate))
        varDate = varDate.substring(0, 2) + " " + varDate.substring(2, 4) + " " + varDate.substring(4, 6);
    else if (varDate.length == 4 && !isNaN(varDate))
        varDate = varDate.substring(0, 2) + " " + varDate.substring(2, 4);

    varDate = getDate(varDate) + " " + getMonthName(getMonth(varDate)) + " " + getYear(varDate);
    //next two lines convert 32 Jan to 1 Feb, etc.
    varDate = new Date(varDate);
    varDate = formatUTCDate(varDate);

    return getDate(varDate) + " " + getMonthName(getMonth(varDate)) + " " + getYear(varDate);
}

function configureTime(varDate) {
    var blnPM = false;
    var blnAM = false;

    varDate = varDate.toLowerCase();
    if (varDate.indexOf("p") > -1) {
        blnPM = true;
    }
    if (varDate.indexOf("a") > -1) {
        blnAM = true;
    }

    varDate = varDate.replace(/pm|p.m|p m|am|a.m|a m|p|a/g, "");
    varDate = varDate.replace(/[-\.\/ ]+/g, ":");

    if (isNaN(varDate.replace(/[:]+/g, "")))
        return "NaN";

    varDate = getHours(varDate) + ":" + getMinutes(varDate) + ":" + getSeconds(varDate);
    varDate = new Date("1 Jan 2000 " + varDate);

    if (blnPM && varDate.getHours() < 12) {
        varDate.setHours(varDate.getHours() + 12);
    } else if (blnAM && varDate.getHours() >= 12) {
        varDate.setHours(varDate.getHours() - 12);
    }
    varDate = formatUTCDate(varDate);
    //subtract 1 January 2000 from the front to leave the time
    varDate = varDate.substr(15, varDate.length - 15);

    return getHours(varDate) + ":" + getMinutes(varDate) + ":" + getSeconds(varDate);
}

function getHours(varDate) {
    if (varDate.indexOf(":") > -1)
        return varDate.substring(0, varDate.indexOf(":"));
    else
        return varDate;
}

function getMinutes(varDate) {
    var varRight;

    if (varDate.indexOf(":") > -1) {
        varRight = varDate.substring(varDate.indexOf(":") + 1, varDate.length);

        if (varRight.indexOf(":") > -1)
            varRight = varRight.substring(0, varRight.indexOf(":"));
        else
            varRight = varRight;

        if (varRight != "")
            return varRight;
        else
            return "0";
    } else {
        return "0";
    }
}

function getSeconds(varDate) {
    var varRight;

    if (varDate.indexOf(":") > -1) {
        varRight = varDate.substring(varDate.indexOf(":") + 1, varDate.length);

        if (varRight.indexOf(":") > -1) {
            varRight = varRight.substring(varRight.indexOf(":") + 1, varRight.length);

            if (varRight.indexOf(":") > -1)
                return varRight.substring(0, varRight.indexOf(":"));
            else
                return varRight;

            if (varRight != "")
                return varRight;
            else
                return "0";
        } else
            return "0";
    } else {
        return "0";
    }
}

// gets the day of the month
function getDate(varDate) {
    if (varDate.indexOf(" ") > -1)
        return varDate.substring(0, varDate.indexOf(" "));
    else
        return varDate;
}

// gets the weekno based on the first four day week
function getWeek(varDate) {
    var dayofWeek;
    var startofyear;
    var timedifference;
    var dayofyear;
    var weekofyear;
    var newDate;

    startofyear = new Date("1 January " + getYear(varDate));

    dayofWeek = startofyear.getDay()
    if (dayofWeek == 0)
        dayofWeek = 7;
    dayofWeek--;
    startofyear = startofyear.valueOf();

    newDate = new Date(varDate);
    newDate = newDate.valueOf();

    timedifference = newDate - startofyear - (new Date(varDate).getTimezoneOffset() - new Date("1 January " + getYear(varDate)).getTimezoneOffset()) * 60000;
    dayofyear = timedifference / 86400000 + 1;
    dayofyear = Math.floor(dayofyear);
    dayofyear += dayofWeek;
    weekofyear = dayofyear / 7;
    weekofyear = Math.ceil(weekofyear);

    if (dayofWeek >= 4) {
        if (weekofyear == 1)
            weekofyear = getWeek("31 December " + (getYear(varDate) - 1));
        else
            weekofyear--;
    }

    if (weekofyear == 53) {
        startofyear = new Date("1 January " + (getYear(varDate) + 1));
        dayofWeek = startofyear.getDay();
        if (dayofWeek == 0)
            dayofWeek = 7;
        dayofWeek--;

        if (dayofWeek < 4)
            weekofyear = 1;
    }

    return weekofyear;
}

// gets the month of the year 1-12
function getMonth(varDate) {
    var varRight;
    var varMonth;

    if (varDate.indexOf(" ") > -1) {
        varRight = varDate.substring(varDate.indexOf(" ") + 1, varDate.length);

        if (varRight.indexOf(" ") > -1)
            varRight = varRight.substring(0, varRight.indexOf(" "));
        else
            varRight = varRight;

        if (varRight != "") {
            varMonth = parseInt(varRight, 10);

            if (isNaN(varMonth))
                return getMonthNumber(varRight);
            else
                return varMonth;
        } else {
            varDate = new Date();
            return varDate.getMonth() + 1;
        }
    } else {
        varDate = new Date();
        return varDate.getMonth() + 1;
    }
}

// gets the yyyy formatted year
function getYear(varDate) {
    var varRight;
    var varYear;
    var varCurrentDate = new Date();
    var varCurrentYear;

    varRight = varDate.substring(varDate.indexOf(" ") + 1, varDate.length);

    if (varRight.indexOf(" ") > -1) {
        varRight = varRight.substring(varRight.indexOf(" ") + 1, varRight.length);

        if (varRight.indexOf(" ") > -1)
            varRight = varRight.substring(0, varRight.indexOf(" "));
        else
            varRight = varRight;

        if (varRight != "") {
            if (varRight.length <= 2) {
                varYear = parseInt(varRight, 10);
                varCurrentYear = varCurrentDate.getFullYear().toString();
                varCurrentYear = parseInt(varCurrentYear.substr(2, 2), 10);

                if (varYear < (30 + varCurrentYear))
                    return 2000 + varYear;
                else
                    return 1900 + varYear;
            } else {
                varYear = parseInt(varRight, 10);
                return varYear;
            }
        } else {
            return varCurrentDate.getFullYear();
        }
    } else {
        return varCurrentDate.getFullYear();
    }
}

// validates a date
function ValidDate(varDate) {
    varDate = configureDate(varDate);

    varDate = new Date(varDate);

    if (isNaN(varDate))
        return false;
    else
        return true;
}

// validates a time
function ValidTime(varDate) {
    varDate = configureTime(varDate);

    varDate = new Date("1 Jan 2000 " + varDate);

    if (isNaN(varDate))
        return false;
    else
        return true;
}

function getMonthName(lngMonth, blnAbbreviate) {
    var strMonthNames;

    if (blnAbbreviate)
        strMonthNames = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
    else
        strMonthNames = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");

    return strMonthNames[lngMonth - 1];
}


// returns the month of the year 1-12 based on the inputed month name
function getMonthNumber(varMonth) {
    var strMonthNames;

    varMonth = varMonth.toLowerCase();

    if (varMonth.length == 3)
        strMonthNames = new Array("jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec");
    else
        strMonthNames = new Array("january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december");

    for (var i = 0; i < strMonthNames.length; i++)
        if (varMonth == strMonthNames[i])
        return i + 1;

    return -1;
}

// formats a UTC formatted date, to a "dd monthname yyyy hh:nn:ss" formatted date.
// Dates must follow month/day/year format.
function formatUTCDate(varDate) {
    var newDate;

    if (varDate == "null" || varDate == null || varDate == "")
        return varDate;

    // Uncomment the following line if you are having hassles with the date changing
    // due to timezone or daylight saving differences:

    //varDate = localiseButKeepSameDateTime(varDate + "");

    varDate = new Date(varDate);

    newDate = varDate.getDate() + " ";
    newDate += getMonthName(varDate.getMonth() + 1) + " ";
    newDate += varDate.getFullYear() + " ";
    if (varDate.getHours() < 10)
        newDate += "0" + varDate.getHours() + ":";
    else
        newDate += varDate.getHours() + ":";
    if (varDate.getMinutes() < 10)
        newDate += "0" + varDate.getMinutes() + ":";
    else
        newDate += varDate.getMinutes() + ":";
    if (varDate.getSeconds() < 10)
        newDate += "0" + varDate.getSeconds();
    else
        newDate += varDate.getSeconds();

    return newDate;
}

// formats a UTC formatted date, to a "hh:nn:ss" formatted date.
function formatUTCTime(varDate) {
    var newDate;

    if (varDate == "null" || varDate == null || varDate == "")
        return varDate;

    varDate = new Date(varDate);

    if (varDate.getHours() < 10)
        newDate = "0" + varDate.getHours() + ":";
    else
        newDate = varDate.getHours() + ":";
    if (varDate.getMinutes() < 10)
        newDate += "0" + varDate.getMinutes() + ":";
    else
        newDate += varDate.getMinutes() + ":";
    if (varDate.getSeconds() < 10)
        newDate += "0" + varDate.getSeconds();
    else
        newDate += varDate.getSeconds();

    return newDate;
}

// returns the day of the week where Sunday = 0
function getDay(varDate) {
    var newDate = new Date(varDate);
    return newDate.getDay();
}

// RETURNS DAY NAME, WHERE SUNDAY = 0
function getDayName(lngDay, blnAbbreviate) {
    var strDayNames;

    if (blnAbbreviate)
        strDayNames = new Array("Sun", "Mon", "Tue", "Wed", "Thr", "Fri", "Sat");
    else
        strDayNames = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");

    return strDayNames[lngDay];
}

// RETURNS DAY INDEX FROM DAY NAME, WHERE SUNDAY = 0
function getDayIndex(strDayName) {
    var strDayIndexes;

    strDayIndexes = new Array();
    strDayIndexes["Sunday"] = 0;
    strDayIndexes["Monday"] = 1;
    strDayIndexes["Tuesday"] = 2;
    strDayIndexes["Wednesday"] = 3;
    strDayIndexes["Thursday"] = 4;
    strDayIndexes["Friday"] = 5;
    strDayIndexes["Saturday"] = 6;

    return strDayIndexes[strDayName];
}

function isLeapYear(year) {
    return (((year % 4) == 0) && ((year % 100) != 0) || ((year % 400) == 0));
}

function getLastDateOfMonth(varDate) {
    if (varDate == "null" || varDate == null || varDate == "") {
        return varDate;
    }

    varDate = addDays(varDate, (getDatePart(varDate, "d") * -1) + 1);
    varDate = addMonths(varDate, 1);
    varDate = addDays(varDate, -1);

    return varDate;
}


function localiseButKeepSameDateTime(dateString) {
    // localise the timezeone but keep the date and time the same
    var dt = new Date(dateString); //Date.parse(d);
    var diff = getTimeZone(dateString) - getTimeZone(dt + "");
    dt = new Date((dt * 1) + (diff * 3600 * 1000));
    return dt;
}

function getTimeZone(d) {
    var p1 = d.substr(d.indexOf("UTC") + 3);
    var p2 = p1.substr(0, p1.indexOf(" ")) * 1;
    var p3 = p2 + "";
    p3 = p3.substr(0, 2);
    return p3 * 1;
}

function validateDateTime(obj) {//Assumes date format dd mmm yyy HH mm tt
    if (obj.value.length == 0) {
        return true;
    }

    var datebreak = obj.value.lastIndexOf(' ');

    if (datebreak == -1)
        datebreak = obj.value.length;

    var datepart = obj.value.slice(0, datebreak);
    var timepart = obj.value.slice(datebreak + 1);

    var newDate = formatDate(datepart, 'dd mmm yyyy')
    var newTime = formatDate(timepart, 'h:nntt')

    if (!ValidDate(newDate) || !ValidTime(newTime)) {
        alert("Invalid Date/Time");
        obj.focus();
        return false;
    }

    var newDateTime = newDate + ' ' + newTime;

    if (newDateTime.indexOf("Nan") > 0) {
        alert("Invalid Date/Time");
        obj.focus();
    }
    else {
        obj.value = newDateTime
    }
}

