function $( id)
{
	return document.getElementById( id);
}

function selectAll( checked, id)
{
	var i = 1;
	while( $( id+i))
	{
		$( id+i).checked = checked;
		i++;
	}
}

function showHide( id)
{
	if( $( id).style.display == "none" )
		$( id).style.display = "";
	else
		$( id).style.display = "none";
}

function popup( link, idFenetre, height, width)
{
	window.open ( link.href, idFenetre, config='height='+height+', width='+width+', toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, directories=no, status=no');
}

function stats( lang, page1, page2, regId, depId, campId)
{
	var rand = Math.round(Math.random()*10000000000);
	var url = '/stats.php?';
	if( lang != '' )
		url += 'lang='+lang+'&';
	if( page1 != '' )
		url += 'page1='+page1+'&';
	if( page2 != '' )
                url += 'page2='+page2+'&';
	if( regId != '' )
                url += 'regId='+regId+'&';
	if( depId != '' )
                url += 'depId='+depId+'&';
	if( campId != '' )
                url += 'campId='+campId+'&';
	url += 'rand='+rand;
	
	document.write('<img src="'+url+'" width="1" height="1" />');
}

function changeOnglet( onglet, liste)
{

	var ongletExist = false;
	for( i=0; i<liste.length; i++)
	{
		$(liste[i]+"_contenu").style.display = "none";
		$(liste[i]+"_img").src = "/Icons/"+lang+"/onglet_"+liste[i]+"_off.gif";
		if( liste[i] == onglet )
			ongletExist = true;
	}
	if( !ongletExist)
		onglet = liste[0];
	$(onglet+"_contenu").style.display = "";
	$(onglet+"_img").src = "/Icons/"+lang+"/onglet_"+onglet+".gif";
}


//GoogleMap
var map = null;
var geocoder = null;
function loadMap( text, address)
{
        if (GBrowserIsCompatible())
        {
                map = new GMap2($("map"));
                map.addControl(new GLargeMapControl());
                map.addControl(new GMapTypeControl());
                geocoder = new GClientGeocoder();
                geocoder.getLatLng( address, function(point) {
                                                        if (point)
                                                        {
                                                                map.setCenter(point, 13);
                                                                map.openInfoWindowHtml(map.getCenter(), text);
                                                                map.addOverlay(new GMarker(point));
                                                        }
                                                });
        }
        window.onUnload = GUnload;
}

function loadIti( text, addressTo, addressFrom)
{

        if (GBrowserIsCompatible())
        {
		$("planIti").style.display = "";
		Hiti = $("itiplan");

                iti = new GMap2(Hiti);
                iti.addControl(new GLargeMapControl());
                iti.addControl(new GMapTypeControl());
		$("trajet").innerHTML = "";
		directions = new GDirections( iti, $("trajet"));
		directions.load("from: " + addressFrom + " to: " + addressTo, { preserveViewport: true, getSteps: true, locale: "fr_FR" });
        }
        window.onUnload = GUnload;
}

function campingUp( id)
{
	campingMove( id, -1);
}

function campingDown( id)
{
	campingMove( id, 1);
}

function campingMove( id, value)
{
	var tabCamping = campingListAll();
        campingRemoveAll();
        var len = tabCamping.length;
        var position = false;
        for(i=0; i<len; i++)
        {
                if( tabCamping[i].id == id)
                {
                        position = i;
                }
        }

        if( position !== false && position + value >= 0 && position + value < tabCamping.length )
        {
                var campTmp = tabCamping[position+value];
                tabCamping[position+value] = tabCamping[position];
                tabCamping[position] = campTmp;
        }
        campingCreateAll( tabCamping);	
}

function campingCreateAll( tabCamping)
{
	var camp = $( "listeCampings");
	var len = tabCamping.length;
        for(i=0; i<len; i++)
        {
		camp.appendChild( tabCamping[i]);
        }	
}

function campingListAll()
{
	var camp = $( "listeCampings");
        var len = camp.childNodes.length;
	var tabCamping = Array();
	for( i=0; i<len; i++)
        {
                if( typeof camp.childNodes[i].id != "undefined" )
                {
                        tabCamping.push( camp.childNodes[i]);
                }
        }
	return tabCamping;
}

function campingRemove( id)
{
	var camp = $( "listeCampings"); 
	var anciennoeud = camp.removeChild( $( id));
}

function campingRemoveAll()
{
	var camp = $( "listeCampings");
        while (camp.firstChild)
        {
          camp.removeChild(camp.firstChild);
        }
}

