/*******************************************************************************
 ShowPasswordCheckbox.js      Adds a "show password" toggle to a password field
 ------------------------------------------------------------------------------
 Adapted from                               FormTools.addShowPasswordCheckboxes
 Info/Docs         http://www.brothercake.com/site/resources/scripts/formtools/
 ------------------------------------------------------------------------------
*******************************************************************************/


function ShowPasswordCheckbox(a){if(typeof document.getElementById=="undefined"||typeof document.styleSheets=="undefined")return false;if(a==null)return false;a._contextwrapper=this.createContextWrapper(a);var b=a._contextwrapper,d=this.convertPasswordFieldHTML(a);a=Math.round(Math.random()*1E3);var f='<label for="showpasscheckbox-'+a+'" class="show-password" title="Show the password as plain text (not advisable in a public place)" style="display:inline-block;position:static;">';f+='<input type="checkbox" id="showpasscheckbox-'+
a+'" title="Show the password as plain text (not advisable in a public place)">';f+='<span style="display:inline-block;" class="small">Show Password</span>';f+="</label>";b.innerHTML+=d+f;d=b.lastChild.previousSibling;f=b.lastChild.firstChild;a=b.firstChild;a._plainfield=d;d._passwordfield=a;f._passwordfield=a;f._plainfield=d;a._contextwrapper=b;var g=this;this.addListener(a,"change",function(c){c=g.getTarget(c);c._plainfield.value=c.value});this.addListener(d,"change",function(c){c=g.getTarget(c);
c._passwordfield.value=c.value});this.addListener(f,"click",function(c){var e=g.getTarget(c);c=e.checked?e._plainfield:e._passwordfield;e=e.checked?e._passwordfield:e._plainfield;c.value=e.value;c.style.display="inline";e.style.display="none"});if(b=this.getParentForm(a)){b._plainfield=d;b._passwordfield=a;this.addListener(b,"submit",function(c){c=g.getTarget(c);if(c._plainfield.style.display=="block")c._passwordfield.value=c._plainfield.value})}return true}
ShowPasswordCheckbox.prototype={createContextWrapper:function(a){var b=document.createElement("span");b.style.position="relative";a.parentNode.insertBefore(b,a);b.appendChild(a);return b},getParentForm:function(a){for(;a;){if(/form/i.test(a.nodeName))break;a=a.parentNode}if(!/form/i.test(a.nodeName))return null;return a},convertPasswordFieldHTML:function(a){var b="<input";a=a.attributes;for(var d=0;d<a.length;d++)if(a[d].specified&&!/^(_|type|name)/.test(a[d].name))b+=" "+a[d].name+'="'+a[d].value+
'"';b+=' type="text" style="display:none" autocomplete="off">';return b},addListener:function(a,b,d){if(typeof document.addEventListener!="undefined")return a.addEventListener(b,d,false);else if(typeof document.attachEvent!="undefined")return a.attachEvent("on"+b,d)},getTarget:function(a){if(!a)return null;return a.target?a.target:a.srcElement}};
