if (typeof(pa) == "undefined" ) { var pa = ""; }

function basename(path) {
    return path.replace( /.*\//, "" );
}

function dirname(path) {
    return path.match( /.*\// );
}

function writediv(message) {
	document.getElementById("message").innerHTML = message;
	document.getElementById("message").style.visibility = "visible";
	document.location="#message"; 
}

function supprimer (type, nom) {
		switch (type){
			case 'categorie' : 
				if(confirm("voulez vous réellement supprimer la categorie "+ nom)) {
					message = "La categorie "+nom+" a bien été supprimée";
					writediv(message);
					alert ("oui")
					return true;
				}
				
				break;
			default : break;
		}
	return false;
}

function file(fichier, sync) {
	if(window.XMLHttpRequest) // FIREFOX
		xhr_object = new XMLHttpRequest();
	else if(window.ActiveXObject) // IE
		xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
	else
		return(false);		
	xhr_object.open("GET", fichier, sync);
	xhr_object.send(null);
	if(xhr_object.readyState == 4)
	return(xhr_object.responseText);
	else return(false);
}


function getVar(key) {
	file_url = atob(this.pa)+"/inc/get_variable.php?ckey="+key;
	texte = file(file_url,false);
	return texte;
}


function majVote(texte, vote_moyenne, video) {
	// alert("texte : "+texte+" | "+(16*vote_moyenne) + "px");
	document.getElementById("infos_vote_" + video).innerHTML = texte;
	document.getElementById("taille_vote_" + video).style.width = (16*vote_moyenne) + "px";
}

function voter (video, note) {
	if (note != "") {
		var file_url = atob(this.pa)+"/inc/vote_ajax.php?key="+escape(video)+"&note="+escape(note);
		// alert(file_url);
	 	texte = file(file_url,false);
		
			// alert("texte : "+texte);
		
		if (texte != "") {
			
			// alert("blabla");
			
			tab = texte.split("|");
			vote_moyenne = tab[0];
			vote_nb = tab[1];
			deja_vote = tab[2];
			affiche = "Note " + vote_moyenne + "/5";
			
			// alert("deja_vote : "+deja_vote);
			
			if (deja_vote == "oui") { affiche = "<font color='red'>D&eacute;j&agrave; vot&eacute;!</font>"; }
			majVote(affiche, vote_moyenne, video);
		}
	}
}

function CookieExist(CookieName) {
	cookieinfo = document.cookie;
	if (cookieinfo.indexOf(CookieName) == -1) {
		return false;
	} else {
		return true;
	}
}

function SetCookie(CookieName,CookieArgs,CookieExpire) {
	document.cookie = CookieName + "=" + CookieArgs + ";" + "expires=" + CookieExpire;
}

function GetCookie(CookieName) {
	if ( CookieExist(CookieName) ) {
		d = cookieinfo.indexOf(CookieName) + CookieName.length + 1;
		f = cookieinfo.indexOf(";",d);
		if ( f == -1) {
			f = cookieinfo.length;
		}
		return (cookieinfo.substring(d,f));
	} else {
		return ("0");
	}
}

function stats ( id_out, aff_pub) {
	url_in = atob(this.pa)+"/inc/stats/clic.php";
	url_out = atob(this.pa)+"/inc/stats/out.php";
	if (id_out != "") {
		error_out = file(url_out+"?ids="+escape(id_out),true);
	}
	error_in = file(url_in,true);
	/* alert(error_in);*/
	
	if (aff_pub == "1") {	
		/* alert("cookie : "+GetCookie("_popup250x250")); */ 
		if (GetCookie("_popup250x250") != 1) {
			window.open(atob(this.pa)+'/promo/popup_250x250.html','PUBLICITE','width=250,height=250');
			SetCookie("_popup250x250", 1, "");
		}
	}
}

function stats_page_in (id_page_in, aff_pub) {
	error_in = file(atob(this.pa)+"/inc/stats/clic.php?id_page_in="+escape(id_page_in),true);
	
	if (aff_pub == "1") {	
		if (GetCookie("_popup250x250") != 1) {
			window.open(atob(this.pa)+'/promo/popup_250x250.html','PUBLICITE','width=250,height=250');
			SetCookie("_popup250x250", 1, "");
		}
	}
}

function afficheBloc(id_du_div) {
	var oDiv = document.getElementById(id_du_div);
	if (oDiv.style.display == "none") {
		oDiv.style.display="";
	} else {
		oDiv.style.display="none";
	}	
}

function compterCaracteres (champ_textarea,nbcar) {
	var nb = champ_textarea.value.length;
	document.getElementById(nbcar).value = nb;
}

function ouvrir_popup (url) {
	winwidth = screen.availWidth - 10;
	winheight = screen.availHeight - 30;
	window.open(url, '_blank', 'scrollbars=yes, width=' + winwidth + ', height=' + winheight + ', top=0, left=0, resizable');
} 

function favoris (nom, url) {
	if ( navigator.appName != 'Microsoft Internet Explorer' ) {
 		window.sidebar.addPanel(nom,url,"");
  } else {
		window.external.AddFavorite(url,nom);
  }
}