//JQuery alert
function JQalert(p_title, p_message) {
    p_title = p_title || "";
    $("<div>" + p_message + "</div>").dialog({
        title: p_title,
        resizable: false,
        modal: true,
        overlay: { backgroundColor: "#000", opacity: 0.5 },
        buttons: { "Ok": function() { $(this).dialog("close"); } },
        close: function(ev, ui) { $(this).remove(); }
    });
}

//JQuery alert - item inserted
function itemInserted(p_title, p_message) {
    p_title = p_title || "";
    $("<div>" + p_message + "</div>").dialog({
        title: p_title,
        resizable: false,
        modal: true,
        overlay: { backgroundColor: "#000", opacity: 0.5 },
        buttons: { "Ok": function() { $(this).dialog("close"); } },
        close: function(ev, ui) { $(this).remove(); }
    });
}

//JQuery Private Prescription Question
function confirmPP(title, prodID, name) {
    $("#dialogPP").dialog({
        bgiframe: true,
        resizable: false,
        height: 170,
        width: 400,
        modal: true,
        title: title,
        overlay: {
            backgroundColor: '#ccc',
            opacity: 0.1
        },
        buttons: {
        'Yes': function() {
        $.ajax({
            type: "POST",
            url: "../../../WebServices/BasketService.asmx/AddToRPPDT",
            contentType: "application/json; charset=utf-8",
            data: "{'prodID': '" + prodID + "','answer': 'Yes','prodName': '" + name + "'}",
            dataType: "json"
            });
                $(this).dialog('close');
            },
            'No': function() {
            $.ajax({
                type: "POST",
                url: "../../../WebServices/BasketService.asmx/AddToRPPDT",
                contentType: "application/json; charset=utf-8",
                data: "{'prodID': '" + prodID + "','answer': 'No','prodName': '" + name + "'}",
                dataType: "json"
            });
            $(this).dialog('close');
            }
        }
    });
}

//Handle Repeating Private Prescription
function repeatingPP(_id, _answer, _name) {
   

    function PPAjaxSucceeded(response) {
        itemInserted('Basket Updated', "Item added to basket.");
    }
    function PPAjaxFailed(result) {
        JQalert("RPP Failure");
    }
}

//JS Whole Number Validation
function isPositiveInteger(val) {
    if (val == null) { return false; }
    if (val.length == 0) { return false; }
    for (var i = 0; i < val.length; i++) {
        var ch = val.charAt(i)
        if (ch < "0" || ch > "9") {
            return false
        }
    }
}

//JS Email Address Validation
function validateEmail(email)
{
    return /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(email);
}