// Fonction d'ouverture de fenetre popup centree
// Simon - egzakt.com
// 2004-10-28
//
function egz_openwindow(lien,cible,w,h) {
	var _win;
	_win = window.open(lien,cible,'width=' + w + ',height=' + h + ',top=' + (screen.height - 400)/2 + 'left='+ (screen.width - 400)/2);
	_win.moveTo((screen.width - w)/2,(screen.height - h)/2);
	_win.focus();

	return _win;
}

// Fonction d'ouverture de fenetre popup centree
// Simon - egzakt.com
// 2004-10-28
//
function egz_openwindow_param(lien,cible,w,h,param) {
	var _win;
	_win = window.open(lien,cible,param);
	_win.moveTo((screen.width - w)/2,(screen.height - h)/2);
	_win.focus();

	return _win;
}


// Fonction ouverture / fermeture de div
// Emilie 
function showhide(objet,objet_courant,image,classe_courante) {
	
	// cacher
	if (document.getElementById(objet).style.display == 'block') {
		document.getElementById(objet).style.display = 'none';
		document.getElementById(objet).style.visibility = 'hidden';
		if (image) {
			document.getElementById(objet_courant).className = classe_courante;
			document.getElementById(objet_courant).style.backgroundImage = "url('" + image + "_off.gif')";
		}
	}
	
	// montrer
	else {
		document.getElementById(objet).style.display = 'block'
		document.getElementById(objet).style.visibility = 'visible'
		if (image) {
			document.getElementById(objet_courant).className = classe_courante + '_selected';
			document.getElementById(objet_courant).style.backgroundImage = "url('" + image + "_on.gif')";
		}
	}
}
// Fonction ouverture / fermeture de div
// Simon
function showhideClass(objet,objet_courant,image,classe_courante) {

	// cacher
	if (document.getElementById(objet).className == 'displayblock') {
		document.getElementById(objet).className = 'displaynone';
		if (image) {
			document.getElementById(objet_courant).className = classe_courante;
			document.getElementById(objet_courant).style.backgroundImage = "url('" + image + "_off.gif')";
		}
	// montrer
	} else {
		document.getElementById(objet).className = 'displayblock'
		if (image) {
			document.getElementById(objet_courant).className = classe_courante + '_selected';
			document.getElementById(objet_courant).style.backgroundImage = "url('" + image + "_on.gif')";
		}
	}
}

// Fonction bulle
// Emilie  - egzakt.com
// 2006
// Basee sur la fonction de Pat
function bulle(x,y,texte) {
	
	var largeur_box = 150;	
	var fin_box = x + largeur_box;
	var spacer = 20;
			
	if (fin_box > 748) {
		new_x = x - largeur_box - spacer;
	}
	else {
		new_x = x + spacer;
	}
		
	document.getElementById("bulle").style.visibility = "visible";
	document.getElementById("bulle").style.left = new_x + "px";
	document.getElementById("bulle").style.top = y + "px";
	document.getElementById("bulle").innerHTML = texte;
}

function cacher_bulle() {
	document.getElementById("bulle").style.visibility = "hidden";
}

// Simon - egzakt.com
// 2006
// t:input - f:obj form - s:section_id
var action_ori = "";
function rechercher(f){
	if (!action_ori) action_ori = f.action;
	var e = encodeURI(f.mots_cles.value).replace(/\%20/g, '+');
	var s = (f.recherche_par_section.checked ||
			((f.recherche_par_section.type != "checkbox") && (f.recherche_par_section.value == "1")))?f.recherche_section_id.value:1;
	f.action = action_ori + s + "/" + e;
	return true;
}


// Fonction qui change la photo moyenne du modele
// Emilie - egzakt.com
// 2006-08-10
function change_photo_modele(cible,cible_lightbox,photo,path) {
	document.getElementById(cible).src = photo;
	document.getElementById(cible_lightbox).href = photo.replace(path + "ap_",path);
}


// unobtrusive JS
// Simon - egzakt.com
// onmouseover dans la liste des produits (le id est aussi la photo)
var tmid = null;		// timeout apercu
var thislink = null;	// lien actif apercu
var id_imgDest = null;

function attacher_evenement_produit(id_conteneur,evenement,id_imgD){
	if(document.getElementById && document.getElementsByTagName){
		if($(id_conteneur)){
			id_imgDest = id_imgD;
			var links = $(id_conteneur).getElementsByTagName('a');
			for(var i=0; i < links.length; i++ ){
				if (links[i].rel != "") {
					links[i].onmouseover = function(){
						window.clearTimeout(tmid);
						thislink = null;
						this.parentNode.style.position = "relative";
						$(id_imgDest).src = this.rel;
						$("apercu").childNodes[0].className = 'apercuOn';
						$("apercu").className = 'apercuOn'+this.parentNode.parentNode.parentNode.className;
						this.parentNode.appendChild($("apercu")); 
						$("apercu").style.display = "block";
						return false;
					};
					links[i].onmouseout = function(){
						thislink = this;
						tmid = setTimeout("cacher_apercu(thislink)",300);
					};
				}
			}
		}
	}
}
// Simon - egzakt.com
// Fonction pour le timer qui referme l'apercu
function cacher_apercu(l) {
	$(id_imgDest).src = "/images/tuiles/trans.gif";
	$("apercu").style.display = "none";
	l.parentNode.style.position = "";
	$("apercu").childNodes[0].className = 'apercuOff';
	return true;
}


function change_img_rep(id,img,chemin_photo) {
	if (id) {
		document.getElementById(img).style.display = 'inline';
		document.getElementById(img).src = chemin_photo + "rep_" + id + ".jpg";
	} else {
		document.getElementById(img).style.display = 'none';
	}
	return true;
}

function enable_champs(champs,valeur) {
	
	var i, strdisable;
	for(i=0;i<champs.length;i++) {
		document.getElementById(champs[i]).disabled = valeur;
	}
}
