/**************************************************************************
** Projet :					CG78
** Nom du fichier :			cg78.inc.js
** Créé le :				02/04/08										Par : 
** Contenu :				Fichier contenant les fonctions de gestion des outils de sélection sur la carte 
**
***************************************************************************/

/* ******** BROWSER DETECTION ********************/
	
var detect = navigator.userAgent.toLowerCase();
var OS,browser,version,total,thestring;

if (checkIt('konqueror')) {
	browser = "Konqueror";
	OS = "Linux";
}
else if (checkIt('safari')) browser = "Safari"
else if (checkIt('omniweb')) browser = "OmniWeb"
else if (checkIt('opera')) browser = "Opera"
else if (checkIt('webtv')) browser = "WebTV";
else if (checkIt('icab')) browser = "iCab"
else if (checkIt('msie')) browser = "Internet Explorer"
else if (!checkIt('compatile')) {
	browser = "Netscape Navigator"
	version = detect.charAt(8);
}
else browser = "An unknown browser";

if (!version) version = detect.charAt(place + thestring.length);

if (!OS) {
	if (checkIt('linux')) OS = "Linux";
	else if (checkIt('x11')) OS = "Unix";
	else if (checkIt('mac')) OS = "Mac"
	else if (checkIt('win')) OS = "Windows"
	else OS = "an unknown operating system";
}

function checkIt(string) {
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}
/* ******** END OF BROWSER DETECTION ********************/

function getRootPath() {
	var theLoc = document.location.href;
	var theLastPos = theLoc.lastIndexOf('/');
	var RootPath = theLoc.substr(0,theLastPos) + '/';	
	return RootPath;
}

function setCursor() {
  var internalCursor = ((navigator.version < 6) && (navigator.appName == 'Netscape'));
  var usedCursor = 'default';
  var rootPath = getRootPath();
  switch (carte_state) {
		case "zoomin" : usedCursor = (internalCursor) ? '-moz-zoom-in' : 'url(' +rootPath + zoominCursor+')'; break;      
		case "zoomout" : usedCursor = (internalCursor) ? '-moz-zoom-out' : 'url(' +rootPath + zoomoutCursor+')'; break;
		case "zoompan" : usedCursor = (internalCursor) ? '-moz-grab' : 'url(' +rootPath + panCursor+')'; break; 		
		case "info" : usedCursor = (internalCursor) ? 'default' : 'url('+rootPath + queryCursor+')'; break;  
  }    
  $('visualisation').style.cursor = usedCursor;  
}

function changeTypeCursor(tag,cursorType){
	visu = $(tag);
	visu.style.cursor = cursorType;	
}
function changeCarte(idcarte){
	if(idcarte == "") return;
	arrayFieldRecherche = new Array();
	parUrl = "ajaxRep.inc.php?realodTheme=oui&idcarte="+idcarte;
	loadDataToDiv(parUrl,"ul_ctrlThemes");
}
function navCurrent(nomNav,iCur,nbreNav) {
	for(nav=1;nav<=nbreNav;nav++){
		cur = $(nomNav+nav);		
		if (iCur == nav) {
			cur.className="current";
			setBgToBlue('sub9');
			setBgToBlue('sub7');
		}else {
			cur.className="";
		}
	}
}
function contraireNavCurrent(nomNav,iCur,nbreNav){
	for(nav=1;nav<=nbreNav;nav++){
		cur = $(nomNav+nav);
		cur.className="";
		if(iCur == 7){
			setBgToBlue('sub9');
			setBgToGreen('sub7');
		}else if(iCur == 9){
			setBgToBlue('sub7');
			setBgToGreen('sub9');
		}
	}
}
function showDivSdb(nomDiv, mode) {
	if(!$(nomDiv)) {
		return false;
	}
	
	if(cibleClass = $(nomDiv)) {
		cibleClass.style.display = mode;
		if(mode != 'none') nomDiv.className = "current";
		$("sidebar").style.width = "205px";
		$("control").style.width = "100%";
		$("controlContent").style.display = "block";
		$("controlContent").style.width = "180px";
	}
}

var VERIF_OPEN_SIDE_BAR = false;
function tabClick(nTab) {
	showDivSdb('ctrlThemes', 'none');
	showDivSdb('ctrlInfoContainer', 'none');
	showDivSdb('ctrlRsch', 'none');
	if(document.all) {
		dltHide = parseInt($("visualisation").offsetWidth) + parseInt($('controlContent').offsetWidth)-28;
		dltShow = parseInt($("visualisation").offsetWidth) - parseInt($('controlContent').offsetWidth)+28;
	}else {
		dltHide = parseInt($("visualisation").offsetWidth) + parseInt($('controlContent').offsetWidth)-30;
		dltShow = parseInt($("visualisation").offsetWidth) - parseInt($('controlContent').offsetWidth)+26;
	}
	if(nTab == "") {
		$("sidebar").style.width = "54px";
		$("controlContent").style.display = "none";
		$("controlContent").style.width = "0px";
		$("visualisation").style.width = dltHide;
		if(VERIF_OPEN_SIDE_BAR) {
			gMap.setSize();
			gMap.toolYet.reinit(ARR_DIRECTION);
		}
		VERIF_OPEN_SIDE_BAR = false;
	}else {
		if(!VERIF_OPEN_SIDE_BAR) {
			$("visualisation").style.width = dltShow;
			gMap.setSize();
			gMap.toolYet.reinit(ARR_DIRECTION);
		}
		VERIF_OPEN_SIDE_BAR = true;
		showDivSdb(nTab, 'block');
	}
	
}

