﻿/// <reference path="jquery-1.3.2-vsdoc.js" />

(function($) {

    $.pagePost = function(values, page) {
        ///<summary> posts a form containing the given values </summary>
        /// <param name="values">json object with key value pairs to be submitted</param>
        /// <param name="page">page to submit to, defautls to current page</param>

        //create a new form to house the values
        var formString = '<form method="post"';
        if (page) {
            formString += ('action=' + page);
        }
        formString += '>'

        //insert the input elements into the form
        for (var key in values) {
            formString += '<input type="hidden" name="' + key + '" value="' + values[key] + '" />';
        }

        formString += '</form>';

        //add the form to the page and submit
        $(formString).appendTo('body').submit();
    };


    $(document).ready(function() {
        //any link with the class submit-link will submit the form its in 
        //and will submit it to the href defined in the link
        $('a.submit-link').click(function(event) {
            event.preventDefault();
            var href = $(this).attr('href')
            $(this).parents('form').attr('action', href).submit();
        });
    });
    


})(jQuery)


