﻿
function LoadZoom(url) {
    var w = 640;
            var h = 480;
            wleft = (screen.width - w) / 2;
            wtop = (screen.height - h) / 2;
            if (wleft < 0) {
                w = screen.width;
                wleft = 0;
            }
            if (wtop < 0) {
                h = screen.height;
                wtop = 0;
            }
    window.open(url,'zoomWin', 'left=' + wleft + ', top=' + wtop + ',toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=660px,height=480px');
}

//CreateXHR
function CreateXHR() {
    var xhr;
    var factories = [
        function() { return new XMLHttpRequest();},
        function() { return new ActiveXObject("Msxml2.XMLHTTP");},
        function() { return new ActiveXObject("Msxml3.XMLHTTP");},
        function() { return new ActiveXObject("Microsoft.XMLHTTP");
        }];
            
    for (var i=0;i<factories.length;++i) {
        try {
            xhr = factories[i]();
            createXHR = factories[i];
            return xhr; 
        } catch (e) {}
    }
}

//SendMail
function SendMail(mail) {
        try {
        sendMail = document.getElementById(mail).value;
        if (sendMail == '' || sendMail == null) {
            alert('Le mail est manquant.');
            return false;
        }
        document.getElementById('forms').style.display ='none';
        document.getElementById('Traitement').style.display ='block';
        var http = CreateXHR();
        http.open("post","AjaxNewsLetter.aspx",true);       
        http.onreadystatechange = function()
        {
            if (http.readyState ==4) 
            {
                if (http.status == 200) 
                {
                        var xmlDoc= http.responseXML.documentElement;
                        var Status = xmlDoc.getElementsByTagName("Status")[0].childNodes[0].nodeValue;
                                                
                        if (Status == "success") {
                            document.getElementById('Traitement').style.display ='none';
                            document.getElementById('divOk').style.display ='block';
                        }
                        
                        if (Status == "failed") {
                            document.getElementById('forms').style.display ='block';
                            document.getElementById('Traitement').style.display ='none';
                            var Exception = xmlDoc.getElementsByTagName("Exception")[0].childNodes[0].nodeValue;
                            alert(Exception);
                        }
                } else 
                {
                    document.getElementById('forms').style.display ='block';
                    document.getElementById('Traitement').style.display ='none';
                    alert('Erreur application,\r\nContactez votre administrateur.');
                }
            }
        };
        http.setRequestHeader("content-type","application/x-www-form-urlencoded");
        http.send("mail="+sendMail);
    } catch (e) {
        alert(e.message);
    }    
    return false;
}

