// Fichier de fonctions javascript

function goto(page)
{	if (page != '')
	{	document.location.href=page;
	}
}

function popup(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=800,height=600');");
}

//function s_hide(o) { if (o == menu_affiche) { setTimeout('ss_hide("'+o+'")',2000); } else { document.getElementById(o).style.display = "none"; } menu_affiche = ''; }
function s_hide(o) { document.getElementById(o).style.display = "none"; menu_affiche = ''; }
function s_show(o) { document.getElementById(o).style.display = "block"; menu_affiche = o; }
//function ss_hide(o) { document.getElementById(o).style.display = "none"; menu_affiche = ''; }

function switch_display_hide(div) {
    if (document.getElementById(div).style.display == "block")
    {   s_hide(div);
    }
    else{
        s_show(div);
    }
}

function switch_hide_display(div) {
    if (document.getElementById(div).style.display == "none")
    {   s_show(div);
    }
    else{
        s_hide(div);
    }
}

function switch_display_hide_w_pic(div,image,img_plus,img_moins){
    if (document.getElementById(div).style.display == "block")
    {   document.getElementById(image).src = img_plus;
        document.getElementById(div).style.display = "none";
    }
    else{
        document.getElementById(image).src = img_moins;
        document.getElementById(div).style.display = "block";
    }
}

function switch_hide_display_w_pic(div,image,img_plus,img_moins){
    if (document.getElementById(div).style.display == "none")
    {   document.getElementById(image).src = img_moins;
        document.getElementById(div).style.display = "block";
    }
    else{
        document.getElementById(image).src = img_plus;
        document.getElementById(div).style.display = "none";
    }
}

// AJAX
function writebox(texte,id_box,htmlorvalue) {
	if (htmlorvalue == 'value') {
		document.getElementById(id_box).value = texte;
	}
	else {
		document.getElementById(id_box).innerHTML = texte;
	}
}

function ajax(fichier,destination,htmlorvalue) {
	if (text = file(fichier))
    {   writebox(text,destination,htmlorvalue);
    }
    else
    {   writebox('Erreur. Fichier : '+fichier+' - Bloc de destination : '+destination,destination);
    }
}

function file(fichier) {
    if (window.XMLHttpRequest)
    {     xhr_object = new XMLHttpRequest();
    }
    else if(window.ActiveXObject)
    {     xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else
    {     return(false);
    }
    xhr_object.open("GET",fichier,false);
    xhr_object.send(null);
    if (xhr_object.readyState == 4)
    {	return(xhr_object.responseText);
    }
    else
    {	return(false);
    }
}
// EOF AJAX

// MENU V2
function menuv2(id,action) {
	var menus = Array('sousmenu_concession','sousmenu_motosneuves','sousmenu_motosoccasions','sousmenu_88');
	var style = '';
	var style_autre = '';
	var delai = 1000;
	if (action == 'afficher') {
		style_autre = 'none';
		style = 'block';
		delai = 0;
	}
	else {
		//setTimeout('void(0)',1000);
		for(var j=0;j<100000;j++) {
			//do nothing
		}
		style_autre = 'none';
		style = 'none';
	}
	
	for(var i=0; i<menus.length; i++) {
		if (menus[i] == id) {
			document.getElementById(menus[i]).style.display = style;
			//setTimeout("apply_display('"+id+"','"+style+"')",delai);
		}
		else {
			document.getElementById(menus[i]).style.display = style_autre;
			//setTimeout("apply_display('"+id+"','"+style_autre+"')",delai);
		}
	}
}

function apply_display(id,display) {
	document.getElementById(id).style.display = display;
}

// EOF MENU V2