  /**
   * Derived from Apple's suggested sniffer.
   * @param {String} desc e.g. Shockwave Flash 7.0 r61
   * @return {String} 7.0.61
   */
   	var LumiereDiv = document.getElementById('Lumiere');
	LumiereDiv.style.display = "none";
	
function getVersionFlash() { 

  function getFlashVersion(desc) {
    var matches = desc.match(/[\d]+/g);
    matches.length = 3;  // To standardize IE vs FF
	var resultfv = matches.join('.');
    return resultfv;
	//console.log('ext :'+resultfv);
  }

  var hasFlash = false;
  var flashVersion = '';
 
     var mimeType = navigator.mimeTypes['application/x-shockwave-flash'];
    hasFlash = mimeType && mimeType.enabledPlugin;
    if (hasFlash) {
      flashVersion = getFlashVersion(mimeType.enabledPlugin.description);
	 // console.log('flashversion :'+flashVersion);
    }
	  //  var plugin = navigator.plugins['Shockwave Flash'];
	

	
	if (flashVersion) { return flashVersion; }
		else {// return "rien du tout";
	
//	return "pouet";

	try { var ax  = new ActiveXObject("ShockwaveFlash.ShockwaveFlash"); 
	if (ax) { throw "bon"; } else { throw "pasbon"; } 
	}
	
	catch(e) {
		if (e=="bon") {
    // Try 7 first, since we know we can use GetVariable with it
      var ax7 = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.7');
	 var ax6 = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.6');
	  var ax = new ActiveXObject('ShockwaveFlash.ShockwaveFlash');
		
      hasFlash = true;
      flashVersion = getFlashVersion(ax.GetVariable('$version'));
	  flashVersion7 = getFlashVersion(ax7.GetVariable('$version'));
	  flashVersion6 = '6.0.21';
	  
	  if (flashVersion) {
		  return flashVersion;
	  }
	  else {	 
	  			if(flashVersion7) {
									return flashVersion7;  
	  								}
									else { if (flashVersion6) {
											return flashVersion6;	
											}
									}
				  }
		}
	}
	///fini du else
		}

}

var resultat = document.getElementById('avertissementflash');
//console.log(resultat);

//var test = getVersionFlash();
var test = getVersionFlash();

if (test) {
var reg=new RegExp("[.]+", "g");
var versionget = test.split(reg);

//console.log(versionget);

//console.log('test:'+ test);
if( versionget[0]<= 9) { 
resultat.innerHTML= "Mettez à niveau votre lecteur et passez à Flash Player 10 pour pouvoir visualiser les vidéos de la TricTrac TV de façon optimales. <a href='http://www.adobe.com/go/getflashplayer/'>Mettre à niveau maintenant.</a>  (Ceci est un conseil amical de la TTTeam.)";
resultat.style.display = 'block';
}

}

function RemoveAllChilds(target,decalage,parent){
	if( !decalage ){ decalage = 0 ; }
	if(target != undefined){
		while(target.childNodes.length>=(decalage+1)){
			if (parent) {
				target.parentNode.removeChild(target.childNodes[decalage]);
			}
			else {
				target.removeChild(target.childNodes[decalage]);	
			}
		}
	}

}

function thisMovie(movieName) {
         if (navigator.appName.indexOf("Microsoft") != -1) {
             return window[movieName];
         } else {
             return document[movieName];
         }
     }


function VerifLumiere() {
	
		var LumiereDiv = document.getElementById('Lumiere');
		var FlashDiv = document.getElementById("FlashID");
	switch (LumiereDiv.style.display) {
		case "none":

			break;
		case "block":
			console.log(document.getElementById("FlashID"));

			thisMovie("FlashID").sendToActionScript({type:"LumiereVerif",arg1:true});

		
			break;
		default: return "error";
		
		
	}
	
}

