var INT 		= /^-{0,1}\d+$/
var POS_INT 	= /^\d*$/;
var NEG_INT 	= /^-\d+$/;
var NONZERO_INT 	= /^[1-9]+\d*$/;
var NUMBER 		= /^-{0,1}\d*\.{0,1}\d+$/;
var POS_NUMBER 	= /^\d*\.{0,1}\d+$/;
var NEG_NUMBER 	= /^-\d*\.{0,1}\d+$/;
var ALPHA		= /^[A-Z]+$/i;
var ALPHPASPACE	= /^[A-Z ]+$/i;
var ALPHANUM	= /^[A-Z0-9]+$/i;
var ALPHANUMSPACE = /^[A-Z0-9 ]+$/i;
var EMAIL		= /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
var NAME		= /^[A-Z .'-]+$/i;

String.prototype.isType = function(regex) {
	if (this.match(regex)) {
		return true;
	}
	else {
		return false;
	}
}

// extend String object to provide function to trim whitespace
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}

// extend String object to provide function to trim whitespace
// and convert inner whitespace sequences to single spaces
String.prototype.trimAndCompact = function() {
	return this.replace(/^\s+|\s+$/g,"").replace(/\s+/g, ' ');
}

function trim(s) {
  if (s.value>0)
  {
  while (s.substring(0,1) == ' ') {
    s = s.substring(1,s.length);
  }
  while (s.substring(s.length-1,s.length) == ' ') {
    s = s.substring(0,s.length-1);
  }
  }
  return s;
}

function isValidEmail(str) {

   return (str.indexOf(".") > 0) && (str.indexOf("@") > 0);
 

}


<!--
// javascript utility functions - mainly for help with form processing ....

// returns form errors as held in (string) array
function frmErrors(errArray) {
	if (errArray.length == 0) { return true; }
	var str = "Please provide the following information:";
	for (i in errArray) { str += "\n - " + errArray[i]; }
	alert(str);
	return false;
}

// trims the text input field and returns the trimmed value
function trimInput(elem) {
	var str = elem.value.trim();
	elem.value = str;
	return str;
}


// returns the value of the radio button group identified be elem
function getRadioValue(radio_elem) {
	for (i=0; i < radio_elem.length; i++) {
		if (radio_elem[i].checked) { return radio_elem[i].value; }
      }
	return null;
}

// return the value of the selected option
function getSelectValue(select_elem) {
	var idx = select_elem.selectedIndex;
	return (idx<0) ? null : select_elem[idx].value;
}

// extend String object to provide regular expression matching against defined patterns:
var INT 		= /^-{0,1}\d+$/
var POS_INT 	= /^\d*$/;
var NEG_INT 	= /^-\d+$/;
var NONZERO_INT 	= /^[1-9]+\d*$/;
var NUMBER 		= /^-{0,1}\d*\.{0,1}\d+$/;
var POS_NUMBER 	= /^\d*\.{0,1}\d+$/;
var NEG_NUMBER 	= /^-\d*\.{0,1}\d+$/;
var ALPHA		= /^[A-Z]+$/i;
var ALPHPASPACE	= /^[A-Z ]+$/i;
var ALPHANUM	= /^[A-Z0-9]+$/i;
var ALPHANUMSPACE = /^[A-Z0-9 ]+$/i;
var EMAIL		= /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
var NAME		= /^[A-Z .'-]+$/i;

var FNAME_EXT     = /^[A-Z_]+[A-Z_-]+\.[A-Z]{3,4}$/i;
var FNAME_NO_EXT  = /^[A-Z_]+[A-Z0-9_-]+$/i;

var PRICE 		= /^\d+(\.\d{2})?$/;

String.prototype.isType = function(regex) {
	if (this.match(regex)) {
		return true;
	}
	else {
		return false;
	}
}

// extend String object to provide function to trim whitespace
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}

// extend String object to provide function to trim whitespace
// and convert inner whitespace sequences to single spaces
String.prototype.trimAndCompact = function() {
	return this.replace(/^\s+|\s+$/g,"").replace(/\s+/g, ' ');
}