function openCadreFrame(url,title, w, h,id){
	if($(id)) {
		$(id).remove();
	}
	if(!w) w = 350;
	if(!h) h = 450;
	if(!t) {
		t = (getWindowHeight() / 2) - (h / 2) ;
	}
	if(!l) {
		l = (getWindowWidth() / 2) - (w / 2) ;
	}
	if(! id) id = Math.random();
	if(!resizable) resizable=false;
	var win = new Windoo({
		id: id,
		width: w,
		height: h,
		top: t,
		left: l,
		title: title,
		type: 'iframe',
		url: url,
		resizable: resizable,
		theme: Windoo.Themes.gs,
		maximize: false,
		shadow: false,
		buttons: {
			maximize: false
		},
		position: false
	}).show();
}

function openCadreContent(content, title, w, h, id, resizable, t, l) {
	if($(id)) {
		$(id).remove();
	}
	if(!w) w = 350;
	if(!h) h = 450;
	if(!t) {
		t = (getWindowHeight() / 2) - (h / 2) ;
	}
	if(!l) {
		l = (getWindowWidth() / 2) - (w / 2) ;
	}
	if(! id) id = Math.random();
	if(!resizable) resizable=false;
	if(title == 'Impression') {
		var scaleCur = gMap.scale.toInt();
		url = url+"?scaleCur="+scaleCur;
	}
	var win = new Windoo({
		id: id,
		width: w,
		height: h,
		top: t,
		left: l,
		title: title,
		type: 'dom',
		content: content,
		resizable: resizable,
		theme: Windoo.Themes.gs,
		maximize: false,
		shadow: false,
		buttons: {
			maximize: false
		},
		position: false
	}).show();
}

function openCadre(url, title, w, h, id, resizable, t, l) {
	if($(id)) {
		$(id).remove();
	}
	if(!w) w = 350;
	if(!h) h = 450;
	if(!t) {
		t = (getWindowHeight() / 2) - (h / 2) ;
	}
	if(!l) {
		l = (getWindowWidth() / 2) - (w / 2) ;
	}
	if(! id) id = Math.random();
	if(!resizable) resizable=true;
	if(title == 'Impression') {
		var scaleCur = gMap.scale.toInt();
		url = url+"?scaleCur="+scaleCur;
	}
	var win = new Windoo({
		id: id,
		width: w,
		height: h,
		top: t,
		left: l,
		title: title,
		type: 'ajax',
		url: url,
		resizable: resizable,
		theme: Windoo.Themes.gs,
		maximize: false,
		shadow: false,
		buttons: {
			maximize: false
		},
		position: false
	}).show();
}

function openCadrePrint(urlPage,paramDivCadre){	
	scaleCur = gMap.scale;
	if($('fichePrint')) {
		removeCadre('fichePrint');
	}
	if(paramDivCadre == 'cadre_print')openCadre(urlPage+"?scaleCur="+scaleCur,'Impression',330,330);
	else openCadre(urlPage+"?scaleCur="+scaleCur,'Export',330,380);
}

function opencadreStat(urlPage){
    openCadre(urlPage,'Statistique de Connexion',400,450);
}

function removeCadre(obj){
	prt = $(obj);
	if(!prt) {
		return;
	}
	
	var regStic = new RegExp ('^windoo ','ig');
	do {
		if(regStic.test(prt.className)) {
			// remove frame pour ie6
			if(window.ie6) {
				var oFrame = prt.previousSibling;
				if(oFrame && oFrame.tagName.toString().toUpperCase =="IFRAME") {
					oFrame.remove();
				}
			}
			//prt.parentNode.removeChild(prt);			
			prt.remove();
			return;
		}
		if(!prt.parentNode)return;
		else prt = prt.parentNode;
	}while(prt);
}

function chargementDivFlottant(url,cadreid){
	if(!arguments[2]){
		xhrCadre = getXhrReturn();
		xhrCadre.onreadystatechange = function() {
			if(xhrCadre.readyState == 4 && xhrCadre.status == 200) {
				oContenuMenu = getObjetContenu(cadreid);
				var rep = xhrCadre.responseText.split('££££');
				oContenuMenu.innerHTML = xhrCadre.responseText;
				deroulerContenu(cadreid);
			}
		}
		xhrCadre.open("GET",url,true);
		xhrCadre.send(null);
	}else{
		oContenuMenu = getObjetContenu(cadreid);
		oContenuMenu.innerHTML = arguments[2];
	}
}

