function verify_email(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){return false}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr) {return false}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr) {return false}
	if (str.indexOf(at,(lat+1))!=-1) {return false}
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot) {return false}
	if (str.indexOf(dot,(lat+2))==-1) {return false}
	if (str.indexOf(" ")!=-1) {return false}
	return true					
	}

function ensureNumeric(strString,mini,maxi)
   {
   var strValidChars = "0123456789";
   var strChar;
   var blnResult = true;
   if (strString.length < mini | strString.length > maxi) return false;
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }

function check_form(str_form,str_args) { 
	var arr_args = str_args.split(",")
	str_error_message = ""
	for(i=0;i<arr_args.length;i++) {
		var arr_this_element = arr_args[i].split("|")
		str_field = arr_this_element[0]
		str_type = arr_this_element[1]
		bln_required = arr_this_element[2]
		str_message = arr_this_element[3]
		this_value = eval("document." + str_form + "." + str_field + ".value")
		this_value = this_value.replace(" ","")
			if (str_type == "t") { //Check String
				if (bln_required==1) {
					if (this_value=='') {str_error_message = str_error_message + str_message + "\n\n"}
				}
			} else if (str_type == "e") { //Check Email
				if (bln_required==1) {
					if (this_value==''||!verify_email(this_value)) {str_error_message = str_error_message + str_message + "\n\n"}
				} else {
					if (this_value!=''&&!verify_email(this_value)) {str_error_message = str_error_message + str_message + "\n\n"}
				}
			} else if (str_type == "n") { //Check Numeric
				if (bln_required==1) {
					if (this_value==''||isNaN(this_value)) {str_error_message = str_error_message + str_message + "\n\n"}
				} else {
					if (this_value!=''&&isNaN(this_value)) {str_error_message = str_error_message + str_message + "\n\n"}
				}
			} else if (str_type == "d") { //Check Date
				if (bln_required==1) {
					if (this_value==''||!verify_date(this_value)) {str_error_message = str_error_message + str_message + "\n\n"}
				} else {
					if (this_value!=''&&!verify_date(this_value)) {str_error_message = str_error_message + str_message + "\n\n"}
				}
			}
		}
		if (str_error_message!="") {
			str_error_message = "Incorrect Form Information!                              \n________________________\n\n" + str_error_message
			alert(str_error_message)
			document.check_form_return = false
		} else {
			document.check_form_return = true
			//eval("document.forms." + str_form + ".submit();")
		}
	}


function check_date(str_input,str_element) {
	var str_prompt = new String("You have entered an invalid date. \n\nPlease ensure dates are entered in the following format... \n\nDD/MM/YYYY \n\n(e.g.) 14/05/2005");
	var bln_good = true;
	var str = new String(str_input);
	if (str!="") {
		var slashes = str.indexOf("/");
		if(slashes < 0) {bln_good = false} else {;
			var arr = str.split("/");
			if(arr.length != 3) {bln_good = false} else {;
				if(isNaN(arr[0])||isNaN(arr[1])||isNaN(arr[2])) {bln_good = false} else {;
					if(arr[2].length!=4) {bln_good = false} else {;
					var arr_months = new Array(0,31,28,31,30,31,30,31,30,31,31,30,31);
					var feb_days = (((arr[2] % 4 == 0) && ( (!(arr[2] % 100 == 0)) || (arr[2] % 400 == 0))) ? 29 : 28 );
					arr_months[2] = feb_days;
					var day = new Number(arr[0])
					var month = new Number(arr[1])
					if(month>12||month<0) {bln_good = false};
					if(arr_months[month]<day||day<1) {bln_good = false};
					}
				}
			}
		}
	}
	if(!bln_good) {
		alert(str_prompt);
		document.getElementById(str_element).style.color = "red";
		} else {
		document.getElementById(str_element).style.color = "black";
		}
}
