String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")};function validate(form){try{validate_startup()}catch(e){}var valid=true;try{tinyMCE.triggerSave()}catch(e){}var elements=new Array();if(form.tagName.toString().toLowerCase()=="form"){var elements=form.getElementsByTagName("*")}else{elements[0]=form;while((form.tagName.toString().toLowerCase()!="form")&&(form.parentNode!=null)){form=form.parentNode}if(form.tagName.toString().toLowerCase()!="form"){elements=new Array()}}for(var eCounter=0;eCounter<elements.length;eCounter++){var element=elements[eCounter];var alt=element.getAttribute("alt");if((alt!=null)&&(alt!=undefined)&&(alt!="")){try{eval("var responseObj = "+alt)}catch(e){continue}var oldElementValue=element.value;element.value=element.value.trim();var elementError=false;var errorMessage="";var required=false;if(responseObj.required!=undefined){required=responseObj.required}if(required){var requiredMessage="Required field";if(responseObj.required_message!=undefined){requiredMessage=responseObj.required_message}if(element.value.length==0){elementError=true;errorMessage=requiredMessage}}if((!elementError)&&(element.value.length>0)&&((responseObj.group==null)||(check_group_validation(form,element,responseObj.group)))){for(var vCounter=0;vCounter<responseObj.validators.length;vCounter++){if(responseObj.validators[vCounter]["class"]!=undefined){var className=responseObj.validators[vCounter]["class"];try{eval("var validator = new "+className+"()")}catch(e){continue}validator.initialize=function(parameters){try{for(var parameter in parameters){this[parameter]=parameters[parameter]}}catch(e){}};validator.initialize(responseObj.validators[vCounter]["parameters"]);errorMessage=validator.execute(element.value);if(errorMessage){elementError=true;break}}}}var alertImg=document.getElementById(element.name+"Error");if(elementError){valid=false;try{element.value=oldElementValue;my_field_error(element,errorMessage)}catch(e){if(alertImg){alertImg.alt=errorMessage;alertImg.title=errorMessage;alertImg.style.display="inline";$(alertImg.id+"SpanError").setStyle({display:"inline"});$(alertImg.id+"SpanError").textContent=errorMessage}}}else{try{element.value=oldElementValue;my_field_error(element,null)}catch(e){if(alertImg){alertImg.style.display="none";$(alertImg.id+"SpanError").setStyle({display:"none"})}}}}}try{validate_shutdown()}catch(e){}return valid}function check_group_validation(form,gElement,group){var elements=form.getElementsByTagName("*");for(var eCounter=0;eCounter<elements.length;eCounter++){var element=elements[eCounter];var alt=element.getAttribute("alt");if((alt!=null)&&(alt!=undefined)&&(alt!="")){try{eval("var responseObj = "+alt)}catch(e){continue}element.value=element.value.trim();if((element.value.length>0)&&(responseObj.group==group)&&(element!=gElement)){return true}}}return false}var sfStringValidator=function(){this.insensitive=false;this.max=null;this.max_error="Input is too long";this.min=null;this.min_error="Input is too short";this.values=null;this.values_error="Invalid selection"};sfStringValidator.prototype.execute=function(A){if((this.min!=null)&&(A.length<this.min)){return this.min_error}if((this.max!=null)&&(A.length>this.max)){return this.max_error}if(this.values!=null){for(i=0;i<this.values.length;i++){if((this.insensitive?(this.values[i].toLowerCase()):(this.values[i]))==(this.insensitive?(A.toLowerCase()):(A))){return false}}return this.values_error}return false};var sfNumberValidator=function(){this.max=null;this.max_error="Input is too large";this.min=null;this.min_error="Input is too small";this.nan_error="Input is not a number";this.type="any";this.type_error="Wrong input"};sfNumberValidator.prototype.execute=function(A){if(isNaN(A)){return this.nan_error}iValue=parseInt(A,10);fValue=parseFloat(A);if((this.type=="int")||(this.type=="integer")){if(fValue!=iValue){return this.type_error}pValue=iValue}else{pValue=fValue}if((this.min!=null)&&(pValue<this.min)){return this.min_error}if((this.max!=null)&&(pValue>this.max)){return this.max_error}return false};var sfRegexValidator=function(){this.match=true;this.match_error="Invalid input";this.pattern=null};sfRegexValidator.prototype.execute=function(value){if(this.pattern!=null){match=Boolean(this.match);pos=0;unescaped="";while(pos<this.pattern.length){c=this.pattern.charAt(pos);if(c=="\\"){pos++}try{unescaped+=this.pattern.charAt(pos)}catch(e){}pos++}try{eval("regExp = "+unescaped);value=String(value);if((value.match(regExp)&&match)||(!value.match(regExp)&&!match)){return false}else{return this.match_error}}catch(e){return false}}else{return false}};var sfEmailValidator=function(){this.email_error="Invalid input"};sfEmailValidator.prototype.execute=function(A){regExp=/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})$/;if(regExp.test(A)){return false}else{return this.email_error}};var sfCompareValidator=function(){this.check=null;this.compare_error="The values you entered do not match. Please try again"};sfCompareValidator.prototype.execute=function(A){if(this.check!=null){check_field=document.getElementById(this.check);if(check_field!=null){check_value=check_field.value;if(check_value!=A){return this.compare_error}}}return false};