function loadDataToDiv(parUrl,idDiv){
	getXhr();
	xhr.onreadystatechange = function(){
		if(xhr.readyState == 4 && xhr.status == 200){
			strRet = xhr.responseText;
			aRetour = strRet.split('jstoeval');
			if(aRetour[0]){
				if($(idDiv)){
					$(idDiv).innerHTML = aRetour[0];
				}
			}
			if(aRetour[1]){
				try {
					eval(aRetour[1]);	
				}catch (e) {
					a = "erreur";
				}
			}
			if($("adresse")) {
				initAutoCompl("adresse","autocomplete.php");
				setParamAutoCompl("adresse","type=adresse");
				setKeyDownAutoCompl("adresse","loadSelectRecherche('adresse='+$('adresse').value,'numeroAdr');changeRadio(2);");
			}
			if($("proprietaire")) {
				initAutoCompl("proprietaire","autocomplete.php");
				setParamAutoCompl("proprietaire","type=proprio");
				setKeyDownAutoCompl("proprietaire","changeRadio(1);");
			}			
		}		
	}
	xhr.open("GET",parUrl,true);
	xhr.send(null);	
}

function switchMenu(obj1) {
	if($(obj1)) {
		obj1 = $(obj1);
	}
	if (obj1.style.display != "block" ) {
		obj1.style.display = 'block';
	}
	else {
		obj1.style.display = 'none';
	}
}

//afficher ou non le menu de selection
function displayOrNotMenu(idDiv){
	var t ='';
	if($(idDiv).style.display == "block"){
		var divSel = $(idDiv);
		t = setTimeout("switchMenu('"+idDiv+"')",200);
		divSel.onmouseover = function(){
			clearTimeout(t);
		}
		divSel.onmouseout = function(){
			//t = setTimeout("switchMenu('"+idDiv+"')",10);
			divSel.style.display = "none";
		}
	}
}

function startExport(){
	
	
}
function startPrint(){
	var reference = "";
	var legende = "";
	var landscape = "";
	var echelle = $('echellePrint').value;
	var format = $('format').value;
	var urlPrint = $('urlPrint').value;
	var minx = $('minx').value;
	var maxx = $('maxx').value;
	var miny = $('miny').value;
	var maxy = $('maxy').value;
	var maxy = $('maxy').value;
	legende = "legende";
	var printHtml = $('html');
	var printWord = $('word');
	var printPdf = $('pdf');
	var printPng = $('png');
	var printJpg = $('jpg');
	if(echelle == ""){
		alert("Choisissez l'echelle d'impression !");
		return false;
	}
	else if(format == ""){
		alert("Choisissez un format de sortie !");
		return false;
	}
	if(_Photo)_Photo.beforeSubmit('fichePrint');
	$('fichePrint').submit();
}

function activeCheckContenuTheme(parIdTheme) {
	ulTHeme = $('lay_'+parIdTheme); 
	oCheck=$('check_'+parIdTheme);
	if (/images\/check_on\.gif/.test(oCheck.src)) {
		statusTheme = "no_actif";	
		active = true ; 
		oCheck.src = "images/check_off.gif";

		$('lay_'+parIdTheme).setOpacity(0.4);

	}else {
		active = false ;
		ulTHeme.style.display = 'block';
		statusTheme = "actif";
		oCheck.src = "images/check_on.gif";

		$('lay_'+parIdTheme).setOpacity(1);

	}
	inputDuTheme = ulTHeme.getElementsByTagName("input");
	for (var i = 0; i < inputDuTheme.length; i++) {
		if(inputDuTheme[i].type == "checkbox") {
			inputDuTheme[i].disabled = active ;	
		}
	}
	var argum = "themeToShow="+parIdTheme+"&status="+statusTheme;
	gMap.tool.sendActionToMap(argum);
	RECHARGER = true;
	arrayFieldRecherche = new Array();
}

function showHideLayer(parLayerName) {
	if(arguments[1]) {
		if(/images\/check_off\.gif/.test($('check_'+arguments[1]).src)) {
			return;
		}
	}
	
	statusTheme = "no_actif";
	oLayerName = $(parLayerName);
	
	if (/images\/check_on\.gif/.test(oLayerName.src)){
		oLayerName.src = "images/check_off.gif";
	}else {
		oLayerName.src = "images/check_on.gif";
		statusTheme = "actif";
	}
	
	var argum = "layerToShow="+parLayerName+"&status="+statusTheme;
	gMap.tool.sendActionToMap(argum);
	RECHARGER = true;
	arrayFieldRecherche = new Array();
}



function onFunction(){
	ROLLER_ACTIVATE = true; //activation du roller de la souris
}
function offFunction(){
	ROLLER_ACTIVATE = false; //désactivation du roller de la souris
	clearTimeout(tmrMove);
}

