function addtocart(id){
    var size = $("#Size").val();
    var q = $("#Quantity").val();
    var colour;
    $("input[name=color]").each(function(){
        if ($(this).is(':checked')){
            colour = $(this).val();
        }
    });
    if (isNaN(q)){
        alert("You must enter a valid quantity");
    }
    else {
        $.post("cartaction.php", {
            action: 'add',
            q: q,
            id: id,
            size: size,
            colour: colour
        }, function(data){
            cartrefresh();
             
        });

    }
    return false;
}

function removeitem(number, ref){
    $.post("cartaction.php", {
        action: 'remove',
        n:  number
    }, function(data){
        cartrefresh();
        if (ref == 'r'){
            self.location = 'index.php?show=checkout';
        }
    });

}

function updatecart(num){
    q = $("#Quantity"+num).val();
    if (!isNaN(q)){
        $.post("cartaction.php", {
            action: 'update',
            n:  num,
            q: q
        }, function(data){
            alert("Item Updated");
            self.location = 'index.php?show=checkout';
        });
    }
}

function cartrefresh(){
    $("#smallcart").load("smallcart.php");

}

function checkme(){
    var name = $("input[name=name]").val();
    var address = $("input[name=address]").val();
    var email = $("input[name=email]").val();
    var number = $("input[name=number]").val();
    var proceed = $("input[name=proceed]").val();

    if ((name == "") || (address == "") || (email == "") || (number == "")){
        alert ("All fields are required");
        return false;
    }

    if (proceed != '1'){
        alert("you have not met minimum order quantites for at least one item");
        return false;
    }

    return true;
}