var defaultfocusinput = "";
var opennodes = new Array();

function getParentWithClass(el,pTagName) {
	if (el == null) return null;
	else if (el.nodeType == 1 && el.className == pTagName)
		return el;
	else
		return getParentWithClass(el.parentNode, pTagName);
}

if(typeof HTMLElement!="undefined"){
		HTMLElement.prototype.__defineGetter__("innerText", function () {
		   var r = this.ownerDocument.createRange();
		   r.selectNodeContents(this);
		   return r.toString();
		});
		
}

function BuildSummary(o) {
	
	var txt = '';
	var txt2 = '';
	var o = document.getElementById(o);
	var swp_pxmin = document.getElementById("pxmin");
	var swp_pxmax = document.getElementById("pxmax");
	var otypebien2Choix = document.getElementById("typebien2Choix");
	if (o) {
		
		allInput = o.getElementsByTagName("input");
		for (i=0; i<allInput.length;i++) {
			if (allInput[i].checked) {
				txt2=txt2+allInput[i].value+',';
				txt=txt+getParent(allInput[i],"LABEL").innerText+',';
				
			}
		}
	}
	
	o = o.getAttribute("name")
	if (o) {
	o2=document.getElementById(o+"Id");
	o=document.getElementById(o+"Text");
		if (o!=null) {
			txt=String(txt).substring(0,txt.length-1);
			txt2=String(txt2).substring(0,txt2.length-1);
			
			if (o.tagName=="INPUT") 
				{
				o.value=txt;
				o2.value=txt2;
				if('function' == typeof(o2.onchange))
					{
					o2.onchange();
					}
				}
			else
				{
				o.innerHTML=txt;
				o2.innerHTML=txt2;
				}
		}
		
	}
}


 function initDropdown() {
		var navRoot = document.getElementById("miniSearch");
		var allInput = navRoot.getElementsByTagName("input");
			for (i=0; i<allInput.length;i++) {
				node = allInput[i];
				
				//if (((node.getAttribute("type")=="checkbox") || (node.getAttribute("type")=="radio")) && node.name!="idsituation") {
				//Erwan dit: j'ai enlevé getAttribute("type")=="radio" car ça bug sur configuration.php
				
				if (((node.getAttribute("type")=="checkbox") ) && node.name!="idsituation") {

					node.onchange=function() {
						setTimeout('BuildSummary("'+getParentWithClass(this,"searchchoix").id+'")',20);
					}
					
					
					node.onclick=function() {
						setTimeout('BuildSummary("'+getParentWithClass(this,"searchchoix").id+'")',20);
					}
					
				}
			}
			var subnodes = navRoot.getElementsByTagName("DIV");
			//for (i=0; i<navRoot.childNodes.length; i++) {
			for (i=0; i<subnodes.length; i++) {
				//node = navRoot.childNodes[i];
				node = subnodes[i];
				if (node.nodeName=="DIV" && node.className=="searchchoix") {
						setTimeout('BuildSummary("'+node.id+'")',10);
						node.onmouseover=function() {
								o = document.getElementById(this.getAttribute("name")+"Liste");
								if (o) o.className+=" over";
								ClearOpenNodes();
								opennodes.push(o);
				  	}
	  				node.onmouseout=function() {
	  					o = document.getElementById(this.getAttribute("name")+"Liste");
						  ClearOpenNodes();
						  //if (o) o.className=o.className.replace(" over", "");
						  
	   				}
   			}
   			else if (node.nodeName=="DIV" && node.className=="dropdown") {
   				node.onmouseout=function() {ClearOpenNodes();}
   			}
  }
}

 function initDropdown2() {
		var navRoot = document.getElementById("miniSearch2");
		var allInput = navRoot.getElementsByTagName("input");
			for (i=0; i<allInput.length;i++) {
				node = allInput[i];
				
				if (((node.getAttribute("type")=="checkbox") || (node.getAttribute("type")=="radio")) && node.name!="idsituation") {
					node.onchange=function() {
						setTimeout('BuildSummary("'+getParentWithClass(this,"searchchoix").id+'")',20);
					}
					node.onclick=function() {
						setTimeout('BuildSummary("'+getParentWithClass(this,"searchchoix").id+'")',20);
					}
				}
			}
			var subnodes = navRoot.getElementsByTagName("DIV");
			//for (i=0; i<navRoot.childNodes.length; i++) {
			for (i=0; i<subnodes.length; i++) {
				//node = navRoot.childNodes[i];
				node = subnodes[i];
				if (node.nodeName=="DIV" && node.className=="searchchoix") {
						setTimeout('BuildSummary("'+node.id+'")',10);
						node.onmouseover=function() {
								o = document.getElementById(this.getAttribute("name")+"Liste");
								if (o) o.className+=" over";
								ClearOpenNodes();
								opennodes.push(o);
				  	}
	  				node.onmouseout=function() {
	  					o = document.getElementById(this.getAttribute("name")+"Liste");
						  ClearOpenNodes();
						  //if (o) o.className=o.className.replace(" over", "");
						  
	   				}
   			}
   			else if (node.nodeName=="DIV" && node.className=="dropdown") {
   				node.onmouseout=function() {ClearOpenNodes();}
   			}
  }
}

function ClearOpenNodes() {
	
	for (var i=0; i<opennodes.length;i++) {
		var o =opennodes[i];
		if(o)
			o.className=o.className.replace(" over", "");
	}
	opennodes=new Array();
}

