
var SP_Data = function() { 
	this.callback=null; 
	this.callbackObj=null;
	this.data = null;
	this.productImages = [];
}
SP_Data.prototype = {
	setCallbacks:function(callback, callbackObj){ this.callback = callback; this.callbackObj = callbackObj; },
	execCallback:function(){			
		if(this.callback != null){
			if(this.callbackObj != null){this.callback.call(this.callbackObj, this);} 
			else{this.callback(this);}
		}
	},	
	populate:function(obj){					
		if(obj){ 
			this.data = obj; 						
			if( this.data.products != null && this.data.products.SPProduct != null)
				this.loadAssociativeImages( this.data.products.SPProduct);
		}
		this.execCallback();
	},
	loadAssociativeImages:function(products){				
		if(products != null){
			for(var i=0;i<products.length;i++){
				var product = products[i];								
				if( product.childProducts != null && product.childProducts.SPProduct != null){ 							
					this.loadAssociativeImages(product.childProducts.SPProduct); 
				}							
				if( product.images != null && product.images.SPImage != null){
					var imgs = product.images.SPImage;
					var a_prodImgs = this.productImages[product.productId];
					for(var j=0;j<imgs.length;j++){						
						if( a_prodImgs == null ){ a_prodImgs = [];}
						var img = imgs[j];						
						a_prodImgs[img.key] = img.url;						
					}
					this.productImages[product.productId] = a_prodImgs;
				}				
			}
		}		
	},
	ajaxError:function(){alert("We are sorry, an unexpected error has occurred and your request cannot be completed at this time.");}	
};

function SPProductCatalogRequest(){}
SPProductCatalogRequest.prototype.objectType = function(){ return "SPProductCatalogRequest"; }

function SP_Product (){	this.products = null; }
SP_Product.prototype = new SP_Data;
SP_Product.prototype.getProducts = function (s_catid, a_items, callback, callbackObj){		
	var obj = new SPProductCatalogRequest();
	obj["catalogId"]=s_catid;
	obj["productCodes"]= a_items;	
	this.setCallbacks(callback, callbackObj);	
	defaultGateway.ajaxService(obj, this.populate, this.ajaxError, null, this);	
};

function SPCategoryRequest(){}
SPCategoryRequest.prototype.objectType = function(){ return "SPCategoryRequest"; }

function SP_Category(){ this.categories=null; this.products = null;	}
SP_Category.prototype = new SP_Data; 
SP_Category.prototype.getCategory = function(s_catId, s_parentId, callback, callObj){
	var obj = new SPCategoryRequest();
	obj["categoryId"]=s_catId;
	if( s_parentId != null ){
		obj["parentId"]=s_parentId;
	}
	this.setCallbacks(callback, callObj);
	defaultGateway.ajaxService(obj, this.populate, this.ajaxError, null, this);	
}

function SiteProductionResponse(){}
SiteProductionResponse.prototype.objectType = function(){ return "SiteProductionResponse"; }