var id_select_to_load = null;
function loadSelectRecherche(param,idSel) {
	if(param == "")	return;
	id_select_to_load = idSel;
	traiteRequeteAdm('x_template.php',param,'GET','text',traiteLoadSelect);
}

function traiteLoadSelect(str) {
	if(id_select_to_load == null)return;
	var oRep = evalStrAutoCompl(str);
	if(oRep) {
		selCurr = $(id_select_to_load);
		selCurr.options.length = 0;
		selCurr.options[selCurr.options.length] = new Option('--','');
		for(var item in oRep) {
			selCurr.options[selCurr.options.length] = new Option(oRep[item].label,oRep[item].value);
		}
		if(selCurr.options[1]) {
			selCurr.options[1].selected = true;
		}	
	}	
}


function selectionRadio(theme) {
	REPONSE = true;
}





var RECHARGER = true;
var MAPSTATE = true;
var REPONSE = false;
function changeState(){
	MAPSTATE = true;
	REPONSE = false;
	RECHARGER = false;
}


function evalResponseAjax(strURL){
  xhrExtr = getXhrReturn();
  // On défini ce qu'on va faire quand on aura la réponse
  xhrExtr.onreadystatechange = function(){
    if(xhrExtr.readyState == 4 && xhrExtr.status == 200){
	    strReponse = xhrExtr.responseText;
			
	    try {
			 eval(strReponse);
			}catch(e) {
			///
			}
         
    }
  }
  xhrExtr.open("GET",strURL,true);
  xhrExtr.send(null);	
}

function evalInnerAjax(strURL,divId){
  xhrExtr = getXhrReturn();
  // On défini ce qu'on va faire quand on aura la réponse
  xhrExtr.onreadystatechange = function(){
    if(xhrExtr.readyState == 4 && xhrExtr.status == 200){
	    strReponse = xhrExtr.responseText;
	    //alert(strReponse);
	    try {
			 	eval(strReponse.replace(/^<script[^>]*?>/, '').replace(/<\/script>$/, ''));
			}catch(e) {
			///
			}
     
     $(divId).innerHTML = strReponse;    
    }
  }
  xhrExtr.open("GET",strURL,true);
  xhrExtr.send(null);	
}


function changeRadio(nb){
	for(var i=0; i < 3; i++){
		id2Elt("rParcelle_"+i).checked = false;
	}
	id2Elt("rParcelle_"+nb).checked = true;
	if(nb != 1){
		try{
			id2Elt('proprioRelative').style.display = "none";
		}catch(e){
			//////////
		}
	}
}



/// SI SANS PARAM, LOUPE SUR TOUTE LA SELECTION
function loupeSelection(table,oid,nomLayer) {
	if(!table && !oid) {
		argum = 'loupeAllSelection=true';
		gMap.tool.sendActionToMap(argum);
	}else {
		if(oid != ""){
			argum = 'tableZoom='+table+'&oidZoom='+oid+'&nomCouche='+nomLayer;
			gMap.tool.sendActionToMap(argum);
		}
	}			
}


/// SI SANS PARAM, SUPPR SUR TOUTE LA SELECTION
function supprSelection(obj,idSel,tblSel) {
	if(!obj && !idSel && !tblSel) {
		$('ctrlInfo').innerHTML = "";
		argum = 'typeSelection=delAll';
		gMap.tool.sendActionToMap(argum);
	}else {
		obj.parentNode.parentNode.parentNode.removeChild(obj.parentNode.parentNode);
		argum = 'typeSelection=delone&delTableSel='+tblSel+'&delidSel='+idSel;
		gMap.tool.sendActionToMap(argum);
	}
}

function sendSearchListeCompl() {
	if($('recherche_voie').getAttribute("textid") == "") {
		var param = $('recherche_voie').getAttribute("textid");
	}else {
		var param = $('recherche_voie').value;
	}

	argum = 'zoomVoie=oui&codeVoieZoom='+param;
	gMap.tool.sendActionToMap(argum);
}


function printAllFiche(orig,type,format){
	url = "x_template.php?orig="+orig+"&type="+type+"&format="+format;
	twAller(url,'','_blank');
}

function printFiche(orig,type,tableName,sqlWhere,layerName,oid,oFormat){
	format = $(oFormat).value;
	if(format == ""){
		alert("Choisissez un format !!");
		$(oFormat).focus();
		return false;
	}
	url = "print_template.php?orig="+orig+"&type="+type+"&format="+format+"&tableName="+tableName+"&sqlWhere="+sqlWhere+"&layerName="+layerName+"&oid="+oid;
	twAller(url,'','_blank');
}

function exportCsvFiche(orig,tableName,sqlWhere){
	url = "print_template_csv.php?orig="+orig+"&tableName="+tableName+"&sqlWhere="+sqlWhere;
	twAller(url,'','_blank');
}

