if (typeof(eAttrChoiceObject) == 'undefined') 
{
    eAttrChoiceObject = function(ajaxEventVar, ajaxEventUID)
    {
    	this.ajaxEventVar = ajaxEventVar;
    	this.ajaxEventUID = ajaxEventUID;
    	
	    this.loader = new eAJAXLoaderObject();
	    
	    this.id = 'attr_choice';
	    
	    this.submitHandler = '#attr_choice_submit';
	    this.cancelHandler = '#attr_choice_cancel';
	    
        this.container = '<div id="' + this.id +'" style="">{{content}}</div>';
        
    	this.cartManager = new eCartManagerObject(ajaxEventVar, ajaxEventUID);  
    }
}
eAttrChoiceObject.prototype.getAttributes = function()
{
        loaderId = 'ajax_message';
        $('body').append('<div id="' + loaderId +'" style="font-weight: bold; background: #FFF; color: #4C84BD; border: 1px solid #4C84BD; padding: 25px;">Your product has been added to the cart. You may continue shopping.</div>');
        $('#' + loaderId).center();
	
	var currentObject = this;
		
	var postData = { __callHandler: 'getAttributes', 
	  		         productId: this.productId
	}; 
	postData[this.ajaxEventVar] = this.ajaxEventUID;
	
	$.post(selfUrl, postData,	
	function(responseData) { 
  		currentObject.onGetAttributesResponse(responseData); 
	},
	'json');    

        setTimeout("$('#"+loaderId+"').remove();", 3000);
}
eAttrChoiceObject.prototype.setProductID = function(id)
{
    this.productId = id;
}
eAttrChoiceObject.prototype.setQuantity = function(quantity)
{
    this.quantity = quantity;
}
eAttrChoiceObject.prototype.show = function(content)
{
    var currentObject = this;
    
    $('body').append(this.container.replace(/\{\{content\}\}/g, content));
    $('#' + this.id).center();
    
    $(this.submitHandler).bind('click', function() {
        currentObject.addToCart();
    });    
    
    $(this.cancelHandler).bind('click', function() {
        currentObject.hide();
    });    
}
eAttrChoiceObject.prototype.hide = function()
{
    $('#' + this.id).remove();    
}
eAttrChoiceObject.prototype.setInfoPanel = function(infoPanelObject)
{
	this.cartManager.setInfoPanel(infoPanelObject);
}
eAttrChoiceObject.prototype.addToCart = function()
{
   var attribute = {};
   for (i in this.attributes)
   {
       attribute[this.attributes[i]] =  $('#attr' + this.attributes[i]).val();
   }
   this.hide();
   this.cartManager.addItem(this.productId, this.quantity, attribute);
}
eAttrChoiceObject.prototype.onGetAttributesResponse = function(responseData)
{
	this.loader.hide();
	
    if ((typeof(showAJAXDebugInfo) != 'undefined') && responseData.PHPAJAXDebug != null) 
    {
        showAJAXDebugInfo(responseData.PHPAJAXDebug.Info, responseData.PHPAJAXDebug.Owner);
    }
	
	if (responseData.Response.Code != 0)
	{
        this.attributes = responseData.Response.Attributes;
        this.show(responseData.Response.Message);
	}
	else
	{
	    this.cartManager.addItem(this.productId, this.quantity, {});
	}
}
