//<script language="JScript">


/* *****************************************************************************
   Dependency : date_const.js
*/   


/* *****************************************************************************
    Description : Getting the date in Date object and returning the string date    
    Parameter   : _dateObj     - Internal Date.
                  dateDisplayObj_- Display Date                
    Return      : The date in string in dd-mm-yyyy
		  The date in string in dd/mm/yyyy.
*/   

//-------------------------------------------------------------------------------

/* *****************************************************************************
   Initialization of Day Arrays
   Access in the form of duDayOfWeek[index1][index2]
     index1 - 0 for short name, 1 for long name.
     index2 - 0 to 6. 0 for Sunday.
*/
var duDayOfWeek = new Array(
    new Array('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'),
    new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday')
  );


/* *****************************************************************************
   Initialization of Month Arrays.
   Access in the form of duMonthNames[index1][index2]
     index1 - 0 for short name, 1 for long name.
     index2 - 0 to 11. 0 for January.
*/
var duMonthNames = new Array(
  new Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 
            'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'),
  new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 
            'August', 'September', 'October', 'November', 'December')
  );

/* *****************************************************************************
   Initialization of Number of Day for a Month Arrays.
   Access in the form of duMonthDays[index1]
     index1 - 0 to 11. 0 for January.
*/
var duMonthDays = new Array( 
    /* Jan */ 31,     /* Feb */ 29, /* Mar */ 31,     /* Apr */ 30, 
    /* May */ 31,     /* Jun */ 30, /* Jul */ 31,     /* Aug */ 31, 
    /* Sep */ 30,     /* Oct */ 31, /* Nov */ 30,     /* Dec */ 31 );

var DATE_FORMAT_DD_MM_YYYY_DISPLY = 1;
var DATE_FORMAT_MM_DD_YYYY = 2;
var DATE_FORMAT_DD_MMM_YYYY = 3;
var DATE_FORMAT_MMM_DD_YYYY = 4;
var DATE_FORMAT_DD_MMMM_YYYY = 5;
var DATE_FORMAT_MMMM_DD_YYYY = 6;
var DATE_FORMAT_DD_MM_YYYY = 7;
var DATE_FORMAT_MM_YYYY =8;
var DATE_FORMAT_MMMM_YY = 9;

//-----------------------------------------------------------------------------

/* *****************************************************************************
    Description : To get date through passing mil.sec(numeric) values   
    Parameter   : DateVal     - Date mil.sec(numeric) values 
                          
    Return      : The current date in string in Selected Format
*/   


function fnCurDate(formatType_, outSeparator_) {
	var lCDate = new Date;
	var lDate,lMonth,lYear;
	var formattedDate;
	lDate=lCDate.getDate();
	lMonth=lCDate.getMonth()+1;
	lYear=lCDate.getFullYear();	
  

	if(formatType_ == DATE_FORMAT_DD_MM_YYYY_DISPLY)
	{
	
		formattedDate=lDate+outSeparator_+lMonth+outSeparator_+lYear;
	}
	else if(formatType_ == DATE_FORMAT_MM_DD_YYYY)
	{
		formattedDate = lMonth + outSeparator_ + 
		             lDate + outSeparator_ + 
		             lYear;
	}


	else if(formatType_ == DATE_FORMAT_DD_MMM_YYYY)
	{
		
		lMonth=lMonth-1
		formattedDate = lDate + outSeparator_ + 
		             getMonthName(lMonth , 0) + outSeparator_ + 
		             lYear;
	}
	else if(formatType_ == DATE_FORMAT_MMM_DD_YYYY)
	{

		lMonth=lMonth-1
		formattedDate = getMonthName(lMonth, 0) + " " + 
		             lDate + ", " + 		             
		             lYear;
	}
	else if(formatType_ == DATE_FORMAT_DD_MMMM_YYYY)
	{

		lMonth=lMonth-1
		formattedDate = lDate + outSeparator_ + 
		             getMonthName(lMonth, 1) + outSeparator_ + 
		             lYear;
	}
	else if(formatType_ == DATE_FORMAT_MMMM_DD_YYYY)
	{

		lMonth=lMonth-1
		formattedDate = getMonthName(lMonth, 1) + " " + 
		             lDate + ", " + 		             
		             lYear;
	}
	else if(formatType_ == DATE_FORMAT_DD_MM_YYYY)
	{
		formattedDate = lDate + outSeparator_ + 
		             lMonth + outSeparator_ + 
		             lYear;
	}

	else if(formatType_ == DATE_FORMAT_MM_YYYY)
	{
		formattedDate = lMonth + outSeparator_ + lYear;
	}

	else if(formatType_ == DATE_FORMAT_MMMM_YY)
	{
		formattedDate = duMonthNames[1][lMonth-1] + outSeparator_ + lYear;
	}
	return formattedDate;


}


