// JavaScript Documeit

/***************************************************/
/*** FONCTION DE CREATION DES LISTES DEROULANTES ***/
/***************************************************/

function createDSelect(index){
	var DSelect_el = new DSelect('select_list', 'invisible', 'select_list'+index, 'select_content'+index, 'select_txt'+index, 'select_input'+index);
	DSelect_el.init();
}


/************************************************************/
/*** FONCTIONS LIEES A L'AFFICHAGE DES SOUSMENU DE LA NAV ***/
/************************************************************/

function showSousMenu(event){
	var menuEl = this.id;
	if(menuEl.substr(0,8)!= 'sousmenu'){
		var idSousMenu = 'sousmenu'+menuEl.substr(4,menuEl.length-4);
	}else{
		var idSousMenu = menuEl;
	}
	var classOn = 'sousmenu';
	var classOnPlus = 'sousmenu_right';
	var classOff = 'invisible';
	var el = document.getElementById(idSousMenu);
	if(el){
		if(el.className == classOff){
			el.className = classOn;
			if(idSousMenu=='sousmenu5')
				addClass(el,classOnPlus);
		}
	}
}

function hideSousMenu(event){
	var menuEl = this.id;
	if(menuEl.substr(0,8)!= 'sousmenu'){
		var idSousMenu = 'sousmenu'+menuEl.substr(4,menuEl.length-4);
	}else{
		var idSousMenu = menuEl;
	}
	var classOff = 'invisible';
	var classOn = 'sousmenu';
	var el = document.getElementById(idSousMenu);
	if(el){
		if(hasClass(el,classOn)){
			el.className = classOff;
		}
	}
}

function showSousMenu2(index){
	var classOn = 'sousmenu';
	var classOnPlus = 'sousmenu_right';
	var classOff = 'invisible';
	var idSousMenu = 'sousmenu';
	var el = document.getElementById(idSousMenu+index);
	if(el){
		if(el.className == classOff){
			el.className = classOn;
			if(idSousMenu=='sousmenu5')
				addClass(el,classOnPlus);
		}
	}
}

function hideSousMenu2(index){
	var classOn = 'sousmenu';
	var classOnPlus = 'sousmenu_right';
	var classOff = 'invisible';
	var idSousMenu = 'sousmenu';
	var el = document.getElementById(idSousMenu+index);
	if(el){
		if(hasClass(el,classOn)){
			el.className = classOff;
		}
	}
}


/****************************************************************/
/*** FONCTIONS LIEES A L'AFFICHAGE DE LA POPIN CODE PRIVILEGE ***/
/****************************************************************/

function showPopinCodePrivilege(){
	var el = document.getElementById('code_conf_popin');
	if(el){
		el.className = 'code_conf_popin';
	}
	if (navigator.platform == "Win32" && navigator.appName == "Microsoft Internet Explorer") {
        alphaBackgrounds();
	}
}

function hidePopinCodePrivilege(){
	var el = document.getElementById('code_conf_popin');
	if(el){
		el.className = 'invisible';
	}
}


/******************************************************************/
/*** FONCTION LIEE A L'AFFICHAGE DU BLOC "AFFINER LA RECHERCHE" ***/
/******************************************************************/

function showAffinerRecherche(){
	var el = document.getElementById('bloc_recherche_affiner');
	var el_bt = document.getElementById('bt_affiner_recherche');
	if(el){
		if(el.className == 'bloc_recherche_affiner'){
			el.className = 'invisible';
			removeClass(el_bt,'on');
		}else{
			el.className = 'bloc_recherche_affiner';
			addClass(el_bt,'on');
			initDCurseur();
			if (navigator.platform == "Win32" && navigator.appName == "Microsoft Internet Explorer") {
				alphaBackgrounds();
			}
		}
	}
}

/*************************************/
/*** FONCTIONS LIEES AUX ROLLOVERS ***/
/*************************************/

