
// CONFIGURATION---------------------------------------------------------------------------

var xmlFile = "http://www.cournon-auvergne.fr/extension/cournon/export.xml"; //l'url du fichier XML enregistré chez vous
var isAffiche = true; //mettre "false" si ne pas afficher, "true" sinon
var isCasting = true; //mettre "false" si ne pas afficher, "true" sinon
var isSynopsis = true; //mettre "false" si ne pas afficher, "true" sinon
var isBandeAnnonce = true; //mettre "false" si ne pas afficher, "true" sinon
var couleurSeances = "#FF0000";
var petitePolice = "0.8em";

// FIN DE CONFIGURATION--------------------------------------------------------------------


// NE PAS TOUCHER !!
document.write ('<script type="text/javascript" src="http://www.allocine.fr/js/Fenetres.js"></script>');

ACAjax = {};
ACAjax.Request = function(url, options){
	var request = null;
	var tentatives = [
		function(){return new XMLHttpRequest();},
		function(){return new ActiveXObject("Msxml2.XMLHTTP");},
		function(){return new ActiveXObject("Microsoft.XMLHTTP");},
		];
	for (i=0;(null==request)&&i<tentatives.length;i++)
	{
		try{
			request = tentatives[i]();
		}
		catch(e){
			continue;
		}
	}
	if (null == request)
		throw new Error("XmlHttp non supporté");
	options = options||{};
	request.onreadystatechange = function() {
        if (request.readyState == 4)
			if ( (request.status == 200) && (options.onSuccess) )
	            options.onSuccess(request);
			else if (options.onFailure)
				options.onFailure(request)
    }
	options.method = options.method || "get";
	switch(options.method.toLowerCase()){
		case "get":
		    request.open(options.method.toUpperCase(), ACAjax.sameDomain(url) + (options.parameters?("?" + options.parameters):""), true);
			request.send(null);
			break;
		case "post":
		    request.open(options.method.toUpperCase(), ACAjax.sameDomain(url), true);
			request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			request.setRequestHeader("Content-Length", (options.parameters?("'" + options.parameters.length + "'"):"0"));
			request.send(options.parameters||"");
			break;
		default:
			break;
	}
}

ACAjax.sameDomain = function(url){
	return url.replace(/^[^/]+\/\/[^/]+/,
		window.location.protocol
		+ "//"
		+ window.location.host
		+ (window.location.port?(":" + window.location.port):"")
	);
}

ACAjax.EncodeParameters = function(parameters){
	if ("object" == typeof parameters){
		var ar = [];
		for (name in parameters){
			var value = parameters[name].toString();
			ar.push(encodeURIComponent(name).replace(/%20/,"+") + '=' +
				encodeURIComponent(value).replace(/%20/,"+"));
		}
		return ar.join("&");
	}
	else
		return "";
}

function xmlGetValue(xmldoc, nodename, nodenum, attname)
{if (xmldoc)
 {if (xmldoc.getElementsByTagName(nodename))
  {if (xmldoc.getElementsByTagName(nodename)[nodenum])
   {if (attname==null || attname=='') {
   		var content =  xmldoc.getElementsByTagName(nodename)[nodenum].text;
   		return content;
   	}
    else {
    	var content = xmldoc.getElementsByTagName(nodename)[nodenum].attributes.getNamedItem(attname).value;

    	//re = new RegExp("[^\x20-\x7E]",'g');
    	//content = content.replace(re, '~');
    	
    	return content;
    }
   }
  }
 }
}

function WriteSeances(xmlSTimes)
{
	var tempSeances = '';
	var nbFilms = xmlSTimes.getElementsByTagName("film").length;
	for (j=0; j<nbFilms; j++)
	{
		tempSeances+='<table><tr>'
		//affiche
		if(isAffiche) tempSeances+='<td width="130" height="180" valign="top"><img src="' + xmlGetValue(xmlSTimes,"film",j,"affichette") + '" border="0" style="float:left;clear:both;margin-bottom:15px;margin-right:10px;" /></td>'
		//titre
		tempSeances+='<td valign="top"><b>' + xmlGetValue(xmlSTimes,"film",j,"titre") + '</b>'
		//casting
		if(isCasting){
		tempSeances+='<div style="font-size:'+petitePolice+'; margin-top:5px;">'
		tempSeances+='de ' + xmlGetValue(xmlSTimes,"film",j,"realisateurs") + '<br />'
		tempSeances+='avec ' + xmlGetValue(xmlSTimes,"film",j,"acteurs") + '<br />'
		tempSeances+='</div>'}
		//synopsis
		if(isSynopsis){
		tempSeances+='<div style="font-size:'+petitePolice+'; margin-top:5px;">'
		tempSeances+='(' + xmlGetValue(xmlSTimes,"film",j,"genreprincipal") + ' - ' + xmlGetValue(xmlSTimes,"film",j,"anneeproduction") + ' - ' + xmlGetValue(xmlSTimes,"film",j,"nationalite") + ') ' + xmlGetValue(xmlSTimes,"film",j,"synopsis") + '<br />'
		tempSeances+='</div>'}
		if(isBandeAnnonce){
			if (xmlGetValue(xmlSTimes,"film",j,"video") != ''){
			tempSeances+='<div style="font-size:'+petitePolice+'; margin-top:5px;">'
			tempSeances+='<a href="javascript:FenACVision(' + xmlGetValue(xmlSTimes,"film",j,"video") + ', 1, \'\', \'salles\')">Voir la bande annonce</a><br />'
			tempSeances+='</div>'}
		}
		//allociné (ne pas supprimer)
		tempSeances+='<div style="font-size:'+petitePolice+'; margin-top:5px;">'
		tempSeances+='Plus d\'infos sur <a target="_allocine" href="http://www.allocine.fr/film/fichefilm_gen_cfilm=' + xmlGetValue(xmlSTimes,"film",j,"id") + '.html">' + xmlGetValue(xmlSTimes,"film",j,"titre") + '</a> avec <a href="http://www.allocine.fr/" target="_allocine"><img src="http://a69.g.akamai.net/n/69/10688/v1/img5.allocine.fr/acmedia/skin/allocinev5/logo/allocine-85x26.gif" border="0" alt="AlloCiné" style="vertical-align:middle;" /></a>'
		tempSeances+='</div>'
		//séances
		tempSeances+='<div style="color:'+couleurSeances+'; margin-top:5px;">'
		for (k=0; k < xmlSTimes.getElementsByTagName("film")[j].childNodes.length; k++){
		if (xmlSTimes.getElementsByTagName("film")[j].childNodes[k].nodeName == "horaire_web")	{
			if (undefined != xmlSTimes.documentElement.text) {showtimes = xmlSTimes.getElementsByTagName("film")[j].childNodes[k].text;} 
			else if (undefined != xmlSTimes.documentElement.textContent) {showtimes = xmlSTimes.getElementsByTagName("film")[j].childNodes[k].textContent;}
			else if (undefined != xmlSTimes.documentElement.nodeValue) {showtimes = xmlSTimes.getElementsByTagName("film")[j].childNodes[k].nodeValue;}
			if (showtimes){showtimes = showtimes.replace(/ \| /gi, '#').replace(/\|/gi, '<br />').replace(/#/gi, ' | ');tempSeances+=showtimes}
		}}
		tempSeances+='</div>'
		tempSeances+='</td></tr></table>'
	}
	document.getElementById("allocine_seances").innerHTML = tempSeances;
}
// FIN DE "NE PAS TOUCHER !!"