/* *****************************************************************************
    Description : To get date through passing mil.sec(numeric) values   
    Parameter   : DateVal     - Date mil.sec(numeric) values 
                          
    Return      : The date in string in Selected Format
*/   

function DateFormatDisp(formatType_, outSeparator_, DateVal) {
	
	var lDate,lMonth,lYear;
	var formattedDate;
	DayMonYr = new Date(Number(DateVal));
	lDate=DayMonYr.getDate();
	lMonth=DayMonYr.getMonth()+1;
	lYear=DayMonYr.getFullYear();

	if(formatType_ == DATE_FORMAT_DD_MM_YYYY_DISPLY)
	{
	
		formattedDate=lDate+outSeparator_+lMonth+outSeparator_+lYear;
	}
	else if(formatType_ == DATE_FORMAT_MM_DD_YYYY)
	{
		formattedDate = lMonth + outSeparator_ + 
		             lDate + outSeparator_ + 
		             lYear;
	}


	else if(formatType_ == DATE_FORMAT_DD_MMM_YYYY)
	{

		lMonth=lMonth-1
		formattedDate = lDate + outSeparator_ + 
		             getMonthName(lMonth , 0) + outSeparator_ + 
		             lYear;
	}
	else if(formatType_ == DATE_FORMAT_MMM_DD_YYYY)
	{

		lMonth=lMonth-1
		formattedDate = getMonthName(lMonth, 0) + " " + 
		             lDate + ", " + 		             
		             lYear;
	}
	else if(formatType_ == DATE_FORMAT_DD_MMMM_YYYY)
	{

		lMonth=lMonth-1
		formattedDate = lDate + outSeparator_ + 
		             getMonthName(lMonth, 1) + outSeparator_ + 
		             lYear;
	}
	else if(formatType_ == DATE_FORMAT_MMMM_DD_YYYY)
	{

		lMonth=lMonth-1	
		formattedDate = getMonthName(lMonth, 1) + " " + 
		             lDate + ", " + 		             
		             lYear;
	}
	else if(formatType_ == DATE_FORMAT_DD_MM_YYYY)
	{
		formattedDate = lDate + outSeparator_ + 
		             lMonth + outSeparator_ + 
		             lYear;
	}
	else if(formatType_ == DATE_FORMAT_MM_YYYY)
	{
		formattedDate = lMonth + outSeparator_ + lYear;
	}

	else if(formatType_ == DATE_FORMAT_MMMM_YY)
	{
		formattedDate = duMonthNames[1][lMonth-1] + outSeparator_ + lYear;
	}
	
	return formattedDate;


}

/* *****************************************************************************
    Description : Returning the name of month. Eg : Jan, Feb...
    Parameter   : _month  - The month. Eg : 0 for January.
                  _fullName - 0 to get short name (Eg :Jan).
                              1 to get long name (Eg : January).
    Return      : Name of the day of week.
*/   
function getMonthName(_month, _fullName)
{
    return duMonthNames[_fullName][_month];
}

function curDateNum(cDteObj_) {
	fnCurDate("",cDteObj_);
	var lCurDate,lCDte;
	lCurDate=(cDteObj_.value).split("/");
	var CurDate = new Date(lCurDate[2],lCurDate[1]-1,lCurDate[0]);
	
	lCDte=CurDate.getTime();
	return lCDte;
}


function getDateNum(cDteObj_, outSeparator_) {
	var formattedDate;
	var lDate,lDateval;

	lDate=(cDteObj_.value).split(outSeparator_);
	var lDateval = new Date(lDate[2],lDate[1]-1,lDate[0]);
	formattedDate = lDateval.getTime();
	return formattedDate;

}

/* *****************************************************************************
    Description : To get date from server and convert it to require format
    Parameter   : cDteval_ = server date value
                          
    Return      : The date in string in Selected Format
*/

function SvrDate(cDteVal_) {

    var mth = cDteVal_.getMonth()-1+2;
    var dt_str = '';
    
    if(cDteVal_.getDate() < 10)
    {
		dt_str += '0' + cDteVal_.getDate();
	}
	else
		dt_str +=cDteVal_.getDate();
	
	dt_str += '/';
	
	if(mth < 10)
    {
		dt_str += '0' + mth;
	}
	else
		dt_str += mth;
	dt_str += '/' + cDteVal_.getFullYear();
	
	return dt_str;

}
//</script>