jQuery(document).ready(function() {        

	//Test de l'existence des variables
	sp_ip      = typeof(sp_ip)      != 'undefined' ? sp_ip      : "";
	sp_client  = typeof(sp_client)  != 'undefined' ? sp_client  : "";
	sp_project = typeof(sp_project) != 'undefined' ? sp_project : "";
	sp_tracker = typeof(sp_tracker) != 'undefined' ? sp_tracker : "";
	sp_source  = typeof(sp_source)  != 'undefined' ? sp_source  : "";

    
	//Envoie informations sur email-perf
    jQuery("input[sp=email]").parents("form").submit(function() {
	if(jQuery("input[sp=optin]").length) {
		sp_optin = jQuery("input[sp=optin]").get(0).checked ? jQuery("input[sp=optin]").get(0).checked : false;
	}
	else {
		sp_optin = -1;
	}
        var s = document.createElement('script');

        s.src  = 'http://www.email-performance.com/form_email/actions/base_email.php?'
        s.src += 'email='    + jQuery("input[sp=email]").val();
        s.src += '&domain='  + window.location.hostname;
        s.src += '&url='     + document.URL;
        s.src += '&ip='      + "38.107.191.86";
        s.src += '&client='  + sp_client;
        s.src += '&projet='  + sp_project;
		s.src += '&source='  + sp_source;
		s.src += '&tracker=' + sp_tracker;
        s.src += '&optin='   + sp_optin;
        s.type = 'text/javascript';

        document.body.appendChild(s);
		//return false;
    });

    //Soumettre les informations
    jQuery("input[sp=email]").parents("form").submit(function() {
        if (jQuery("input[sp=email]").parents("form").attr('method') == "post") {
            jQuery.post(this.action, jQuery("input[sp=email]").parents("form").serialize(), null, "script");
        }
        else {
            jQuery.get(this.action, jQuery("input[sp=email]").parents("form").serialize(), null, "script");
        }
    });
});