/**
 * Contact form validation
 */

function validateForm(frm) {
	
	var emailFilter=/^[-a-z0-9\._]+@[-a-z0-9\._]+\.+[a-z]{2,3}$/i;
	
	if (trim(frm.salutation.value) == '') {
	   alert('Please select a Title');
	   frm.salutation.focus();
	   return false;
	}
	
	if (trim(frm.first_name.value) == '') {
	   alert('Please fill in your First Name');
	   frm.first_name.focus();
	   return false;
	}
	
	if (trim(frm.last_name.value) == '') {
	   alert('Please fill in your Last Name');
	   frm.last_name.focus();
	   return false;
	}
    
	if (trim(frm.company.value) == '') {
       alert('Please fill in your Organization');
       frm.company.focus();
       return false;
    }
    
	if (trim(frm.title.value) == '') {
       alert('Please fill in your Job Title');
       frm.title.focus();
       return false;
    }
	
	if (trim(frm.city.value) == '') {
       alert('Please fill in your City');
       frm.city.focus();
       return false;
    }
	
	if (trim(frm.state.value) == '') {
       alert('Please fill in your State/Province');
       frm.state.focus();
       return false;
    }
	
	if (trim(frm.zip.value) == '') {
       alert('Please fill in your Zip/Postal Code');
       frm.zip.focus();
       return false;
    }
	
	if (trim(frm.phone.value) == '') {
       alert('Please fill in your Telephone Number');
       frm.phone.focus();
       return false;
    }
	
	if (trim(frm.email.value) == '') {
       alert('Please fill in your Email Address');
       frm.email.focus();
       return false;
    }
	
	if (!emailFilter.test(frm.email.value)) {
       alert('Please make sure your Email Address is valid');
       frm.email.focus();
       return false;
    }
	
	/**
	 * If all of the validation returns true, perform the following functions to get 
	 * appropriate data sent to SalesForce by concatenating data to Comments field (named 'description').
	 */
	 
	if (frm.checkbox.checked) {
	  frm.description.value += '\n\nContact me about The Winslow Assessments';
	}
	
	if (frm.checkbox2.checked) {
	  frm.description.value += '\n\nSend me a preview video';
	}
	
	if (frm.checkbox3.checked) {
	  frm.description.value += '\n\nContact me about Robert speaking to my organization';
	}
	
	if (frm.checkbox4.checked) {
	  frm.description.value += '\n\nSubscribe to Roberts E-mail newsletter';
	}
	
	if (frm.checkbox5.checked) {
	  frm.description.value += '\n\nContact me about Results2X';
	}
	
	if (frm.checkbox6.checked) {
	  frm.description.value += '\n\nI\'m interested in becoming a Certified Results2X Project Manager';
	}
	
	if (frm.checkbox7.checked) {
	  frm.description.value += '\n\nI\'m interested in becoming a Certified Results2X Coach/Consultant';
	}
	
	frm.street.value += '\n\n' + frm.addr2.value;
	
	return true;
 }
 
 function trim(str) {
	str = str.replace(/^\s*|\s*$/g,"");
	return str;
 }