function HideContent() {
	var elems = document.getElementsByTagName("DIV");
	for(var i = 0; i < elems.length; i++)
	{
		//Hide all the indicators
		if (elems[i].id.substr(0, 4) == "ind_")
		{
			elems[i].style.display="none";
		}
		//Hide all the products
		else if (elems[i].id.substr(0, 5) == "prod_")
		{
			elems[i].style.display="none";
		}
	} 		
}

function UpdateAllPrices() {
	var elems = document.getElementsByTagName("DIV");
	for(var i = 0; i < elems.length; i++)
	{
		if (elems[i].id.indexOf("_EACH") > -1)
		{
			UpdatePrices(elems[i].id.substr(0, elems[i].id.indexOf("_EACH")));
		}
	} 		
}


function ShowContent(d) {
	if(d.length < 1) 
		{ return; }
	
	var elem = document.getElementById(d);
	if (elem != null)
	{
		elem.style.display = "block"
	}
}

function HideDiv(d) {
	if(d.length < 1) 
		{ return; }
	
	var elem = document.getElementById(d);
	if (elem != null)
	{
		elem.style.display = "none"
	}

}

function isNumberKey(evt)
{
	var charCode;
	if (evt){
		charCode = evt.which;
	}
	else if (window.event) {
		charCode = window.event.keyCode;
	}
		//event = evt || window.event; 
		//var charCode = (evt.which) ? evt.which : event.keyCode
		//37 and 39 are left and right arrow keys
		if (charCode > 31 && (charCode < 48 || charCode > 57) && (charCode != 37) && (charCode != 39))
			return false;
			
	return true;
}

function ChangeText(id, str) {
	if(id.length < 1) 
		{ return; }

	document.getElementById(id).innerHTML  = str;
}

function UpdatePrices(id) {

	if (document.getElementById(id + '_PRODPRICE') != null) {
		productPrice = parseFloat(document.getElementById(id + '_PRODPRICE').value);
	} else {
		productPrice = 0;
	}
	
	if (document.getElementById(id + '_ATTRPRICE') != null) {
		attributePrice = parseFloat(document.getElementById(id + '_ATTRPRICE').value);
	} else {
		attributePrice = 0;
	}
	
	if (document.getElementById(id + '_LEN') != null) {
		var each=productPrice + (attributePrice * document.getElementById(id + '_LEN').value);
		var subtotal=(productPrice + (attributePrice * document.getElementById(id + '_LEN').value)) * document.getElementById(id + '_QTY').value;
		ChangeText(id + '_EACH', '$' + each.toFixed(2));
		ChangeText(id + '_SUBTOTAL', '$' + subtotal.toFixed(2));
	} else if(document.getElementById(id + '_QTY') != null) {
		var each = productPrice;
		var subtotal= (productPrice ) * document.getElementById(id + '_QTY').value;
		ChangeText(id + '_EACH', '$' + each.toFixed(2));
		ChangeText(id + '_SUBTOTAL', '$' + subtotal.toFixed(2));
	} else {
		var each = productPrice;
		var subtotal= productPrice;
		ChangeText(id + '_EACH', '$' + each.toFixed(2));
		ChangeText(id + '_SUBTOTAL', '$' + subtotal.toFixed(2));
	}
}

function SizeInRange(id, minimum, maximum) {
	var elem = document.getElementById(id + '_LEN');
	if (elem != null) {
		if (elem.value < minimum) {
			document.getElementById(id + '_QTY').value = '0';
			ShowContent('InputError');
			//alert("Length must be a minimum of " + minimum + " ft");
			elem.value = '10';
			return false;
		} else if (elem.value > maximum) {
			document.getElementById(id + '_QTY').value = '0';
			ShowContent('InputError');
			//alert("Length must be a maximum of " + maximum + " ft");
			elem.value = '250';
			return false;
		}
		else
		{
			HideDiv('InputError');
			document.getElementById(id + '_QTY').value = '1';
		}
		return true;
	} 
	return false;
}

function myPopup(url,windowname,w,h,x,y){
	window.open(url,windowname,"resizable=no,toolbar=no,scrollbars=no,menubar=no,status=no,directories=no,width="+w+",height="+h+",left="+x+",top="+y+"");
}