//*********** Fonctions AJAX    ********************///		
var ligneFicheProduit = '';

	function getXhr(){
		if(window.XMLHttpRequest) // Firefox et autres
			xhr = new XMLHttpRequest(); 
		else if(window.ActiveXObject){ // Internet Explorer 
			try {
				xhr = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				xhr = new ActiveXObject("Microsoft.XMLHTTP");
			}
		}
		else { // XMLHttpRequest non support&eacute; par le navigateur 
			alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
			xhr = false; 
		} 
	}
	
	function go(value, link, id){
		getXhr()
		// On d&eacute;fini ce qu'on va faire quand on aura la r&eacute;ponse
			xhr.onreadystatechange = function(){
		// On ne fait quelque chose que si on a tout re&ccedil;u et que le serveur est ok
			if(xhr.readyState == 4 && xhr.status == 200){
				response = xhr.responseText;
				document.getElementById(id).innerHTML = response; 
			}
		}	
		
		xhr.open("POST", link ,true);
		xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");                  
		xhr.send(value);
		
	}	
	function goLexique(value, link, id){
		getXhr()
		// On d&eacute;fini ce qu'on va faire quand on aura la r&eacute;ponse
			xhr.onreadystatechange = function(){
		// On ne fait quelque chose que si on a tout re&ccedil;u et que le serveur est ok
			if(xhr.readyState == 4 && xhr.status == 200){
				response = xhr.responseText;
				if(response.length > 0){
					document.getElementById(id).innerHTML = response; 
					afficheMaskSelect('hidden');
					if(objLien = document.getElementById('closeList')){
						objLien.style.visibility = 'visible';
					}
					document.getElementById(id).style.display = 'block';
					
				}
			}
		}	
		
		xhr.open("POST", link ,true);
		xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");                  
		xhr.send(value);
		
	}
	
	//  masquer  action=hidden; afficher   action=visible;  //
	function afficheMaskSelect(action){
		selectTag = document.getElementsByTagName('select');
		
		for(i = 0; i < selectTag.length; i++){
			if(selectTag[i].name.search('PF_') != -1){
				selectTag[i].style.visibility = action;
			}
		}
	}

//***********			Fiche produit    ********************///			
	function afficheFicheProduit(lien, valeurs, idLigne){
		document.getElementById('content').style.overflow = 'hidden';	
		if(document.getElementById('planMaison')) { document.getElementById('planMaison').style.display = 'none'; }
		document.getElementById('contentFicheProduit').style.display = 'block';	
		if (ligne = document.getElementById(ligneFicheProduit)){			ligne.className = '';		}
		ligneFicheProduit = idLigne;
		
		go(valeurs, lien, "ficheProduit");
	}
	
	function masqueFicheProduit(){
		document.getElementById('ficheProduit').innerHTML = '';	
		if(document.getElementById('planMaison')) { document.getElementById('planMaison').style.display = 'block'; }
		document.getElementById('contentFicheProduit').style.display = 'none';	
		document.getElementById('content').style.overflow = 'auto';	
		if (ligne = document.getElementById(ligneFicheProduit)){			ligne.className = 'trSelect';		}
	}
	
//***********			Zoom photo  	********************///			
	function affichePhotoZoom(image){
		document.getElementById('content').style.overflow = 'hidden';	
		document.getElementById('contentPhotoZoom').style.display = 'block';	
		
		setOpacity(	document.getElementById('contentBlank'), 70);	
		document.getElementById('photoZoomImg').src = image;	
		
	}	
	
	function masquePhotoZoom(){
		document.getElementById('contentPhotoZoom').style.display = 'none';	
		setOpacity(	document.getElementById('contentBlank'), 0);	
		document.getElementById('content').style.overflow = 'auto';	
		document.getElementById('photoZoomImg').src = 'styles/commun/fleur.gif';	
	}
	
	
function afficheListPlanteMaison(idEmplacement){
	go('id='+idEmplacement, 'modules/jardins-de-loire/maison/listePlante.php', 'listePlantes');

}	
//***********			 Fonctions Formulaire    ********************///		

