//Fonction permettant de positionner un DIV ? une position occup?e par un autre objet "parent"
function setToAnchor(parentID, parentName, divID, offsetTopSupp, offsetLeftSupp) {
	
	var DivLeft = 0;	  //Position du Div par rapport au c?t? gauche de la page
	var DivTop = 0;	  //Position du Div par rapport au haut de la page
	
	var ns = (document.layers)? true:false;	 	//NS
	var ie = (document.all)? true:false;	 	//IE
	var dom = (document.getElementById)? true:false;	//DOM (FireFox)
	
	if (dom)
	        {
	        pos = document.getElementById(parentID);
	        DivLeft = getLeft(pos);
	        DivTop = getTop(pos);
	        document.getElementById(divID).style.left = DivLeft + offsetLeftSupp;
	        document.getElementById(divID).style.top = DivTop + offsetTopSupp;
	 }
	
	else if (ie) {
	        pos = document.all[parentID];
	        DivLeft = getLeft(pos);
	        DivTop = getTop(pos);
	        document.all[divID].style.posLeft = DivLeft + offsetLeftSupp;
	        document.all[divID].style.posTop = DivTop + offsetTopSupp;
	 }
	
	else if (ns) {
	        pos = document.anchors[parentName];
	        DivLeft = pos.x;
	        DivTop = pos.y;
	        document.layers[divID].pageX = DivLeft + offsetLeftSupp;
	        document.layers[divID].pageY = DivTop + offsetTopSupp;
	}
}	
	    
//Fonction permettant de conna?tre la position d'un objet par rapport au bord gauche de la page.
function getLeft(MyObject) { 
	if (MyObject.offsetParent) 
		return (MyObject.offsetLeft + getLeft(MyObject.offsetParent));
	else
		 return (MyObject.offsetLeft);
}

//Fonction permettant de conna?tre la position d'un objet par rapport au bord haut de la page.
function getTop(MyObject) { 
	if (MyObject.offsetParent) 
		return (MyObject.offsetTop + getTop(MyObject.offsetParent));
	else 
		return (MyObject.offsetTop);
 }

// Fonctions Left et Right sur des chaines de caract?re
	
function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}	





// Fonctions pour les moteurs de recherche =========================================================================================

function majListe(item,inputText,txtDefaut) {
	
	//window.alert(inputText.id);
	if (item.checked==false) {
		item.checked=true;
	}
	else {
		item.checked=false;
	}
	
	inputText.value = '';
			
	for (cpt=1; cpt < document.rechannonce.length; cpt++) {
		if (document.rechannonce[cpt].name) {
			
			//if (document.rechannonce[cpt].name.substr(0,posTmp) == item.id.substr(0,posTmp)) {
			if (document.rechannonce[cpt].name == item.id.substr(0,item.id.indexOf('_'))) {
				if (document.rechannonce[cpt].checked == true) {
					inputText.value += ', ' + document.getElementById('hidden'+document.rechannonce[cpt].id).value;
				}
			}
		}
	}
	if (inputText.value.substring(0,2) == ', ') {inputText.value = inputText.value.substring(2, inputText.value.length)}
	if (inputText.value == '') {inputText.value = unescape(txtDefaut);}
}





function majListeUnique(item,inputText,txtDefaut) {
	
	ancien_etat = item.checked;
	
	for (cpt=1; cpt < document.rechannonce.length; cpt++) {
		if (document.rechannonce[cpt].name) {
			if (document.rechannonce[cpt].name.substr(0,6) == item.id.substr(0,6)) {
				document.rechannonce[cpt].checked = false
			}
		}
	}
	
	if (ancien_etat==false) {
		item.checked=true;
	}
	else {
		item.checked=false;
	}
		
	inputText.value = '';
	
	for (cpt=1; cpt < document.rechannonce.length; cpt++) {
		if (!document.rechannonce[cpt].name) {
			// rien
		}		
		else {	
			if (document.rechannonce[cpt].name.substr(0,6) == item.id.substr(0,6)) {
				if (document.rechannonce[cpt].checked == true) {
					//alert(document.getElementById('hidden'+document.rechannonce[cpt].id).value);
					//alert(document.rechannonce[cpt].id);
					inputText.value += ', ' + document.getElementById('hidden'+document.rechannonce[cpt].id).value;
				}
			}
		}
	}
	if (inputText.value.substring(0,2) == ', ') {inputText.value = inputText.value.substring(2, inputText.value.length)}
	if (inputText.value == '') {inputText.value = unescape(txtDefaut);}
}


function majIntervalle(valeur,inputText,borne,valeurDefaut) {
	
	//window.alert(inputText);
	
	valeurPrec = GetId(inputText).value;
	valeurPrec = valeurPrec.replace(valeurDefaut + ' : ','');
	
	valeurMinPrec = '0';
	valeurMaxPrec = '';
	
	posSepar = valeurPrec.indexOf('-');
	if (posSepar > 0) {
		valeurMinPrec = valeurPrec.substr(0,posSepar-1);
		valeurMaxPrec = valeurPrec.substr(posSepar+2,valeurPrec.length-posSepar);
	}
		
	GetId(inputText).value = valeurDefaut + ' : ';
	
	//if (valeur != '') {
		if (borne == 'min') {
			GetId(inputText).value += 	valeur + ' - ' + valeurMaxPrec;
		}
		else {
			GetId(inputText).value += 	valeurMinPrec + ' - ' + valeur;
		}
	//}	
}
	