function CinemaMode(modeselect) {
	var LumiereDiv = document.getElementById('Lumiere');
/*
	switch (modeselect) {
		case "on":
			LumiereDiv.style.display = "none"; 
			break;
		case "off":
			LumiereDiv.style.display = "block"; 
			break;
		default: LumiereDiv.style.display = "none";

	}
	
	*/
	var opacitytab = new Array();
	opacitytab = [ "0", "0.20", "0.40", "0.60", "0.80", "0.9" ];
	
	LumiereDiv.onclick = function() {
		//console.log(LumiereDiv);
			//RemoveAllChilds(LumiereDiv, 0);	
		//LumiereDiv.style.display = "none";
//		LumiereDiv.style.opacity = 0;
						var i = 6;
				var intervalEteindre = function() {

				LumiereDiv.style.opacity = opacitytab[i];
					if (i==0) {
						LumiereDiv.style.display = "none";
						clearInterval(EteindreOn);
					}
					i--;
				//	console.log(i);
				
				
				}
				 VerifLumiere();
				var EteindreOn = setInterval(intervalEteindre, 100);
				
		
	}
	

	
	if (LumiereDiv.style.display == "none") {
		LumiereDiv.style.display = "block";
		LumiereDiv.style.position = "fixed";
		LumiereDiv.style.height = "100%";
		LumiereDiv.style.width = "100%";
		LumiereDiv.style.backgroundColor = "#000000";
		LumiereDiv.style.zIndex = "998";
		LumiereDiv.style.left = "0";
		LumiereDiv.style.top = "0";
		
		var i = 0;
		var intervalAllumer = function() {
			
		LumiereDiv.style.opacity = opacitytab[i];
		if (i==6) {
				LumiereDiv.style.display = "block";
				clearInterval(AllumerOn);
			}
			i++;
		//	console.log(i);
		}
		var AllumerOn = setInterval(intervalAllumer, 100);

	}
	else {
			if (LumiereDiv.style.display == "block") {
					LumiereDiv.style.position = "fixed";
				LumiereDiv.style.height = "100%";
				LumiereDiv.style.width = "100%";
				LumiereDiv.style.backgroundColor = "#000000";
				LumiereDiv.style.zIndex = "998";
				LumiereDiv.style.left = "0";
				LumiereDiv.style.top = "0";
				
				var i = 6;
				var intervalEteindre = function() {
			
					LumiereDiv.style.opacity = opacitytab[i];
					if (i==0) {
						LumiereDiv.style.display = "none";
						clearInterval(EteindreOn);
					}
					i--;
				//	console.log(i);
				}
				var EteindreOn = setInterval(intervalEteindre, 100);
			
			}
	}
}

function Button(value, width, height){
	var button = document.createElement("input");
	button.setAttribute("type" , "button");
	button.setAttribute("value" , value);
	button.setAttribute("width" , width);
	button.setAttribute("height" , height);
	return button;
}
function Tableau(NumOfColumns,VAlign,Align){
	this.NumOfColumns = NumOfColumns;
	if( VAlign ){
	this.VAlign = VAlign;
	}
	this.Content = document.createElement('table');
	this.Tbody = document.createElement('tbody');
	if( Align ){
	this.Content.align = Align;
	}
	this.Content.appendChild(this.Tbody);
	this.Col = 1;
	/* fonction d'ajout de contenu au tableau */
	this.Add = function( element , width , classe , colspan ){
		/* si on s'apprete à ajouter un element en debut de ligne, on créé celle ci */
		if( this.Col == 1 ){

			var tr = document.createElement('tr'); this.Tbody.appendChild(tr);
		}
		/*création de la cellule, avec le contenu à l'interieur */
		var td = document.createElement('td');
		if( this.VAlign ){
			td.setAttribute("valign",this.VAlign);	
		}
		if( width ){
			td.setAttribute("width" , width );
		}
		if( colspan ){
			
			td.setAttribute("colspan" , colspan );
		}
		if( classe ){
			td.className = classe;
		}else{
			td.className = "Col"+this.Col;
		}
		
		if( element ){
			if( typeof(element) == "object" ){
				td.appendChild(element);
			}else if( typeof(element) == "string" ){
				td.appendChild(Text(element));
			}
		}
		this.Tbody.lastChild.appendChild(td);
		/* si le nombre de colonnes est null on fait qu'une ligne*/
		if( this.NumOfColumns != null ){
		/*si on arrive à la fin de la ligne, la prochaine cellule sera dans une nouvelle ligne */
			if( this.Col == this.NumOfColumns ){
				this.Col = 1;
			}else{
				if( colspan ){
				this.Col += colspan;
				}else{
				this.Col++;
				}
			}
		}else{
			if( colspan ){
			this.Col += colspan;
			}else{
			this.Col++;
			}
		}
		
		return td;
		
	}
	this.AddTh = function( element , width , classe , colspan ){
		/* si on s'apprete à ajouter un element en debut de ligne, on créé celle ci */
		if( this.Col == 1 ){

			var tr = document.createElement('tr'); this.Tbody.appendChild(tr);
		}
		/*création de la cellule, avec le contenu à l'interieur */
		var th = document.createElement('th');
		if( this.VAlign ){
			th.setAttribute("valign",this.VAlign);	
		}
		if( width ){
			th.setAttribute("width" , width );
		}
		if( colspan ){
			th.setAttribute("colspan" , colspan );
		}
		if( classe ){
			th.className = classe;
		}else{
			th.className = "Col"+this.Col;
		}
		
		if( element ){
			if( typeof(element) == "object" ){
				th.appendChild(element);
			}else if( typeof(element) == "string" ){
				th.appendChild(Text(element));
			}
		}
		this.Tbody.lastChild.appendChild(th);
		/* si le nombre de colonnes est null on fait qu'une ligne*/
		if( this.NumOfColumns != null ){
		/*si on arrive à la fin de la ligne, la prochaine cellule sera dans une nouvelle ligne */
			if( this.Col == this.NumOfColumns ){
				this.Col = 1;
			}else{
				this.Col++;
			}
		}else{
			this.Col++;
		}
		
	}
	this.changeTbody = function(){
		this.Col = 1;
		this.Tbody = document.createElement('tbody');
		this.Content.appendChild(this.Tbody);
	}
	this.Clear = function(){
		RemoveAllChilds( this.Tbody );
	}
}
Tableau.prototype.VTransforme = function(){};



