function addToCart(productId, modificationId, url)
{

	new Ajax.Request(url+'/'+productId+'/'+modificationId+'/1',
	{
    method:'get',
    onSuccess: function(msg){
    	$('cart_container').update(msg.responseText);
    	refreshCart();
    },
    onFailure: function(){ alert('Bandykite dar..') }
  });
	
}



function changeNewAddress(yes, no)
{
	if (currentAddress)
	{
		currentAddress = false;
		$('#add_address_form').hide();
		$('#need_new_address_span').html(no);

	}
	else
	{
		currentAddress = true;
		$('#add_address_form').show();
		$('#need_new_address_span').html(yes);

	}
}


current = false;

function changeInvoice(yes, no)
{
	if (current)
	{
		current = false;
		$('#invoice_form').hide();
		$('#need_invoice_span').html(no);
		$('#need_invoice').val('0');
	}
	else
	{
		current = true;
		$('#invoice_form').show();
		$('#need_invoice_span').html(yes);
		$('#need_invoice').val('1');
	}
}

function changePaymentType(value)
{
	
	$('payment_type').setValue(value);
	$('pay_form').submit();
}



function refreshCart()
{
	/*$('.your-basket').mouseover(function()
	{
		isoncart = true;
		$(this).addClass('your-basket-full');
		$('.cart-flyout').show();
	}).mouseout(function()
	{
		isoncart = false;
		setTimeout(function(){ if (!isoncart) { $(".cart-flyout").fadeOut() } }, 1500);

		$(this).removeClass('your-basket-full');
	});
	
	
	$('.cart-flyout').mouseover(function()
	{

		isoncart = true;
	}).mouseout(function()
	{
		isoncart = false;
		//setTimeout(function(){ $("#submenu").fadeOut() }, 500);
		setTimeout(function(){ if (!isoncart) { $(".cart-flyout").fadeOut() } }, 1500);

	});
	
	$('.your-basket').addClass('your-basket-full');
	setTimeout(function(){  $('.your-basket').removeClass('your-basket-full'); }, 1500);
	*/
}


function delFromCart(productId, modificationId, url)
{
	new Ajax.Request(url+'/'+productId+'/'+modificationId+'/1',
	{
	    method:'get',
	    onSuccess: function(msg){
	    	$('cart_container').update(msg.responseText);
	    	refreshCart();
	    },
	    onFailure: function(){ alert('Bandykite dar..') }
	  });

}


function number_format( number, decimals, dec_point, thousands_sep ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     bugfix by: Michael White (http://getsprink.com)
    // +     bugfix by: Benjamin Lupton
    // +     bugfix by: Allan Jensen (http://www.winternet.no)
    // +    revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +     bugfix by: Howard Yeend
    // *     example 1: number_format(1234.5678, 2, '.', '');
    // *     returns 1: 1234.57     
 
    var n = number, c = isNaN(decimals = Math.abs(decimals)) ? 2 : decimals;
    var d = dec_point == undefined ? "." : dec_point;
    var t = thousands_sep == undefined ? "," : thousands_sep, s = n < 0 ? "-" : "";
    var i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0;
    
    return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
}



function checkvals(formname)
{
	empty = false;
	
	for (i=0; i<fields.length; i++)
	{
		if (document.getElementById('form_'+fields[i]).value == "")
		{
			empty = true;
			document.getElementById('label_'+fields[i]).className = 'error';
		}
		else
		{
			document.getElementById('label_'+fields[i]).className = '';
		}
	}
	
	for (i=0; i<inputs.length; i++)
	{
		if (document.getElementById('form_'+inputs[i]).checked != true)
		{
			empty = true;
			document.getElementById('label_'+inputs[i]).className = 'error';
		}
		else
		{
			document.getElementById('label_'+inputs[i]).className = '';
		}
	}
	
	
	if (empty) setTimeout('clearVals()', 1000);
	else formname.submit();
}


function clearVals()
{
	return; // kad nedingtu raudoni
	
	for (i=0; i<fields.length; i++)
	{
		if (document.getElementById('form_'+fields[i]).value == "")
		{
			document.getElementById('label_'+fields[i]).className = '';
		}
	}
	
	for (i=0; i<inputs.length; i++)
	{
		if (document.getElementById('form_'+inputs[i]).checked != true)
		{
			document.getElementById('label_'+inputs[i]).className = '';
		}
	}
}


function billingNewAddress(show)
{
	if (show == '-1')
	{
		//$('billing-address-select').selectIndex = '1';
		//$('select_new').setAttribute("selected", "selected");
		//$('select_new').value='-1';
		$('billing-address-select').value='-1';
		$('billing-new-address-form').show();
	}
	else
	{
	//	$('select_new').value='-1';
		///$('select_new').setAttribute("selected", "");
		$('billing-new-address-form').hide();
	}
}
