/**************************************************************************
 ** Projet :					CRAQUITAINE
 ** Nom du fichier :			craquitaine.inc.js
 ** Créé le :				02/03/2007										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;
var jsarray = null;
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('compatible'))
			{
			    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;  
    }    
    document.getElementById('visualisation').style.cursor = usedCursor;  
}
function changeTypeCursor(tag,cursorType){
    visu = document.getElementById(tag);
    visu.style.cursor = cursorType;	
}
function changeCarte(idcarte){	
    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 = document.getElementById(nomNav+nav);		
	if (iCur == nav) {
	    cur.className="current";
	}else {
	    cur.className="";
	}
    }
}
function smoothloading(cur){
    if(document.all) {
	n+=1;
	cur.filters.alpha.opacity = n;
    }
    else {
	n+=2;
	b = n/100;
	cur.style.setProperty("-moz-opacity", b, "");
    }
    if ( n <= 100 ) tempoAnim = setTimeout("smoothloading(cur)",50);
}
function showDivSdb(nomDiv, mode){
    if(!document.getElementById(nomDiv)) {
	return false
	    }
    if(cibleClass = document.getElementById(nomDiv)) {
	cibleClass.style.display = mode ;	
	if(mode != 'none') nomDiv.className = "current";
	n = 0;
	cur = document.getElementById(nomDiv);
	document.getElementById("control").style.width = "300px";
	document.getElementById("controlContent").style.display = "block";
	if(parseInt(document.getElementById("controlContent").style.width) < 250)
	    ity("controlContent").style.width = "230px";
	//document.getElementById("visualisation").style.width = "560px";
	document.getElementById("ctrlMask").style.display = "block";
	//smoothloading(cur);
    }
}
function tabClick(nTab){
    showDivSdb('ctrlResearch', 'none');
    showDivSdb('ctrlResult', 'none');	
    showDivSdb('ctrlLegend', 'none');	
    showDivSdb('buttonRecherche', 'none');	
    if(nTab == "") {
	$("control").style.width = "20px";
	$("controlContent").style.display = "none";
	$("ctrlMask").style.display = "none";
    }
    else{
	if(nTab == 'ctrlResearch'){
	    clickOnglet = 'Recherche' ;
	    showDivSdb('buttonRecherche', 'block'); 
	}
	else if(nTab == 'ctrlResult')clickOnglet = 'Resultats' ;
	else if(nTab == 'ctrlLegend')clickOnglet = 'Legende' ;
	showDivSdb(nTab, 'block'); 
    }
}
function switchMenu(obj1){
    var el = document.getElementById(obj1);
    if ( el.style.display != "block" ) {
	el.style.display = 'block';
    }
    else {
	el.style.display = 'none';
    }
}
function twAller(_url,_cadre,_target){		
    if (_url){
	if (_cadre){
	    parent._cadre.location.href = _url;
	} 
	else if (_target){
	    _target = window.open(_url,_target);
	} 
	else{
	    window.location.href = _url;
	}
    }
}
function showLayer(param){
    if(ity(param).style.display == 'block' || ity(param).style.display == ''){
	ity(param).style.display = 'none' ;
	elt = $(param).parentNode ;
	if(elt.tagName.toLowerCase() == 'li'){
	    elt.childNodes[0].src = 'images/plus.gif' ;
	}
    }
    else if($(param).style.display == 'none'){
	$(param).style.display = 'block' ;
	elt = ity(param).parentNode ;
	if(elt.tagName.toLowerCase() == 'li'){
	    elt.childNodes[0].src = 'images/minus.gif' ;
	}
    }
}
function showAllLayer(param){
    ult = ity(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/plus.gif' ;	
    }
    else{
	for(iLi=0; iLi < aLi.length ; iLi++){
	    aLi[iLi].style.display = 'block' ;
	}
	ult.childNodes[0].src = 'images/minus.gif' ;
    }
}
function showAllLayer2(param,idimg){
    ult = $(param) ;
    aLi = ult.getElementsByTagName('li') ;
    var objImg = document.getElementById(idimg);
    if(aLi[0].style.display == 'block' || aLi[0].style.display == ''){
	for(iLi=0; iLi < aLi.length ; iLi++){
	    aLi[iLi].style.display = 'none' ;
	}
	objImg.src = 'images/plus.gif' ;	
    }
    else{
	for(iLi=0; iLi < aLi.length ; iLi++){
	    aLi[iLi].style.display = 'block' ;
	}
	objImg.src = 'images/minus.gif' ;
    }
}
function showLegend(param){
    imlgd = ity(param) ;
    if(imlgd.style.display == 'none'){
	imlgd.style.display = 'block';
    }
    else {
	imlgd.style.display = 'none';
    }
}

function reloadlegendContent() {	
    var parurl = "legende.pop.php";	
    xhrrleg = getXhrPost();
    var param = "act=reload";
    xhrrleg.onreadystatechange = function() {
	if(xhrrleg.readyState == 4 && xhrrleg.status == 200) {
	    Windows.getWindow('L�gende').setHTMLContent(xhrrleg.responseText);
	    var curw = $("lgdContainChecked").offsetWidth;
	    var curh = $("lgdContainChecked").offsetHeight;
	    Windows.getWindow('L�gende').setSize(curw,curh);
  	}
    }
    xhrrleg.open("POST",parurl,true);
    xhrrleg.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    xhrrleg.send(param);	
}

function sendChecked(){	
    layerCheck = new Array();  
    var lgd = $('lgdContain');
    var tabCheck = $('lgdContain').getElementsByTagName('input');
    for(i=0; i<tabCheck.length;i++){
	if(tabCheck[i].checked)layerCheck.push(tabCheck[i].value+'_ON');
	else layerCheck.push(tabCheck[i].value+'_OFF');
    }
    parCadre = "layerCheck="+layerCheck+"&act=visible";
	
    if(Windows.getWindow('L�gende')){
	Windows.getWindow('L�gende').setHTMLContent("Chargement ...");
	parCadre += "&reloadlegend=1";
    }
	
    gMap.tool.setMode(GSMAP_VISIBLE);
    gMap.sendX_Load(parCadre);
    gMap.tool.setMode(GSMAP_PAN);
    return true;
}
function openPopUpWithName(winurl,namePop){
    var top=(screen.height-500)/2;
    var left=(screen.width-500)/2;
    var winPopup = window.open(winurl, namePop,"top="+top+",left="+left+",width=400,height=300,status=no,resizable=no,scrollbars=yes");
    winPopup.focus();
}
function zoomScale(paramScale){
    parCadre = "scale="+paramScale+"&act=zoomScale";
    gMap.tool.setMode(GSMAP_SCALE) ;
    gMap.sendX_Load(parCadre) ;	
    gMap.tool.setMode(GSMAP_PAN) ;
}
//::GESTION FICHIER MAP:://
function changemap(fichier){
    fichier = fichier+".map";
    parCadre = "fichier="+fichier+"&act=mvMap";
    gMap.tool.setMode(GSMAP_CHG_CARTE) ;
    gMap.sendX_Load(parCadre) ;	
    gMap.tool.setMode(GSMAP_PAN) ;
}
///GET TOP AND GET LEFT
function getLeftAvecBody(l){
    if (l.offsetParent) return (l.offsetLeft + getLeft2(l.offsetParent));
    else return (l.offsetLeft);
}
function getLeft2(l){
    leftRetour = getLeftAvecBody(l);
    if (document.all){
	bod = document.getElementById('body');
	leftRetour = leftRetour  + parseInt(bod.style.borderWidth);
    }
    return leftRetour ;
}
function getTopAvecBody(l){
    if (l.offsetParent) return (l.offsetTop + getTop2(l.offsetParent));
    else return (l.offsetTop);
}
function getTop2(l){
    topRetour = getTopAvecBody(l);
    if (document.all){
	bod = document.getElementById('body');
	topRetour = topRetour  + parseInt(bod.style.borderWidth);
    }
    return topRetour ;
}
//	Fonction permettant de superposer un div sur un autre
function toTop(divId){
    var aList = new Array('div','img');
    var zIndexMax = 0;
    for (iList=0;iList < aList.length ; iList++){
	var listDiv = document.getElementsByTagName(aList[iList]);
	for (var i = 0; i < listDiv.length; i++) {
	    if (parseInt(listDiv[i].style.zIndex) > parseInt(zIndexMax)) {
		zIndexMax = parseInt(listDiv[i].style.zIndex);
	    }
	}
    }
    //document.getElementById('gsMap').style.zIndex = 0;
    if(document.getElementById(divId)) {
	document.getElementById(divId).style.zIndex = parseInt(zIndexMax) + 1;
    }else {
	divId.style.zIndex = parseInt(zIndexMax) + 1;
    }
}
function wait(stat){
    if(stat == 'ON'){
	ity('divWait').style.display = 'block' ;
	topWaiting = 275;
	leftWaiting = 375;
	if(ity('ctrlMask').display == 'block' || ity('ctrlInfo').display == 'block')leftWaiting = leftWaiting + 25 ;
	ity('divWait').style.top = topWaiting+'px' ;
	ity('divWait').style.left = leftWaiting+'px' ;
    }
    else if(stat == 'OFF')ity('divWait').style.display = 'none' ;
    return true ;
}
function getListe(val){
    if(val == "")return ;
    var parurl = "ajax.inc.php";	
    xhrListe = getXhrPost();
    param = "niv="+val ;
    xhrListe.onreadystatechange = function() {
	if(xhrListe.readyState == 4 && xhrListe.status == 200) {
	    try{
		eval(xhrListe.responseText);
	    }
	    catch(e){
		var s = ity('detSelect');
		s.options.length = 0;
	    }
  	}
    }
    xhrListe.open("POST",parurl,true);
    xhrListe.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    xhrListe.send(param);
}
function cadreReference(){
    var couche = ity('nivSelect').value ;
    var recherche = ity('detSelect').value ;
    if(recherche == "" || couche == ""){
	alert('Choississer un niveau!') ;
	return false ;
    }
    parCadre = "couche="+couche+"&recherche="+recherche+"&act=cadre";
    gMap.tool.setMode(GSMAP_ZOOM_COM) ;
    gMap.sendX_Load(parCadre) ;		
    gMap.tool.setMode(GSMAP_PAN) ;
}
function getMousePoseInfo(e){
    if(document.all){
	posx = event.x;
	posy = event.y;
    }else{
	posx = e.pageX ;
	posy = e.pageY;
    }
    return new Array(posx,posy);
}
function getOffset(element,attr){
    var offset=0;
    element = $(element);
    while(element){
	offset+=element[attr];
	element=element.offsetParent
	    }
    return offset;
}

function createAndAppend(tag,parentObj,bool){
    if(bool) {
	var newElement = document.createElement(tag);
    }else {
	var newElement = document.createTextNode(tag);
    }
    if(arguments[3]) {
	$(parentObj).insertBefore(newElement,$(parentObj).firstChild);
    }else {
	$(parentObj).appendChild(newElement);
    }
    return newElement;
}
function launchTransparence(val, param){
    gMap.tool.setMode(GSMAP_TRANSPARENCE_LAYER) ;
    parSend = 'act=transCouche&trp='+val+'&group='+param ;
    gMap.sendX_Load(parSend) ;		
    gMap.tool.setMode(GSMAP_PAN) ;
}
function closeGuide(){
    if(Windows.getWindow('Guide')){
	Windows.getWindow('Guide').close() ;
    }	
}
function openCadre(urlPage,titre, w, h,resizable){
    if(!w) w = 500;
    if(!h) h = 350;
    if(titre == 'Impression'){
	var scaleCur = gMap.scale.toInt();
	urlPage = urlPage+"?scaleCur="+scaleCur;
    }
    gWindowz.calledAjaxContent(titre,{
	    className: 'dialog',
		title: titre,
		draggable: true,
		resizable: resizable,
		maximizable:   false,
		width: w,
		height: h,
		minWidth: 320,
		maxWidth: 800,
		minHeight: 50,
		maxHeight: 800
		},urlPage);
    if(urlPage == "legende.pop.php"){
	gWindowz.setLocation(150, 650);	
    }
    else gWindowz.setLocation(150, 250);
}
function displayOpacity(divopac,divlog){
    //clearTimeout(optmr);
    opacdiv = document.getElementById(divopac);
    logdiv = document.getElementById(divlog);
	
    opacdiv.style.display = "block";
}
function hideOpacity2(divopac){
    document.getElementById(divopac).style.display = "none";
}
var optmr ;
function hideOpacity(obj){
    optmr = setTimeout("hideOpacity2('"+obj+"')",500);
}
function keepOpacity(){
    window.clearTimeout(optmr);
}
function findServices(){
    tabClick('ctrlResult');
    navCurrent('control',2,4);
    setTitleLabel('Resultats');
	
    var param = "act=findservice";
	
    var otheme = ity("slcthm");
    var owifi = ity("chkwifi");
    var owimax = ity("chkwimax");
	
    theme = otheme.options[otheme.options.selectedIndex].value;	
	
    param += "&theme="+theme;	
    if(owifi.checked) param += "&wifi=1";
    if(owimax.checked) param += "&wimax=1";
	
    var parurl = "ajax.inc.php";
    var xhrserv = getXhrPost();
	
    document.getElementById("ctrlResult").innerHTML = "Chargement...";
    xhrserv.onreadystatechange = function(){
	if(xhrserv.readyState == 4 && xhrserv.status == 200){
	    document.getElementById("ctrlResult").innerHTML = xhrserv.responseText;
	}
    }
    xhrserv.open("POST",parurl,true);  
    xhrserv.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    xhrserv.send(param);	
}
function findSousServices(){
    $("ctrlResult").innerHTML = "Chargement ..." ;
    tabClick('ctrlResult');
    navCurrent('control',2,4);
    setTitleLabel('Resultats');
    var osubservice = ity("valSousService");
}

function checkAllSServiceNew(obj, idUlContent){
    var asserv = $(idUlContent).getElementsByTagName("input");
    for(it = 0; it <  asserv.length; it++){ 
	if(asserv[it].type == 'checkbox') {			
	    asserv[it].checked = obj.checked;
	}
    }
    checkserviceinlegende();
}

function checkServiceInputNew(obj, idUlContent, idInputCtrl){
    var asserv = $(idUlContent).getElementsByTagName("input");
    var res = false ;
    for(it = 0; it <  asserv.length; it++){
	if(asserv[it].type == 'checkbox'){
	    if(asserv[it].checked == true){
		res = true ;
		break;
	    }
	}
    }
    checkserviceinlegende();	
    $(idInputCtrl).checked = res ;
}

function checkserviceinlegende(){
    var asserv = $("controlservice").getElementsByTagName("input");
    for(it = 0; it <  asserv.length; it++){
	if(asserv[it].type == 'checkbox'){
	    var idchklayer = "chklayer_"+asserv[it].value;
	    if(ity(idchklayer)) ity(idchklayer).checked = asserv[it].checked ;
	}
    }
}

function sh(idO, oClick){
    var elt = $(idO) ;
    if(elt){ 
	if(elt.style.display == 'none'){
	    elt.style.display = 'block' ;
	    oClick.style.background = 'url(images/minus1.gif) 0 0 no-repeat' ;
	}
	else{
	    elt.style.display = 'none' ;
	    oClick.style.background = 'url(images/plus_lgd.gif) 0 0 no-repeat' ;
	}
    }
}
function sh2(idO, tagbtn){
    var oClick = ity(tagbtn);
    sh(idO,oClick);
}
function logout(){
    var authentCont = ity("authentdiv");
    var connectedUserCont = ity("userconnect");	
    var divId = ity("users");
    divId.style.display = "none";	
    authentCont.style.display = "block";	
    connectedUserCont.style.display = "none";	
    ity("chplogin").value = "";
    ity("chppasswd").value = "";
		
}
function changeAcces(users,acces, login){
    if(login=="TRUE"){
	//alert(acces) ;
	var authentCont = ity("authentdiv");
	var connectedUserCont = ity("userconnect");	
	authentCont.style.display = "none";	
	connectedUserCont.style.display = "block";
	var strHTML =users+"<br><br>Vous &ecirc;tes dans l'espace "+acces ;
	ity("lblusername").innerHTML = strHTML;
	var changeacces = "act=changeAcces";
	gMap.tool.setMode(GSMAP_CHG_CARTE) ;
	gMap.sendX_Load(changeacces) ;	
	gMap.tool.setMode(GSMAP_PAN) ;
    }	

}
function refreshListService(strList){
    var oService = ity("listsousservice");
    var aList = strList.split(",");
    oService.length = 0;
    addOptionSelectThm(oService,"Choisir","");
    for(i = 0; i < aList.length; i++){
	addOptionSelectThm(oService,aList[i],aList[i]);
    }
    ity("listSousServices").innerHTML = "";
}

function refreshListTheme(strList){
    var oTheme = ity("listtheme");
    var aList = strList.split(",");
    oTheme.length = 0;
    addOptionSelectThm(oTheme,"Choisir","");
    for(i = 0; i < aList.length; i++){
	addOptionSelectThm(oTheme,aList[i],aList[i]);
    }
}

/// FONTIONS MANIPULATION SELECT
function addOptionSelectThm (objSelect,label,opt) {
    if(document.getElementById(objSelect)) {
	objSelect = document.getElementById(objSelect);
    }
    objSelect.options[objSelect.options.length] = new Option(label,opt);
    return objSelect.options[(objSelect.options.length-1)];
}


function manageUsers(){
    var divId = ity("users");
    divId.style.display = "block";	
}
function findTheme(otheme){
    tabClick('ctrlResult');
    navCurrent('control',2,4);
    setTitleLabel('Resultats');
	
    var theme = otheme.options[otheme.options.selectedIndex].value;	
    var param = "act=findtheme";
    param += "&theme="+theme;	
	
    var parurl = "ajax.inc.php";
    var xhrserv = getXhrPost();
    document.getElementById("ctrlResult").innerHTML = "Chargement...";
    xhrserv.onreadystatechange = function(){
	if(xhrserv.readyState == 4 && xhrserv.status == 200){
	    document.getElementById("ctrlResult").innerHTML = xhrserv.responseText;
	}
    }
    xhrserv.open("POST",parurl,true);  
    xhrserv.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    xhrserv.send(param);
}
function loadSousService(oservice){
    var service = oservice.options[oservice.options.selectedIndex].value;		
    var param = "act=loadsousserv";
    param += "&service="+service;		
    var parurl = "ajax.inc.php";	
    var xhrsubser = getXhrPost();
    xhrsubser.onreadystatechange = function(){
	if(xhrsubser.readyState == 4 && xhrsubser.status == 200){
	    document.getElementById("listSousServices").innerHTML = xhrsubser.responseText;
	}
    }
    xhrsubser.open("POST",parurl,true);  
    xhrsubser.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    xhrsubser.send(param);
}
/********Constantes************/
var vitRed = 4; // vitesse de transition lors de la r�duction ou de l'agrandissemnt, en %
var DurRed = 10; // dur?entre deux appels de la fonction, en ms
var wmax = 200; // le width max de la cadre r�f�rence 
var wmin = 0;
function showControl(tagdiv,show){	
    var ctrltagDiv = ity(tagdiv);
    var wnow = parseInt(ctrltagDiv.style.width.split("px")[0]);
    var tmpcib = 0;
    if(show){
	tmpcib = wnow + ( wmax * vitRed / 100 );
    }
    else{
	tmpcib = wnow - ( wmax * vitRed / 100 );
    }
    if ( tmpcib >= wmin && tmpcib <= wmax ) {
	ctrltagDiv.style.width = tmpcib + "px";
	(show) ? setTimeout("showControl(true);",DurRed) : setTimeout("showControl(false);",DurRed);
    }
}
function openQuestionnaire(){
    var parurl = "questionnaire.pop.php";
    openCadre(parurl,"Votre avis", 350, 500,true);
}
function checkQuestions(){
    var oprue = ity("operateur_rue");
    var opcp = ity("operateur_cp");
    var opville = ity("operateur_ville");
	
    var formQues = ity("questionfrm");
    var res = true;
    if(oprue.value == "" || opcp.value == "" || opville.value == "") res = false;
    if(res){
	formQues.submit();
    }
    else{
	alert("Vous devez remplir les champs obligatoires");
    }
}
function closeStiky(idSticky){
    if(Windows.getWindow(idSticky)){
	Windows.getWindow(idSticky).close() ;
    }	
    return ;
}

