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 = "
Veuillez 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+="" +$('description', this).text()+"
";
});
$("#"+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+="