// SCRIPTS JAVASCRIPT NECESSAIRES AU BON FONCTIONNEMENT DES FONCTIONS AJAX/ WEB2.0 DU SITE

function load_fav(objID, serverPage) {
	win = new Window({className: "mac_os_x", title: "Gestionnaire de favoris", width:460, height:300, destroyOnClose: true, recenterAuto:false});
	win.getContent().update("<strong>Chargement des favoris en cours...</strong>");
	win.showCenter(false,true,true); 
	win.setAjaxContent(serverPage,  { method: 'get'});

}

function delfavoris(idfiche,niveau){
	if(confirm('Voulez-vous vraiment supprimer ce favoris?')) {
		if(!isInteger(idfiche)){ 
			alert('omfg!');
			return true;
		} else {
			var Params = 'idfiche='+encodeURIComponent(idfiche);
			var myAjax = new Ajax.Updater(idfiche, "http://www.power-anime.ca/delfavoris.php", { method: 'get', parameters: Params});
			Effect.SwitchOff(idfiche, { duration: 2.0 });
		}
	} else { 
		return false; 
	}
	return false;
}

function addfavoris(idfiche){
	Element.update('notice_dl', '--- Enregistrement du favoris en cours ---');
	new Effect.Appear('notice_dl' , { duration: 1.4 } );
	var Params = 'idfiche='+encodeURIComponent(idfiche);
	var myAjax = new Ajax.Updater('notice_dl', "http://www.power-anime.ca/addfavoris.php", { method: 'get', parameters: Params , onSuccess:viretoi } );
}

function viretoi(){
	window.setTimeout(effacenotice,5000);
}

function Filtre_Type(ToDisplay) {

     var divs = document.getElementsByTagName('li');
     
     for(var i=0; i<divs.length; i++) {
          if(divs[i].className == 'typeALL') {
               divs[i].style.visible = 'inline';
			} else {
				divs[i].style.visible = 'none';
				if(divs[i].className == ToDisplay) {
					divs[i].style.visible = 'inline';
				}
			}
		}
  
	return false;
}

function effacenotice(){
	new Effect.Fade('notice_dl');
}

function isInteger (s){
	var i;

	if (isEmpty(s))
	if (isInteger.arguments.length == 1) return 0;
	else return (isInteger.arguments[1] == true);

	for (i = 0; i < s.length; i++)
	{
		 var c = s.charAt(i);

		 if (!isDigit(c)) return false;
	}

	return true;
 }

function isEmpty(s){
	return ((s == null) || (s.length == 0))
}

function isDigit (c){
  return ((c >= "0") && (c <= "9"))
}