function swapvisible(obj,swp) {
	if (obj) {
		if ( swp == 'no' ) {
			obj.style.visibility='hidden';
			obj.style.display = 'none';
		}else {
			obj.style.visibility='visible';
			obj.style.display = 'inline';
		}
	}
}

function returnChecked(o)
	{
		allInput = o.getElementsByTagName("input");
		for (i=0; i<allInput.length;i++) 
		  {
		  if (allInput[i].checked) {
		  return allInput[i].value;	
		  }
		}		
	}			

function engine (id) {
	var o = document.getElementById(id);
	var oidtt = document.getElementById('ididtt');
	var cornerd = document.getElementById("cornerd_"+id);
	var cornerg = document.getElementById("cornerg_"+id);
	var tab = Array ("ogl_achat","ogl_location","ogl_bureaucomm","ogl_locvac");
	var swp_typetransac = document.getElementById("typetransacChoix");
	var swp_nb_pieces = document.getElementById("nb_piecesChoix");
	var swp_nb_chambres = document.getElementById("nb_chambresChoix");
	var swp_idsituationgrp = document.getElementById("idsituationgrp");
	var swp_typebien2Choix = document.getElementById("typebien2Choix");
	var swp_typebienChoix = document.getElementById("typebienChoix");
	var swp_typecommerceChoix = document.getElementById("typecommerceChoix");
	var swp_bascritere = document.getElementById("bascritere");
	
	var swp_pxmin = document.getElementById("pxmin");
	var swp_pxmax = document.getElementById("pxmax");
	if(o && o.className != "activelink" ) {
	for(i=0;i<tab.length;i++){
			document.getElementById(tab[i]).className = "inactivelink";
			document.getElementById("cornerg_"+tab[i]).className = "oglinactivg";
			document.getElementById("cornerd_"+tab[i]).className = "oglinactivd";
		}
		o.className = "activelink";
		cornerg.className = "oglactivg";
		cornerd.className = "oglactivd";	
		if(id == "ogl_achat") {
			oidtt.value = "2"; 
			swapvisible(swp_typetransac,'no');
			swapvisible(swp_nb_pieces,'yes');
			swapvisible(swp_nb_chambres,'yes');
			swapvisible(swp_idsituationgrp,'no');
			swapvisible(swp_typebien2Choix,'no');
			swapvisible(swp_typebienChoix,'yes');
			swapvisible(swp_typecommerceChoix,'no');		
			swapvisible(swp_bascritere,'yes');		
			swp_pxmax.name = "pxmax";	
			swp_pxmin.name = "pxmin";		
		}else{
			if(id == "ogl_location") {
				oidtt.value = "1"; 
				swapvisible(swp_typetransac,'no');
				swapvisible(swp_nb_pieces,'yes');
				swapvisible(swp_nb_chambres,'yes');
				swapvisible(swp_idsituationgrp,'no');
				swapvisible(swp_typebien2Choix,'no');
				swapvisible(swp_typebienChoix,'yes');
				swapvisible(swp_typecommerceChoix,'no');
				swp_pxmax.name = "px_loyermax";	
				swp_pxmin.name = "px_loyermin";		
			swapvisible(swp_bascritere,'yes');		

			}else{
				if(id == "ogl_locvac") {
					oidtt.value = "4"; 
					swapvisible(swp_typebien2Choix,'yes');
					swapvisible(swp_typebienChoix,'no');
					swapvisible(swp_typecommerceChoix,'no');	
					swapvisible(swp_nb_pieces,'yes');
					swapvisible(swp_nb_chambres,'yes');
					swapvisible(swp_typetransac,'no');
					swapvisible(swp_idsituationgrp,'yes');
			swapvisible(swp_bascritere,'no');		
					
					swp_pxmax.name = "px_bs_semainemax";	
					swp_pxmin.name = "px_bs_semainemin";	
				}else{
					oidtt.value = "com"; 
					activeForm('typebienListe');
					activeForm('typebien2Liste');
					swapvisible(swp_typetransac,'yes');
					swapvisible(swp_nb_pieces,'no');
					swapvisible(swp_nb_chambres,'no');
					swapvisible(swp_idsituationgrp,'no');
					swapvisible(swp_typebien2Choix,'no');
					swapvisible(swp_bascritere,'yes');		

					if(returnChecked()!= 10){
						swapvisible(swp_typebienChoix,'yes');	
						swapvisible(swp_typecommerceChoix,'no');
					}else {
						swapvisible(swp_typebienChoix,'no');	
						swapvisible(swp_typecommerceChoix,'yes');
					}	
					swp_pxmax.name = "pxmax";	
					swp_pxmin.name = "pxmin";		 
							
				}
			}
		}
	}
}

function focusinput (o) {
	if (o.value==defaultfocusinput) {
		o.value="";
		o.style.color="black";
	}
}

function addEvent(elm, evType, fn, useCapture) {
	if (elm.addEventListener) {
		elm.addEventListener(evType, fn, useCapture);
		return true;
	}
	else if (elm.attachEvent) {
		var r = elm.attachEvent('on' + evType, fn);
		return r;
	}
	else {
		elm['on' + evType] = fn;
	}
}

function $() {
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == 'string')
			element = document.getElementById(element);
		if (arguments.length == 1)
			return element;
		elements.push(element);
	}
	return elements;
}

function doEcr(x) {
var oEcr = document.getElementById("dbg");
	if (oEcr)
		oEcr.innerHTML=x+"<br/>"+oEcr.innerHTML;
}

function getParent(el, pTagName) {
	if (el == null) return null;
	else if (el.nodeType == 1 && el.tagName == pTagName)
		return el;
	else
		return getParent(el.parentNode, pTagName);
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}
