var currentDivNumber = 0;

function show(divIDPattern, divIDNumber, subheader) {
	currentDivNumber = divIDNumber;

	allDivs = document.getElementsByTagName('div'); 
	for (i=0; i<allDivs.length; i++) {
		if (allDivs[i].id.indexOf(divIDPattern) == 0) {
			if (allDivs[i].id.indexOf(divIDPattern+divIDNumber) == 0) {
				allDivs[i].style.display = "block";
			} else {
				allDivs[i].style.display = "none";
			}
		} else if (allDivs[i].id.indexOf('menuitem') == 0) {
			allDivs[i].style.backgroundColor = '#bb3637';
			
			if (allDivs[i].id.indexOf('menuitem'+divIDNumber) == 0) {		
//				allDivs[i].style.backgroundColor = '#e04244';
				allDivs[i].style.backgroundColor = '#1f70a1';

			}
		}
	}

	document.getElementById('subheaderP').innerHTML = subheader;
}

function leftMenuOn(menuNumber) {
	el = document.getElementById('menuitem' + menuNumber);
//	el.style.backgroundColor = '#e04244';
	el.style.backgroundColor = '#1f70a1';

}

function leftMenuOff(menuNumber) {
	if (menuNumber != currentDivNumber) {
		el = document.getElementById('menuitem' + menuNumber);
		el.style.backgroundColor = '#bb3637';	
	}
}

function addToList(arg1, arg2, price) {
	alert("Summary:\n" + arg1 + "\n" + arg2 + "\n" + price);
}


function initCalculator() {
	show('priceList',1, '');
	createList('1_1');
}

function createList(rowID) {
	var strFrom;
	var strTo;
	var str = "";
	var endString = "";

	var finalString = "";
	var which;
	var subtotal = 250 * 1;
	var currentRowClass = "";
	var itemID = rowID;
	var qtyID = "q" + rowID;

	finalString = "<table class=\"shoppingList\" ";
	finalString += "cellpadding=\"0\" cellspacing=\"0\" ";
	finalString += "style=\"background-color: #2686BF;\">";

	allCheckboxes = document.getElementsByTagName("input");
	for(i=0; i < allCheckboxes.length; i++) {
		if (allCheckboxes(i).checked == true) {
			strFrom = allCheckboxes(i).value;
			which = 1;
			while (strFrom.length > 0) {
				strTo = strFrom.substring(0,strFrom.indexOf(";"));
				strFrom = strFrom.substring(strFrom.indexOf(";")+1);

				if (which == 1) {
					if (allCheckboxes(i).id == itemID) {
						currentRowClass = "<tr class=\"shoppingListHighRow\" valign=\"";
						endString += currentRowClass;
						endString += "top\">"
					} else {
						currentRowClass = "<tr class=\"shoppingListLowRow\" valign=\"";
						endString += currentRowClass;
						endString += "top\">"
					}
				} else {
					if (which == 2) {
						str += "<td class=\"shoppingList\" align=\"left\" rowspan=\"2\">";
						str += strTo;
						str += "</td><td class=\"shoppingList\" align=\"right\">";
						str += "<a href=\"javascript:uncheck('";
						str += allCheckboxes(i).id;
						str += "');\">";
						str += "<img src=\"images/delete.gif\" border=\"0\" background-color=\"#2686BF\">";
						str += "</a></td></tr>";
					} else if (which > 2){
						str += currentRowClass;
						str += "bottom\">"
						str += "<td class=\"shoppingList\" align=\"right\"><b>";
						alert("this is price: " + strTo);
						qtyID = 'q' + allCheckboxes(i).id;
						alert("qtyID=" + qtyID);
						if (document.getElementById(qtyID).value == '') {
							document.getElementById(qtyID).value = 1;
						}
						qty = document.getElementById(qtyID).value * 1;
						alert("qty=" + qty);
						alert("strTo::" + strTo);
						unitPrice = parseInt(strTo.substring(1, strTo.length)) * 1;
						alert("unitPrice=" + unitPrice);
						total = qty * unitPrice;
						strTo = "$" + total;
						str += strTo;
						str += "</b></td>";
					}
			
					endString += str;

					if (strTo.indexOf("$") == 0) {
						//subtotal += parseInt(strTo.substring(1, strTo.length)) * 1;
						subtotal += qty * unitPrice;
					}
					str = "";
				}
				which++;
			}
			
			endString += "</tr>";
		}
	}
	
	finalString += "<tr class=\"shoppingListLowRow\"><td class=\"shoppingList\" style=\"border-bottom: 1px solid #ffffff\" colspan=\"2\">Please note that these prices are estimates and do not constitute an official quote.  Items that don't have their price specified will not be included in the list subtotal.</td></tr>"
	finalString += "<tr class=\"shoppingListSubtotal\"><td class=\"shoppingList\" style=\"border-bottom: 1px solid #ffffff\" align=\"left\">Subtotal:</td><td class=\"shoppingList\"  style=\"border-bottom: 1px solid #ffffff\"align=\"right\"><b>$";
	finalString += subtotal;
	finalString += "</b></td></tr>";
	
	finalString += endString;
	document.getElementById('summary').innerHTML = finalString;
}


function uncheck(cb) {
	document.getElementById(cb).checked = false;
	createList('');
}

