//Javascript name: My Date Time Picker
//Date created: 16-Nov-2003 23:19
//Scripter: TengYong Ng
//FileName: DateTimePicker.js
//Version: 0.8

// -----------------------------------------------------
// MASSIVELY modified and adapted by David Tichy for GGL
// -----------------------------------------------------



//Global variables
var DTP_dtToday=new Date();
var DTP_Cal=null;
var DTP_MonthName=["January", "February", "March", "April", "May", "June","July", 
	"August", "September", "October", "November", "December"];
var DTP_WeekDayName=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];	
var DTP_exDateTime;//Existing Date and Time

//Configurable parameters
var DTP_Config_MinuteIncrement=15;//minutes are displayed in increments of this number (must be divisible into 60)


var DTP_PathToImages="/core/imgs/";//path to image files
var DTP_PathToThemedStyleSheet="/core/style.css";//path to default stylesheet location
var DTP_WeekChar=2;//number of character for week day. if 2 then Mo,Tu,We. if 3 then Mon,Tue,Wed.
var DTP_DateSeparator="-";//Date Separator, you can change it to "/" if you want.
var DTP_TimeMode=12;//default DTP_TimeMode value. 12 or 24
var DTP_ShowLongMonth=true;//Show long month name in Calendar header. example: "January".
var DTP_ShowMonthYear=true;//Show Month and Year in Calendar header.
//end Configurable parameters
//end Global variable



