﻿Date.prototype.getDayName = function() {
    switch (this.getDay()) {
        case 0:
            return "Sunday";
            break;
        case 1:
            return "Monday";
            break;
        case 2:
            return "Tuesday";
            break;
        case 3:
            return "Wednesday";
            break;
        case 4:
            return "Thursday";
            break;
        case 5:
            return "Friday";
            break;
        case 6:
            return "Saturday";
            break;
    }
}

Date.prototype.getMonthName = function() {
    switch (this.getMonth()) {
        case 0:
            return "January";
            break;
        case 1:
            return "February";
            break;
        case 2:
            return "March";
            break;
        case 3:
            return "April";
            break;
        case 4:
            return "May";
            break;
        case 5:
            return "June";
            break;
        case 6:
            return "July";
            break;
        case 7:
            return "August";
            break;
        case 8:
            return "September";
            break;
        case 9:
            return "October";
            break;
        case 10:
            return "November";
            break;
        case 11:
            return "December";
            break;
    }

}

Date.prototype.getMonthShortName = function() {
    switch (this.getMonthName().toUpperCase()) {
        case "JULY":
            return "July";
            break;
        case "SEPTEMBER":
            return "Sept.";
            break;
        default:
            return this.getMonthName().substring(0, 3) + ".";
            break;
    }
}

Date.prototype.FormatDate = function(value, Format) {

    var Dt = new Date(Date.parse(value));
    if (typeof (value) != String) {

    }
    else {
        return NaN;
    }

    Format = Format.toString().replace("DDDD", Dt.getDayName());
    Format = Format.toString().replace("DD", Dt.getDay());
    Format = Format.toString().replace("MMMM", Dt.getMonthName());
    Format = Format.toString().replace("MMM", Dt.getMonthShortName());
    Format = Format.toString().replace("yyyy", Dt.getFullYear());
    Format = Format.toString().replace("hh", (Dt.getHours() > 12) ? ((Dt.getHours() - 12).toString().length > 1) ? (Dt.getHours() - 12).toString() : "0" + (Dt.getHours() - 12).toString() : Dt.getHours());
    Format = Format.toString().replace("mm", Dt.getMinutes());
    Format = Format.toString().replace("ss", Dt.getSeconds().toString().length > 1 ? Dt.getSeconds().toString() : "0" + Dt.getSeconds().toString());
    Format = Format.toString().replace("tt", (Dt.getHours() > 12) ? "PM" : "AM");
    return Format
}