function datebetween(mdate, sdate, edate)
{
		
	if ( (Date.parse(mdate) >= Date.parse(sdate)) && (Date.parse(mdate) <= Date.parse(edate)))
		return true ;
		
	return false ;
}

function datecmp(date1, date2)
{
	date1 = chkdate(date1);
	date2 = chkdate(date2);
	
	if ((date1 == false) && (date2 == false) )
		return 0;

	if (Date.parse(date1) < Date.parse(date2))
		return -1 ;
		// if date1 is less than date2 
	
	if (Date.parse(date1) == Date.parse(date2))
		return 0 ;
		// if dates are equal

	if (Date.parse(date1) > Date.parse(date2))
		return 1 ;
		// if date2 is less than date1

}


function chkdate(pdate) 
{
	var strDate = pdate;

	var strDateArray;
	var strDay;
	var strMonth;
	var strYear;
	var intday;
	var intMonth;
	var intYear;
	var booFound = false;
	var strSeparatorArray = new Array("-"," ","/",".");
	var intElementNr;
	var err = 0;

	if (strDate.length < 6) 
	{return false;}

	for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) 
	{	if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) 
		{
			strDateArray = strDate.split(strSeparatorArray[intElementNr]);
			if (strDateArray.length != 3) 
			{	err = 1;
				return false;
			}
			else 
			{
				strMonth = strDateArray[0];
				strDay = strDateArray[1];
				strYear = strDateArray[2];
			}
			booFound = true;
		}
	}

	if (booFound == false) 
	{	if (strDate.length>5) 
		{
			strMonth = strDate.substr(0, 2);
			strDay = strDate.substr(2, 2);
			strYear = strDate.substr(4);
		}
	}
	if (strYear.length == 2) 
	{	strYear = '20' + strYear;
	}

	intday = parseInt(strDay, 10);
	if (isNaN(intday)) 
	{
			err = 2;
		return false;
	}
	intMonth = parseInt(strMonth, 10);

	if (isNaN(intMonth)) 
	{
		for (i = 0;i<12;i++) 
		{
			if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) 
			{
				intMonth = i+1;
				strMonth = strMonthArray[i];
				i = 12;
			}
		}

		if (isNaN(intMonth)) 
		{
			err = 3;
			return false;
		}
	}
	intYear = parseInt(strYear, 10);
	if (isNaN(intYear)) 
	{
		err = 4;
		return false;
	}
	if (intMonth>12 || intMonth<1) 
	{
		err = 5;
		return false;
	}
	if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) 
	{
		err = 6;
		return false;
	}
	if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) 
	{
		err = 7;
		return false;
	}
	if (intMonth == 2) 
	{
		if (intday < 1) 
		{
			err = 8;
			return false;
		}
		if (LeapYear(intYear) == true) 
		{
			if (intday > 29) 
			{
				err = 9;	
				return false;
			}
		}
		else 
		{
			if (intday > 28) 
			{
				err = 10;
				return false;
			}
		}
	}

	return (intMonth + "/" + intday+"/" + strYear);
}

function LeapYear(intYear) 
{
	if (intYear % 100 == 0) 
	{	if (intYear % 400 == 0) 
		{ return true; }
	}
	else 
	{
		if ((intYear % 4) == 0) 
		{ return true; }
	}
return false;
}

function datecheck(e)
{
	//e = rebuildEvent(e);
	//var whichCode = (window.Event) ? e.which : e.keyCode;
	 
//test(e);
	/// e=window.event;
 	 //var whichCode = e.keycode ? e.keycode : e.which;
	//var whichCode = e.keyCode;
	e = (e) ? e : ((event) ? event : null);
	var whichCode = (e.keyCode) ? e.keyCode:e.charCode;
	 //if e.keycode=undefined then whichcode=e.which else whichcode=e.keycode
	 //var whichCode = (e.keycode=='undefined') ? e.which:e.keycode
	 
	var strCheck = '0123456789./';
	
	if (whichCode == 13) return true;  
	key = String.fromCharCode(whichCode);  // Get key value from key code
	
	if (strCheck.indexOf(key) == -1) 
	{
		e.returnValue =false;
		return false;
	}
}
function test(evt)
{

var keyCode;
if(evt == null)
{
keyCode = window.event.keyCode;
alert('1st');
}
else
{
keyCode = evt.keyCode;
alert('2st');
}

// alert(keyCode);

alert(String.fromCharCode(keyCode));




}
function schdatecheck(mobj, m)
{

	var m1 = m ;
	if (mobj.value == "" && m1 == "N" )
	{
		return true;
	}
	if (chkdate(mobj.value)== false )
	{
		alert("Please enter a valid date.");
		mobj.select();
		mobj.focus();
		return false;
	}
	mobj.value = chkdate(mobj.value);
	return true;
}

function limit_mts(cboHour,cboMin)
{

 if (document.getElementById(cboMin) != null )
 {
 
	if (document.getElementById(cboHour).value==17) // if its 5'o clock
	{
		
		for (i=31;i<=59;i++)
		{
			document.getElementById(cboMin).remove(32);
		}
	}
	else
	{
		if (document.getElementById(cboMin).options.length == 32) //if previos selection is 5'o clock
		{
			for (j=1;j<=59;j++)
			{
				document.getElementById(cboMin).remove(2);
			}
			for (i=1;i<=59;i++)
			{
				var opt = document.createElement("option");
				document.getElementById(cboMin).options.add(opt);
				if (i < 10)
				{
					opt.text = '0' + i;
					opt.value = '0' + i;
				}
				else
				{
					opt.text = i;
					opt.value = i;
				}
			}
		}		
	}	
 }
 
}

// Javascript function to rebuild an event object in a consistant way regardless 

// of the browser that it is used on.

// Returned object has the following fields:

// event: The original event object used

// type: The type of event

// target: The target of the event

// keyCode: The keyCode of the key pressed, if applicable.

// charCode: The character code of the key pressed, if applicable.

// character: The character represented by the charCode, if applicable.

function rebuildEvent(e)

{

	var event = new Object();

	// Get the right event object

	if (!e)

	{

		e = window.event;

	}

	

	// Store the event object

	event.event = e;

	

	// Store the type of the event

	event.type = e.type;

	

	// Store the target of the event

	if (e.target) 

	{

		event.target = e.target;

	}

	else if (e.srcElement)

	{

		event.target = e.srcElement;

	}

	if (event.target.nodeType == 3) // defeat Safari bug

	{

		event.target = event.target.parentNode;	

	}



	// Store the keycode of the event (if applicable)

	// Note that this might store the mouse button on a mouse event instead of being blank.

	if ('number' == typeof e.which)

	{

		event.keyCode = e.keyCode;

		event.charCode = e.which;

	}

	else if (e.keyCode)

	{

		event.keyCode = 0;

		event.charCode = e.keyCode;

	}

	if (event.charCode)

	{

		event.character = String.fromCharCode(event.charCode);

	}

	else

	{

		event.character = null;

	}

	

	// Store if any of alt, ctrl, shift or meta were pressed

	event.altKey = e.altKey;

	event.ctrlKey = e.ctrlKey;

	event.shiftKey = e.shiftKey;

	event.metaKey = e.metaKey || false;

	

	return event;

}