var nn4 = (document.layers)? true : false; // Netscape 4.xx 
var iex = (document.all)? true : false; // IE4+ 
var dom = (document.getElementById && !document.all && !document.layers)? true: false; // compatible DOM, IE 5+, Netscape 6+, Mozilla, Firefox 
var _uid = "";
var _ok = 0;



//---------------------------------------------------------------------
function useHttpResponsePanelState() {
  if (http.readyState == 4) {
		// Do nothing, the state is saved.. Nothing to show
  }
}
//---------------------------------------------------------------------


//---------------------------------------------------------------------
// Etat des rubriques
function toggle(anId, idImg, itemNumber){
	if(window.XMLHttpRequest) // Firefox et autres
	   http = new XMLHttpRequest(); 
	else if(window.ActiveXObject){ // Internet Explorer 
	   try {
				http = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				http = new ActiveXObject("Microsoft.XMLHTTP");
			}
	}
		
	node = document.getElementById(anId);
	if (node.style.visibility=="hidden"){
		// Contenu caché, le montrer
		node.style.visibility = "visible";
		document.getElementById(idImg).style.backgroundImage='url(image/rubriqueVisible.gif)';
		
		if (itemNumber > 5){
			node.style.height = "332px";	
		}else{
			node.style.height = "auto";			
		}
		
		//Sauver l'etat de la rubrique
		http.open("GET", "watchsavestatepanel.php?id=" + anId + "&visible=1", true);
		http.onreadystatechange = useHttpResponsePanelState;
		http.send(null);
		
	}else{
		node.style.visibility = "hidden";
		node.style.height = "0";
		document.getElementById(idImg).style.backgroundImage='url(image/rubriqueHidden.gif)';
		
		//Sauver l'etat de la rubrique
		http.open("GET", "watchsavestatepanel.php?id=" + anId + "&visible=0", true);
		http.onreadystatechange = useHttpResponsePanelState;
		http.send(null);
	}
}
//---------------------------------------------------------------------



//---------------------------------------------------------------------
function thumbsover(anId){
	node = document.getElementById(anId);
	node.style.border = "2px solid #E36203";
	_ok = 0;
}
//---------------------------------------------------------------------


//---------------------------------------------------------------------
function thumbsout(anId){
	node = document.getElementById(anId);
	node.style.border = "2px solid #606060"; 
}
//---------------------------------------------------------------------


//---------------------------------------------------------------------
function showtab(tabIndex){
	if (tabIndex == 1){
		Montre('contentdescription', 1);
		Efface('contentComments',1);
	} else if (tabIndex == 2){
		Efface('contentdescription', 1);
		Montre('contentComments',1);
	} else if (tabIndex == 3){
		Efface('contentdescription', 1);
		Efface('contentComments',1);
	} 
}
//---------------------------------------------------------------------


//---------------------------------------------------------------------
function validOffence() {
  var canGo = true;
  if(document.formoffence.offenceComment.value == "") {
	canGo = false;
  }
  if((document.formoffence.selectOffence.value == "Please select") || (document.formoffence.selectOffence.value == "")) {
	canGo = false;
  }  
  
  if (canGo == false){
  	alert("You must fill all the fields");
  }
  return canGo;
}
//---------------------------------------------------------------------


//---------------------------------------------------------------------
function validOffenceMAIL() {
  var canGo = true;
  if(document.formoffence.offenceComment.value == "") {
	canGo = false;
  }
  if(document.formoffence.emailoffence.value == "") {
	canGo = false;
  }
  if((document.formoffence.selectOffence.value == "Please select") || (document.formoffence.selectOffence.value == "")) {
	canGo = false;
  }  
  
  if (canGo == false){
  	alert("You must fill all the fields");
  }
  return canGo;
}
//---------------------------------------------------------------------


//---------------------------------------------------------------------
function showOffence(Index){
	if (Index == 1){
		Montre('OffenceTab', 1);
	} else {
		Efface('OffenceTab', 1);
	}
}
//--------------------------------------------------------------------


//---------------------------------------------------------------------
// Count characters in the comment textarea
function countchar(id, NbCar){
	var nbcar = document.formpostcomment.postText.value.length;
	var myText = document.formpostcomment.postText.value;
	var mystr = String(500 - nbcar) + " Characters left" ;

	if (nbcar >= 500) document.formpostcomment.postText.value = myText.substring(0,499);

	if (dom) { 
		document.getElementById("leftchar").innerHTML = mystr;} 
	else if (iex) { 
		document.all["leftchar"].innerHTML = mystr;} 
	else if (nn4) { 
		document.layers["leftchar"].innerHTML = mystr;
	} 
}
//---------------------------------------------------------------------




