

function formatPhone( str ) {

	var newphone = str.replace(/[^\d]/g, "");
	var phonematches = newphone.match(/^(\d{0,3})(\d{0,3})(\d{0,4})/);
	
	if (phonematches[1].length > 0) 
		newphone = "" + phonematches[1];
	
	if (phonematches[1].length == 3) {
	  
	  newphone += "-" + phonematches[2];
	  
	  if (phonematches[2].length == 3)
		newphone += "-" + phonematches[3];
	}
	
	return newphone;
}	

function formatDate( str ) {

	var newdate = str.replace(/[^\d]/g, "");
	var datematches = newdate.match(/^(\d{0,2})(\d{0,2})(\d{0,4})/);
	
	if (datematches[1].length > 0) 
		newdate = "" + datematches[1];
	
	if (datematches[1].length == 2) {
	  
	  newdate += "/" + datematches[2];
	  
	  if (datematches[2].length == 2)
		newdate += "/" + datematches[3];
	}
	
	return newdate;
}	

function isValidEmail( strEmail ) {
	var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	return !filter.test(strEmail);
}


function validateContactForm() {

	var msg = "";
	
	if( $('name').value == '' ) 
		msg += "&middot Please enter a Name to continue.<br />";	
	
	if( isValidEmail( $('email').value ) || $('email').value == '' ) 	
		msg += "&middot Please enter a valid Email Address to continue.<br />";	
	
	if ( $('subject').value == '' ) 
		msg += "&middot Please enter a Subject to continue.<br />";	
	
	/*
	if ( $('note').value == '' ) 
		msg += "&middot Please enter a Note to continue.<br />";	
	*/
	
	if( msg != "" ) {
		$('company_leadership_message').set( 'html', msg );
		$('company_leadership').fade('in');
	}
	else {
		document.frmContact.submit();
	}
}