var strLastNomRecherche="";
var curXBulle = 0;
var curYBulle = 0;
var infoBulle = null;
var lastIdentObj = "";
var callFiche = "";
var identFiche = "";

// test pour ouverture de fiche metropole
var haveMoreInfo = false;

function initSpecificComponents(){
 var cliW = document.body.clientWidth;
 var cliH = document.body.clientHeight;
 var objDivMap = document.getElementById("divMap");
 
 objDivMap.style.width = 570+"px";
 objDivMap.style.height = 652+"px"; 
 objDivMap.style.left = ((cliW/2) - (parseInt(objDivMap.style.width)/2) - 18)+"px";
 objDivMap.style.top = 0+"px";
 objDivMap.style.zIndex = 500;
 
 document.getElementById('divBandeau').style.left = objDivMap.style.left;
 document.getElementById('divBandeau').style.width = objDivMap.style.width;
 
  StyleSheetChanger(".divFonction"  , "left", ((parseInt(objDivMap.style.left) + parseInt(objDivMap.style.width)) + 12) +"px");  
  
   StyleSheetChanger(".divFonction"  , "left", ((parseInt(objDivMap.style.left) + parseInt(objDivMap.style.width)) + 12) +"px");  
   
 document.getElementById('divFonction').style.top    = 158 +"px";
 document.getElementById('divFonction').style.zIndex = 5;
 
 document.getElementById('divRightCol').style.left = (parseInt(objDivMap.style.left) + parseInt(objDivMap.style.width))+"px";
 document.getElementById('divRightCol').style.top  = (parseInt(objDivMap.style.top) - 11)+"px";
 document.getElementById('divLeftCol').style.left  = (parseInt(objDivMap.style.left) - parseInt(document.getElementById('divLeftCol').style.width))+"px";
 document.getElementById('divLeftCol').style.top   = (parseInt(objDivMap.style.top) - 11)+"px";
 document.getElementById('divBottom').style.left   = (parseInt(objDivMap.style.left))+"px";
 document.getElementById('divBottom').style.top    = (parseInt(objDivMap.style.top) + parseInt(objDivMap.style.height))+"px";
 document.getElementById('divBottom').style.width  = (parseInt(objDivMap.style.width))+"px";
 document.getElementById('divBottomLeft').style.left  = (parseInt(document.getElementById('divBottom').style.left) - parseInt(document.getElementById('divBottomLeft').style.width) + 1)+"px";
 document.getElementById('divBottomLeft').style.top   = document.getElementById('divBottom').style.top;
 document.getElementById('divBottomRight').style.left = document.getElementById('divRightCol').style.left;
 document.getElementById('divBottomRight').style.top  = document.getElementById('divBottom').style.top;
 document.getElementById('divTopLeft').style.left  = (parseInt(document.getElementById('divBandeau').style.left) - parseInt(document.getElementById('divTopLeft').style.width))+"px";
 document.getElementById('divTopLeft').style.top   = 6+"px";
 document.getElementById('divTopRight').style.left = document.getElementById('divRightCol').style.left;
 document.getElementById('divTopRight').style.top  = 6+"px";
 
 document.getElementById('divProgress').style.top  = (parseInt(objDivMap.style.top) + 159)+"px";
 document.getElementById('divProgress').style.left = (parseInt(objDivMap.style.left) + 11)+"px";
 
  
 
{
  StyleSheetChanger(".divOngletLegende"  , "top", 158+"px");  
  StyleSheetChanger(".divOngletLegende"  , "left", document.getElementById('divLeftCol').style.left);
  StyleSheetChanger(".divOngletLegende"  , "width", ((parseInt(document.getElementById('divLeftCol').style.width) - 12))+"px");
  StyleSheetChanger(".divOngletLegende"  , "height", 36+"px");
  
  StyleSheetChanger(".divOngletActif"  , "top", 158+"px");
  StyleSheetChanger(".divOngletActif"  , "left", document.getElementById('divLeftCol').style.left);
  StyleSheetChanger(".divOngletActif"  , "width", ((parseInt(document.getElementById('divLeftCol').style.width) - 12))+"px");

 
  StyleSheetChanger(".divfLegendeContainerbg", "top", 188+"px");
  StyleSheetChanger(".divfLegendeContainerbg", "left", document.getElementById('divLeftCol').style.left);
  StyleSheetChanger(".divfLegendeContainerbg", "width", ((parseInt(document.getElementById('divLeftCol').style.width)-12))+"px");

  StyleSheetChanger(".divfLegendeContainer", "top", 188+"px");
  StyleSheetChanger(".divfLegendeContainer", "left", document.getElementById('divLeftCol').style.left);
  StyleSheetChanger(".divfLegendeContainer", "width", ((parseInt(document.getElementById('divLeftCol').style.width)-12))+"px");
  
  StyleSheetChanger("#fLegende", "left", 20+"px");
  StyleSheetChanger("#fLegende", "height", 340+"px");
 
	
 }
   StyleSheetChanger(".divResultat",  "top", ((parseInt(document.getElementById('divFonction').style.top) + 33))+"px");
   StyleSheetChanger(".divResultat",  "left", ((parseInt(objDivMap.style.left) + parseInt(objDivMap.style.width)) + 12)+"px");
   //if(isMinNS4 == 1)
   //StyleSheetChanger(".divResultat",  "width", ((parseInt(document.getElementById('divRightCol').style.width)-28)) + "px");
   
   document.getElementById('divCredits').style.top = ((parseInt(document.getElementById('divLeftCol').style.height) - 45))+"px";
   document.getElementById('divCredits').style.left = ((parseInt(objDivMap.style.left) + parseInt(objDivMap.style.width)) + 12)+"px";
   
   
   document.getElementById('divBtLegende').style.top = ((parseInt(document.getElementById('divLeftCol').style.height) - 45))+"px";
   
   document.getElementById('divBtLegende').style.left = parseInt(document.getElementById('divLeftCol').style.left) +"px";
	document.getElementById('divBtLegende').style.width = (parseInt(document.getElementById('divRightCol').style.width)-72)+"px";
   
  
   StyleSheetChanger(".divMiniMap", "left",((parseInt(objDivMap.style.left) + parseInt(objDivMap.style.width)) + 57)+"px");
   
   
   
  
}
var currentpositionFlashX = 0;
var currentpositionFlashY = 0;
UpdateMousePosition = function(x,y)
{
	ConvertViewToSys(x,y);
	currentpositionFlashX = mapCurrentX;
	currentpositionFlashY = mapCurrentY;

}

