function isFilled(str){ return (str != ""); }
	function isEmail(string) { return (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1); }
 	function isDigital(str)	{ return(parseFloat(str,10)==(str*1)); }
 	function isCurrency(val) { 	var re = /^(\$?\d+\$?|\$?\d+\.\d+\$?)$/; return (re.test(val)); }

function WAAddError(formElement,errorMsg,focusIt,stopIt)  {
  if (document.WAFV_Error)  {
	  document.WAFV_Error += "\n" + errorMsg;
  }
  else  {
    document.WAFV_Error = errorMsg;
  }
  if (!document.WAFV_InvalidArray)  {
    document.WAFV_InvalidArray = new Array();
  }
  document.WAFV_InvalidArray[document.WAFV_InvalidArray.length] = formElement;
  if (focusIt && !document.WAFV_Focus)  {
	document.WAFV_Focus = focusIt;
  }

  if (stopIt == 1)  {
	document.WAFV_Stop = true;
  }
  else if (stopIt == 2)  {
	formElement.WAFV_Continue = true;
  }
  else if (stopIt == 3)  {
	formElement.WAFV_Stop = true;
	formElement.WAFV_Continue = false;
  }
}

function WA_isCreditCard(st) {
  if (st == 0)
    return (false);

  if (st.length > 19)
    return (false);

  sum = 0; mul = 1; l = st.length;
  for (i = 0; i < l; i++) {
    digit = st.substring(l-i-1,l-i);
    tproduct = parseInt(digit ,10)*mul;
    if (tproduct >= 10)
      sum += (tproduct % 10) + 1;
    else
      sum += tproduct;
    if (mul == 1)
      mul++;
    else
      mul--;
  }

  if ((sum % 10) == 0)
    return (true);
  else
    return (false);

}

function WAValidateCC(formElement,value,errorMsg,format,allow,focusIt,stopIt,required)  {
  var isValid = true;
  var accepted = "\r\n\t.- ";
  if ((!document.WAFV_Stop && !formElement.WAFV_Stop) && !(!required && value==""))  {
    var stripVal = "";
	for (var x=0; x<value.length; x++)  {
	  if (value.charCodeAt(x)>=48 && value.charCodeAt(x)<=57)
	    stripVal += value.charAt(x);
	  else if (accepted.indexOf(value.charAt(x))<0)  {
	    isValid = false;
	  }
	}
	if (isValid)  {
	  if (allow!="")  {
	    isValid = false;
	    allow = allow.split(":");
		for (var y=0; y<allow.length-1 && !isValid; y++)  {
		  if (stripVal.indexOf(allow[y])==0)
		    isValid = true;
		}
	  }
	}
	if (isValid)  {
	  isValid = WA_isCreditCard(stripVal);
	}
	if (isValid && format!="")  {
	  var newFormat = "";
	  while (format!="")  {
	    if (format.charAt(0) == "x") {
		  newFormat += stripVal.charAt(0);
		  stripVal = stripVal.substring(1);
		}
		else  {
		  newFormat += format.charAt(0);
		}
		format = format.substring(1);
	  }
	  formElement.value = newFormat;
	}
  }
  if (!isValid)  {
    WAAddError(formElement,errorMsg,focusIt,stopIt);
  }
}

