// JavaScript Document

function cls_hexDate() {
	var dayNames = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
	var monthName = new Array("January","Febuary","March","April","May","June","July","August","September","October","November","December");
	
	date.prototype.toDay 		= _toDay
	date.prototype.convertDate 	= _convertDate
	date.prototype.monthName	= _monthName
	date.prototype.dayName		= _dayName
	date.prototype.addDay		= _addDay
	date.prototype.addMonth		= _addMonth
	date.prototype.date			= _date
	date.prototype.daysInMonth 	= _getMonthDayCount;
	date.prototype.isToday		= _isToday;
	date.prototype.copyDate		= _copy;
	
	date.prototype.weekDay		= _weekDayNum
	
	date.prototype.toUniversal	= _toUniversal;
	date.prototype.toLong		= _toLong;
	
	/*this.init = function () {
		hexAjax.prototype.date = new date()
		hexAjax.prototype.dateTime = date
	}*/
	
	this.dateTime = date
	
	function date() {		
		this.day = null
		this.month = null			//1 to 12
		this.year = null
		
		this.toDay()
	}
	
	function _copy(objDate) {
		this.year = objDate.date()[0]
		this.month = objDate.date()[1]
		this.day = objDate.date()[2]
	}
	function _date() {
		return new Array(this.year,this.month,this.day)	
	}
	
	function _weekDayNum(blnMonStart) {
		var tempDate = new Date()
		tempDate.setYear(this.year)
		tempDate.setMonth(this.month -1)
		tempDate.setDate(this.day)
		var intWeekDay = tempDate.getDay()
		
		intWeekDay = (blnMonStart) ? intWeekDay-1 : intWeekDay
		intWeekDay = (intWeekDay < 0) ? 6 : intWeekDay
		return intWeekDay
	}
	
	function _addDay(intDays) {
		this.day += (intDays != null) ? intDays : 1
		if (this.day > 28 || this.day < 1) {
			var tempDate = new Date()
			tempDate.setYear(this.year)
			tempDate.setMonth(this.month -1)
			tempDate.setDate(this.day)
			this.day = tempDate.getDate();
			this.month = tempDate.getMonth() + 1;
			this.year = tempDate.getYear()
		}
	}
	function _addMonth(intMonths) {
		intMonths = (intMonths != null) ? intMonths : 1
		var tempDate = new Date()
		tempDate.setYear(this.year)
		tempDate.setMonth(this.month -1 + intMonths)
		tempDate.setDate(this.day)
		this.day = tempDate.getDate();
		this.month = tempDate.getMonth() + 1;
		this.year = tempDate.getYear()
		
	}
	
	function _toDay(blnKeepDate) {
		var tempDate = new Date()
		blnKeepDate = (blnKeepDate == null) ? false : blnKeepDate
		if (!blnKeepDate) {
			this.day = tempDate.getDate();
			this.month = tempDate.getMonth() + 1;
			this.year = tempDate.getYear()
		}
		return new Array(tempDate.getYear(),(tempDate.getMonth()+1),tempDate.getDate())
		tempDate = null
	} 
	
	function _isToday() {
		var tempDate = new Date()
		if (tempDate.getYear() == this.year && ((tempDate.getMonth()+1) == this.month && (tempDate.getDate() == this.day))){
			return true;
		}else{
			return false;
		}
	}
	
	function _monthName (intFormat) {
		var strMonthName = (this.month != null) ? monthName[this.month-1] : null
		switch (intFormat) {
			case 1:
				strMonthName = strMonthName.substring(0,3)
			break;
			case 2:
				strMonthName = strMonthName.substring(0,1)
			break;
		}
		return strMonthName
	}
	
	function _getMonthDayCount(){
		var dtmTemp = new Date();		
		dtmTemp.setYear(this.year);
		dtmTemp.setMonth(this.month);
		dtmTemp.setDate(1);
		dtmTemp.setDate(0);
		return dtmTemp.getDate();
	}
	
	function _dayName(intFormat,intDay) {
		if (!isNaN(intDay)) {
			
			var strDayName = dayNames[intDay-1]
		}else{
			var tempDate = new Date()
			tempDate.setDate(this.day)
			tempDate.setMonth(this.month-1)
			tempDate.setYear(this.year)
			var strDayName = dayNames[tempDate.getDay()]
		}
		switch (intFormat) {
			case 1:
				strDayName = strDayName.substring(0,3)
			break;
			case 2:
				strDayName = strDayName.substring(0,1)
			break;
			case -1:
				strDayName = tempDate.getDay()
			break;
		}
		tempDate = null
		return strDayName
	}
	
	
	function _convertDate(objDate,intType) {
		var objReturn
		switch (intType) {
			case 0:
				if (objDate != null && (/.*-.*-.*/.test(objDate))) {
					objDate = objDate.split("-")
					objReturn = new Array(objDate[0],objDate[1],objDate[2])
				}
			break;
			case 1:
				if (objDate != null && (/.*\/.*\/.*/.test(objDate))) {
					objDate = objDate.split("/")
					objReturn = new Array(parseInt(objDate[2]),objDate[1],(objDate[0]))
				}
			break;
		}
		this.day = Math.abs(objReturn[2])
		this.month = Math.abs(objReturn[1])
		this.year = Math.abs(objReturn[0])
		
		return objReturn
	}
	
	function AccessDateToUnversal(strValue) {
		if (strValue != null && (/.*\/.*\/.*/.test(strValue))) {
			strValue = strValue.split("/")
			return strValue[2] + "-" + strValue[1] + "-" + strValue[0]
		}else{
			return strValue
		}
	}
	
	function AccessDateToLong(strValue) {
		if (strValue != null && (/.*\/.*\/.*/.test(strValue))) {
			strValue = strValue.split("/")
			return strValue[0] + " " + monthName[strValue[1]-1] + " " + strValue[2]
		}else{
			return strValue
		}
	}
	
	function _toUniversal() {
		var strZero = "0"
		var strMonth = (parseInt(this.month)<10) ? strZero + parseInt(this.month).toString() : this.month
		var strDay	 = (parseInt(this.day)<10) ? strZero + this.day.toString() : this.day
		return this.year + "-" + strMonth + "-" + strDay
	}
	
	function _toLong() {
		return this.day + " " + this.monthName() + " " + this.year
	}
	
	
	
}