(function($){$.extend($.fn,{validate:function(options){if(!this.length){options&&options.debug&&window.console&&console.warn("nothing selected, can't validate, returning nothing");return;}var validator=$.data(this[0],"validator");if(validator){return validator;}validator=new $.validator(options,this[0]);$.data(this[0],"validator",validator);if(validator.settings.onsubmit){this.find("input, button").filter(".cancel").click(function(){validator.cancelSubmit=true;});if(validator.settings.submitHandler){this.find("input, button").filter(":submit").click(function(){validator.submitButton=this;});}this.submit(function(event){if(validator.settings.debug){event.preventDefault();}function handle(){if(validator.settings.submitHandler){if(validator.submitButton){var hidden=$("<input type='hidden'/>").attr("name",validator.submitButton.name).val(validator.submitButton.value).appendTo(validator.currentForm);}validator.settings.submitHandler.call(validator,validator.currentForm);if(validator.submitButton){hidden.remove();}return false;}return true;}if(validator.cancelSubmit){validator.cancelSubmit=false;return handle();}if(validator.form()){if(validator.pendingRequest){validator.formSubmitted=true;return false;}return handle();}else{validator.focusInvalid();return false;}});}return validator;},valid:function(){if($(this[0]).is("form")){return this.validate().form();}else{var valid=true;var validator=$(this[0].form).validate();this.each(function(){valid&=validator.element(this);});return valid;}},removeAttrs:function(attributes){var result={},$element=this;$.each(attributes.split(/\s/),function(index,value){result[value]=$element.attr(value);$element.removeAttr(value);});return result;},rules:function(command,argument){var element=this[0];if(command){var settings=$.data(element.form,"validator").settings;var staticRules=settings.rules;var existingRules=$.validator.staticRules(element);switch(command){case"add":$.extend(existingRules,$.validator.normalizeRule(argument));staticRules[element.name]=existingRules;if(argument.messages){settings.messages[element.name]=$.extend(settings.messages[element.name],argument.messages);}break;case"remove":if(!argument){delete staticRules[element.name];return existingRules;}var filtered={};$.each(argument.split(/\s/),function(index,method){filtered[method]=existingRules[method];delete existingRules[method];});return filtered;}}var data=$.validator.normalizeRules($.extend({},$.validator.metadataRules(element),$.validator.classRules(element),$.validator.attributeRules(element),$.validator.staticRules(element)),element);if(data.required){var param=data.required;delete data.required;data=$.extend({required:param},data);}return data;}});$.extend($.expr[":"],{blank:function(a){return !$.trim(a.value);},filled:function(a){return !!$.trim(a.value);},unchecked:function(a){return !a.checked;}});$.validator=function(options,form){this.settings=$.extend({},$.validator.defaults,options);this.currentForm=form;this.init();};$.validator.format=function(source,params){if(arguments.length==1){return function(){var args=$.makeArray(arguments);args.unshift(source);return $.validator.format.apply(this,args);};}if(arguments.length>2&&params.constructor!=Array){params=$.makeArray(arguments).slice(1);}if(params.constructor!=Array){params=[params];}$.each(params,function(i,n){source=source.replace(new RegExp("\\{"+i+"\\}","g"),n);});return source;};$.extend($.validator,{defaults:{messages:{},groups:{},rules:{},errorClass:"error",validClass:"valid",errorElement:"label",focusInvalid:true,errorContainer:$([]),errorLabelContainer:$([]),onsubmit:true,ignore:[],ignoreTitle:false,onfocusin:function(element){this.lastActive=element;if(this.settings.focusCleanup&&!this.blockFocusCleanup){this.settings.unhighlight&&this.settings.unhighlight.call(this,element,this.settings.errorClass,this.settings.validClass);this.errorsFor(element).hide();}},onfocusout:function(element){if(!this.checkable(element)&&(element.name in this.submitted||!this.optional(element))){this.element(element);}},onkeyup:function(element){if(element.name in this.submitted||element==this.lastElement){this.element(element);}},onclick:function(element){if(element.name in this.submitted){this.element(element);}},highlight:function(element,errorClass,validClass){$(element).addClass(errorClass).removeClass(validClass);},unhighlight:function(element,errorClass,validClass){$(element).removeClass(errorClass).addClass(validClass);}},setDefaults:function(settings){$.extend($.validator.defaults,settings);},messages:{required:"This field is required.",remote:"Please fix this field.",email:"Please enter a valid email address.",url:"Please enter a valid URL.",date:"Please enter a valid date.",dateISO:"Please enter a valid date (ISO).",dateDE:"Bitte geben Sie ein g????ltiges Datum ein.",number:"Please enter a valid number.",numberDE:"Bitte geben Sie eine Nummer ein.",digits:"Please enter only digits",creditcard:"Please enter a valid credit card number.",equalTo:"Please enter the same value again.",accept:"Please enter a value with a valid extension.",maxlength:$.validator.format("Please enter no more than {0} characters."),minlength:$.validator.format("Please enter at least {0} characters."),rangelength:$.validator.format("Please enter a value between {0} and {1} characters long."),range:$.validator.format("Please enter a value between {0} and {1}."),max:$.validator.format("Please enter a value less than or equal to {0}."),min:$.validator.format("Please enter a value greater than or equal to {0}.")},autoCreateRanges:false,prototype:{init:function(){this.labelContainer=$(this.settings.errorLabelContainer);this.errorContext=this.labelContainer.length&&this.labelContainer||$(this.currentForm);this.containers=$(this.settings.errorContainer).add(this.settings.errorLabelContainer);this.submitted={};this.valueCache={};this.pendingRequest=0;this.pending={};this.invalid={};this.reset();var groups=(this.groups={});$.each(this.settings.groups,function(key,value){$.each(value.split(/\s/),function(index,name){groups[name]=key;});});var rules=this.settings.rules;$.each(rules,function(key,value){rules[key]=$.validator.normalizeRule(value);});function delegate(event){var validator=$.data(this[0].form,"validator");validator.settings["on"+event.type]&&validator.settings["on"+event.type].call(validator,this[0]);}$(this.currentForm).delegate("focusin focusout keyup",":text, :password, :file, select, textarea",delegate).delegate("click",":radio, :checkbox",delegate);if(this.settings.invalidHandler){$(this.currentForm).bind("invalid-form.validate",this.settings.invalidHandler);}},form:function(){this.checkForm();$.extend(this.submitted,this.errorMap);this.invalid=$.extend({},this.errorMap);if(!this.valid()){$(this.currentForm).triggerHandler("invalid-form",[this]);}this.showErrors();return this.valid();},checkForm:function(){this.prepareForm();for(var i=0,elements=(this.currentElements=this.elements());elements[i];i++){this.check(elements[i]);}return this.valid();},element:function(element){element=this.clean(element);this.lastElement=element;this.prepareElement(element);this.currentElements=$(element);var result=this.check(element);if(result){delete this.invalid[element.name];}else{this.invalid[element.name]=true;}if(!this.numberOfInvalids()){this.toHide=this.toHide.add(this.containers);}this.showErrors();return result;},showErrors:function(errors){if(errors){$.extend(this.errorMap,errors);this.errorList=[];for(var name in errors){this.errorList.push({message:errors[name],element:this.findByName(name)[0]});}this.successList=$.grep(this.successList,function(element){return !(element.name in errors);});}this.settings.showErrors?this.settings.showErrors.call(this,this.errorMap,this.errorList):this.defaultShowErrors();},resetForm:function(){if($.fn.resetForm){$(this.currentForm).resetForm();}this.submitted={};this.prepareForm();this.hideErrors();this.elements().removeClass(this.settings.errorClass);},numberOfInvalids:function(){return this.objectLength(this.invalid);},objectLength:function(obj){var count=0;for(var i in obj){count++;}return count;},hideErrors:function(){this.addWrapper(this.toHide).hide();},valid:function(){return this.size()==0;},size:function(){return this.errorList.length;},focusInvalid:function(){if(this.settings.focusInvalid){try{$(this.findLastActive()||this.errorList.length&&this.errorList[0].element||[]).filter(":visible").focus();}catch(e){}}},findLastActive:function(){var lastActive=this.lastActive;return lastActive&&$.grep(this.errorList,function(n){return n.element.name==lastActive.name;}).length==1&&lastActive;},elements:function(){var validator=this,rulesCache={};return $([]).add(this.currentForm.elements).filter(":input").not(":submit, :reset, :image, [disabled]").not(this.settings.ignore).filter(function(){!this.name&&validator.settings.debug&&window.console&&console.error("%o has no name assigned",this);if(this.name in rulesCache||!validator.objectLength($(this).rules())){return false;}rulesCache[this.name]=true;return true;});},clean:function(selector){return $(selector)[0];},errors:function(){return $(this.settings.errorElement+"."+this.settings.errorClass,this.errorContext);},reset:function(){this.successList=[];this.errorList=[];this.errorMap={};this.toShow=$([]);this.toHide=$([]);this.formSubmitted=false;this.currentElements=$([]);},prepareForm:function(){this.reset();this.toHide=this.errors().add(this.containers);},prepareElement:function(element){this.reset();this.toHide=this.errorsFor(element);},check:function(element){element=this.clean(element);if(this.checkable(element)){element=this.findByName(element.name)[0];}var rules=$(element).rules();var dependencyMismatch=false;for(method in rules){var rule={method:method,parameters:rules[method]};try{var result=$.validator.methods[method].call(this,element.value.replace(/\r/g,""),element,rule.parameters);if(result=="dependency-mismatch"){dependencyMismatch=true;continue;}dependencyMismatch=false;if(result=="pending"){this.toHide=this.toHide.not(this.errorsFor(element));return;}if(!result){this.formatAndAdd(element,rule);return false;}}catch(e){this.settings.debug&&window.console&&console.log("exception occured when checking element "+element.id+", check the '"+rule.method+"' method");throw e;}}if(dependencyMismatch){return;}if(this.objectLength(rules)){this.successList.push(element);}return true;},customMetaMessage:function(element,method){if(!$.metadata){return;}var meta=this.settings.meta?$(element).metadata()[this.settings.meta]:$(element).metadata();return meta&&meta.messages&&meta.messages[method];},customMessage:function(name,method){var m=this.settings.messages[name];return m&&(m.constructor==String?m:m[method]);},findDefined:function(){for(var i=0;i<arguments.length;i++){if(arguments[i]!==undefined){return arguments[i];}}return undefined;},defaultMessage:function(element,method){return this.findDefined(this.customMessage(element.name,method),this.customMetaMessage(element,method),!this.settings.ignoreTitle&&element.title||undefined,$.validator.messages[method],"<strong>Warning: No message defined for "+element.name+"</strong>");},formatAndAdd:function(element,rule){var message=this.defaultMessage(element,rule.method);if(typeof message=="function"){message=message.call(this,rule.parameters,element);}this.errorList.push({message:message,element:element});this.errorMap[element.name]=message;this.submitted[element.name]=message;},addWrapper:function(toToggle){if(this.settings.wrapper){toToggle=toToggle.add(toToggle.parent(this.settings.wrapper));}return toToggle;},defaultShowErrors:function(){for(var i=0;this.errorList[i];i++){var error=this.errorList[i];this.settings.highlight&&this.settings.highlight.call(this,error.element,this.settings.errorClass,this.settings.validClass);this.showLabel(error.element,error.message);}if(this.errorList.length){this.toShow=this.toShow.add(this.containers);}if(this.settings.success){for(var i=0;this.successList[i];i++){this.showLabel(this.successList[i]);}}if(this.settings.unhighlight){for(var i=0,elements=this.validElements();elements[i];i++){this.settings.unhighlight.call(this,elements[i],this.settings.errorClass,this.settings.validClass);}}this.toHide=this.toHide.not(this.toShow);this.hideErrors();this.addWrapper(this.toShow).show();},validElements:function(){return this.currentElements.not(this.invalidElements());},invalidElements:function(){return $(this.errorList).map(function(){return this.element;});},showLabel:function(element,message){var label=this.errorsFor(element);if(label.length){label.removeClass().addClass(this.settings.errorClass);label.attr("generated")&&label.html(message);}else{label=$("<"+this.settings.errorElement+"/>").attr({"for":this.idOrName(element),generated:true}).addClass(this.settings.errorClass).html(message||"");if(this.settings.wrapper){label=label.hide().show().wrap("<"+this.settings.wrapper+"/>").parent();}if(!this.labelContainer.append(label).length){this.settings.errorPlacement?this.settings.errorPlacement(label,$(element)):label.insertAfter(element);}}if(!message&&this.settings.success){label.text("");typeof this.settings.success=="string"?label.addClass(this.settings.success):this.settings.success(label);}this.toShow=this.toShow.add(label);},errorsFor:function(element){return this.errors().filter("[for='"+this.idOrName(element)+"']");},idOrName:function(element){return this.groups[element.name]||(this.checkable(element)?element.name:element.id||element.name);},checkable:function(element){return/radio|checkbox/i.test(element.type);},findByName:function(name){var form=this.currentForm;return $(document.getElementsByName(name)).map(function(index,element){return element.form==form&&element.name==name&&element||null;});},getLength:function(value,element){switch(element.nodeName.toLowerCase()){case"select":return $("option:selected",element).length;case"input":if(this.checkable(element)){return this.findByName(element.name).filter(":checked").length;}}return value.length;},depend:function(param,element){return this.dependTypes[typeof param]?this.dependTypes[typeof param](param,element):true;},dependTypes:{"boolean":function(param,element){return param;},string:function(param,element){return !!$(param,element.form).length;},"function":function(param,element){return param(element);}},optional:function(element){return !$.validator.methods.required.call(this,$.trim(element.value),element)&&"dependency-mismatch";},startRequest:function(element){if(!this.pending[element.name]){this.pendingRequest++;this.pending[element.name]=true;}},stopRequest:function(element,valid){this.pendingRequest--;if(this.pendingRequest<0){this.pendingRequest=0;}delete this.pending[element.name];if(valid&&this.pendingRequest==0&&this.formSubmitted&&this.form()){$(this.currentForm).submit();}else{if(!valid&&this.pendingRequest==0&&this.formSubmitted){$(this.currentForm).triggerHandler("invalid-form",[this]);}}},previousValue:function(element){return $.data(element,"previousValue")||$.data(element,"previousValue",previous={old:null,valid:true,message:this.defaultMessage(element,"remote")});}},classRuleSettings:{required:{required:true},email:{email:true},url:{url:true},date:{date:true},dateISO:{dateISO:true},dateDE:{dateDE:true},number:{number:true},numberDE:{numberDE:true},digits:{digits:true},creditcard:{creditcard:true}},addClassRules:function(className,rules){className.constructor==String?this.classRuleSettings[className]=rules:$.extend(this.classRuleSettings,className);},classRules:function(element){var rules={};var classes=$(element).attr("class");classes&&$.each(classes.split(" "),function(){if(this in $.validator.classRuleSettings){$.extend(rules,$.validator.classRuleSettings[this]);}});return rules;},attributeRules:function(element){var rules={};var $element=$(element);for(method in $.validator.methods){var value=$element.attr(method);if(value){rules[method]=value;}}if(rules.maxlength&&/-1|2147483647|524288/.test(rules.maxlength)){delete rules.maxlength;}return rules;},metadataRules:function(element){if(!$.metadata){return{};}var meta=$.data(element.form,"validator").settings.meta;return meta?$(element).metadata()[meta]:$(element).metadata();},staticRules:function(element){var rules={};var validator=$.data(element.form,"validator");if(validator.settings.rules){rules=$.validator.normalizeRule(validator.settings.rules[element.name])||{};}return rules;},normalizeRules:function(rules,element){$.each(rules,function(prop,val){if(val===false){delete rules[prop];return;}if(val.param||val.depends){var keepRule=true;switch(typeof val.depends){case"string":keepRule=!!$(val.depends,element.form).length;break;case"function":keepRule=val.depends.call(element,element);break;}if(keepRule){rules[prop]=val.param!==undefined?val.param:true;}else{delete rules[prop];}}});$.each(rules,function(rule,parameter){rules[rule]=$.isFunction(parameter)?parameter(element):parameter;});$.each(["minlength","maxlength","min","max"],function(){if(rules[this]){rules[this]=Number(rules[this]);}});$.each(["rangelength","range"],function(){if(rules[this]){rules[this]=[Number(rules[this][0]),Number(rules[this][1])];}});if($.validator.autoCreateRanges){if(rules.min&&rules.max){rules.range=[rules.min,rules.max];delete rules.min;delete rules.max;}if(rules.minlength&&rules.maxlength){rules.rangelength=[rules.minlength,rules.maxlength];delete rules.minlength;delete rules.maxlength;}}if(rules.messages){delete rules.messages;}return rules;},normalizeRule:function(data){if(typeof data=="string"){var transformed={};$.each(data.split(/\s/),function(){transformed[this]=true;});data=transformed;}return data;},addMethod:function(name,method,message){$.validator.methods[name]=method;$.validator.messages[name]=message||$.validator.messages[name];if(method.length<3){$.validator.addClassRules(name,$.validator.normalizeRule(name));}},methods:{required:function(value,element,param){if(!this.depend(param,element)){return"dependency-mismatch";}switch(element.nodeName.toLowerCase()){case"select":var options=$("option:selected",element);return options.length>0&&(element.type=="select-multiple"||($.browser.msie&&!(options[0].attributes.value.specified)?options[0].text:options[0].value).length>0);case"input":if(this.checkable(element)){return this.getLength(value,element)>0;}default:return $.trim(value).length>0;}},remote:function(value,element,param){if(this.optional(element)){return"dependency-mismatch";}var previous=this.previousValue(element);if(!this.settings.messages[element.name]){this.settings.messages[element.name]={};}this.settings.messages[element.name].remote=typeof previous.message=="function"?previous.message(value):previous.message;param=typeof param=="string"&&{url:param}||param;if(previous.old!==value){previous.old=value;var validator=this;this.startRequest(element);var data={};data[element.name]=value;$.ajax($.extend(true,{url:param,mode:"abort",port:"validate"+element.name,dataType:"json",data:data,success:function(response){var valid=response===true;if(valid){var submitted=validator.formSubmitted;validator.prepareElement(element);validator.formSubmitted=submitted;validator.successList.push(element);validator.showErrors();}else{var errors={};errors[element.name]=previous.message=response||validator.defaultMessage(element,"remote");validator.showErrors(errors);}previous.valid=valid;validator.stopRequest(element,valid);}},param));return"pending";}else{if(this.pending[element.name]){return"pending";}}return previous.valid;},minlength:function(value,element,param){return this.optional(element)||this.getLength($.trim(value),element)>=param;},maxlength:function(value,element,param){return this.optional(element)||this.getLength($.trim(value),element)<=param;},rangelength:function(value,element,param){var length=this.getLength($.trim(value),element);return this.optional(element)||(length>=param[0]&&length<=param[1]);},min:function(value,element,param){return this.optional(element)||value>=param;},max:function(value,element,param){return this.optional(element)||value<=param;},range:function(value,element,param){return this.optional(element)||(value>=param[0]&&value<=param[1]);},email:function(value,element){return this.optional(element)||/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i.test(value);},url:function(value,element){return this.optional(element)||/^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i.test(value);},date:function(value,element){return this.optional(element)||!/Invalid|NaN/.test(new Date(value));},dateISO:function(value,element){return this.optional(element)||/^\d{4}[\/-]\d{1,2}[\/-]\d{1,2}$/.test(value);},dateDE:function(value,element){return this.optional(element)||/^\d\d?\.\d\d?\.\d\d\d?\d?$/.test(value);},number:function(value,element){return this.optional(element)||/^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)?$/.test(value);},numberDE:function(value,element){return this.optional(element)||/^-?(?:\d+|\d{1,3}(?:\.\d{3})+)(?:,\d+)?$/.test(value);},digits:function(value,element){return this.optional(element)||/^\d+$/.test(value);},creditcard:function(value,element){if(this.optional(element)){return"dependency-mismatch";}if(/[^0-9-]+/.test(value)){return false;}var nCheck=0,nDigit=0,bEven=false;value=value.replace(/\D/g,"");for(n=value.length-1;n>=0;n--){var cDigit=value.charAt(n);var nDigit=parseInt(cDigit,10);if(bEven){if((nDigit*=2)>9){nDigit-=9;}}nCheck+=nDigit;bEven=!bEven;}return(nCheck%10)==0;},accept:function(value,element,param){param=typeof param=="string"?param.replace(/,/g,"|"):"png|jpe?g|gif";return this.optional(element)||value.match(new RegExp(".("+param+")$","i"));},equalTo:function(value,element,param){return value==$(param).val();}}});$.format=$.validator.format;})(jQuery);(function($){var ajax=$.ajax;var pendingRequests={};$.ajax=function(settings){settings=$.extend(settings,$.extend({},$.ajaxSettings,settings));var port=settings.port;if(settings.mode=="abort"){if(pendingRequests[port]){pendingRequests[port].abort();}return(pendingRequests[port]=ajax.apply(this,arguments));}return ajax.apply(this,arguments);};})(jQuery);(function($){$.each({focus:"focusin",blur:"focusout"},function(original,fix){$.event.special[fix]={setup:function(){if($.browser.msie){return false;}this.addEventListener(original,$.event.special[fix].handler,true);},teardown:function(){if($.browser.msie){return false;}this.removeEventListener(original,$.event.special[fix].handler,true);},handler:function(e){arguments[0]=$.event.fix(e);arguments[0].type=fix;return $.event.handle.apply(this,arguments);}};});$.extend($.fn,{delegate:function(type,delegate,handler){return this.bind(type,function(event){var target=$(event.target);if(target.is(delegate)){return handler.apply(target,arguments);}});},triggerEvent:function(type,target){return this.triggerHandler(type,[$.event.fix({type:type,target:target})]);}});})(jQuery);jQuery.fn.labelify=function(settings){settings=jQuery.extend({text:"title",labelledClass:""},settings);var lookups={title:function(input){return $(input).attr("title");},label:function(input){return $("label[for="+input.id+"]").text();}};var lookup;var jQuery_labellified_elements=$(this);return $(this).each(function(){if(typeof settings.text==="string"){lookup=lookups[settings.text];}else{lookup=settings.text;}if(typeof lookup!=="function"){return;}var lookupval=lookup(this);if(!lookupval){return;}$(this).data("label",lookup(this).replace(/\n/g,""));$(this).focus(function(){if(this.value===$(this).data("label")){this.value=this.defaultValue;$(this).removeClass(settings.labelledClass);}}).blur(function(){if(this.value===this.defaultValue){this.value=$(this).data("label");$(this).addClass(settings.labelledClass);}});var removeValuesOnExit=function(){jQuery_labellified_elements.each(function(){if(this.value===$(this).data("label")){this.value=this.defaultValue;$(this).removeClass(settings.labelledClass);}});};$(this).parents("form").submit(removeValuesOnExit);$(window).unload(removeValuesOnExit);if(this.value!==this.defaultValue){return;}this.value=$(this).data("label");$(this).addClass(settings.labelledClass);});};(function(c){var d=[];c.tools=c.tools||{};c.tools.tooltip={version:"1.1.2",conf:{effect:"toggle",fadeOutSpeed:"fast",tip:null,predelay:0,delay:30,opacity:1,lazy:undefined,position:["top","center"],offset:[0,0],cancelDefault:true,relative:false,oneInstance:true,events:{def:"mouseover,mouseout",input:"focus,blur",widget:"focus mouseover,blur mouseout",tooltip:"mouseover,mouseout"},api:false},addEffect:function(e,g,f){b[e]=[g,f];}};var b={toggle:[function(e){var f=this.getConf(),g=this.getTip(),h=f.opacity;if(h<1){g.css({opacity:h});}g.show();e.call();},function(e){this.getTip().hide();e.call();}],fade:[function(e){this.getTip().fadeIn(this.getConf().fadeInSpeed,e);},function(e){this.getTip().fadeOut(this.getConf().fadeOutSpeed,e);}]};function a(f,g){var p=this,k=c(this);f.data("tooltip",p);var l=f.next();if(g.tip){l=c(g.tip);if(l.length>1){l=f.nextAll(g.tip).eq(0);if(!l.length){l=f.parent().nextAll(g.tip).eq(0);}}}function o(u){var t=g.relative?f.position().top:f.offset().top,s=g.relative?f.position().left:f.offset().left,v=g.position[0];t-=l.outerHeight()-g.offset[0];s+=f.outerWidth()+g.offset[1];var q=l.outerHeight()+f.outerHeight();if(v=="center"){t+=q/2;}if(v=="bottom"){t+=q;}v=g.position[1];var r=l.outerWidth()+f.outerWidth();if(v=="center"){s-=r/2;}if(v=="left"){s-=r;}return{top:t,left:s};}var i=f.is(":input"),e=i&&f.is(":checkbox, :radio, select, :button"),h=f.attr("type"),n=g.events[h]||g.events[i?(e?"widget":"input"):"def"];n=n.split(/,\s*/);if(n.length!=2){throw"Tooltip: bad events configuration for "+h;}f.bind(n[0],function(r){if(g.oneInstance){c.each(d,function(){this.hide();});}var q=l.data("trigger");if(q&&q[0]!=this){l.hide().stop(true,true);}r.target=this;p.show(r);n=g.events.tooltip.split(/,\s*/);l.bind(n[0],function(){p.show(r);});if(n[1]){l.bind(n[1],function(){p.hide(r);});}});f.bind(n[1],function(q){p.hide(q);});if(!c.browser.msie&&!i&&!g.predelay){f.mousemove(function(){if(!p.isShown()){f.triggerHandler("mouseover");}});}if(g.opacity<1){l.css("opacity",g.opacity);}var m=0,j=f.attr("title");if(j&&g.cancelDefault){f.removeAttr("title");f.data("title",j);}c.extend(p,{show:function(r){if(r){f=c(r.target);}clearTimeout(l.data("timer"));if(l.is(":animated")||l.is(":visible")){return p;}function q(){l.data("trigger",f);var t=o(r);if(g.tip&&j){l.html(f.data("title"));}r=r||c.Event();r.type="onBeforeShow";k.trigger(r,[t]);if(r.isDefaultPrevented()){return p;}t=o(r);l.css({position:"absolute",top:t.top,left:t.left});var s=b[g.effect];if(!s){throw'Nonexistent effect "'+g.effect+'"';}s[0].call(p,function(){r.type="onShow";k.trigger(r);});}if(g.predelay){clearTimeout(m);m=setTimeout(q,g.predelay);}else{q();}return p;},hide:function(r){clearTimeout(l.data("timer"));clearTimeout(m);if(!l.is(":visible")){return;}function q(){r=r||c.Event();r.type="onBeforeHide";k.trigger(r);if(r.isDefaultPrevented()){return;}b[g.effect][1].call(p,function(){r.type="onHide";k.trigger(r);});}if(g.delay&&r){l.data("timer",setTimeout(q,g.delay));}else{q();}return p;},isShown:function(){return l.is(":visible, :animated");},getConf:function(){return g;},getTip:function(){return l;},getTrigger:function(){return f;},bind:function(q,r){k.bind(q,r);return p;},onHide:function(q){return this.bind("onHide",q);},onBeforeShow:function(q){return this.bind("onBeforeShow",q);},onShow:function(q){return this.bind("onShow",q);},onBeforeHide:function(q){return this.bind("onBeforeHide",q);},unbind:function(q){k.unbind(q);return p;}});c.each(g,function(q,r){if(c.isFunction(r)){p.bind(q,r);}});}c.prototype.tooltip=function(e){var f=this.eq(typeof e=="number"?e:0).data("tooltip");if(f){return f;}var g=c.extend(true,{},c.tools.tooltip.conf);if(c.isFunction(e)){e={onBeforeShow:e};}else{if(typeof e=="string"){e={tip:e};}}e=c.extend(true,g,e);if(typeof e.position=="string"){e.position=e.position.split(/,?\s/);}if(e.lazy!==false&&(e.lazy===true||this.length>20)){this.one("mouseover",function(h){f=new a(c(this),e);f.show(h);d.push(f);});}else{this.each(function(){f=new a(c(this),e);d.push(f);});}return e.api?f:this;};})(jQuery);(function(d){var c=d.tools.tooltip;c.plugins=c.plugins||{};c.plugins.dynamic={version:"1.0.1",conf:{api:false,classNames:"top right bottom left"}};function b(h){var e=d(window);var g=e.width()+e.scrollLeft();var f=e.height()+e.scrollTop();return[h.offset().top<=e.scrollTop(),g<=h.offset().left+h.width(),f<=h.offset().top+h.height(),e.scrollLeft()>=h.offset().left];}function a(f){var e=f.length;while(e--){if(f[e]){return false;}}return true;}d.fn.dynamic=function(g){var h=d.extend({},c.plugins.dynamic.conf),f;if(typeof g=="number"){g={speed:g};}g=d.extend(h,g);var e=g.classNames.split(/\s/),i;this.each(function(){if(d(this).tooltip().jquery){throw"Lazy feature not supported by dynamic plugin. set lazy: false for tooltip";}var j=d(this).tooltip().onBeforeShow(function(n,o){var m=this.getTip(),l=this.getConf();if(!i){i=[l.position[0],l.position[1],l.offset[0],l.offset[1],d.extend({},l)];}d.extend(l,i[4]);l.position=[i[0],i[1]];l.offset=[i[2],i[3]];m.css({visibility:"hidden",position:"absolute",top:o.top,left:o.left}).show();var k=b(m);if(!a(k)){if(k[2]){d.extend(l,g.top);l.position[0]="top";m.addClass(e[0]);}if(k[3]){d.extend(l,g.right);l.position[1]="right";m.addClass(e[1]);}if(k[0]){d.extend(l,g.bottom);l.position[0]="bottom";m.addClass(e[2]);}if(k[1]){d.extend(l,g.left);l.position[1]="left";m.addClass(e[3]);}if(k[0]||k[2]){l.offset[0]*=-1;}if(k[1]||k[3]){l.offset[1]*=-1;}}m.css({visibility:"visible"}).hide();});j.onShow(function(){var l=this.getConf(),k=this.getTip();l.position=[i[0],i[1]];l.offset=[i[2],i[3]];});j.onHide(function(){var k=this.getTip();k.removeClass(g.classNames);});f=j;});return g.api?f:this;};})(jQuery);(function(c){c.tools=c.tools||{};c.tools.overlay={version:"1.1.2",addEffect:function(e,f,g){b[e]=[f,g];},conf:{top:"10%",left:"center",absolute:false,speed:"normal",closeSpeed:"fast",effect:"default",close:null,oneInstance:true,closeOnClick:true,closeOnEsc:true,api:false,expose:null,target:null}};var b={};c.tools.overlay.addEffect("default",function(e){this.getOverlay().fadeIn(this.getConf().speed,e);},function(e){this.getOverlay().fadeOut(this.getConf().closeSpeed,e);});var d=[];function a(g,k){var o=this,m=c(this),n=c(window),j,i,h,e=k.expose&&c.tools.expose.version;var f=k.target||g.attr("rel");i=f?c(f):null||g;if(!i.length){throw"Could not find Overlay: "+f;}if(g&&g.index(i)==-1){g.click(function(p){o.load(p);return p.preventDefault();});}c.each(k,function(p,q){if(c.isFunction(q)){m.bind(p,q);}});c.extend(o,{load:function(u){if(o.isOpened()){return o;}var r=b[k.effect];if(!r){throw'Overlay: cannot find effect : "'+k.effect+'"';}if(k.oneInstance){c.each(d,function(){this.close(u);});}u=u||c.Event();u.type="onBeforeLoad";m.trigger(u);if(u.isDefaultPrevented()){return o;}h=true;if(e){i.expose().load(u);}var t=k.top;var s=k.left;var p=i.outerWidth({margin:true});var q=i.outerHeight({margin:true});if(typeof t=="string"){t=t=="center"?Math.max((n.height()-q)/2,0):parseInt(t,10)/100*n.height();}if(s=="center"){s=Math.max((n.width()-p)/2,0);}if(!k.absolute){t+=n.scrollTop();s+=n.scrollLeft();}i.css({top:t,left:s,position:"absolute"});u.type="onStart";m.trigger(u);r[0].call(o,function(){if(h){u.type="onLoad";m.trigger(u);}});if(k.closeOnClick){c(document).bind("click.overlay",function(w){if(!o.isOpened()){return;}var v=c(w.target);if(v.parents(i).length>1){return;}c.each(d,function(){this.close(w);});});}if(k.closeOnEsc){c(document).unbind("keydown.overlay").bind("keydown.overlay",function(v){if(v.keyCode==27){c.each(d,function(){this.close(v);});}});}return o;},close:function(q){if(!o.isOpened()){return o;}q=q||c.Event();q.type="onBeforeClose";m.trigger(q);if(q.isDefaultPrevented()){return;}h=false;b[k.effect][1].call(o,function(){q.type="onClose";m.trigger(q);});var p=true;c.each(d,function(){if(this.isOpened()){p=false;}});if(p){c(document).unbind("click.overlay").unbind("keydown.overlay");}return o;},getContent:function(){return i;},getOverlay:function(){return i;},getTrigger:function(){return g;},getClosers:function(){return j;},isOpened:function(){return h;},getConf:function(){return k;},bind:function(p,q){m.bind(p,q);return o;},unbind:function(p){m.unbind(p);return o;}});c.each("onBeforeLoad,onStart,onLoad,onBeforeClose,onClose".split(","),function(p,q){o[q]=function(r){return o.bind(q,r);};});if(e){if(typeof k.expose=="string"){k.expose={color:k.expose};}c.extend(k.expose,{api:true,closeOnClick:k.closeOnClick,closeOnEsc:false});var l=i.expose(k.expose);l.onBeforeClose(function(p){o.close(p);});o.onClose(function(p){l.close(p);});}j=i.find(k.close||".close");if(!j.length&&!k.close){j=c('<div class="close"></div>');i.prepend(j);}j.click(function(p){o.close(p);});}c.fn.overlay=function(e){var f=this.eq(typeof e=="number"?e:0).data("overlay");if(f){return f;}if(c.isFunction(e)){e={onBeforeLoad:e};}var g=c.extend({},c.tools.overlay.conf);e=c.extend(true,g,e);this.each(function(){f=new a(c(this),e);d.push(f);c(this).data("overlay",f);});return e.api?f:this;};})(jQuery);(function(b){var a=b.tools.overlay;a.plugins=a.plugins||{};a.plugins.gallery={version:"1.0.0",conf:{imgId:"img",next:".next",prev:".prev",info:".info",progress:".progress",disabledClass:"disabled",activeClass:"active",opacity:0.8,speed:"slow",template:"<strong>${title}</strong> <span>Image ${index} of ${total}</span>",autohide:true,preload:true,api:false}};b.fn.gallery=function(d){var o=b.extend({},a.plugins.gallery.conf),m;b.extend(o,d);m=this.overlay();var r=this,j=m.getOverlay(),k=j.find(o.next),g=j.find(o.prev),e=j.find(o.info),c=j.find(o.progress),h=g.add(k).add(e).css({opacity:o.opacity}),s=m.getClosers(),l;function p(u){c.fadeIn();h.hide();s.hide();var t=u.attr("href");var v=new Image();v.onload=function(){c.fadeOut();var y=b("#"+o.imgId,j);if(!y.length){y=b("<img/>").attr("id",o.imgId).css("visibility","hidden");j.prepend(y);}y.attr("src",t).css("visibility","hidden");var z=v.width;var A=(b(window).width()-z)/2;l=r.index(r.filter("[href="+t+"]"));r.removeClass(o.activeClass).eq(l).addClass(o.activeClass);var w=o.disabledClass;h.removeClass(w);if(l===0){g.addClass(w);}if(l==r.length-1){k.addClass(w);}var B=o.template.replace("${title}",u.attr("title")||u.data("title")).replace("${index}",l+1).replace("${total}",r.length);var x=parseInt(e.css("paddingLeft"),10)+parseInt(e.css("paddingRight"),10);e.html(B).css({width:z-x});j.animate({width:z,height:v.height,left:A},o.speed,function(){y.hide().css("visibility","visible").fadeIn(function(){if(!o.autohide){h.fadeIn();s.show();}});});};v.onerror=function(){j.fadeIn().html("Cannot find image "+t);};v.src=t;if(o.preload){r.filter(":eq("+(l-1)+"), :eq("+(l+1)+")").each(function(){var w=new Image();w.src=b(this).attr("href");});}}function f(t,u){t.click(function(){if(t.hasClass(o.disabledClass)){return;}var v=r.eq(i=l+(u?1:-1));if(v.length){p(v);}});}f(k,true);f(g);b(document).keydown(function(t){if(!j.is(":visible")||t.altKey||t.ctrlKey){return;}if(t.keyCode==37||t.keyCode==39){var u=t.keyCode==37?g:k;u.click();return t.preventDefault();}return true;});function q(){if(!j.is(":animated")){h.show();s.show();}}if(o.autohide){j.hover(q,function(){h.fadeOut();s.hide();}).mousemove(q);}var n;this.each(function(){var v=b(this),u=b(this).overlay(),t=u;u.onBeforeLoad(function(){p(v);});u.onClose(function(){r.removeClass(o.activeClass);});});return o.api?n:this;};})(jQuery);(function(b){b.tools=b.tools||{};b.tools.expose={version:"1.0.5",conf:{maskId:null,loadSpeed:"slow",closeSpeed:"fast",closeOnClick:true,closeOnEsc:true,zIndex:9998,opacity:0.8,color:"#456",api:false}};function a(){if(b.browser.msie){var f=b(document).height(),e=b(window).height();return[window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth,f-e<20?e:f];}return[b(window).width(),b(document).height()];}function c(h,g){var e=this,j=b(this),d=null,f=false,i=0;b.each(g,function(k,l){if(b.isFunction(l)){j.bind(k,l);}});b(window).resize(function(){e.fit();});b.extend(this,{getMask:function(){return d;},getExposed:function(){return h;},getConf:function(){return g;},isLoaded:function(){return f;},load:function(n){if(f){return e;}i=h.eq(0).css("zIndex");if(g.maskId){d=b("#"+g.maskId);}if(!d||!d.length){var l=a();d=b("<div/>").css({position:"absolute",top:0,left:0,width:l[0],height:l[1],display:"none",opacity:0,zIndex:g.zIndex});if(g.maskId){d.attr("id",g.maskId);}b("body").append(d);var k=d.css("backgroundColor");if(!k||k=="transparent"||k=="rgba(0, 0, 0, 0)"){d.css("backgroundColor",g.color);}if(g.closeOnEsc){b(document).bind("keydown.unexpose",function(o){if(o.keyCode==27){e.close();}});}if(g.closeOnClick){d.bind("click.unexpose",function(o){e.close(o);});}}n=n||b.Event();n.type="onBeforeLoad";j.trigger(n);if(n.isDefaultPrevented()){return e;}b.each(h,function(){var o=b(this);if(!/relative|absolute|fixed/i.test(o.css("position"))){o.css("position","relative");}});h.css({zIndex:Math.max(g.zIndex+1,i=="auto"?0:i)});var m=d.height();if(!this.isLoaded()){d.css({opacity:0,display:"block"}).fadeTo(g.loadSpeed,g.opacity,function(){if(d.height()!=m){d.css("height",m);}n.type="onLoad";j.trigger(n);});}f=true;return e;},close:function(k){if(!f){return e;}k=k||b.Event();k.type="onBeforeClose";j.trigger(k);if(k.isDefaultPrevented()){return e;}d.fadeOut(g.closeSpeed,function(){k.type="onClose";j.trigger(k);h.css({zIndex:b.browser.msie?i:null});});f=false;return e;},fit:function(){if(d){var k=a();d.css({width:k[0],height:k[1]});}},bind:function(k,l){j.bind(k,l);return e;},unbind:function(k){j.unbind(k);return e;}});b.each("onBeforeLoad,onLoad,onBeforeClose,onClose".split(","),function(k,l){e[l]=function(m){return e.bind(l,m);};});}b.fn.expose=function(d){var e=this.eq(typeof d=="number"?d:0).data("expose");if(e){return e;}if(typeof d=="string"){d={color:d};}var f=b.extend({},b.tools.expose.conf);d=b.extend(f,d);this.each(function(){e=new c(b(this),d);b(this).data("expose",e);});return d.api?e:this;};})(jQuery);(function(){function g(o){console.log("$f.fireEvent",[].slice.call(o));}function k(q){if(!q||typeof q!="object"){return q;}var o=new q.constructor();for(var p in q){if(q.hasOwnProperty(p)){o[p]=k(q[p]);}}return o;}function m(t,q){if(!t){return;}var o,p=0,r=t.length;if(r===undefined){for(o in t){if(q.call(t[o],o,t[o])===false){break;}}}else{for(var s=t[0];p<r&&q.call(s,p,s)!==false;s=t[++p]){}}return t;}function c(o){return document.getElementById(o);}function i(q,p,o){if(typeof p!="object"){return q;}if(q&&p){m(p,function(r,s){if(!o||typeof s!="function"){q[r]=s;}});}return q;}function n(s){var q=s.indexOf(".");if(q!=-1){var p=s.substring(0,q)||"*";var o=s.substring(q+1,s.length);var r=[];m(document.getElementsByTagName(p),function(){if(this.className&&this.className.indexOf(o)!=-1){r.push(this);}});return r;}}function f(o){o=o||window.event;if(o.preventDefault){o.stopPropagation();o.preventDefault();}else{o.returnValue=false;o.cancelBubble=true;}return false;}function j(q,o,p){q[o]=q[o]||[];q[o].push(p);}function e(){return"_"+(""+Math.random()).substring(2,10);}var h=function(t,r,s){var q=this;var p={};var u={};q.index=r;if(typeof t=="string"){t={url:t};}i(this,t,true);m(("Begin*,Start,Pause*,Resume*,Seek*,Stop*,Finish*,LastSecond,Update,BufferFull,BufferEmpty,BufferStop").split(","),function(){var v="on"+this;if(v.indexOf("*")!=-1){v=v.substring(0,v.length-1);var w="onBefore"+v.substring(2);q[w]=function(x){j(u,w,x);return q;};}q[v]=function(x){j(u,v,x);return q;};if(r==-1){if(q[w]){s[w]=q[w];}if(q[v]){s[v]=q[v];}}});i(this,{onCuepoint:function(x,w){if(arguments.length==1){p.embedded=[null,x];return q;}if(typeof x=="number"){x=[x];}var v=e();p[v]=[x,w];if(s.isLoaded()){s._api().fp_addCuepoints(x,r,v);}return q;},update:function(w){i(q,w);if(s.isLoaded()){s._api().fp_updateClip(w,r);}var v=s.getConfig();var x=(r==-1)?v.clip:v.playlist[r];i(x,w,true);},_fireEvent:function(v,y,w,A){if(v=="onLoad"){m(p,function(B,C){if(C[0]){s._api().fp_addCuepoints(C[0],r,B);}});return false;}A=A||q;if(v=="onCuepoint"){var z=p[y];if(z){return z[1].call(s,A,w);}}if(y&&"onBeforeBegin,onMetaData,onStart,onUpdate,onResume".indexOf(v)!=-1){i(A,y);if(y.metaData){if(!A.duration){A.duration=y.metaData.duration;}else{A.fullDuration=y.metaData.duration;}}}var x=true;m(u[v],function(){x=this.call(s,A,y,w);});return x;}});if(t.onCuepoint){var o=t.onCuepoint;q.onCuepoint.apply(q,typeof o=="function"?[o]:o);delete t.onCuepoint;}m(t,function(v,w){if(typeof w=="function"){j(u,v,w);delete t[v];}});if(r==-1){s.onCuepoint=this.onCuepoint;}};var l=function(p,r,q,t){var s={};var o=this;var u=false;if(t){i(s,t);}m(r,function(v,w){if(typeof w=="function"){s[v]=w;delete r[v];}});i(this,{animate:function(y,z,x){if(!y){return o;}if(typeof z=="function"){x=z;z=500;}if(typeof y=="string"){var w=y;y={};y[w]=z;z=500;}if(x){var v=e();s[v]=x;}if(z===undefined){z=500;}r=q._api().fp_animate(p,y,z,v);return o;},css:function(w,x){if(x!==undefined){var v={};v[w]=x;w=v;}r=q._api().fp_css(p,w);i(o,r);return o;},show:function(){this.display="block";q._api().fp_showPlugin(p);return o;},hide:function(){this.display="none";q._api().fp_hidePlugin(p);return o;},toggle:function(){this.display=q._api().fp_togglePlugin(p);return o;},fadeTo:function(y,x,w){if(typeof x=="function"){w=x;x=500;}if(w){var v=e();s[v]=w;}this.display=q._api().fp_fadeTo(p,y,x,v);this.opacity=y;return o;},fadeIn:function(w,v){return o.fadeTo(1,w,v);},fadeOut:function(w,v){return o.fadeTo(0,w,v);},getName:function(){return p;},getPlayer:function(){return q;},_fireEvent:function(w,v,x){if(w=="onUpdate"){var y=q._api().fp_getPlugin(p);if(!y){return;}i(o,y);delete o.methods;if(!u){m(y.methods,function(){var A=""+this;o[A]=function(){var B=[].slice.call(arguments);var C=q._api().fp_invoke(p,A,B);return C==="undefined"||C===undefined?o:C;};});u=true;}}var z=s[w];if(z){z.apply(o,v);if(w.substring(0,1)=="_"){delete s[w];}}}});};function b(o,t,z){var E=this,y=null,x,u,p=[],s={},B={},r,v,w,D,A,q;i(E,{id:function(){return r;},isLoaded:function(){return(y!==null);},getParent:function(){return o;},hide:function(F){if(F){o.style.height="0px";}if(y){y.style.height="0px";}return E;},show:function(){o.style.height=q+"px";if(y){y.style.height=A+"px";}return E;},isHidden:function(){return y&&parseInt(y.style.height,10)===0;},load:function(F){if(!y&&E._fireEvent("onBeforeLoad")!==false){m(a,function(){this.unload();});x=o.innerHTML;if(x&&!flashembed.isSupported(t.version)){o.innerHTML="";}flashembed(o,t,{config:z});if(F){F.cached=true;j(B,"onLoad",F);}}return E;},unload:function(){if(x.replace(/\s/g,"")!==""){if(E._fireEvent("onBeforeUnload")===false){return E;}try{if(y){y.fp_close();E._fireEvent("onUnload");}}catch(F){}y=null;o.innerHTML=x;}return E;},getClip:function(F){if(F===undefined){F=D;}return p[F];},getCommonClip:function(){return u;},getPlaylist:function(){return p;},getPlugin:function(F){var H=s[F];if(!H&&E.isLoaded()){var G=E._api().fp_getPlugin(F);if(G){H=new l(F,G,E);s[F]=H;}}return H;},getScreen:function(){return E.getPlugin("screen");},getControls:function(){return E.getPlugin("controls");},getConfig:function(F){return F?k(z):z;},getFlashParams:function(){return t;},loadPlugin:function(I,H,K,J){if(typeof K=="function"){J=K;K={};}var G=J?e():"_";E._api().fp_loadPlugin(I,H,K,G);var F={};F[G]=J;var L=new l(I,null,E,F);s[I]=L;return L;},getState:function(){return y?y.fp_getState():-1;},play:function(G,F){function H(){if(G!==undefined){E._api().fp_play(G,F);}else{E._api().fp_play();}}if(y){H();}else{E.load(function(){H();});}return E;},getVersion:function(){var G="flowplayer.js 3.1.4";if(y){var F=y.fp_getVersion();F.push(G);return F;}return G;},_api:function(){if(!y){throw"Flowplayer "+E.id()+" not loaded when calling an API method";}return y;},setClip:function(F){E.setPlaylist([F]);return E;},getIndex:function(){return w;}});m(("Click*,Load*,Unload*,Keypress*,Volume*,Mute*,Unmute*,PlaylistReplace,ClipAdd,Fullscreen*,FullscreenExit,Error,MouseOver,MouseOut").split(","),function(){var F="on"+this;if(F.indexOf("*")!=-1){F=F.substring(0,F.length-1);var G="onBefore"+F.substring(2);E[G]=function(H){j(B,G,H);return E;};}E[F]=function(H){j(B,F,H);return E;};});m(("pause,resume,mute,unmute,stop,toggle,seek,getStatus,getVolume,setVolume,getTime,isPaused,isPlaying,startBuffering,stopBuffering,isFullscreen,toggleFullscreen,reset,close,setPlaylist,addClip,playFeed").split(","),function(){var F=this;E[F]=function(H,G){if(!y){return E;}var I=null;if(H!==undefined&&G!==undefined){I=y["fp_"+F](H,G);}else{I=(H===undefined)?y["fp_"+F]():y["fp_"+F](H);}return I==="undefined"||I===undefined?E:I;};});E._fireEvent=function(O){if(typeof O=="string"){O=[O];}var P=O[0],M=O[1],K=O[2],J=O[3],I=0;if(z.debug){g(O);}if(!y&&P=="onLoad"&&M=="player"){y=y||c(v);A=y.clientHeight;m(p,function(){this._fireEvent("onLoad");});m(s,function(Q,R){R._fireEvent("onUpdate");});u._fireEvent("onLoad");}if(P=="onLoad"&&M!="player"){return;}if(P=="onError"){if(typeof M=="string"||(typeof M=="number"&&typeof K=="number")){M=K;K=J;}}if(P=="onContextMenu"){m(z.contextMenu[M],function(Q,R){R.call(E);});return;}if(P=="onPluginEvent"){var F=M.name||M;var G=s[F];if(G){G._fireEvent("onUpdate",M);G._fireEvent(K,O.slice(3));}return;}if(P=="onPlaylistReplace"){p=[];var L=0;m(M,function(){p.push(new h(this,L++,E));});}if(P=="onClipAdd"){if(M.isInStream){return;}M=new h(M,K,E);p.splice(K,0,M);for(I=K+1;I<p.length;I++){p[I].index++;}}var N=true;if(typeof M=="number"&&M<p.length){D=M;var H=p[M];if(H){N=H._fireEvent(P,K,J);}if(!H||N!==false){N=u._fireEvent(P,K,J,H);}}m(B[P],function(){N=this.call(E,M,K);if(this.cached){B[P].splice(I,1);}if(N===false){return false;}I++;});return N;};function C(){if($f(o)){$f(o).getParent().innerHTML="";w=$f(o).getIndex();a[w]=E;}else{a.push(E);w=a.length-1;}q=parseInt(o.style.height,10)||o.clientHeight;if(typeof t=="string"){t={src:t};}r=o.id||"fp"+e();v=t.id||r+"_api";t.id=v;z.playerId=r;if(typeof z=="string"){z={clip:{url:z}};}if(typeof z.clip=="string"){z.clip={url:z.clip};}z.clip=z.clip||{};if(o.getAttribute("href",2)&&!z.clip.url){z.clip.url=o.getAttribute("href",2);}u=new h(z.clip,-1,E);z.playlist=z.playlist||[z.clip];var F=0;m(z.playlist,function(){var H=this;if(typeof H=="object"&&H.length){H={url:""+H};}m(z.clip,function(I,J){if(J!==undefined&&H[I]===undefined&&typeof J!="function"){H[I]=J;}});z.playlist[F]=H;H=new h(H,F,E);p.push(H);F++;});m(z,function(H,I){if(typeof I=="function"){if(u[H]){u[H](I);}else{j(B,H,I);}delete z[H];}});m(z.plugins,function(H,I){if(I){s[H]=new l(H,I,E);}});if(!z.plugins||z.plugins.controls===undefined){s.controls=new l("controls",null,E);}s.canvas=new l("canvas",null,E);t.bgcolor=t.bgcolor||"#000000";t.version=t.version||[9,0];t.expressInstall="http://www.flowplayer.org/swf/expressinstall.swf";function G(H){if(!E.isLoaded()&&E._fireEvent("onBeforeClick")!==false){E.load();}return f(H);}x=o.innerHTML;if(x.replace(/\s/g,"")!==""){if(o.addEventListener){o.addEventListener("click",G,false);}else{if(o.attachEvent){o.attachEvent("onclick",G);}}}else{if(o.addEventListener){o.addEventListener("click",f,false);}E.load();}}if(typeof o=="string"){flashembed.domReady(function(){var F=c(o);if(!F){throw"Flowplayer cannot access element: "+o;}else{o=F;C();}});}else{C();}}var a=[];function d(o){this.length=o.length;this.each=function(p){m(o,p);};this.size=function(){return o.length;};}window.flowplayer=window.$f=function(){var p=null;var o=arguments[0];if(!arguments.length){m(a,function(){if(this.isLoaded()){p=this;return false;}});return p||a[0];}if(arguments.length==1){if(typeof o=="number"){return a[o];}else{if(o=="*"){return new d(a);}m(a,function(){if(this.id()==o.id||this.id()==o||this.getParent()==o){p=this;return false;}});return p;}}if(arguments.length>1){var r=arguments[1];var q=(arguments.length==3)?arguments[2]:{};if(typeof o=="string"){if(o.indexOf(".")!=-1){var t=[];m(n(o),function(){t.push(new b(this,k(r),k(q)));});return new d(t);}else{var s=c(o);return new b(s!==null?s:o,r,q);}}else{if(o){return new b(o,r,q);}}}return null;};i(window.$f,{fireEvent:function(){var o=[].slice.call(arguments);var q=$f(o[0]);return q?q._fireEvent(o.slice(1)):null;},addPlugin:function(o,p){b.prototype[o]=p;return $f;},each:m,extend:i});if(typeof jQuery=="function"){jQuery.prototype.flowplayer=function(q,p){if(!arguments.length||typeof arguments[0]=="number"){var o=[];this.each(function(){var r=$f(this);if(r){o.push(r);}});return arguments.length?o[arguments[0]]:new d(o);}return this.each(function(){$f(this,k(q),p?k(p):{});});};}})();(function(){var e=typeof jQuery=="function";var i={width:"100%",height:"100%",allowfullscreen:true,allowscriptaccess:"always",quality:"high",version:null,onFail:null,expressInstall:null,w3c:false,cachebusting:false};if(e){jQuery.tools=jQuery.tools||{};jQuery.tools.flashembed={version:"1.0.4",conf:i};}function j(){if(c.done){return false;}var l=document;if(l&&l.getElementsByTagName&&l.getElementById&&l.body){clearInterval(c.timer);c.timer=null;for(var k=0;k<c.ready.length;k++){c.ready[k].call();}c.ready=null;c.done=true;}}var c=e?jQuery:function(k){if(c.done){return k();}if(c.timer){c.ready.push(k);}else{c.ready=[k];c.timer=setInterval(j,13);}};function f(l,k){if(k){for(key in k){if(k.hasOwnProperty(key)){l[key]=k[key];}}}return l;}function g(k){switch(h(k)){case"string":k=k.replace(new RegExp('(["\\\\])',"g"),"\\$1");k=k.replace(/^\s?(\d+)%/,"$1pct");return'"'+k+'"';case"array":return"["+b(k,function(n){return g(n);}).join(",")+"]";case"function":return'"function()"';case"object":var l=[];for(var m in k){if(k.hasOwnProperty(m)){l.push('"'+m+'":'+g(k[m]));}}return"{"+l.join(",")+"}";}return String(k).replace(/\s/g," ").replace(/\'/g,'"');}function h(l){if(l===null||l===undefined){return false;}var k=typeof l;return(k=="object"&&l.push)?"array":k;}if(window.attachEvent){window.attachEvent("onbeforeunload",function(){__flash_unloadHandler=function(){};__flash_savedUnloadHandler=function(){};});}function b(k,n){var m=[];for(var l in k){if(k.hasOwnProperty(l)){m[l]=n(k[l]);}}return m;}function a(r,t){var q=f({},r);var s=document.all;var n='<object width="'+q.width+'" height="'+q.height+'"';if(s&&!q.id){q.id="_"+(""+Math.random()).substring(9);}if(q.id){n+=' id="'+q.id+'"';}if(q.cachebusting){q.src+=((q.src.indexOf("?")!=-1?"&":"?")+Math.random());}if(q.w3c||!s){n+=' data="'+q.src+'" type="application/x-shockwave-flash"';}else{n+=' classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"';}n+=">";if(q.w3c||s){n+='<param name="movie" value="'+q.src+'" />';}q.width=q.height=q.id=q.w3c=q.src=null;for(var l in q){if(q[l]!==null){n+='<param name="'+l+'" value="'+q[l]+'" />';}}var o="";if(t){for(var m in t){if(t[m]!==null){o+=m+"="+(typeof t[m]=="object"?g(t[m]):t[m])+"&";}}o=o.substring(0,o.length-1);n+='<param name="flashvars" value=\''+o+"' />";}n+="</object>";return n;}function d(m,p,l){var k=flashembed.getVersion();f(this,{getContainer:function(){return m;},getConf:function(){return p;},getVersion:function(){return k;},getFlashvars:function(){return l;},getApi:function(){return m.firstChild;},getHTML:function(){return a(p,l);}});var q=p.version;var r=p.expressInstall;var o=!q||flashembed.isSupported(q);if(o){p.onFail=p.version=p.expressInstall=null;m.innerHTML=a(p,l);}else{if(q&&r&&flashembed.isSupported([6,65])){f(p,{src:r});l={MMredirectURL:location.href,MMplayerType:"PlugIn",MMdoctitle:document.title};m.innerHTML=a(p,l);}else{if(m.innerHTML.replace(/\s/g,"")!==""){}else{m.innerHTML="<h2>Flash version "+q+" or greater is required</h2><h3>"+(k[0]>0?"Your version is "+k:"You have no flash plugin installed")+"</h3>"+(m.tagName=="A"?"<p>Click here to download latest version</p>":"<p>Download latest version from <a href='http://www.adobe.com/go/getflashplayer'>here</a></p>");if(m.tagName=="A"){m.onclick=function(){location.href="http://www.adobe.com/go/getflashplayer";};}}}}if(!o&&p.onFail){var n=p.onFail.call(this);if(typeof n=="string"){m.innerHTML=n;}}if(document.all){window[p.id]=document.getElementById(p.id);}}window.flashembed=function(l,m,k){if(typeof l=="string"){var n=document.getElementById(l);if(n){l=n;}else{c(function(){flashembed(l,m,k);});return;}}if(!l){return;}if(typeof m=="string"){m={src:m};}var o=f({},i);f(o,m);return new d(l,o,k);};f(window.flashembed,{getVersion:function(){var m=[0,0];if(navigator.plugins&&typeof navigator.plugins["Shockwave Flash"]=="object"){var l=navigator.plugins["Shockwave Flash"].description;if(typeof l!="undefined"){l=l.replace(/^.*\s+(\S+\s+\S+$)/,"$1");var n=parseInt(l.replace(/^(.*)\..*$/,"$1"),10);var r=/r/.test(l)?parseInt(l.replace(/^.*r(.*)$/,"$1"),10):0;m=[n,r];}}else{if(window.ActiveXObject){try{var p=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");}catch(q){try{p=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");m=[6,0];p.AllowScriptAccess="always";}catch(k){if(m[0]==6){return m;}}try{p=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");}catch(o){}}if(typeof p=="object"){l=p.GetVariable("$version");if(typeof l!="undefined"){l=l.replace(/^\S+\s+(.*)$/,"$1").split(",");m=[parseInt(l[0],10),parseInt(l[2],10)];}}}}return m;},isSupported:function(k){var m=flashembed.getVersion();var l=(m[0]>k[0])||(m[0]==k[0]&&m[1]>=k[1]);return l;},domReady:c,asString:g,getHTML:a});if(e){jQuery.fn.flashembed=function(l,k){var m=null;this.each(function(){m=flashembed(this,l,k);});return l.api===false?this:m;};}})();$f.addPlugin("controls",function(wrap,options){function fixE(e){if(typeof e=="undefined"){e=window.event;}if(typeof e.layerX=="undefined"){e.layerX=e.offsetX;}if(typeof e.layerY=="undefined"){e.layerY=e.offsetY;}return e;}function w(e){return e.clientWidth;}function offset(e){return e.offsetLeft;}function Draggable(o,min,max,offset){var dragging=false;function foo(){}o.onDragStart=o.onDragStart||foo;o.onDragEnd=o.onDragEnd||foo;o.onDrag=o.onDrag||foo;function move(x){if(x>max){return false;}if(x<min){return false;}o.style.left=x+"px";return true;}function end(){document.onmousemove=null;document.onmouseup=null;o.onDragEnd(parseInt(o.style.left,10));dragging=false;}function drag(e){e=fixE(e);var x=e.clientX-offset;if(move(x)){dragging=true;o.onDrag(x);}return false;}o.onmousedown=function(e){e=fixE(e);o.onDragStart(parseInt(o.style.left,10));document.onmousemove=drag;document.onmouseup=end;return false;};this.dragTo=function(x){if(move(x)){o.onDragEnd(x);}};this.setMax=function(val){max=val;};this.isDragging=function(){return dragging;};return this;}function extend(to,from){if(from){for(key in from){if(key){to[key]=from[key];}}}}function byClass(name){var els=wrap.getElementsByTagName("*");var re=new RegExp("(^|\\s)"+name+"(\\s|$)");for(var i=0;i<els.length;i++){if(re.test(els[i].className)){return els[i];}}}function pad(val){val=parseInt(val,10);return val>=10?val:"0"+val;}function toTime(sec){var h=Math.floor(sec/3600);var min=Math.floor(sec/60);sec=sec-(min*60);if(h>=1){min-=h*60;return pad(h)+":"+pad(min)+":"+pad(sec);}return pad(min)+":"+pad(sec);}function getTime(time,duration){return"<span>"+toTime(time)+"</span> <strong>"+toTime(duration)+"</strong>";}var self=this;var opts={playHeadClass:"playhead",trackClass:"track",playClass:"play",pauseClass:"pause",bufferClass:"buffer",progressClass:"progress",timeClass:"time",muteClass:"mute",unmuteClass:"unmute",duration:0,template:'<a class="play">play</a><div class="track"><div class="buffer"></div><div class="progress"></div><div class="playhead"></div></div><div class="time"></div><a class="mute">mute</a>'};extend(opts,options);if(typeof wrap=="string"){wrap=document.getElementById(wrap);}if(!wrap){return;}if(!wrap.innerHTML.replace(/\s/g,"")){wrap.innerHTML=opts.template;}var ball=byClass(opts.playHeadClass);var bufferBar=byClass(opts.bufferClass);var progressBar=byClass(opts.progressClass);var track=byClass(opts.trackClass);var time=byClass(opts.timeClass);var mute=byClass(opts.muteClass);time.innerHTML=getTime(0,opts.duration);var trackWidth=w(track);var ballWidth=w(ball);var head=new Draggable(ball,0,0,offset(wrap)+offset(track)+(ballWidth/2));track.onclick=function(e){e=fixE(e);if(e.target==ball){return false;}head.dragTo(e.layerX-ballWidth/2);};var play=byClass(opts.playClass);play.onclick=function(){if(self.isLoaded()){self.toggle();}else{self.play();}};mute.onclick=function(){if(self.getStatus().muted){self.unmute();}else{self.mute();}};var timer=null;function getMax(len,total){return parseInt(Math.min(len/total*trackWidth,trackWidth-ballWidth/2),10);}self.onStart(function(clip){var duration=clip.duration||0;clearInterval(timer);timer=setInterval(function(){var status=self.getStatus();if(status.time){time.innerHTML=getTime(status.time,clip.duration);}if(status.time===undefined){clearInterval(timer);return;}var x=getMax(status.bufferEnd,duration);bufferBar.style.width=x+"px";head.setMax(x);if(!self.isPaused()&&!head.isDragging()){x=getMax(status.time,duration);progressBar.style.width=x+"px";ball.style.left=(x-ballWidth/2)+"px";}},500);});self.onBegin(function(){play.className=opts.pauseClass;});self.onPause(function(){play.className=opts.playClass;});self.onResume(function(){play.className=opts.pauseClass;});self.onMute(function(){mute.className=opts.unmuteClass;});self.onUnmute(function(){mute.className=opts.muteClass;});self.onFinish(function(clip){clearInterval(timer);});self.onUnload(function(){time.innerHTML=getTime(0,opts.duration);});ball.onDragEnd=function(x){var to=parseInt(x/trackWidth*100,10)+"%";progressBar.style.width=x+"px";if(self.isLoaded()){self.seek(to);}};ball.onDrag=function(x){progressBar.style.width=x+"px";};return self;});(function(a){$f.addPlugin("playlist",function(d,o){var n=this;var b={playingClass:"playing",pausedClass:"paused",progressClass:"progress",template:'<a href="${url}">${title}</a>',loop:false,playOnClick:true,manual:false};a.extend(b,o);d=a(d);var j=n.getPlaylist().length<=1||b.manual;var k=null;function e(q){var p=m;a.each(q,function(r,s){if(!a.isFunction(s)){p=p.replace("${"+r+"}",s).replace("$%7B"+r+"%7D",s);}});return p;}function i(){k=d.children().unbind("click.playlist").bind("click.playlist",function(){return h(a(this),k.index(this));});}function c(){d.empty();a.each(n.getPlaylist(),function(){d.append(e(this));});i();}function h(p,q){if(p.hasClass(b.playingClass)||p.hasClass(b.pausedClass)){n.toggle();}else{p.addClass(b.progressClass);n.play(q);}return false;}function l(){if(j){k=d.children();}k.removeClass(b.playingClass);k.removeClass(b.pausedClass);k.removeClass(b.progressClass);}function f(p){return(j)?k.filter("[href="+p.originalUrl+"]"):k.eq(p.index);}if(!j){var m=d.is(":empty")?b.template:d.html();c();}else{k=d.children();if(a.isFunction(k.live)){a(d.selector+"> *").live("click",function(){var p=a(this);return h(p,p.attr("href"));});}else{k.click(function(){var p=a(this);return h(p,p.attr("href"));});}var g=n.getClip(0);if(!g.url&&b.playOnClick){g.update({url:k.eq(0).attr("href")});}}n.onBegin(function(p){l();f(p).addClass(b.playingClass);});n.onPause(function(p){f(p).removeClass(b.playingClass).addClass(b.pausedClass);});n.onResume(function(p){f(p).removeClass(b.pausedClass).addClass(b.playingClass);});if(!b.loop&&!j){n.onBeforeFinish(function(p){if(!p.isInStream&&p.index<k.length-1){return false;}});}if(j&&b.loop){n.onBeforeFinish(function(q){var p=f(q);if(p.next().length){p.next().click();}else{k.eq(0).click();}return false;});}n.onUnload(function(){l();});if(!j){n.onPlaylistReplace(function(){c();});}n.onClipAdd(function(q,p){k.eq(p).before(e(q));i();});return n;});})(jQuery);(function(){function toAbsolute(url,base){if(url.substring(0,4)=="http"){return url;}if(base){return base+(base.substring(base.length-1)!="/"?"/":"")+url;}base=location.protocol+"//"+location.host;if(url.substring(0,1)=="/"){return base+url;}var path=location.pathname;path=path.substring(0,path.lastIndexOf("/"));return base+path+"/"+url;}$f.addPlugin("embed",function(options){var self=this;var conf=self.getConfig(true);var opts={width:self.getParent().clientWidth||"100%",height:self.getParent().clientHeight||"100%",url:toAbsolute(self.getFlashParams().src),index:-1,allowfullscreen:true,allowscriptaccess:"always"};$f.extend(opts,options);opts.src=opts.url;opts.w3c=true;delete conf.playerId;delete opts.url;delete opts.index;this.getEmbedCode=function(runnable,index){index=typeof index=="number"?index:opts.index;if(index>=0){conf.playlist=[self.getPlaylist()[index]];}index=0;$f.each(conf.playlist,function(){conf.playlist[index++].url=toAbsolute(this.url,this.baseUrl);});var html=flashembed.getHTML(opts,{config:conf});if(!runnable){html=html.replace(/\</g,"&lt;").replace(/\>/g,"&gt;");}return html;};return self;});})();(function(a){a.fn.autoResize=function(j){var b=a.extend({onResize:function(){},animate:true,animateDuration:150,animateCallback:function(){},extraSpace:20,limit:1000},j);this.filter("textarea").each(function(){var c=a(this).css({resize:"none","overflow-y":"hidden"}),k=c.height(),f=(function(){var l=["height","width","lineHeight","textDecoration","letterSpacing"],h={};a.each(l,function(d,e){h[e]=c.css(e);});return c.clone().removeAttr("id").removeAttr("name").css({position:"absolute",top:0,left:-9999}).css(h).attr("tabIndex","-1").attr("id","hiddenTA").insertBefore(c);})(),i=null,g=function(){f.height(0).val(a(this).val()).scrollTop(10000);var d=Math.max(f.scrollTop(),k)+b.extraSpace,e=a(this).add(f);if(i===d){return;}i=d;if(d>=b.limit){a(this).css("overflow-y","");return;}b.onResize.call(this);b.animate&&c.css("display")==="block"?e.stop().animate({height:d},b.animateDuration,b.animateCallback):e.height(d);};c.unbind(".dynSiz").bind("click.dynSiz",g).bind("keyup.dynSiz",g).bind("keydown.dynSiz",g).bind("hover.dynSiz",g).bind("change.dynSiz",g);});return this;};})(jQuery);(function($){$.GrowingInput=function(element,options){var value,lastValue,calc;options=$.extend({min:0,max:null,startWidth:15,correction:15},options);element=$(element).data("growing",this);var self=this;var init=function(){calc=$("<span></span>").css({"float":"left",display:"inline-block",position:"absolute",left:-1000}).insertAfter(element);$.each(["font-size","font-family","padding-left","padding-top","padding-bottom","padding-right","border-left","border-right","border-top","border-bottom","word-spacing","letter-spacing","text-indent","text-transform"],function(i,p){calc.css(p,element.css(p));});element.blur(resize).keyup(resize).keydown(resize).keypress(resize);resize();};var calculate=function(chars){calc.text(chars);var width=calc.width();return(width?width:options.startWidth)+options.correction;};var resize=function(){lastValue=value;value=element.val();var retValue=value;if(chk(options.min)&&value.length<options.min){if(chk(lastValue)&&(lastValue.length<=options.min)){return;}retValue=str_pad(value,options.min,"-");}else{if(chk(options.max)&&value.length>options.max){if(chk(lastValue)&&(lastValue.length>=options.max)){return;}retValue=value.substr(0,options.max);}}element.width(calculate(retValue));return self;};this.resize=resize;init();};var chk=function(v){return !!(v||v===0);};var str_repeat=function(str,times){return new Array(times+1).join(str);};var str_pad=function(self,length,str,dir){if(self.length>=length){return this;}str=str||" ";var pad=str_repeat(str,length-self.length).substr(0,length-self.length);if(!dir||dir=="right"){return self+pad;}if(dir=="left"){return pad+self;}return pad.substr(0,(pad.length/2).floor())+self+pad.substr(0,(pad.length/2).ceil());};})(jQuery);(function($){$.TextboxList=function(element,_options){var original,container,list,current,focused=false,index=[],blurtimer,events={};var options=$.extend(true,{prefix:"textboxlist",max:null,unique:false,uniqueInsensitive:true,endEditableBit:true,startEditableBit:true,hideEditableBits:true,inBetweenEditableBits:true,keys:{previous:37,next:39},bitsOptions:{editable:{},box:{}},plugins:{},encode:function(o){return $.grep($.map(o,function(v){v=(chk(v[0])?v[0]:v[1]);return chk(v)?v.toString().replace(/,/,""):null;}),function(o){return o!=undefined;}).join(",");},decode:function(o){return o.split(",");}},_options);element=$(element);var self=this;var init=function(){original=element.css("display","none").attr("autocomplete","off").focus(focusLast);container=$('<div class="'+options.prefix+'" />').insertAfter(element).click(function(e){if((e.target==list.get(0)||e.target==container.get(0))&&(!focused||(current&&current.toElement().get(0)!=list.find(":last-child").get(0)))){focusLast();}});list=$('<ul class="'+options.prefix+'-bits" />').appendTo(container);for(var name in options.plugins){enablePlugin(name,options.plugins[name]);}afterInit();};var enablePlugin=function(name,options){self.plugins[name]=new $.TextboxList[camelCase(capitalize(name))](self,options);};var afterInit=function(){if(options.endEditableBit){create("editable",null,{tabIndex:original.tabIndex}).inject(list);}addEvent("bitAdd",update,true);addEvent("bitRemove",update,true);$(document).click(function(e){if(!focused){return;}if(e.target.className.indexOf(options.prefix)!=-1){if(e.target==$(container).get(0)){return;}var parent=$(e.target).parents("div."+options.prefix);if(parent.get(0)==container.get(0)){return;}}blur();}).keydown(function(ev){if(!focused||!current){return;}var caret=current.is("editable")?current.getCaret():null;var value=current.getValue()[1];var special=!!$.map(["shift","alt","meta","ctrl"],function(e){return ev[e];}).length;var custom=special||(current.is("editable")&&current.isSelected());var evStop=function(){ev.stopPropagation();ev.preventDefault();};switch(ev.which){case 8:if(current.is("box")){evStop();return current.remove();}case options.keys.previous:if(current.is("box")||((caret==0||!value.length)&&!custom)){evStop();focusRelative("prev");}break;case 46:if(current.is("box")){evStop();return current.remove();}case options.keys.next:if(current.is("box")||(caret==value.length&&!custom)){evStop();focusRelative("next");}}});setValues(options.decode(original.val()));};var create=function(klass,value,opt){if(klass=="box"){if(chk(options.max)&&list.children("."+options.prefix+"-bit-box").length+1>options.max){return false;}if(options.unique&&$.inArray(uniqueValue(value),index)!=-1){return false;}}return new $.TextboxListBit(klass,value,self,$.extend(true,options.bitsOptions[klass],opt));};var uniqueValue=function(value){return chk(value[0])?value[0]:(options.uniqueInsensitive?value[1].toLowerCase():value[1]);};var add=function(plain,id,html,afterEl){var b=create("box",[id,plain,html]);if(b){if(!afterEl||!afterEl.length){afterEl=list.find("."+options.prefix+"-bit-box").filter(":last");}b.inject(afterEl.length?afterEl:list,afterEl.length?"after":"top");}return self;};var focusRelative=function(dir,to){var el=getBit(to&&$(to).length?to:current).toElement();var b=getBit(el[dir]());if(b){b.focus();}return self;};var focusLast=function(){var lastElement=list.children().filter(":last");if(lastElement){getBit(lastElement).focus();}return self;};var blur=function(){if(!focused){return self;}if(current){current.blur();}focused=false;return fireEvent("blur");};var getBit=function(obj){return(obj.type&&(obj.type=="editable"||obj.type=="box"))?obj:$(obj).data("textboxlist:bit");};var getValues=function(){var values=[];list.children().each(function(){var bit=getBit(this);if(!bit.is("editable")){values.push(bit.getValue());}});return values;};var setValues=function(values){if(!values){return;}$.each(values,function(i,v){if(v){add.apply(self,$.isArray(v)?[v[1],v[0],v[2]]:[v]);}});};var update=function(){original.val(options.encode(getValues()));};var addEvent=function(type,fn){if(events[type]==undefined){events[type]=[];}var exists=false;$.each(events[type],function(f){if(f===fn){exists=true;return;}});if(!exists){events[type].push(fn);}return self;};var fireEvent=function(type,args,delay){if(!events||!events[type]){return self;}$.each(events[type],function(i,fn){(function(){args=(args!=undefined)?splat(args):Array.prototype.slice.call(arguments);var returns=function(){return fn.apply(self||null,args);};if(delay){return setTimeout(returns,delay);}return returns();})();});return self;};var removeEvent=function(type,fn){if(events[type]){for(var i=events[type].length;i--;i){if(events[type][i]===fn){events[type].splice(i,1);}}}return self;};var isDuplicate=function(v){return $.inArray(uniqueValue(v),index);};this.onFocus=function(bit){if(current){current.blur();}clearTimeout(blurtimer);current=bit;container.addClass(options.prefix+"-focus");if(!focused){focused=true;fireEvent("focus",bit);}};this.onAdd=function(bit){if(options.unique&&bit.is("box")){index.push(uniqueValue(bit.getValue()));}if(bit.is("box")){var prior=getBit(bit.toElement().prev());if((prior&&prior.is("box")&&options.inBetweenEditableBits)||(!prior&&options.startEditableBit)){var priorEl=prior&&prior.toElement().length?prior.toElement():false;var b=create("editable").inject(priorEl||list,priorEl?"after":"top");if(options.hideEditableBits){b.hide();}}}};this.onRemove=function(bit){if(!focused){return;}if(options.unique&&bit.is("box")){var i=isDuplicate(bit.getValue());if(i!=-1){index=index.splice(i+1,1);}}var prior=getBit(bit.toElement().prev());if(prior&&prior.is("editable")){prior.remove();}focusRelative("next",bit);};this.onBlur=function(bit,all){current=null;container.removeClass(options.prefix+"-focus");blurtimer=setTimeout(blur,all?0:200);};this.setOptions=function(opt){options=$.extend(true,options,opt);};this.getOptions=function(){return options;};this.getContainer=function(){return container;};this.isDuplicate=isDuplicate;this.addEvent=addEvent;this.removeEvent=removeEvent;this.fireEvent=fireEvent;this.create=create;this.add=add;this.getValues=getValues;this.plugins=[];init();};$.TextboxListBit=function(type,value,textboxlist,_options){var element,bit,prefix,typeprefix,close,hidden,focused=false,name=capitalize(type);var options=$.extend(true,type=="box"?{deleteButton:true}:{tabIndex:null,growing:true,growingOptions:{},stopEnter:true,addOnBlur:false,addKeys:[13]},_options);this.type=type;this.value=value;var self=this;var init=function(){prefix=textboxlist.getOptions().prefix+"-bit";typeprefix=prefix+"-"+type;bit=$("<li />").addClass(prefix).addClass(typeprefix).data("textboxlist:bit",self).hover(function(){bit.addClass(prefix+"-hover").addClass(typeprefix+"-hover");},function(){bit.removeClass(prefix+"-hover").removeClass(typeprefix+"-hover");});if(type=="box"){bit.html(chk(self.value[2])?self.value[2]:self.value[1]).click(focus);if(options.deleteButton){bit.addClass(typeprefix+"-deletable");close=$('<a href="#" class="'+typeprefix+'-deletebutton" />').click(remove).appendTo(bit);}bit.children().click(function(e){e.stopPropagation();e.preventDefault();});}else{element=$('<input type="text" class="'+typeprefix+'-input" autocomplete="off" />').val(self.value?self.value[1]:"").appendTo(bit);if(chk(options.tabIndex)){element.tabIndex=options.tabIndex;}if(options.growing){new $.GrowingInput(element,options.growingOptions);}element.focus(function(){focus(true);}).blur(function(){blur(true);if(options.addOnBlur){toBox();}});if(options.addKeys||options.stopEnter){element.keydown(function(ev){if(!focused){return;}var evStop=function(){ev.stopPropagation();ev.preventDefault();};if(options.stopEnter&&ev.which===13){evStop();}if($.inArray(ev.which,splat(options.addKeys))!=-1){evStop();toBox();}});}}};var inject=function(el,where){switch(where||"bottom"){case"top":bit.prependTo(el);break;case"bottom":bit.appendTo(el);break;case"before":bit.insertBefore(el);break;case"after":bit.insertAfter(el);break;}textboxlist.onAdd(self);return fireBitEvent("add");};var focus=function(noReal){if(focused){return self;}show();focused=true;textboxlist.onFocus(self);bit.addClass(prefix+"-focus").addClass(prefix+"-"+type+"-focus");fireBitEvent("focus");if(type=="editable"&&!noReal){element.focus();}return self;};var blur=function(noReal){if(!focused){return self;}focused=false;textboxlist.onBlur(self);bit.removeClass(prefix+"-focus").removeClass(prefix+"-"+type+"-focus");fireBitEvent("blur");if(type=="editable"){if(!noReal){element.blur();}if(hidden&&!element.val().length){hide();}}return self;};var remove=function(){blur();textboxlist.onRemove(self);bit.remove();return fireBitEvent("remove");};var show=function(){bit.css("display","block");return self;};var hide=function(){bit.css("display","none");hidden=true;return self;};var fireBitEvent=function(type){type=capitalize(type);textboxlist.fireEvent("bit"+type,self).fireEvent("bit"+name+type,self);return self;};this.is=function(t){return type==t;};this.setValue=function(v){if(type=="editable"){element.val(chk(v[0])?v[0]:v[1]);if(options.growing){element.data("growing").resize();}}else{value=v;}return self;};this.getValue=function(){return type=="editable"?[null,element.val(),null]:value;};if(type=="editable"){this.getCaret=function(){var el=element.get(0);if(el.createTextRange){var r=document.selection.createRange().duplicate();r.moveEnd("character",el.value.length);if(r.text===""){return el.value.length;}return el.value.lastIndexOf(r.text);}else{return el.selectionStart;}};this.getCaretEnd=function(){var el=element.get(0);if(el.createTextRange){var r=document.selection.createRange().duplicate();r.moveStart("character",-el.value.length);return r.text.length;}else{return el.selectionEnd;}};this.isSelected=function(){return focused&&(self.getCaret()!==self.getCaretEnd());};var toBox=function(){var value=self.getValue();var b=textboxlist.create("box",value);if(b){b.inject(bit,"before");self.setValue([null,"",null]);return b;}return null;};this.toBox=toBox;}this.toElement=function(){return bit;};this.focus=focus;this.blur=blur;this.remove=remove;this.inject=inject;this.show=show;this.hide=hide;this.fireBitEvent=fireBitEvent;init();};var chk=function(v){return !!(v||v===0);};var splat=function(a){return $.isArray(a)?a:[a];};var camelCase=function(str){return str.replace(/-\D/g,function(match){return match.charAt(1).toUpperCase();});};var capitalize=function(str){return str.replace(/\b[a-z]/g,function(A){return A.toUpperCase();});};$.fn.extend({textboxlist:function(options){return this.each(function(){new $.TextboxList(this,options);});}});})(jQuery);