function WAAlertErrors(errorHead,errorFoot,setFocus,submitForm)  { 
  if (!document.WAFV_StopAlert)  { 
	  document.WAFV_StopAlert = true;
	  if (document.WAFV_InvalidArray)  {  
	    document.WAFV_Stop = true;
        var errorMsg = document.WAFV_Error;
	    if (errorHead!="")
		  errorMsg = errorHead + "\n" + errorMsg;
		if (errorFoot!="")
		  errorMsg += "\n" + errorFoot;
		document.MM_returnValue = false;
		if (document.WAFV_Error!="")
		  alert(errorMsg.replace(/&quot;/g,'"'));
		else if (submitForm)
		  submitForm.submit();
	    if (setFocus && document.WAFV_Focus)  {
		  document.tempFocus = document.WAFV_Focus;
          setTimeout("document.tempFocus.focus();setTimeout('document.WAFV_Stop = false;document.WAFV_StopAlert = false;',1)",1); 
        }
        else {
          document.WAFV_Stop = false;
          document.WAFV_StopAlert = false;
        }
        for (var x=0; x<document.WAFV_InvalidArray.length; x++)  {
	      document.WAFV_InvalidArray[x].WAFV_Stop = false;
	    }
	  }
	  else  {
        document.WAFV_Stop = false;
        document.WAFV_StopAlert = false;
	    if (submitForm)  {
	      submitForm.submit();
	    }
	    document.MM_returnValue = true;
	  }
      document.WAFV_Focus = false;
	  document.WAFV_Error = false;
	  document.WAFV_InvalidArray = false;
  }
}

function WAValidateNM(formElement,errorMsg,minLength,maxLength,allowDecimals,roundDecimals,reformatDecimals,punctuationMarks,focusIt,stopIt,required)  {
  var isValid = true;
  var theThousand = punctuationMarks.charAt(0);
  var theDecimal = punctuationMarks.charAt(1);
  var theCheck = 11/10;
  var trueDecimal = (String(theCheck).charAt(1));
  var value = formElement.value;
  var decimalIndex = value.length;
  if (punctuationMarks.indexOf(trueDecimal)<0 && value.indexOf(trueDecimal)>=0)  {
    isValid = false;
  }
  if (value.lastIndexOf(theDecimal)>=0) {
    decimalIndex = value.lastIndexOf(theDecimal);
  }
  while (value.indexOf(theThousand)>=0)  {
    decimalIndex = value.length;
    if (value.lastIndexOf(theDecimal)>=0) {
      decimalIndex = value.lastIndexOf(theDecimal);
    }
    if ((decimalIndex-(value.lastIndexOf(theThousand)+1))%3 != 0)
      isValid = false;
    value = value.substring(0,value.lastIndexOf(theThousand)) + value.substring(value.lastIndexOf(theThousand)+1);
  }
  if (trueDecimal != theDecimal)  {
    while (value.indexOf(theDecimal)>=0)  {
      value = value.substring(0,value.indexOf(theDecimal)) + trueDecimal + value.substring(value.indexOf(theDecimal)+1);
    }
  }
  if ((!document.WAFV_Stop && !formElement.WAFV_Stop) && !(!required && value==""))  {
    for (var x=0; x<value.length; x++)  {
      if  ((value.charAt(x)<0 || value.charAt(x) > 9) && (value.charAt(x) != " " && value.charAt(x) != "," && value.charAt(x) != "."))  {
        isValid = false;
      }
    }
    if (value == "")  {
      isValid = false;
    }
    var oldVal = String(value);
    if (oldVal.indexOf(trueDecimal)>=0)  {
      while (oldVal.charAt(oldVal.length-1)=="0" || oldVal.charAt(oldVal.length-1) == trueDecimal) {
        if (oldVal.charAt(oldVal.length-1) == trueDecimal) {
          oldVal = oldVal.substring(0,oldVal.length-1);
          break;
        }
        else oldVal = oldVal.substring(0,oldVal.length-1);
      }
      if (oldVal.indexOf(trueDecimal)==0)
        oldVal = "0" + oldVal;
    }
    if (String(allowDecimals) !="" )  {
      if (String(value).indexOf(".") > 0 && ((String(value).indexOf(".") + allowDecimals + 2 <= String(value).length) || allowDecimals == 0))  {
        isValid = false;
      }
    }
    value = parseFloat(value);
    if (isNaN(value))  {
      isValid = false;
    }
    else if (String(value).length!=String(oldVal).length && String(oldVal).substring(String(value).length+1).search(/^\.?0*$/) == -1 ) {
	  isValid = false;
    }
    else if ((minLength != "" && minLength > value) || (maxLength != "" && maxLength < value)) {
      isValid = false;
    }
  }
  if (!isValid)  {
    WAAddError(formElement,errorMsg,focusIt,stopIt);
  }
  else  {
    if (value != "")  {
      if (roundDecimals != "")  {
        value = Math.round(value*roundDecimals)/roundDecimals;
      }
      if (reformatDecimals != "")  {
        value = String(value);
        if (value.indexOf(trueDecimal)<0)
          value += trueDecimal;
        if (value.indexOf(trueDecimal) < value.length - reformatDecimals)  {
          value = value.substring(0,value.indexOf(trueDecimal) + reformatDecimals + 1);
        }
        else  {
          while (value.indexOf(trueDecimal) > value.length - reformatDecimals - 1)  {
             value += "0";
          }
        }
      }
    }
    if (trueDecimal != theDecimal)  {
      value = String(value);
      while (value.indexOf(trueDecimal)>=0)  {
        value = value.substring(0,value.indexOf(trueDecimal)) + theDecimal + value.substring(value.indexOf(trueDecimal)+1);
      }
    }
    if (roundDecimals != "" || reformatDecimals != "")
      formElement.value = value;
  }
}

