ralentango.forms={version:2131};jQuery.fn.addOption=function(value,text){this.each(function(){if(this.nodeName.toLowerCase()!="select")return;option=document.createElement("option");option.value=value;option.text=text;this.options.add(option)});return this};ralentango.classifyInputs=function(){$("input[type='file']").addClass("fileinput");$("input[type='password']").addClass("password");$("input[type='text']").addClass("textinput");$("input[type='checkbox']").addClass("checkbox");$("input[type='radio']").addClass("radio");$("input[type='hidden']").addClass("hidden")};ralentango.linkForms=function(){var action=function(){return ralentango.handleFormEvent(this)};$("input[type='text'], input[type='password'], input[type='file'], textarea, select").bind("change",action).bind("blur",action);$("input[type='checkbox'], input[type='radio'], button").bind("click",action)};ralentango.resetForms=function(){$("form").each(function(){ralentango.resetForm(this)})};ralentango.handleFormEvent=function(element){var $element=$(element);var $form=$element.parents("form");if(!$form.length)return false;var form=$form.get(0);if(element.type=="submit"){if(!ralentango.FormReadyToGo(form))return false;var smsg="Are you sure that want to submit these details";if($("#formprocessed",form).length){if(!confirm(smsg+" a second time?"))return false;$("#formprocessed",form).remove()}else if($form.is(".confirm"))if(!confirm(smsg+"?"))return false;$form.after(env("div",{id:"formsubmitted","class":"forminfo"},"Processing your submission ...")).filter(".hideafter").hide("normal");if($form.is(".ajax")){aps={ajax:"true"};$form.find("input, textarea, select").not("[type='radio']").not("[type='checkbox']").add(":checked").each(function(){if(this.value!="")aps[this.name]=this.value});$.post($form.attr("action"),aps,function(htm){$("#formsubmitted").remove();$form.show("normal").after(htm);if($("#formprocessed").size())$("#formprocessed")[0].scrollIntoView(false)});return false}return true}$("#formprocessed").remove();if(element.type=="reset"){if(confirm("Reset all the fields on this form?"))ralentango.resetForm($form.get(0));return false}if(element.type=="button"){if(!$element.is(".formtortf"))return false;aps={ajax:"true"};$form.find("input, textarea, select").not("[type='radio']").not("[type='checkbox']").add(":checked").each(function(){if(this.value!="")aps[this.name]=this.value});$.post("scripts/formtortf.php",aps,function(htm){alert(htm)});return false}$("[type=reset]",form).each(function(){this.disabled=false});if(!ralentango.checkElement(element))return false;var qpl=$element.parents("label");if(qpl.length>0)if(element.value||(qpl.textValue().search(/"Please correct"/i)>=0))ralentango.setElementLabel(element);$("[type=submit]",form).each(function(){this.disabled=!ralentango.FormReadyToGo(form,true)});return true};ralentango.resetForm=function(form){$("input[type='radio'], input[type='checkbox']",form).each(function(){this.checked=this.defaultChecked});$("input[type='text'], input[type='password'], input[type='file'], select, textarea",form).each(function(){this.value=this.defaultValue;ralentango.setElementLabel(this)});$("[type=submit]",form).each(function(){this.disabled=false&&!ralentango.FormReadyToGo(form,true)});$("[type=reset]",form).each(function(){this.disabled=true});return true};ralentango.checkElement=function(element){if($(element).is(".email")){if(element.value){if(!/@.*\./.test(element.value)){ralentango.setElementLabel(element,"correct");element.focus();return false}}}return true};ralentango.setElementLabel=function(element,dowhat){var $label=$(element).parents("label");if(!$label.length)return false;var labeltext=$label.textValue().replace(/^Please \w* /,"");var lt0=labeltext.substr(0,1);if(arguments.length<2){lt0=lt0.toUpperCase();$label.removeClass("formerror")}else{lt0="Please "+dowhat+" "+lt0.toLowerCase();$label.addClass("formerror")}$label.textValue(lt0+labeltext.substr(1));return true};ralentango.FormReadyToGo=function(form,quiet){if(arguments.length<2)quiet=false;if($("#formprocessed.formerror").length)return false;if($("#formsubmitted").length){if(!quiet)alert("The form is already being processed");return false}var ok=true;$(form).find("input, select, textarea").not("[type='hidden']").each(function(){if(!ralentango.checkElement(this))ok=false}).filter(".required").each(function(){if(!this.value){if(!quiet)ralentango.setElementLabel(this,this.tagName=="SELECT"?"":"give");ok=false}});if(ok)return true;if(!quiet){$(form).after(env("div",{id:"formprocessed","class":"formerror"},"There are errors in the form that prevent it being processed."));if($("#formprocessed").size())$("#formprocessed")[0].scrollIntoView(false)}return false};$(document).ready(function(){ralentango.classifyInputs();ralentango.linkForms();ralentango.resetForms();console.log("Loaded forms extension "+ralentango.formsversion)});
