YAHOO.namespace("cart");

/**
 * Make the request to the server.  This needs its own response handler so we 
 * can update the shipping total on data load.
 * @param string contentId
 */
YAHOO.cart.makeRequest = function(formObject) {

	args = {
		responseArea:'shippingRatesArea',
		errorMessage:'We are unable to get live shipping rates back at this time.  Please try again later.'
	};

	callback = {
		success:YAHOO.cart.ezHandleSuccess,
		failure:YAHOO.cart.ezHandleFailure,
		argument:args
	};

	sUrl = "cart_rpc.php";
	YAHOO.util.Connect.setForm(formObject);
	request = YAHOO.util.Connect.asyncRequest('POST', sUrl, callback);

} /*function*/


/**
 * Generic asynch response handler.  It will set the specified arg objects
 * argument.responseArea values innerHTML to the responseText.
 * @param object
 * @return void
 * @since 2006.10.13
 */
YAHOO.cart.ezHandleSuccess = function(o) {

    content = o.argument.responseArea;
    contentArea = document.getElementById(content);
    contentArea.innerHTML = o.responseText;
	
	if (document.getElementById('shipping') !== undefined) {
		calcShipping(document.getElementById('shipping'));
	} /*if*/

}; /*function*/


/**
 * This will handle a generic asynch failure.  In the argument object passed
 * to the request you can specify a errorMessage property to define a custom
 * error message.
 * @param object
 * @return void
 * @since 2006.10.13
 */
YAHOO.cart.ezHandleFailure = function(o) {

    content = o.argument.responseArea;
    contentArea = document.getElementById(content);

    if (o.responseText !== undefined) {
        if (o.argument.errorMessage !== undefined) {
            contentArea.innerHTML = o.argument.errorMessage;
        } else {
            contentArea.innerHTML = "There was a problem updating the data.  Please try again.";
        }
    }
}; /*function*/
