function SF(func) { try { if(eval('window.' + func) != null) return true; else return false; } catch(e) { alert('Failed to execute code: ' + code + '\r\n\r\n' + e.description); } return false; }function GE(v) { if(document.all) return document.all[v]; return document.getElementById(v); }
var imgssearch = new Array(3);imgssearch[0] = new Image();imgssearch[0].src='images/bt_go.gif';imgssearch[1] = new Image();imgssearch[1].src='images/bt_go_o.gif';imgssearch[2] = new Image();imgssearch[2].src='images/bt_go_d.gif';


/* increasing and decreasing text size.
how this works:
1- loop through all of the stylesheets
2 - check if they have a title
3 - check if that title contains "article" (indicates our article stylesheet)
4 - disable all article stylesheets
5 - enable the next size up or down.
6 - exit, enjoy the day.
*/
var sz=13 //default stylesheet
function selectStyleSheet(dir) {
var li; // link items - that is, stylesheets
//make sure we're under limit
if (10<sz+dir&&sz+dir<20){
   for(var i=0; li=document.getElementsByTagName("link")[i]; i++) {
// get stylesheets
     if(li.getAttribute("rel").indexOf("style") != -1 && li.getAttribute("title")) {
      if(li.getAttribute("title").indexOf("article") !=-1) li.disabled = true;
// check if 1 - it's a stylesheet with a title, 2- if it is an article stylesheet, disable it
		if (li.getAttribute("title").indexOf(sz+dir)>-1)li.disabled = false;
// if it's the next in line, enable it
	  }
	 }
//don't forget to increment the size, so we know what's next....
    sz=sz+dir;
   }
  }



function wikidef(url)
{
document.location="zone.php?titre="+url;
}

function nbs(s, o) 
{ 
    if(event != null && event.button > 1)
        return;

    if(o == null && s !== null) 
    {
        if(s.complete == true)
            event.srcElement.src = s.src; 
    }
    else if(s !== null)
    {
        if(s.complete == true)  
            o.src = s.src; 
    }       
}

function valid()
{

	var url=document.search.why.value;
	var text=document.search.string.value;
		{
		document.location=url+text;
		}
	}
	
function HomePage(obj)
{
	obj.style.behavior='url(#default#homepage)';
	obj.setHomePage('http://www.scarla.net/');
}

function PopupImage(img) {
	titre="Scarla";
	w=open("",'image','width=400,height=400,toolbar=no,scrollbars=no,resizable=yes');	
	w.document.write("<HTML><HEAD><TITLE>"+titre+"</TITLE></HEAD>");
	w.document.write("<SCRIPT language=javascript>function checksize()  { if (document.images[0].complete) {  window.resizeTo(document.images[0].width+12,document.images[0].height+30); window.focus();} else { setTimeout('check()',250) } }</"+"SCRIPT>");
	w.document.write("<BODY onload='checksize()' leftMargin=0 topMargin=0 marginwidth=0 marginheight=0><IMG src='"+img+"' border=0>");
	w.document.write("");
	w.document.write("</BODY></HTML>");
	w.document.close();
}

function Favoris()
{
	window.external.AddFavorite('http://www.scarla.net', 'Scarla');
}
function changeimg(nom,source){
	nom.src=source;
}

/* DEBUT MODIFICATION TRANSPARENCE */

var TabAlpha=new Array();
TabAlpha.length=22;
for (var alphaI=0;alphaI<TabAlpha.length;alphaI++) {
	TabAlpha[alphaI]=-1;
}
function ModifAlpha(no,alpha){
	if (document.images["img"+no]) {
		if (document.images["img"+no].filters) {
			TabAlpha[no]=alpha;
			if (tjstimer==0) {setTimeout("tjstimerAlpha()",50)}
		}
	}
}
var tjstimer=0;
function tjstimerAlpha(){
	var opacity=0;
	for (var alphaI=0;alphaI<TabAlpha.length;alphaI++) {
		if (TabAlpha[alphaI]!=-1) {
			opacity =TabAlpha[alphaI] - document.images["img"+alphaI].filters.alpha.opacity;
			if (opacity!=0) {
				tjstimer=1;
				document.images["img"+alphaI].filters.alpha.opacity+=Math.abs(opacity)/opacity * 5;		
			} else {
				TabAlpha[alphaI]=-1
			}
		}
	}
	if (tjstimer==1) {setTimeout("tjstimerAlpha()",45);} else {tjstimer=0}
}
/* FIN MODIFICATION TRANSPARENCE */

/* DEBUT MONTRE/MASQUE VOIR/DEBATRE */

function whatsup()
{
	document.getElementById("whatsup").className = 'montrediv';
	document.getElementById("forumlive").className = 'cachediv';
}
function forumlive()
{
	document.getElementById("forumlive").className = 'montrediv';
	document.getElementById("whatsup").className = 'cachediv';
}

ens_voir_on= new Image();
ens_voir_on.src="images/ens_voir_on.gif";

ens_voir_off=new Image();
ens_voir_off.src="images/ens_voir_off.gif";

ens_deb_on= new Image();
ens_deb_on.src="images/ens_deb_on.gif";

ens_deb_off= new Image();
ens_deb_off.src="images/ens_deb_off.gif";

// Change l'image au passage de la souris
function enschange(thenum){
   var theimgs
   theimgs= new Array("", "ens_voir","ens_deb")
   for (var i=0;i<3;i++){
         if (i==thenum) {
            ImgOn(theimgs[i]);
         } else {
            ImgOff(theimgs[i]);
         }
   }                       
   
}

