var BP = {
    urls: new Object(),

    submitForm: function( formName )
    {
        document.forms[ formName ].submit();
    },

    resetForm: function( formName )
    {
        document.forms[ formName ].reset();
    },

    updateCartCounter: function()
    {
        //console.debug("BP.updateCartCounter()");

        dojo.xhrGet({
            url: BP.urls.shoppingCartSize,
            handleAs: "json",
            timeout:5000,
            headers: { 'X-Requested-With': 'XMLHttpRequest' },
            load: function( response, ioArgs )
            {
                dojo.byId("cartCounter").innerHTML = response.cartSize + (response.cartSize == 1 ? "&nbsp;item" : "&nbsp;items");
                return response;
            },
            error: function( response, ioArgs )
            {
                BP.handleAjaxError("Error updating shopping cart size.", ioArgs);
                return response;
            }
        });
    },

    redirect: function( url )
    {
        document.location.href = url;
    },

    reloadPage: function()
    {
        history.go(0);
    },

    handleAjaxError: function( error, ioArgs )
    {
        console.error("BP.handleAjaxError(): " + error + ". [" + ioArgs.xhr.status + "]");
        var dialog = new BellaDialog();
        dialog.showInfoDialog("Error", error, "Close");
    },

    addDirtyTracking: function( formName )
    {
        var theForm = dojo.byId(formName);
        theForm.dirty = false;

        dojo.connect(theForm, "onchange", function()
        {
            theForm.dirty = true;
        });

        dojo.connect(theForm, "onsubmit", function()
        {
            theForm.dirty = false;
        });
    },

    warnIfDirty: function( formName, message )
    {
        if ( dojo.byId(formName).dirty )
        {
            return message;
        }
        return null;
    }

}