function viderObjetDom(objet)
{
	if (objet != null)
	{	
		while (objet.firstChild) 
			objet.removeChild(objet.firstChild);
	}
}


function commandeAjax(commande)
{
	$.ajax({type: "POST", url: "framework/requetes.php5", data: commande , success: function(data){ eval(data);  }});		
}


function supprimerEnfantsDOM(noeud)
{
	if (noeud != null)
	{	
		while (noeud.firstChild) 
		{
		  noeud.removeChild(noeud.firstChild);
		}
	}
}

function verifMail(lemail) 
{
    var arobase = lemail.indexOf("@"); var point = lemail.lastIndexOf(".")
    if((arobase < 3)||(point + 2 > lemail.length)||(point < arobase+3)) 
        return false
    else    
        return true
}

function nouveaute(zn, famille, numero, libelle, image, xwidth, xheight)
{
	var divNouv = document.createElement("div");
	divNouv.style.fontSize = "12px";
	texte = document.createTextNode(libelle);
	divNouv.appendChild(texte);
	var br = document.createElement("br");
	divNouv.appendChild(br);
	var img = document.createElement("img");
	img.style.cursor = 'pointer';
	img.src="catalogue/" + image;
	img.onclick = function() { window.location = "detailCatalogue.html?famille=" + famille + "&choix=" + numero};
	img.onmouseover = function() { montrerNouveaute(this);};
	img.onmouseout = function() { cacherNouveaute();};
	img.height=xheight;
	img.width = xwidth;
	divNouv.appendChild(img);
	
	zn.appendChild(divNouv);				
	
}

function verifierPanier()	
{
	commandeAjax('fonction=verifierPanier');
}

function afficherPanier()
{
	commandeAjax("fonction=afficherPanier");
}

function afficherNouveautes()
{
	commandeAjax("fonction=afficherNouveautes");
}

function ouvrirFenetreconnection()
{
	$('#fenetreConnection').show();
}

function fermerFenetreconnection()
{
	$('#fenetreConnection').hide();
}

function deconnection()
{
	commandeAjax("fonction=deconnection");
}

function doValiderLoginPassword(formulaire)
{
	commandeAjax("fonction=validerLoginPassword&login=" + formulaire.login.value + "&password=" + formulaire.password.value);
}

function position(e) 
{
	x = (navigator.appName.substring(0,3) == "Net") ? e.pageX : event.x+document.body.scrollLeft;
	y = (navigator.appName.substring(0,3) == "Net") ? e.pageY : event.y+document.body.scrollTop;
	//document.getElementById('debug').innerHTML = "Souris x:"+x+" | y:"+y;
	//debug();
}

function montrerNouveaute(objet)
{
	if (x)
	{	
		document.getElementById("divImageNouveaute").style.display = "block";
		document.getElementById("divImageNouveaute").style.visibility = "visible";
		document.getElementById("divImageNouveaute").style.left = (x - 180) + "px";
		document.getElementById("divImageNouveaute").style.top = y + "px";
		document.getElementById("imgImageNouveaute").src = objet.src; 
		document.getElementById("imgImageNouveaute").style.width = "150px"; 
	}
}

function cacherNouveaute()
{
	document.getElementById("divImageNouveaute").style.display = "none";
	document.getElementById("divImageNouveaute").style.visibility = "hidden";
}

function afficherMiniatureNouveaute(image)
{
}

function validerLoginPassword()
{
	doValiderLoginPassword(document.formulaireLoginPassword);
}

function validerLoginPassword2()
{
	doValiderLoginPassword(document.formulaireLoginPassword2);
}

function validerNouvelIdentifiant()
{
	var formulaire = document.formulairenouvelIdentifiant;
	var commande = 'fonction=validerNouvelIdentifiant&nom=' + formulaire.nom.value;
	commande = commande + '&prenom=' + formulaire.prenom.value;
	commande = commande + '&adresse=' + formulaire.adresse.value;
	commande = commande + '&codepostal=' + formulaire.codepostal.value;
	commande = commande + '&ville=' + formulaire.ville.value;
	commande = commande + '&email=' + formulaire.email.value;
	//alert(commande);
	commandeAjax(commande);	
	
	
}

function verifierNouvelIdentifiant()
{
	var erreur = '';
	var retour = true;
	var formulaire = document.formulairenouvelIdentifiant;
	if (formulaire.nom == '') erreur = erreur + 'Veuillez saisir un nom\n';
	if (formulaire.prenom == '') erreur = erreur + 'Veuillez saisir un pr\351nom\n';
	if (formulaire.email == '') erreur = erreur + 'Veuillez saisir un email\n';
	
	if (erreur != '')
	{	
		retour = false;
		alert(erreur);
	}	
	return retour;
}


//------------------------------------------------------------------------
//------------------------ FONCTIONS JQUERY ------------------------------
//------------------------------------------------------------------------

jQuery.fn.center = function () { 
    this.css("position","absolute"); 
    this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px"); 
    this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px"); 
    return this; 
}

