//check if user choosed any item, otherwise do nothing and show an alert
function countChoosenProducts(controllerName)
{
    if ($('.choosenItem:checked').length > 0) {  // the "> 0" part is unnecessary, actually
        if (controllerName == 'buyBillController')
        {
            $("#form1").attr("action", "buyBillController.php?do=delete");
        }
        else if (controllerName == 'buyAndReturnBillController')
        {
            $("#form1").attr("action", "buyAndReturnBillController.php?do=delete");
        }
        else if (controllerName == 'returnBuyBillController')
        {
            $("#form1").attr("action", "returnBuyBillController.php?do=delete");
        }
        else
        {
            $("#form1").attr("action", controllerName + ".php?do=executeOperation");
        }
        return true;
    }
    else
    {
        $("#form1").attr("action", "");
        //alert("يجب اختيار العناصر أولا");
        $("#noElementsError").css("display", "block");
        setTimeout(function () {
            $("#noElementsError").css("display", "none");
        }, 4000);
        return false;
    }
}


$(document).ready(function (e) {

    var outputStringValue = $("#outputStringValue").html();
    if (outputStringValue == "")
    {

        $("#outputString").css("display", "none");
    }
    else
    {

        $("#outputString").css("display", "block");
        setTimeout(function () {
            $("#outputString").css("display", "none");
        }, 4000);
    }

    //fadeout outputString
    //$("#outputString").fadeOut(4000);
    /*----------------------------------------*/
    //check or uncheck all
    // Listen for click on toggle checkbox
    $('#checkAll').click(function (event) {
        if (this.checked) {
            // Iterate each checkbox
            $('.choosenItem').each(function () {
                this.checked = true;
            });
        }
        else {
            // Iterate each checkbox
            $(".choosenItem").each(function () {
                this.checked = false;
            });
        }
    });

});