function TextArea(name,value){
	var textarea = document.createElement("textarea");
	textarea.setAttribute("name" , name);
	if( value ){
	textarea.value = value;
	}
	return textarea;
}
function Text(text){
	return document.createTextNode(text);
}

function editCom(idEv) {
	if (idEv) {
		
		var comselect = document.getElementById("com_"+idEv);
		if (!comselect.edit && !comselect.del) {
			
			comselect.edit = true;
			if( comselect ){
				
				var data_tmp = comselect.innerHTML;
		
				RemoveAllChilds(comselect);
				
				var TextModif = new TextArea("modif", data_tmp);
				
				var btnCancel = Button("Annuler");
				var btnModif = Button("Modification");
				
				TextModif.style.width = "100%";
				TextModif.style.height = "100px";
				TextModif.style.fontSize = "11px";
				TextModif.style.fontFamily = "Verdana,Geneva,sans-serif";
				comselect.appendChild(TextModif);
				
				var Tabbtn = new Tableau(2);
				
				Tabbtn.Add(btnCancel);
				Tabbtn.Add(btnModif);
				
				
				btnCancel.onclick = function() {
					RemoveAllChilds(comselect);
					comselect.edit = false;
					comselect.innerHTML = data_tmp;		
				}
				
				btnModif.onclick = function() {
					var requete = new ObjXMLHttpRequest();
					var varlist = "operation=edit_com&comment_id="+idEv+"&comment_text="+encodeURIComponent(TextModif.value);
					requete.SendRequest("/ressources/request/request.php" , true , varlist );
					requete.onreadystatechange = function(){
						if( this.readyState == 4 ){
							if( this.status == 200 ){
								if( this.responseText != "error" ){
									var datas = eval('('+this.responseText+')');
									
									if (datas['etat']) {
										if (datas['etat'] == 999) {
												RemoveAllChilds(comselect);
												comselect.edit = false;
												comselect.innerHTML = datas['commentaire'];
										}
										else {
												RemoveAllChilds(comselect);
												comselect.edit = false;
												comselect.innerHTML = data_tmp;
										}
									}
									
								}
							}
						}
					}				
				}
				
				
				comselect.appendChild(Tabbtn.Content);
				
			}
		}	
	}
}
function delCom(idEv) {
	if (idEv) {
		var divselect = document.getElementById('com_'+idEv);
		
		if (!divselect.del && !divselect.edit) {
		var data_original = divselect.innerHTML;
		divselect.del = true;
		RemoveAllChilds(divselect);
		
		var TextDelete = Text("Voulez-vous réellement supprimer ce commentaire ?");
		
		var DelBtn = Button("Supprimer");
		var CancelBtn = Button("Annuler");
		
		CancelBtn.onclick = function() {
			RemoveAllChilds(divselect);
			divselect.innerHTML = data_original;	
			divselect.del = false;
		}
		
		DelBtn.onclick = function() {
			var requete = new ObjXMLHttpRequest();
					var varlist = "operation=del_com&comment_id="+idEv;
					requete.SendRequest("/ressources/request/request.php" , true , varlist );
					requete.onreadystatechange = function(){
						if( this.readyState == 4 ){
							if( this.status == 200 ){
								if( this.responseText != "error" ){
									var datas = eval('('+this.responseText+')');
									
									if (datas['etat']) {
										if (datas['etat'] == 999) {
												RemoveAllChilds(divselect);
												divselect.appendChild(Text("supprimé..."));
												
										}
										else {
												RemoveAllChilds(comselect);
												divselect.del = false;
												divselect.innerHTML = data_original;
										}
									}
									
								}
							}
						}
					}					
		}
		
		var TabDel = new Tableau(2);
		TabDel.Add(CancelBtn);
		TabDel.Add(DelBtn);
		
		divselect.appendChild(TextDelete);
		divselect.appendChild(TabDel.Content);
		
		}
	}
}

