//////////////////////////////////////////////////mailing recherche//////////////////////////////////////////////////

function init()
{
	if (document.getElementById("lien-image-wizzard"))
	{
		document.getElementById("lien-image-wizzard").style.display = 'block';
	}
	/*place_recherche(user_id);*/
}


function MM_reloadPage(init) 
{  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);		



////////////////////////////////////////////////// barre de navigation//////////////////////////////////////////////////
sfHover = function() 
{
	var sfEls = document.getElementById("menuDeroulant").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) 
	{
		sfEls[i].onmouseover=function() 
		{
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() 
		{
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}

if (window.attachEvent) window.attachEvent("onload", sfHover);


/*function montreMenu()
{
	isActive = true;
	document.getElementById("recherche").style.visibility="hidden";
}*/

function montreMenu()
{
	isActive = true;
	setTimeout('montrer()',100);
}

function montrer()
{
	document.getElementById("level2").style.visibility="hidden";
}
    
function cacheMenu()
{
	isActive = false;
	setTimeout('cacher()',100);
}
    
function cacher()
{
		if(!isActive)
		{
		document.getElementById("level2").style.visibility = "visible";
		}
}

	
//////////////////////////////////////////////////fiche produit//////////////////////////////////////////////////

	function centrage_image(divID)
	{
			//sous firefox on récupère les propriétés après le chargement de l'image				
			//centrage image	
			var l = document.images[divID].width;
			var h = document.images[divID].height;		
			/*alert(l);
			alert(h);*/		
			l = (550 - l) / 2;
			h = (400 - h) / 2;
			var marge = new Array();
			marge[0] = l ;
			marge[1] = h;	
			return marge;
	}
	
		function image_thumb(champ0, champ1, champ2, champ3)
		{				
				/*var reg = new RegExp(" ", "gi");
				var str = champ2.replace(reg, "-") + "-" + champ3.replace(reg, "-");				
				src = str.toLowerCase() + ".jpg' ";*/
				src = champ0 + "tbre.jpg' ";
																																													
				document.getElementById("image" + champ0).innerHTML = "<img src='/store/html/images/produits/vignettes/" + src + "alt='" + champ2 + " " + champ3 + "' title='" + champ2 + " " + champ3 + "'>";
		}

	
		function image_situation(champ0, champ1, champ2, champ3)
		{				
				/*var reg = new RegExp(" ", "gi");
				var str = champ2.replace(reg, "-") + "-" + champ3.replace(reg, "-");
				src = str.toLowerCase() + ".jpg' "; */
				if (document.getElementById("wizzard" + champ0))
				{
				document.getElementById("wizzard" + champ0).style.display = 'none';
				}
				document.getElementById("image" + champ0).style.display = 'block';
				document.getElementById("image" + champ0).style.margin = '0 0 0 0';	
				document.getElementById("situation").style.display = 'block';				
				document.getElementById("face").style.display = 'none';								
				document.getElementById("large").style.display = 'none';
				document.getElementById("dos").style.display = 'none';
				//alert("image_situation");				
		}	

		
		function image_face(champ0, champ1, champ2, champ3)
		{							
				/*var reg = new RegExp(" ", "gi");
				var str = champ2.replace(reg, "-") + "-" + champ3.replace(reg, "-");
				src = str.toLowerCase() + ".jpg' ";*/							
				document.getElementById("image" + champ0).style.display = 'block';
				document.getElementById("image" + champ0).style.margin = '0 0 0 0';
				/*document.getElementById("image" + champ0).style.margin = centrage_image("face")[1] + 'px 0 0 ' + centrage_image("face")[0] + 'px';		*/
				document.getElementById("situation").style.display = 'none';				
				document.getElementById("face").style.display = 'block';								
				document.getElementById("large").style.display = 'none';
				document.getElementById("dos").style.display = 'none';
				//alert("image_face");
		}

		function image_large(champ0, champ1, champ2, champ3)
		{				
				/*var reg = new RegExp(" ", "gi");
				var str = champ2.replace(reg, "-") + "-" + champ3.replace(reg, "-");
				src = str.toLowerCase() + ".jpg' ";*/
				document.getElementById("image" + champ0).style.display = 'block';
				document.getElementById("image" + champ0).style.margin = '0 0 0 0';
				/*document.getElementById("image" + champ0).style.margin = centrage_image("large")[1] + 'px 0 0 ' + centrage_image("large")[0] + 'px';	*/	
				document.getElementById("situation").style.display = 'none';				
				document.getElementById("face").style.display = 'block';								
				document.getElementById("large").style.display = 'none';
				document.getElementById("dos").style.display = 'none';					
				//alert("image_large");
		}

		function image_recto(champ0, champ1, champ2, champ3)
		{				
				/*var reg = new RegExp(" ", "gi");
				var str = champ2.replace(reg, "-") + "-" + champ3.replace(reg, "-");
				src = str.toLowerCase() + ".jpg' ";*/
				document.getElementById("image" + champ0).style.display = 'block';
				document.getElementById("image" + champ0).style.margin = '0 0 0 0';
				/*document.getElementById("image" + champ0).style.margin = centrage_image("dos")[1] + 'px 0 0 ' + centrage_image("dos")[0] + 'px';		*/
				document.getElementById("situation").style.display = 'none';				
				document.getElementById("face").style.display = 'block';								
				document.getElementById("large").style.display = 'none';
				document.getElementById("dos").style.display = 'none';				
				
				//alert("image_recto");
		}
		
		function cache_prod_ass(nbre_prod_ass)
		{		
			if(nbre_prod_ass == 0)
			{
			//document.getElementById("caract-produit-associe-titre").style.width = '700px';
			document.getElementById("caracteristiques").style.width = '1024px'; 
			document.getElementById("produits-associes-titre").style.visibility = "hidden";
			document.getElementById("produits-associes").style.visibility = "hidden";
			}
		}
				
//////////////////////////////////////////////////popup///////////////////////////////////////////////////////////////////

pop=
{
	maxH:1024, 
	maxW:1280, obj:null, win:null, img:null, intervalCheck:null,
	
	open:function(link) 
	{
		pop.obj = link;
		pop.win = window.open("/store/html/js/popup.html", "_blank", "width=" + (pop.maxW) + ", height=" + (pop.maxH) + ", scrollbars=no, status=no, resizable=yes" );
	},
	
	makeImg:function()
	{
		if (!pop.win) return;
		var img = pop.win.document.getElementById("image");
		pop.img = img;
		img.src = pop.obj.href;
		pop.intervalCheck=setInterval("pop.checkimgSize()",200);
	},
	
	checkimgSize:function() 
	{
		if (pop.img.height!="" ) 
		{
			clearInterval(pop.intervalCheck);
			setTimeout("pop.resizeImg()",200);
		}
	},
	
	resizeImg:function() 
	{
		var img=pop.img;
		imgH=parseInt(img.height);
		imgW=parseInt(img.width);
		if (imgH>imgW && imgH>pop.maxH ) 
		{
			img.height=pop.maxH;
			img.width=parseInt(imgW/imgH*pop.maxH);
		} 
		else 
		{
			if (imgW>imgH && imgW>pop.maxW ) 
			{
				img.width=pop.maxW;
				img.height=parseInt(imgH/imgW*pop.maxW);
			}
		}
		pop.win.resizeTo(parseInt((img.width+30)),parseInt((img.height+80)));
	}
	
}


//////////////////////////////////////////////////liste//////////////////////////////////////////////////
	
function getProperties(/*Object*/ obj)
{
    var msg = "";
    for (prop in obj){
        msg += "property : " + prop + "\t\t value : " + obj[prop] + "\n";
    }
    alert(msg);
}

function dim(id, hauteur)
{
		var d = document.getElementById(id);
		/*if (navigator.appName == "Microsoft Internet Explorer")
		{*/
			if (d) 
			{ 
				d.style.height = hauteur + 'px'; //hauteur + 'px;';
				/*d.style.overflow= 'auto';
				d.style.float = 'left';
				d.style.width = '100%';
				d.style.margin = '0 0 0 15px';
				d.style.padding = '0px';
				d.style.border = '1px solid #ADAC9D';
				d.style.font-family = 'Arial, Verdana, sans-serif'; 
				d.style.font-size = '12px';*/
			}			
		//}
}


/**************panier********************************/
	function plus(str)
	{
		var qte = parseInt(document.getElementById(str).value);
		qte += 1;
		document.getElementById(str).value = qte;
		document.ChangePanier.submit();
	}
	
		function moins(str)
	{
		var qte = parseInt(document.getElementById(str).value);
		qte -= 1;
		
		if (qte < 0)
		{
			document.getElementById(str).value = 0;
		}
		else
		{
			document.getElementById(str).value = qte;
		}	
		document.ChangePanier.submit();
	}
		
		function zero(str)
	{
		document.getElementById(str).value = 0;
		document.ChangePanier.submit();
	}
	
	function recupID(str)
	{
		var position = str.indexOf('_', str);
		return str.substring(0, position);
	}
	
	function recupFamille(str)
	{
		var position = str.indexOf('_', str) + 1;
		return str.substring(position, str.length);
	}
	
	function faireLien(str, modele, user_id)
	{
		var lien = "<b><a target=_blank href=/store/search.cgi?" + user_id + "&database=base.db&template=produit.htm&0=" + recupID(str) + "><b>";
		lien += modele + "</b></a>";
		document.getElementById("modele").innerHTML = lien; 
		alert(lien);
	}




/************** GESTION DES COMMANDES ********************************/

function add_cart(frm, user_id)
{					
		var chaine = frm.elements['produit'].options[frm.elements['produit'].selectedIndex].value;
		
		var tableau=chaine.split("::");
		
		var data = null;
		data="ID=" + tableau[0];
		data+="&Price=" + tableau[1];
		data+="&marque=" + tableau[2];
		data+="&modele=" + tableau[3];
		data+="&ecotaxe=" + tableau[4];
		data+="&famille=" + tableau[5];
		data+="&Quantity=1";
		
		
		var xhr_object = null;
		
		if(window.XMLHttpRequest) 
		{
			// Firefox
			xhr_object = new XMLHttpRequest();
		}
		else if(window.ActiveXObject) // Internet Explorer
		{
			xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
		}
		else 
		{ 
			// XMLHttpRequest non supporté par le navigateur
			alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
			return;
		}
			
		xhr_object.open("POST", "/store/add_cart_interne.cgi?" + user_id, true);			
	 	xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			
		xhr_object.send(data);

		var vazy="/store/viewcart_interne.cgi?" + user_id;
		var Nom = navigator.appName;			
		var ns = (Nom == 'Netscape') ? 1:0
		var ie = (Nom == 'Microsoft Internet Explorer') ? 1:0			
		if (ns || ie)
		{
				location.replace(vazy);
		}
		else
		{
				location.href = vazy;	
		}			
		
}



function compareEmail()
{
  return (document.subscribeform.elements["email"].value == document.subscribeform.elements["emailconfirm"].value);
}

function checkform()
{
			if (document.subscribeform.htmlemail.checked == false)
			{
				return document.subscribeform.htmlemail.value = 1 ;
			}
			else
			{
				return document.subscribeform.htmlemail.value = 0 ;	
			}
			
			
		  if(! compareEmail())
		  {
		    alert("Email Addresses you entered do not match");
		    return false;
		  }
			
}



