var lastZoom = new Array();
function changeSvgSrc(spath)
{document.svgmap.setSrc(spath);
svgChanged();}
function svgChanged()
{setTimeout('setAllCheck()',1000);}
function setAllCheck(){var vCheck='cklay';
for (i=0;i<99;i++) {  vCheck='cklay'+i;
if (document.forms['frmLay'].elements[vCheck]) 
	{  document.forms['frmLay'].elements[vCheck].onclick();
		document.forms['frmLay'].elements[vCheck].onclick();}
}
if (document.forms['frmLay'].ckfd) 
	{	document.forms['frmLay'].ckfd.onclick();
		document.forms['frmLay'].ckfd.onclick();	
	}
}

function beforeZoom(){ 
	if(lastZoom!=null){
		root.currentTranslate.x = lastZoom["tX"];		 
		root.currentTranslate.y = lastZoom["tY"];		
		root.currentScale		= lastZoom["scale"];
	}
}

function layerShow(theCheckBox, theLayer)
{
var oLay = document.svgmap.getSVGDocument().getElementById(theLayer);
if (oLay) {
 if (theCheckBox.checked==false) VisState="hidden"; else VisState="visible";
 oLay.getStyle().setProperty("visibility", VisState); }
}
function zoomMap(k) { 
svgdoc=document.svgmap.getSVGDocument(); root=svgdoc.getDocumentElement();
lastZoom["tX"]		= root.currentTranslate.x;
lastZoom["tY"]		= root.currentTranslate.y;
lastZoom["scale"]	= root.currentScale;

sViewbox = root.getAttribute("viewBox");var vbox = sViewbox.split(' ');
x0 = parseInt(vbox[0]);y0 = parseInt(vbox[1]);
vboxW = parseInt(vbox[2]);vboxH = parseInt(vbox[3]);
svgW = parseInt(root.getAttribute("width"));svgH = parseInt(root.getAttribute("height"));
x1 = root.currentTranslate.x;
y1 =root.currentTranslate.y;
s1=root.currentScale;
px=(svgW/2);py=(svgH/2);
rx=(vboxW/svgW); ry=(vboxH/svgH);
if (k == 99) 
	{
	root.currentScale = 1;
	root.currentTranslate.x=1;
	root.currentTranslate.y=1;
	return;
	}
else
	{
	root.currentScale = root.currentScale * k;
	}

// Nouvelle étendue (pixel)
s2=root.currentScale;
// Calcul des coords reelles du centre de la fenêtre
cx1 = x0+(px-x1)*(rx/s1);
cy1 = y0+(py-y1)*(ry/s1);
// Calcul de la translation nécessaire pour replacer au centre le point cx1/cy1
x2 = px - ((cx1-x0)/(rx/s2));
y2 = py - ((cy1-y0)/(ry/s2));
root.currentTranslate.x=x2;
root.currentTranslate.y=y2;
}

function panMap(dx,dy) {
var decal = 100;
//SVGSTEP 
svgdoc=document.svgmap.getSVGDocument(); root=svgdoc.getDocumentElement();
lastZoom["tX"]		= root.currentTranslate.x;
lastZoom["tY"]		= root.currentTranslate.y;
lastZoom["scale"]	= root.currentScale;

if (dx!=0) root.currentTranslate.x=root.currentTranslate.x+(dx*decal);
if (dy!=0) root.currentTranslate.y = root.currentTranslate.y+(dy*decal);
}



// --- 04/10/04 JI SP2 compatible
// --- Revisé le 05/04/2005 par JI
// Le try catch n'est pas tres propre, il est pourtant necessaire quand la popup
// est fermé manuellement.

var newWin = new Object();
parent.openWindow = openWindow;

function openWindow (path,param1,param2)
{
    try
    {
        // Si la popup newWin existe il est préférable de changer l'url de la popup.
        // (Ce qui était fait avant : on rappelé la fonction open et IE crashé aléatoirement lors de stress)
        if (newWin.toString() != "[object Object]") 
        {
            newWin.changeLocation(path);
            newWin.focus();
        }
        else // La popup newWin n'existe pas on la créer
        {
            newWin = window.open(path,param1,param2);
            newWin.focus();
        }
    }
    catch(e) // La popup myWin à été fermée mais l'objet myWin existe toujours en memoire => on la réouvre
    {
        newWin = null;
        newWin = window.open(path,param1,param2);
        newWin.focus();        
    }
}
function newWinChangeLocation (newLocation)
{
    newWin.changeLocation(newLocation);
}

function changeLocation (newLocation)
{
    location.href = newLocation;
}

