var LiveValidation=function(_1,_2){
this.initialize(_1,_2);
};
LiveValidation.VERSION="1.3 standalone";
LiveValidation.TEXTAREA=1;
LiveValidation.TEXT=2;
LiveValidation.PASSWORD=3;
LiveValidation.CHECKBOX=4;
LiveValidation.SELECT=5;
LiveValidation.FILE=6;
LiveValidation.massValidate=function(_3){
var _4=0;
var _5=true;
$("jointext").update("Checking...");
for(var i=0,_7=_3.length;i<_7;++i){
var _8=_3[i].validate();
if(_8==false){
_4++;
}
if(_5){
_5=_8;
}
}
if(_4>0){
if(_4==1){
$("jointext").update("There is <strong>"+_4+" error</strong>, please fix the <span class=\"LV_invalid\">red box</span>.");
}else{
$("jointext").update("There are <strong>"+_4+" errors</strong>, please fix the <span class=\"LV_invalid\">red boxes</span>.");
}
Effect.Pulsate("jointext");
}
return _5;
};
LiveValidation.prototype={validClass:"LV_valid",invalidClass:"LV_invalid",messageClass:"LV_validation_message",validFieldClass:"LV_valid_field",invalidFieldClass:"LV_invalid_field",initialize:function(_9,_a){
var _b=this;
if(!_9){
throw new Error("LiveValidation::initialize - No element reference or element id has been provided!");
}
this.element=_9.nodeName?_9:document.getElementById(_9);
if(!this.element){
throw new Error("LiveValidation::initialize - No element with reference or id of '"+_9+"' exists!");
}
this.validations=[];
this.elementType=this.getElementType();
this.form=this.element.form;
var _c=_a||{};
this.validMessage=_c.validMessage||"";
var _d=_c.insertAfterWhatNode||this.element;
this.insertAfterWhatNode=_d.nodeType?_d:document.getElementById(_d);
this.onValid=_c.onValid||function(){
this.insertMessage(this.createMessageSpan());
this.addFieldClass();
};
this.onInvalid=_c.onInvalid||function(){
this.insertMessage(this.createMessageSpan());
this.addFieldClass();
};
this.onlyOnBlur=_c.onlyOnBlur||false;
this.wait=_c.wait||0;
this.onlyOnSubmit=_c.onlyOnSubmit||false;
if(this.form){
this.formObj=LiveValidationForm.getInstance(this.form);
this.formObj.addField(this);
}
this.oldOnFocus=this.element.onfocus||function(){
};
this.oldOnBlur=this.element.onblur||function(){
};
this.oldOnClick=this.element.onclick||function(){
};
this.oldOnChange=this.element.onchange||function(){
};
this.oldOnKeyup=this.element.onkeyup||function(){
};
this.element.onfocus=function(e){
_b.doOnFocus(e);
return _b.oldOnFocus.call(this,e);
};
if(!this.onlyOnSubmit){
switch(this.elementType){
case LiveValidation.CHECKBOX:
this.element.onclick=function(e){
_b.validate();
return _b.oldOnClick.call(this,e);
};
case LiveValidation.SELECT:
case LiveValidation.FILE:
this.element.onchange=function(e){
_b.validate();
return _b.oldOnChange.call(this,e);
};
break;
default:
if(!this.onlyOnBlur){
this.element.onkeyup=function(e){
_b.deferValidation();
return _b.oldOnKeyup.call(this,e);
};
}
this.element.onblur=function(e){
_b.doOnBlur(e);
return _b.oldOnBlur.call(this,e);
};
}
}
},destroy:function(){
if(this.formObj){
this.formObj.removeField(this);
this.formObj.destroy();
}
this.element.onfocus=this.oldOnFocus;
if(!this.onlyOnSubmit){
switch(this.elementType){
case LiveValidation.CHECKBOX:
this.element.onclick=this.oldOnClick;
case LiveValidation.SELECT:
case LiveValidation.FILE:
this.element.onchange=this.oldOnChange;
break;
default:
if(!this.onlyOnBlur){
this.element.onkeyup=this.oldOnKeyup;
}
this.element.onblur=this.oldOnBlur;
}
}
this.validations=[];
this.removeMessageAndFieldClass();
},add:function(_13,_14){
this.validations.push({type:_13,params:_14||{}});
return this;
},remove:function(_15,_16){
var _17=false;
for(var i=0,len=this.validations.length;i<len;i++){
if(this.validations[i].type==_15){
if(this.validations[i].params==_16){
_17=true;
break;
}
}
}
if(_17){
this.validations.splice(i,1);
}
return this;
},deferValidation:function(e){
if(this.wait>=300){
this.removeMessageAndFieldClass();
}
var _1b=this;
if(this.timeout){
clearTimeout(_1b.timeout);
}
this.timeout=setTimeout(function(){
_1b.validate();
},_1b.wait);
},doOnBlur:function(e){
this.focused=false;
this.validate(e);
},doOnFocus:function(e){
this.focused=true;
this.removeMessageAndFieldClass();
},getElementType:function(){
switch(true){
case (this.element.nodeName.toUpperCase()=="TEXTAREA"):
return LiveValidation.TEXTAREA;
case (this.element.nodeName.toUpperCase()=="INPUT"&&this.element.type.toUpperCase()=="TEXT"):
return LiveValidation.TEXT;
case (this.element.nodeName.toUpperCase()=="INPUT"&&this.element.type.toUpperCase()=="PASSWORD"):
return LiveValidation.PASSWORD;
case (this.element.nodeName.toUpperCase()=="INPUT"&&this.element.type.toUpperCase()=="CHECKBOX"):
return LiveValidation.CHECKBOX;
case (this.element.nodeName.toUpperCase()=="INPUT"&&this.element.type.toUpperCase()=="FILE"):
return LiveValidation.FILE;
case (this.element.nodeName.toUpperCase()=="SELECT"):
return LiveValidation.SELECT;
case (this.element.nodeName.toUpperCase()=="INPUT"):
throw new Error("LiveValidation::getElementType - Cannot use LiveValidation on an "+this.element.type+" input!");
default:
throw new Error("LiveValidation::getElementType - Element must be an input, select, or textarea!");
}
},doValidations:function(){
this.validationFailed=false;
for(var i=0,len=this.validations.length;i<len;++i){
var _20=this.validations[i];
switch(_20.type){
case Validate.Presence:
case Validate.Confirmation:
case Validate.Acceptance:
this.displayMessageWhenEmpty=true;
this.validationFailed=!this.validateElement(_20.type,_20.params);
break;
default:
this.validationFailed=!this.validateElement(_20.type,_20.params);
break;
}
if(this.validationFailed){
return false;
}
}
this.message=this.validMessage;
return true;
},validateElement:function(_21,_22){
var _23=(this.elementType==LiveValidation.SELECT)?this.element.options[this.element.selectedIndex].value:this.element.value;
if(_21==Validate.Acceptance){
if(this.elementType!=LiveValidation.CHECKBOX){
throw new Error("LiveValidation::validateElement - Element to validate acceptance must be a checkbox!");
}
_23=this.element.checked;
}
var _24=true;
try{
_21(_23,_22);
}
catch(error){
if(error instanceof Validate.Error){
if(_23!==""||(_23===""&&this.displayMessageWhenEmpty)){
this.validationFailed=true;
this.message=error.message;
_24=false;
}
}else{
throw error;
}
}
finally{
return _24;
}
},validate:function(){
if(!this.element.disabled){
var _25=this.doValidations();
if(_25){
this.onValid();
return true;
}else{
this.onInvalid();
return false;
}
}else{
return true;
}
},enable:function(){
this.element.disabled=false;
return this;
},disable:function(){
this.element.disabled=true;
this.removeMessageAndFieldClass();
return this;
},createMessageSpan:function(){
var _26=document.createElement("span");
var _27=document.createTextNode(this.message);
_26.appendChild(_27);
return _26;
},insertMessage:function(_28){
this.removeMessage();
if((this.displayMessageWhenEmpty&&(this.elementType==LiveValidation.CHECKBOX||this.element.value==""))||this.element.value!=""){
var _29=this.validationFailed?this.invalidClass:this.validClass;
_28.className+=" "+this.messageClass+" "+_29;
if(this.insertAfterWhatNode.nextSibling){
this.insertAfterWhatNode.parentNode.insertBefore(_28,this.insertAfterWhatNode.nextSibling);
}else{
this.insertAfterWhatNode.parentNode.appendChild(_28);
}
}
},addFieldClass:function(){
this.removeFieldClass();
if(!this.validationFailed){
if(this.displayMessageWhenEmpty||this.element.value!=""){
if(this.element.className.indexOf(this.validFieldClass)==-1){
this.element.className+=" "+this.validFieldClass;
}
}
}else{
if(this.element.className.indexOf(this.invalidFieldClass)==-1){
this.element.className+=" "+this.invalidFieldClass;
}
}
},removeMessage:function(){
var _2a;
var el=this.insertAfterWhatNode;
while(el.nextSibling){
if(el.nextSibling.nodeType===1){
_2a=el.nextSibling;
break;
}
el=el.nextSibling;
}
if(_2a&&_2a.className.indexOf(this.messageClass)!=-1){
this.insertAfterWhatNode.parentNode.removeChild(_2a);
}
},removeFieldClass:function(){
if(this.element.className.indexOf(this.invalidFieldClass)!=-1){
this.element.className=this.element.className.split(this.invalidFieldClass).join("");
}
if(this.element.className.indexOf(this.validFieldClass)!=-1){
this.element.className=this.element.className.split(this.validFieldClass).join(" ");
}
},removeMessageAndFieldClass:function(){
this.removeMessage();
this.removeFieldClass();
}};
var LiveValidationForm=function(_2c){
this.initialize(_2c);
};
LiveValidationForm.instances={};
LiveValidationForm.getInstance=function(_2d){
var _2e=Math.random()*Math.random();
if(!_2d.id){
_2d.id="formId_"+_2e.toString().replace(/\./,"")+new Date().valueOf();
}
if(!LiveValidationForm.instances[_2d.id]){
LiveValidationForm.instances[_2d.id]=new LiveValidationForm(_2d);
}
return LiveValidationForm.instances[_2d.id];
};
LiveValidationForm.prototype={initialize:function(_2f){
this.name=_2f.id;
this.element=_2f;
this.fields=[];
this.oldOnSubmit=this.element.onsubmit||function(){
};
var _30=this;
this.element.onsubmit=function(e){
return (LiveValidation.massValidate(_30.fields))?_30.oldOnSubmit.call(this,e||window.event)!==false:false;
};
},addField:function(_32){
this.fields.push(_32);
},removeField:function(_33){
var _34=[];
for(var i=0,len=this.fields.length;i<len;i++){
if(this.fields[i]!==_33){
_34.push(this.fields[i]);
}
}
this.fields=_34;
},destroy:function(_37){
if(this.fields.length!=0&&!_37){
return false;
}
this.element.onsubmit=this.oldOnSubmit;
LiveValidationForm.instances[this.name]=null;
return true;
}};
var Validate={Presence:function(_38,_39){
var _39=_39||{};
var _3a=_39.failureMessage||"Can't be empty!";
if(_38===""||_38===null||_38===undefined){
Validate.fail(_3a);
}
return true;
},Numericality:function(_3b,_3c){
var _3d=_3b;
var _3b=Number(_3b);
var _3c=_3c||{};
var _3e=((_3c.minimum)||(_3c.minimum==0))?_3c.minimum:null;
var _3f=((_3c.maximum)||(_3c.maximum==0))?_3c.maximum:null;
var is=((_3c.is)||(_3c.is==0))?_3c.is:null;
var _41=_3c.notANumberMessage||"Must be a number!";
var _42=_3c.notAnIntegerMessage||"Must be an integer!";
var _43=_3c.wrongNumberMessage||"Must be "+is+"!";
var _44=_3c.tooLowMessage||"Must not be less than "+_3e+"!";
var _45=_3c.tooHighMessage||"Must not be more than "+_3f+"!";
if(!isFinite(_3b)){
Validate.fail(_41);
}
if(_3c.onlyInteger&&(/\.0+$|\.$/.test(String(_3d))||_3b!=parseInt(_3b))){
Validate.fail(_42);
}
switch(true){
case (is!==null):
if(_3b!=Number(is)){
Validate.fail(_43);
}
break;
case (_3e!==null&&_3f!==null):
Validate.Numericality(_3b,{tooLowMessage:_44,minimum:_3e});
Validate.Numericality(_3b,{tooHighMessage:_45,maximum:_3f});
break;
case (_3e!==null):
if(_3b<Number(_3e)){
Validate.fail(_44);
}
break;
case (_3f!==null):
if(_3b>Number(_3f)){
Validate.fail(_45);
}
break;
}
return true;
},Format:function(_46,_47){
var _46=String(_46);
var _47=_47||{};
var _48=_47.failureMessage||"Not valid!";
var _49=_47.pattern||/./;
var _4a=_47.negate||false;
if(!_4a&&!_49.test(_46)){
Validate.fail(_48);
}
if(_4a&&_49.test(_46)){
Validate.fail(_48);
}
return true;
},Email:function(_4b,_4c){
var _4c=_4c||{};
var _4d=_4c.failureMessage||"Must be a valid email address!";
Validate.Format(_4b,{failureMessage:_4d,pattern:/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i});
return true;
},Length:function(_4e,_4f){
var _4e=String(_4e);
var _4f=_4f||{};
var _50=((_4f.minimum)||(_4f.minimum==0))?_4f.minimum:null;
var _51=((_4f.maximum)||(_4f.maximum==0))?_4f.maximum:null;
var is=((_4f.is)||(_4f.is==0))?_4f.is:null;
var _53=_4f.wrongLengthMessage||"Must be "+is+" characters long!";
var _54=_4f.tooShortMessage||"Must not be less than "+_50+" characters long!";
var _55=_4f.tooLongMessage||"Must not be more than "+_51+" characters long!";
switch(true){
case (is!==null):
if(_4e.length!=Number(is)){
Validate.fail(_53);
}
break;
case (_50!==null&&_51!==null):
Validate.Length(_4e,{tooShortMessage:_54,minimum:_50});
Validate.Length(_4e,{tooLongMessage:_55,maximum:_51});
break;
case (_50!==null):
if(_4e.length<Number(_50)){
Validate.fail(_54);
}
break;
case (_51!==null):
if(_4e.length>Number(_51)){
Validate.fail(_55);
}
break;
default:
throw new Error("Validate::Length - Length(s) to validate against must be provided!");
}
return true;
},Inclusion:function(_56,_57){
var _57=_57||{};
var _58=_57.failureMessage||"";
var _59=(_57.caseSensitive===false)?false:true;
if(_57.allowNull&&_56==null){
return true;
}
if(!_57.allowNull&&_56==null){
Validate.fail(_58);
}
var _5a=_57.within||[];
if(!_59){
var _5b=[];
for(var j=0,_5d=_5a.length;j<_5d;++j){
var _5e=_5a[j];
if(typeof _5e=="string"){
_5e=_5e.toLowerCase();
}
_5b.push(_5e);
}
_5a=_5b;
if(typeof _56=="string"){
_56=_56.toLowerCase();
}
}
var _5f=false;
for(var i=0,_5d=_5a.length;i<_5d;++i){
if(_5a[i]==_56){
_5f=true;
}
if(_57.partialMatch){
if(_56.indexOf(_5a[i])!=-1){
_5f=true;
}
}
}
if((!_57.negate&&!_5f)||(_57.negate&&_5f)){
Validate.fail(_58);
}
return true;
},Exclusion:function(_61,_62){
var _62=_62||{};
_62.failureMessage=_62.failureMessage||"";
_62.negate=true;
Validate.Inclusion(_61,_62);
return true;
},Confirmation:function(_63,_64){
if(!_64.match){
throw new Error("Validate::Confirmation - Error validating confirmation: Id of element to match must be provided!");
}
var _64=_64||{};
var _65=_64.failureMessage||"Does not match!";
var _66=_64.match.nodeName?_64.match:document.getElementById(_64.match);
if(!_66){
throw new Error("Validate::Confirmation - There is no reference with name of, or element with id of '"+_64.match+"'!");
}
if(_63!=_66.value){
Validate.fail(_65);
}
return true;
},Acceptance:function(_67,_68){
var _68=_68||{};
var _69=_68.failureMessage||"Must be accepted!";
if(!_67){
Validate.fail(_69);
}
return true;
},Custom:function(_6a,_6b){
var _6b=_6b||{};
var _6c=_6b.against||function(){
return true;
};
var _6d=_6b.args||{};
var _6e=_6b.failureMessage||"Not valid!";
if(!_6c(_6a,_6d)){
Validate.fail(_6e);
}
return true;
},now:function(_6f,_70,_71){
if(!_6f){
throw new Error("Validate::now - Validation function must be provided!");
}
var _72=true;
try{
_6f(_70,_71||{});
}
catch(error){
if(error instanceof Validate.Error){
_72=false;
}else{
throw error;
}
}
finally{
return _72;
}
},fail:function(_73){
throw new Validate.Error(_73);
},Error:function(_74){
this.message=_74;
this.name="ValidationError";
}};