var sGlobXML = false;
var bGlobLoad = false;


function kitmapSetXml(xml) {
    var obj = swfobject.getObjectById('kitmap');
    if (obj) {
        obj.setXml(xml);
    }
}


function kitmapReady() {
    bGlobLoad = true;
    if (sGlobXML)
        kitmapSetXml(sGlobXML);
}


function kitmapClickZone(id) {
    var dept = id.substring(1);
    location.href = 'atlasPHP.html?input0103=' + dept + "&formpage=ok";
}


function kitmapClickIcon(id) {
    var atlasid = id.substring(5);
    document.location = "viewFiche.html?id=" + atlasid;
}


/****
var flashvars = {enabled_depts: 'd01,d46'};
var params = {loop: false, menu: false, allowscriptaccess: 'always'};
var attributes = {};
swfobject.embedSWF('inpes.swf', 'kitmap', '400', '440', '8.0.0', 'expressInstall.swf', flashvars, params, attributes);
****/

function testXml() {
    kitmapSetXml(document.forms[0].xmlarea.value);
}

function getPoints (dept, theme, pub) {
    // Ajax
    var xhr = null;
    // Création de l'objet ajax
    try { xhr = new ActiveXObject("Microsoft.XMLHTTP"); } // IE
    catch(e) { xhr = new XMLHttpRequest() }

    // Fonction executée au retour du serveur
    xhr.onreadystatechange = 
        function() {
            if (xhr.readyState == 4) {
                if (xhr.status == 200) {
                    node = xhr.responseXML.getElementsByTagName('dept').item(0);
                    if (node != null) {
                        if (bGlobLoad == true)
                            kitmapSetXml(xhr.responseText);
                        else
                            sGlobXML = xhr.responseText;
//                      kitmapSetXml(xhr.responseXML);
                        return;
                    }
                    alert("Les points sur la cartes ne peuvent être affichés");
                }
                else 
                    alert("Ajax erreur : " + xhr.status);
            }
        };

    // Url de lancement du php
    xhr.open('GET', "getFichesForKitMap.xml?theme=" + theme + "&public=" + pub + "&dept=" + dept, true);
    xhr.send(null);
}
