
var shopFront = Class.create();

shopFront.prototype = {
	
	
	initialize: function( numberAttributes, xml ) {	
		
		this.numberAttributes = numberAttributes;
		
		this.xml = xml;
		
		this.xmlTree = new Object;
		
		this.selectedAttributes = new Array;
		
		this.in_stock = 0;
		
		this.price = 0;
		
		this.id = 0;
		
		this.processXML();
		
	},
	
	
	processXML: function() {	
		
		if( this.xml ) {
			
			var xotree = new XML.ObjTree();
				
			this.xmlTree = xotree.parseXML( this.xml );
						
		}
		
	},
	
	
	setAttribute: function( number, value ) {	
		
		this.selectedAttributes[ number ] = value;
		
	},
	
	
	
	validateSelections: function() {	
		
		var found = false;
		if( (this.selectedAttributes.length -1 ) == this.numberAttributes ) {

			if( !this.xmlTree.attributes.attribute.length ) {
				
				if( this.xmlTree.attributes.attribute.attrib_1 == this.selectedAttributes[1] && this.xmlTree.attributes.attribute.attrib_2 == this.selectedAttributes[2] ) {

					this.in_stock = this.xmlTree.attributes.attribute.attrib_stock;
					
					this.price = this.xmlTree.attributes.attribute.attrib_price;
					
					this.id = this.xmlTree.attributes.attribute.attrib_id;
					
					found = true;
					
				}
				
			} else {

				for( i=0; i<this.xmlTree.attributes.attribute.length; i++ ) {
					
					if( this.xmlTree.attributes.attribute[i].attrib_1 == this.selectedAttributes[1] && this.xmlTree.attributes.attribute[i].attrib_2 == this.selectedAttributes[2] ) {
						
						this.in_stock = this.xmlTree.attributes.attribute[i].attrib_stock;
						
						this.price = this.xmlTree.attributes.attribute[i].attrib_price;
						
						this.id = this.xmlTree.attributes.attribute[i].attrib_id;
						
						found = true;
						
					}
					
				}
			
			}
			
			//if( found == false ) alert( 'ERROR: Product Attributes not found');
			
		}
		
		return found;
		
	},
	
	
	removeChildren: function( element ) {	
	
		if( element.hasChildNodes() ) {
				
			numberOfChildren = element.childNodes.length

			for( var i=0; i<numberOfChildren; i++ )
					element.removeChild( element.childNodes[0] );
			
		}
		
	}
	
	
	
};


