/*
 * Copyright (C) 2004 Stephen Ostermiller
 * http://ostermiller.org/contact.pl?regarding=Bookmarklets
 *
 * This bookmarklet is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This bookmarklet is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

/**
 * Allow the web browser to remember passwords, even when the site has password storage disabled.
 *
 * Traverses all frames on the current page searching for forms and password boxes.
 * If the form or password box has an "autocomplete=off" setting, it turns autocomplete
 * back on, allowing the web browser to remember the passwords.
 *
 * @name Remember Passwords
 *
 * @substitute form_element_autocomplete_count a
 * @substitute form_autocomplete_count         b
 * @substitute form_count                      c
 * @substitute current_element                 d
 * @substitute current_frame                   e
 * @substitute frame_index                     f
 * @substitute document_forms                  g
 * @substitute form_index                      h
 * @substitute current_form                    i
 * @substitute element_index                   j
 * @substitute caught_exception                k
 *
 * @compatible Firefox
 * @compatible Netscape
 * @notapplicable Internet Explorer
 * @notapplicable Opera
 * @compatible Mozilla
 * @notapplicable Konqueror
 * @notapplicable Safari
 *
 * @category Password
 * @category Utilities
 *
 * @keyword remember passwords bookmarklet
 * @keyword save passwords bookmarklet
 * @keyword store passwords bookmarklet
 * @keyword password saving bookmarklet
 */
 void(
    (function(){
        var form_element_autocomplete_count,form_autocomplete_count,form_count,current_element;
        form_autocomplete_count=form_element_autocomplete_count=form_count=0;
        (function(current_frame){
            var frame_index,document_forms,form_index,current_form,element_index;
            // For each frame in the current document
            for(frame_index=0;frame_index<current_frame.length;frame_index++){
                try{
                    arguments.callee(current_frame.frames[frame_index]); // Recurse frame
                }catch(caught_exception){}
            }
            document_forms=current_frame.document.forms;
            // For each form in the document
            for(form_index=0;form_index<document_forms.length;form_index++){
                current_form=document_forms[form_index];
                form_count++;
                if(current_form.attributes["autocomplete"]){
                    current_form.attributes["autocomplete"].value="on";
                    form_autocomplete_count++;
                }
                // For each element in the form
                for(element_index=0;element_index<current_form.length;element_index++){
                    current_element=current_form[element_index];
                    if(current_element.attributes["autocomplete"]){
                        current_element.attributes["autocomplete"].value="on";
                        form_element_autocomplete_count++;
                    }
                }
            }
        })(top); // Start with the top level frame
        // Print statistics
        alert("Removed autocomplete prevention\nfrom "+form_autocomplete_count+" forms, "+form_element_autocomplete_count+" form elements\nout of "+form_count+" possible forms.");
    })()
)