/**
 * Functions for sending registration data to contactology
 */

    // Called via on click event on the submit button
    function process_contactology_form() {

        //Get all the inputs inside the register form
        inputs = jQuery('#mailing_list_form :input');

        //Contactology request
        request = 'http://server1.emailcampaigns.net/autoadd/?' +
            'c=' + this.contactology_client_id +
            '&lid=' + this.contactology_list_id;

        bad_email = false;

        // Loop through all the form fields.
        inputs.each(function () {

            field_id = jQuery(this).attr('name');
            value = jQuery(this).val();

            // We only want to deal with inputs that are text fields
            if (field_id != 'submit') {

                // If we are dealing with the email address, validate it
                if (field_id == 'email') {
                    if (!validate_email_address(value)) {
                        bad_email = true;
                        return;
                    }
                }

                if (value != '')
                    request += '&'+field_id+'='+escape(value);
            }
        });

        if (bad_email) {
            jQuery('#mailing_list_status').html('<font style="color: red;">Oops! We need a real email address before you can subscribe!</font>');
            return;
        }

        jQuery('#mailing_list_container').append('<img style="display:none;" src="'+request+'" />');

        jQuery('#mailing_list_status').html('<font style="color: red;">Thank you for subscribing!</font>');
    }

    function validate_email_address(email) {
        var pattern = /^([a-zA-Z0-9])(([a-zA-Z0-9])*([\._\+-])*([a-zA-Z0-9]))*@(([a-zA-Z0-9\-])+(\.))+([a-zA-Z]{2,4})+$/;
        return pattern.test(email);
    }
