function sayhi(){
	alert("Hello World!");
}
function checklen(x){
	while(''+ x.value.charAt(x.value.length-1)==' ')
		x.value=x.value.substring(0,x.value.length-1); 
	while(''+x.value.charAt(0)==' ')
		x.value=x.value.substring(1,x.value.length);
	}
	
function limittext(iTarget,MyChar,MyText) {
	var a = eval(MyChar);
	var areaname = iTarget.name;
	StrLen = iTarget.value.length;
	if (StrLen > a ) {
		iTarget.value = iTarget.value.slice(0,a);
		charsLeft = 0;
		alert("The " + MyText + " is limited to " + MyChar + " characters.  Please modify your entry.");
		iTarget.focus();
	}
	else {
		charsLeft = a - StrLen;
	}
}
 

function isnum(field) {
	var valid = "-.0123456789 ";
	var ok = "yes";
	var temp;
	for (var i=0; i<field.value.length; i++) {
		temp = "" + field.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") ok = "no";
	}
	if (ok == "no") {
		alert("Please enter a numeric value.");
		field.value = "";
		field.focus();
		field.select();
    }
}

/* Old Function:
function isnumdate(field) {
	var valid = "/0123456789"
	var ok = "yes";
	var temp;
	for (var i=0; i<field.value.length; i++) {
	temp = "" + field.value.substring(i, i+1);
	if (valid.indexOf(temp) == "-1") 
		ok = "no";
	}
	if (ok == "no") {
		alert("Please enter a valid date.");
		field.value = "";
		field.focus();
		return false;
	}
} */

function isnumdate(field) {
	if (field.value != "")
	{
		var array = field.value.replace(/[-.]/g, "/").split("/");
		var month = parseInt(array[0], 10);
		var day = parseInt(array[1], 10);
		var year = parseInt(array[2], 10);
		var startYear = 2000;
		var endYear = 2020;
	
		// If parseInt fails, it returns NaN.  Also, a negative year, or a day 0 are both improper.  If any of these conditions appear,
		// then we fail.
		if (isNaN(month) || isNaN(day) || day < 1 || isNaN(year) || year < 0)
		{
			alert("The date you entered does not appear to be a valid date.  Please enter your date again, in the format mm/dd/yyyy.");
			field.value = "";
			field.focus();
			return false;
		}
		
		// If we have a two digit year, force conversion to four-digit year.  Must be updated before 2100.
		if (year < 100)
			year = 2000 + year;
	
		// Process the month first.  Ensure that it is a valid month (in the range 1-12).
		if (month < 1 || month > 12)
		{
			alert("The month entered is incorrect.  Please enter your date again, in the format mm/dd/yyyy.");
			field.value = "";
			field.focus();
			return false;
		}
	
		// Set the maximum number of days 
		var maxDays = 0;
		switch(month)
		{
			case 4:
			case 6:
			case 9:
			case 11:
				maxDays = 30;
				break;
			case 2:
				// Leap Year
				if (year % 4 == 0)
					maxDays = 29;
				// Not Leap Year
				else
					maxDays = 28;			
				break;
			default:
				maxDays = 31;		
		}
	
		// Check to make sure the day indicated exists within the month.
		if (day > maxDays)
		{
			alert("The number of days is invalid for the given month.  Please enter your date again in the format mm/dd/yyyy.");
			field.value = "";
			field.focus();
			return false;
		}
		
		// Check to see that the year is a valid recent year (between 2000 and 2020).
		if (year < startYear || year > endYear)
		{
			alert("The year given is invalid.  Please enter a year between " + startYear + " and " + endYear);
			field.value = "";
			field.focus();
			return false;
		}
		// If we get here, all is well.
		if (month < 10)
			month = "0" + month.toString();
		if (day < 10)
			day = "0" + day.toString();
		field.value = month + "/" + day + "/" + year;
		return true;
	}
	return false;
}
function formatprice(value) {
	if(value != ""){
		result=Math.floor(value)+".";
		var cents=100*(value-Math.floor(value))+0.5;
		result += Math.floor(cents/10);
		result += Math.floor(cents%10);
		return result;
	}
}

function round(number,x) {
		x = (!x ? 2 : x);
		return Math.round(number*Math.pow(10,x))/Math.pow(10,x);

}

