// These are AJAX-related client-side functions for the ChangeExchange application.

/*
 * Last Modified on January 26, 2009 by Aaron L Beverly
 */
 
/*
 * This is a generic error function to be invoked when a transport error occurs in an AJAX request/response
 */
 function ajaxError(xmlObj) {
	alert('AJAX Error: ' + xmlObj); 
	/*for(i in xmlObj) {
		alert(i + ': ' + xmlObj[i]); 	
	}*/
 }

/*
 * This is a function to receive the response from a request to adjust the shares in a user's 
 * tentative portfolio
 *
 */
 function portfolioSharesAdjusted(xmlObj) {
	if(xmlObj && xmlObj.responseText) {
		var e = $('portfolio_widget');
		if(e) {
			e.innerHTML = xmlObj.responseText;	
		}
	}
 }
 
/*
 * This is a function to adjust the number of shares in a user's tentative portfolio
 * It makes an AJAX request to update the totals in the user session and then redraws the 
 * portfolio widget on the client
 *
 */
 function adjustPortfolioShares(launcher, amt) {
	 if(launcher && amt) {
		 var e = $('portfolio_widget');
		 if(e) {
			new Ajax.Request('/invest/adjustportfolio/'+escape(launcher)+'/', {
                method: 'get',
                parameters: 'adjustby=' + escape(amt),
                onSuccess: portfolioSharesAdjusted,
                onFailure: ajaxError
            });
		 }
	 }
 }