function openUserGuide(param){
    var urlGuide = "accueil.pop.php" ;   
    if(param != "")urlGuide += "?theme="+param ;
    var entete = "Pr\351sentation" ;
    openCadre(urlGuide,entete,500,300,true);
}

function zoomZonegeo(){
    var oObj = ity("valzonegeo");
    parCadre = "valzonegeo="+oObj.value+"&act=zoomzonegeo";
    gMap.tool.setMode(GSMAP_CHG_CARTE) ;
    gMap.sendX_Load(parCadre) ;	
    gMap.tool.setMode(GSMAP_PAN) ;
}
function initializezone(){
    var oValGeo = ity("valzonegeo");
    oValGeo.value = "";
    $("zoneGeo_com").checked = true;
    $("ctrlResearch_listdept").options.selectedIndex = 0;
    $("result_ctrlResearch").value= "" ;
    if($('input_ctrlResearch'))$("input_ctrlResearch").value = "";
}
function showContenuObj(elt){
    obj = $(elt) ;
    leStyle = obj.style ;
    if(leStyle.display == "block"){
	leStyle.display = "none" ;
	if(arguments[1]){
	    sp = arguments[1] ;
	    var im = sp.getElementsByTagName('img');	
	    ims = im[0];		
	    ims.src = "images/plus.gif" ;
	}
    }else{
	leStyle.display = "block" ;
	if(arguments[1]){
	    sp = arguments[1] ;
	    var im = sp.getElementsByTagName('img');	
	    ims = im[0];		
	    ims.src = "images/minus_lgd.gif" ;
	}
    }
}

