function formatAsMoney(mnt) {
    mnt -= 0;
    mnt = (Math.round(mnt*100))/100;
    return (mnt == Math.floor(mnt)) ? mnt + '.00' 
              : ( (mnt*10 == Math.floor(mnt*10)) ? 
                       mnt + '0' : mnt);
}

function formmailformFilter() {
	var filter = document.formmailform.filter.value;
	var imgnum = document.formmailform.imgnum.value;
	if(	(filter == "Lapidary" && imgnum == 0) || (filter == "lapidary" && imgnum == 0) || (filter == "LAPIDARY" && imgnum == 0) || (filter == "Arrow" && imgnum == 1) || (filter == "arrow" && imgnum == 1) || (filter == "ARROW" && imgnum == 1) || (filter == "Jewel" && imgnum == 2) || (filter == "jewel" && imgnum == 2) || (filter == "JEWEL" && imgnum == 2) || (filter == "Stones" && imgnum == 3) || (filter == "stones" && imgnum == 3) || (filter == "STONES" && imgnum == 3) || (filter == "Beads" && imgnum == 4) || (filter == "beads" && imgnum == 4) || (filter == "BEADS" && imgnum == 4) ) {
		document.formmailform.action = '/formmail.php';
	}
	return true;
}

function inventoryCheck() {
	var qtytocheck = document.getElementById('qty').value;
	var invtocheck = document.getElementById('inv').value;
	var prodname = document.getElementById('product').value;
	var newprodname = prodname.replace('&gt;',' -');
	if(parseFloat(qtytocheck) > parseFloat(invtocheck)) { 
		document.getElementById('qty').value = invtocheck; 
		alert('We currently have only '+invtocheck+' of '+newprodname+' in stock. '+invtocheck+' is the most available to be purchased.'); 
		}
}

function multi_inventoryCheck() {
	var qtytocheck = document.getElementById('qty'+'1').value;
	var selectedoption = document.getElementById('productpr1').selectedIndex;
	var optionid = document.getElementById('productpr1').options[selectedoption].id;
	var invtocheck = document.getElementById('inv'+optionid).value;
	var prodname = document.getElementById('productpr'+'1').value;
	var newprodname = prodname.replace('&gt;',' -');
	newprodname = newprodname.replace(':',' $');
	newprodname = newprodname.replace('>','-');
	if(parseFloat(qtytocheck) > parseFloat(invtocheck)) { 
		document.getElementById('qty'+'1').value = invtocheck; 
		alert('We currently have only '+invtocheck+' of '+newprodname+' in stock. '+invtocheck+' is the most available to be purchased.'); 
		}
}

function changeInventory() {
	var selectedoption = document.getElementById('productpr1').selectedIndex;
	var optionid = document.getElementById('productpr1').options[selectedoption].id;
	var inv = document.getElementById('inv'+optionid).value;
	if(inv > 0) { document.getElementById('currentinv').value = 'In Stock'; }
	if(inv <=0) { document.getElementById('currentinv').value = 'Out of Stock'; document.getElementById('qty1').value = 0; }
}

function changeUnits() {
	var selectedoption = document.getElementById('productpr1').selectedIndex;
	var optionid = document.getElementById('productpr1').options[selectedoption].id;
	var units = document.getElementById('units'+optionid).value;
	document.getElementById('units1').value = units;
	if(units == 0) {
		document.getElementById('currentshipping').value = 'FREE SHIPPING (Continental USA only)';
		document.getElementById('currentshipping').style.display = 'block';
		document.getElementById('shipformat').style.display = 'block';
	} else { 
		document.getElementById('currentshipping').value = '';
		document.getElementById('currentshipping').style.display = 'none';
		document.getElementById('shipformat').style.display = 'none';
	}
}

function checkDropShip() {
	var selectedoption = document.getElementById('productpr1').selectedIndex;
	var optionid = document.getElementById('productpr1').options[selectedoption].id;
	var check = document.getElementById('dropship'+optionid).value;
	document.getElementById('dropshipped').value = check;
	if(check == 1) {
		document.getElementById('dropshipped').value = 'Drop Shipped from Manufacturer';
		document.getElementById('currentshipping').style.display = 'block';
		document.getElementById('dropformat').style.display = 'block';
	} else { 
		document.getElementById('dropshipped').value = '';
		document.getElementById('currentshipping').style.display = 'none';
		document.getElementById('dropformat').style.display = 'none';
	}
}

function addmasterName() {
	if(document.getElementById('mastername').value != '') {
		var mastername = document.getElementById('mastername').value;
		var selectedindex = document.getElementById('productpr1').selectedIndex;
		var selectedvalue = document.getElementById('productpr1').options[selectedindex].value;
		var stopindex = selectedvalue.indexOf(':');
		var prodnamefull = selectedvalue.split(':');
		var prodname = prodnamefull[0].split('>');
		document.getElementById('productpr1').options[selectedindex].value = prodname[0] + ' > ' + mastername + ' - ' + prodname[1] + ':' + prodnamefull[1];
	}
}

function addmasterNames() {
	if(document.getElementById('mastername').value != '') {
		var opcount = document.getElementById('opcount').value;
		var mastername = document.getElementById('mastername').value;
		var selectedvalue = '';
		var prodname = '';
		var prodnamefull = '';
		var stopindex = '';
		var test = '';
		
		for(var x=0; x < opcount; x++) {
			selectedvalue = document.getElementById('productpr'+(x+1)).value;
			stopindex = selectedvalue.indexOf(':');
			prodnamefull= selectedvalue.split(':');
			prodname = prodnamefull[0].split('>');
			document.getElementById('productpr'+(x+1)).value = prodname[0] + ' > ' + mastername + ' - ' + prodname[1] + ':' + prodnamefull[1];
		}
	}
}

function combopackLmt() {
	var opcount = document.getElementById('opcount').value;
	var lmt = document.getElementById('lmt').value;
	var checkcount = 0;
	var el = '';
	for(var x=0; x < opcount; x++) {
		el = document.getElementById('product[]op'+(x+1)).checked;
		if(el == true) { checkcount++; } 
	}
	if(checkcount == lmt) { 
		for(x=0; x < opcount; x++) { 
			el = document.getElementById('product[]op'+(x+1)).checked;
			if(el == false) { document.getElementById('product[]op'+(x+1)).disabled = true; }
		}
	}
	if(checkcount < lmt) { 
		for(x=0; x < opcount; x++) { 
			el = document.getElementById('product[]op'+(x+1)).checked;
			if(el == false && document.getElementById('product[]op'+(x+1)).disabled == true) { document.getElementById('product[]op'+(x+1)).disabled = false; }
		}
	}
}

