function WatxColorsObject()
{
  this.carCodeAtrrName = "codecart";
  this.defaultValue = "";
  this.currentSphere = this.defaultValue;
  this.currentBracelet = this.defaultValue;
  this.prizeAttrName = "prize";
  this.stockAttrName = "stock";
  this.swarAttrName = "swar";

  //Wrapped function
  this.addToBag = function ()
  {
    
    if ( (this.currentSphere == this.defaultValue) &&
         (this.currentBracelet == this.defaultValue) )
    {
       this.consoleLog("No items selected");
       return false;
    }
    
    if (this.currentSphere == this.defaultValue)
    {
        addToBagFromCollection(new Array(this.currentBracelet));
        this.consoleLog("Only added Bracelet with value: " + this.currentBracelet + " to the store cart");
        return true;
    }
    
    if(this.currentBracelet == this.defaultValue)
    {
      addToBagFromCollection(new Array(this.currentSphere));
      this.consoleLog("Only added Sphere with value: " + this.currentSphere + " to the store cart");
      return true;
    }
    
    addToBagFromCollection(new Array(this.currentBracelet,this.currentSphere));
    this.consoleLog("Added Bracelet with Value: " + this.currentBracelet + " and Sphere with value: " +this.currentSphere);
    return true;
  }


  this.init = function()
  {
      this.calculatePrize();
      var bracActive = this.getActiveBracelet();
      if ( $(bracActive).length > 0)
      {
        this.consoleLog("INIT bracelet");
        this.setBracelet(bracActive);
      }
      else
      {
        this.consoleLog("Bracelet does not has a init value");
      }
      
      var espActive = this.getActiveSphere();
      if ( $(espActive).length > 0)
      {
        this.consoleLog("INIT esphere");
        this.setSphere(espActive);
      }
      else
      {
        this.consoleLog("Sphere does not has a init value");
      }
  }
  
  this.calculatePrize = function()
  {
      var totalPrize = 0;
	  var hihaStockBra = true;
	  var hihaStockEsf = true;
	  var hihaSwar = false;
      var bracActive = this.getActiveBracelet();
      if ( $(bracActive).length > 0)
      {
          totalPrize = totalPrize + this.getPrizeAttrValue($(bracActive));
		  hihaStockBra = true;
		  if(this.getStockAttrValue($(bracActive)) > 0){
			hihaStockBra = true;
		  }
		  if(this.getSwarAttrValue($(bracActive)) > 0){
			hihaSwar = true;
		  }
          this.consoleLog("Bracelet costs " + totalPrize + "AAAA");
      }
      var espActive = this.getActiveSphere();
      if ( $(espActive).length > 0)
      {
		  var prize = this.getPrizeAttrValue($(espActive));
          totalPrize = totalPrize + prize ;
          hihaStockEsf = false;
		  if(this.getStockAttrValue($(espActive)) > 0){
			hihaStockEsf = true;
		  }
		  if(this.getSwarAttrValue($(espActive)) > 0){
			hihaSwar = true;
		  }
          this.consoleLog("Sphere costs " + prize + "&euro;");
      }
	  
       this.consoleLog("The total costs is " + totalPrize + "&euro;");
       totalPize = totalPrize.toFixed(2).toString();						// Jordi, afegit .toFixed(2)
       
	   if(!hihaStockBra || !hihaStockEsf || (totalPize == 0)){
			$("#pricewatx").html("");
			$("#addToCartBot").hide();
			$("#addToCartOr").hide();
	   }else{
			$("#pricewatx").html("" + totalPize.replace(".",",") + "&euro;");
			$("#addToCartBot").show();
			$("#addToCartOr").show();
	   }
	   
	   if(hihaSwar){
			$(".topo-bisel").show();
	   }else{
			$(".topo-bisel").hide();
	   }
	   
  }

  


  this.setSphere = function(sphereLinkObject)
  {
    if (!this.isDoubleProduct(sphereLinkObject))
    {
        this.currentSphere = this.getCarCodeAttrValue(sphereLinkObject);
        this.consoleLog("Value of Sphere: " +  this.currentSphere);
    }
    else
    {
        this.setBracSphe(sphereLinkObject);
    }
  }

  this.setBracelet = function(braceletLinkObject)
  {
    if (!this.isDoubleProduct(braceletLinkObject))
    {
      this.currentBracelet = this.getCarCodeAttrValue(braceletLinkObject);
      this.consoleLog("Value of Bracelet: " +  this.currentBracelet);
    }
    else
    {
       this.setBracSphe(braceletLinkObject);
    }
  }
  
  this.setBracSphe = function(braceSpheLinkObject)
  {
     var codesObjectsCart = this.getCarCodeAttrValue(braceSpheLinkObject);
     var separatorNumber = codesObjectsCart.indexOf(",");
     this.currentBracelet = codesObjectsCart.substr(0,separatorNumber);
     this.currentSphere = codesObjectsCart.substr(separatorNumber+1,codesObjectsCart.length);
     this.consoleLog("Value of Bracelet: " +  this.currentBracelet);
     this.consoleLog("Value of Sphere: " +  this.currentSphere);
  }
  
 
  this.getActiveBracelet = function ()
  {
    return $('ul.initPul').find('a.activo');
  }
  
   this.getActiveSphere = function ()
  {
    return $('ul.initEsf').find('a.activo');
  }
  
  this.isDoubleProduct = function (linkObject)
  {
      var codeCart = this.getCarCodeAttrValue(linkObject);
      if (codeCart.indexOf(",") == -1)
      {
        return false;
      }
      return true;
  }
  
  this.getPrizeAttrValue = function (linkObject)
  {
    return parseFloat(linkObject.attr(this.prizeAttrName).replace(",","."));
  }
  
  this.getStockAttrValue = function (linkObject)
  {
    return parseFloat(linkObject.attr(this.stockAttrName));
  }
  
  this.getSwarAttrValue = function (linkObject)
  {
    return parseFloat(linkObject.attr(this.swarAttrName));
  }
  
  this.getCarCodeAttrValue = function (linkObject)
  {
    return linkObject.attr(this.getCarCodeAttrName());
  }
  
  this.getCarCodeAttrName = function()
  {
    return this.carCodeAtrrName;
  }
  
  this.getDefaultValue = function ()
  {
    return this.defaultValue;
  }
  
  this.consoleLog = function(mesg)
  {
    //if (console != undefined)
    //{
    //  if (typeof (console.log) == "function")
    //  {
    //    console.log(mesg);
    //  }
    //}
  }

}