function rollover_recheche(){
	var el = document.getElementById('recherche');
	if(el){
		el.className = 'bt_recherche_on';
	}
}
function rollout_recheche(){
	var el = document.getElementById('recherche');
	if(el){
		el.className = 'bt_recherche';
	}
}

function rollover_cliquerici_guide(){
	var el = document.getElementById('bt_cliquerici');
	if(el){
		el.src = '/skins/fr/img/left/guide/bt_cliquerici_on.gif';
	}
}
function rollout_cliquerici_guide(){
	var el = document.getElementById('bt_cliquerici');
	if(el){
		el.src = '/skins/fr/img/left/guide/bt_cliquerici.gif';
	}
}

function rollover_bt_ensavoirplus(){
	var el = document.getElementById('bt_ensavoirplus');
	if(el){
		el.src = '/skins/fr/img/commun/bt_ensavoirplus_on.gif';
	}
}
function rollout_bt_ensavoirplus(){
	var el = document.getElementById('bt_ensavoirplus');
	if(el){
		el.src = '/skins/fr/img/commun/bt_ensavoirplus.gif';
	}
}

function rollover_bt_cliquezici_br(){
	var el = document.getElementById('bt_cliquezici_br');
	if(el){
		el.src = '/skins/fr/img/home/invest_borloo_robien/bt_cliquezici_on.gif';
	}
}
function rollout_bt_cliquezici_br(){
	var el = document.getElementById('bt_cliquezici_br');
	if(el){
		el.src = '/skins/fr/img/home/invest_borloo_robien/bt_cliquezici.gif';
	}
}

function rollover_valider_rdv(){
	var el = document.getElementById('valider_rdv');
	if(el){
		el.className = 'bt_valider_on';
	}
}
function rollout_valider_rdv(){
	var el = document.getElementById('valider_rdv');
	if(el){
		el.className = 'bt_valider';
	}
}

function rollover_bt_valider(){
	var el = document.getElementById('bt_valider');
	if(el){
		el.className = 'bt_valider_on';
	}
}
function rollout_bt_valider(){
	var el = document.getElementById('bt_valider');
	if(el){
		el.className = 'bt_valider';
	}
}


/*********************************************************************************/
/*** FONCTIONS LIEES AU CONTROLE DES CHAMPS DE SAISIE POUR LE NOMBRE DE PIECES ***/
/*********************************************************************************/

function updateListNbrePieceMax(idCibleInput,idCibleTxt,idCible,maxValue,myThis){
	var valMin = myThis.innerHTML;
	var el_cible = document.getElementById(idCible);
	var cibleTxt = document.getElementById(idCibleTxt);
	var cibleInput = document.getElementById(idCibleInput);
	if(el_cible && cibleTxt && cibleInput){
		var contenu = '<li><a id="select_list3_1" href="#" onclick="updateContent(\'select_txt3\',\'select_input3\',0,this);" >max</a></li>';
		var myVal = valMin;
		for(var i=0;i<=(maxValue-valMin);i++){
			if(myVal<=maxValue || myVal=='min'){
				contenu += '<li><a id="select_list3_'+(i+2)+'" href="#" onclick="updateContent(\'select_txt3\',\'select_input3\','+myVal+',this);" >'+myVal+'</a></li>';
			}
			myVal++;
		}
		if(eval(cibleInput.value)<valMin){
			cibleTxt.innerHTML = 'max';
			cibleInput.value = '0';
		}
		el_cible.innerHTML = contenu;
	}
	
}


/***************************************************************/
/*** FONCTIONS LIEES AUX EFFETS DE LA PAGE PROJET IMMOBILIER ***/
/***************************************************************/

function showOngletTxt(event){
	var myId = this.id;
	var index = myId.substr(6,myId.length-6);
	var ongletTxt = document.getElementById('onglet_txt'+index);
	if(ongletTxt){
		if(ongletTxt.className=='invisible'){
			ongletTxt.className='txt';
		}
	}
}

