// JavaScript Document

String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ""); };


function validateForm(theForm){
	
	
	try {
		
		var domain = "www.spectodesign.com";
		var appPath = "/servlet/SendContact";
		var message = '';
		var bError = false;
		var index = 0;

		if ( theForm.name.value.trim() == '' ) {
			message ="Please enter a name.\n";
			bError =  true;
			theForm.name.focus(); 
			index = 1;	
		} 
		if(theForm.email.value.trim() ==''){
			
			message +="Please enter an email address.\n";
			bError = true;
			if(index==0){
				index=2;
			} else if(index==1){
				//index=2;
				theForm.name.focus();
			} else {
				index=2;
				theForm.email.focus();
			}
			
		}
		else{
		
			var str=theForm.email.value.trim();
			var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
			if (!filter.test(str)){
				message +="Please enter a valid email address.\n";
				bError = true;
				if(index==0){
					index=2;
				} else if(index==1){
					//index=2;
					theForm.name.focus();
				} else {
					index=2;
					theForm.email.focus(); 
				}
				
			}
		}
		
		if ( theForm.telephone.value.trim() == '' ) {
			message +="Please enter your telephone.\n";
			bError =  true;
			if(index==1){
				theForm.name.focus();
			} else if(index==2){
				theForm.email.focus();
			} else {
				theForm.telephone.focus();
			}
		
		}
		
		if(bError){
			alert(message);
			return false;
		} else {
			theForm.action = 'http://' + domain + appPath;
			theForm.submit();
			return true;
		}

	} catch (e) {
		alert(e.message);
		return false;
	}
	
	


}// end function
