
// date validation functions
// these functions are includes in the cal_core.js, cal_core_mpage.js and the datevalidation.js files. When a date field is included with the form, one
// of these files will be included and they will always have these standard functions

var MONTH_NAMES=new Array('January','February','March','April','May','June','July','August','September','October','November','December','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
var DAY_NAMES=new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sun','Mon','Tue','Wed','Thu','Fri','Sat');
function LZ(x) {return(x<0||x>9?"":"0")+x}


ie4 = (document.all)? true:false
ns6 = (!ie4 && document.getElementById)? true:false
ns4 = (document.layers)? true:false


function daysinthemonth(totaldays,mn,dn,yn,turnon){
//alert('' + mn + ',' + dn + ',' + yn + ',' + turnon + '');
if (turnon=="yes"){

	if (ns6){
		if (document.getElementsByName(mn)){
			monthname=document.getElementsByName(mn)[0]; 
			dayname=document.getElementsByName(dn)[0];
			yearname=document.getElementsByName(yn)[0];
		}
	}
	if (ie4){
	//alert(document.all[mn]);
		if (document.all[mn]){
		//alert('yes1');
			if (document.all[mn][0].name){monthname=document.all[mn][0];dayname=document.all[dn][0];yearname=document.all[yn][0]}
			else if (document.all[mn].name){monthname=document.all[mn];dayname=document.all[dn];yearname=document.all[yn]}
		}
	}
	if (ns4){
		for (i=0;i<pages.length;i++){
			if (eval('document.'+pages[i][2]+'.document.'+pages[i][2]+'_form.'+mn)){
				monthname=eval('document.'+pages[i][2]+'.document.'+pages[i][2]+'_form.'+mn);
				dayname=eval('document.'+pages[i][2]+'.document.'+pages[i][2]+'_form.'+dn);
				yearname=eval('document.'+pages[i][2]+'.document.'+pages[i][2]+'_form.'+yn);
			}
		}
	}
	totaldays=parseFloat(totaldays);
	


	
	
	if (totaldays>28){
		var daysinmonth=totaldays;
		if (monthname.options[monthname.selectedIndex].value == "February"){
			if (yearname[yearname.selectedIndex].value%400==0 || (yearname[yearname.selectedIndex].value%4 == 0 && yearname[yearname.selectedIndex].value%100!=0) ){daysinmonth =29}
			else {daysinmonth=28}
		}
		if (monthname.options[monthname.selectedIndex].value == "April" || monthname.options[monthname.selectedIndex].value == "June" || monthname.options[monthname.selectedIndex].value == "September" || monthname.options[monthname.selectedIndex].value == "November"){
			if (totaldays>=30){daysinmonth=30}else{daysinmonth=totaldays}}
			dayname.length=daysinmonth;
			for (i=0;i<daysinmonth;i++){
				dayname[i].value=i+1;
				dayname[i].text=i+1;
		}
		dayname.length=daysinmonth;
	}
}
}



// ------------------------------------------------------------------
// isDate ( date_string, format_string )
// Returns true if date string matches format of format string and
// is a valid date. Else returns false.
// It is recommended that you trim whitespace around the value before
// passing it to this function, as whitespace is NOT ignored!
// ------------------------------------------------------------------
function isDate(val,format) {
	var date=getDateFromFormat(val,format);
	if (date==0) { return false; }
	return true;
	}

// -------------------------------------------------------------------
// compareDates(date1,date1format,date2,date2format)
//   Compare two date strings to see which is greater.
//   Returns:
//   1 if date1 is greater than date2
//   0 if date2 is greater than date1 of if they are the same
//  -1 if either of the dates is in an invalid format
// -------------------------------------------------------------------
function compareDates(date1,dateformat1,date2,dateformat2) {
	var d1=getDateFromFormat(date1,dateformat1);
	var d2=getDateFromFormat(date2,dateformat2);
	if (d1==0 || d2==0) {
		return -1;
		}
	else if (d1 > d2) {
		return 1;
		}
	return 0;
	}