function NewDTPCal(pCtrl,pFormat,pShowTime,pTimeMode,pShowYearScroll)
{
	// Destroy any open windows if this was already called.
	if(DTP_Cal!=null) 
	{
		if(DTP_Cal.Ctrl==pCtrl) return true; // Just reuse the object
				
		/* Clear the calendar div */
		document.getElementById('DateTimePicker_'+DTP_Cal.Ctrl).innerHTML='';
		document.getElementById('DateTimePicker_'+DTP_Cal.Ctrl).style.visibility='hidden';
		DTP_Cal.Ctrl=null;
		DTP_Cal=null;
	}
	
	DTP_Cal=new DTP_Calendar(DTP_dtToday);
	if ((pShowTime!=null) && (pShowTime))
	{
		DTP_Cal.ShowTime=true;
		if ((pTimeMode!=null) &&((pTimeMode=='12')||(pTimeMode=='24')))
		{
			DTP_TimeMode=pTimeMode;
		}		
	}	
	
	DTP_ShowYearScroll=pShowYearScroll;
	
	
	if (pCtrl!=null)
		DTP_Cal.Ctrl=pCtrl;
	if (pFormat!=null)
		DTP_Cal.Format=pFormat.toUpperCase();
	
	/*
	if(ThemedStyleSheet != '')
		DTP_PathToThemedStyleSheet = ThemedStyleSheet;
	*/
	
	DTP_exDateTime=document.getElementById(pCtrl).value;
	if (DTP_exDateTime!="" && DTP_exDateTime!=null)//Parse Date String
	{
		var Sp1;//Index of Date Separator 1
		var Sp2;//Index of Date Separator 2 
		var tSp1;//Index of Time Separator 1
		var tSp1;//Index of Time Separator 2
		var strMonth;
		var strDate;
		var strYear;
		var intMonth;
		var YearPattern;
		var strHour;
		var strMinute;
		//var strSecond;
		var currentLoop;
		//parse month
		Sp1=DTP_exDateTime.indexOf(DTP_DateSeparator,0)
		Sp2=DTP_exDateTime.indexOf(DTP_DateSeparator,(parseInt(Sp1)+1));
		
		if ((DTP_Cal.Format.toUpperCase()=="DDMMYYYY") || (DTP_Cal.Format.toUpperCase()=="DDMMMYYYY"))
		{
			strMonth=DTP_exDateTime.substring(Sp1+1,Sp2);
			strDate=DTP_exDateTime.substring(0,Sp1);
			strYear=DTP_exDateTime.substring(Sp2+1,Sp2+5);
			YearPattern=/^\d{4}$/;
			if (YearPattern.test(strYear))
			DTP_Cal.Year=parseInt(strYear,10);
		} else if ((DTP_Cal.Format.toUpperCase()=="MMDDYYYY") || (DTP_Cal.Format.toUpperCase()=="MMMDDYYYY")) {
			strMonth=DTP_exDateTime.substring(0,Sp1);
			strDate=DTP_exDateTime.substring(Sp1+1,Sp2);
			strYear=DTP_exDateTime.substring(Sp2+1,Sp2+5);
			YearPattern=/^\d{4}$/;
			if (YearPattern.test(strYear))
			DTP_Cal.Year=parseInt(strYear,10);
		} else if ((DTP_Cal.Format.toUpperCase()=="YYYYMMDD")) {
			strYear=DTP_exDateTime.substring(0,Sp1);
			strMonth=DTP_exDateTime.substring(Sp1+1,Sp2);
			strDate=DTP_exDateTime.substring(Sp2+1,Sp2+3);
			YearPattern=/^\d{4}$/;
			if (YearPattern.test(strYear))
			DTP_Cal.Year=parseInt(strYear,10);
		}
		if (isNaN(strMonth)) {
			intMonth=DTP_Cal.GetMonthIndex(strMonth);
		} else {
			intMonth=parseInt(strMonth,10)-1;	
		}
		if ((parseInt(intMonth,10)>=0) && (parseInt(intMonth,10)<12)) {
			DTP_Cal.Month=intMonth;
		}
		//end parse month
		//parse Date
		if ((parseInt(strDate,10)<=DTP_Cal.GetMonDays()) && (parseInt(strDate,10)>=1)) {
			DTP_Cal.Date=strDate;
		}
		//end parse Date
		//parse year
		//end parse year
		//parse time
		if (DTP_Cal.ShowTime==true)
		{
			tSp1=DTP_exDateTime.indexOf(":",0)
			tSp2=DTP_exDateTime.indexOf(":",(parseInt(tSp1)+1));
			strHour=DTP_exDateTime.substring(tSp1,(tSp1)-2);
			DTP_Cal.SetHour(strHour);
			strMinute=DTP_exDateTime.substring(tSp1+1,tSp2);
			
			strMinute=this.PadToTwoDigits((Math.ceil(strMinute/DTP_Config_MinuteIncrement)*DTP_Config_MinuteIncrement));
			if(strMinute=='60') { strMinute='00'; this.Hours++; }
			DTP_Cal.SetMinute(strMinute);
			//strSecond=DTP_exDateTime.substring(tSp2+1,tSp2+3);
			//DTP_Cal.SetSecond(strSecond);
			
			// Fix to get AM or PM as it exists
			tSp3=DTP_exDateTime.indexOf(" ",(parseInt(tSp2)+1));
			strAMPM=DTP_exDateTime.substring(tSp3+1,tSp3+3);
			if(strAMPM == 'PM') {
				//DTP_Cal.AMorPM = strAMPM;
				if(parseInt(strHour,10) < 12) { 
					DTP_Cal.Hours+=12; 
				}
				DTP_Cal.SetAmPm('PM');
			} else if(parseInt(strHour,10) > 12) {
//				DTP_Cal.Hours-=12;
				DTP_Cal.SetAmPm("PM");
			} else if(parseInt(strHour,10) == 0) {
				DTP_Cal.SetAmPm("AM");
			} else if(parseInt(strHour,10) == 12) {
				DTP_Cal.SetAmPm("PM");
			} else {
				//DTP_Cal.Hours=parseInt(strHour,10);
				DTP_Cal.SetAmPm("AM");
			}
		}	
	}
	DTP_RenderCal();
}

