var isNetscape = (navigator.appName && navigator.appName.indexOf("Netscape")>=0);

function CheckEmail(value){
	if ((value.indexOf('@')<=0)||(value.indexOf('.')<=0))
		return false;
	if ((value.indexOf('@')>0)&&(value.indexOf('@')!=value.lastIndexOf('@')))
		return false;
	if (value.lastIndexOf('@')>value.lastIndexOf('.'))
		return false;
	if (value.lastIndexOf('.')==value.length-1)
		return false;
	return true;
}

function onError(error_message, acontrol) {
	alert('\n' + error_message);
	acontrol.focus();
	return false;   
}

function CheckSelect(selectbox, DisplayName) {
	if (selectbox.selectedIndex == 0)
		return(onError("Please select a value for " + DisplayName, selectbox));
	return true;
}

function CheckRadio(radiobox, DisplayName) {
	var checked = false;
	for (var radioind = 0; radioind < radiobox.length; radioind++)
		checked = (checked || radiobox[radioind].checked);
	if (checked)
		return true;
	else
		return(onError("Please select an option for " + DisplayName, radiobox[0]));
}

function CheckDate(datefield, DisplayName, thisform, nullable) {
	if (nullable) {
		if ((eval("thisform." + datefield + "day.selectedIndex == 0")) && (eval("thisform." + datefield + "null.checked == false")))
			return(onError("Please enter a value for the day of the " + DisplayName + ", otherwise click the null? box", eval("thisform." + datefield + "day")));
		if ((eval("thisform." + datefield + "month.selectedIndex == 0")) && (eval("thisform." + datefield + "null.checked == false")))
			return(onError("Please enter a value for the month of the " + DisplayName + ", otherwise click the null? box", eval("thisform." + datefield + "month")));
		if ((eval("thisform." + datefield + "year.value == ''")) && (eval("thisform." + datefield + "null.checked == false")))
			return(onError("Please enter a value for the year of the " + DisplayName + ", otherwise click the null? box", eval("thisform." + datefield + "year")));
		else if ((eval("thisform." + datefield + "null.checked == false")) && (!eval("CheckNumber(thisform." + datefield + "year.value)")))
			return(onError("Please enter a numeric value for the year of the " + DisplayName + ", otherwise click the null? box", eval("thisform." + datefield + "year")));
		else if ((eval("thisform." + datefield + "null.checked == false")) && (eval("parseInt(thisform." + datefield + "year.value) < 1900")))
			return(onError("Please enter a numeric value greater than 1900 for the year of the " + DisplayName + ", otherwise click the null? box", eval("thisform." + datefield + "year")));
	} else {
		if (eval("thisform." + datefield + "day.selectedIndex == 0"))
			return(onError("Please enter a value for the day of the " + DisplayName, eval("thisform." + datefield + "day")));
		if (eval("thisform." + datefield + "month.selectedIndex == 0"))
			return(onError("Please enter a value for the month of the " + DisplayName, eval("thisform." + datefield + "month")));
		if (eval("thisform." + datefield + "year.value == ''"))
			return(onError("Please enter a value for the year of the " + DisplayName, eval("thisform." + datefield + "year")));
		else if (!eval("CheckNumber(thisform." + datefield + "year.value)"))
			return(onError("Please enter a numeric value for the year of the " + DisplayName, eval("thisform." + datefield + "year")));
		else if (eval("parseInt(thisform." + datefield + "year.value) < 1900"))
			return(onError("Please enter a numeric value greather than 1900 for the year of the " + DisplayName, eval("thisform." + datefield + "year")));
	}
	return true;
}

function CheckTime(datefield, DisplayName, thisform, nullable) {
	if (nullable) {
		if ((eval("thisform." + datefield + "hour.selectedIndex == 0")) && (eval("thisform." + datefield + "null.checked == false")))
			return(onError("Please enter a value for the hour of the " + DisplayName + ", otherwise click the null? box", eval("thisform." + datefield + "hour")));
		if ((eval("thisform." + datefield + "minute.selectedIndex == 0")) && (eval("thisform." + datefield + "null.checked == false")))
			return(onError("Please enter a value for the minute of the " + DisplayName + ", otherwise click the null? box", eval("thisform." + datefield + "minute")));
	} else {
		if (eval("thisform." + datefield + "hour.selectedIndex == 0"))
			return(onError("Please enter a value for the hour of the " + DisplayName, eval("thisform." + datefield + "hour")));
		if (eval("thisform." + datefield + "minute.selectedIndex == 0"))
			return(onError("Please enter a value for the minute of the " + DisplayName, eval("thisform." + datefield + "minute")));
	}
	return true;
}

function CheckDateTime(datefield, DisplayName, thisform, nullable) {
	if (!CheckDate(datefield, DisplayName, thisform, nullable))
		return false;
	if (!CheckTime(datefield, DisplayName, thisform, nullable))
		return false;
	return true;
}

function CheckTextBox(VarName, DisplayName, thisform, nullable) {
	if (!nullable) {
		if (eval("thisform." + VarName + ".value == ''"))
			return(onError("Please enter a value for " + DisplayName, eval("thisform." + VarName)));
	}
	return true;
}

function CheckMoney(VarName, DisplayName, thisform, nullable) {
	if (!CheckNumberField(VarName + 'Dollars','the dollar value of ' + DisplayName,thisform,nullable))
		return false;
	if (!CheckNumberField(VarName + 'Cents','the cents value of ' + DisplayName,thisform,nullable))
		return false;
	return true;
}
		
function CheckNumberField(VarName, DisplayName, thisform, nullable) {
	if (!CheckTextBox(VarName,DisplayName,thisform,nullable))
		return false;
	else if (!eval("CheckNumber(thisform." + VarName + ".value)"))
		return(onError("Please enter a numeric value for " + DisplayName, eval("thisform." + VarName)));
	return true;
}
		
function CheckNumber(NumberValue) {
	var numberformat = "0123456789";
	var isnumber = true;
	for (var valueInd = 0; valueInd < NumberValue.length; valueInd++)
		isnumber = ((isnumber) && (numberformat.indexOf(NumberValue.charAt(valueInd)) >= 0));
	return(isnumber);
}