function hideOngletTxt(event){
	var myId = this.id;
	var index = myId.substr(6,myId.length-6);
	var ongletTxt = document.getElementById('onglet_txt'+index);
	if(ongletTxt){
		if(ongletTxt.className=='txt'){
			ongletTxt.className='invisible';
		}
	}
}


/**********************************************************************************/
/*** FONCTIONS LIEES A LA SELECTION DES DEPARTEMENTS DANS LA RECHERHCHE AVANCEE ***/
/**********************************************************************************/

function addInputSelectionDepartement(valueDepartement){
	var myInput = document.getElementById('departement_liste');
	var myValue = myInput.value;
	myValue+=valueDepartement+';';
	myInput.value = myValue;
}

function addSelectionDepartement(valueDepartement,el){
	var conteneur = document.getElementById('departement_selectionne');
	var contenu = conteneur.innerHTML;
	var nbChildren = getArrayChildren(conteneur).length;
	var myInput = document.getElementById('departement_liste');
	var myValue = myInput.value;
	if(nbChildren<3 && myValue.indexOf(valueDepartement)==-1){
		var innerElement = el.innerHTML;
		contenu+='<a href="#" onclick="removeSelectionDepartement('+valueDepartement+',this);">'+innerElement+'</a>';
		addInputSelectionDepartement(valueDepartement);
		conteneur.innerHTML=contenu;
	}
}

function removeInputSelectionDepartement(valueDepartement){
	var myInput = document.getElementById('departement_liste');
	var myValue = myInput.value;
	var valueToRemove = valueDepartement+';';
	var arrayMyValue = myValue.split(valueToRemove);
	var myNewValue = arrayMyValue[0]+arrayMyValue[1];
	myInput.value = myNewValue;
}

function removeSelectionDepartement(valueDepartement,el){
	var conteneur = document.getElementById('departement_selectionne');
	var innerElement = el.innerHTML;
	var myChildren = getArrayChildren(conteneur);
	for(var i=0;i<myChildren.length;i++){
		if(myChildren[i].innerHTML==innerElement){
			conteneur.removeChild(myChildren[i]);
			removeInputSelectionDepartement(valueDepartement);
			return;
		}
	}
}


/**********************************************************************************/
/*** FONCTIONS LIEES AUX CURSEURS ET A LA MISE A JOUR DES INPUT HIDDEN ASSOCIES ***/
/**********************************************************************************/

function getMinValue(param,id){
    var valuecursor = document.getElementById('valuecursor'+id+'_left');
	if(valuecursor){
		valuecursor.value = param;
	}
}

function getMaxValue(param,id){
	var valuecursor = document.getElementById('valuecursor'+id+'_right');
	if(valuecursor){
		valuecursor.value = param;
	}
}


/*****************************************************************************************************************/
/*** FONCTION LIEE A L'ACTIVATION/DESACTIVATION DU CURSEUR "NOMBRE DE PIECES" DANS LA PAGE "RECHERCHE AVANCEE" ***/
/*****************************************************************************************************************/

var valuecursor1_left;
var valuecursor1_right;
try {
	if (document.getElementById('type_bien3').checked == true ) {ableDisableCursorNbPieces();}
}
catch(e) {}


function ableDisableCursorNbPieces(){
	var mythis = document.getElementById('type_bien3');
	if(mythis){
		if(mythis.checked==true){
			var el = document.getElementById('layerDisable'); 
			if(el){
				el.className='';
				el.style.width='280px';
				el.style.height='25px';
				el.style.position='absolute';
				el.style.left='0px';
				el.style.top='-25px';
				el.style.zIndex='1000';
				el.style.backgroundColor='#FFFFFF';
				setOpacity(el,70);
				valuecursor1_left = document.getElementById('valuecursor1_left').value;
				valuecursor1_right = document.getElementById('valuecursor1_right').value;
				document.getElementById('valuecursor1_left').value = '';
				document.getElementById('valuecursor1_right').value = '';
			}
		}else{
			var el = document.getElementById('layerDisable');
			if(el){
				document.getElementById('valuecursor1_left').value = valuecursor1_left;
				document.getElementById('valuecursor1_right').value = valuecursor1_right;
				el.className='invisible';
			}
		}
	}
}

