//Tabs menu
function tab(nr){

	for (i = 1; i < 8; i++)
	{
			if (nr == i)
			{
				document.getElementById("menu" + i).className = "on";
				if(document.getElementById("sub" + i)) document.getElementById("sub" + i).style.display = "";
			}
			else
			{
				document.getElementById("menu" + i).className="";
				if(document.getElementById("sub" + i)) document.getElementById("sub" + i).style.display = "none";
			}
 }
}

function subtab(nr){

	for (i = 1; i < 6; i++)
	{
			if (nr == i)
			{
				if(document.getElementById("submenu" + i)) document.getElementById("submenu" + i).className = "on";
				if(document.getElementById("subtab" + i)) document.getElementById("subtab" + i).style.display = "";
			}
			else
			{
				if(document.getElementById("submenu" + i)) document.getElementById("submenu" + i).className="";
				if(document.getElementById("subtab" + i)) document.getElementById("subtab" + i).style.display = "none";
			}
 }
}

function addToCartLoading(id)
{
    $(id).value = 'Chargement ...';
    $(id).disabled = 'disabled';
    document.body.style.cursor="wait";

}

function addToCartComplete(id)
{
    $(id).value = 'Ajout\xe9';
    $(id).className = $(id).className+'_off';
    document.body.style.cursor="";

}

function cartLoading()
{
//    document.body.style.cursor="wait";
//    $("but_checkout").disabled="disabled";
//    $("but_checkout").className=$("but_checkout").className+'_off';
    $("loading-mask").style.display="";
}

function cartComplete()
{
//    document.body.style.cursor="";
//    $("but_checkout").disabled="";
//    $("but_checkout").className=$("but_checkout").className.sub('_off', '');
    $("loading-mask").style.display="none";
}

function updateCart(key, cart)
{
    cart = eval('(' + cart + ')');
    $('item_total_'+key).update(cart.offer);

    $('cart_total').update(cart.total);
    $("loading-mask").style.display="none";
}

function deleteCartItem(key, cart)
{
    cart = eval('(' + cart + ')');
    $('item_'+key).fade();
    $('cart_total').update(cart.total);
    $("loading-mask").style.display="none";
}

function updateCheckout(cart, balance)
{
    cart = eval('(' + cart + ')');

    if(cart.error) {
        alert(cart.error);
    } else {
        if($('total_shipping')) $('total_shipping').update(cart.total_shipping);
        if($('checkout_total')) $('checkout_total').update(cart.total);
        if($('checkout_credit')) $('checkout_credit').update(cart.credit);
        if($('checkout_to_pay')) $('checkout_to_pay').update(cart.total - cart.credit);
        $('balance').update(balance - cart.credit);
    } 

    $("loading-mask").style.display="none";
}

function showTooltip(event)
{
        $('container').select('.pop2').each(function(item){
        //get is of clicked "?" and show pop
        var id = event.findElement().id.substring(2);
        var item_id = item.id.substring(4);
        if(id == item_id) {
            item.toggle();
        } else {
            item.hide();
        }
    });
}