// extend String object to provide function to check if string ends with either:
// str_or_arr value (as String) or one of str_or_arr values (as array)
// ignorecase - optional parameter defaults to false
String.prototype.endsWith = function(str_or_arr, ignorecase) {
	var str = (isArray(str_or_arr) && str_or_arr.length > 0) 
	        ? "("+ str_or_arr.join("|") + ")" 
		  : String(str_or_arr);
	var pattern = (ignorecase === undefined || ignorecase != true) 
	            ? new RegExp(str+ "$") 
			: new RegExp(str+ "$", "i");
	return pattern.test(this);
	
}

// extend String object to provide function to check if string starts with either:
// str_or_arr value (as String) or one of str_or_arr values (as array)
// ignorecase - optional parameter defaults to false
String.prototype.startsWith = function(str_or_arr, ignorecase) {
	var str = (isArray(str_or_arr) && str_or_arr.length > 0) 
	        ? "("+ str_or_arr.join("|") + ")" 
		  : String(str_or_arr);
	var pattern = (ignorecase === undefined || ignorecase != true) 
	            ? new RegExp("^" + str) 
			: new RegExp("^" + str, "i");
	return pattern.test(this);
}

// determine if variable is string
function isString(s) {
	if (typeof s == 'string') { return true; }
	if (typeof s == 'object') {  
		var match = s.constructor.toString().match(/string/i); 
		return (match != null);
	}
	return false;
}

// determine if variable is array
function isArray(a) {
	if (typeof a == 'object') {  
		var match = a.constructor.toString().match(/array/i); 
		return (match != null);
	}
	return false;
}
function process_registration()
{
   myerror=0;
   myerrormsg="";
   myerrormsg='Please provide:\n';

   if (trim(document.frm.f_title[0].selected))
   {
	  myerror=1;
	  myerrormsg=myerrormsg+' -Title\n';
	  
   }
   if (trim(document.frm.f_firstname.value)=='')
   {
	  myerror=1;
	  myerrormsg=myerrormsg+' -First Name\n';
	  
   }
   if (trim(document.frm.f_lastname.value)=='')
   {
	  myerror=1;
	  myerrormsg=myerrormsg+' -Last Name\n';
	  
   }
   if (trim(document.frm.f_job.value)=='')
   {
	  myerror=1;
	  myerrormsg=myerrormsg+' -Position\n';
	  
   }
   if (trim(document.frm.f_company.value)=='')
   {
	  myerror=1;
	  myerrormsg=myerrormsg+' -Company\n';
	  
   }
   if (trim(document.frm.f_address1.value)=='')
   {
	  myerror=1;
	  myerrormsg=myerrormsg+' -Address1\n';
	  
   }
   if (trim(document.frm.f_city.value)=='')
   {
	  myerror=1;
	  myerrormsg=myerrormsg+' -City\n';
	  
   }
   if (trim(document.frm.f_postcode.value)=='')
   {
	  myerror=1;
	  myerrormsg=myerrormsg+' -Postcode\n';
	  
   }
   if (trim(document.frm.f_telephone.value)=='')
   {
	  myerror=1;
	  myerrormsg=myerrormsg+' -Telephone\n';
	  
   }
   if (trim(document.frm.f_email.value)=='')
   {
	  myerror=1;
	  myerrormsg=myerrormsg+' -Email Address\n';
   }
   else
   {
      if (isValidEmail(document.frm.f_email.value)==false)   
	  {
		 myerror=1;
	     myerrormsg=myerrormsg+' -Email Address (A Valid one)\n';
		  
	  }
   }
   
   if (document.frm.f_howdid[0].selected)
   {
	    myerror=1;
	    myerrormsg=myerrormsg+' -How did you hear of us\n';
	   
   }
   else
   {
	  if (document.frm.f_howdid[11].selected)   
	  {
		  if (trim(document.frm.f_howdid_other.value)=='')
         {
	        myerror=1;
	        myerrormsg=myerrormsg+' -You have specified that you heard from us via an Other source than those listed, could you tell us where?\n';
         } 
		  
	  }
   }

   if (myerror==1)
   {
      alert(myerrormsg);
      return false;
   }
   else
   {
      return true;
   }
}