function WAtrimIt(theString,leaveLeft,leaveRight)  {
  if (!leaveLeft)  {
    while (theString.charAt(0) == " ")
      theString = theString.substring(1);
  }
  if (!leaveRight)  {
    while (theString.charAt(theString.length-1) == " ")
      theString = theString.substring(0,theString.length-1);
  }
  return theString;
}

function WAValidateRQ(formElement,errorMsg,focusIt,stopIt,trimWhite,inputType)  {
  var isValid = true;
  if (!document.WAFV_Stop && !formElement.WAFV_Stop)  {
    if (inputType == "select")  {
	  if (formElement.selectedIndex == -1)  {
	    isValid = false;
	  }
	  else if (!formElement.options[formElement.selectedIndex].value || formElement.options[formElement.selectedIndex].value == "") {
	    isValid = false;
	  }
	}
	else if (inputType == "checkbox")  {
	  if (formElement.length)  {
	    isValid = false;
        focusIt = false;
	    for (var x=0; x<formElement.length ; x++)  {
	      if (formElement[x].checked && formElement[x].value!="")  {
		    isValid = true;
		    break;
		  }
	    }
	  }
      else if (!formElement.checked)
	    isValid = false;
	}
	else if (inputType == "radio")  {
	  isValid = false;
	  if (formElement.checked)
	    isValid = true;
	}
	else if (inputType == "radiogroup")  {
	  isValid = false;
	  for (var x=0; x<formElement.length; x++)  {
	    if (formElement[x].checked && formElement[x].value!="")  {
		  isValid = true;
		  break;
		}
	  }
	  formElement = formElement[0];
	}
	else  {
	  var value = formElement.value;
	  if (trimWhite)  {
	    value = WAtrimIt(value);
	  }
	  if (value == "")  {
	    isValid = false;
	  }
	}
  }
  if (!isValid)  {
    WAAddError(formElement,errorMsg,focusIt,stopIt);
  }
}

