﻿function DateObject()
{    
    var _Day = (_Day) ? _Day : 0 ;
    var _Month = (_Month) ? _Month : 0 ;
    var _Year = (_Year) ? _Year : 0 ;
    var _Hour = (_Hour) ? _Hour : 0 ;
    var _Minute = (_Minute) ? _Minute : 0 ;
    var _Second = (_Second) ? _Second : 0 ;
    var _Millisecond = (_Millisecond) ? _Millisecond : 0 ;
    
    var date = CreateDateObject(_Day, _Month, _Year, _Hour, _Minute, _Second, _Millisecond);
}
DateObject.prototype.Day = function(i) {
    var value = (i == null) ? this._Day : i ;
	this._Day = value;
	return value;
}
DateObject.prototype.Month = function(i) {
	var value = (i == null) ? this._Month : i ;
	this._Month = value;
	return value;
}
DateObject.prototype.Year = function(i) {
	var value = (i == null) ? this._Year : i ;
	this._Year = value;
	return value;
}
DateObject.prototype.Hour = function(i) {
    var value = (i == null) ? this._Hour : i ;
	this._Hour = value;
	return value;
}
DateObject.prototype.Minute = function(i) {
	var value = (i == null) ? this._Minute : i ;
	this._Minute = value;
	return value;
}
DateObject.prototype.Second = function(i) {
	var value = (i == null) ? this._Second : i ;
	this._Second = value;
	return value;
}
DateObject.prototype.Millisecond = function(i) {
	var value = (i == null) ? this._Millisecond : i ;
	this._Millisecond = value;
	return value;
}

function CreateDateObject(d, m, y, hh, mm, ss, ms)
{ 
	var value = new Date(y, m-1, d, hh, mm, ss, ms);
	return value;
}

function ValidateDate(str_date, str_format, str_delim)
{
    /*
    acceptable value in str_format:
    DD      - 2 digit day
    MM      - 2 digit month
    YY      - 2 digit year
    YYYY    - 4 digit year
    */
    var regex;
    var str_regex = "/";
    var boo_value = false;
    var arr_format = str_format.split(str_delim.toString().toUpperCase());
    
    if(arr_format.length != 3)
    {
        return false;
    }
    for(i = 0; i < arr_format.length; i++)
    {
        if(arr_format[i] == "DD")
        {
            str_regex += "(0[1-9]|1[0-9]|2[0-9]|3[0-1])";
        }
        if(arr_format[i] == "MM")
        {
            str_regex += "(0[1-9]|1[0-2])";
        }
        if(arr_format[i] == "YY")
        {
            str_regex += "(\\d{2})";
        }
        if(arr_format[i] == "YYYY")
        {
            str_regex += "(20\\d{2})";
        }
        if(i < (arr_format.length -1))
        {
            str_regex += "\\" + str_delim;
        }
    }
    
    str_regex += "$/";
    regex = eval(str_regex);

    if(regex.test(str_date))
    {
        boo_value = true;
    }
    return boo_value;
}

function ValidateTime(str_time, str_format, str_Delim)
{
    /*
    acceptable value in str_format:
    hh      - 2 digit hours
    mm      - 2 digit minutes
    ss      - 2 digit seconds
    ms      - 2 digit milliseconds
    */
}
