var form2js=(function(){"use strict";function form2js(a,b,c,d,e){if(typeof c=='undefined'||c==null)c=true;if(typeof b=='undefined'||b==null)b='.';if(arguments.length<5)e=false;a=typeof a=='string'?document.getElementById(a):a;var f=[],currNode,i=0;if(a.constructor==Array||(typeof NodeList!="undefined"&&a.constructor==NodeList)){while(currNode=a[i++]){f=f.concat(getFormValues(currNode,d,e))}}else{f=getFormValues(a,d,e)}return processNameValues(f,c,b)}function processNameValues(a,b,c){var d={},arrays={},i,j,k,l,value,nameParts,currResult,arrNameFull,arrName,arrIdx,namePart,name,_nameParts;for(i=0;i<a.length;i++){value=a[i].value;if(b&&(value===''||value===null))continue;name=a[i].name;_nameParts=name.split(c);nameParts=[];currResult=d;arrNameFull='';for(j=0;j<_nameParts.length;j++){namePart=_nameParts[j].split('][');if(namePart.length>1){for(k=0;k<namePart.length;k++){if(k==0){namePart[k]=namePart[k]+']'}else if(k==namePart.length-1){namePart[k]='['+namePart[k]}else{namePart[k]='['+namePart[k]+']'}arrIdx=namePart[k].match(/([a-z_]+)?\[([a-z_][a-z0-9_]+?)\]/i);if(arrIdx){for(l=1;l<arrIdx.length;l++){if(arrIdx[l])nameParts.push(arrIdx[l])}}else{nameParts.push(namePart[k])}}}else nameParts=nameParts.concat(namePart)}for(j=0;j<nameParts.length;j++){namePart=nameParts[j];if(namePart.indexOf('[]')>-1&&j==nameParts.length-1){arrName=namePart.substr(0,namePart.indexOf('['));arrNameFull+=arrName;if(!currResult[arrName])currResult[arrName]=[];currResult[arrName].push(value)}else if(namePart.indexOf('[')>-1){arrName=namePart.substr(0,namePart.indexOf('['));arrIdx=namePart.replace(/(^([a-z_]+)?\[)|(\]$)/gi,'');arrNameFull+='_'+arrName+'_'+arrIdx;if(!arrays[arrNameFull])arrays[arrNameFull]={};if(arrName!=''&&!currResult[arrName])currResult[arrName]=[];if(j==nameParts.length-1){if(arrName==''){currResult.push(value);arrays[arrNameFull][arrIdx]=currResult[currResult.length-1]}else{currResult[arrName].push(value);arrays[arrNameFull][arrIdx]=currResult[arrName][currResult[arrName].length-1]}}else{if(!arrays[arrNameFull][arrIdx]){if((/^[a-z_]+\[?/i).test(nameParts[j+1]))currResult[arrName].push({});else currResult[arrName].push([]);arrays[arrNameFull][arrIdx]=currResult[arrName][currResult[arrName].length-1]}}currResult=arrays[arrNameFull][arrIdx]}else{arrNameFull+=namePart;if(j<nameParts.length-1){if(!currResult[namePart])currResult[namePart]={};currResult=currResult[namePart]}else{currResult[namePart]=value}}}}return d}function getFormValues(a,b,c){var d=extractNodeValues(a,b,c);return d.length>0?d:getSubFormValues(a,b,c)}function getSubFormValues(a,b,c){var d=[],currentNode=a.firstChild;while(currentNode){d=d.concat(extractNodeValues(currentNode,b,c));currentNode=currentNode.nextSibling}return d}function extractNodeValues(a,b,c){var d,fieldValue,result,fieldName=getFieldName(a,c);d=b&&b(a);if(d&&d.name){result=[d]}else if(fieldName!=''&&a.nodeName.match(/INPUT|TEXTAREA/i)){fieldValue=getFieldValue(a);result=[{name:fieldName,value:fieldValue}]}else if(fieldName!=''&&a.nodeName.match(/SELECT/i)){fieldValue=getFieldValue(a);result=[{name:fieldName.replace(/\[\]$/,''),value:fieldValue}]}else{result=getSubFormValues(a,b,c)}return result}function getFieldName(a,b){if(a.name&&a.name!='')return a.name;else if(b&&a.id&&a.id!='')return a.id;else return''}function getFieldValue(a){if(a.disabled)return null;switch(a.nodeName){case'INPUT':case'TEXTAREA':switch(a.type.toLowerCase()){case'radio':case'checkbox':if(a.checked&&a.value==="true")return true;if(!a.checked&&a.value==="true")return false;if(a.checked)return a.value;break;case'button':case'reset':case'submit':case'image':return'';break;default:return a.value;break}break;case'SELECT':return getSelectedOptionValue(a);break;default:break}return null}function getSelectedOptionValue(a){var b=a.multiple,result=[],options,i,l;if(!b)return a.value;for(options=a.getElementsByTagName("option"),i=0,l=options.length;i<l;i++){if(options[i].selected)result.push(options[i].value)}return result}return form2js})();