
// Validate the add an event form.
        // Declaring required variables
        var digits = "0123456789";
        // non-digit characters which are allowed in phone numbers
        var phoneNumberDelimiters = "()- ";
        // characters which are allowed in international phone numbers
        // (a leading + is OK)
        var validWorldPhoneChars = phoneNumberDelimiters + "+";
        // Minimum no of digits in an international phone no.
        var minDigitsInIPhoneNumber = 10;

        function isInteger(s){
            var i;
            for (i = 0; i < s.length; i++){   
                // Check that current character is number.
                var c = s.charAt(i);
                if (((c < "0") || (c > "9"))) return false;
            }
            // All characters are numbers.
            return true;
        }

        function stripCharsInBag(s, bag){
            var i;
            var returnString = "";
            // Search through strings characters one by one.
            // If character is not in bag, append to returnString.
            for (i = 0; i < s.length; i++){   
                var c = s.charAt(i);
                if (bag.indexOf(c) == -1) returnString += c;
            }
            return returnString;
        }

        function isInternationalPhone(strPhone){
            s=stripCharsInBag(strPhone,validWorldPhoneChars);
            return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
        }
       
        function checkPhone(nm){
            if (isInternationalPhone(nm.value)==false){
                nm.focus()
                alert("This is not a valid phone number. Please try again.")
                return false
            }
            return true
        }
        
        function checkCat(cat){
          if (cat.value==""){
             cat.focus()
             alert("Please select the event category type")
             return false
          }
          return true;
        }
        
        function checkLocation(loc){
          if (loc.value==""){
             loc.focus()
             alert("Please enter the location of the event")
             return false
          }
          return true;
        }
        
        function checkTown(town){
          if (town.value==""){
             town.focus()
             alert("Please select the town where the event is to take place.")
             return false
          }
          return true;
        }
        
        function checkEmail(email){
          if (town.value==""){
             town.focus()
             alert("Please select the town where the event is to take place.")
             return false
          }
          return true;
        }
        
        function checkEmail(email){
		  var email1 = /^[^@]+@[^@.]+\.[^@]*\w\w$/  ;
		  var email2 = /^[A-Za-z][\w.-]+@\w[\w.-]+\.[\w.-]*[A-Za-z][A-Za-z]$/  ;
	      
	      if(email.value.length > 0){
		    if (!email1.test(email.value)) {
		      email.focus()
		      alert ("ERROR: not a valid e-mail address");
		      return false;
		    }

		    if (!email2.test(email.value)){
              email.focus()
		      alert ("Unusual e-mail address - check if correct");
		      return false;
		    }else{
		      return true;
		    }
		  }
		}
//]]>