/* *********************************************
   *  pulp'arts  ******  webdesign development *
   *  www.pulp-arts.com - studio@pulp-arts.com *
   *  ---------------------------------------- *
   ********************************************* */
   

// retourne un objet xmlHttpRequest.
// méthode compatible entre tous les navigateurs (IE/Firefox/Opera)

function getXMLHTTP(){
	
	var xhr=null;
	
	if(window.XMLHttpRequest) // Firefox et autres
		xhr = new XMLHttpRequest();
	else if(window.ActiveXObject){ // Internet Explorer
		try {
		xhr = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
			xhr = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e1) {
			xhr = null;
			}
		}
	}
	else { // XMLHttpRequest non supporté par le navigateur
	alert("XMLHTTPRequest Objects are not supported here, consider to upgrade your browser.");
	}

	return xhr;
}

// *******


// l'objet xmlHttpRequest utilisé pour contacter le serveur

var AffichageTV_xmlHttp = null;

var SwitchTV_xmlHttp = null;

// *******


// AFFICHAGE TV *******

function RefreshTV(){
	
	var _AdresseStatutLive = "_inc/affichageTV.php"; // l'adresse à interroger
	//var url="_inc/selection.php?var="+id; // le script à appeller
  
	if(AffichageTV_xmlHttp&&AffichageTV_xmlHttp.readyState!=0){
		AffichageTV_xmlHttp.abort()
	}
	
	AffichageTV_xmlHttp=getXMLHTTP();
  
	if(AffichageTV_xmlHttp){
    	//appel à l'url distante
		AffichageTV_xmlHttp.open("POST",_AdresseStatutLive,true);
		
		AffichageTV_xmlHttp.onreadystatechange=function() {
			if(AffichageTV_xmlHttp.readyState==4) {
					if(AffichageTV_xmlHttp.responseText=='ON') {
						document.getElementById( 'tv' ).innerHTML = "<p style=\"margin:20px\">Loading Live...</p>" ;
						window.location.href = "live/index.php";
					}
			}			
		};
	
		// envoi de la requête
		AffichageTV_xmlHttp.send(null);
	
		// refresh
		setTimeout("RefreshTV()",2000);
	}
	
}


// INITIALISATION TV *******

function InitialiseTV(){
	
	var _AdresseStatutLive = "_inc/initialisationTV.php"; // l'adresse à interroger
	//var url="_inc/selection.php?var="+id; // le script à appeller
  
	if(AffichageTV_xmlHttp&&AffichageTV_xmlHttp.readyState!=0){
		AffichageTV_xmlHttp.abort()
	}
	
	AffichageTV_xmlHttp=getXMLHTTP();
  
	if(AffichageTV_xmlHttp){
    	//appel à l'url distante
		AffichageTV_xmlHttp.open("POST",_AdresseStatutLive,true);
		
		AffichageTV_xmlHttp.onreadystatechange=function() {
			if(AffichageTV_xmlHttp.readyState==4) {
					if(AffichageTV_xmlHttp.responseText=='ON') {
						document.getElementById( 'tv' ).innerHTML = "<p style=\"margin:20px\">Loading Live...</p>" ;
						window.location.href = "live/index.php";
	
					}
					else {
						document.getElementById( 'tv' ).innerHTML = AffichageTV_xmlHttp.responseText ;
						// AFFICHAGE
						RefreshTV();
					}
			}		
		};
	
		// envoi de la requête
		AffichageTV_xmlHttp.send(null);
	}
	
}


// SWITCH TV *******

function SwitchTV(){
	
	var _AdresseSwitchLive = "../_inc/affichageTV.php"; // l'adresse à interroger
	//var url="_inc/selection.php?var="+id; // le script à appeller
  
	if(SwitchTV_xmlHttp&&SwitchTV_xmlHttp.readyState!=0){
		SwitchTV_xmlHttp.abort()
	}
	
	SwitchTV_xmlHttp=getXMLHTTP();
  
	if(SwitchTV_xmlHttp){
    	//appel à l'url distante
		SwitchTV_xmlHttp.open("POST",_AdresseSwitchLive,true);
		
		SwitchTV_xmlHttp.onreadystatechange=function() {
			if(SwitchTV_xmlHttp.readyState==4) {
					if(SwitchTV_xmlHttp.responseText=='OFF') {
						window.location.href = "../index.php";
					}
			}			
		};
	
		// envoi de la requête
		SwitchTV_xmlHttp.send(null);
	
		// refresh
		setTimeout("SwitchTV()",2000);
	}
	
}

function Alerter(){
alert('OK');	
}
