function getXhr()
{
	var xhr = null; 
	if (window.XMLHttpRequest)
		xhr = new XMLHttpRequest(); 
	else if (window.ActiveXObject)
	{
		try
		{
			xhr = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xhr = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	else 
	{
		xhr = false; 
	}
	return xhr;
}

function liste_contenu_par_section(section)
{
	var xhr = getXhr();
	xhr.onreadystatechange = function()
	{
		if (xhr.readyState == 4)
		{
			content = xhr.responseText;
			document.getElementById('resultat_sections').innerHTML = content;
		}
	}
	xhr.open("POST","../scripts/ajax.contenu.section.php");
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr.send("section="+section);
}

function verif_nombre(champ)
{
	var chiffres = new RegExp("[0-9]");
	var verif;
	var points = 0;

	for (x = 0 ; x < champ.value.length ; x++)
	{
		verif = chiffres.test(champ.value.charAt(x));
		if (champ.value.charAt(x) == ".")
		{
			points++;
		}
		if (points > 1)
		{
			verif = false;
			points = 1;
		}
		if (verif == false)
		{
			champ.value = champ.value.substr(0,x) + champ.value.substr(x+1,champ.value.length-x+1);
			x--;
		}
	}
}

function verif_float(champ)
{
	var chiffres = new RegExp("[0-9.,]");
	var verif;
	var points = 0;

	for (x = 0 ; x < champ.value.length ; x++)
	{
		verif = chiffres.test(champ.value.charAt(x));
		if (champ.value.charAt(x) == "." || champ.value.charAt(x) == ",")
		{
			points++;
		}
		if (points > 1)
		{
			verif = false;
			points = 1;
		}
		if (verif == false)
		{
			champ.value = champ.value.substr(0,x) + champ.value.substr(x+1,champ.value.length-x+1);
			x--;
		}
	}
}

function montrerCacher(id)
{
	el = document.getElementById(id);
	el.style.display = (el.style.display != 'block')? 'block' : 'none';
}

function ajouterLigne()
{
	var p = document.createElement('p');
	var input_poids_minimum = document.createElement('input');
	var input_poids_maximum = document.createElement('input');
	var input_prix_ht_livraison = document.createElement('input');
	input_poids_minimum.setAttribute('type','text');
	input_poids_minimum.setAttribute('id','poids_minimum');
	input_poids_minimum.setAttribute('name','poids_minimum[]');
	input_poids_minimum.setAttribute('maxlength',255);
	input_poids_minimum.setAttribute('style','width:200px;');
	input_poids_minimum.setAttribute('onKeyUp','verif_nombre(this);');
	input_poids_minimum.setAttribute('value','');
	input_poids_minimum.appendChild(document.createTextNode(''));
	
	input_poids_maximum.setAttribute('type','text');
	input_poids_maximum.setAttribute('id','poids_maximum');
	input_poids_maximum.setAttribute('name','poids_maximum[]');
	input_poids_maximum.setAttribute('maxlength',255);
	input_poids_maximum.setAttribute('style','width:200px;');
	input_poids_maximum.setAttribute('onKeyUp','verif_nombre(this);');
	input_poids_maximum.setAttribute('value','');
	input_poids_maximum.appendChild(document.createTextNode(''));
	
	input_prix_ht_livraison.setAttribute('type','text');
	input_prix_ht_livraison.setAttribute('id','prix_ht_livraison');
	input_prix_ht_livraison.setAttribute('name','prix_ht_livraison[]');
	input_prix_ht_livraison.setAttribute('maxlength',255);
	input_prix_ht_livraison.setAttribute('style','width:200px;');
	input_prix_ht_livraison.setAttribute('onKeyUp','verif_float(this);');
	input_prix_ht_livraison.setAttribute('value','');
	input_prix_ht_livraison.appendChild(document.createTextNode(''));

	p.appendChild (document.createTextNode('De '));
	p.appendChild (input_poids_minimum);
	p.appendChild (document.createTextNode(' grammes à '));
	p.appendChild (input_poids_maximum);
	p.appendChild (document.createTextNode(' grammes '));
	p.appendChild (input_prix_ht_livraison);
	p.appendChild (document.createTextNode(' € H.T.'));

	document.getElementById('contacts_supplementaires').appendChild(p);
}

/* ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** */
function deplacerOption( liste_depart, liste_arrivee )
{
	for( i = 0; i < liste_depart.options.length; i++ )
	{
		if( liste_depart.options[i].selected && liste_depart.options[i] != "" )
		{
			o = new Option( liste_depart.options[i].text, liste_depart.options[i].value );
			liste_arrivee.options[liste_arrivee.options.length] = o;
			liste_depart.options[i] = null;
			i = i - 1 ;
		}
		else
		{
			// alert( "aucun element selectionne" );
		}
	}
}

function validerListeOptions( liste )
{
	var listelen = liste.length;
	for( i = 0; i < listelen; i++ )
	{
		liste.options[i].selected = true;
	}
}
/* ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** */
