﻿// JScript File
//page method
//adds recipient to jango mailer
function CallAddRecipient(EmailAddress) {
    $.ajax({
        url: "SiteService.asmx/AddRecipient",
        data: "{'Email':'" + EmailAddress + "'}",
        async: false,
        type: "POST",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {
            alert("called service");
            /*if (msg.d == "Success") {
                alert('Thanks, you have been added to our mailing list.');
            } else {
                alert('Sorry, you have not been added to our mailing list.');   
            } */           
        },
        error: function(e){
            alert("Sorry, you have not been added to our mailing list.");                         
        }
    });  
}
//checks the supplied email address is valid
function isValidEmailAddress(emailAddress) {
    var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
    return pattern.test(emailAddress);
}
