var SC_Item = function (id)
{
  // initialize the member variables for this instance
  this.id = id;
  this.attributes = new Array();
  this.toStringAttrib = "";
  
  // initialize the member function references 
  // for the class prototype
  _SC_Item_prototype_called = true;
  SC_Item.prototype.getId = getId;
  SC_Item.prototype.setId = setId;
  SC_Item.prototype.getAllAttributes = getAllAttributes;
  SC_Item.prototype.setAllAttributes = setAllAttributes;
  SC_Item.prototype.getAttributeByName = getAttributeByName;
  SC_Item.prototype.getNumericAttributeValueByName = getNumericAttributeValueByName;
  SC_Item.prototype.extractNumbers = extractNumbers;
  SC_Item.prototype.addAttribute = addAttribute;
  SC_Item.prototype.delAttribute = delAttribute;
  SC_Item.prototype.extractLeftCeros = extractLeftCeros;


  // define a Item's method ID
  function getId()
  {
     return this.id;
  }
  function setId(value)
  {
     this.id = value;
  }
  //------------------------
  
  // define a Item's method ATTRIBUTES
  function getAllAttributes()
  {
     return this.attributes;
  }
  function setAllAttributes(value)
  {
     this.attributes = value;
  }
  //------------------------
  
  // define a Item's method ATTRIBUTES BY ID
  function getAttributeByName(name)
  {
     for (var i = 0; i<this.attributes.length;i++){
     	var attrib = this.attributes[i];
     	if (attrib.getName() == name) {
     		return attrib; 		
     	}
     }
  }
  //------------------------
  
  function getNumericAttributeValueByName(name){
  	 for (var i = 0; i<this.attributes.length;i++){
     	var attrib = this.attributes[i];
     	if (attrib.getName() == name) {
     		return this.extractNumbers(attrib.getValue()); 		
     	}
     }
  }
  
  function extractNumbers(str){
  	var str2 = "";
  	var strNumber = 0;
  	for ( var i=0; i<str.length; i++){
		var strNumber = str.charAt(i);
		if( IsNumeric(strNumber)){
			str2 += strNumber;
		}
  	}
  	if ( navigator.appVersion.indexOf("Safari") != -1){
  		var str3 = extractLeftCeros(str2);
  		if ( itemctrl.reportMsgs == true ) alert(str3);
		return parseFloat(str3);	
	}else{
		return parseFloat(str2);
	}
  }
  
  function extractLeftCeros(str){
  	var retStr = "";
  	var numFound = false;
	for (var i=0;i<str.length;i++){
		if ( str.charAt(i) != "0" ) numFound = true; 
		if ( str.charAt(i) != "0" || numFound != false){
			retStr += str[i]		
		}
	}
	return retStr;
  }
  
  function IsNumeric(sChar)
  {
	var ValidChars = "0123456789.";
	var IsNumber=true;
	if (ValidChars.indexOf(sChar) == -1) 
	{
		return false;
	}
	return true;
  }

  // define a Item's method ADD ATTRIBUTES
  // if the attribute exist it changes the value
  function addAttribute(id, name, value, uniqueValue)
  {
  	var i=0;
  	value = ""+value;
  	if ( name == "Price"){
  		var justPrice = value;
		justPrice = justPrice.split('$')[1]
		while(justPrice.length<9){
			justPrice = "0" + justPrice;
		}
		value = "$"+justPrice;
	}
	value = value.toUpperCase();
    for ( i = 0; i<this.attributes.length;i++){
     	var attrib = this.attributes[i];
     	if (attrib.getName() == name) {
			attrib.setValue(value);
			attrib.setUnique(uniqueValue);
     		return 0; 		
     	}
    }
     var newAttrib = new SC_ItemAttribute(id,name, value, uniqueValue);
     this.attributes[this.attributes.length] = newAttrib;
     return 1;
  }
  //------------------------
  
  //---------DELETE ATTRIBUTE--------------
  function delAttribute(name){
	for (var i = 0; i<this.attributes.length;i++){
     	var attrib = this.attributes[i];
     	if (attrib.getName() == name) {
			this.attributes.splice(i,1);; 		
			return 0;
     	}
    }  	
    return 1;
  }
  //----------------------------------------
  
  function toString(){
	return this.attributes[this.toStringAttrib];
  }

}