/* * This notice must be untouched at all times. * * visibleIf.js - a cross browser form field manager that hides and shows * form fields depending on the values of other form fields. * * Version 1.0 released Feb 21, 2009 * Version 2.0 (this release) released June 20, 2010. Features new * rules engine originally developed for HTML5Widgets.js and HTML5 custom * data- attribute support. * * Written by: Zoltan Hawryluk. * * Latest release available at http://www.useragentman.com/ * * released under the MIT License: * http://www.opensource.org/licenses/mit-license.php */ var visibleIf=new function(){var me=this;var formInputCache=new Array();var changedInput=null;var visibleIfNodes;var mandatoryNodes;var varRe=/\s([a-zA-Z][a-zA-Z0-9\.]*)\s/g;var operatorRe=/\s*(~|!=|==|>={0,1}|<={0,1})\s*/g;var leftBkRe=/\(/g;var rightBkRe=/\)/g;var reRe=/~ \"([^\"]*)\"/g;var equalsRe=/ == /g;var quotedStringRe=/"[^"]*"/g;var quotedStringOneOnlyRe=/"[^"]*"/;var placeHolderString='_pLaCeHoLdEr_';var placeHolderRe=new RegExp(placeHolderString);var nodesWithEventsAttached=new Array();var inputsToClear;var req=null;var nameCounter=0;var CSSHelpers,StringHelpers,XMLHelpers,DOMHelpers;me.init=function(reset){if(EventHelpers.hasPageLoadHappened(arguments)&&!reset){return}visibleIfNodes=CSSHelpers.getElementsByClassName(document,'visibleIf');mandatoryNodes=CSSHelpers.getElementsByClassName(document,'mandatoryIf');removeDisabledNodes();me.refreshPage({isPageLoad:true});setMandatoryStates();setEvents()}function removeDisabledNodes(){for(var i=0;i0){var url=DOMHelpers.getDatasetItem(document.body,'visibleif-deletedataurl');if(url){req=XMLHelpers.getXMLHttpRequest(url,deleteRequestHandler,'GET',qs)}}for(var i=0;i0){var fieldNode=parentForm[inputVars[j]];if(fieldNode!=null){if(fieldNode.nodeName!="SELECT"&&fieldNode.length){for(var k=0;k')}me.urlencode=function(str){return escape(str).replace('+','%2B').replace('%20','+').replace('*','%2A').replace('/','%2F').replace('@','%40')}}}if(window.XMLHelpers){XMLHelpers=window.XMLHelpers}else{XMLHelpers=new function(){var me=this;me.getOuterXML=function(node,options){var r;if(node.xml){r=node.xml}else if(node.outerHTML){r=node.outerHTML}else if(window.XMLSerializer){var serializer=new XMLSerializer();var text=serializer.serializeToString(node);r=text}else{return null}if(options){if(options.insertClosingTags){r=r.replace(selfClosingTagRe,"<$1>")}}return r}me.getXMLHttpRequest=function(url,processReqChange){var argv=me.getXMLHttpRequest.arguments;var argc=me.getXMLHttpRequest.arguments.length;var httpMethod=(argc>2)?argv[2]:'GET';var data=(argc>3)?argv[3]:"";var isAsync=(argc>4)?argv[4]:true;var req;if(window.XMLHttpRequest){req=new XMLHttpRequest()}else if(window.ActiveXObject){try{req=new ActiveXObject('Msxml2.XMLHTTP')}catch(ex){req=new ActiveXObject("Microsoft.XMLHTTP")}}else{return null}if(isAsync){req.onreadystatechange=processReqChange}if(httpMethod=="GET"&&data!=""){url+="?"+data}req.open(httpMethod,url,isAsync);req.setRequestHeader("If-Modified-Since","Sat, 1 Jan 2000 00:00:00 GMT");req.send(data);return req}}}function StringBuffer(){var me=this;var buffer=[];me.append=function(string){buffer.push(string);return me}me.appendBuffer=function(bufferToAppend){buffer=buffer.concat(bufferToAppend)}me.toString=function(){return buffer.join("")}me.getLength=function(){return buffer.length}me.flush=function(){buffer.length=0}}String.prototype.trim=function(){var str=this;if(this.length>6000){str=this.replace(StringHelpers.initWhitespaceRe,'');var i=str.length;while(StringHelpers.whitespaceRe.test(str.charAt(--i)));return str.slice(0,i+1)}else{return this.replace(StringHelpers.initWhitespaceRe,'').replace(StringHelpers.endWhitespaceRe,'')}}}var formCache=new function(){var me=this;var values=new Array();me.setValue=function(name,value){values[name]=value}me.getValue=function(name){if(values[name]==undefined){return""}else{return values[name]}}}EventHelpers.addPageLoadEvent('visibleIf.init');