// 07/11/2011 Doug Smith, updated email validation to allow quotes, parenteses and apostrophes.  1904 1.0
// 07/14/2011 Doug Smith, updated to include commas in the alert message.  1904 1.0

function isEmpty(strTextField) {
   if ((strTextField.value.length==0) ||
   (strTextField.value==null)) {
      return true;
   }
   else { return false; }
}	

function formValidate(){
var legals = /[^\w\/\-\s\.\?\$\@\,\"\'\(\)]/

  if (isEmpty(document.getElementById('txtName'))){
    alert("Please enter your full name.");
    document.getElementById('txtName').focus();
    return false;
  }
  
if (document.getElementById('txtName').value.match(legals)) {
		alert("Invalid entry!  Only letters, numbers, spaces, underscores [ _ ], periods, commas, question marks, quote marks,  parentheses, apostrophes, forward slashes [ / ],  hyphens [ - ], dollar signs and the at symbol [@] are accepted.")
		document.getElementById('txtName').focus()
		return false
	}

	
	var illegals = /[^@\-\.\w]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/
 	var check = /@[\w\-]+\./
 	var checkend = /\.[a-zA-Z]{2,4}$/
 	if(((document.getElementById('Email').value.search(illegals) != -1) || (document.getElementById('Email').value.search(check)) == -1) || (document.getElementById('Email').value.search(checkend) == -1)){	
		alert("Please enter a correctly formatted E-mail address.")
    document.getElementById('Email').focus();
    return false;
  } 	

  if (isEmpty(document.getElementById('FinancialInstitution'))){
    alert("Please enter the name of your Financial Institution.");
    document.getElementById('FinancialInstitution').focus();
    return false;
  }
  
  if (document.getElementById('FinancialInstitution').value.match(legals)) {
		alert("Invalid entry!  Only letters, numbers, spaces, underscores [ _ ], periods, commas, question marks, quote marks,  parentheses, apostrophes, forward slashes [ / ],  hyphens [ - ], dollar signs and the at symbol [@] are accepted.")
		document.getElementById('FinancialInstitution').focus()
		return false
	}

	if (document.getElementById('Phone').value.match(legals)) {
		alert("Invalid entry!  Only letters, numbers, spaces, underscores [ _ ], periods, commas, question marks, quote marks,  parentheses, apostrophes, forward slashes [ / ],  hyphens [ - ], dollar signs and the at symbol [@] are accepted.")
		document.getElementById('Phone').focus()
		return false
	}
	
	
  var zip = document.getElementById('Zipcode')
  if (isEmpty(zip)){
    alert("Please enter your ZIP code/Mail code.");
    zip.focus();
    return false;
  }

  if (document.getElementById('Zipcode').value.length < 5)
  {
    alert("Please enter at least 5 characters for your ZIP code/Mail code.");
    document.getElementById('Zipcode').focus();
    return false;
  }
  
  if (document.getElementById('Zipcode').value.match(legals)) {
		alert("Invalid entry!")
		document.getElementById('Zipcode').focus()
		return false
	}
	

  
 if (document.getElementById('textarea').value.match(legals)) {
		alert("Invalid entry!  Only letters, numbers, spaces, underscores [ _ ], periods, commas, question marks, quote marks,  parentheses, apostrophes, forward slashes [ / ],  hyphens [ - ], dollar signs and the at symbol [@] are accepted.")
		document.getElementById('textarea').focus()
		return false
	}
   if (document.getElementById('textarea').value.length > 2000)
  {
    alert("Please shorten your comments, no more than 2000 characters are allowed.");
    document.getElementById('textarea').focus();
    return false;
  } 
  
 document.getElementById('frmSignin').submit()
}
