//disable return key for sumbitting; 
 function checkCR(evt) {
    var evt  = (evt) ? evt : ((event) ? event : null);
    var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
    if ((evt.keyCode == 13) && (node.type=="text")) {return false;}
  }
  document.onkeypress = checkCR;
  

//by LA 8/1/05 -- check to make sure either email, phone, or fax entered (required). also required are name and comments. If email entered, validates '@' then '.com, .gov, ...'
//broken up like this because I wanted all required items in same alert popup
var submitcount=0;
function valCheck() {
nameField = document.forms[1].Name.value;
commentsTextarea = document.forms[1].Comments.value;
emailField = document.forms[1].email.value;
phoneField = document.forms[1].Phone.value;
faxField = document.forms[1].Fax.value;

if (((emailField == "") && (phoneField == "") && (faxField == "")) && (nameField == "") && (commentsTextarea == ""))  {
	alert('• Please enter your name.\n• You must enter either an Email Address, Phone or Fax #\n• Do not forget your comments.');
	document.forms[1].Name.focus();
return false;
}
if ((nameField == "") && (commentsTextarea == "")) {
	alert('• Please enter your name.\n• Do not forget your comments.'); 
	document.forms[1].Name.focus();
return false;
}
if (((emailField == "") && (phoneField == "") && (faxField == "")) && (nameField == ""))  {
	alert('• Please enter your name.\n• You must enter either an Email Address, Phone or Fax #');
	document.forms[1].Name.focus();
return false;
}
if (((emailField == "") && (phoneField == "") && (faxField == "")) && (commentsTextarea == ""))  {
	alert('• You must enter either an Email Address, Phone or Fax #\n• Do not forget your comments.'); 
	document.forms[1].email.focus();
return false;
}
if ((emailField == "") && (phoneField == "") && (faxField == ""))  {
	alert('• You must enter either an Email Address, Phone or Fax #');
	document.forms[1].email.focus();
return false;
}
if (nameField == "")  {
	alert('• Please enter your name.');
	document.forms[1].Name.focus();
return false;
}
if (commentsTextarea == "")  {
	alert('• Do not forget your comments.');
	document.forms[1].Comments.focus();
return false;
}
if (emailField != "")   {
      txt=document.forms[1].email.value;
		var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  var isOK = !r1.test(txt) && r2.test(txt);
  if (!isOK) {
  	alert('Your email address is invalid.');
	document.forms[1].email.focus();
  return isOK;
  }
  else if (isOK) {
	  document.forms[1].submit.value = "  Sending...  ";
	  document.forms[1].submit.disabled = true;
	  }
}

document.forms[1].submit.value = "  Sending...  ";
document.forms[1].submit.disabled = true;
return true;	
} //end function valCheck()


function makeDate(){
	var tmpDate = new Date();
	var tmpYear = tmpDate.getFullYear() 
	var tmpMonth = tmpDate.getMonth() + 1
	if (tmpMonth<10) tmpMonth="0"+tmpMonth;
	var tmpDay = tmpDate.getDate()
	if (tmpDay<10) tmpDay="0"+tmpDay;
	var tmpHour = tmpDate.getHours()
	if (tmpHour<10) tmpHour="0"+tmpHour;
	var tmpMinute = tmpDate.getMinutes()
	if (tmpMinute<10) tmpMinute="0"+tmpMinute;
	var tmpSecond = tmpDate.getSeconds()
	if (tmpSecond<10) tmpSecond="0"+tmpSecond;
	var tmpSerial = tmpMonth.toString()+"/"+tmpDay.toString()+"/"+tmpYear.toString() +" "+ tmpHour.toString()+":"+tmpMinute.toString()+":"+tmpSecond.toString();
	return(tmpSerial);
}
function getDate() {
	document.contactUsForm.email_title.value = "Contact Us FNWValve.com " + makeDate();
}


//removes extra white spaces from fields onblur
function trim(str)
{
  return compressWhiteSpace(str);
}
function compressWhiteSpace(s) {
  // Condense white space.
  s = s.replace(/\s+/g, " ");
  s = s.replace(/^\s(.*)/, "$1");
  s = s.replace(/(.*)\s$/, "$1");
  // Remove uneccessary white space around operators, braces and parentices.
  //s = s.replace(/\s([\x21\x25\x26\x28\x29\x2a\x2b\x2c\x2d\x2f\x3a\x3b\x3c\x3d\x3e\x3f\x5b\x5d\x5c\x7b\x7c\x7d\x7e])/g, "$1");
 // s = s.replace(/([\x21\x25\x26\x28\x29\x2a\x2b\x2c\x2d\x2f\x3a\x3b\x3c\x3d\x3e\x3f\x5b\x5d\x5c\x7b\x7c\x7d\x7e])\s/g, "$1");
  return s;
}


