var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	try {
		xmlhttp = new XMLHttpRequest();
	} catch (e) {
		xmlhttp=false;
	}
}
if (!xmlhttp && window.createRequest) {
	try {
		xmlhttp = window.createRequest();
	} catch (e) {
		xmlhttp=false;
	}
}

/* COMMENTAIRE DES VIDEOS */

function commentaire(video_id, password_video, alias)
{
  xmlhttp.open("POST","/modules/video_commentaires.php",true);
  xmlhttp.onreadystatechange=function() {
   if (xmlhttp.readyState==4) { /* debug => alert(xmlhttp.responseText); */
    if( xmlhttp.responseText == 'champs' )
    { alert("Tous les champs sont obligatoires"); }

    else if( xmlhttp.responseText == 'videos' )
    { alert("Vous ne pouvez pas laisser de commentaire pour cette vidéo"); }
    
    else
    {    
    alert("Commentaire posté");
    document.getElementById('basecommentaire').innerHTML = xmlhttp.responseText;
    document.getElementById('text').value = '';
    }
   }
  }
	xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xmlhttp.send("xmlhttp=1&video_id="+video_id+"&password_video="+password_video+"&alias="+alias+"&text="+document.getElementById('text').value);
 
 return false;
}

/* NOTATION DES VIDEOS */

function notation(video_id, note)
{
  xmlhttp.open("POST","/modules/video_notation.php",true);
  xmlhttp.onreadystatechange=function() {
   if (xmlhttp.readyState==4) { /* debug => alert(xmlhttp.responseText); */
    if( xmlhttp.responseText == 'already' )
    { alert("Vous avez déjà voté pour cette vidéo aujourd\'hui"); }

    else if( xmlhttp.responseText == 'videos' )
    { alert("Vous ne pouvez pas laisser de note pour cette vidéo"); }
    
    else
    {    
    alert("Vidéo noté :) Merci");
    document.getElementById('basenote').innerHTML = xmlhttp.responseText;
    }
   }
  }
	xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xmlhttp.send("xmlhttp=1&video_id="+video_id+"&note="+note);
 
 return false;
}

function uncolor(nb)
{
for(var i=0; i<=nb; i++)
{
if( document.getElementById('ok'+i) )
{ document.getElementById('ok'+i).style.background = 'green'; }

if( document.getElementById('pas_ok'+i) )
{ document.getElementById('pas_ok'+i).style.background = 'red'; }

if( document.getElementById('n'+i) )
{ document.getElementById('n'+i).style.background = 'white'; } 
}
}

function color(nb)
{
for(var i=0; i<=nb; i++)
{
if(document.getElementById('ok'+i)) 
{ document.getElementById('ok'+i).style.background = 'gray'; }

if( document.getElementById('pas_ok'+i) )
{ document.getElementById('pas_ok'+i).style.background = 'gray'; }

if( document.getElementById('n'+i) )
{ document.getElementById('n'+i).style.background = 'gray'; } 
}
}

/* FAVORIS */

function favori_delete(video_id, alias, password)
{
  xmlhttp.open("POST","/modules/favori_delete.php",true);
  xmlhttp.onreadystatechange=function() {
   if (xmlhttp.readyState==4) { /* debug => alert(xmlhttp.responseText); */
    alert("Favori retiré à votre espace personnel");
    document.getElementById('basefavori').innerHTML = '<br  /><a href="/modules/favori_add.php?id_video='+video_id+'&alias='+alias+'&password_video='+password+'" onclick="favori_add('+video_id+', \''+alias+'\', \''+password+'\'); return false;">Ajouter à mes favoris</a>';

   }
  }
	xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xmlhttp.send("xmlhttp=1&video_id="+video_id);
 
 return false;
}

function favori_add(video_id, alias, password)
{
  xmlhttp.open("POST","/modules/favori_add.php",true);
  xmlhttp.onreadystatechange=function() {
   if (xmlhttp.readyState==4) { /* debug => alert(xmlhttp.responseText); */
    if( xmlhttp.responseText == 'videos' )
    {
    	alert('Cette vidéo n\'existe pas');
    }
    else
    {
    alert("Favori ajouté à votre espace personnel");
    document.getElementById('basefavori').innerHTML = '<br  /><a href="/modules/favori_delete.php?id_video='+video_id+'&alias='+alias+'&password_video='+password+'" onclick="favori_delete('+video_id+', \''+alias+'\', \''+password+'\'); return false;">Supprimer de mes favoris</a>';
    }
   }
  }
	xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xmlhttp.send("xmlhttp=1&video_id="+video_id);
 
 return false;
}

function send_friend(video_id, password_video, alias)
{
  xmlhttp.open("POST","/modules/send_to_friend.php",true);
  xmlhttp.onreadystatechange=function() {
   if (xmlhttp.readyState==4) {
    if( xmlhttp.responseText == 'champs' )
    { alert("Tous les champs sont obligatoires"); }
    
    else
    {    
    alert("Nous avons envoyé un e-mail à votre ami(e)!");
    }
   }
  }
	xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xmlhttp.send("video_id="+video_id+"&password_video="+password_video+"&alias="+alias+"&email="+document.getElementById('email').value+"&prenom="+document.getElementById('prenom').value);
 
 return false;
}