function DTP_RenderCal()
{
	var vCalHeader;
	var vCalData;
	var vCalTime;
	var i;
	var j;
	var SelectStr;
	var vDayCount=0;
	var vFirstDay;
	
	var contents;
	contents='';
	
	vCalHeader="<table border=\"0\" cellpadding=0 cellspacing=0 align=\"center\" valign=\"top\">\n";
	//Calendar header shows Month and Year
	if (DTP_ShowMonthYear) {
		if(DTP_ShowYearScroll) {
			vCalHeader+="<tr><td colspan=\"7\" valign=\"middle\" align=\"center\" style=\"background-color: #e0e0e0; cursor: pointer;\" onclick=\"DTP_Cal.IncYear();DTP_RenderCal();\"><img src=\""+DTP_PathToImages+"cal_up_arrow.png\" style=\"margin: 0px;\" /></td></tr>";
		}
		vCalHeader+="<tr><td colspan=\"7\" valign=\"middle\" align=\"center\" nowrap=\"nowrap\" class=\"monthyear\">";
		
		vCalHeader+="<div>";
		vCalHeader+="<img src=\""+DTP_PathToImages+"cal_right_arrow.png\" class=\"fright\" onclick=\"javascript:DTP_Cal.IncMonth();DTP_RenderCal();\" />";
		vCalHeader+="<img src=\""+DTP_PathToImages+"cal_left_arrow.png\" class=\"fleft\" onclick=\"javascript:DTP_Cal.DecMonth();DTP_RenderCal();\" />";
		vCalHeader+=DTP_Cal.GetMonthName(DTP_ShowLongMonth)+" "+DTP_Cal.Year+"</div>";
		vCalHeader+="</td></tr>\n";
		if(DTP_ShowYearScroll) {
			vCalHeader+="<tr><td colspan=\"7\" valign=\"middle\" align=\"center\" style=\"background-color: #e0e0e0; cursor: pointer;\" onclick=\"DTP_Cal.DecYear();DTP_RenderCal();\"><img src=\""+DTP_PathToImages+"cal_down_arrow.png\" style=\"margin: 0px;\" /></td></tr>";
		}
		
	}
	//Week day header
	vCalHeader+="<tr class=\"weekhead\">";
	for (i=0;i<7;i++)
	{
		vCalHeader+="<td align=\"center\">"+DTP_WeekDayName[i].substr(0,DTP_WeekChar)+"</td>";
	}
	vCalHeader+="</tr>";	
	contents+=vCalHeader;
	
	//Calendar detail
	CalDate=new Date(DTP_Cal.Year,DTP_Cal.Month);
	CalDate.setDate(1);
	vFirstDay=CalDate.getDay();
	vCalData="<tr>";
	for (i=0;i<vFirstDay;i++)
	{
		vCalData=vCalData+GenCell();
		vDayCount=vDayCount+1;
	}
	for (j=1;j<=DTP_Cal.GetMonDays();j++)
	{
		var strCell;
		vDayCount=vDayCount+1;
		if (j==DTP_Cal.Date)
		{
			//strCell=GenCell(j,true,SelDateColor);
			strCell=GenCell(j,true,'highlight');
		}
		else if ((j==DTP_dtToday.getDate())&&(DTP_Cal.Month==DTP_dtToday.getMonth())&&(DTP_Cal.Year==DTP_dtToday.getFullYear())) {
			//strCell=GenCell(j,true,TodayColor);//Highlight today's date
			strCell=GenCell(j,true,'today');//Highlight today's date
		}
		else
		{
			if (vDayCount%7==0) {
				//strCell=GenCell(j,false,SaturdayColor);
				strCell=GenCell(j,false,'weekend');
			} else if ((vDayCount+6)%7==0) {
				//strCell=GenCell(j,false,SundayColor);
				strCell=GenCell(j,false,'weekend');
			} else {
				//strCell=GenCell(j,null,WeekDayColor);
				strCell=GenCell(j,null,null);
			}

		}						
		vCalData=vCalData+strCell;

		if((vDayCount%7==0)&&(j<DTP_Cal.GetMonDays()))
		{
			vCalData=vCalData+"</tr>\n<tr>";
		}
	}
	while(vDayCount%7!=0) {
		vCalData+=GenCell();
		vDayCount++;
	}
	vCalData+"</tr>";
	contents+=vCalData;
	//Time picker
	if (DTP_Cal.ShowTime)
	{
		var showHour;
		showHour=DTP_Cal.getShowHour();		
		vCalTime="<tr>\n<td colspan='7' align='center'>";
		
		vCalTime+="<div style=\"font-size: 10px;\">";
		vCalTime+="</div>";
		
		vCalTime+="<table class=\"timepicker\" cellspacing=\"0\"><tr valign=\"bottom\">";
		vCalTime+="<td><img src=\""+DTP_PathToImages+"cal_up_arrow.png\" onmousedown=\"DTP_Cal.StartLoop('IncHour()');\" onmouseout=\"DTP_Cal.StopLoop();\" onmouseup=\"DTP_Cal.StopLoop();\" /></td>";
		vCalTime+="<td style=\"font-size: 4px;\">&nbsp;</td>";
		vCalTime+="<td><img src=\""+DTP_PathToImages+"cal_up_arrow.png\" onmousedown=\"DTP_Cal.StartLoop('IncMinute()');\" onmouseout=\"DTP_Cal.StopLoop();\" onmouseup=\"DTP_Cal.StopLoop();\" /></td>";
		vCalTime+="<td style=\"font-size: 4px;\">&nbsp;</td>";
		//vCalTime+="<td><img src=\""+DTP_PathToImages+"cal_up_arrow.png\" onmousedown=\"DTP_Cal.StartLoop('IncSecond()');\" onmouseout=\"DTP_Cal.StopLoop();\" onmouseup=\"DTP_Cal.StopLoop();\" /></td>";
		//vCalTime+="<td>&nbsp;</td>";
		vCalTime+="</tr>";
		
		vCalTime+="<tr valign=\"middle\">";
		vCalTime+="<td><input type='text' name='hour' id=\"popup_hour\" maxlength=2 readonly=\"readonly\" size=1 style=\"width: 22px; text-align:center;\" value="+showHour+" onchange=\"javascript:DTP_Cal.SetHour(this.value);\"></td>";
		vCalTime+="<td> : </td>";
		vCalTime+="<td><input type='text' name='minute' id=\"popup_minute\" maxlength=2 readonly=\"readonly\" size=1 style=\"width: 22px; text-align:center;\" value="+DTP_Cal.Minutes+" onchange=\"javascript:DTP_Cal.SetMinute(this.value)\"></td>";
		//vCalTime+="<td> : </td>";
		//vCalTime+="<td><input type='text' name='second' id=\"popup_second\" maxlength=2 readonly=\"readonly\" size=1 style=\"width: 22px; text-align:center;\" value="+DTP_Cal.Seconds+" onchange=\"javascript:DTP_Cal.SetSecond(this.value)\"></td>";
		if (DTP_TimeMode==12)
		{
			var SelectAm =(DTP_Cal.AMorPM == "AM")? "selected=\"selected\"":"";
			var SelectPm =(DTP_Cal.AMorPM == "PM")? "selected=\"selected\"":"";
						
			vCalTime+="<td>&nbsp;";
			vCalTime+="<select name=\"ampm\" id=\"popup_ampm\" onchange=\"javascript:DTP_Cal.SetAmPm(this.options[this.selectedIndex].value);\">";
			vCalTime+="<option "+SelectAm+" value=\"AM\">AM</option>";
			vCalTime+="<option "+SelectPm+" value=\"PM\">PM</option>";
			vCalTime+="</select>";
			vCalTime+="<td>";
		}
		
		vCalTime+="</tr>";
		vCalTime+="<tr valign=\"top\">";
		vCalTime+="<td><img src=\""+DTP_PathToImages+"cal_down_arrow.png\" onmousedown=\"DTP_Cal.StartLoop('DecHour()');\" onmouseout=\"DTP_Cal.StopLoop();\" onmouseup=\"DTP_Cal.StopLoop();\" /></td>";
		vCalTime+="<td style=\"font-size: 4px;\">&nbsp;</td>";
		vCalTime+="<td><img src=\""+DTP_PathToImages+"cal_down_arrow.png\" onmousedown=\"DTP_Cal.StartLoop('DecMinute()');\" onmouseout=\"DTP_Cal.StopLoop();\" onmouseup=\"DTP_Cal.StopLoop();\" /></td>";
		vCalTime+="<td style=\"font-size: 4px;\">&nbsp;</td>";
		//vCalTime+="<td><img src=\""+DTP_PathToImages+"cal_down_arrow.png\" onmousedown=\"DTP_Cal.StartLoop('DecSecond()');\" onmouseout=\"DTP_Cal.StopLoop();\" onmouseup=\"DTP_Cal.StopLoop();\" /></td>";
		//vCalTime+="<td>&nbsp;</td>";
		vCalTime+="</tr>";
		
		
		
		vCalTime+="\n</td>\n</tr>";
		contents+=vCalTime;
	}	
	//end time picker
	contents+="\n</table>";
	contents+="<div align=\"center\">";
	contents+="<input type=\"button\" value=\"Set This Date/Time\" style=\"margin-top: 5px; margin-bottom: 5px;\" onclick=\"javascript:DTP_Cal.sendDateToParent(0); DTP_Cal.sendClose();\" />";
	contents+="<br /><input type=\"button\" value=\"Clear Date\" style=\"margin-bottom: 10px;\" onclick=\"javascript:DTP_Cal.sendClear();\" />";
	contents+="</div>";
	var whichDiv = 'DateTimePicker_'+DTP_Cal.Ctrl;
	document.getElementById(whichDiv).innerHTML=contents;
}


