// JavaScript Document
var assoclayer;var packprodlayer;
var islayerexist=0;
var islayerexist2=0;
//var firstpackprodlayer=0;
//var firstassoclayer=0;
var poptmt2;
/*
var assoclayer=document.createElement("div");
assoclayer.setAttribute("id", "assoclayer");
assoclayer.style.zIndex="2";
assoclayer.style.display="none";
assoclayer.style.position="absolute";
assoclayer.style.width=250;

var packprodlayer=document.createElement("div");
packprodlayer.setAttribute("id", "packprodlayer");
packprodlayer.style.zIndex="3";
packprodlayer.style.display="none";
packprodlayer.style.position="absolute";
packprodlayer.style.width=250;
*/
function mpop_affiche2(idprodlay){
/*
	if (firstassoclayer==0) {
		var tmpBody=document.getElementsByTagName("body")[0];
		tmpBody.appendChild(assoclayer);
		firstassoclayer=1;
	}
	tmpassoclayer=findObj('prodassoc_'+idprodlay);
	assoclayer.innerHTML=tmpassoclayer.innerHTML;
*/
	assoclayer=findObj('prodassoc_'+idprodlay);
	assoclayer.style.left=(gpagepos_x+2)+"px";
	assoclayer.style.top=(gpagepos_y+2)+"px";
	assoclayer.style.visibility='visible';
	assoclayer.style.display='block';
	assoclayer.style.zIndex=20;
	islayerexist2=1;
}
function mpop_close2(typeclose){
	if(islayerexist2>0){
		assoclayer.style.visibility='hidden';
		assoclayer.style.display='none';
		islayerexist2=0;
	}
}

/* Fonctions pour les packs V1 */
var packprodlayer;
var islayerexist=0;
var islayerexist2=0;
var poptmt;
function mpop_affiche(idprodlay,idpacklay){
/*
	if (firstpackprodlayer==0) {
		var tmpBody=document.getElementsByTagName("body")[0];
		tmpBody.appendChild(packprodlayer);
		firstpackprodlayer=1;
	}
	tmppackprodlayer=findObj('pack_'+idpacklay+'prod_'+idprodlay);
	packprodlayer.innerHTML=tmppackprodlayer.innerHTML;
*/
 	packprodlayer=findObj('pack_'+idpacklay+'prod_'+idprodlay);
 	packprodlayer.style.left=(gpagepos_x+2)+"px";
	packprodlayer.style.top=(gpagepos_y+2)+"px";
	packprodlayer.style.visibility='visible';
	packprodlayer.style.display='block';
	packprodlayer.style.zIndex=20;
	islayerexist=1;
}
function mpop_close(typeclose){
	if(islayerexist>0){
	packprodlayer.style.visibility='hidden';
	packprodlayer.style.display='none';
	islayerexist=0;
	}
}

// Example: obj = findObj("image1");
function findObj(theObj, theDoc)
{
	var p, i, foundObj;

	if(!theDoc) theDoc = document;
	if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
	{
		theDoc = parent.frames[theObj.substring(p+1)].document;
		theObj = theObj.substring(0,p);
	}
	if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
	for (i=0; !foundObj && i < theDoc.forms.length; i++)
	foundObj = theDoc.forms[i][theObj];
	for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++)
	foundObj = findObj(theObj,theDoc.layers[i].document);
	if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);

	return foundObj;
}
/*
var IE = document.all?true:false
if (!IE) {document.captureEvents(Event.MOUSEMOVE);var extpx='px';}else{var extpx='';}
document.onmousemove = getMouseXY;
*/
var assocquantity = new Array();
function buyItemAssoc2(newItem, newPrice, newPort,newID,newQuantity) {
	rbuyItem(newItem, newPrice, newPort,newID,newQuantity);
	assocquantity[newID]=1;
	ShowItemAssoc2();

/*
	if (navigator.appName == "Microsoft Internet Explorer")
	{
		var noticescroll=document.body.scrollTop;
	}
	else{
		var noticescroll=window.pageYOffset;
	}
	if(parseInt(newQuantity)>1){
		noticediv=document.getElementById('basketnotice2');
	}
	else{
		noticediv=document.getElementById('basketnotice');
	}
	document.getElementById('basketnotice2_nom').innerHTML=newItem;
	document.getElementById('basketnotice_nom').innerHTML=newItem;
	var noticetop=(parseInt(noticeheight)/2)-(150/2)+parseInt(noticescroll);
	var noticeleft=(noticewidth/2)-(299/2);
	noticetop=parseInt(noticetop)+'px';
	noticeleft=parseInt(noticeleft)+'px';
	//alert(noticetop+'=top left='+noticeleft);
	noticediv.style.display='block';
	noticediv.style.visibility='visible';
	noticediv.style.left=noticeleft;
	noticediv.style.top=noticetop;
*/
	//alert('ah='+window.screen.availHeight+'ns='+noticescroll+'noticestop='+noticetop+'innerhgt='+noticeheight);

}
// *****************************************************************************
// Fonction buyItemAssoc3 - MK - 04/08/2008
// ***************************************************************************** 
// Pour les fichiers stickersXXXXX.htm
function buyItemAssoc3(newItem, newPrice, newPort,newID,newQuantity) 
{
	// Rajoute le produit sélectionné au panier
	rbuyItem(newItem, newPrice, newPort,newID,newQuantity);
}