try {
	if (document.getElementById('avancee_type_log_3').checked == true) {ableDisableCursorNbPieces2();}
}
catch(e) {}

function ableDisableCursorNbPieces2(){
	var mythis = document.getElementById('avancee_type_log_3');
	if(mythis){
		if(mythis.checked==true){
			var el = document.getElementById('layerDisable');
			if(el){
				el.className='';
				el.style.width='280px';
				el.style.height='25px';
				el.style.position='absolute';
				el.style.left='0px';
				el.style.top='-25px';
				el.style.zIndex='1000';
				el.style.backgroundColor='#FFFFFF';
				setOpacity(el,70);
				valuecursor1_left = document.getElementById('valuecursor1_left').value;
				valuecursor1_right = document.getElementById('valuecursor1_right').value;
				document.getElementById('valuecursor1_left').value = '';
				document.getElementById('valuecursor1_right').value = '';
			}
		}else{
			var el = document.getElementById('layerDisable');
			if(el){
				document.getElementById('valuecursor1_left').value = valuecursor1_left;
				document.getElementById('valuecursor1_right').value = valuecursor1_right;
				el.className='invisible';
			}
		}
	}
}

/*********************************************/
/*** FONCTIONS LIEES A LA POPIN DE LA HOME ***/
/*********************************************/


function showPopinHome(){
	var el = document.getElementById('popin_home');
	if(el){
		if(el.className != 'popin_home'){
			el.className = 'popin_home';
			updateHeightPopinHome(el);
		}
	}
}
	
function updateHeightPopinHome(el){
	if (navigator.appName == "Microsoft Internet Explorer" && window.attachEvent) {
		el.style.height = document.body.clientHeight+'px';
	}
}
	
function closePopinHome(){
	var el = document.getElementById('popin_home');
	if(el){
		if(el.className != 'invisible')
			el.className = 'invisible';
	}
}

/*********************************************/
/*** FONCTIONS LIEES A LA POPIN DE L'INSCRIPTION NEWSLETTER ***/
/*********************************************/

function showPopinNewsL(){
	var el = document.getElementById('popinsc_news');
	if(el){
		if(el.className != 'popinsc_news'){
			el.className = 'popinsc_news';
			updateHeightPopinHome(el);
		}
	}
}
	
function closePopinNewsL(){
	var el = document.getElementById('popinsc_news');
	if(el){
		if(el.className != 'invisible')
			el.className = 'invisible';
	}
}



/*********************************************/
/********* FONCTIONS POPIN DU MENU    ********/
/*********************************************/
function close_popinLeft() {
	var el = document.getElementById('popin_left');
	if(el){
		window.clearTimeout(timeoutID);
		el.fade(0);
	}
}

function popinLeft() {
	var el = document.getElementById('popin_left');
	if(el){
		document.getElementById('bt_fermer_popin_left').addEvent('click', el.fade.bind(el, [0]));
		document.getElementById('bt_ouvrir_popin_left').addEvent('click', function(e) {e.stop();el.fade(1);});
		timeoutID = window.setTimeout(close_popinLeft, 5000);
	}
}

/*
BUG AVEC LA PAGE PRENDRE RDV MODIFIE LE 02/09/10
function close_popinLeft() {
	var el = $('popin_left');
	if(el){
		window.clearTimeout(timeoutID);
		el.fade(0);
	}
}

function popinLeft() {
	var el = $('popin_left');
	if(el){
		$('bt_fermer_popin_left').addEvent('click', el.fade.bind(el, [0]));
		$('bt_ouvrir_popin_left').addEvent('click', function(e) {e.stop();el.fade(1);});
		timeoutID = window.setTimeout(close_popinLeft, 5000);
	}
}
*/
