//Trouve objet
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;
}

function setStyle(objName, fg)
{
  obj = findObj(objName);
  if (obj.style)
  {
    obj.style.display = fg;
  }
}

function popupQuantity(url) {
	  window.open(url,'popupWindow2','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=500,height=600,screenX=150,screenY=150,top=150,left=150');
	}

function popupTailles(url) {
  window.open(url,'popupWindow3','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=500,height=400,screenX=150,screenY=150,top=150,left=150');
}

function popupFlipping(url) {
  window.open(url,'popupWindow4','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=1024,height=800,screenX=0,screenY=0,top=0,left=0');
}

function CheckForm() {
   var bValide = true
   oForm = document.cart_quantity;
   for(i = 0; i < oForm.elements.length; i++) {
	 oElement = oForm.elements[i];
	  if(oElement.name.substring(0, 3) == "id[") {
		/* if(oElement.selectedIndex == 0) bValide = false; */
		if(parseInt(oElement.value) == 0) bValide = false;
	  }
   }
   if(!bValide) {
	 alert('Merci de préciser les options couleur(s), taille(s),... pour ce produit.');
	  return false;
   } else {
	 return true;
   }
}

function GereControle(Controleur, Controle, Masquer) {
var objControleur = document.getElementById(Controleur);
var objControle = document.getElementById(Controle);
	if (Masquer=='1')
		objControle.style.visibility=(objControleur.checked==true)?'visible':'hidden';
	else if (Masquer=='2')
		objControle.style.display=(objControleur.checked==true)?'table-header-group':'none';
	else if (Masquer=='3')
		objControle.style.display=(objControleur.checked==false)?'table-row':'none';
	else if (Masquer=='4')
		objControle.checked=(objControleur.checked==true)?false:'';
	else
		objControle.disabled=(objControleur.checked==true)?false:true;
	return true;
}

window.addEvent('domready', function() {

	//-Informations supplémentaires
	if(document.getElementById('extra_field_slide')){
		var myFx = new Fx.Slide('extra_field_slide').hide().chain(function(){
		    this.show().slideIn('vertical');
		});

		$('extra_toggle').addEvent('click', function(e){
				e.stop();
				myFx.toggle();
			});
	}

	//-Informations sur le stock
	/*produits simples*/

	var limit=20;
	for(var i = 0; i < limit; i++) {
		if(i == 0) {
			if(document.getElementById('stock_field')) {
				var myFx0 = new Fx.Slide('stock_field').hide().chain(function(){
				    this.show().slideIn('vertical');
				});
				$('stock_toggle').addEvent('click', function(e){
						e.stop();
						myFx0.toggle();
					});
			}
		} else if(document.getElementById('stock_field_' + i)) {
			eval("myFx_"+i+"= new Fx.Slide('stock_field_"+i+"').hide().chain(function(){this.show().slideIn('vertical');});");
			eval("$('stock_toggle_"+i+"').addEvent('click', function(e){e.stop(); myFx_"+i+".toggle();});");

		} else {
			break;
		}
	}

});

function bookmarksite(title, url){
if (document.all)
	window.external.AddFavorite(url, title);
else if (window.sidebar)
	window.sidebar.addPanel(title, url, "")
}