function clearMap()
{
	legendeIsLoaded = false;
	//szUser = "";
	//szClientID = 0;
	//UpdateUserConnection();
	
	var chaine = szHttpServeur + "&ACTION=ResetMapVisibility&DYMMY="+new Date().getTime()+"&PORT="+szPort ;
	
	var param = new HttpRequestParam( "GET", chaine, function(xmlhttp) {ClearMap();});
	xmlHttpRequest(param);
	
	
}

function getMiniInfo(strlayer,strIdent)
{
	var loc = location.href;
	strLastNomRecherche = strlayer;
	var chaine = szHttpServeur +
                "&ACTION=GetInfo!EMPRISE=ALL!"+
								"!SELECT=" + strlayer + "@1" +
								"!OUTPUTSIZE=300@150!ALPHAJ=" + strIdent + "!CHAMPS1=!CHAMPS2="+
								"!LOCATION=" + loc ;
	updateBufferMiniInfo(chaine);
}

function updateBufferMiniInfo(target)
{

frames['bufferMiniInfo'].location.href=target+"XSL=miniinfo.xsl&FORMAT=" + szFormat + "&PORT=" + szPort;


}
 
function moveBulle(force)
{
	if(currentpositionFlashX!=0)
	{
		curXBulle = currentpositionFlashX;
		curYBulle = currentpositionFlashY;
		currentpositionFlashX = 0;
		currentpositionFlashY = 0;
	}
	MouseOnItemRechercheMap(curXBulle,curYBulle)
	ConvertSysToView(curXBulle,curYBulle);
	infoBulle.moveTo(viewCurrentX,viewCurrentY);
	var fTop = parseFloat(infoBulle.owner.style.top);
	
	if(force)
	infoBulle.mustMove = true;
	if((fTop<0)&&(force))
	{
		infoBulle.owner.style.top = 0;
		
		infoBulle.setVisible(false);
		ApplyPanMap(0,0,0,-fTop);
		
	}
	

}