//---------------------------------------------------------------------
function useHttpResponseVoted() {
  if (http.readyState == 4) {
    var textout = http.responseText;
	if (dom) { 
		document.getElementById("divVote").innerHTML = http.responseText;} 
	else if (iex) { 
		document.all["divVote"].innerHTML = http.responseText;} 
	else if (nn4) { 
		document.layers["divVote"].innerHTML = http.responseText;
	} 
	getRate(_uid);
  }
}
//---------------------------------------------------------------------


//---------------------------------------------------------------------
// Validation  du rate
function validRate(rate, uid){ 
	_uid = uid;
	if(window.XMLHttpRequest) // Firefox et autres
	   http = new XMLHttpRequest(); 
	else if(window.ActiveXObject){ // Internet Explorer 
	   try {
                http = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                http = new ActiveXObject("Microsoft.XMLHTTP");
            }
	}
	
	http.open("GET", "postrate.php?v=" + _uid + "&rate=" + rate, true);
  	http.onreadystatechange = useHttpResponseVoted;
  	http.send(null);
}
//---------------------------------------------------------------------



//---------------------------------------------------------------------
function useHttpResponseGetRate() {
  if (http.readyState == 4) {
    var textout = http.responseText;
	if (dom) { 
		document.getElementById("videorate").innerHTML = textout;} 
	else if (iex) { 
		document.all["videorate"].innerHTML = textout;} 
	else if (nn4) { 
		document.layers["videorate"].innerHTML = textout;} 
  }
}
//---------------------------------------------------------------------

//---------------------------------------------------------------------
function getRate(uid){
	if(window.XMLHttpRequest) // Firefox et autres
	   http = new XMLHttpRequest(); 
	else if(window.ActiveXObject){ // Internet Explorer 
	   try {
                http = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                http = new ActiveXObject("Microsoft.XMLHTTP");
            }
	}
	http.open("GET", "getrate.php?v=" + uid, true);
  	http.onreadystatechange = useHttpResponseGetRate;
  	http.send(null);
}
//---------------------------------------------------------------------



//---------------------------------------------------------------------
function useHttpResponseGetNBComments() {
  if (http.readyState == 4) {
    var textout = http.responseText;
	if (dom) { 
		document.getElementById("menu").innerHTML = textout;} 
	else if (iex) { 
		document.all["menu"].innerHTML = textout;} 
	else if (nn4) { 
		document.layers["menu"].innerHTML = textout;} 
		
	RoundedTop("div#nav li","transparent","#2D2D2D");	
  }
}
//---------------------------------------------------------------------

//---------------------------------------------------------------------
function getNbComments(uid){
	_uid = uid;
	if(window.XMLHttpRequest) // Firefox et autres
	   http = new XMLHttpRequest(); 
	else if(window.ActiveXObject){ // Internet Explorer 
	   try {
                http = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                http = new ActiveXObject("Microsoft.XMLHTTP");
            }
	}
	http.open("GET", "getNbComments.php?v=" + uid, true);
  	http.onreadystatechange = useHttpResponseGetNBComments;
  	http.send(null);
}
//---------------------------------------------------------------------

//---------------------------------------------------------------------
function rate(starCount){
	if (starCount == 1){
			afficheselectionPicture('rate1', 'stargreen.gif');
	}if (starCount == 2){
			afficheselectionPicture('rate1', 'stargreen.gif');
			afficheselectionPicture('rate2', 'stargreen.gif');
	}if (starCount == 3){
			afficheselectionPicture('rate1', 'stargreen.gif');
			afficheselectionPicture('rate2', 'stargreen.gif');
			afficheselectionPicture('rate3', 'stargreen.gif');
	}if (starCount == 4){
			afficheselectionPicture('rate1', 'stargreen.gif');
			afficheselectionPicture('rate2', 'stargreen.gif');
			afficheselectionPicture('rate3', 'stargreen.gif');
			afficheselectionPicture('rate4', 'stargreen.gif');
	}if (starCount == 5){
			afficheselectionPicture('rate1', 'stargreen.gif');
			afficheselectionPicture('rate2', 'stargreen.gif');
			afficheselectionPicture('rate3', 'stargreen.gif');
			afficheselectionPicture('rate4', 'stargreen.gif');
			afficheselectionPicture('rate5', 'stargreen.gif');
	}
}
//---------------------------------------------------------------------


//---------------------------------------------------------------------
function unrate(){
			afficheselectionPicture('rate1', 'stargreen16empty.gif');
			afficheselectionPicture('rate2', 'stargreen16empty.gif');
			afficheselectionPicture('rate3', 'stargreen16empty.gif');
			afficheselectionPicture('rate4', 'stargreen16empty.gif');
			afficheselectionPicture('rate5', 'stargreen16empty.gif');
}
//---------------------------------------------------------------------