function GenCell(pValue,pHighLight,pColor)//Generate table cell with value
{
	var PValue;
	var PCellStr;
	var classStr;

	if (pValue==null)
		PValue="";
	else
		PValue=pValue;
	
	if (pValue==null)
		return "<td class=\"caldates\">&nbsp;</td>";
	else if (pColor!=null)
		{classStr="caldate_"+pColor;}//bgcolor=\""+pColor+"\"";}
	else
		{classStr="";}
	
	PCellStr="<td class=\"caldates\"><a href=\"javascript:DTP_Cal.sendDateToParent('"+PValue+"');\" class=\""+classStr+"\">"+PValue+"</a></td>";
	return PCellStr;
}





/* =============================================== */
/* BEGIN NEW STUFF */
/* =============================================== */

function sendDateToParent(thisdate)
{
	var code;
	if(thisdate != 0) {
		DTP_Cal.Date=thisdate;
		code=DTP_Cal.FormatDate(thisdate);
	} else {
		code=DTP_Cal.FormatDate(DTP_Cal.Date);
	}
	
	document.getElementById(DTP_Cal.Ctrl).value=code;
	if (DTP_Cal.ShowTime)
	{
		document.getElementById(DTP_Cal.Ctrl).value+=' ';
		//if(DTP_Cal.AMorPM=='PM' && DTP_Cal.Hours < 24)
		if(DTP_Cal.AMorPM=='PM' && DTP_Cal.getShowHour() < 12)
		{ 
			document.getElementById(DTP_Cal.Ctrl).value+=DTP_Cal.PadToTwoDigits(parseInt(DTP_Cal.getShowHour(),10)+12);
		} 
		else if(DTP_Cal.AMorPM=='AM' && DTP_Cal.getShowHour() == 12)
		{ 
			document.getElementById(DTP_Cal.Ctrl).value+=DTP_Cal.PadToTwoDigits(0);
		} else {
			document.getElementById(DTP_Cal.Ctrl).value+=DTP_Cal.PadToTwoDigits(DTP_Cal.getShowHour()); 
		}
		//document.getElementById(DTP_Cal.Ctrl).value+=":"+DTP_Cal.Minutes+':'+DTP_Cal.Seconds;
		document.getElementById(DTP_Cal.Ctrl).value+=":"+DTP_Cal.Minutes+':00';
	}
	
	DTP_RenderCal();
}
DTP_Calendar.prototype.sendDateToParent=sendDateToParent;

