function addToCart(id)
{
    document.shopitem.product_id.value = id;
    var qty = parseInt(document.getElementById('quantity-'+id).value);
    if(!isNaN(qty))
    {
        document.shopitem.submit();
    }
    else
    {
        alert('Your input value is not valid. \n Please use only numbers 0 - 9 with no decimals');
        document.getElementById('quantity-'+id).focus();

    }
}

function addWholeCategoryProducts(id){
	$('input[name=category_id]').val(id);
	var qty = parseInt($('#category-quantity').val());
	if(!isNaN(qty))
	{ $('#shopitem').submit() ;}
	else
	{
		alert('Your input value is not valid. \n Please use only numbers 0 - 9 with no decimals');
		$('input[name=category_id]').focus();
	}
}

function countTotal(id)
{
    var qty = parseInt(document.getElementById('quantity-'+id).value);
    var price = parseFloat(document.getElementById('price-'+id).innerHTML);
	var weight = parseFloat(document.getElementById('weight-'+id).innerHTML);

    if(!isNaN(qty))
    {
        var totalPrice = qty * price;
		var totalWeight = qty * weight;
        document.getElementById('total-'+id).innerHTML = totalPrice;
		document.getElementById('totalweight-'+id).innerHTML = totalWeight;
    }
    else
    {
        document.getElementById('total-'+id).innerHTML = 0;
    }
	
	countAll();
}	

function countAll()
{
	var totalrow = parseInt(document.getElementById('total-row').value);
	var totalPrice = 0;
	var totalWeight = 0;
	
	for(i=0; i<totalrow; i++)
	{
		totalPrice += parseFloat(document.getElementById('total-'+i).innerHTML);
		totalWeight += parseFloat(document.getElementById('totalweight-'+i).innerHTML);
	}
	
	document.getElementById('total-weight').innerHTML = totalWeight;
	document.getElementById('total-price').innerHTML = totalPrice;
}

function toggleAll(total)
{
    var bool;
    if(document.getElementById('checkAll').checked)
    {bool = true;}
    else
    {bool = false;}

    for(i=0;i<total;i++)
    {
        document.getElementById('remove-'+i).checked = bool;
    }
}


function setAction(action)
{
    var webroot= document.shoppingcart.action;

    if(action=='remove')
    { document.shoppingcart.action = webroot + "shoppingcart/remove"; document.shoppingcart.submit();}

	if(action=='checkout')
    { document.shoppingcart.action = webroot + "shoppingcart/checkout"; document.shoppingcart.submit();}

    if(action=='confirm')
    { document.shoppingcart.action = webroot + "shoppingcart/update/confirm"; document.shoppingcart.submit();}
	
	if(action=='cancel')
    { document.shoppingcart.action = webroot + "shoppingcart/cancel"; document.shoppingcart.submit();}
	
	if(action=='catalogue')
    { document.shoppingcart.action = webroot; document.shoppingcart.submit();}
}

function goBack(action)
{
	var webroot= document.submit_frm.action;
	
	if(action=='checkout')
    { document.submit_frm.action = webroot + "checkout"; document.submit_frm.submit();}
}

function setDisplay()
{
    if(document.getElementById('registeredMember').style.display == 'none')
    {
        document.getElementById('registeredMember').style.display='';
        document.getElementById('registration').style.display='none';
        document.getElementById('membership').value='New member';
    }
    else
    {
        document.getElementById('registeredMember').style.display='none';
        document.getElementById('registration').style.display='';
        document.getElementById('membership').value='Already a member';
    }
}

function setConfirm(webroot)
{
	if(document.getElementById('registeredMember').style.display == 'none')
	{document.memberInfo.action+= "shoppingcart/confirm/register";}
	else
	{document.memberInfo.action+= "shoppingcart/confirm/member";}
	
    document.memberInfo.submit();
    
    return true;
}

