
var AjaxSCS = {	
	reRender : function(layout, storeId, options) {
		if (typeof jQuery != 'undefined') {
			$.ajax({
				url: '/Magellan/pages/ajax/reRenderHelper.jsp',
				type: 'POST',
				data: ({
						layoutPath: layout,
						storeId: storeId
					}),
				dataType: 'json',
				success: function(response) {
					if (response.result == 'SUCCESS') {
						var contentUrl = response.contentUrl;
						var targetDiv = response.targetDiv;
						$.ajax({
							url: contentUrl,
							type: 'POST',
							success: function(response) {
								$('#'+targetDiv).html(response);
							}
						});
					}
				}
			});
		} else {
			var options = Object.extend({
				evalScripts : true,
				parameters : {},
				onFailure : null,
				onSuccess : null
			}, options || {});
			
			var func = function(targetDiv, contentUrl) {
				new Ajax.Request(contentUrl, {
					method: 'post',
					parameters: options.parameters,
					onFailure: function(response) {
						if (options.onFailure) options.onFailure();
					},
					onSuccess: function(response) {
						$(targetDiv).innerHTML = response.responseText;
						if (options.evalScripts) response.responseText.evalScripts();
						if (options.onSuccess) options.onSuccess(response.responseText);
					}
				})};
				
			
			new Ajax.Request('/Magellan/pages/ajax/reRenderHelper.jsp', {
				method: 'post',
				parameters: {
					layoutPath: layout,
					storeId: storeId
				},
				onFailure: function(response) {
					if (options.onFailure) options.onFailure();
				},
				onSuccess: function(response) {
					var res = response.responseJSON;				
					if (res.result == "SUCCESS") {
						func(res.targetDiv, res.contentUrl);
					} else {
						if (options.onFailure) options.onFailure();
					}
				}
			});
		}
	},
	
	login : function() {
	
	},
	
	verifyCoupon : function() {
		
	},
	
	subscribe : function() {
	
	},
	
	//
	// Gets an array of suggestions from server matching input string 'str'.
	// Function 'callback' with the array of suggestions as parameter will be
	// called after a successful request.
	//
	autocomplete : function(str, type, storeId, callback) {
		new Ajax.Request('/Magellan/pages/ajax/autoCompleteJSON.jsp', {
			method: 'post',
			parameters: {
				prefix: encodeURIComponent(str),
				type: type,
				storeId: storeId
			},
			onSuccess: function(response) {
				callback(response.responseJSON.texts);
			}
		});
	}
};