function sendClear()
{
	document.getElementById(DTP_Cal.Ctrl).value='';
	DTP_Cal.sendClose();
}
DTP_Calendar.prototype.sendClear=sendClear;

function sendClose()
{
	document.getElementById('DateTimePicker_'+DTP_Cal.Ctrl).innerHTML='';
	document.getElementById('DateTimePicker_'+DTP_Cal.Ctrl).style.visibility='hidden';
	DTP_Cal=null;
}
DTP_Calendar.prototype.sendClose=sendClose;

/* =============================================== */
/* END NEW STUFF */
/* =============================================== */





function DTP_Calendar(pDate,pCtrl)
{
	//Properties
	this.Date=pDate.getDate();//selected date
	this.Month=pDate.getMonth();//selected month number
	this.Year=pDate.getFullYear();//selected year in 4 digits
	this.Hours=pDate.getHours();	

	this.Minutes=this.PadToTwoDigits((Math.ceil(pDate.getMinutes()/DTP_Config_MinuteIncrement)*DTP_Config_MinuteIncrement));
	if(this.Minutes=='60') { this.Minutes='00'; this.Hours++; }
	/*
	if (pDate.getMinutes()<10)
		this.Minutes="0"+pDate.getMinutes();
	else
		this.Minutes=pDate.getMinutes();
	*/
	/*
	if (pDate.getSeconds()<10)
		this.Seconds="0"+pDate.getSeconds();
	else		
		this.Seconds=pDate.getSeconds();
	*/
	this.MyWindow=window.self;
	this.Ctrl=pCtrl;
	this.Format="ddMMyyyy";
	this.Separator=DTP_DateSeparator;
	this.ShowTime=false;
	if (parseInt(this.Hours,10)<12)
	{
		this.SetAmPm('AM');
		//this.AMorPM="AM";
	} else {
		this.SetAmPm('PM');
		//this.AMorPM="PM";
	}
	
}