var colorPickerObj = {	
	register: function(){
  	this.color = new photoPicker() ;
	},
  picker: function(img,inp,event){
  	var rgb = img.style.backgroundColor ;
  	var r,g,b ;
  	if(rgb == "" || rgb == "transparent"){
  		r = g = b = 255 ;
  	}else{
  		rgb = rgb.split("rgb(")[1].replace(")","").split(",");
  		r = rgb[0].trim();
  		g = rgb[1].trim();
  		b = rgb[2].trim();
  	}
  	var options = {
  		initColor:{r:r,g:g,b:b},
  		imgSet: img,
  		inputSet: inp
  	}
  	this.color.called(options,event);
  },
  closePicker: function(){
  	this.color.hide();
  }
};


function showPicker(idBackgroud,idInput,evt){
	colorPickerObj.picker($(idBackgroud),$(idInput),evt);
}

/* BUTTONS EFFECT */
function btover(oBtn){
	$(oBtn).style.backgroundPosition = "0 -"+oBtn.offsetHeight+"";
}
function btout(oBtn){
	$(oBtn).style.backgroundPosition = "0 0";
}

function tabClickStat(nTab){
	showDiv('statjour', 'none');
	showDiv('statsem', 'none');
	showDiv('statmois', 'none');
	showDiv('statannee', 'none');
	$(nTab).innerHTML = "Chargememt ...";
	showDiv(nTab, 'block');
	switch(nTab){
	    case 'statjour':
	        param = 'jour';
	        break;
	    case 'statsem':
	        param = 'semaine';
	        break;
	    case 'statmois':
	        param = 'mois';
	        break;
	    case 'statannee':
	        param = 'annee';
	        break;     
	}
	sRequest = 'act=changeonglet&periode='+param;
	 new Ajax('stat.inc.php',{
			method: 'get',
			postBody: sRequest,
			evalScripts: true
	 }).request();
	
}

function showDiv(nomDiv, mode){
	if(cibleClass = $(nomDiv)) {
		cibleClass.style.display = mode;	
		if(mode != 'none') nomDiv.className = "current";
	}
}

function exportStat(periode,paramDate){
   url = 'stat.inc.php?act=exportCsv&periode='+periode+'&paramDate='+paramDate;
    window.open(url);
}
function loadSortableTable(tbl,headers,data){
		new MooTable(tbl,{
			debug: false,
			height: '250px',
			headers: headers,
			sortable: true,
			useloading: false,
			resizable: false,
			data : data,
			pagination : 10,
			typepagination : 'fles'
		});
}
function verifaffichdivplusstyle(){
	elementsyl = $('plusstyle').style.display;
	if(elementsyl == 'none')$('plusstyle').style.display = 'block';
	else if(elementsyl == 'block')$('plusstyle').style.display = 'none';
}
function VerifyAnswer(e){
	// Détéction des browsers
	var strUserAgent = navigator.userAgent.toLowerCase(); 
	var isIE = strUserAgent.indexOf("msie") > -1; 
	var isNS6 = strUserAgent.indexOf("netscape6") > -1; 
	var isNS4 = !isIE && !isNS6  && parseFloat(navigator.appVersion) < 5; 

	if (isIE){
		iKeyCode = e.keyCode;
	} else {
		iKeyCode = e.which;		
	}
	
	if (((iKeyCode >= 48) && (iKeyCode <=57))|| (iKeyCode == 44) || (iKeyCode == 46) || (iKeyCode == 40) || (iKeyCode == 41) || (iKeyCode == 43) || (iKeyCode == 32) || (iKeyCode == 45) || (iKeyCode == 8) || (iKeyCode == 0)){
		if (isIE){
			e.returnValue = true;
		}
		else{
			return true;
		}
	}
	else{
		if (isIE){
			e.returnValue = false;
		}
		else{
			return false;
		}
	}
}
var TIMER_INFO_BULL;
function sendInfoBulle(evt){
	if(gMap.tool.mode != GSMAP_INFOBULL){
		return;
	}
	evt = new Event(evt);
	ptX = evt.client.x  - gMap.left; //$("visualisation").offsetLeft;
	ptY = evt.client.y - gMap.top;   //$("visualisation").offsetTop;
	var ajaxMove = new Ajax('ajaxRep.inc.php?ptX='+ptX+'&ptY='+ptY,{
	 	method:'get',
		postBody:'',
		onComplete: function(originalRequest){
			try {
				eval(originalRequest);
			}catch(e) {
				//
			}
		}
	});
	clearInfoBulle() ; 
	TIMER_INFO_BULL = (function(){
		ajaxMove.request();
	}).delay(500 , this);
}
function clearInfoBulle(){
	$clear(TIMER_INFO_BULL);
}
function initMenu(el){
	el = $(el);
	var aUl = el.getElements('ul');
	for(var iL=0; iL < aUl.length; iL++){
		aUl[iL].style.display = 'none';
		aUl[iL].style.visibility = 'hidden';
	}
}

