﻿/// <reference path="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.4.min.js" />
/// <reference path="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.7/jquery-ui.min.js" />

//------------------------//
// Begin Global Functions //
//------------------------//

var urlParams = {};
(function () {
    var e,
a = /\+/g,  // Regex for replacing addition symbol with a space
r = /([^&;=]+)=?([^&;]*)/g,
d = function (s) { return decodeURIComponent(s.replace(a, " ")); },
q = window.location.search.substring(1);

    while (e = r.exec(q))
        urlParams[d(e[1])] = d(e[2]);
})();

function subscribe() {
    var contactname = document.getElementById('txtanname').value;
    var contactemail = document.getElementById('txtannemail').value;

    if (contactname.length > 0 && contactemail.length > 0 && contactname != 'Name' && contactemail != 'Email Address') {
        //    if(contactemail.match(/^\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,3}$/g)) {
        if (contactemail.match(/^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/g)) {

            // Send info
            $.ajax({
                type: "POST",
                url: "http://www.avz.com.asp1-18.dfw1-2.websitetestlink.com/siteservices.asmx/AddSubscriber",
                data: "{'_name': '" + contactname + "','_email': '" + contactemail + "'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function(msg){
                    // Alert success
                    if (msg.d == "[success]") {
                        alert("Your information has been successfully submitted");
                    }
                    else {
                        alert(msg.d.toString().replace("[error]", ""));
                    }
                },
                error: function (msg) {
                    alert("An error was encountered while processing your request. If the problem persists, please contact the system administrator");
                }
            })
        } else {
            alert("Please enter a valid e-mail address");
        }
    } else {
        alert('All fields required');

    }
    return false;
}
//----------------------//
// End Global Functions //
//----------------------//

//---------------------------//
// Begin Home Page Functions //
//---------------------------//

// Sends and email with data from "Ask An Accountant" form on home page
function Home_AskAccountantEmail(txtName, txtEmail, txtComment) {
    $.ajax({
        type: "POST",
        url: "siteservices.asmx/Home_AskAccountantEmail",
        data: "{'_name': '" + txtName + "','_email': '" + txtEmail + "','_comment': '" + txtComment + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {
            // Alert success
            if (msg.d == "[success]") {
                alert("Your information has been successfully submitted");
            }
            else {
                alert(msg.d.toString().replace("[error]",""));
            }
        },
        error: function (msg) {
            alert("An error was encountered while processing your request. If the problem persists, please contact the system administrator");
        }
    });
}

//-------------------------//
// End Home Page Functions //
//-------------------------//