function ImgOn (theimage){
   if (theimage != "") {
      document[theimage].src= eval(theimage + "_on.src");
   }
}
function ImgOff (theimage){
   if (theimage != "") {
      document[theimage].src= eval(theimage + "_off.src");
   }
}

/* FIN MONTRE/MASQUE VOIR/DEBATRE */


/* Notation */

var xhr_object = null;
	
if(window.XMLHttpRequest){ // Firefox
	xhr_object = new XMLHttpRequest();
} else if(window.ActiveXObject){ // Internet Explorer
	xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
} else { // XMLHttpRequest non supporté par le navigateur
	alert("Votre navigateur ne suporte pas l'obejt XMLHttpRequest");
}

StarOutUrl =		'images/StarOut.gif';		//image par défaut
StarOverUrl =		'images/StarOver.gif';		//image d'une étoile sélectionnée

StarBaseId =		'Star';			//id de base des étoiles
NbStar =			5;			//nombre d'étoiles
note = 0;
var ajax_url = "";
LgtStarBaseId=StarBaseId.lastIndexOf('');

function setStarURL(off, on){
	StarOutUrl = off;
	StarOverUrl = on;
}

function setAjaxURL(url){
	ajax_url = url;
}

function NotationSystem() {
	for (i=0;i<NbStar+1;i++) {
		var img	= document.getElementById('Star'+i);
		if(img){
			img.onclick	= function() {
				
				note = Name2Nb(this.id)*1;
				
				if(xhr_object != null){
					xhr_object.open("POST", ajax_url , false);
					xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
					xhr_object.send(makeParam());
					if(xhr_object.readyState == 4){
						if(xhr_object.responseText != ""){
							alert(xhr_object.responseText);
						}
					}
				}
				StarOut(this.id);
			};
			//Réaction lors du clic sur une étoile
			//Evidemment, il faudrait compléter cette fonction pour la rendre vraiment utile.
			//Par exemple, envoyer la note dans une base de donnée via un XMLHttpRequest.
			
			img.alt			='Donner la note de '+i;
			//Texte au survol
			if(i != 0){
				img.src			= StarOutUrl;
			}
			img.onmouseover	= function() {StarOver(this.id);};
			img.onmouseout	= function() {StarOut(this.id);};
		}
		
	}
	init_note();
}

function StarOver(Star) {
	StarNb=Name2Nb(Star);
	for (i=1;i<(StarNb*1)+1;i++) {
		document.getElementById('Star'+i).src=StarOverUrl;
	}
	
	for (i=(StarNb*1)+1;i<NbStar+1;i++){
		document.getElementById('Star'+i).src=StarOutUrl;
	}
}

function StarOut(Star) {
	for (i=1;i<(note+1)+1;i++) {
		document.getElementById('Star'+i).src=StarOverUrl;
	}
	for(i=(note+1);i<=NbStar;i++){
		document.getElementById('Star'+i).src=StarOutUrl;
	}
}

function setNote(user_note){
	note = user_note*1;
	init_note();
}

function init_note(){
	for(i=1;i<=note;i++){
		document.getElementById('Star'+i).src=StarOverUrl;
	}
}

function Name2Nb(Star) {
	//Le survol d'une étoile ne nous permet pas de connaître directement son numéro
	//Cette fonction extrait donc ce numéro à partir de l'Id
	StarNb=Star.slice(LgtStarBaseId);
	return(StarNb);
}

onload = function () {
	NotationSystem();
}




/* COntrôles */ 


function verifMail(champ){
	var value = document.getElementById(champ).value;
	
	if (value.indexOf("@") != "-1" && value.indexOf(".") != "-1" && value != ""){
		return true;
	}

	return false;
}



/***************************************************************************************************************/
/* PORTAIL DES ARTISTES */

var selectedArtiste = '*';

function changeList(start,uri){
	if(xhr_object != null){
		xhr_object.open("POST", "ajax/list_artistes.php?uri="+uri, false);
		xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xhr_object.send("start="+start);
		if(xhr_object.readyState == 4){
			var text = xhr_object.responseText;
			document.getElementById('artiste-list').innerHTML = text;
			document.getElementById('select-'+selectedArtiste).style.fontWeight="normal";
			document.getElementById('select-'+selectedArtiste).style.color="#5E6AC4";
			document.getElementById('select-'+start).style.fontWeight="bold";
			document.getElementById('select-'+start).style.color="red";
			selectedArtiste = start;
		}
	} else {
		alert('Erreur Ajax');
	}
}

function search_artiste(uri){
	if(xhr_object != null){
		xhr_object.open("POST", "ajax/search_artistes.php?uri="+uri, false);
		xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xhr_object.send("artiste="+document.getElementById('artiste').value);
		if(xhr_object.readyState == 4){
			var text = xhr_object.responseText;
			document.getElementById('search-list').innerHTML = text;
		}
	} else {
		alert('Erreur Ajax');
	}
}

function showlayer(layer){
	var myLayer = document.getElementById(layer);
	if(myLayer.style.display=="none" || myLayer.style.display==""){
		myLayer.style.display="block";
		document.getElementById(layer+'_image').src = 'images/tab-left-close.gif';
	} else {
		myLayer.style.display="none";
		document.getElementById(layer+'_image').src = 'images/tab-left.gif';
	}
}

/*******************************************************************************************/
/**
 * Fonction permettant de changer de répertoire dans le gestionnaire d'images
 */
function changedir(new_path){
  if(document.getElementById('change_dir') && document.getElementById('image_add')){
	  document.getElementById('change_dir').value = new_path;
	  document.getElementById('image_add').submit();
	}
}
