function addSmallDiamondInput(color)
{
	$("."+color+"_input:last").clone().insertAfter($("."+color+"_input:last"));
	newinput = $("."+color+"_input:last");
	$(newinput).children("input").val("");
	$(newinput).children("input").focus();
}

function getcolortotal(color)
{
	$("#"+color+"-price").html("Calculating price ...");
	
	var amounts = new Array();
	var carats = new Array();
	$("."+color+"_input").each( function() { 
		amounts.push($(this).children("input").val());
		carats.push($(this).children("select").val());
	});
	
	$("#"+color+"-price").load("/services/getSmallDiamondPrice/", { 'color': color, 'amounts[]': amounts, 'carats[]' : carats });
	
	
	//console.log()
}

function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}


function updateColorPrices(color)
{
	html  = "<div class='inner'>";
	html += "<table style='width:100%' class='info_table'>";
	
	html += "<tr><th width=\"93\">Carat</th><th width=\"120\">Diameter (mm)</th><th width=\"93\">Price</th><th width=\"93\" class=\"pricecarat\">Price/Carat</th></tr>";
	
	for(i=0;i<colorPrices[color].length;i++)
	{
		r = colorPrices[color][i];
		
		myprice = r["Price"].substr(1);
		myprice =  parseFloat(myprice.replace(",",""));
		
		html += "<tr>";
		html += "<td>"+r["Carat"]+"</td>";
		html += "<td>"+r["Diameter"]+"</td>";
		html += "<td>"+r["Price"]+"</td>";
		html += "<td class=\"pricecarat\">$"+addCommas((myprice/r["Carat"]).toFixed(0))+"</td>";
		html += "</tr>";
	}

	html += "</table></div>";
	
	$("#color_" + color).html(html);
	//console.log(html);
	//console.log(colorPrices[color]);
}