function GetMonthIndex(shortMonthName)
{
	for (i=0;i<12;i++)
	{
		if (DTP_MonthName[i].substring(0,3).toUpperCase()==shortMonthName.toUpperCase())
		{	return i;}
	}
}
DTP_Calendar.prototype.GetMonthIndex=GetMonthIndex;

function IncYear()
{	DTP_Cal.Year++;}
DTP_Calendar.prototype.IncYear=IncYear;

function DecYear()
{	DTP_Cal.Year--;}
DTP_Calendar.prototype.DecYear=DecYear;
	
function IncMonth()
{
	DTP_Cal.Month++;
	if(DTP_Cal.Month > 11)
	{
		DTP_Cal.Month = 0;
		DTP_Cal.Year++;
	}
}
DTP_Calendar.prototype.IncMonth=IncMonth;

function DecMonth()
{
	DTP_Cal.Month--;
	if(DTP_Cal.Month < 0)
	{
		DTP_Cal.Month = 11;
		DTP_Cal.Year--;
	}
}
DTP_Calendar.prototype.DecMonth=DecMonth;
	
function SwitchMth(intMth)
{	DTP_Cal.Month=intMth;}
DTP_Calendar.prototype.SwitchMth=SwitchMth;

function SetHour(intHour)
{	
	var MaxHour;
	var MinHour;
	MaxHour=23;MinHour=0;
	/*
	if (DTP_TimeMode==24)
	{	MaxHour=23;MinHour=0}
	else if (DTP_TimeMode==12)
	{	MaxHour=12;MinHour=1}
	else
		alert("DTP_TimeMode can only be 12 or 24");		
	*/
				
	var HourExp=new RegExp("^\\d\\d$");
	if (HourExp.test(intHour) && (parseInt(intHour,10)<=MaxHour) && (parseInt(intHour,10)>=MinHour))
	{	
		if ((DTP_TimeMode==12) && parseInt(intHour,10)>12)
		{
			DTP_Cal.Hours=parseInt(intHour,10);
			DTP_Cal.SetAmPm("PM");
		/*
		} 
		else if ((DTP_TimeMode==12) && (DTP_Cal.AMorPM=="PM"))
		{
			
			alert('1');
			if (parseInt(intHour,10)==12) {
				DTP_Cal.Hours=12;
			} else {
				DTP_Cal.Hours=parseInt(intHour,10)+12;
			}
		}	
		else if ((DTP_TimeMode==12) && (DTP_Cal.AMorPM=="AM"))
		{
			if (intHour==12) {
				intHour=0;
			}
			DTP_Cal.Hours=parseInt(intHour,10);
		}		
		else if (DTP_TimeMode==24) {
			DTP_Cal.Hours=parseInt(intHour,10);
		*/
		} else {
			DTP_Cal.Hours=parseInt(intHour,10);
			DTP_Cal.SetAmPm("AM");
		}
	} else {
		//alert('oops. something\'s munged up.');
	}
	
}
DTP_Calendar.prototype.SetHour=SetHour;

function SetMinute(intMin)
{
	var MinExp=new RegExp("^\\d\\d$");
	if (MinExp.test(intMin) && (intMin<60))
		DTP_Cal.Minutes=intMin;
}
DTP_Calendar.prototype.SetMinute=SetMinute;
/*
function SetSecond(intSec)
{	
	var SecExp=new RegExp("^\\d\\d$");
	if (SecExp.test(intSec) && (intSec<60))
		DTP_Cal.Seconds=intSec;
}
DTP_Calendar.prototype.SetSecond=SetSecond;
*/
function SetAmPm(pvalue)
{
	this.AMorPM=pvalue;
	if (this.Hours==24) {
		this.Hours=0;
	}
	/*
	if (pvalue=="PM")
	{
		
	}
	else if (pvalue=="AM")
	{
		//this.Hours-=12;
	}
	*/
}
DTP_Calendar.prototype.SetAmPm=SetAmPm;









/* =============================================== */
/* BEGIN NEW STUFF */
/* =============================================== */


function PadToTwoDigits(intValue)
{	
	intValue=parseInt(intValue, 10);
	if(intValue < 10) { 
		return "0"+intValue;
	} else {
		return intValue;
	}
}
DTP_Calendar.prototype.PadToTwoDigits=PadToTwoDigits;



