function emailCheck(emailStr) {
	var checkTLD=1;
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=emailStr.match(emailPat);

	if (matchArray==null) {
		// alert("Email address seems incorrect (check @ and .'s)");
		return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];
	for (i=0; i<user.length; i++) {
		if (user.charCodeAt(i)>127) {
			// alert("Ths username contains invalid characters.");
			return false;
   		}
	}
	for (i=0; i<domain.length; i++) {
		if (domain.charCodeAt(i)>127) {
			// alert("Ths domain name contains invalid characters.");
			return false;
   		}
	}
	if (user.match(userPat)==null) {
		// alert("The username doesn't seem to be valid.");
		return false;
	}
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {
		for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				// alert("Destination IP address is invalid!");
				return false;
   			}
		}
		return true;
	}
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) {
		if (domArr[i].search(atomPat)==-1) {
			// alert("The domain name does not seem to be valid.");
			return false;
		}
	}
	if (checkTLD && domArr[domArr.length-1].length!=2 && 
		domArr[domArr.length-1].search(knownDomsPat)==-1) {
		// alert("The address must end in a well-known domain or two letter " + "country.");
		return false;
	}
	if (len<2) {
		// alert("This address is missing a hostname!");
		return false;
	}
	return true;
}

function validate(thisForm, actionStr) {
	var fullActionStr=actionStr;
	with (document.forms[thisForm]) {
		var alertMessage = "";
		if (Workshop.value == -1) alertMessage += "\nWorkshop Name";
		if (Location.value == -1) alertMessage += "\nLocation";
		if (StartDate.value == "") alertMessage += "\nDate";
		if (CustomerFirstName.value == "") alertMessage += "\nFirst Name";
		if (CustomerLastName.value == "") alertMessage += "\nLast Name";
		if (JobTitle.value == "") alertMessage += "\nJob Title";
		if (Organisation.value == "") alertMessage += "\nOrganisation";
		if (CustomerEmail.value == "") alertMessage += "\nEmail";
		if (CustomerPhone.value == "") alertMessage += "\nPhone Number";
		if (CustomerAddress.value == "") alertMessage += "\nStreet Address";
		if (CustomerSuburb.value == "") alertMessage += "\nSuburb";
		if (CustomerState.value == -1) alertMessage += "\nState";
		}
	return alertMessage;
}

function SubmitForm(formName, actionStr, needValidate) {
      var strResult;
    if (actionStr.indexOf("operation=CancelRegistration")>0){
		var user_input;
		user_input=false;
	    user_input=confirm("Are you sure you want to cancel this registration");
		if (user_input==true){
			document.forms[formName].action = actionStr;
			document.forms[formName].target = '_top';
			document.forms[formName].submit(); 
		}
		return true; 
	}
	if(needValidate==false) {
		document.forms[formName].action = actionStr;
		document.forms[formName].target = '_top';
		document.forms[formName].submit();
	 }
	 else {
	     strResult=validate(formName, actionStr);
		if (strResult==""){
			document.forms[formName].action = actionStr;
			document.forms[formName].target = '_top';
			document.forms[formName].submit(); 
		}
		else {
			if (actionStr.indexOf("operation=Finish")>0){
				var input_box=confirm(	"The following fields are missing:\n" + strResult 
				                        + "\n\nClick Cancel to stay on this page or click OK to see the Booking Summary page");

										
				if (input_box==true){
					document.forms[formName].action = actionStr+"&skip=true";
					document.forms[formName].target = '_top';
					document.forms[formName].submit();
				}
			}
		}
	}
	return true;
}

function EditRegistration(actionStr, eventNum, customerNum){
    var actionTxt,formName;
	formName="formSummary";
	document.forms[formName].elements["EventID"].value=eventNum;
    document.forms[formName].elements["CustomerID"].value=customerNum;
	actionTxt=trimAll(actionStr);
    if (actionTxt=="DeleteCustomer"){
       var input_box=confirm("Are you sure you want to delete this attendee?");
	   if (input_box==true){
	      document.forms[formName].action ="register.asp?operation=DeleteCustomer";
		  document.forms[formName].target = '_top';
		  document.forms[formName].submit(); 
	   }
	  return true;       
    }
    if (actionTxt=="AddRegistration"){
	   document.forms[formName].action ="register.asp?operation=AddRegistration";
	   document.forms[formName].target = '_top';
	   document.forms[formName].submit(); 
	   return true;       
    }
	if(actionTxt=="AddEventForCustomer"){
	   document.forms[formName].action ="register.asp?operation=AddEventForCustomer";
	   document.forms[formName].target = '_top';
	   document.forms[formName].submit(); 
	   return true;   
   }
  if(actionTxt=="EditEventForCustomer"){
	   document.forms[formName].action ="register.asp?operation=EditEventForCustomer";
	   document.forms[formName].target = '_top';
	   document.forms[formName].submit(); 
	   return true;   
   }
  return false;
}

function object_Exists(objectToBeChecked) {
	if (objectToBeChecked == null)
		return false;
	else
		return true;
}

function trimAll(sString) {
	while (sString.substring(0,1) == ' ') {
  		sString = sString.substring(1, sString.length); 
	}
	while (sString.substring(sString.length-1, sString.length) == ' ') {
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}
function disableHearFrom(){
	var box, source;
	box = document.forms[0].elements["cmbHearFrom"];
	source = box.options[box.selectedIndex].value;
	if (source != "Other"){
		document.forms[0].elements["txtHearFrom"].value="";
		document.forms[0].elements["txtHearFrom"].disabled=true;
	}
	else{
		document.forms[0].elements["txtHearFrom"].disabled=false; 
	}
	return true;
}