﻿function CheckEmailFormat(email) {
    var at = email.indexOf("@");
    var dot = email.lastIndexOf(".");
    var inv = '\/\'\\ ";:?!()[]\{\}^|';
    if (email == "") { return false; }
    if (at == -1 || dot == -1) { return false; }
    if (dot < at) { return false; }
    if (dot - at == 1) { return false; }
    for (i = 0; i < inv.length; i++) {
        if (email.indexOf(inv.charAt(i), 0) > -1) { return false; }
    }
    for (i = 0; i < email.length; i++) {
        if (email.charCodeAt(i) > 127) { return false; }
    }
    if (dot >= email.length - 1) { return false; }

    return true;
}

function EmailAddressExists(email, validatorurl) {
    var success = false;
    $.postJSON(validatorurl, { email: email }, function(result) {
        success = result;
    }, false);

    return success;
}

function ValidZipCode(zipcode, validatorurl) {
    var success = false;
    $.postJSON(validatorurl, { zip: zipcode }, function(result) {
        success = result;
    }, false);

    return success;
}

function IsStringEmpty(text) {
    return (text.length > 0);
}

function IsValidLength(text, len) {
    return (text.length >= len);
}