function IncHour()
{	
	var prefix="";
	var hours;
	
	DTP_Cal.Hours++;
	if (DTP_Cal.Hours >= 24) {
		DTP_Cal.Hours=0;
	}
	
	hours=DTP_Cal.Hours;
	if (DTP_Cal.Hours<12) {
		//this.AMorPM="AM";
		DTP_Cal.SetAmPm("AM");
		//document.Calendar.ampm.selectedIndex=0;
		document.getElementById('popup_ampm').selectedIndex=0;
	} else {
		//this.AMorPM="PM";
		DTP_Cal.SetAmPm("PM");
		//document.Calendar.ampm.selectedIndex=1;
		document.getElementById('popup_ampm').selectedIndex=1;
		if(DTP_TimeMode==12 && DTP_Cal.Hours > 12) 
			hours=DTP_Cal.Hours-12
	}
	if(hours == 0) hours=12;
	if(hours < 10) { prefix="0"; DTP_Cal.Hours=prefix+parseInt(DTP_Cal.Hours,10); }
	//document.Calendar.hour.value=prefix+parseInt(hours,10);
	document.getElementById('popup_hour').value=prefix+parseInt(hours,10);
}
DTP_Calendar.prototype.IncHour=IncHour;

/* =============================================== */

function DecHour()
{	
	var prefix="";
	var hours;
	
	DTP_Cal.Hours--;
	if (DTP_Cal.Hours < 0) {
		DTP_Cal.Hours=23;
	}

	hours=DTP_Cal.Hours;
	if (DTP_Cal.Hours<12) {
		//this.AMorPM="AM";
		DTP_Cal.SetAmPm("AM");
		//document.Calendar.ampm.selectedIndex=0;
		document.getElementById('popup_ampm').selectedIndex=0;
	} else {
		//this.AMorPM="PM";
		DTP_Cal.SetAmPm("PM");
		//document.Calendar.ampm.selectedIndex=1;
		document.getElementById('popup_ampm').selectedIndex=1;
		if(DTP_TimeMode==12 && DTP_Cal.Hours > 12) 
			hours=DTP_Cal.Hours-12
	}
	if(hours == 0) hours=12;
	if(hours < 10) { prefix="0"; DTP_Cal.Hours=prefix+parseInt(DTP_Cal.Hours,10); }
	//document.Calendar.hour.value=prefix+parseInt(hours,10);
	document.getElementById('popup_hour').value=prefix+parseInt(hours,10);
}
DTP_Calendar.prototype.DecHour=DecHour;

/* =============================================== */

function IncMinute()
{	
	var prefix="";
	var minutes;
	
	DTP_Cal.Minutes+=DTP_Config_MinuteIncrement;
	DTP_Cal.Minutes=parseInt(DTP_Cal.Minutes,10);
	if (DTP_Cal.Minutes >= 60) {
		DTP_Cal.Minutes=0;
		DTP_Cal.IncHour();
	}
	minutes=DTP_Cal.Minutes;
	if(minutes < 10) { prefix="0"; DTP_Cal.Minutes=prefix+DTP_Cal.Minutes; }
	//document.Calendar.minute.value=prefix+minutes;
	document.getElementById('popup_minute').value=prefix+minutes;
}
DTP_Calendar.prototype.IncMinute=IncMinute;

/* =============================================== */

function DecMinute()
{	
	var prefix="";
	var minutes;
	
	DTP_Cal.Minutes-=DTP_Config_MinuteIncrement;
	if (DTP_Cal.Minutes < 0) {
		DTP_Cal.Minutes=(60-DTP_Config_MinuteIncrement);
		DTP_Cal.DecHour();
	}
	minutes=DTP_Cal.Minutes;
	if(minutes < 10) { prefix="0"; DTP_Cal.Minutes=prefix+DTP_Cal.Minutes; }
	//document.Calendar.minute.value=prefix+minutes;
	document.getElementById('popup_minute').value=prefix+minutes;
}
DTP_Calendar.prototype.DecMinute=DecMinute;

