function contactUsFormValidation(){var errors={},tmp={};tmp=$$("form *[name=name]").pop();if(tmp!=null){tmp=tmp.value.replace(/[^a-z]/ig,"");if(tmp.match(/^[a-z]{3,}$/i)==null)tmp=null;}if(tmp==null)errors.name="Please enter your full name.";tmp=$$("form *[name=comments]").pop();if(tmp!=null){tmp=tmp.value.replace(/[^a-z]/ig,"");if(tmp.match(/^[a-z]{3,}$/i)==null)tmp=null;}if(tmp==null)errors.comments="Please enter a comment.";showcontactUsFormErrors(errors);return false;} function showcontactUsFormErrors(errors) { var errDiv = new Element('div', {id:'contact-us-form-errors'}).hide(), effects=[], contactForm=$$('form')[0]; // create effects to highlight each row that has an error for(field in errors) { field = $$('input[name='+field+'], textarea[name='+field+']')[0]; if (!field.hasClassName('error')) { effects.push( new Effect.Morph(field, { style: 'error', sync: true }) ); } /* errDiv.appendChild( new Element('p').update(errors[field.name]) ); */ } var fields = $$('input, textarea').pluck('name'); var errorFields = Object.keys(errors); if (errorFields.length > 0) { errDiv.appendChild( new Element('p').addClassName('error').update("Please enter your name and comment.") ); } // create effect for each field that WAS an error, but now passes validation fields.each(function (name) { if (errorFields.include(name) || !$$('input[name='+name+'],textarea[name='+name+']')[0].hasClassName('error')) return; effects.push( new Effect.Morph($$('input[name='+name+'], textarea[name='+name+']')[0], { style: 'error', sync: true, transition: Effect.Transitions.reverse, afterFinish: function (e) { e.element.removeClassName('error'); } }) ); }); // did we have an error message displaying already? then slide it up in half the time the rest of the // animations will take, replace the contect with the new error messages, and slide it back down if (contactForm.down('div#contact-us-form-errors') != null) { effects.push( new Effect.BlindUp(contactForm.down('div'), { duration: .25, sync: true, afterFinish:function (e) { e.element.replace(errDiv); new Effect.BlindDown(errDiv, { duration: .25 }) } }) ); } // otherwise, show the new error messages else { contactForm.insert({top:errDiv}); effects.push( new Effect.BlindDown(errDiv, {sync:true}) ); } // run all the effects that we just set up in parallel new Effect.Parallel(effects, { duration: .5 }); // no errors found? disable the submit button and submit the form if (Object.keys(errors).length == 0) { contactForm.down('button').disabled = true; if (effects.length == 0) contactForm.submit(); else setTimeout('$("contactForm").submit()', 500); } }