function setEventMenu(el){
	el = $(el);
	PARENTUL = el;
	
	var aLi = el.getElements('li');
	for(var iL=0; iL < aLi.length; iL++) {
		var li = aLi[iL];
		var lilab = aLi[iL].getElements('label')[0];
		if(!lilab) continue;
		lilab.addEvent('click',function() {
			var ul = this.parentNode.getElements('ul');
			var ull = this.parentNode.parentNode.getElements('ul');
			for(var iull=0; iull < ull.length; iull++) {
				if(ul && ul[0] && ull[iull] === ul[0]) {
					ul[0].style.position = 'absolute';
					ul[0].style.top = this.parentNode.offsetTop+'px';
					ul[0].style.left = this.parentNode.offsetLeft+this.parentNode.offsetWidth-8+'px';
					if(ul[0].style.display == 'none') {
						ul[0].style.display = 'block';
						ul[0].style.visibility = 'visible';
					}else {
						ul[0].style.display = 'none';
						ul[0].style.visibility = 'hidden';
					}
				}else {
					ull[iull].style.display = 'none';
					ull[iull].style.visibility = 'hidden';
				}
			}
		});

		li.addEvent('mousemove',function() {
			clearTimeout(CMPTIMER);
		});
	}
	el.addEvent('mouseout',function () {
		CMPTIMER = setTimeout('hideul()',800);
	});

}

function openuserprofil_(iduser) {
	var parurl = "admin/profil.php";
	var titre = "EDTION DES PROFILS";
	openCadre(parurl,titre, 285, 379);
}

/* PRECHARGEMENT DES IMAGES */

var img01 = new Image(); img01.src = "images/refmap.gif";
var img02 = new Image(); img02.src = "images/nav/sub1f.png";
var img03 = new Image(); img03.src = "images/nav/sub2f.png";
var img04 = new Image(); img04.src = "images/nav/sub3f.png";
var img05 = new Image(); img05.src = "images/nav/sub4f.png";
var img06 = new Image(); img06.src = "images/nav/sub5f.png";
var img07 = new Image(); img07.src = "images/nav/sub6f.png";
var img08 = new Image(); img08.src = "images/nav/sub7f.png";
var img09 = new Image(); img09.src = "images/nav/sub8f.png";
var img10 = new Image(); img10.src = "images/nav/sub9f.png";
var img11 = new Image(); img11.src = "images/nav/sub10f.png";
var img12 = new Image(); img12.src = "images/nav/sub11f.png";
var img13 = new Image(); img13.src = "images/nav/sub12f.png";
var img14 = new Image(); img14.src = "images/nav/sub13f.png";
var img15 = new Image(); img15.src = "images/nav/sub14f.png";
var img16 = new Image(); img16.src = "images/nav/sub1n.png";
var img17 = new Image(); img17.src = "images/nav/sub2n.png";
var img18 = new Image(); img18.src = "images/nav/sub3n.png";
var img19 = new Image(); img19.src = "images/nav/sub4n.png";
var img20 = new Image(); img20.src = "images/nav/sub5n.png";
var img21 = new Image(); img21.src = "images/nav/sub6n.png";
var img22 = new Image(); img22.src = "images/nav/sub7n.png";
var img23 = new Image(); img23.src = "images/nav/sub8n.png";
var img24 = new Image(); img24.src = "images/nav/sub9n.png";
var img25 = new Image(); img25.src = "images/nav/sub10n.png";
var img26 = new Image(); img26.src = "images/nav/sub11n.png";
var img27 = new Image(); img27.src = "images/nav/sub12n.png";
var img28 = new Image(); img28.src = "images/nav/sub13n.png";
var img29 = new Image(); img29.src = "images/nav/sub14n.png";
var img30 = new Image(); img30.src = "images/nav/ctrlinfo1.gif";
var img31 = new Image(); img31.src = "images/nav/ctrlinfo2.gif";
var img32 = new Image(); img32.src = "images/nav/ctrlinfo3.gif";
var img33 = new Image(); img33.src = "images/nav/ctrlinfo4.gif";
var img34 = new Image(); img34.src = "images/nav/ctrlinfo5.gif";
var img35 = new Image(); img35.src = "images/nav/ctrlinfo6.gif";
var img36 = new Image(); img36.src = "images/photoPicker/pikerbg.png";

