/*validation for masterSpec.jsp by LMA 02/10 */

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.masterSpecForm.email_title.value = "MasterSpec Specifications FNWValve.com " + makeDate();
}


//removes  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");
  return s;
}


/* format phone on blur */
//phone and fax number formatting
function doThis(nums){

var re= /\D/;
// test for this format: xxx-xxxx
//var re2 = /^\d{3}-\d{4}/; 
// test for this format: (xxx)xxx-xxxx
var re2 = /^\({1}\d{3}\)\s\d{3}-\d{4}/; 
// test for this format: xxx-xxx-xxxx
//var re2 = /^\d{3}-\d{3}-\d{4}/;

for (i=0; i<nums.length;i++){
var num=eval(nums+'.value');

var newNum;
 if (num != "" && re2.test(num)!=true){
   if (num != ""){
     while (re.test(num)){
     num = num.replace(re,"");
	}
   }

  if (num.length != 10){
    alert('Please enter a 10 digit number');
    eval(nums).select();
    break;
    }
   else {
	   // for format  xxx-xxxx
     //newNum = num.substring(0,3) + '-' + num.substring(3,7);
     // for format (xxx) xxx-xxxx
     newNum = '(' + num.substring(0,3) + ')' + ' ' + num.substring(3,6) + '-' + num.substring(6,10);
     // for format xxx-xxx-xxxx
     // newNum = num.substring(0,3) + '-' + num.substring(3,6) + '-' + num.substring(6,10);
     eval(nums).value=newNum;
     }
   }
  }
}





/* validate form */
function masterSpecFormChecker(form) {
    var errors='';
    var fieldFocus='';
	var formPass = false;
    //check the simple basic stuff first.
    //there is probobly a more glamorous way to do all this,  but I kept it simple since this is for single use. 
    if (form.name.value == '') {
        errors += 'Your Name is required.\n';
		if (fieldFocus == '') {
			fieldFocus = 'form.name';
		}
    }
	if (form.company.value == '') {
        errors += 'Company Name is required.\n';
		if (fieldFocus == '') {
			fieldFocus = 'form.company';
		}
    }
	
	if (form.email.value == '') {
        errors += 'Email address is required.\n';
		if (fieldFocus == '') {
			fieldFocus = 'form.email';
		}
    }
    
		//if email address is entered ensure it is valid
		if (form.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(form.email.value) && r2.test(form.email.value);
				if (!isOK) {
					errors += 'Your e-mail address is not in the proper format.\n';
					if (fieldFocus == '') {
						fieldFocus = form.email;
					}
				}
		}
	
	
    if (form.phone.value == '') {
        errors += 'Phone Number is required.\n';
		if (fieldFocus == '') {
			fieldFocus ='form.phone';
    	}
    }
		//if phone is entered ensure it is valid
			if (form.phone.value != '') {
				var rx=new RegExp("^\\(\\d{3}\\)\\s\\d{3}\\-\\d{4}");
				if (!rx.test(form.phone.value)) {
					errors += 'Please format your phone number (###) ###-####.\n';
					  if (fieldFocus == '') {
						fieldFocus ='form.phone';
					}
				}
			}
	

	
   
	//make sure Business Type is not left on ""
	 if (form.busType.value == '') {
            errors += 'Your Business Type is required.\n';
			if (fieldFocus == '') {
				fieldFocus ='form.busType';
			}
        }
   	
	
	//make sure Section/Numbering Format is not left on ""
	 if (form.numFormat.value == '') {
            errors += 'Section/Numbering Format is required.\n';
			if (fieldFocus == '') {
				fieldFocus ='form.numFormat';
			}
        }
		
		//make sure Version is not left on ""
	 if (form.version.value == '') {
            errors += 'Your Version is required.\n';
			if (fieldFocus == '') {
				fieldFocus ='form.version';
			}
        }
		
		//make sure Document Length is not left on ""
	 if (form.docLength.value == '') {
            errors += 'Document Length is required.\n';
			if (fieldFocus == '') {
				fieldFocus ='form.docLength';
			}
        }
		
		//make sure File Format is not left on ""
	 if (form.fileFormat.value == '') {
            errors += 'File Format is required.\n';
			if (fieldFocus == '') {
				fieldFocus ='form.fileFormat';
			}
        }
	
  
	
 //make sure one of these radio buttons is selected
    if (!form.license[0].checked) {
        errors += 'Have you read and agreed to the licensing agreement?\n';
    }
 

    //return failures if it failed validation
    if (errors != ''){
        alert('The required information is incomplete or contains errors:\t\t\t\t\t\n\n'+errors);
		return false;
		
		//strip out extra white space
	} else {
		 
		for (var i=0;i<form.length;i++) {
			fieldValue = form.elements[i].value;
  			fieldValue = fieldValue.replace(/\s+/g, " ");
  			fieldValue = fieldValue.replace(/^\s(.*)/, "$1");
  			fieldValue = fieldValue.replace(/(.*)\s$/, "$1");
			form.elements[i].value = fieldValue;
		}
		return true;
    }
}

<!-- Web Site:  http://dynamicdrive.com -->
<!-- Begin disable submit button after clicked to prevent multiple submittals
function onKeyPress () {
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;
if (keycode == 13) {
//alert("Please click on the Send Request button to submit form.");
return false
}
return true 
}
document.onkeypress = onKeyPress;
//  End -->
