function checkform ( form ) { 
  if (form.description.value == "") {
    alert( "Please enter your project description." );
    form.description.focus();
    return false ;
  }      

  else if (form.firstname.value == "") {
    alert( "Please enter your first name." );
    form.firstname.focus();
    return false ;
  }
  
  else if (form.lastname.value == "") {
    alert( "Please enter your last name." );
    form.lastname.focus();
    return false ;
  }
 
  else if (form.phone.value == "") {
    alert( "Please enter your phone number." );
    form.phone.focus();
    return false ;
  }
  
  else if(form.phone.value.search(/\d{3}\-\d{3}\-\d{4}/)==-1) {
      alert("Please enter a phone number with the format xxx-xxx-xxxx.");
      form.phone.focus();
      return false;
   }

  else if (form.email.value == "") {
    alert( "Please enter your email address." );
    form.email.focus();
    return false ;
  }
  
  else if ( isValidEmail(form.email.value) == false ) {
    alert( "The email address you entered\r\ndoes not appear to be valid.\r\nPlease re-enter your email address." );
    form.email.focus();
    return false ;  	
  }
  
  return true ;
}

function isValidEmail(str) {
  // These comments use the following terms from RFC2822:
  // local-part, domain, domain-literal and dot-atom.
  // Does the address contain a local-part followed an @ followed by a domain?
  // Note the use of lastIndexOf to find the last @ in the address
  // since a valid email address may have a quoted @ in the local-part.
  // Does the domain name have at least two parts, i.e. at least one dot,
  // after the @? If not, is it a domain-literal?
  // This will accept some invalid email addresses
  // BUT it doesn't reject valid ones. 
  var atSym = str.lastIndexOf("@");
  if (atSym < 1) { return false; } // no local-part
  if (atSym == str.length - 1) { return false; } // no domain
  if (atSym > 64) { return false; } // there may only be 64 octets in the local-part
  if (str.length - atSym > 255) { return false; } // there may only be 255 octets in the domain

  // Is the domain plausible?
  var lastDot = str.lastIndexOf(".");
  // Check if it is a dot-atom such as example.com
  if (lastDot > atSym + 1 && lastDot < str.length - 1) { return true; }
  //  Check if could be a domain-literal.
  if (str.charAt(atSym + 1) == '[' &&  str.charAt(str.length - 1) == ']') { return true; }
  return false;
}

function confirm() {
	alert ("Thank you. Your request has been sent.");
}

function parseparam( name ) {
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return null;
  else
    return results[1];
}

var submit_param = parseparam( 'result' );
if ( submit_param != null ) {
  alert ("Thank you. Your request has been submitted.");
}