function setOpacity(obj, opacity) {
  if(opacity == 0){
	obj.style.visibility = 'hidden';
  }else{
  obj.style.visibility = 'visible';
  opacity = (opacity == 100)?99.999:opacity;
  // IE/Win
  obj.style.filter = "alpha(opacity:"+opacity+")";
  // Safari<1.2, Konqueror
  obj.style.KHTMLOpacity = opacity/100;
  // Older Mozilla and Firefox
  obj.style.MozOpacity = opacity/100;
  // Safari 1.2, newer Firefox and Mozilla, CSS3
  obj.style.opacity = opacity/100;
 }
}



function verifChecked(obj, divId, nomClassAct, nomClassIna){
	if(!nomClassAct){ nomClassAct = 'divSelected'; }
	if(!nomClassIna){ nomClassIna = ''; }
	if(obj.checked){
		document.getElementById(divId).className = nomClassAct;
	}else{
		document.getElementById(divId).className = nomClassIna;
	}
}

function lockDelock(tableau, trueFalse){
	for(i=0; i < tableau.length; i++){
		document.getElementsByName(tableau[i])[0].disabled=trueFalse;	
	}
}


function lockDelockFormContenant(valeur, numLigne){
	valeurs = new Array('PC_SOUS_CATEGO['+numLigne+']', 'PC_GENCOD['+numLigne+']', 'PC_DESCRI['+numLigne+']', 'PC_NEW['+numLigne+']', numLigne+'[PC_PHOTO_CONDI]', 'ACTION_'+numLigne+'_PC_PHOTO_CONDI');
	
	if(valeur == 1 || valeur == 2){
		lockDelock(valeurs, false)
		document.getElementById('ligne_'+numLigne).className = 'divSelected';
	}else {
		lockDelock(valeurs, true)
		document.getElementById('ligne_'+numLigne).className = '';
	}
}

function focusInput(obj, nomClass){
	obj.className = nomClass;
	}


function blurInput(obj, nomClass){
	obj.className = nomClass;
}

function changeImg(idObj, newSrc, idLeg, newLegende){
	if(obj = document.getElementById(idObj)){
		obj.src = newSrc;
	}
	if(leg = document.getElementById(idLeg)){
		leg.innerHTML = newLegende;
	}

}

function changeClassName(objId, nomClass){
	document.getElementById(objId).className = nomClass;
}

//***********			 Fonctions Div maskée    ********************///		

function insertText( idDiv, idInput, text ){
	afficheMaskDiv( idDiv );
	afficheMaskSelect('visible');
	document.getElementById(idInput).value = text;
}

function maskFauxSelect( idObj ){
	document.getElementById(idObj).style.display = 'none';
	afficheMaskSelect('visible');
}

function afficheFauxSelect( idObj ){
	document.getElementById(idObj).style.display = 'block';
	afficheMaskSelect('hidden');
	
}

function afficheMaskFauxSelect( idObj ){
	if(document.getElementById(idObj).style.display == 'block'){
		maskFauxSelect( idObj );
	}else{
		afficheFauxSelect( idObj ); 
	}
}


function maskDiv( idObj ){
	document.getElementById(idObj).style.display = 'none';
	if(objLien = document.getElementById('closeList')){
		objLien.style.visibility = 'hidden';
	}

}

function afficheDiv( idObj ){
	document.getElementById(idObj).style.display = 'block';
}

function afficheMaskDiv( idObj ){
	if(document.getElementById(idObj).style.display == 'block'){
		maskDiv( idObj );
	}else{
		afficheDiv( idObj ); 
	}
}

function formateTexte(objName, type){
	if(obj = document.getElementById(objName)){
		if (obj.createTextRange) {
			var text;
			obj.focus(obj.caretPos);
			obj.caretPos = document.selection.createRange().duplicate();
			if(obj.caretPos.text.length>0)	{
			
				//gère les espace de fin de sélection. Un double-click sélectionne le mot + un espace qu'on ne souhaite pas forcément...
				var sel = obj.caretPos.text;
				var fin = '';
				while(sel.substring(sel.length-1, sel.length)==' ')       {
					sel = sel.substring(0, sel.length-1)
					fin += ' ';
				}
				obj.caretPos.text = '['+type+']'+ sel + '[/'+type+']' + fin;
			}
			else      obj.caretPos.text = '';
		}
		else 
		alert('Votre Navigateur n\'est pas compatible. Vous devez rajouter manuellement " ['+ type +'] " avant le texte et   " [/'+ type +'] " aprÃ¨s');
	}
}
