﻿// Constant Contact account creation
// Requires jQuery 1.3.1
//
// Adjust the ccUrl variable for your website (the file must exist and be on the same domain).

var ccUrl = "http://www.shoptwigs.com/ConstantContact.ashx"

// Do not edit anything below this line.
///////////////////////////////////////////////////////////////

function addContact() {

    var email = '', fname = '', lname = '', pcode = '';

    // try to get email from form value
    var els = $('.ccEmail');

    if (els.length > 0) {
        email = els.val();
        if (email != '') {
            els = $('.ccEmailCheck');
            if (els.length > 0) {
                // If checkbox is not checked, exit
                if (els.children(':checked').size() == 0) return false;
            }
            
            els = $('.ccFirstName');
            if (els.length > 0) fname = els.val();
            els = $('.ccLastName');
            if (els.length > 0) lname = els.val();
            els = $('.ccPostCode');
            if (els.length > 0) pcode = els.val();

            // Build the query string
            var query = 'email=' + email + '&fname=' + fname + '&lname=' + lname + '&pcode=' + pcode;
            //alert(query);
            
            // Send the request
            var xhr = $.ajax({
                url: ccUrl,
                data: query,
                dataType: "text",
                success: function(data, status) { if (data.length > 0) alert(data); }
                //  error: function(req, status, err) { alert(err) }
            });
        }
    }
}
