﻿function validatePESEL(peselInputID){
    var pesel = $("#" + peselInputID).val();
    pesel = pesel.replace(/ /g, '');
    if (pesel.length == 11) 
    {
        $.ajax({
            type: "GET",
            url: rootPath + "Common/ValidatePESEL",
            data: "pesel=" + pesel,
            dataType: "JSON",
            success: function(result) {
                if (result == "false") {
                    $("#badPESEL").removeClass("hide");
                }
                else{
                    $("#badPESEL").addClass("hide");
                }
            }
        });
    }
    else if (pesel.length == 0) 
    {
        $("#badPESEL").addClass("hide");
    }
    else
    {
        $("#badPESEL").removeClass("hide");
    }
}

function validateNIP(nipInputID) {
    var nip = $("#" + nipInputID).val();
    nip = nip.replace(/-/g, '');
    nip = nip.replace(/ /g, '');
    if (nip.length == 10) {
        $.ajax({
            type: "GET",
            url: rootPath + "Common/ValidateNIP",
            data: "nip=" + nip,
            dataType: "JSON",
            success: function(result) {
                if (result == "false") {
                    $("#badNIP").removeClass("hide");
                }
                else {
                    $("#badNIP").addClass("hide");
                }
            }
        });
    }
    else if (nip.length == 0) {
        $("#badNIP").addClass("hide");
    }
    else {
        $("#badNIP").removeClass("hide");
    }
}

function validateREGON() {
    var regon = $("#regonNumber").val();
    regon = regon.replace(/-/g, '');
    regon = regon.replace(/ /g, '');
    if (regon.length == 9) {
        $.ajax({
            type: "GET",
            url: rootPath + "Common/ValidateREGON",
            data: "regon=" + regon,
            dataType: "JSON",
            success: function(result) {
                if (result == "false") {
                    $("#badREGON").removeClass("hide");
                }
                else {
                    $("#badREGON").addClass("hide");
                }
            }
        });
    }
    else if (regon.length == 0) {
        $("#badREGON").addClass("hide");
    }
    else {
        $("#badREGON").removeClass("hide");
    }
}


