var popin_status = 0 ; $(document).ready(function() { popin_open(); // Closing pop-in // X event! $("#newsletter_popupContactClose").click(function() { popin_close(0); }); // Click out event $("#newsletter_backgroundPopup").click(function() { popin_close(0); }); // Press Escape event $(document).keypress(function(e) { if(e.keyCode==27 && popin_status==1) { popin_close(0); } }); // Action $("#newsletter_validerpop").mousedown(function() { var api_class = "newsletter" ; var api_method = "popin_signup" ; // arguments var email = $("#email").val() ; if ($("#is_newsletter_join").attr('checked')) { var is_newsletter_join = 1 ; } else { var is_newsletter_join = 0 ; } if ($("#is_newsletter_partner_join").attr('checked')) { var is_newsletter_partner_join = 1 ; } else { var is_newsletter_partner_join = 0 ; } $.ajax( { //type: "POST", url: "http://www.lelutinrouge.fr/api.php?class="+api_class+"&method="+api_method+"&email="+URLEncode(email)+"&is_newsletter_join="+is_newsletter_join+"&is_newsletter_partner_join="+is_newsletter_partner_join, cache: false, success:function(html) { $("#email").val('') ; $("#newsletter_popmessage").empty() ; $("#newsletter_popmessage").append(html) ; }, error:function(XMLHttpRequest, textStatus, errorThrows){} }); }); }); function popin_open() { // loads pop-in only if it is disabled if(popin_status == 1) return false ; // Center //request data for centering var windowWidth = document.documentElement.clientWidth; var windowHeight = document.documentElement.clientHeight; var popupHeight = $("#newsletter_popupContact").height(); var popupWidth = $("#newsletter_popupContact").width(); $("#newsletter_popupContact").css({ "position": "absolute", "top": (windowHeight/2-popupHeight/2)+125, "left": (windowWidth/2-popupWidth/2)+225 }); //only need force for IE6 $("#newsletter_backgroundPopup").css({ "height": windowHeight }); // Display $("#newsletter_backgroundPopup").css({ "opacity": "0.7" }); $("#newsletter_backgroundPopup").fadeIn("slow"); $("#newsletter_popupContact").fadeIn("slow"); popin_status = 1 ; } // close pop-in // TODO Youssef : prendre en compte le delay avant la fermeture de la popin function popin_close() { //disables popup only if it is enabled if(popin_status == 0) return ; $("#newsletter_backgroundPopup").fadeOut("slow"); $("#newsletter_popupContact").fadeOut("slow"); popin_status = 0 ; } // http://cass-hacks.com/articles/code/js_url_encode_decode/ function URLEncode(clearString) { var output = ''; var x = 0; clearString = clearString.toString(); var regex = /(^[a-zA-Z0-9_.]*)/; while (x < clearString.length) { var match = regex.exec(clearString.substr(x)); if (match != null && match.length > 1 && match[1] != '') { output += match[1]; x += match[1].length; } else { if (clearString[x] == ' ') output += '+'; else { var charCode = clearString.charCodeAt(x); var hexVal = charCode.toString(16); output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase(); } x++; } } return output; } function URLDecode(encodedString) { var output = encodedString; var binVal, thisString; var myregexp = /(%[^%]{2})/; while ((match = myregexp.exec(output))!= null && match.length > 1 && match[1] != '') { binVal = parseInt(match[1].substr(1),16); thisString = String.fromCharCode(binVal); output = output.replace(match[1], thisString); } return output; }