function ShowItemAssoc2(){
	var inbprod=0;
	//	[accessoire Film Protecteur pour Ecran LCD - pour PDA/Téléphone/APN/GPS,2.95#0.03!21004|1]
	index = document.cookie.indexOf('TheBasket');
	countbegin = (document.cookie.indexOf('=', index) + 1);
	countend = document.cookie.indexOf(';', index);
	if (countend == -1) {
		countend = document.cookie.length+1;
	}
	moreItem=true ;
	fulllist = document.cookie.substring(countbegin, countend);
	//findObj('listeprodassoc').innerHTML='';
	//findObj('leftassoc').innerHTML='';
	newItemList = null;
	itemlist = 0;
	var assocprice=parseFloat('0');
	for (var i = 0; i <= fulllist.length; i++) {
		if (fulllist.substring(i,i+1) == '[') {
			itemstart = i+1;
		}
		else if (fulllist.substring(i,i+1) == '|') {
			qpos= i ;
			qstart = i+1;
		}
		else if (fulllist.substring(i,i+1) == '!') {
			var ipos= i ;
			var istart = i+1;
		}
		else if (fulllist.substring(i,i+1) == ',') {
			var npos= i ;
			var nstart = i+1;
		}
		else if (fulllist.substring(i,i+1) == '#') {
			var ppos= i ;
			var pstart = i+1;
		}
		else if (fulllist.substring(i,i+1) == ']') {
			itemend = i;
			theitem = fulllist.substring(itemstart, itemend);
			var theitemid = fulllist.substring(istart, qpos);
			var theitemname = fulllist.substring(itemstart, npos);
			var theitemprice = fulllist.substring(nstart, ppos);
			thequantity = fulllist.substring(qstart, itemend);
			itemlist=itemlist+1;
			if(assocquantity[theitemid]>0){
				//findObj('listeprodassoc').innerHTML+='&nbsp;- '+theitemname+'<br>';
				//findObj('leftassoc').innerHTML+='&nbsp;- '+theitemname+'<br>';
				inbprod=inbprod+1;
				//<a href=\"javascript:RemoveItemAssoc(\''+theitemid+'\')\">suppr</a>
				assocprice=assocprice+parseFloat(theitemprice);
			}
		}
	}
	assocprice=assocprice+parseFloat(prixproduitpere);
	assocprice=assocprice*100;
	assocprice=Math.round(assocprice);
	assocprice=assocprice/100;
	//if(inbprod<1){
	//findObj('listeprodassoc').innerHTML+='Aucun produit sélectionné<br>';
	//}
	findObj('prodassocprice').innerHTML=number_format(assocprice,2,'&nbsp;')+'&nbsp;&euro;';
	//findObj('prodassocprice').innerHTML=number_format(assocprice,2,' ')+' &euro;';
//	findObj('prodassocprice2').innerHTML=assocprice+' &euro;';
//	showBasket(0);
}
function RemoveItemAssoc2(rid){
	newItemList = null;
	itemlist = 0;
	index = document.cookie.indexOf('TheBasket');
	countbegin = (document.cookie.indexOf('=', index) + 1);
	countend = document.cookie.indexOf(';', index);
	if (countend == -1) {
		countend = document.cookie.length+1;
	}
	moreItem=true ;
	fulllist = document.cookie.substring(countbegin, countend);
	for (var i = 0; i <= fulllist.length; i++) {
		if (fulllist.substring(i,i+1) == '[') {
			itemstart = i+1;
		}
		else if (fulllist.substring(i,i+1) == '|') {
			qpos= i ;
			qstart = i+1;
		}
		else if (fulllist.substring(i,i+1) == '!') {
			var ipos= i ;
			var istart = i+1;
		}else if (fulllist.substring(i,i+1) == ']') {
			itemend = i;
			theitem = fulllist.substring(itemstart, itemend);
			var theitemid = fulllist.substring(istart, qpos);
			thequantity = fulllist.substring(qstart, itemend);
			itemlist=itemlist+1;

			if (parseInt(theitemid) != parseInt(rid)) {
				newItemList = newItemList+'['+fulllist.substring(itemstart, itemend)+']';
				//alert('+'+theitemid+'+'+rid+'+');
			}


		}
	}
	index = document.cookie.indexOf("TheBasket");
	document.cookie="TheBasket="+newItemList+';path=/';
	indextoto = toto.indexOf('TheBasket');
	countbegintoto = (toto.indexOf('=', indextoto) + 1);
	countendtoto = toto.indexOf(';', indextoto);
	if (countendtoto == -1) {
		countendtoto = toto.length;
	}

	document.cookie='TheBasket='+newItemList+';path=/'+';domain=grosbill.com';;

	assocquantity[rid]=0;
	ShowItemAssoc2();
	calc_minipanier();
//	showBasket(0);
}
function gobasketp(){
	stampbasket = new Date();
	location = "/monpanierv2.php3?b="+stampbasket.getMinutes()+stampbasket.getSeconds() ;
}
