// JavaScript Document

function runStartList()
{
var ls=window.StartList;
if (ls)
	{
	for(i=0;i<ls.length;i++)
		{
		//alert(fnc);
		fnc=ls[i];
		if (typeof(fnc)=='function')	fnc();
		else							eval(fnc);
		}
	}
}

window.onload=runStartList;

function realReplace (sStr,sFind,sReplace)
{
//Replace an element for each occurence (js replace doesn't seem to do correctly)
var lPos=0;
var lCount=0;
var i;

//Count occurences
lPos=sStr.indexOf (sFind,lPos)
while (lPos!=-1)
	{
	lCount++;
	lPos=sStr.indexOf (sFind,lPos+1);
	}
//replace
for (i=0;i<lCount;i++)	sStr=sStr.replace (sFind, sReplace);
return(sStr);
}

getOffsetPosition=function(oObj,inTYPE)
{
var iVal=0;
var sType='oObj.offset'+inTYPE;
while (oObj && oObj.tagName!='BODY')
	{
	iVal+=eval(sType);
	oObj=oObj.offsetParent;
	}
return iVal;
}

function checkUncheck(objName)
{
obj=document.getElementById(objName)
if (obj)
	{
	//alert(obj.nodeName);
	if (obj.nodeName=='INPUT')
		{
		//alert(obj.checked);
		if (obj.checked==true)	obj.checked=false;
		else					obj.checked=true;
		}
	}
}

function inputEncode(str)
{
return str.replace('"', '&#034;');
}


function popupLien(obj)
{
if (obj)
	{
	if (obj.nodeName=='A')	window.open(obj.href);
	}
return false;
}

function switchBlocDiv(obj,p)
{
var n=10;
while (n>0 && obj.className.substr(0,4)!='Bloc')
	{
	obj=obj.parentNode;
	n--;
	}
if (obj && n>0)
	{
	if (p)	obj.className='Bloc'+p;
	else	obj.className='Bloc';

	for (i=0;i<obj.childNodes.length;i++)
		{
		if (obj.childNodes[i].nodeName=='DIV')
			{
			if (obj.childNodes[i].style.display=='none')	obj.childNodes[i].style.display='';
			else											obj.childNodes[i].style.display='none'
			}
		}
	}
return false;
}


function switchOuterBloc(obj,largeur)
{
var n=10;
while (n>0 && obj.className.substr(0,4)!='Bloc')
	{
	obj=obj.parentNode;
	n--;
	}
if (obj && n>0)
	{
	if (largeur)	obj.className='Bloc'+largeur;
	else			obj.className='Bloc';
	}
return false;
}

function openCarteCommune(id,lat,lon,elo,mt)
{
var obj=document.getElementById(id);
if (!elo)	elo=14;
if (!mt)	mt=G_HYBRID_TYPE;
if (obj && GBrowserIsCompatible())
	{
	if (obj.style.display=='none')
		{
		obj.style.display='block';
		map=new GMap2(obj);
		map.addControl(new GMapTypeControl());
		map.addControl(new GSmallMapControl());
		map.setCenter(new GLatLng(lat/1000000,lon/1000000),elo,mt);
		}
	else	obj.style.display='none';

	return false;
	}
return true;
}

function bgFocus(obj)
{
if (obj)
	{
	if (obj.className!='Focus')
		{
		obj.className='Focus';
		}
	else
		{
		obj.className='';
		}
	}
}


