$q = jQuery.noConflict();
$q(document).ready(function() {
	$q(".plus-qty").click(function()
	{
		id = $q(this).attr("id").replace("buttonplus", "");
		qty = parseInt($q("#" + id + "row .qty").val());
		qty++;
		price = parseFloat($q("#" + id + "row .price").html().replace("$", ""));
		cost = parseFloat(qty) * price;
		$q("#" + id + "row .qty").val(qty);
		$q("#" + id + "row .cost").html(format_currency(cost));
		calc_total();
		return false;
	});
	$q(".minus-qty").click(function()
	{
		id = $q(this).attr("id").replace("buttonminus", "");
		qty = parseInt($q("#" + id + "row .qty").val());
		if(qty > 0)
		{
			qty--;
			price = parseFloat($q("#" + id + "row .price").html().replace("$", ""));
			cost = parseFloat(qty) * price;
			$q("#" + id + "row .qty").val(qty);
			$q("#" + id + "row .cost").html(format_currency(cost));
			calc_total();
		}
		return false;
	});
	$q(".qty").keyup(function()
	{
		if($q(this).val() == "")
			$q(this).val("0");
		
		calc_total();
			
	});

});
function calc_total() {
	total = 0;
	$q(".cost").each(function()
	{
		total += parseFloat($q(this).html().replace("$", ""));
	});
	$q("#total").html(format_currency(total));
}
function format_currency(strValue)
{
	//http://www.sonofsofaman.com/hobbies/code/js/formatcurrency.asp
	strValue = strValue.toString().replace(/\$|\,/g,'');
	dblValue = parseFloat(strValue);

	blnSign = (dblValue == (dblValue = Math.abs(dblValue)));
	dblValue = Math.floor(dblValue*100+0.50000000001);
	intCents = dblValue%100;
	strCents = intCents.toString();
	dblValue = Math.floor(dblValue/100).toString();
	if(intCents<10)
		strCents = "0" + strCents;
	for (var i = 0; i < Math.floor((dblValue.length-(1+i))/3); i++)
		dblValue = dblValue.substring(0,dblValue.length-(4*i+3))+','+
		dblValue.substring(dblValue.length-(4*i+3));
	return (((blnSign)?'':'-') + '$' + dblValue + '.' + strCents);

}
function ajax_json(url, objevent, start_date, end_date)
{
		 $q.getJSON(url, {'id' : objevent.id,'startdate': start_date,'enddate': end_date,'text': objevent.text,'firstname':objevent.firstname,'surname':objevent.surname,'email':objevent.email, 'project':objevent.projectdescription}, function(result) {
		alert(result.message); 
	}); 
}



