var LANG=''; var totalPage = 0; // holds an instances of XMLHttpRequest //var xhrObjects = new Array(); // variables that establish how often to access the server var updateInterval = 5; // how many seconds to wait to get new message var errorRetryInterval = 30; // seconds to wait after server error // when set to true, display detailed error messages var debugMode = false; var errorRetryInterval = 30; // seconds to wait after server error function debug(text) {if (debugMode) alert(text);} function loading(objectName){document.getElementById(objectName).innerHTML = "Chargement en coursVeuillez patienter...";} // function that displays a new message on the page function display(objectName, message){ myDiv = document.getElementById(objectName); myDiv.innerHTML = message + "
";} // function that displays an error message function displayError($message, objectName){ // display error message, with more technical details if debugMode is true display(objectName, "Error retrieving the news message! Will retry in " + errorRetryInterval + " seconds." + (debugMode ? "
" + $message : "")); // restart sequence // setTimeout("process();", errorRetryInterval * 1000); } // call server asynchronously function loadXMLDoc(requestType,url,objectName,selectedValue,reqPage){ var xhr = null; // var rnd = Math.random(); var completeUrl ='/nav.php/XML/type/'+requestType; if(url> '') completeUrl = completeUrl+"/"+url; // urlString = completeUrl // +'/rnd/'+rnd; $.ajax({ async : true ,type: "GET" ,url: completeUrl ,dataType: "xml" // ,before:loading(objectName) ,success: function(xmlData){handleResponse(xmlData,requestType,url,objectName,selectedValue,reqPage);} }) } function handleResponse(xml,requestType,url,objectName,selectedValue,reqPage){ switch (requestType){ case "genre": case "topGenre": wGenre(xml,objectName); break; case "album": wAlbums(xml,objectName, requestType,reqPage,url); break; case "albumDetail": wAlbumDetail(xml,objectName); break; case "single": loading(objectName);wSingle(xml,objectName, requestType,reqPage,url); break; case "singleList": wSingleList(xml,objectName, requestType,reqPage,url); break; case "genre": wGenre(xml,objectName); break; case "genreArtist": wGenreArtist(xml,objectName); break; case "albumArtistList": wAlbumArtistList(xml,objectName,requestType,selectedValue,reqPage, url); break; case "optionArtistList": wOptionArtistList(xml,objectName,requestType,selectedValue,reqPage, url); break; case "singleArtistList": wSingleArtistList(xml,objectName,requestType,selectedValue,reqPage, url); break; case "fileArtistList": wFileArtistList(xml,objectName,requestType,selectedValue,reqPage, url); break; case "imageArtistList": wImageArtistList(xml,objectName,requestType,selectedValue,reqPage, url); break; case "artist": wArtistDetail(xml,objectName); break; case "newsList": wNews(xml,objectName,requestType,selectedValue,reqPage, url); break; case "statsArtist": wArtistStats(xml,objectName,requestType,selectedValue,reqPage, url); break; case "search" : case "newItem": wSearchResult(xml,objectName,requestType,selectedValue,reqPage, url); break; } } function loadXMLForm(requestType,objectName,url,selectedValue,divID){ var xhr = null; // var rnd = Math.random(); var completeUrl ='/nav.php/XML/type/'+objectName; if(url> '') completeUrl = completeUrl+"/"+url; $.ajax({ async : true ,type: "GET" ,url: completeUrl ,dataType: "xml" // ,before:loading(objectName) ,success: function(xmlData){generateFormEntries(xmlData,requestType,objectName,selectedValue,divID);} // ,complete:bindBehaviors() }) } function generateFormEntries(xml,requestType,objectName,selectedValue,divID){ switch (requestType){ case "formSelect": buildSelectForm(xml,objectName,selectedValue,divID); break; case "formCheckBox": buildCheckBoxes(xml,objectName,selectedValue,true); break; case "formCheckBoxSingle": buildCheckBoxes(xml,objectName,selectedValue,false); break; case "formRadio": buildRadio(xml,objectName,selectedValue,divID); break; } } // empty a select list content function clearSelectList(objectName) { try{ var select=eval('document.forms[0].'+ objectName); // define witch object to work with while (select.length > 0) select.remove(0); //delete each line of the current select } catch(e){ if(debugMode==1) alert('Clear list error=> ' + e); window.status= "Error (5) Unable to build select";} } function buildSelectForm(xml, objectName,selectedValue,divID) { // alert ("BUILKD SELECT=> object="+objectName + " / size =>"+$("item",xml).length+"selected value=>"+selectedValue); $("#"+objectName).empty(); if($("item",xml).length>0){ $("#"+objectName).addOption('', '', false); $("//items/item", xml).each(function(){ if($('id', this).text()==selectedValue) $("#"+objectName).addOption($('id', this).text(), $('description', this).text(), true); else $("#"+objectName).addOption($('id', this).text(), $('description', this).text(), false); }); } else $("#"+objectName).empty().attr('disable'); } function buildCheckBoxes(xml,objectName,selectedValue,array) { // alert ("inside buicjeck"); if($("item",xml).length>0){ var output= ""; $("//items/item", xml).each(function(){ //alert ("singl==>"+single); // output+="
" + $('description', this).text()+""; }); $("#"+objectName).empty().append(output); } } function buildRadio(xml,objectName,selectedValue,divID) { if($("item",xml).length>0){ var output=''; $("//items/item", xml).each(function(){ output+=""; }); $("#"+divID).empty().append(output); bindBehaviors(); } } // Writting a list of news function wNews(xml,divID, requestType,selectedValue,reqPage, url) { nbPerPage=_NB_NEWS_PER_PAGE; var nbItem = $("item",xml).length; var output=''; var detail=''; if(nbItem>0){ output+="

