
function ValidateEmail (Email) {
//--- Makes sure there is a @ and a . in the value entered
 	var Check = 0;
	Check = Email.value;
	if (Check == '') {
		return false;
	}
 	if ((Check.indexOf ('@',0) == -1)) {
        return false;
	} else {
		return true;
	}
}

function CheckNum (CheckThis, XLabel) {
//--- Makes sure the field consists only of digits
	var newval = new String ();
	if (CheckThis.value == '') {
		alert (XLabel + ' has not been entered, please enter and try again!');
		CheckThis.focus ();
		return false;
	}
	newval = CheckThis.value;
	var newnew = '';
	for (i = 0; i < newval.length; i++) {
		if ((parseInt (newval.charAt(i)) > 0) || (parseInt (newval.charAt(i)) < 9)) {
			newnew += newval.charAt(i);
		} else {
			if ((newval.charAt(i) == ' ') || (newval.charAt(i) == '(') || (newval.charAt(i) == '-') || (newval.charAt(i) == ')') || (newval.charAt(i) == '+')) {
				//--- do nothing
			} else {
				newnew += newval.charAt(i);			
			}
		}
	}
	if (isNaN (newnew)) {
		alert (XLabel + ' is an invalid number!')
		CheckThis.focus ();
		return false;
	} else {
		return true;
	}
}

function CheckDropDownBox (which) {
//--- Makes sure that a drop down box is selected
	var IndexOfWhich = which.selectedIndex;
	if (IndexOfWhich == 0) {
		return false;
	} else {
		return true;
	}
}

function ValidateTextBox (which, FieldName) {
//--- Function that validates a text box
	var FieldValue = 0;
	FieldValue = which.value;
	if (!FieldValue) {
		alert (FieldName + ' is not filled in');
		which.focus();
		return false;
	} else {
		return true;
	}
}

function ValidateCell (which, FieldName) {
//--- Function that validates a text box
	var FieldValue = 0;
	FieldValue = which.value;
	
	if (!FieldValue) {
		alert (FieldName + ' is not filled in the correct format [0821234123]');
		which.focus();
		return false;
	} 
	else
	{
		return true;
	}
}

function ValidateDateField (FieldName, FieldLabel) {
//--- Function that validates an Ensight field
	var Temp = FieldName + '_Day';
	var day = document.postForm.elements[Temp].selectedIndex;
	
	Temp = FieldName + '_Month';
	var month = document.postForm.elements[Temp].selectedIndex;

	Temp = FieldName + '_Year';
	var year = document.postForm.elements[Temp].selectedIndex;
	if ((day == 0) || (month == 0) || (year == 0)) {
		alert (FieldLabel + ' is not entered correctly');
		document.postForm.elements[FieldName + '_Day'].focus();
		return false;
	} else {
		return true;
	}	
}

function ValidateRadioButton (which, FieldName) {
//--- Validates the radio button

	var x = 0;
	var sel = 0;
	var i = 0;
	for (i = 0; i < which.length; i++) {
		if (which[i].checked == true) {
			sel = 1;
		}
	}
	if (sel == 1) {
		return true;
	} else {
		alert (FieldName + ' is not selected');
		return false;
	}

}

function DecimalsOnly (which) {
//--- this function makes sure that people can only enter in numbers into the text boxes
	var x = 0;
	x = which.value;
	var newvalue = '';
	var i =0;
	for (i = 0; i < x.length; i++) {
	//--- go thru all of the characters
		switch (x.charAt (i)) {
			case "-" :
			case "0" :	
			case "1" :
			case "2" :
			case "3" :
			case "4" :
			case "5" :
			case "6" :
			case "7" :
			case "8" :
			case "9" :	
			case "." : newvalue = newvalue + x.charAt (i);
				break;
		}; //--- end switch
	}
	which.value = newvalue;
	return true;
}

function IntegersOnly (which) {
//--- this function makes sure that people can only enter in numbers into the text boxes
	var x = 0;
	x = which.value;
	var newvalue = '';
	var i =0;
	for (i = 0; i < x.length; i++) {
	//--- go thru all of the characters
		switch (x.charAt (i)) {
			case "-" :
			case "0" :	
			case "1" :
			case "2" :
			case "3" :
			case "4" :
			case "5" :
			case "6" :
			case "7" :
			case "8" :
			case "9" : newvalue = newvalue + x.charAt (i);
				break;
		}; //--- end switch
	}
	which.value = newvalue;
	return true;
}

