// JavaScript Document


function zoomImage(fichier, width, height)
{
	window.open('zoom.php?fichier=fichiers/' + fichier, '', 'width=' + width +',height=' + height);
	return false;
}

/* gestion des cookies en js */

// depose un cookie
function EcrireCookie(nom, valeur)
{
	var argv=EcrireCookie.arguments;
	var argc=EcrireCookie.arguments.length;
	var expires=(argc > 2) ? argv[2] : null;
	var path=(argc > 3) ? argv[3] : null;
	var domain=(argc > 4) ? argv[4] : null;
	var secure=(argc > 5) ? argv[5] : false;
	document.cookie=nom+"="+escape(valeur)+
	((expires==null) ? "" : ("; expires="+expires.toGMTString()))+
	((path==null) ? "" : ("; path="+path))+
	((domain==null) ? "" : ("; domain="+domain))+
	((secure==true) ? "; secure" : "");
}

// sous-fonctions - ne pas utiliser en appel direct
function getCookieVal(offset)
{
	var endstr=document.cookie.indexOf (";", offset);
	if (endstr==-1) endstr=document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

// renvoie la valeur d'un cookie
function LireCookie(nom)
{
	var arg=nom+"=";
	var alen=arg.length;
	var clen=document.cookie.length;
	var i=0;
	while (i<clen)
	{
	var j=i+alen;
	if (document.cookie.substring(i, j)==arg) return getCookieVal(j);
	i=document.cookie.indexOf(" ",i)+1;
	if (i==0) break;
	
	}
	return null;
}

function masqueMenu (id)
{
	setTimeout("masque('"+ id + "')",10000);
		
}

function masque(id)
{
	var d = document.getElementById(id);
	d.style.display='none';	
}




function searchKeywords() 
{
	if (document.getElementById('keywords').value != '')	
		document.forms['form_search'].submit();
}

function openRecherche(bAff)
{
	var d = document.getElementById('bloc_recherche');

	
	if (bAff == '')
	{
	
		if (d.style.display == 'block')
			d.style.display = 'none';
		else
			d.style.display = 'block';
	}
	else
	{
		if (bAff == 1)
			d.style.display = 'block';
		else
			d.style.display = 'none';	
	}
	
}

/* gestion panier + commande */
function ajoutPanier(id)
{
	document.getElementById('panier_produit_id').value = id;
	document.getElementById('url_retour').value = document.location.href;
	document.forms['form_panier'].submit();
	return false;

}

function majPanier()
{
	document.forms['form_maj'].submit();
}

function validerPanier()
{
	document.forms['form_maj'].action = "panier_compte.php";
	document.forms['form_maj'].submit();
	
}

function affichePanier(url_panier)
{
	document.getElementById('url_retour').value = document.location.href;
	document.forms['form_panier'].submit();
}

function validerCommande()
{
	document.forms['form_checkout'].submit();
}

function afficheBloc(nomBloc)
{
	var d = document.getElementById(nomBloc);
	
	if (d.style.display == 'block')
		d.style.display='none';	
	else
		d.style.display='block';			
}

function changeStyle(nomBloc,nomStyle)
{
	var d = document.getElementById(nomBloc);
	
	if (d.className == nomStyle)
		d.className = '';
	else
		d.className=nomStyle;
}

function estEmail(email)
{
    var indexAr = email.value.indexOf("@");
    if (indexAr != -1)
        return (true);
    return (false);
}


function verifMail(email, messageAlert)
{
    if (!estEmail(email))
        {
            alert(messageAlert);
            return (false);
        }
    return (true);
}

function ajouterFavoris(phrase, lien)
{
   if (window.sidebar)
   {
   window.sidebar.addPanel(phrase, lien,"");
   }
   else if( document.all )
   {
   window.external.AddFavorite(lien, phrase);
   }
   else
        {
   return true;
   } 	
}

function affImage (id)
{

	if (id != "")
	{
		// masque photo precedente
		if (prec_id != 0)
			document.getElementById('photo[' + prec_id + ']').style.display = "none";

		//affiche la photo actuelle
		if (id != 0)
			document.getElementById('photo[' + id + ']').style.display = "block";
	
		prec_id = id;
	}
}
