// code javascript



/* code pour chargement des pages */
function chargement()
{
	document.body.style.cursor = "wait";
	var tbl = document.createElement("TABLE");
    tbl.style.background = 'url(images/fondBlanc.png) repeat';
    tbl.style.position = 'fixed';
    tbl.style.top = '0px';
    tbl.style.left = '0px';
    tbl.style.width = '100%';
    tbl.style.height = '100%';
	tbl.style.zIndex = '100';
    var tbody = document.createElement("TBODY");
    var tr = document.createElement("TR");
    var td = document.createElement("TD");
    td.align = 'center';
    td.innerHTML = '<img src="images/MEx_loading.gif" />';
	tr.appendChild(td);
    tbody.appendChild(tr);
    tbl.appendChild(tbody);
    document.body.appendChild(tbl);
}

function charge(page)
{
	chargement();
	
	window.location = page;
}


/* fonction utilisé pour le rollover du menu... */

function rollOverMenu(obj, nomImage)
{
	if (obj.style.background.substring(obj.style.background.indexOf('/')+1, obj.style.background.indexOf(')')) != nomImage)
		obj.style.background = 'url(images/'+nomImage+') no-repeat';
	else
	{
		if (nomImage.indexOf('_') > -1)
			obj.style.background = 'url(images/'+nomImage.substr(0, nomImage.indexOf('_'))+'.png) no-repeat';
		else
			obj.style.background = 'url(images/'+nomImage.substr(0, nomImage.indexOf('.'))+'_h.png) no-repeat';
	}
}


function itemMenuHover(itemMenu, image, ssmenu)
{
	var p, n;
	if (itemMenu.previousSibling.style)
	{
		p = itemMenu.previousSibling;
		n = itemMenu.nextSibling;
	}
	else
	{
		p = itemMenu.previousSibling.previousSibling;
		n = itemMenu.nextSibling.nextSibling;
	}
	
	p.style.background = 'url(images/'+image+'_hgauche.png) no-repeat right top';
	itemMenu.style.background = 'url(images/'+image+'_h.png) repeat-x';
	n.style.background = 'url(images/'+image+'_hdroite.png) no-repeat left top';
	
	//itemMenu.style.color = "#000000";

	itemMenu.onmouseout = function()
	{
		var p, n;
		if (this.previousSibling.style)
		{
			p = this.previousSibling;
			n = this.nextSibling;
		}
		else
		{
			p = this.previousSibling.previousSibling;
			n = this.nextSibling.nextSibling;
		}
		
		p.style.background = '';
		this.style.background = '';
		n.style.background = '';
		
		//this.style.color = "#ffffff";
		
		initSsMenu(menuCourant, image);
	}
	affssmenu(ssmenu);
}



function initSsMenu(itemMenu, image)
{
	if (itemMenu == null)
	{
		if (document.getElementById('ssmenudebP'))
		{
			itemMenu = document.getElementById('ssmenudebP');
			image = 'product';
		}
		else if (document.getElementById('ssmenudebS'))
		{
			itemMenu = document.getElementById('ssmenudebS');
			image = 'service';
		}
		else if (document.getElementById('ssmenudebE'))
		{
			itemMenu = document.getElementById('ssmenudebE');
			image = 'entreprise';
		}
	}
	
	if (itemMenu)
	{
		var p, n;
		if (itemMenu.previousSibling.style)
		{
			p = itemMenu.previousSibling;
			n = itemMenu.nextSibling;
		}
		else
		{
			p = itemMenu.previousSibling.previousSibling;
			n = itemMenu.nextSibling.nextSibling;
		}
		p.style.background = 'url(images/'+image+'_sgauche.png) no-repeat right top';
		itemMenu.style.background = 'url(images/'+image+'_s.png) repeat-x';
		n.style.background = 'url(images/'+image+'_sdroite.png) no-repeat left top';
		
		//itemMenu.style.color = "#000000";
		menuCourant = itemMenu;
	}
}

var menuCourant;

function affssmenu(id)
{
	if (document.getElementById(id))
	{
		document.getElementById(id).style.display = 'block';
	}
}


function cacherssmenu(id)
{
	if (document.getElementById(id))
	{
		document.getElementById(id).style.display = 'none';
	}
}


function cacherTout(tbl)
{
   for(var n in ssmenu)
   {
	   if (document.getElementById(ssmenu[n]))
		   document.getElementById(ssmenu[n]).style.display = 'none';
   }
}


function passeProduct(id)
{
	document.getElementById(id).style.display = 'block';
}

function passeRub(id)
{
	passeProduct(id);
}

function exitRub(id)
{
	document.getElementById(id).style.display = 'none';
}

function exitTable(pref)
{
	for(var i = 1; i < 10; i++)
	{
		if (document.getElementById(pref+i) && document.getElementById(pref+i).style.display != 'none')
			document.getElementById(pref+i).style.display = 'none';
	}
}

/* fil d'ariane : */

function cacherFilDAriane()
{
	var i = 1;
	
	while(document.getElementById('fa'+i))
	{
		i++;
	}
	if (i > 2)
	{
		for(var j = (i - 3); j > 0;j--)
		{
			document.getElementById('fa'+j).style.display = 'none';
		}
		document.getElementById('fa0').innerHTML = '... <img src="images/pucePGQbleu.png" />';
	}
}


/* function utilisé pour validé le panier... */

function chpToForm(nameOfChp, form)
{
	for(var i = 0; i < form.length; i++)
	{
        if (form.elements[i].name == nameOfChp)
            return form.elements[i];
    }
    return null;
}


function validateForm(chp, vInf, vSup)
{
	if (valider(chp.form, chp.name, vInf, vSup))
		chp.form.submit();
}

function valider(form, nameOfChp, vInf, vSup)
{
	chp = chpToForm(nameOfChp, form);
	vInf = parseInt(vInf);
	vSup = parseInt(vSup);
	if (!isNaN(chp.value) && chp.value != '' && chp.value[0] != ' ')
	{
		if (parseInt(chp.value) < vInf)
			chp.value = vInf;
		else if (parseInt(chp.value) > vSup)
			chp.value = vSup;
		return true;
		chargement();
	}
	siNonRemplis(chp);
	return false;
}

function siNonRemplis(chp)
{
	chp.style.backgroundColor = '#FF6666';
	chp.focus();
	chp.onkeypress = function()
	{
		this.style.backgroundColor = '';
		this.onkeypress = null;
	}
}

/* iniatialisation : */
var imgTemp;
function initialisation()
{
	initSsMenu();
	cacherFilDAriane();
	
	imgTemp = new Array();
	imgTemp[imgTemp.lenght] = new Image().src = 'images/MEx_loading.gif';
	imgTemp[imgTemp.lenght] = new Image().src = 'images/fondBlanc.png';
}

window.onload = initialisation;