//---------------------------------------------------------------------
function afficheselectionPicture(melement, myPicture){
if (dom) { 
	document.getElementById(melement).style.backgroundImage='url(image/' + myPicture +')';} 
	else if (iex) { 
	document.all[melement].style.backgroundImage='url(image/' + myPicture +')';} 
	else if (nn4) { 
	document.layers[melement].backgroundImage='url(image/' + myPicture +')';} 
}
//---------------------------------------------------------------------

//---------------------------------------------------------------------
function Montre(valeur,b){
	if (dom){ 
		document.getElementById(valeur).style.visibility="visible"; 
		if (b == 1) document.getElementById(valeur).style.display=""; 
	} else if (iex) { 
		document.all[valeur].style.visibility="visible";
		if (b == 1) document.all[valeur].style.display="";
	} else if (nn4) { 
		document.layers[valeur].visibility="visible";
		if (b == 1) document.layers[valeur].display="";
	} 
}
//---------------------------------------------------------------------
//---------------------------------------------------------------------
function Efface(valeur, b){
	if (dom){ 
		document.getElementById(valeur).style.visibility="hidden"; 
		if (b == 1) document.getElementById(valeur).style.display="none"; 
	} else if (iex) { 
		document.all[valeur].style.visibility="hidden";
		if (b == 1) document.all[valeur].style.display="none";
	} else if (nn4) { 
		document.layers[valeur].visibility="hidden"; 
		if (b == 1) document.layers[valeur].display="none";
	} 
}
//---------------------------------------------------------------------



//---------------------------------------------------------------------
function openVideo(mylink){
	if (_ok == 0) location.replace(mylink);
}
//---------------------------------------------------------------------










//---------------------------------------------------------------------
function useHttpResponseCommentPosted() {
  if (http.readyState == 4) {
  	var myText = http.responseText;
	if (myText.substring(0,13) == "ERRORLIMITMAX") alert("You can't post more than 20 comments for the same video in the same day.");
	myText = myText.replace(/ERRORLIMITMAX/, "");
	
	if (dom) { 
		document.getElementById("allComments").innerHTML = myText;
		document.getElementById("leftchar").innerHTML = "";} 
	else if (iex) { 
		document.all["allComments"].innerHTML = myText;
		document.all["leftchar"].innerHTML = "";} 
	else if (nn4) { 
		document.layers["allComments"].innerHTML = myText;
		document.layers["leftchar"].innerHTML = "";
	} 
  	getNbComments(_uid);
	document.formpostcomment.postText.value = "";
  }
}
//---------------------------------------------------------------------

//---------------------------------------------------------------------
// Post a new comment
function postComment(videoId){ 
	_uid = videoId;
	var comment = document.formpostcomment.postText.value;
	if (comment.length > 0){
		if(window.XMLHttpRequest) // Firefox et autres
		   http = new XMLHttpRequest(); 
		else if(window.ActiveXObject){ // Internet Explorer 
		   try {
					http = new ActiveXObject("Msxml2.XMLHTTP");
				} catch (e) {
					http = new ActiveXObject("Microsoft.XMLHTTP");
				}
		}
		
		http.open("GET", "postcomment.php?v=" + videoId + "&comment=" + comment, true);
		http.onreadystatechange = useHttpResponseCommentPosted;
		http.send(null);
	}else{
		alert("You must write your comment before trying to post it");
	}
}
//---------------------------------------------------------------------








//---------------------------------------------------------------------
function useHttpResponsePassPosted() {
  if (http.readyState == 4) {
		var myText = http.responseText;	
		if (myText.substring(0,9) == "Incorrect")
		{
			alert("Incorrect passord");
			document.getElementById('privatepass').value = "";
		}else
		{
			Montre('contentplayer', 1);
			Efface('privateContent',1);
		}
  } // Fin ready state
}
//---------------------------------------------------------------------



//---------------------------------------------------------------------
// Post the password to see private videos
//---------------------------------------------------------------------
function postPrivatePass(mypass,iduser){ 
	if (mypass != ""){
		if(window.XMLHttpRequest) // Firefox et autres
		   http = new XMLHttpRequest(); 
		else if(window.ActiveXObject){ // Internet Explorer 
		   try {
					http = new ActiveXObject("Msxml2.XMLHTTP");
				} catch (e) {
					http = new ActiveXObject("Microsoft.XMLHTTP");
				}
		}
		
		http.open("GET", "postprivatepass.php?password=" + mypass + "&user=" + iduser, true);
		http.onreadystatechange = useHttpResponsePassPosted;
		http.send(null);
	}else{
		alert("You must enter the password.");
	}
}
//---------------------------------------------------------------------



//---------------------------------------------------------------------
function nothingpress(evt) {
			return false;
}
//---------------------------------------------------------------------
