function convertToName(myArray){
	switch(myArray[0]){
		case "square":
			myArray[0] = "Square";
			break;
		case "circle":
			myArray[0] = "Circle";
	}
	switch(myArray[1]){
		case "highgloss":
			myArray[1] = "High-Gloss";
			break;
		case "semigloss":
			myArray[1] = "Semi-Gloss";
			break;
		case "matte":
			myArray[1] = "Matte Polypropylene";
			break;
	}
	switch(myArray[2]){
		case "small":
			myArray[2] = "Small";
			break;
		case "medium":
			myArray[2] = "Medium";
			break;
		case "large":
			myArray[2] = "Large";
			break;
	}
	switch(myArray[3]){
		case "fullcolor":
			myArray[3] = "Full Color";
			break;
	}
	switch(myArray[4]){
		case "100":
			myArray[4] = "100-249";
			break;
		case "250":
			myArray[4] = "250-499";
			break;
		case "500":
			myArray[4] = "500-999";
			break;
		case "1000":
			myArray[4] = "1000+";
			break;	
	}
	
	return myArray;
}

// class for label objects        
function customLabelObj(material,shape,productNumber){
	
	// gets subSku's prices and size
	this.subSku = new Array();
	this.productNumber = productNumber;
	this.material = material;
	this.shape = shape;
		
}

function subSkuObj(size,qty,price){
	this.attrSize = size;
	this.attrQty = qty;
	this.attrPrice = price;

}

// IE has a bug with the select innerHtml
// this is a work around
function printAvailShapes(obj){
   
	//removeOptions('shape');
	var elSel = document.getElementById('shape');
	var options = "";
	for(var j in obj){
		//checking if that shape is already and option
	    if(options.match(obj[j].shape)==null){
		        
			options += obj[j].shape+';';
			var element = document.createElement('option');
			element.value = obj[j].shape;
			element.text = obj[j].shape;
			if(obj[j].shape.match('Square')){
				element.text += '/Rectangle';
			}
			
			try{
				elSel.add(element,null);
			}catch(e){
				elSel.add(element); // IE only
			}
		}
	}
	 
}

// IE has a bug with the select innerHtml
// this is a work around
// parameter obj is an array of customLabelObj
function printAvailMaterials(obj){

	//removeOptions('material');
	var elSel = document.getElementById('material');
	var options = "";
	for(var j in obj){
		// checking if that material is already an option
		if(options.match(obj[j].material)==null){
			options += obj[j].material+';';
			
			var element = document.createElement('option');
			element.value = obj[j].material;
			element.text = obj[j].material;
			try{
				elSel.add(element,null);
			}catch(e){
				elSel.add(element); // IE only
			}
			
			
			
		}
	}

    return options;
}


function removeOptions(element){
	var elSel = document.getElementById(element);
	var i;
	for (i = elSel.length - 1; i>=0; i--) {
		elSel.remove(i);
    
	}
}

/*
function showSelectedSizes(obj){
	
	removeOptions('size');
	var elSel = document.getElementById('size');
	if(getSelectedOption('shape')=='--' || getSelectedOption('material')=='--'){
		var element = document.createElement('option');
		element.value = '--';
		element.text = '--';
		try{
			elSel.add(element,null);
		}catch(e){
			elSel.add(element); // IE only
		}
		return;
	
	}
	
	
	var product = getSelectedProductNum(obj);
	if(product==null){
		var element = document.createElement('option');
		element.style.color = 'red';
		element.value = '--';
		element.text = 'None Available For This Combo';
		try{
			elSel.add(element,null);
		}catch(e){
			elSel.add(element); // IE only
		}
		return;
    }	

    

    var sizes = "";
	for(var j in obj[product].subSku){
		// checking if that material is already an option
		
		for(var i in obj[product].subSku[j]){
			
			if(sizes.match(i)==null){
				sizes += i;
			//	elSel.selectedIndex = 0;
				var element = document.createElement('option');
				element.value = i;
				element.text = i;
			//	var elOptOld = elSel.options[0];  
				try{
					elSel.add(element,null);
				}catch(e){
					elSel.add(element); // IE only
				}
			}
		}
	}
}
*/