/* =============================================== */
/*
function IncSecond()
{	
	var prefix="";
	var seconds;
	
	DTP_Cal.Seconds++;
	DTP_Cal.Seconds=parseInt(DTP_Cal.Seconds,10);
	if (DTP_Cal.Seconds >= 60) {
		DTP_Cal.Seconds=0;
		DTP_Cal.IncMinute();
	}
	seconds=DTP_Cal.Seconds;
	if(seconds < 10) { prefix="0"; DTP_Cal.Seconds=prefix+DTP_Cal.Seconds; }
	//document.Calendar.second.value=prefix+seconds;
	document.getElementById('popup_second').value=prefix+seconds;
}
DTP_Calendar.prototype.IncSecond=IncSecond;
*/
/* =============================================== */
/*
function DecSecond()
{	
	var prefix="";
	var seconds;
	
	DTP_Cal.Seconds--;
	if (DTP_Cal.Seconds < 0) {
		DTP_Cal.Seconds=59;
		DTP_Cal.DecMinute();
	}
	seconds=DTP_Cal.Seconds;
	if(seconds < 10) { prefix="0"; DTP_Cal.Seconds = prefix+DTP_Cal.Seconds; }
	//document.Calendar.second.value=prefix+seconds;
	document.getElementById('popup_second').value=prefix+seconds;
}
DTP_Calendar.prototype.DecSecond=DecSecond;
*/

/* =============================================== */

function StartLoop(whatToTime)
{
	setTimeout(whatToTime, 0);	
	DTP_Cal.currentLoop=setTimeout("DTP_Cal.StartLoop('"+whatToTime+"')", 150);	
}
DTP_Calendar.prototype.StartLoop=StartLoop;
function StopLoop()
{
	clearTimeout(DTP_Cal.currentLoop);
}
DTP_Calendar.prototype.StopLoop=StopLoop;

/* =============================================== */
/* END NEW STUFF */
/* =============================================== */








function getShowHour()
{
	var finalHour;
    if (DTP_TimeMode==12)
    {
    	if (parseInt(this.Hours,10)==0)
		{
			this.AMorPM="AM";
			finalHour=parseInt(this.Hours,10)+12;	
		}
		else if (parseInt(this.Hours,10)==12)
		{
			this.AMorPM="PM";
			finalHour=12;
		}		
		else if (this.Hours>12)
		{
			this.AMorPM="PM";
			if ((this.Hours-12)<10)
				finalHour="0"+((parseInt(this.Hours,10))-12);
			else
				finalHour=parseInt(this.Hours,10)-12;	
		}
		else
		{
			this.AMorPM="AM";
			if (this.Hours<10)
				finalHour="0"+parseInt(this.Hours,10);
			else
				finalHour=this.Hours;	
		}
	}
	else if (DTP_TimeMode==24)
	{
		if (this.Hours<10)
			finalHour="0"+parseInt(this.Hours,10);
		else	
			finalHour=this.Hours;
	}	
	return finalHour;	
}					
DTP_Calendar.prototype.getShowHour=getShowHour;		

function GetMonthName(IsLong)
{
	var Month=DTP_MonthName[this.Month];
	if (IsLong)
		return Month;
	else
		return Month.substr(0,3);
}
DTP_Calendar.prototype.GetMonthName=GetMonthName;

function GetMonDays()//Get number of days in a month
{
	var DaysInMonth=[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
	if (this.IsLeapYear())
	{
		DaysInMonth[1]=29;
	}	
	return DaysInMonth[this.Month];	
}
DTP_Calendar.prototype.GetMonDays=GetMonDays;

function IsLeapYear()
{
	if ((this.Year%4)==0)
	{
		if ((this.Year%100==0) && (this.Year%400)!=0)
		{
			return false;
		}
		else
		{
			return true;
		}
	}
	else
	{
		return false;
	}
}
DTP_Calendar.prototype.IsLeapYear=IsLeapYear;

function FormatDate(pDate)
{
	if (this.Format.toUpperCase()=="DDMMYYYY") {
		return (pDate+DTP_DateSeparator+(this.Month+1)+DTP_DateSeparator+this.Year);
	} else if (this.Format.toUpperCase()=="DDMMMYYYY") {
		return (pDate+DTP_DateSeparator+this.GetMonthName(false)+DTP_DateSeparator+this.Year);
	} else if (this.Format.toUpperCase()=="MMDDYYYY") {
		return ((this.Month+1)+DTP_DateSeparator+pDate+DTP_DateSeparator+this.Year);
	} else if (this.Format.toUpperCase()=="MMMDDYYYY") {
		return (this.GetMonthName(false)+DTP_DateSeparator+pDate+DTP_DateSeparator+this.Year);
	} else if (this.Format.toUpperCase()=="YYYYMMDD") {
		return (this.Year+DTP_DateSeparator+PadToTwoDigits(this.Month+1)+DTP_DateSeparator+PadToTwoDigits(pDate));
	}
}
DTP_Calendar.prototype.FormatDate=FormatDate;	