function setup() {

}

function page_continue() {
	if (validateEmail() && validatePhoneNumber()) {
		document.page.submit();		
	}
}

function validateEmail() {
  emailAddr = document.page['elements'].emailaddress;
                
  emailStr = String(emailAddr.value);
        
  // checks if the e-mail address is valid
  var emailPat = /^(\".*\"|[A-Za-z0-9\_][A-Za-z0-9\.\-\_]*)@(\[\d{1,3}(\.\d{1,3}){3}]|([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,3})$/;
  var matchArray = emailStr.match(emailPat);
  if (matchArray == null) {
    emailAddr.select();
    emailAddr.focus();
    validateAlert("Please enter a valid email address into %f.\n(check the '@' and '.' characters)", emailAddr);
    return false;
  }
  // make sure the IP address domain is valid
  var IPArray = matchArray[2].match(/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/);
  if (IPArray != null) {
    for (var i=1; i<=4 ;i++) {
      if (IPArray[i]>255) {
        emailAddr.select();
        emailAddr.focus();
        validateAlert("Please enter a valid destination IP address into %f.", emailAddr)
        return false;
      }
    }
  }
  return true;
}


function validatePhoneNumber() {
  var phoneNumber = document.page['elements'].phonenumber;
  if (phoneNumber.value =="")
    return true;
        
  //var pattern = /^(([0-9]+)|([1-9][0-9]{0,2}(,[0-9]{3})+))$/;
  var pattern = /[0-9]/;
  
  if ((!phoneNumber.value || phoneNumber.value == "") || phoneNumber.value.search(pattern) < 0) {
    phoneNumber.select();
    phoneNumber.focus();
  
    var message;
      
    if (isNaN(parseInt(phoneNumber.value.replace(/,/g, ''), 10))) {
      message = "You have entered details in the telephone number field which do not include any digits.";
      alert(message) ;
    } else {
      message = "You have entered details in the telephone number field which do not include any digits.";
      alert(message) ;
    }
    
    return false;
  }
   
  var num = parseInt(phoneNumber.value, 10);
  var minValue = 1;
  var maxValue = Number.MAX_VALUE;
  
  if (!isNaN(phoneNumber.minValue))
    minValue = Math.max(phoneNumber.minValue, minValue);
  if (!isNaN(phoneNumber.maxValue))
    maxValue = Math.min(phoneNumber.maxValue, maxValue);
  
  if (num < minValue) {
    phoneNumber.select();   
    phoneNumber.focus();
 
    message = "You have entered details in the telephone number field which do not include any digits.";
    alert(message) ;
  
    return false;
  } else if (num > phoneNumber.maxValue) {
    phoneNumber.select();
    phoneNumber.focus();
    
    message = "You have entered details in the telephone number field which do not include any digits.";
    alert(message) ;
      
    return false;
  }
  return true;
}
     

