/************************************************
* MaToolBox v0.2 — Nicolas Feschotte 27/01/2010 *
* need JQUERY 1.4.1                             *
************************************************/


// TEST
/* affichage / masque forcé ou non d'un obj */
function swap_obj(obj) {
	if($(obj).css('diplay') == 'none') $(obj).css('diplay', 'block');
	else $(obj).css('diplay', 'none');
}


/* 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(); 
}


/* blocage de la touche enter/return */
/* uncomment pour activer le blocage */
//if (document.layers) document.captureEvents(Event.KEYPRESS)

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); }
}

// on source rollOver maBox:obj switch display & follow mouse 
function flyOver(source, maBox, mX, mY) {
	$(maBox).hide();
	$(source).mousemove(function(e) {
		modifX = modif_flyOver(e.pageX, mX, $(window).width(), $(maBox).width());
		modifY = modif_flyOver(e.pageY, mY, $(window).height(), $(maBox).height());
		$(maBox).show();
		$(maBox).css({
			left: (modifX) + "px",
			top: (modifY) + "px"
		});
	});
	$(source).mouseout(function(e){
		$(maBox).hide();
	});	
	
}
// move the box to coord:mouse + mod:size
// if the mouse closer to browser border, move the box to coord:mouse - box:size - mod:size
function modif_flyOver(coord, mod, wT, bT) {
	newMod = coord + mod;
	if (coord > wT - bT) {
		newMod = coord - bT - mod;
	}
	return newMod;
}
