/*
* Web Forms 2.0 Cross-browser Implementation
* Version: 0.5.4 (2008-07-29)
* Copyright: 2007, Weston Ruter
* License: GNU General Public License, Free Software Foundation
*
*
* The comments contained in this code are largely quotations from the
* WebForms 2.0 specification:
*
* Usage:
*/
if(!window.$wf2){var $wf2={};if(document.implementation&&document.implementation.hasFeature&&!document.implementation.hasFeature("WebForms","2.0")){$wf2={version:"0.5.4",isInitialized:false,libpath:"",globalEvent:null,hasElementExtensions:window.HTMLElement&&HTMLElement.prototype,hasGettersAndSetters:$wf2.__defineGetter__&&$wf2.__defineSetter__,hasBadImplementation:navigator.userAgent.indexOf("WebKit"),callBeforeValidation:[],callAfterValidation:[],callAfterDOMContentLoaded:[],onDOMContentLoaded:function(){if(!$wf2.isInitialized){$wf2.isInitialized= true;var a;if(document.createEventObject)$wf2.globalEvent=document.createEventObject();else if(document.createEvent)$wf2.globalEvent=document.createEvent("HTMLEvents");a=document.createElement("link");a.setAttribute("type","text/css");a.setAttribute("rel","stylesheet");a.setAttribute("href",$wf2.libpath+"webforms2.css");var b=document.getElementsByTagName("head")[0];b||(b=document.getElementsByTagName("*")[0]);b.insertBefore(a,b.firstChild);$wf2.zeroPoint={};$wf2.zeroPoint.datetime=$wf2.parseISO8601("1970-01-01T00:00:00.0Z"); $wf2.zeroPoint["datetime-local"]=$wf2.parseISO8601("1970-01-01T00:00:00.0");$wf2.zeroPoint.date=$wf2.zeroPoint.datetime;$wf2.zeroPoint.month=$wf2.zeroPoint.datetime;$wf2.zeroPoint.week=$wf2.parseISO8601("1970-W01");$wf2.zeroPoint.time=$wf2.zeroPoint.datetime;$wf2.xhr=null;if(window.XMLHttpRequest)$wf2.xhr=new XMLHttpRequest;else if(window.ActiveXObject)try{$wf2.xhr=new ActiveXObject("Msxml2.XMLHTTP")}catch(c){try{$wf2.xhr=new ActiveXObject("Microsoft.XMLHTTP")}catch(d){}}if($wf2.xhr){$wf2.prefillSelectElements(); $wf2.prefillFormElements()}$wf2.initRepetitionBlocks();$wf2.initRepetitionTemplates();$wf2.initRepetitionButtons("add");$wf2.initRepetitionButtons("remove");$wf2.initRepetitionButtons("move-up");$wf2.initRepetitionButtons("move-down");$wf2.updateAddButtons();$wf2.updateMoveButtons();if(document.addEventListener){document.addEventListener("mousedown",$wf2.clearInvalidIndicators,false);document.addEventListener("keydown",$wf2.clearInvalidIndicators,false)}else if(document.attachEvent){document.attachEvent("onmousedown", $wf2.clearInvalidIndicators);document.attachEvent("onkeydown",$wf2.clearInvalidIndicators)}$wf2.initNonRepetitionFunctionality();for(a=0;a<$wf2.callAfterDOMContentLoaded.length;a++)$wf2.callAfterDOMContentLoaded[a]()}},prefillSelectElements:function(){for(var a,b=$wf2.getElementsByTagNames.apply(document.documentElement,["select","datalist"]),c=0;a=b[c];c++){var d=$wf2.loadDataURI(a);if(d&&d.documentElement&&/:?\bselect$/i.test(d.documentElement.nodeName)&&d.documentElement.namespaceURI=="http://www.w3.org/1999/xhtml"){d= d.documentElement;if(d.getAttribute("type")!="incremental")for(;a.lastChild;)a.removeChild(a.lastChild);for(node=d.firstChild;node;){a.appendChild($wf2.cloneNode(node));node=node.nextSibling}}}},prefillFormElements:function(){for(var a,b=document.getElementsByTagName("form"),c=0;a=b[c];c++){var d=$wf2.loadDataURI(a);if(d&&d.documentElement&&/:?\bformdata$/.test(d.documentElement.nodeName)&&d.documentElement.namespaceURI=="http://n.whatwg.org/formdata"){var e,f=d.documentElement;f.getAttribute("type")!= "incremental"&&a.reset();var g=f.getElementsByTagName("clear");for(j=0;d=g[j];j++)if(d.namespaceURI=="http://n.whatwg.org/formdata"&&d.parentNode==f&&!d.firstChild&&(e=document.getElementById(d.getAttribute("template")))&&e.getAttribute("repeat")=="template"){var k,h;for(d=e.parentNode.firstChild;d;)if(d.nodeType==1&&(k=d.getAttributeNode("repeat"))&&k.value!="template"){h=d.nextSibling;d.parentNode.removeChild(d);d=h}else d=d.nextSibling}var q;g=f.getElementsByTagName("repeat");for(j=0;d=g[j];j++)if(d.namespaceURI== "http://n.whatwg.org/formdata"&&d.parentNode==f&&!d.firstChild&&(e=document.getElementById(d.getAttribute("template")))&&e.getAttribute("repeat")=="template"&&/^-?\d+$/.test(q=d.getAttribute("index"))){var m;for(d=e.parentNode.firstChild;d;){if(d.nodeType==1&&(k=d.getAttributeNode("repeat"))&&k.value==q){m=true;break}d=d.nextSibling}m||$wf2.addRepetitionBlockByIndex.apply(e,[null,q])}var n;f=f.getElementsByTagName("field");g=$wf2.getFormElements.apply(a);for(j=0;n=f[j];j++){var l=n.getAttributeNode("index"), o=n.getAttribute("name");if(!(!o||l&&!/^\d+$/.test(l.value))){h="";for(p=0;d=n.childNodes[p];p++)if(d.nodeType==3||d.nodeType==4)h+=d.data;else break;for(p=n=0;d=g[p];p++)if(d.type=="image"){if(d.name?d.name+".x"==o||d.name+".y"==o:o=="x"||o=="y")if(!l||++n-1>=l.value)break}else if(d.name==o){if(l){if(++n-1this.repetitionIndex)this.repetitionIndex=b;c=this.getAttribute("id")?"id":this.getAttribute("name")?"name":"";d=this.getAttribute(c);var f,g=this.repetitionIndex,k;if(d&&!/\u005B|\u02D1|\u005D|\u00B7/.test(d)){k=RegExp("(\\[|\u02d1)"+d+"(\\]|\u00b7)","g");f=function(n){if(!n)return n;n=n.toString();if(n.indexOf("\ufeff")===0)return n.replace(/^\uFEFF/,"");return n.replace(k,g)}}f=$wf2.cloneNode(this,f);f.wf2Initialized= false;k=null;f.setAttribute("repeat",this.repetitionIndex);f.removeAttribute("repeat-min");f.removeAttribute("repeat-max");f.removeAttribute("repeat-start");if(c){f.setAttribute("repeat-template",d);f.removeAttribute(c)}if(a){a.parentNode.insertBefore(f,a.nextSibling);this.repetitionBlocks.push(f);$wf2.sortNodes&&this.repetitionBlocks.sort($wf2.sortNodes)}else{for(a=this;a.previousSibling&&a.previousSibling.repetitionType!=RepetitionElement.REPETITION_BLOCK;)a=a.previousSibling;this.parentNode.insertBefore(f, a);this.repetitionBlocks.push(f)}this.repetitionIndex++;$wf2.constructRepetitionBlock.apply(f);$wf2.initRepetitionTemplates(f);$wf2.initRepetitionButtons("add",f);$wf2.initRepetitionButtons("remove",f);$wf2.initRepetitionButtons("move-up",f);$wf2.initRepetitionButtons("move-down",f);if($wf2.isInitialized){$wf2.updateAddButtons(this);$wf2.updateMoveButtons(this.parentNode)}$wf2.initNonRepetitionFunctionality(f);var h;try{if(document.createEvent)h=document.createEvent("UIEvents");else if(document.createEventObject)h= document.createEventObject();RepetitionEvent._upgradeEvent.apply(h);h.initRepetitionEvent("added",true,false,f);this.dispatchEvent&&this.dispatchEvent(h)}catch(q){h={};RepetitionEvent._upgradeEvent.apply(h);h.initRepetitionEvent("added",true,false,f)}if((c=this.getAttribute("onadded"))&&(!this.onadded||typeof this.onadded!="function"))this.onadded=new Function("event",c);else if((c=this.getAttribute("onadd"))&&(!this.onadd||typeof this.onadd!="function"))this.onadd=new Function("event",c);try{if(this.onadded)this.onadded.apply(this, [h]);else this.onadd&&this.onadd.apply(this,[h])}catch(m){setTimeout(function(){throw m;},0)}return f},addRepetitionBlockByIndex:function(a,b){$wf2.addRepetitionBlock.apply(this,[a,b])},removeRepetitionBlock:function(){if(this.repetitionType!=RepetitionElement.REPETITION_BLOCK)throw $wf2.DOMException(9);var a=this.parentNode;a.removeChild(this);$wf2.updateMoveButtons(a);if(this.repetitionTemplate!=null)for(a=0;a=d.repeatMax)b[c].disabled=true},updateMoveButtons:function(a){var b=[];if(a){var c,d,e;for(a=a.firstChild;a;){a.repetitionType==RepetitionElement.REPETITION_BLOCK&&b.push(a);a=a.nextSibling}for(a=0;e=b[a];a++){var f=$wf2.getElementsByTagNamesAndAttribute.apply(e,[["button"],"type","move-up"]);for(c=0;d=f[c];c++)d.disabled=!(rb=$wf2.getRepetitionBlock(d))||a==0;e=$wf2.getElementsByTagNamesAndAttribute.apply(e, [["button"],"type","move-down"]);for(c=0;d=e[c];c++)d.disabled=!(rb=$wf2.getRepetitionBlock(d))||a==b.length-1}}else{c=[];b=$wf2.getElementsByTagNamesAndAttribute.apply(document.documentElement,[["*"],"repeat","template",true]);for(a=0;e=b[a];a++)if(!$wf2.arrayHasItem(c,e.parentNode)){$wf2.updateMoveButtons(e.parentNode);c.push(e.parentNode)}}},initNonRepetitionFunctionality:function(a){a=a||document.documentElement;var b,c,d=a.getElementsByTagName("form");for(b=0;c=d[b];b++)if(!(c.checkValidity&& !$wf2.hasBadImplementation)){c.checkValidity=$wf2.formCheckValidity;c.addEventListener?c.addEventListener("submit",$wf2.onsubmitValidityHandler,false):c.attachEvent("onsubmit",$wf2.onsubmitValidityHandler)}d=$wf2.getElementsByTagNames.apply(a,["input","select","textarea","button"]);for(b=0;c=d[b];b++){$wf2.applyValidityInterface(c);$wf2.updateValidityState(c)}c=$wf2.getElementsByTagNamesAndAttribute.apply(document.documentElement,[["*"],"autofocus"]);a.getAttribute("autofocus")&&c.unshift(a);for(b= 0;ba.max}else if(e=="file"){a.min=b&&/^\d+$/.test(b.value)?Number(b.value):0;a.max=c&&/^\d+$/.test(c.value)?Number(c.value):1}else{if(b){a.min=$wf2.parseISO8601(b.value,e);a.validity.rangeUnderflow=a.min&&a.wf2Valuea.max}}if(q&&!a.validity.rangeUnderflow&&!a.validity.rangeOverflow){g=$wf2.getOriginalAttrNode(a,"step");a.step=g?g.value=="any"?"any": $wf2.numberRegExp.test(g.value)&&g.value>0?Number(g.value):f?60:1:f?60:1;if(a.step!="any"){a.wf2StepDatum=null;a.wf2StepDatum=b?a.min:c?a.max:$wf2.zeroPoint[e]?$wf2.zeroPoint[e]:0;b=a.step;if(e=="month"&&a.wf2StepDatum&&a.wf2StepDatum.getUTCFullYear){e=a.wf2StepDatum.getUTCFullYear()*12+a.wf2StepDatum.getUTCMonth();c=a.wf2Value.getUTCFullYear()*12+a.wf2Value.getUTCMonth();a.validity.stepMismatch=(c-e)%b!=0}else{switch(e){case "datetime":case "datetime-local":case "time":b=parseInt(b*1E3);break;case "date":b= parseInt(b*24*60*60*1E3);break;case "week":b=parseInt(b*7*24*60*60*1E3)}a.validity.stepMismatch=Math.round((a.wf2Value-a.wf2StepDatum)*1E3)%Math.round(b*1E3)!=0}}}}if(m&&a.maxLength>=0&&a.value!=a.defaultValue){m=a.value;a.wf2ValueLength=m.length;for(d=1;da.maxLength}}a.validity.valid=!$wf2.hasInvalidState(a.validity)},applyValidityInterface:function(a){if($wf2.hasBadImplementation){if(a.type== "submit"||a.type=="button")a.formNoValidate=true}else if(a.validity&&a.validity.typeMismatch!==undefined)return a;a.validationMessage="";a.validity=$wf2.createValidityState();a.willValidate=true;var b=a.nodeName.toLowerCase();if(b=="button"||b=="fieldset"){a.setCustomValidity=function(){throw $wf2.DOMException(9);};a.checkValidity=function(){return true};return a}if(!a.setCustomValidity)a.setCustomValidity=$wf2.controlSetCustomValidity;a.checkValidity=$wf2.controlCheckValidity;if(/(hidden|button|reset|add|remove|move-up|move-down)/.test(a.getAttribute("type")? a.getAttribute("type").toLowerCase():a.type)||!a.name||a.disabled)a.willValidate=false;else if(window.RepetitionElement)for(b=a;b=b.parentNode;)if(b.repetitionType==RepetitionElement.REPETITION_TEMPLATE){a.willValidate=false;break}return a},onsubmitValidityHandler:function(a){for(var b=a.currentTarget||a.srcElement,c=0;c<$wf2.callBeforeValidation.length;c++)$wf2.callBeforeValidation[c](a);if(b.checkValidity())b=a.returnValue=true;else{a.preventDefault&&a.preventDefault();b=a.returnValue=false}for(c= 0;c<$wf2.callAfterValidation.length;c++)$wf2.callAfterValidation[c](a,b);return b},controlSetCustomValidity:function(a){if(a){this.validationMessage=String(a);this.validity.customError=true}else{this.validationMessage="";this.validity.customError=false}this.validity.valid=!$wf2.hasInvalidState(this.validity)},hasInvalidState:function(a){return a.typeMismatch||a.rangeUnderflow||a.rangeOverflow||a.stepMismatch||a.tooLong||a.patternMismatch||a.valueMissing||a.customError},createValidityState:function(){return{typeMismatch:false, rangeUnderflow:false,rangeOverflow:false,stepMismatch:false,tooLong:false,patternMismatch:false,valueMissing:false,customError:false,valid:true}},invalidIndicators:[],indicatorTimeoutId:null,indicatorIntervalId:null,stepUnits:{datetime:"second","datetime-local":"second",time:"second",date:"day",week:"week",month:"month"},invalidMessages:{valueMissing:"A value must be supplied or selected.",typeMismatch:"The value is invalid for %s type.",rangeUnderflow:"The value must be equal to or greater than %s.", rangeOverflow:"The value must be equal to or less than %s.",stepMismatch:"The value has a step mismatch; it must be a certain number multiples of %s from %s.",tooLong:"The value is too long. The field may have a maximum of %s characters but you supplied %s. Note that each line-break counts as two characters.",patternMismatch:"The value is not in the format required."},valueToWF2Type:function(a,b){switch(String(b).toLowerCase()){case "datetime":case "datetime-local":case "date":case "month":case "week":case "time":return $wf2.dateToISO8601(a, b);default:return a}},addInvalidIndicator:function(a){var b=document.createElement("div");b.className="wf2_errorMsg";b.id=(a.id||a.name)+"_wf2_errorMsg";b.onmousedown=function(){this.parentNode.removeChild(this)};var c=a.getAttribute("type")?a.getAttribute("type").toLowerCase():a.type,d=document.createElement("ol");a.validity.valueMissing&&d.appendChild($wf2.createLI($wf2.invalidMessages.valueMissing));a.validity.typeMismatch&&d.appendChild($wf2.createLI($wf2.invalidMessages.typeMismatch.replace(/%s/, c)));a.validity.rangeUnderflow&&d.appendChild($wf2.createLI($wf2.invalidMessages.rangeUnderflow.replace(/%s/,$wf2.valueToWF2Type(a.min,c))));a.validity.rangeOverflow&&d.appendChild($wf2.createLI($wf2.invalidMessages.rangeOverflow.replace(/%s/,$wf2.valueToWF2Type(a.max,c))));if(a.validity.stepMismatch)d.appendChild($wf2.createLI($wf2.invalidMessages.stepMismatch.replace(/%s/,a.step+($wf2.stepUnits[c]?" "+$wf2.stepUnits[c]+"(s)":"")).replace(/%s/,$wf2.valueToWF2Type(a.wf2StepDatum,c))));if(a.validity.tooLong)d.appendChild($wf2.createLI($wf2.invalidMessages.tooLong.replace(/%s/, a.maxLength).replace(/%s/,a.wf2ValueLength?a.wf2ValueLength:a.value.length)));if(a.validity.patternMismatch)d.appendChild($wf2.createLI($wf2.invalidMessages.patternMismatch.replace(/%s/,a.title?a.title:' "'+a.getAttribute("pattern")+'"')));a.validity.customError&&d.appendChild($wf2.createLI(a.validationMessage));if(d.childNodes.length==1)d.className="single";b.appendChild(d);c=document.body?document.body:document.documentElement;$wf2.invalidIndicators.length?c.insertBefore(b,$wf2.invalidIndicators[$wf2.invalidIndicators.length- 1].errorMsg):c.insertBefore(b,null);for(c=a;c&&(c.nodeType!=1||c.style.display=="none"||c.style.visibility=="hidden"||!c.offsetParent);)c=c.parentNode;d=left=0;var e=c;if(e&&e.offsetParent){left=e.offsetLeft;for(d=e.offsetTop;e=e.offsetParent;){left+=e.offsetLeft;d+=e.offsetTop}d+=c.offsetHeight}b.style.top=d+"px";b.style.left=left+"px";$wf2.invalidIndicators.push({target:a,errorMsg:b});a.className.match(/\bwf2_invalid\b/)||(a.className+=" wf2_invalid");if($wf2.indicatorIntervalId==null){$wf2.indicatorIntervalId= setInterval(function(){for(var f,g=0;f=$wf2.invalidIndicators[g];g++)if(f.target.className.match(/\bwf2_invalid\b/))f.target.className=f.target.className.replace(/\s?wf2_invalid/,"");else f.target.className+=" wf2_invalid"},500);setTimeout(function(){for(var f=0;f<$wf2.callAfterValidation.length;f++)$wf2.callAfterValidation[f](null,false)},1);$wf2.indicatorTimeoutId=setTimeout($wf2.clearInvalidIndicators,4E3)}},clearInvalidIndicators:function(){clearTimeout($wf2.indicatorTimeoutId);$wf2.indicatorTimeoutId= null;clearInterval($wf2.indicatorIntervalId);$wf2.indicatorIntervalId=null;for(var a;a=$wf2.invalidIndicators[0];){a.errorMsg&&a.errorMsg.parentNode&&a.errorMsg.parentNode.removeChild(a.errorMsg);a=a.target;a.className=a.className.replace(/\s?wf2_invalid/,"");$wf2.invalidIndicators.shift()}},cloneNode_customAttrs:{type:1,template:1,repeat:1,"repeat-template":1,"repeat-min":1,"repeat-max":1,"repeat-start":1,value:1,"class":1,required:1,pattern:1,form:1,autocomplete:1,autofocus:1,inputmode:1,max:1, min:1,step:1,onmoved:1,onadded:1,onremoved:1,onadd:1,onremove:1,onmove:1},cloneNode_skippedAttrs:{name:1,"class":1,"for":1,style:1,checked:1,addRepetitionBlock:1,addRepetitionBlockByIndex:1,moveRepetitionBlock:1,removeRepetitionBlock:1,repetitionBlocks:1,setCustomValidity:1,checkValidity:1,validity:1,validationMessage:1,willValidate:1,wf2StepDatum:1,wf2Value:1,wf2Initialized:1,wf2ValueLength:1},cloneNode_rtEventHandlerAttrs:{onmoved:1,onadded:1,onremoved:1,onadd:1,onremove:1,onmove:1},cloneNode:function(a, b,c){c||(c=0);var d,e,f;switch(a.nodeType){case 1:var g=a.getAttribute("repeat")=="template";g&&c++;d=[];if(a.name)d.name=b?b(a.name):a.name;if(a.type=="radio")d.type=a.type;if(a.checked)d.checked="checked";d=$wf2.createElement(a.nodeName,d);for(e=0;f=a.attributes[e];e++)if((f.specified||$wf2.cloneNode_customAttrs[f.name])&&!$wf2.cloneNode_skippedAttrs[f.name]&&(!g||c>1||!$wf2.cloneNode_rtEventHandlerAttrs[f.name]))if(c<2&&f.name.indexOf("on")===0&&typeof a[f.name]=="function"){var k=b(a[f.name].toString().match(/{((?:.|\n)+)}/)[1]); k=b(k);d[f.name]=new Function("event",k)}else{k=a.getAttribute(f.name);k=b?b(k):k;d.setAttribute(f.name,k)}if(a.className){g=b?b(a.className):a.className;if(d.getAttributeNode("class"))for(e=0;e');if(a.tagName.toLowerCase()!="div"||a.name!="foo")throw"create element error";return function(c,d){var e="<"+c,f;for(f in d)e+=" "+f+'="'+d[f]+'"';e+=">";if(c.toLowerCase()!="input")e+=""+c+">";return document.createElement(e)}}catch(b){return function(c,d){var e=document.createElement(c),f;for(f in d)e.setAttribute(f,d[f]);return e}}}(),sortNodes:function(){var a=document.documentElement.firstChild;if(a.sourceIndex)return function(b,c){return b.sourceIndex- c.sourceIndex};else if(a.compareDocumentPosition)return function(b,c){return 3-(b.compareDocumentPosition(c)&6)}}(),createLI:function(a){var b=document.createElement("li");b.appendChild(document.createTextNode(a));return b},ISO8601RegExp:/^(?:(\d\d\d\d)-(W(0[1-9]|[1-4]\d|5[0-2])|(0\d|1[0-2])(-(0\d|[1-2]\d|3[0-1])(T(0\d|1\d|2[0-4]):([0-5]\d)(:([0-5]\d)(\.(\d+))?)?(Z)?)?)?)|(0\d|1\d|2[0-4]):([0-5]\d)(:([0-5]\d)(\.(\d+))?)?)$/,parseISO8601:function(a,b){var c=$wf2.validateDateTimeType(a,b);if(!c)return null; var d=new Date(0),e=8;if(c[15]){if(b&&b!="time")return null;e=15}else{d.setUTCFullYear(c[1]);if(c[3]){if(b&&b!="week")return null;d.setUTCDate(d.getUTCDate()+(8-d.getUTCDay())%7+(c[3]-1)*7);return d}else{d.setUTCMonth(c[4]-1);c[6]&&d.setUTCDate(c[6])}}c[e+0]&&d.setUTCHours(c[e+0]);c[e+1]&&d.setUTCMinutes(c[e+1]);c[e+2]&&d.setUTCSeconds(c[e+3]);c[e+4]&&d.setUTCMilliseconds(Math.round(Number(c[e+4])*1E3));c[4]&&c[e+0]&&!c[e+6]&&d.setUTCMinutes(d.getUTCMinutes()+d.getTimezoneOffset());return d},validateDateTimeType:function(a, b){var c=false,d=$wf2.ISO8601RegExp.exec(a);if(!d||!b)return d;b=b.toLowerCase();if(b=="week")c=d[2].toString().indexOf("W")===0;else if(b=="time")c=!!d[15];else if(b=="month")c=!d[5];else if(d[6])if((new Date(d[1],d[4]-1,d[6])).getMonth()!=d[4]-1)c=false;else switch(b){case "date":c=d[4]&&!d[7];break;case "datetime":c=!!d[14];break;case "datetime-local":c=d[7]&&!d[14]}return c?d:null},zeroPad:function(a,b){b||(b=2);for(var c=a.toString();c.length<\/script>");document.write("