// JavaScript Document

function submitform ( selectedtype )
{
  document.onlinequote.formaction.value = selectedtype ;
  
  var oktosubmit = 1;
   
  


	var emailStr=document.onlinequote.email.value;
	
	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);
	
	// Check basic formatting
	
	if (matchArray==null) {
		alert("Your email address seems incorrect (check @ and .'s)");
		document.onlinequote.email.focus();
	oktosubmit = 0;
	}
	
	var user=matchArray[1];
	var domain=matchArray[2];
	
	// Start by checking that only basic ASCII characters are in the strings (0-127).
	
	for (i=0; i<user.length; i++) {
	if (user.charCodeAt(i)>127) {
		alert("Your email address contains invalid characters.");
		document.onlinequote.email.focus();
	oktosubmit = 0;
	   }
	}
	for (i=0; i<domain.length; i++) {
	if (domain.charCodeAt(i)>127) {
		alert("Your email address contains invalid characters.");
		document.onlinequote.email.focus();
	oktosubmit = 0;
	   }
	}
	
	// See if "user" is valid 
	
	if (user.match(userPat)==null) {
	
	// user is not valid
	
		alert("Your email address is invalid - check the part before the @ symbol.");
		document.onlinequote.email.focus();	
	oktosubmit = 0;
	}
	
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {
	
	// this is an IP address
	
	for (var i=1;i<=4;i++) {
	if (IPArray[i]>255) {
		alert("Your email address is invalid - destination IP address is invalid!");
		document.onlinequote.email.focus();
	oktosubmit = 0;
	   }
	}
	oktosubmit = 1;
	}
	
	// Domain is symbolic name.  Check if it's valid.
	 
	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("Your email address does not seem to be valid.");
		document.onlinequote.email.focus();	
	oktosubmit = 0;
	   }
	}
	
	if (checkTLD && domArr[domArr.length-1].length!=2 && 
	domArr[domArr.length-1].search(knownDomsPat)==-1) {
		alert("Your email address is invalid: it must end in a well-known domain or two letter country.");
		document.onlinequote.email.focus();
	oktosubmit = 0;
	}
	
	// Make sure there's a host name preceding the domain.
	
	if (len<2) {
		alert("Your email address is invalid: it is missing a hostname (the bit after the @ symbol)");
		document.onlinequote.email.focus();
	oktosubmit = 0;
	}

  // This just checks that the form has been filled out correctly
  // There is a different JS routine to check the email address is valid
    
  if (document.onlinequote.name.value == "") {
    alert( "Please enter your name." );
    document.onlinequote.name.focus();
    oktosubmit = 0 ;
  }  
  
  if (document.onlinequote.tel.value == "") {
    alert( "Please enter a contact telephone number." );
    document.onlinequote.tel.focus();
    oktosubmit = 0 ;
  }  
  
  if (document.onlinequote.email.value == "") {
    alert( "Please enter your email address." );
    document.onlinequote.email.focus();
    oktosubmit = 0 ;
  }

  if (document.onlinequote.address.value == "") {
    alert( "Please enter your address." );
    document.onlinequote.address.focus();
    oktosubmit = 0 ;
  }

  if (document.onlinequote.type.value == "") {
    alert( "Please enter the type of event." );
    document.onlinequote.type.focus();
    oktosubmit = 0 ;
  }
  
  if (document.onlinequote.location.value == "") {
    alert( "Please enter the location of event." );
    document.onlinequote.location.focus();
    oktosubmit = 0 ;
  }
  
    if (document.onlinequote.date.value == "") {
    alert( "Please enter the date of event." );
    document.onlinequote.date.focus();
    oktosubmit = 0 ;
  }
  
    if (document.onlinequote.attendees.value == "") {
    alert( "Please enter the number of attendees of event (or an estimate)." );
    document.onlinequote.attendees.focus();
    oktosubmit = 0 ;
  }
  
  // ** END **

  if (oktosubmit == 1){
  document.onlinequote.submit() ;
  }

}

