function loadctrlinfo(){
	var divtmp = document.getElementById("ctrlInfo");
	var parurl = "recherche.php";	
	xhrinfo = getXhrPost();
	xhrinfo.onreadystatechange = function() {
    if(xhrinfo.readyState == 4 && xhrinfo.status == 200) {
      divtmp.innerHTML = xhrinfo.responseText;	      
  	}
  }
  xhrinfo.open("POST",parurl,true);
  xhrinfo.send(null); 
}
function getXhrPost(){
  if(window.XMLHttpRequest)var newxhr = new XMLHttpRequest();
  else if(window.ActiveXObject){
  	try {
    	var newxhr = new ActiveXObject("Msxml2.XMLHTTP");
    } 
    catch (e) {
    	var newxhr = new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
  else {
   alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
   var newxhr = false;
  }
  return newxhr;
}

function searchinfo(idObj){
	var strSearch = document.getElementById(idObj).value;
	var reg_search = /^ {1,}| {1,}$/g;
	strSearch = strSearch.replace(reg_search,"");
	if (strSearch.length > 0) {
		var nav = (navigator.appName == 'Netscape')? "netscape" : "ie";
		var param = "motCle="+strSearch+"&nav="+nav;
		traiteRequete(param,'ctrlinfoRes');
	}
	else alert("Saisissez au moins une lettre");
}

function traiteRequete(param,divId) {
	var parurl = "recherche.php";
	var xhrinfo = getXhrPost();
	document.getElementById(divId).innerHTML = "chargement...";
	xhrinfo.onreadystatechange = function(){
		if(xhrinfo.readyState == 4 && xhrinfo.status == 200){
			document.getElementById(divId).innerHTML = xhrinfo.responseText;
		}
	}
   xhrinfo.open("POST",parurl,true);  
	xhrinfo.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhrinfo.send(param);
	
}

function setTitleLabel(strtitle,i){
	showPan = true ;
	otLabel = $("ttlLabel");
	otLabel.innerHTML = strtitle;
	otLabel.parentNode.style.backgroundImage = 'url(images/nav/ctrlthm'+i+'.jpg)';
	$("ctrlhelp").style.backgroundImage = 'url(images/nav/chelp'+i+'.gif)';;
}

function go2zomm(layerindex,shapeindex,tileindex){
	var param = "layerindex="+layerindex+"&shapeindex="+shapeindex+"&tileindex="+tileindex+"&act=zoomsrch";
	gMap.tool.setMode(GSMAP_ZOOM_OBJ) ;
	gMap.sendX_Load(param) ;	
}

function zoomSousService(){
	var param = "&act=zoomsousserv";
	gMap.tool.setMode(GSMAP_ZOOM_OBJ) ;
	gMap.sendX_Load(param) ;
}

function displayfiche(layerindex,shapeindex,tileindex){
	var parurl = "fiche/fiche.pop.php?layerindex="+layerindex+"&shapeindex="+shapeindex+"&tileindex="+tileindex;
	openCadre(parurl,'Fiche', 480, 300,true);
}

function openprintpop(){
	var divprint = document.getElementById("cadreprint");
	var limitX = new Array(420, 600) ;
	var limitY = new Array(400, 800) ;
	openCadreEvent("print.pop.php","index","cadreprint", "cadreprint_resize", limitX, limitY);
}

function openCadreEvent(urlPage,parentPage,paramDivCadre, divResizer, limitx, limity){	
	divRepr = document.getElementById(paramDivCadre);
	if (divRepr.style.display != "block"){				
		divRepr.style.display = "block";
		divRepr.style.opacity="";
		divRepr.style.filter="";
	}
	if(ity(divResizer) && limitx.length == 2 && limity.length == 2){
		var limitXmin = limitx[0] ;
		var limitXmax = limitx[1] ;
		var limitYmin = limity[0] ;
		var limitYmax = limity[1] ;
		this.resizeOptionsMenu = {
			handle: $(divResizer),
			inY: true,
			//limit:{x:[limitXmin,limitXmax], y:[limitYmin,limitYmax]},
			onDrag: function(){
				///
			}.bind(this)
		};
		$(paramDivCadre).makeResizable(this.resizeOptionsMenu);
	}
	chargementDivFlottant(urlPage ,paramDivCadre);
}
function chargementDivFlottant(url,cadreid){
	xhrDivFlottant = getXhrPost();
	xhrDivFlottant.onreadystatechange = function(){
		try{
			if(xhrDivFlottant.readyState == 4 && xhrDivFlottant.status == 200){
				oContenuMenu = getObjetContenu(cadreid);
				reponseAjax = xhrDivFlottant.responseText.split('££££') ;
				oContenuMenu.innerHTML = reponseAjax[0] ;			
				deroulerContenu(cadreid);
			}
		}
		catch(e){
		}		
	}
	xhrDivFlottant.open("GET",url,true);
	xhrDivFlottant.send(null);	
}

function closecadre(idcadre){
	var divprint = document.getElementById(idcadre);
	divprint.style.display = "none";
}

function openexportpop(){
	var divprint = document.getElementById("cadre_export");
	divprint.style.width = "300px"; 
	openCadreEvent("export.pop.php?open=true","index","cadre_export");
}

function download(){
	var param = "jpeg";
	var choix = document.getElementById("expchoix1");	
	if(choix.checked) param = "zip";
	twAller("export.pop.php?download="+param);
}

function ity(param){
	if(document.getElementById(param))
	return document.getElementById(param) ;	
	else return null ;
}
function showInfoClick(strHtml){
	ity('ctrlinfoRes').innerHTML = strHtml ;
	cachemodeExpertInfo(true) ;
	ity('modeExpertInfo').style.display = 'block' ;
	ity('modeStandardInfo').style.display = 'none' ;
	ity('control2').onclick() ;
}
function positionCroix(param){
	elt = createAndAppend('div',document.body,true) ;
	elt.style.display = 'none' ;
	elt.id = 'infoClick' ;
	posX = param[0] ;
	posY = param[1] ;
	if(!document.all){
		divT = getOffset(ity('gsmap'),'offsetTop');
		divL = getOffset(ity('gsmap'),'offsetLeft');
		posX += divL;
		posY += divT;
	} 
	posX -= 10;
	posY -= 10;
	elt.style.display = 'block';
	elt.style.top = posY+'px';
	elt.style.left = posX+'px';	
}

function getElementByIdent(prt, scaleCur) {
	if(!document.getElementById(prt))return ;
	elt = document.getElementById(prt)
	aLi = elt.getElementsByTagName('li');
	for(var i =0 ; i < aLi.length; i++) {
		if(aLi[i].getAttribute('ident',false) != "" && aLi[i].getAttribute('ident',false) != null) {
			valEchelle = aLi[i].getAttribute('ident',false) ;
			if(valEchelle != "_" && valEchelle != "-1_-1"){
				aEchelle = valEchelle.split('_') ;
				eMin = parseInt(aEchelle[0]) ;
				eMax = parseInt(aEchelle[1]) ;
				if(scaleCur >= eMin && scaleCur <= eMax ){
					aLi[i].className = 'lgdthm_on' ;
					aCheck = aLi[i].getElementsByTagName('input') ;
					aCheck[0].disabled = false ;
				}
				else{
					aLi[i].className = 'lgdthm_off' ;
					aCheck = aLi[i].getElementsByTagName('input') ;
					aCheck[0].disabled = true ;
				}
			}
			else{
					aLi[i].className = 'lgdthm_on' ;
					aCheck = aLi[i].getElementsByTagName('input') ;
					aCheck[0].disabled = false ;
			}
		}
	}
	return false;
}