function showSelectedSizes(obj){
	
	removeOptions('size');
	var elSel = document.getElementById('size');
	var selectedShape = getSelectedOption('shape');
	if(getSelectedOption('shape')=='--' || getSelectedOption('material')=='--'){
		var element = document.createElement('option');
		element.value = '--';
		element.text = '--';
		try{
			elSel.add(element,null);
		}catch(e){
			elSel.add(element); // IE only
		}
		return;
	
	}
	
	
	var product = getSelectedProductNum(obj);
	if(product==null){
		var element = document.createElement('option');
		element.style.color = 'red';
		element.value = '--';
		element.text = 'Sizes Unvailable';
		try{
			elSel.add(element,null);
		}catch(e){
			elSel.add(element); // IE only
		}
		return;
    }	

    

    var sizes = "";
	
	for(var j in obj[product].subSku){
		// checking if that material is already an option
		
		
	    var subSize = obj[product].subSku[j].attrSize;
		if(sizes.match(subSize)==null){
			sizes += subSize;
		//	elSel.selectedIndex = 0;
			var element = document.createElement('option');
			element.value = subSize;
			var subSizesDim = subSize.split("X");
			element.text = subSizesDim[0]+'"x'+subSizesDim[1]+'"';
			
			if(selectedShape.match('Circle')){
				element.text += ' Circle';
			}else if(subSizesDim[0]==subSizesDim[1]){
				element.text += ' Square';
			}else{
				element.text += ' Rectangle';
			}
			
		//	var elOptOld = elSel.options[0];  
			try{
				elSel.add(element,null);
			}catch(e){
				elSel.add(element); // IE only
			}
		}
		
	}
}

function getPrice(obj){
   	
	var size = getSelectedOption('size');
	var product = getSelectedProductNum(obj);
	var sku = getSelectedSubSku(obj);
	var price = obj[product].subSku[sku].attrPrice.replace(/\$/g,'');
	return price;
	
	
}

// gets the selected product number based on the 
// selected shape and material of label
function getSelectedProductNum(obj){

	var selectedMatIndex = document.getElementById('material').selectedIndex;
	var selectedShapeIndex = document.getElementById('shape').selectedIndex;
	var selectedMat = document.getElementById('material').options[selectedMatIndex].value;
	var selectedShape = document.getElementById('shape').options[selectedShapeIndex].value;
	
	for(var j in obj){
	    
		if(obj[j].material == selectedMat && obj[j].shape==selectedShape){
			return j;
		}
	
	}
	
    return null;
}


function getSelectedOption(element){
	var selIndex = document.getElementById(element).selectedIndex;
	return document.getElementById(element).options[selIndex].value;

}

function getSelectedSubSku(obj){
	
	 
    var product = getSelectedProductNum(obj);
	
	var size = getSelectedOption('size');
	selIndex = document.getElementById('shape').selectedIndex;
	var shape = document.getElementById('shape').options[selIndex].value;
    selIndex = document.getElementById('material').selectedIndex;
	var material = document.getElementById('material').options[selIndex].value;

	var quantity;
	if(document.getElementById('quantity').value >= 100 && document.getElementById('quantity').value <= 249){
		quantity = '100-249';
	}else if(document.getElementById('quantity').value >= 250 && document.getElementById('quantity').value <= 499){
		quantity = '250-499';
	}else if(document.getElementById('quantity').value >= 500 && document.getElementById('quantity').value <= 999){
		quantity = '500-999';
	}else if(document.getElementById('quantity').value >= 1000){
		quantity = '1000+';
	}else{
		return null;
	}
	
	for(var j in obj[product].subSku){
		// checking if that material is already an option
		
		if(obj[product].subSku[j].attrSize==size && obj[product].subSku[j].attrQty==quantity){
			return j;
		}
		
	}
	
	return null;
	
	
	
}

function getQuantityAttr(){

    if(document.getElementById('quantity').value < 100 ){
		alert('Quantity has to be at least 100');
		return;
	}
	var quantity;
	if(document.getElementById('quantity').value >= 100){
		quantity = '100-249';
	}
	if(document.getElementById('quantity').value >= 250){
		quantity = '250-499';
	}
	if(document.getElementById('quantity').value >= 500){
		quantity = '500-999';
	}
	if(document.getElementById('quantity').value >= 1000){
		quantity = '1000+';
	}
	
    return quantity;
}