L'actualité

"; if(nbItem > nbPerPage){ // Handling pagination if (reqPage==undefined || reqPage==null ) reqPage=1; //Define a default page is not defined firstItem = (reqPage * nbPerPage) - nbPerPage //Calculating the first item to display lastItem = firstItem + nbPerPage; if (lastItem >nbItem) lastItem=nbItem; }else { firstItem=0;lastItem =nbItem; } for (var i = firstItem; i < lastItem; i++) { $("//items/item", xml).eq(i).each(function(i){ if ( $('url', this).text()>'') website="
Plus d'information: "+$('url', this).text(); else website=""; output+="
  • "+$('title', this).text() +"
  • "; if($('id', this).text()== selectedValue){ detail= "
    "+$('title', this).text()+"
    "+$('description', this).text()+website; } }); } if(nbItem > nbPerPage){ output +=pagination (nbItem,reqPage, requestType,divID,url);} $("#"+divID).empty().append(output+detail); } else{ if(divID=='announceList') $("#"+divID).empty().append('Aucun élément trouvé pour le moment'); } } // Writting a list of news function wNews_backup(xhr,divID, requestType,selectedValue,reqPage, url) { nbPerPage=_NB_NEWS_PER_PAGE; try{ var req = xhr.responseXML.documentElement; var website=''; nbItem=req.getElementsByTagName("item").length; // nb items if(req.getElementsByTagName("items").length>0) {items = req.getElementsByTagName("item");} var doc = document.getElementById(divID); var output=''; if(nbItem>0){ if(nbItem > nbPerPage){ if (reqPage==undefined || reqPage==null ) reqPage=1; //Define a default page is not defined firstItem = (reqPage * nbPerPage) - nbPerPage //Calculating the first item to display lastItem = firstItem + nbPerPage; if (lastItem >nbItem) lastItem=nbItem; }else { firstItem=0;lastItem =nbItem; } output+="

    Les news

    "; for (var i = firstItem; i < lastItem; i++) { if (arrayVal(items[i], "url")>'') website="
    Plus d'information: "+arrayVal(items[i], "url"); else website=""; if(arrayVal(items[i], "id") == selectedValue){ document.getElementById('newsDetail').innerHTML="
    "+arrayVal(items[i], "title")+"" +"
    "+arrayVal(items[i], "description") +website; } output+="
  • " +arrayVal(items[i], "title") +"
  • "; } if(nbItem > nbPerPage){ // Displaying the number of page output+=pagination (nbItem,reqPage, requestType,divID,url); } doc.innerHTML = output ; } } catch(e){ //if(debugMode==1) alert('writeNews2 =>' + e); window.status= "Error (4) Unable to read Node / " + xhr.readyState +" /"+xhr.status; } } //function arrayVal() function arrayVal(obj,tag){ var element = obj.getElementsByTagName(tag)[0]; if (element.hasChildNodes()) {return unescape (element.firstChild.nodeValue);} else return ''; } // Return am XML node value function getNodeValue(req,tagName, index){ //alert ('tag name=>'+tagName); var element = req.getElementsByTagName(tagName)[index]; if (element.hasChildNodes()) { txt = nl2br(unescape (element.firstChild.nodeValue)); } else txt = ''; return txt;} // This function replace all \n char by a HTML BR function nl2br(myString) {return myString.replace(/\n/g,'
    ');} //pagination (nbItem,reqPage, requestType,objectName,url); function pagination(totalItem,reqPage,requestType,divID,url ){ if (( reqPage > 0) && (reqPage != 'ALL') ) firstItem = reqPage; if (divIsInt(totalItem, nbPerPage) > 0) totalPage = divFloor(totalItem, nbPerPage) +1; else totalPage = divFloor(totalItem, nbPerPage); var txt = "