﻿function CheckMicrochip() {

    var myTextField = document.getElementById('txtMicroship');
    var errormsg = "";
    if (isNaN(myTextField.value) == true) {
        errormsg = "1";
        //errormsg = errormsg + "Please enter only numeric values only \n";
        //alert('Please enter only numeric values only');
    }
    if (myTextField.value.length != "15") {
        errormsg = "1";
        //errormsg = errormsg + "Your Microchip code should be 15 characters long \n";
        //alert('Your Microchip code should be 15 characters long');
    }
    if (Left(myTextField.value, 5) == "98514") {
        errormsg = "1";
        //errormsg = errormsg + "Your Microchip code cannot start with these digits \n";
        //alert('Your Microchip code cannot start with these digits');
    }
    if (Left(myTextField.value, 3) == "977") {
        errormsg = "1";
        //errormsg = errormsg + "Your Microchip code cannot start with these digits \n";
        //alert('Your Microchip code cannot start with these digits');
    }
    if (myTextField.value.substring(4, 6) == "77") {
        errormsg = "1";
        //errormsg = errormsg + "Your Microchip code cannot contain these digits \n";
        //alert('Your Microchip code cannot start with these digits');
    }
    if (errormsg != "") {
        errormsg = "This chip number is not compatible with the Microchip Petporte smart flap®.  Please verify that you have entered the number correctly using the following guidelines: \n";
        errormsg = errormsg + "Please enter numeric values only \n";
        errormsg = errormsg + "Your Microchip code should be 15 characters long \n";
        errormsg = errormsg + "Your Microchip code cannot start with these digits (98514) or (977)\n";
        errormsg = errormsg + "Your Microchip code cannot contain these digits (77) in the 5th and 6th digit location \n";
        alert(errormsg);
    } else {
    alert('This chip should work well with the Microchip Petporte smart flap®');
    }
    
    
    return false;
}

function Left(str, n) {
    if (n <= 0)
        return "";
    else if (n > String(str).length)
        return str;
    else
        return String(str).substring(0, n);
}

function mid(str, n) {
    if (n <= 0)
        return "";
    else if (n > String(str).length)
        return str;
    else
        return String(str).substring(5, n);
}