/* THEME */
function sendChecked(elt){
	var oTheme = $('ulctrlThemes');
	var aOCheck = oTheme.getElementsByTagName("input");
	var aCheck = new Array();
	for(i = 0; i < aOCheck.length ; i++ ){
      var oCheck = aOCheck[i];
      if(oCheck.checked && oCheck.value != "" && oCheck.name != "anarana")aCheck.push(oCheck.id);
   }
	parCadre = "layerCheck="+aCheck;
	curMode = gMap.tool.mode;
	gMap.tool.setMode(GSMAP_VISIBLE) ;
	gMap.mode_old = curMode ;
	gMap.sendX_Load(parCadre) ;	
	return true;
}
function checkAllGroupe(elt,idDiv){
  var oDiv = $(idDiv);
  var aOCheck = oDiv.getElementsByTagName("input");
  if(elt.checked){
  	for(i = 0; i < aOCheck.length ; i++ ){
  		aOCheck[i].checked = true;
  	}
  }else{
  	for(i = 0; i < aOCheck.length ; i++ ){
  		aOCheck[i].checked = false;
  	}
  }
  sendChecked(elt);
}
function checkGroup(idGroupeInput,idDiv){
	var oInputMere = $(idGroupeInput);
	var oDiv = $(idDiv);
	var nombreDesInputCoche = 0;
	var nombreDesInputDecoche = 0;
	var aOCheck = oDiv.getElementsByTagName("input");
	for(i = 0; i < aOCheck.length ; i++ ){
		if(aOCheck[i].checked) nombreDesInputCoche++;
		else nombreDesInputDecoche++;
	}
	if(nombreDesInputCoche == i) oInputMere.checked = true;
	else if(nombreDesInputDecoche <= i) oInputMere.checked = false;
}

function showLayer(param){
	if($(param).style.display == 'block' || $(param).style.display == ''){
		$(param).style.display = 'none' ;
			elt = $(param).parentNode ;
			if(elt.tagName.toLowerCase() == 'li'){
				elt.childNodes[0].src = 'images/sidebar/plus.gif' ;
			}
	}
	else if($(param).style.display == 'none'){
		$(param).style.display = 'block' ;
		elt = $(param).parentNode ;
		if(elt.tagName.toLowerCase() == 'li'){
			elt.childNodes[0].src = 'images/sidebar/minus.gif' ;
		}
	}
}
function showAllLayer(param){
	ult = $(param) ;
	aLi = ult.getElementsByTagName('li') ;
	if(aLi[0].style.display == 'block' || aLi[0].style.display == ''){
		for(iLi=0; iLi < aLi.length ; iLi++){
			aLi[iLi].style.display = 'none' ;
		}
		ult.childNodes[0].src = 'images/sidebar/plus.gif' ;	
	}
	else{
		for(iLi=0; iLi < aLi.length ; iLi++){
			aLi[iLi].style.display = 'block' ;
		}
		ult.childNodes[0].src = 'images/sidebar/minus.gif' ;
	}
}
function showAllLayer2(param,idimg){
	var objImg = $(idimg);
	ult = $(param) ;
	if(ult.style.display == 'block'  || ult.style.display == '') {
		ult.style.display = 'none' ;
		objImg.src = 'images/sidebar/plus.gif' ;
	}else {
		ult.style.display = 'block' ;
		objImg.src = 'images/sidebar/minus.gif' ;
	}
}
function displayOpacity(divopac,divlog){
	//clearTimeout(optmr);
	opacdiv = $(divopac);
	logdiv = $(divlog);
	
	opacdiv.style.display = "block";
}

function hideOpacity2(divopac){
	$(divopac).style.display = "none";
}

var optmr ;
function hideOpacity(obj){
	optmr = setTimeout("hideOpacity2('"+obj+"')",500);
}

function keepOpacity(){
	window.clearTimeout(optmr);
}



function showClass(param){
	ult = $(param) ;
	if(ult){
		if(ult.style.display == 'block'  || ult.style.display == ''){
			ult.style.display = 'none' ;
		}else {
			ult.style.display = 'block' ;
		}
	}
}
var groupOrder = new Array();

var aListMap = "";
var aListGroup = "";
function getordergroupMap(groupMap,igroup) {
	var aGroup = new Array();
	var aMap = new Array();
	if($(groupMap)) {
		list = $(groupMap).getElementsByTagName('a');
		for(i = 0 ; i < list.length; i++) {
			if(list[i].getAttribute('niveauObj',false) == "group") {
				aGroup.push(list[i].firstChild.data);
			}
		}			
		mapname = $("LIMVMAP_"+igroup).getElementsByTagName('span'); 	
		thismap = mapname[0].firstChild.data;	
	}	
	
	
	var parentdiv = $("lgdContain");
	var tagg = parentdiv.getElementsByTagName("span");	
	for(j = 0 ; j < tagg.length; j++) {
		if(tagg[j].getAttribute('niveauObj',false) == "map") {
			aMap.push(tagg[j].firstChild.data);
		}
	}

	if(aListGroup == aGroup.toString())  {
		return;
	}
	aListGroup = aGroup.toString();
		
	parCadre = "&agroup="+aGroup+"&amap="+aMap+"&thismap="+thismap+"&act=movelayergroup";
	curMode = gMap.tool.mode;
	gMap.tool.setMode(GSMAP_CHG_CARTE) ;
	gMap.mode_old = curMode ;
	gMap.sendX_Load(parCadre) ;

}