function GetId(id)
{
return document.getElementById(id);
}
//-------------------------------------------------------------------------------------------------------------------------------------
var i=false; // La variable i nous dit si la bulle est visible ou non
//-------------------------------------------------------------------------------------------------------------------------------------
function move(e) {
	
	if(i) {  // Si la bulle est visible, on calcule en temps reel sa position ideale
		if (GetId("curseur")) {
			
			if (!e) e=event;
				if (e.pageX) {
					//l=e.pageX +- 10+"px";
					//t=e.pageY + 10+"px";
					l=e.clientX+document.body.scrollLeft;
					t=e.clientY+document.body.scrollTop;
				}
				else
				{
					l=e.clientX+document.body.scrollLeft;
					t=e.clientY+document.body.scrollTop;
				}
				
					
				if(GetId("curseur")!=null) {
			//		infobCur.innerHTML=l+" top"+t;
					GetId("curseur").style.top=t+10;
					GetId("curseur").style.left=l;
					GetId("curseur").style.width=430;
					GetId("curseur").style.display='inline';
					GetId("curseur").style.visibility='visible';
			
				}
				
		}
	}
}
//-------------------------------------------------------------------------------------------------------------------------------------
function move_tmp(e) {
  if(i) {  // Si la bulle est visible, on calcule en temps reel sa position ideale
  if (GetId("curseur")) {
    if (navigator.appName!="Microsoft Internet Explorer") { // Si on est pas sous IE
	GetId("curseur").style.left=e.pageX + 10+"px";
	GetId("curseur").style.top=e.pageY + 10+"px";
	}
    else { 
	if(document.documentElement.clientWidth>0) {
	GetId("curseur").style.left=20+event.x+document.documentElement.scrollLeft+"px";
	GetId("curseur").style.top=10+event.y+document.documentElement.scrollTop+"px";
	} 
	else {
		GetId("curseur").style.left=20+event.x+document.body.scrollLeft+"px";
		GetId("curseur").style.top=10+event.y+document.body.scrollTop+"px";
		}
	}
  }
  }
}
//-------------------------------------------------------------------------------------------------------------------------------------
function montre(text) {
  if(i==false) {
	GetId("curseur").style.visibility="visible"; // S'il est cach? (la verif n'est qu'une securit?) on le rend visible.
	GetId("curseur").innerHTML = unescape(text); // on copie notre texte dans l'?l?ment html
	i=true;
  }
}
//-------------------------------------------------------------------------------------------------------------------------------------
function cache() {
if(i==true) {
	GetId("curseur").style.visibility="hidden"; // Si la bulle est visible on la cache
	i=false;
	}
}
//-------------------------------------------------------------------------------------------------------------------------------------

function cacheAutresDivs(exception) {
	tableDiv = document.getElementsByTagName('div')
	for (cpt=0; cpt<tableDiv.length; cpt++) {
		toto = cpt+''
		
		if (tableDiv[cpt].id.substr(0,7) == 'deroule') {
			if (tableDiv[cpt].id != exception) {
				if (tableDiv[cpt].style.display == 'block') {
					
					//tableDiv[cpt].style.visibility='hidden';
					tableDiv[cpt].style.display='none';					
				}
			}
		}
	}		
} 


////-------------------------------------------------------------------------------------------------------------------------------------

function checkTypeRech() {
	 if (document.getElementById('typeRech').value=='a') {
	 	
	 	// Recherche avanc?e	 	
		document.getElementById('divRechAvancee').style.display = 'block';
		document.getElementById('divTitreRechLoca').style.display = 'block';
		document.getElementById('divTitreRechCrit').style.display = 'block';
		document.getElementById('divRechLoca').style.display = 'block';
		document.getElementById('divBasFormSimple').style.display = 'none';

	}
	else {
		
		// Recherche simple
		document.getElementById('divBasFormSimple').style.display = 'block';
	}
	
	redimCacheurDivs();
}
//-------------------------------------------------------------------------------------------------------------------------------------

function redimCacheurDivs() {
	document.getElementById('cacheurDivs').style.width = document.body.clientWidth - 350;
	
	if (document.getElementById('typeRech').value=='a') {
    		document.getElementById('cacheurDivs').style.height = 350; //175;
    	}
    	else {
    		document.getElementById('cacheurDivs').style.height = 200;
    	}
}
//-------------------------------------------------------------------------------------------------------------------------------------




//-------------------------------------------------------------------------------------------------------------------------------------
document.onmousemove=move; // d?s que la souris bouge, on appelle la fonction move pour mettre ? jour la position de la bulle.

							
				
function displayStaticMessage(messageContent,cssClass)
{
	//alert('test');
	messageObj.setHtmlContent(messageContent);
	messageObj.setSize(400,200);
	messageObj.setCssClassMessageBox(cssClass);
	messageObj.setSource(false);		// no html source since we want to use a static message here.
	messageObj.setShadowDivVisible(false);	// Disable shadow for these boxes	
	messageObj.display();
					
}

function closeMessage()
{
	messageObj.close();	
}

function alerter (txt) {
	var chaine = unescape(txt);
	var reg = new RegExp("(<br>)", "g");
	
	window.alert(chaine.replace(reg,"\n"));	
}
