var F_axUrl = "http://www.autobooker.fr/ax";

function Getxhr()
{
 var xhr=null;
    
    if (window.ActiveXObject) 
    {
    
         try
        {
            xhr = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e)
        {
            xhr = new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    else if (window.XMLHttpRequest) { 
        xhr = new XMLHttpRequest();
    }
    return xhr;
}



function changepic(img_name,img_src) {
    //alert(img_name + ":" + img_src + "," + document[img_name]);
    if (document[img_name] != null){
    document[img_name].src=img_src;
    }
//    else
//    alert(img_name + ' '  + img_src);
}

function memcaller(EndUrl)
{
   var xhr=Getxhr();
    xhr.onreadystatechange = function() { refresh_s(xhr); };
    //document.getElementById("message").className="tumevois";
    //prompt(F_axUrl + "/" +EndUrl, F_axUrl + "/" +EndUrl);
    xhr.open("GET", F_axUrl + "/" +EndUrl, true);
    xhr.send(null);
}

function mem(reference)
{
    l_imgname = "star_" + reference.toLowerCase();
    l_add = "1";
    if (document[l_imgname] != null){
        if (document[l_imgname].src.indexOf('s_on.png') > -1 )
        {
            l_add = "0";
        }
        }
    memcaller("favx.php?id=" +reference + "&act=" + l_add);
}

function CheckMem()
{
    l_ids = "";
    for(i=0; i < document.images.length; i++)
    {
    if (document.images[i].src.indexOf('images/s_off.png')  > -1 )
        l_ids += document.images[i].name.substring(5) + "," ;
    }
    memcaller("favx.php?ids=" +l_ids + "&act=3");    
}



function refresh_s(xhr)
{
    if (xhr.readyState==4) 
    {
    	//document.getElementById("message").className="tumevoispas";
    
    	var docXML= xhr.responseXML;
    	var items = docXML.getElementsByTagName("on")
    	//on fait juste une boucle sur chaque element "donnee" trouvé
    	
    	for (i=0;i<items.length;i++)
    	{
    	l_imgname = "star_" + items.item(i).firstChild.data;
   	    changepic(l_imgname.toLowerCase(), "images/s_on.png");
    	}
    	
    	items = docXML.getElementsByTagName("off")
    	for (i=0;i<items.length;i++)
    	{
    	    l_imgname = "star_" + items.item(i).firstChild.data;
    	    changepic(l_imgname.toLowerCase(), "images/s_off.png");
    	}
    	
    	items = docXML.getElementsByTagName("total")
    	for (i=0;i<items.length;i++)
    	{
    	    document.getElementById("notation").innerText = "(" + items.item(i).firstChild.data  + ")"; // for IE
    	    
            document.getElementById("notation").textContent =  "(" + items.item(i).firstChild.data  + ")"; // for the rest of the known world
           
    	    if (items.item(i).firstChild.data == 0)
    	    {changepic("smem", "images/s_off.png");}
    	    else
    	    {changepic("smem", "images/s_on.png");}
    	    
    		
    	}
    }
}




