/****************************************
* MaToolBox v0.15 — Nicolas Feschotte *
****************************************/

/* récup de l'id d'un obj */
function getID(obj) {
	return MM_findObj(obj);	
}

/* affichage / masque forcé ou non d'un obj */
function affiche_masque(obj,force) {
	target = getID(obj);	
	if(target.style.display!="none") { target.style.display="none"; } 
	else { target.style.display="block"; }
	
	if(force=="show") target.style.display = "block";
	if(force=="hide") target.style.display = "none";
}

/* box l'alerte de confirmation */
function alerte(contenu) {
	return confirm(contenu);
}

/* redim une window */
function resize(percentage_largeur,percentage_hauteur) {
	largeur_ecran = screen.width;
	hauteur_ecran = screen.height;
	new_largeur = (percentage_largeur * largeur_ecran) / 100;
	new_hauteur = (percentage_hauteur * hauteur_ecran) / 100;
	window.resizeTo(new_largeur, new_hauteur);
	
}

/* déplace une window */
function move(topx,topy) {
	window.moveTo(topx,topy);
}

/* coche ou décoche toutes les checkbox du formulaire "form" */
function selectAllChk(form){
	var frm = document.forms[form] ;
	var chk = eval(form+'.checked') ;
	var cpt = eval(form+'.length') ;
	if(cpt) {
		for(i=0;i<cpt;i+=1){
			eval(form+'[i].checked = chk') ;
		}
	} else {
		eval(form+'.checked = chk') ;
	}
}

/* on click tu coche / décoche une box */
function checkmabox(mabox) {
	labox = getID(mabox);
	if (labox.checked == 1) labox.checked = 0;
	else labox.checked = 1;
}

/* verifie la liste des comboxs pour savoir si elles sont déchecked… si c'est le cas on check lastbox */
function verif_box(lastbox, comboxs) {
	var anychecked = false;
	var allbox = comboxs.split(',');
	for (var i=0; i<allbox.length; i++) {
		var abox = getID(allbox[i]);
		if (abox.checked == 1) { anychecked = true; }
	}
	if(anychecked == false) {
		checkmabox(lastbox, 'check');
	}
}

/* recharger ou aller à une page */
function gotoURL(dest) {
	if (dest != null) 
	window.location.href = dest;
	else window.location.href= window.location.href;
}
/* recharger dans une frame */
function gotoURLinFrame(dest, maframe) {
	parent.frames[maframe].window.location = dest; 
}

/* equivalent php de is_set */
function is_set(variablename){
	if(variablename.value == "") {
		return false;
	}
	return true;
}

/* prendre le focus */
function focusON(form,champ) {
	document.forms[form].elements[champ].focus(); 
}

if (document.layers) document.captureEvents(Event.KEYPRESS)

/* blocage de la touche enter/return */
/* uncomment pour activer le blocage */
/*
function process_keypress(e) {
	if(window.event){
		if (window.event.type == "keypress" & window.event.keyCode == 13) return !(window.event.type == "keypress" & window.event.keyCode == 13);
	}
	if(e) {
		if (e.type == "keypress" & e.keyCode == 13)	return !e;
	}
}
document.onkeypress = process_keypress;
*/

/* fonction d'ajout de favoris ie/firefox */
function aj_favoris(nom,adresse) {
	// exemple
	// javascript:void(aj_favoris('Home Staging Europe','http://www.home-staging-europe.fr/'));
	
	if ( navigator.appName != 'Microsoft Internet Explorer' )
	{ window.sidebar.addPanel(nom,adresse,""); }
	else { window.external.AddFavorite(adresse,nom); }
}
