function updatePrices(){
	
	var elem = document.getElementById('attributevalue_1');
	if(!elem){	
		return;
	}
	
	var selectedValue = elem.options[elem.selectedIndex].value;
	if(typeof(products[selectedValue])=='undefined'){	
		return;
	}
	
	var elSel = document.getElementById('attributevalue_2');
	var elSelValue = elSel.options[elSel.selectedIndex].value;
	
	removeOptions();
	
	
	for(var i in products[selectedValue]){
  		
  		// this means its out of stock
  		// should we put this in the out of stock function?
  		// or combine the two function?
  	
        if(products[selectedValue][i]=='0'){
        	continue;
        }
		var element = document.createElement('option');
		element.value = i;
		
		
		if(i==elSelValue){
			
			element.selected = true;
		}
		var attributeValues = i.split('/');
		
		attributeValues[attributeValues.length-1] = '$'+parseFloat(attributeValues[attributeValues.length-1]).toFixed(2);
		
		element.text = attributeValues.join(' / ');
		try{
			elSel.add(element,null);
		}catch(e){
			elSel.add(element); // IE only
		}
		
	}
	
	
	removeOutOfStockOptions();
	document.getElementById('outOfStockDiv').innerHTML = 'Item is unavailable in '+selectedValue;
	if(elSel.options.length == 0){
	
		var element = document.createElement('option');
		element.value = '--';
		element.text = 'Out Of Stock';
		try{
			elSel.add(element,null);
		}catch(e){
			elSel.add(element); // IE only
		}
		
		document.getElementById('addToCartBtn').disabled = true;
		document.getElementById('addToCartBtn').style.display = 'none';
		document.getElementById('outOfStockDiv').style.display = '';
	
		
	}else{
		document.getElementById('addToCartBtn').disabled = false;
		document.getElementById('addToCartBtn').style.display = '';
		document.getElementById('outOfStockDiv').style.display = 'none';
		
	
	}

}

function removeOutOfStockOptions(){
    
	var elSel = document.getElementById('attributevalue_2');
	if(!elSel){
		return;
	}
	var re = /(do not)|(out of)|(no) stock/i;
	for (var i = elSel.length - 1; i>=0; i--) {
		
		if(re.test(elSel[i].value)){
				elSel.remove(i);	
				continue;
		}
	
		var attributeValues = elSel[i].value.split('/');
		attributeValues[attributeValues.length-1] = attributeValues[attributeValues.length-1].replace('$','');
		
		
		if(parseFloat(attributeValues[attributeValues.length-1])<=0){
			
			elSel.remove(i);	
			continue;
		}
		
		

	}

}


function removeOptions(){
	var elSel = document.getElementById('attributevalue_2');
	for (var i = elSel.length - 1; i>=0; i--) {
		elSel.remove(i);

	}
}

function addProduct(color,size,available){

	
	if(typeof(products[color])=='undefined'){	
		products[color] = new Array();
	
	}
	
	products[color][size] = available;
	
}
	     
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}