/* 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; 
    }
} 
function setLayoutStyle(elt,attr,val) {
    if(arguments[3])alert(arguments[3]);	
    if($(elt)) {
	try { $(elt).setStyle(attr,val); }
	catch(e) {}
    }	
}
function initlayout() {
    xWin = getWindowWidth();
    yWin = getWindowHeight();
    oBanner = $('banner');
    oNavmain = $('navmain');
    oContainer = $('container');
    oNavrgt = $('navrgt');
    oNavthm = $('navthm');
    oVisu = $('visualisation');
    oControl = $('control');
    oCtrlmain = $('controlMain');
    oCtrlmain.style.width = "20px";
    oFooter = $('footer');
    oLayerbk = $('layerbk');

    yoContainer = yWin - (oBanner.offsetHeight + oNavthm.offsetHeight + 5);
    xoVisu = xWin - (parseInt(oCtrlmain.style.width) + oNavrgt.offsetWidth + 8);
    yoVisu = yoContainer - oFooter.offsetHeight;
    parS = 20 ;
    if(document.all)parS = 25 ;
    yoPaneau = yoVisu - parS ;
    yoPaneauListe = yoVisu - 200 ;
    setLayoutStyle(oControl,'position','absolute');
    setLayoutStyle(oContainer,'width',xWin.offsetWidth);
    setLayoutStyle(oContainer,'height',yoContainer);
    setLayoutStyle(oVisu,'width',xoVisu);
    setLayoutStyle(oVisu,'height',yoVisu);
    setLayoutStyle($('controlContent'),'height',yoVisu);
    setLayoutStyle($('ctrlResult'),'height',yoPaneau);
    setLayoutStyle($('ctrlLegend'),'height',yoPaneau);
    setLayoutStyle($('ctrlResearch'),'height',yoPaneau);
    setLayoutStyle($('listSousServices'),'height',yoPaneauListe);
	
    // Ajout BCN 05.11.2007
    setLayoutStyle($('controlContent'),'width',250);
    setLayoutStyle($('controlContent'),'height','90%');
    setLayoutStyle($('ctrlResult'),'width',250);
    setLayoutStyle($('ctrlLegend'),'width',250);
    setLayoutStyle($('ctrlResearch'),'width',250);
	
	
	
    setLayoutStyle(oLayerbk,'height',yoVisu);
}

var asousservice = new Array();

function loadsousserivceSLBOX(){
    var serv = document.getElementById("service_slctbox");
    var souserv = ity('sousserv_slct');
    iindex = serv.options.selectedIndex;		
    if(iindex > 0){
	souserv.options.length = 0;
	addOptionSelectThm(souserv,"Choisir",0);
	for(i = 0; i < asousservice[iindex-1].length; i++){
	    addOptionSelectThm(souserv,asousservice[iindex-1][i],asousservice[iindex-1][i]);				 
	}
    }
}
var clickOnglet = null ;
function openAide(){
    if(clickOnglet == null)return false ;
    var thmPrm = 'aide.php?theme='+clickOnglet ;
    var ttWin = clickOnglet ;
    if(clickOnglet == 'Legende')ttWin = "Options affichage" ;
    openCadre(thmPrm,ttWin,500,300,true);
}
function checkAllServiceInput(but){
    var aInput = $('sousservice').getElementsByTagName('input') ;
    for(i = 0; i < aInput.length; i++){
	if(aInput[i].type =="checkbox" && aInput[i].id != "zoneGeo")aInput[i].checked = but.checked ;
    }
    checkserviceinlegende();
}
function checkLayer(parLayer){
    var tabCheck = $('lgdContain').getElementsByTagName('input');
    for(i = 0; i < tabCheck.length; i++){
	if(parLayer.indexOf(tabCheck[i].value) != -1)tabCheck[i].checked = true ;
    }
}
function griseGeo(obj){
    var hCtrlR = $('listSousServices').style.height ; 
    var divWidth = hCtrlR.split('px') ; 
    if(obj.checked){
	$('listSousServices').style.height = divWidth[0]-140+"px" ;
	$('ctrlZoneGeo').style.display = "block" ;
	$('ctrlResearchService').style.display = "block" ;
    }else{
	$('ctrlResearchService').style.display = "none" ;
	$('ctrlZoneGeo').style.display = "none" ;
	$('ctrlZoneGeo').style.height = 0 ;
	hgtServ = parseInt(divWidth[0])+140 ;
	$('listSousServices').style.height = hgtServ+"px" ;
    }
}

function baseName(path) {
    var filename = path.split('/');
    if (filename.length == 1) {
	var filename = path.split("\\");    
    }
    filename = filename[filename.length-1];
    return filename;
}

function hidePanneauOnmouseOut(){
    if(clrTmr)return ;
    $("ctrlResearch").show();
    $("ctrlLegend").hide();
    $("ctrlResult").hide();
    $("controlContent").show();
    $("control").style.width = "20px";	
    showPan = false ;
}
/*
  function hidePanneauOnmouseOut(){
  if(clrTmr)return ;
  $("ctrlResearch").hide();
  $("ctrlLegend").hide();
  $("ctrlResult").hide();
  $("controlContent").hide();
  $("control").style.width = "20px";	
  showPan = false ;
  }
*/

function refreshlengend(){
    if(Windows.getWindow('L\351gende')){
	Windows.getWindow('L\351gende').setHTMLContent("Chargement ...");
	reloadlegendContent();
    }
    else {
	openCadre('legende.pop.php','L\351gende', 250, 200, true);
	//var curw = $("lgdContainChecked").offsetWidth;
  	//var curh = $("lgdContainChecked").offsetHeight;
  	//Windows.getWindow('L�gende').setSize(curw,curh);
    }
}

function loadSortableTable(tbl,headers,data) {
    new MooTable(tbl,{
	    debug: false,
		height: '250px',
		headers: headers,
		sortable: true,
		sortable: true,
		useloading: false,
		resizable: false,
		data : data,
		pagination : false,
		typepagination : 'fles'
		});
}