function WAValidateEM(formElement,value,errorMsg,focusIt,stopIt,required) {
  var isValid = true;
  if ((!document.WAFV_Stop && !formElement.WAFV_Stop) && !(!required && value==""))  {
    var knownDomsPat = /^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
    var emailPat = /^(.+)@(.+)$/;
    var accepted = "\[^\\s\\(\\)><@,;:\\\\\\\"\\.\\[\\]\]+";
    var quotedUser = "(\"[^\"]*\")";
    var ipDomainPat = /^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
    var section = "(" + accepted + "|" + quotedUser + ")";
    var userPat = new RegExp("^" + section + "(\\." + section + ")*$");
    var domainPat = new RegExp("^" + accepted + "(\\." + accepted +")*$");
    var theMatch = value.match(emailPat);
    var acceptedPat = new RegExp("^" + accepted + "$");
    var userName = "";
    var domainName = "";
    if (theMatch==null) {
      isValid = false;
    }
    else  {
      userName = theMatch[1];
      domainName = theMatch[2];
	  var domArr = domainName.split(".");
	  var IPArray = domainName.match(ipDomainPat);
      for (x=0; x < userName.length; x++) {
        if (userName.charCodeAt(x) > 127) {
          isValid = false;
        }
      }
      for (x=0; x < domainName.length; x++) {
        if (domainName.charCodeAt(x) > 127) {
          isValid = false;
        }
      }
      if (userName.match(userPat) == null) {
        isValid = false;
      }
      if (IPArray != null) {
        for (var x=1; x<=4; x++) {
          if (IPArray[x] > 255) {
            isValid = false;
          }
        }
      }
      for (x=0; x < domArr.length; x++) {
        if (domArr[x].search(acceptedPat) == -1 || domArr[x].length == 0) {
          isValid = false;
        }
      }
      if (domArr[domArr.length-1].length !=2 && domArr[domArr.length-1].search(knownDomsPat) == -1) {
        isValid = false;
      }
      if (domArr.length < 2) {
        isValid = false;
      }
    }
  }
  if (!isValid)  {
    WAAddError(formElement,errorMsg,focusIt,stopIt);
  }
}


//the jave below is for enrol_comp.php//////////////////////////////////////////////////////




function isFilled(str){ return (str != ""); }
	function isEmail(string) { return (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1); }
 	function isDigital(str)	{ return(parseFloat(str,10)==(str*1)); }
 	function isCurrency(val) { 	var re = /^(\$?\d+\$?|\$?\d+\.\d+\$?)$/; return (re.test(val)); }
		function ValidForm(form) {
		var field, i;
		var req = new Array(9);
		var email = new Array(1);
		var digits = new Array(0);
		var currs = new Array(0);
		req[0] = "rm_I_wish_to_enrol_in_";
		req[1] = "r_Title";
		req[2] = "r_Surname";
		req[3] = "r_First_Name";
		req[4] = "r_Residential_Address";
		req[5] = "r_State";
		req[6] = "r_Postcode";
		req[7] = "r_Home_Phone_Number";
		req[8] = "re_Email";
		email[0] = "re_Email";

		for (i=0;i<9;i++)	{
			eval("field = form." + req[i]);
			if (!isFilled(field.value))	{
				alert("Field '" + field.title + "' is required to be filled in before successful submission.");
				field.focus();
				return false;
				break;
			}}
		for (i=0;i<1;i++)	{
			eval("field = form." + email[i]);
			if (!isEmail(field.value)) {
				alert("Field '" + field.title + "' is required to be filled in with valid email addresses before successful submission.");
				field.focus();
				return false;
				break;
			}}
		for (i=0;i<0;i++)	{
			eval("field = form." + digits[i]);
			if (!isDigital(field.value)) {
				alert("Field " + field.title + " is required to be filled in only with digits (0-9) and decimal point before successful submission.");
				field.focus();
				return false;
				break;
			}}
		for (i=0;i<0;i++)	{
			eval("field = form." + currs[i]);
			if (!isCurrency(field.value)) {
				alert("Field " + field.title + " is required to be filled in only with digits (0-9) a decimal point, or a dollar sign before successful submission.");
				field.focus();
				return false;
				break;
			}}
		if(form.elements['cardholder'].value=="")
		{
			alert('Card Holder is missing ...');
			form.elements['cardholder'].focus();
			return false;
		}

		if(form.elements['card_type'].value=="")
		{
			alert('Please select a card type ...');
			form.elements['card_type'].focus();
			return false;
		}

		if(form.elements['cc_exp_month'].value=="")
		{
			alert('Month of credit card expiry missing ...');
			form.elements['cc_exp_month'].focus();
			return false;
		}

		if(form.elements['cc_exp_yr'].value=="")
		{
			alert('Year of credit card expiry missing ...');
			form.elements['cc_exp_yr'].focus();
			return false;
		}

		if(form.elements['card_number'].value=="")
		{
			alert('Credit card number is missing ...');
			form.elements['card_number'].focus();
			return false;
		}
		return true; }


