function getmaporder(){
	var aMap = new Array();
	var parentdiv = $("lgdContain");
	var tagg = parentdiv.getElementsByTagName("span");	
	for(j = 0 ; j < tagg.length; j++) {
		if(tagg[j].getAttribute('niveauObj',false) == "map") {		
			aMap.push(tagg[j].firstChild.data);
		}
	}
	if(aListMap == aMap.toString()) {
		return;
	}
	aListMap = aMap.toString();
	
	parCadre = "&amap="+aMap+"&act=movegroupmap";
	curMode = gMap.tool.mode;
	gMap.tool.setMode(GSMAP_CHG_CARTE) ;
	gMap.mode_old = curMode ;
	gMap.sendX_Load(parCadre) ;	
	
}
function activerNested(){
	var xposcur = null;	
	if($('ulctrlThemes')){
		sortIt = new Nested('ulctrlThemes',{
			collapse: true,			
			onStart: function(el) {
				el.addClass('drag');
				xposcur = el.getTop();
			},
			onComplete: function(el){
				if(!el.moved){
					nodeType = el.getAttribute('sous_type') ;
					if(nodeType == 'span'){
						aL = el.getElementsByTagName('span') ;
						showAllLayer2(aL[0].getAttribute('divcorres'),aL[0].getAttribute('groupAct'));
					}
					else{
						aL = el.getElementsByTagName('a') ;
						showClass(aL[0].getAttribute('divcorres'));	
					}
					return ;
				}
				el.removeClass('drag');	
				var listInput = $('ulctrlThemes').getElementsByTagName('input') ;
				var aresult = new Array()
				for(i=0; i < listInput.length; i++){
					if(listInput[i].type != 'checkbox')continue ;
					aresult.push(listInput[i].value) ;
				}
				var parCadre = "&act=movetheme&list="+aresult;
				gMap.sendX_Load(parCadre) ;	
			}
		}) ;
	}
}


function griseCouche(cch){
	if($('beginLegende')){
		ulList = $('beginLegende').getElementsByTagName('ul') ;
		for(i=0;i< ulList.length;i++){
			liList = ulList[i].getElementsByTagName('li') ;
			for(j=0;j< liList.length;j++){
				if(liList[j].getAttribute('ident') == null || liList[j].getAttribute('ident') == '-1_-1')continue ;
				scaleCouche = liList[j].getAttribute('ident').split('_') ;
				if(parseInt(cch) < parseInt(scaleCouche[0]) || parseInt(scaleCouche[1]) < parseInt(cch)){
						liList[j].className = 'lgdthm_off' ;
				}
				else{
					liList[j].className = 'lgdthm_on' ;
				}
			}
		}
	}
}

function selectTypePrint(param){
	if($('type_result1').checked == false && $('type_result2').checked == false){
		alert('Veuillez d\'abord selectionner l\'un des 2 choix en haut');
		return;
	}else if($('type_result1').checked == true){
		if(param == 'html')window.open('x_template.php?liste_result_rech&excel=non&action=all','_blank');
		else if(param == 'pdf')window.open('x_template.php?liste_result_rech&print=pdf&action=all','_blank')
		else if(param == 'csv')window.open('x_template.php?export=exportCsv&action=all','_blank');
	}else if($('type_result2').checked == true){
		if(param == 'html')window.open('x_template.php?liste_print_fiche_all=oui&action=all','_blank');
		else if(param == 'pdf')window.open('x_template.php?liste_print_fiche_all=oui&action=all&print=pdf','_blank');
		else if(param == 'csv')window.open('x_template.php?liste_print_fiche_all=oui&action=all&print=csv','_blank');
	}
}

function startPrintSelectListe(){
	if($('format_export1').checked == false && $('format_export2').checked == false && $('format_export3').checked == false){
		alert('Veuillez d\'abord selectionner une format d\'impression: soit PDF , soit CSV ou impression immediat! ');
		return;
	}else if($('format_export1').checked == true)selectTypePrint('html');
	 else if($('format_export2').checked == true)selectTypePrint('pdf');
	 else if($('format_export3').checked == true)selectTypePrint('csv');
	removeCadre(this);
}

function configMasque(arrayIdMasque){
	$('navsub').style.display = 'block' ;
	$('controlMain').style.display = 'block' ;
	if(arrayIdMasque.length == 0)return ;
	for(i=0;i< arrayIdMasque.length;i++){
		try{
			$(arrayIdMasque[i]).style.display = 'block' ;
			if(arrayIdMasque[i] == "outil_selection" || arrayIdMasque[i] == "outil_recherche"){
				$("outil_resultat").style.display = 'block' ;
			}
		}catch(e){}
	}
}

/* Dimensions de la fenêtre d'affichage du navigateur */

function getWindowHeight() {
	if (document.all) {
		return document.body.offsetHeight; 
	} 
	else { 
		return window.innerHeight; 
	}
}

function getWindowWidth() { 
	if (document.all) { 
		return document.body.offsetWidth; 
	} 
	else { 
		return window.innerWidth; 
	}
}