function displayBulle(content)
{
/*
var szPlusDinfo = "<table width=\"100%\"><tr><td style=\"text-align:right;\"><table><tr><td><a style=\"color:red\" border=\"0\"  onclick=\"javascript:ClickItemRechercheInfo(callFiche,'"+identFiche+"','','');\" href=\"javascript:;\"><img border=\"0\" src=\"iconToolBar/miniinfo.gif\" alt=\"Consulter les informations détaillées\"></img></td><td valign=\"middle\"><a  style=\"color:red\" border=\"0\"  onclick=\"javascript:ClickItemRechercheInfo(callFiche,'"+identFiche+"','','');\" href=\"javascript:;\">Plus d'informations</a></td></tr></table></td></tr></table></a>"*/


var szPlusDinfo = "<table width=\"100%\"><tr><td/><td class=\"btplusinfo\"  valign=\"middle\" align=\"center\"><a  border=\"0\"  href=\"javascript:ClickItemRechercheInfo(callFiche,'"+identFiche+"','','');\" href=\"javascript:;\">en savoir +</a></td></tr></table>"


if(haveMoreInfo)
	content = "<div>" +content  + "</div><div>" + szPlusDinfo + "</div>";
	else
content = "<div>" +content  + "</div>";

	infoBulle.setContent(content);
	moveBulle(true);
}

function loadMiniInfo()
{

 var inner = "";
inner = frames['bufferMiniInfo'].document.body.innerHTML;
 //var obj = document.getElementById("iframMiniInfo");

    if(inner!="")
    {
	/*	
		if(obj!=null)
		{
           obj.innerHTML =inner ;
			}
           showObject("iframMiniInfo");*/
		  displayBulle(inner);
          
    }
     else
     {
          	/*if(obj!=null)
                obj.innerHTML = "";*/
              
          }
   
   
}

function searchElementNearStreet(szAJ,szRechercheName)
{
var loc = location.href;
 var chaine = szHttpServeur  + "&ACTION=Recherche!NAME="+szRechercheName+"!INTERACTIVE=2!ALLFILTERS=1!ALLFILLED=0!PREVFILTER=!LOCATION=" + loc +"&NINTERFILTER=100&CODERUE="+szAJ;
updateBufferResultat(chaine);
								
}


function getProximiteRue(OID,szNomRecherche,idDiv)
{
	szNomRecherche = escape(szNomRecherche);
	
	setTimeout("execProximiteRue(\""+OID+"\",\""+szNomRecherche+"\","+idDiv+")",200);
}
function execProximiteRue(OID,szNomRecherche,idDiv)
{


	var loc = location.href;
	var chaine = szHttpServeur +
	                "&ACTION=GetInfo!EMPRISE=ALL!" +
									"!SELECT=" + szNomRecherche + "@1" +
									"!ALPHAJ=" + OID +"!PARAMXML=<SRC oid=\""+OID+"\" recherche=\""+szNomRecherche+"\"/>"+
									"!LOCATION=" + loc +"&bummy="+ new Date().getTime() +"&PORT=" + szPort;
									
	var param = new HttpRequestParam( "GET", chaine, function(xmlhttp) {displayInfoPOI(xmlhttp.responseText,idDiv,szNomRecherche,OID);});
	xmlHttpRequest(param);

}


