
	
	//accepts a date in mm/dd/yyyy format and returns a date
	function changeToDate(strDate) { 
		var entMonth = parseFloat(strDate.substring(0,2));
		var entDate = parseFloat(strDate.substring(3,5));
		var entYear = parseFloat(strDate.substring(6,11));
		var retDate = new Date(entYear, (entMonth-1), entDate);
		
		return retDate;
	}
	
	// accepts two date objects and returns the number of days between them
	function days_between(date1, date2) {
		
		if (date1 == undefined || date2 == undefined) {
			return 0;
		}
		
		// The number of milliseconds in one day
		var ONE_DAY = 1000 * 60 * 60 * 24
		
		// Convert both dates to milliseconds
		var date1_ms = date1.getTime();
		var date2_ms = date2.getTime();
		
		// Calculate the difference in milliseconds
		var difference_ms = date2_ms - date1_ms;
		
		// Convert back to days and return
		return Math.round(difference_ms/ONE_DAY);
	
	}
		

	// USAGE:  <input name="phone" type="text" onBlur="formatPhone(this);">
	function formatPhone(obj) {
		obj.className = '';
		if (obj.value != '') {
			var bool = formatString(obj.value,/\d{3}-\d{3}-\d{4}/);
			if (!bool) {	// error found
				obj.className = 'required';	
				alert('Expecting phone format 000-000-0000');
				obj.focus();
			}
			return bool;
		}
	}
	
	// USAGE:  <input name="dateInput" type="text" onBlur="formatDate(this);">
	function formatDate(obj) {	// assuming mm/dd/yyyy
		obj.className = '';
		if (obj.value != '') {
			var bool = formatString(obj.value,/\d{2}\/\d{2}\/\d{4}/);
			if (!bool) {	// error found
				obj.className = 'required';	
				alert('Expecting date format mm/dd/yyyy');
				obj.focus();
			}
			return bool;
		}
	}
	
	function formatString(str,pattern) {
		// format a string based on what is passed in 
		// 999-999-9999
		var retVal = true;
		//pattern = /\d{3}-\d{3}-\d{4}/;
		if (!pattern.test(str)) {
			//document.forms[0].elements[2].focus();
			retVal = false;
		}
		return retVal;
	}
	
	numChars = '0123456789';
	phoneChars = numChars + '-';
	dateChars = numChars + '/';
	// USAGE: <input type="text" onKeyPress="return allowChar(this,phoneChars);">
	function allowChar(obj,allowedChars) {
		var key = String.fromCharCode(event.keyCode).toLowerCase();
		if (allowedChars.indexOf(key)<0) {
			return false;
		}
	}

