jQuery.fn.extend({yav:function(params,yav_config){var yavC=jQuery.extend({errorsdiv:"yavDiv",debugmode:false,DEFAULT_MSG:"",inputclassnormal:"i",inputhighlight:"h",inputclasserror:"c",trimenabled:true,RULE_SEP:"|",multipleclassname:true},yav_config);var params=jQuery.extend({errorDiv:"errorDiv",errorMessage:"ERROR, please correct",errorClass:"error",errorTag:"p",errorPosition:"before",onError:"",onOk:""},params);for(var name in yavC){window[name]=yavC[name]}var yav_defRules=new Array("alnumhyphen","alnumhyphenat","alphabetic","alphanumeric","alphaspace","date","date_le","date_lt","double","email","empty","equal","integer","keypress","maxlength","minlength","notequal","numeric","numrange","regexp","required");function setRules(o){var rules=new Array();var conds=new Array();var str_rule="";if(jQuery(o).is("form")){jQuery("input, textarea, select",o).each(function(){m=this.className.match(/\{.*\}/);if(m!=null){$(this).attr("alt",m);this.className=this.className.replace(/\{.*\}/,"")}var f_alt={};try{f_alt=eval("("+$(this).attr("alt")+")");f_alt=(typeof f_alt=="undefined")?{}:f_alt}catch(e){}var the_rule=setRules(this);for(var j=0;j<the_rule.length;j++){try{var condition=f_alt.condition;var require_condition=f_alt.require;if(typeof condition!="undefined"){if(typeof condition.name!="undefined"){condition=[condition]}var cond_index="";for(var i=0;i<condition.length;i++){if(typeof conds[condition[i].name]!="undefined"){conds[condition[i].name].indexes.push(((cond_index=="")?cond_index=rules.push(the_rule[j]):cond_index)-1);if(typeof require_condition!="undefined"&&require_condition=="post-condition"){conds[condition[i].name].postcondition=conds[condition[i].name].indexes.length-1}}else{conds[condition[i].name]={id:((typeof condition[i].id=="undefined")?this.id:condition[0].id),type:condition[i].type,msg:condition[i].msg,indexes:[((cond_index=="")?cond_index=rules.push(the_rule[j]):cond_index)-1],require:((typeof condition[i].require=="undefined")?null:condition[i].require),group:((typeof condition[i].group!="undefined")?condition[i].group:null),postcondition:((typeof require_condition!="undefined"&&require_condition=="post-condition")?0:null)}}}}else{rules.push(the_rule[j])}}catch(e){if(the_rule[j]!=null){rules.push(the_rule[j])}}}if(the_rule[0]!=null&&typeof(f_alt.event)!="undefined"){this.yavrules=the_rule;var yavhandler=function(){resetMsgs();var parent_form=$(this).parents("form");if(!performCheck(parent_form[0].id,this.yavrules,'jsVar')){showErrors(parent_form[0])}};var fieldevents=f_alt.event.replace(" ","").split(",");for(var e=0;e<fieldevents.length;e++){$(this).bind(fieldevents[e],yavhandler)}}});var conditional_rule="";for(var name in conds){if(conds.hasOwnProperty(name)&&conds[name].group==null){if(conds[name].postcondition!=null){conds[name].indexes.push(conds[name].indexes[conds[name].postcondition]);conds[name].indexes.splice(conds[name].postcondition,1)}conds[name].indexes=conds[name].indexes.reverse();conditional_rule=conds[name].indexes.pop()+"|"+conds[name].type+"|"+strParams(conds[name].indexes,"-")+"|"+((conds[name].require==null)?"{id:'"+conds[name].id+"',msg:'"+conds[name].msg+"'}":conds[name].require);conds[name].rule_index=rules.push(conditional_rule)-1}}for(var name in conds){if(conds.hasOwnProperty(name)&&conds[name].group!=null){conds[name].group=conds[name].group.reverse();conditional_rule=conds[conds[name].group.pop()].rule_index+"|"+conds[name].type+"|";for(var i=0;i<conds[name].group.length;i++){conds[name].group[i]=conds[conds[name].group[i]].rule_index}conditional_rule+=strParams(conds[name].group,"-")+"|"+((conds[name].require==null)?"{id:'"+conds[name].id+"',msg:'"+conds[name].msg+"'}":conds[name].require);rules.push(conditional_rule)}}return rules}else{var arr_rules=new Array();var num_rules=0;for(var i=0;i<yav_defRules.length;i++){if(jQuery(o).is("."+yav_defRules[i])){try{str_rule=createRule(o,yav_defRules[i],(jQuery(o).attr("title")),((typeof eval("("+jQuery(o).attr("alt")+")").params!="undefined"&&typeof eval("("+jQuery(o).attr("alt")+")").params[0]=="object")?eval("("+jQuery(o).attr("alt")+")").params[num_rules]:eval("("+jQuery(o).attr("alt")+")").params),eval("("+jQuery(o).attr("alt")+")").require)}catch(e){str_rule=createRule(o,yav_defRules[i],(jQuery(o).attr("title")))}arr_rules.push(str_rule);num_rules++}}var rulename;for(rulename in jQuery.yav_customfunctions){if(jQuery(o).is("."+rulename)){try{str_rule=createRule(o,"jQuery.yav_customfunctions."+rulename,(jQuery(o).attr("title")),((typeof eval("("+jQuery(o).attr("alt")+")").params[0]=="object")?eval("("+jQuery(o).attr("alt")+")").params[num_rules]:eval("("+jQuery(o).attr("alt")+")").params),eval("("+jQuery(o).attr("alt")+")").require)}catch(e){str_rule=createRule(o,"jQuery.yav_customfunctions."+rulename,(jQuery(o).attr("title")))}arr_rules.push(str_rule);num_rules++}}}return((arr_rules.length>0)?arr_rules:[null])}function createRule(o,rulename,text,rule_params,require){if(typeof rule_params!="undefined"&&typeof rule_params!="object"){rule_params=[rule_params]}else if(typeof rule_params=="undefined"){rule_params=[]}if(rulename.indexOf("jQuery.yav")>=0){return rulename+"({id:'"+o.id+"',msg:'"+text+"'"+((typeof(require)=="undefined")?"":",require:'"+require+"'")+"}"+((rule_params.length==0)?"":",")+strParams(rule_params,",")+")|custom"}else{return o.id+"|"+rulename+"|"+((rule_params.length>0)?(strParams(rule_params,"-")+"|"):"")+((typeof(require)=="undefined")?"{id:'"+o.id+"',msg:'"+text+"'}":require)}}function strParams(arrParam,separator){var str="";for(var i=0;i<arrParam.length;i++){str+=((separator=="-")?"":"'")+arrParam[i]+((separator=="-")?"":"'")+separator}return str.substr(0,str.length-1)}function showErrors(o){var error_is_shown=new Array();jQuery(params.errorTag+"."+params.errorClass,o).remove();jQuery("#"+params.errorDiv).html("<"+params.errorTag+" class='"+params.errorClass+"'>"+params.errorMessage+"</"+params.errorTag+">");for(var i=0;i<jsErrors.length;i++){objError=(typeof(jsErrors[i])=="object")?jsErrors[i]:eval("("+jsErrors[i]+")");if(typeof error_is_shown[objError.id]=="undefined"&&typeof objError.require=="undefined"){error_is_shown[objError.id]=1;evalText="jQuery('#"+objError.id+"')."+params.errorPosition+"(\""+"<"+params.errorTag+" class='"+params.errorClass+"'>"+objError.msg+"</"+params.errorTag+">"+"\")";eval(evalText);jQuery("#"+objError.id).addClass(inputclasserror)}}if(jQuery("#"+params.errorDiv).size()>0){jQuery("#"+params.errorDiv)[0].scrollIntoView(true)}}function resetMsgs(){jQuery("#"+yavC.errorsdiv).remove();jQuery("#"+params.errorDiv).html("");jQuery(params.errorTag+"."+params.errorClass,this).remove();jQuery("body").append("<div id='"+yavC.errorsdiv+"'></div>");jQuery("."+yavC.inputclasserror).removeClass(yavC.inputclasserror)}jQuery.yav_customfunctions=params.custom;return this.each(function(){setRules(this);jQuery(this).bind("submit",function(){resetMsgs();var formRules=setRules(this);if(formRules.length==0||performCheck(this.id,formRules,'jsVar')){return((typeof params.onOk=="function")?params.onOk(this):true)}else{showErrors(this);return((typeof params.onError=="function")?params.onError(this):false)}})})}});if(typeof(deleteInline)=="function"){jQuery.deleteInline=deleteInline;deleteInline=function(msg){if(typeof(msg)=="string"){return jQuery.deleteInline(msg)}else{return msg}}}else{function highlight(el,clazz){}}