function ClickItemRechercheMapProximite(szSrcRecherche,szOID,szNomRecherche,szAlphaJ,szChamp1,szChamp2,preservesel) {
	var loc = location.href;
	var szPreserve = "";
	
	if(preservesel)
	{

		szPreserve = "PRESERVESEL=1!";
	}
	
	var chaine1 = szHttpServeur + "&ACTION=ResetMapVisibility&DYMMY="+new Date().getTime()+"&PORT="+szPort ;
	
	var param1 = new HttpRequestParam( "GET", chaine1, function(xmlhttp) {
	
	
	var chaine = szHttpServeur +
                "&ACTION=BuildMap!EMPRISE=ALL!OUTPUTSIZE=10@10" +
								"!SELECT=" + szSrcRecherche + "@1" +
								"!ALPHAJ=" + szOID + "!REALYPAINT=0!CHAMPS1="+
								"!LOCATION=" + loc ;
	var param = new HttpRequestParam( "GET", chaine+"&PORT="+szPort, function(xmlhttp) {ClickItemRechercheMap(szNomRecherche,szAlphaJ,szChamp1,szChamp2,preservesel);});
		xmlHttpRequest(param);					
});		
xmlHttpRequest(param1);
								

		
	
	
}

function showHelpFile()
{
	window.open("http://www.chambery-metropole.fr/3142.htm");
}

var scriptToEval = [];
function displayInfoPOI ( content,idDiv,szNomRecherche,OID )
	{

	
		document.getElementById("divInfoPOI"+idDiv).innerHTML = content;
		scrollerres.updateScroller();
		ClickItemRechercheMap(szNomRecherche,OID,"","");

	}
		
function evalNextScript()
{
	if(scriptToEval.length>0)
	{
	
		thescript = scriptToEval[0];
		scriptToEval.shift();
		evalCurrentSrcipt(thescript);
		
		
	}
}

function evalCurrentSrcipt(thescript)
{
	eval(thescript);
}

		
var curIDPrefixe = "";
function ZoomAllPOI(szNomRecherche,szListPOI)
{
//divhalte.style.display = "block";

	
	var loc = location.href;
	
	
	reg = new RegExp(",","ig");
	var thePOIo = szListPOI;
	thePOI = thePOIo.replace(reg,"@");
	
				 // recentrage sur l'objet d'origine
	var w = 10;
	var h = 10;
	if(scriptToEval.length==0)
	{
		 w = mapClientwidth;
		 h = mapClientheight;
	}
	
	w = mapClientwidth;
	h = mapClientheight;
	
	var chaine = szHttpServeur +
                "&ACTION=BuildMap!EMPRISE=" + mapleft + "@" + mapbottom + "@" + (mapright-mapleft) + "@" +  (maptop - mapbottom) + "!OUTPUTSIZE=" + w + "@" + h +
								"!PRESERVESEL=1!SELECT="+szNomRecherche+"@0" +
								"!ALPHAJ=" + thePOI + 
								"!LOCATION=" + loc   ;

	isloading = false;
	
	if(scriptToEval.length==0)
	{
		updateBufferMap(chaine);
	}
	else
	{
		var param = new HttpRequestParam( "GET", chaine+"&PORT="+szPort, function(xmlhttp) {evalNextScript();});
		xmlHttpRequest(param);
	}
	
	//setTimeout("RequestCoordPOI('"+szNomRecherche+"','"+thePOIo+"');",20);
	
}


function RequestCoordPOI(szNomRecherche,thePOI)
{


	curIDPrefixe = szNomRecherche;
	var loc = location.href;
	var POIFILTER = "";
	var tPOILocal = []
	tPOILocal = thePOI.split(",");
	tHALTE = [];
	
	if(szNomRecherche=='Halte')
	{
		tHALTEG = tHALTE;
	}
	for(k=0;k<tPOILocal.length;k++)
	{
		POIFILTER = POIFILTER + "&OID="+tPOILocal[k];
		curPOI = new POI(0,0,tPOILocal[k],szNomRecherche,k);
		tHALTE.push(curPOI);
		
	}
	
	
	var chaine = szHttpServeur + "&XSL=reqpoi.xsl&ACTION=Recherche!NAME="+szNomRecherche+"!LOCATION=" + loc + "!NO_SELECTION!INTERACTIVE=2"+POIFILTER+"&PORT=" + szPort;

	var param = new HttpRequestParam( "GET", chaine, function(xmlhttp) {displayPOI(xmlhttp.responseText);});
	xmlHttpRequest(param);
}

// ouvre une url dans une nouvelle fenetre
function openlink(url)
	{
		window.open(url)
	}