function zoom (imageName, imageWidth, imageHeight, alt, posLeft, posTop) {

	newWindow = window.open("","newWindow","width="+imageWidth+",height="+imageHeight+",scrollbars=no,left="+posLeft+",top="+posTop);
	newWindow.document.open();
	newWindow.document.write('<html><title>'+alt+'</title><body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" onBlur="self.close()">'); 
	newWindow.document.write('<img src=\"'+imageName+'\" width='+imageWidth+' height='+imageHeight+' alt=\"'+alt+'\">');
	newWindow.document.write('</body></html>');
	newWindow.document.close();
	newWindow.focus();

}

var checkflag = "false";
var avertissementpresencepananon = false;

function check(field) {
	if (checkflag == "false") {
		for (i = 0; i < field.length; i++) {
			field[i].checked = true;
			}
		checkflag = "true";
		return "Tout décocher";
		}
	else {
		for (i = 0; i < field.length; i++) {
			field[i].checked = false;
			}

		checkflag = "false";
		return "Tout cocher";
		}
	}

function confirm_vider()
{
    vider = window.confirm('Vider ce panier ?\n\nVous ne pourrez pas annuler cette action.');
    //alert(vider);
    return vider;
}

function getElementsByClass(searchClass,node,tag)
{
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

window.onload = function ()
{
	// disparition des boutons des formulaires dans fiche-client.php et colonne droite
	var submits = new Array();
	submits = getElementsByClass('submitshide');
	if(submits.length > 0)
	{
		for(i = 0; i < submits.length; i++)
		{
	        submits[i].style.display = "none";
		}
	}
	
	// validation formulaire au changement des select
	selects = getElementsByClass('selectshide');
	if(selects.length > 0)
	{
		for(i = 0; i < selects.length; i++)
		{
			//alert( formid );
			selects[i].onchange = function ()
			{
			    selectid = this.id;
	       		formid = selectid.substr(3, selectid.length);
			    //alert(selectid +' ->'+ formid );
	        	document.getElementById(formid).submit();
			}
		}
	}
	
	// avertissement quand actions sur les paniers (fiche-client.php) et presence de panier anonyme
	if(avertissementpresencepananon)
	{
	    //alert('onload');
		formboutonpaniers = getElementsByClass('actionpanier');
		if(formboutonpaniers.length > 0)
		{
		    //alert('form trouvés');
			for(i = 0; i < formboutonpaniers.length; i++)
			{
				//alert( i+' '+formboutonpaniers[i] );
				formboutonpaniers[i].onsubmit = function ()
				{
				    //alert('question');
					reponse = confirm("Vous allez perdre le contenu du panier anonyme.\n\nEffectuer cette action ?")
				    if(reponse)
						return true;
					else
						return false
				}
				
			}
		}
	}
	else
	{
        //alert(avertissementpresencepananon);
	}
	
	
	// avertissement sur le bouton nouveau panier
	if(avertissementpresencepananon)
	{
	    if(document.getElementById('formbtnouvpanier'))
		{
		    //alert('catched');
			btnouvpanier = document.getElementById('formbtnouvpanier');
			btnouvpanier.onsubmit = function ()
				{
					reponse = confirm("Vous allez perdre le contenu du panier anonyme.\n\nEffectuer cette action ?")
				    if(reponse)
						return true;
					else
						return false
				}
		}
		else
		{
	        //alert('not catched'+document.getElementsById('formbtnouvpanier'));
		}
	}
	else
	{
        //alert(document.getElementsById('formbtnouvpanier'));
	}

	// autoselection du bouton radio quand changement de panier dans les select au moment du choix dans panier temporaire
	// ajouter au panier
	if( document.getElementById('choix-pan-temp-ajout') )
	{
        document.getElementById('choix-pan-temp-ajout').onchange = function()
            {
                document.getElementById('choix-pan-temp-aj').checked = 'checked';
			}
	}
	//remplacer le panier
	if( document.getElementById('choix-pan-temp-remp') )
	{
        document.getElementById('choix-pan-temp-remp').onchange = function()
            {
                document.getElementById('choix-pan-temp-rp').checked = 'checked';
			}
	}

	// avertissement a la suppression d'adresse
	formboutonsupadd = getElementsByClass('supadd');
	if(formboutonsupadd.length > 0)
	{
	    //alert('form trouvés');
		for(i = 0; i < formboutonsupadd.length; i++)
		{
			//alert( i+' '+formboutonpaniers[i] );
			formboutonsupadd[i].onclick = function ()
			{
				reponse = confirm("Voulez-vous vraiment supprimer cette adresse ?")
			    if(reponse)
					return true;
				else
					return false
			}

		}
	}
	        
}
