/*
 * 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.
 */
 
/**
 * Changes forms to submit using the GET method rather than using POST.
 *
 * Traverses all frames on the current page searching for forms and sets their
 * method to GET.
 * <p>
 * When a form submits via GET, its arguments are visible in the URL bar allowing
 * them to be inspected or the url to be bookmarked.  Many servers are configured
 * to accept parameters through either GET or POST so the functionality may be the
 * same.  There are, however, servers that will only accept POST forms.
 * 
 * @name Forms to GET
 *
 * @substitute forms_changed    a
 * @substitute forms_seen       b
 * @substitute current_frame    c
 * @substitute frame_index      d
 * @substitute document_forms   e
 * @substitute form_index       f
 * @substitute current_form     g 
 * @substitute caught_exception h
 *
 * @compatible Firefox
 * @compatible Netscape
 * @compatible Opera
 * @compatible Mozilla
 * @compatible Konqueror
 * @compatible Internet Explorer
 * @compatible Safari
 *
 * @category Form
 * @category Utilities
 *
 * @keyword form to get bookmarklet
 * @keyword post to get bookmarklet
 * @keyword submit via get bookmarklet
 * @keyword get form submission bookmarklet
 */
void(
    (function(){
        var forms_changed,forms_seen;
        forms_changed=forms_seen=0;
        (function(current_frame){
            var frame_index,document_forms,form_index,current_form;
            // 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];
                if(current_form.method.toLowerCase()=="post"){
                    current_form.method="GET";
                    forms_changed++;
                }
                forms_seen++;
            }
        })(top); // Start with the top level frame
        alert(forms_changed+" of "+forms_seen+" forms changed from POST to GET");
    })()
)
