function RequestObject()
{
	var Request = null;

	if (typeof(XMLHttpRequest) != 'undefined')
	{
		Request = new XMLHttpRequest();
	}
	else
	{
		try
		{
			Request = new ActiveXObject('Microsoft.XMLHTTP');
		}
		catch (e)
		{
			Request = null;
		}
	}

	return Request;
}


function ShowPopup(IDPROD, QTE, NOMPROD,IDSESSION)
{
	var Request = RequestObject();

	if (!Request)
	{
		alert("probleme request");
		return;
	}
	Request.onreadystatechange = function()
	{

		if (Request.readyState == 4 && Request.status == 200)
		{
	
			if (Request.responseText)
			{
				
				var FondMessage = document.createElement("div");
				FondMessage.style.backgroundColor = '#000000';
				FondMessage.style.width = '100%';
				FondMessage.style.height = '1400px';
				FondMessage.id = 'FondPopup';
				FondMessage.style.position = 'absolute';
				FondMessage.style.opacity = '0.8';
				FondMessage.style.filter = 'alpha (opacity=80)';
				FondMessage.style.top ='0px';
				FondMessage.style.left ='0px';
				
				var ZonePopup = document.createElement("div");
				ZonePopup.style.width = '470px';
				ZonePopup.style.height = '160px';
				ZonePopup.style.position = 'absolute';
				ZonePopup.id= 'Popup';
				ZonePopup.style.background = '#A2A1AF';
				ZonePopup.style.border = '2px solid #FFF';
				ZonePopup.style.left = '0';
				ZonePopup.style.top = '0';

			var HTML = '<div style="background-color:#051D5B; z-index:500000;"><div style="text-align:center; height:22px; padding-left:10px; padding-right:10px;  padding-top:10px; color:#FFFFFF; font-size:14px; font-weight:bold;">Ajout de Produit</div></div>'
			+ '<div>'
			+ '<table width="100%" border="0" cellspacing="0" cellpadding="2">'
			+ '<tr>'
			+ '<td height="70" colspan="2" valign="middle" style="color:#000; padding-left:10px;padding-right:10px;">';
			if (NOMPROD)
			{
				HTML += '<div style="font-size:13px; font-weight:bold;">' + NOMPROD + '</div>';
				if(QTE>1){
					HTML +=  '<div><span style="color:#FF0000">' + QTE + '</span> articles ont &eacute;t&eacute; ajout&eacute;s &agrave; votre panier.</div>';
				}else{
					HTML +=  '<div><span style="color:#FF0000">' + QTE + '</span> article a &eacute;t&eacute; ajout&eacute; &agrave; votre panier.</div>';	
				}
			}
			HTML += '</td>'
			+ '</tr>'
			+ '<tr>'
			+ '<td width="50%" height="48" align="center" valign="top"><a href="#" onclick="verspanier(true,\''+IDSESSION+'\'); return false;"><img src="http://www.ruedelafete.com/ruedelafete/ruedelafete2/img/btretourboutique.gif" width="197" height="36" border="0" alt="Retour sur la boutique" title="Retour sur la boutique" /></a></td>'
			+ '<td width="50%" height="48" align="center" valign="top"><a href="#" onclick="verspanier(false,\''+IDSESSION+'\'); return false;"><img src="http://www.ruedelafete.com/ruedelafete/ruedelafete2/img/btvoirpanier.gif" width="197" height="36" border="0" alt="Voir votre panier" title="Voir votre panier" /></a></td>'
			+ '</tr>'
			+ '</table>'
			+ '</div>'
			;
				ZonePopup.innerHTML = HTML;
				 
				majpanier = document.getElementById('montantpanier');
				majpanier.innerHTML = Request.responseText;
	
				document.body.appendChild(FondMessage);
				document.body.appendChild(ZonePopup);
				

				
				if (navigator.appName=="Microsoft Internet Explorer")
				{	
					document.getElementById('visuel').className='cache';
					if ( document.getElementById('zoneliste') ) {
						document.getElementById('zoneliste').className='cache';
					} 
					document.getElementById('zonequantite').className='cache';
					ScrollY = document.documentElement.scrollTop + document.body.scrollTop;
					ScrollX = document.documentElement.scrollLeft + document.body.scrollLeft;
				}
				else
				{
					ScrollY = window.pageYOffset;
					ScrollX = window.pageXOffset;
				}
				var View = {
					width 	: (
						// W3C Compliant calculation
						window.innerWidth ? 
							window.innerWidth : 
							// IE 6 + 
							( document.documentElement && document.documentElement.clientWidth ) ?
								document.documentElement.clientWidth  : 
								// IE 4
								document.body.clientWidth
					),
					height  : (
						// W3C Compliant calculation
						window.innerHeight ? 
							window.innerHeight  : 
							// IE 6 + 
							( document.documentElement && document.documentElement.clientHeight ) ?
								document.documentElement.clientHeight  : 
								// IE 4
								document.body.clientHeight
					)
				}

				
				ZonePopup.style.left = (View.width / 2 	- ZonePopup.offsetWidth / 2 + ScrollX) + 'px';
				ZonePopup.style.top = (View.height / 2 	- ZonePopup.offsetHeight / 2 + ScrollY ) + 'px';
			
			}
		}
	}

	Request.open('GET', '/php/main_new_api.php?EXEC=7&ID_SESSION='+IDSESSION+'&ID_PRODUCT='+IDPROD+'&NUMBER='+QTE, true);
	Request.send(null);

}


  // Nicolas
  function form_to_url( elt )
  {
    var u = "";
    var Telts =elt.childNodes;
    var nb_elt=Telts.length;

    for(var i=0; i<nb_elt; i++) {
      elt=Telts[i];
      // nodeType
      // ELEMENT_NODE : 1
      // TEXT_NODE : 3
      // nodeName : INPUT  FIELDSET...
      // Ignorer les champs 'button' sauf pour celui qui est actif...

      // if (elt && elt.type && elt.type=='submit')
      // {
      //   alert( 'n=' + elt.name + ' t=' + elt.type + ' v=' + elt.value +
      //          ' dv=' + elt.defaultvalue + ' s=' + elt.size + ' ml=' + elt.maxlength +
      //          ' c=' + elt.checked + ' d=' + elt.disabled + ' r=' + elt.readOnly);
      // }

      if (elt && elt.name && elt.value) {
        var key=encodeURIComponent(elt.name);
        var val=encodeURIComponent(elt.value);
        if (key!="AJAX") u+= "&" + key + "=" + val;
      }
      u+=form_to_url(elt);
    }
    return u;
  }

function ShowPopup2(URL, FORM, QTE, NOMPROD)
{
	var Request = RequestObject();

	if (!Request)
	{
		alert("probleme request");
		return;
	}
	Request.onreadystatechange = function()
	{

		if (Request.readyState == 4 && Request.status == 200)
		{
	
			if (Request.responseText)
			{
				
				var FondMessage = document.createElement("div");
				FondMessage.style.backgroundColor = '#000000';
				FondMessage.style.width = '100%';
				FondMessage.style.height = '1400px';
				FondMessage.id = 'FondPopup';
				FondMessage.style.position = 'absolute';
				FondMessage.style.opacity = '0.8';
				FondMessage.style.filter = 'alpha (opacity=80)';
				FondMessage.style.top ='0px';
				FondMessage.style.left ='0px';
				
				var ZonePopup = document.createElement("div");
				ZonePopup.style.width = '470px';
				ZonePopup.style.height = '160px';
				ZonePopup.style.position = 'absolute';
				ZonePopup.id= 'Popup';
				ZonePopup.style.background = '#A2A1AF';
				ZonePopup.style.border = '2px solid #FFF';
				ZonePopup.style.left = '0';
				ZonePopup.style.top = '0';

			var HTML = '<div style="background-color:#051D5B; z-index:500000;"><div style="text-align:center; height:22px; padding-left:10px; padding-right:10px;  padding-top:10px; color:#FFFFFF; font-size:14px; font-weight:bold;">Ajout de Produit</div></div>'
			+ '<div>'
			+ '<table width="100%" border="0" cellspacing="0" cellpadding="2">'
			+ '<tr>'
			+ '<td height="70" colspan="2" valign="middle" style="color:#000; padding-left:10px;padding-right:10px;">';
			if (NOMPROD)
			{
				HTML += '<div style="font-size:13px; font-weight:bold;">' + NOMPROD + '</div>';
				if(QTE>1){
					HTML +=  '<div><span style="color:#FF0000">' + QTE + '</span> articles ont &eacute;t&eacute; ajout&eacute;s &agrave; votre panier.</div>';
				}else{
					HTML +=  '<div><span style="color:#FF0000">' + QTE + '</span> article a &eacute;t&eacute; ajout&eacute; &agrave; votre panier.</div>';	
				}
			}
			HTML += '</td>'
			+ '</tr>'
			+ '<tr>'
			+ '<td width="50%" height="48" align="center" valign="top"><a href="#" onclick="verspanier2(true,\''+URL+'\'); return false;"><img src="http://www.ruedelafete.com/ruedelafete/ruedelafete2/img/btretourboutique.gif" width="197" height="36" border="0" alt="Retour sur la boutique" title="Retour sur la boutique" /></a></td>'
			+ '<td width="50%" height="48" align="center" valign="top"><a href="#" onclick="verspanier2(false,\''+URL+'\'); return false;"><img src="http://www.ruedelafete.com/ruedelafete/ruedelafete2/img/btvoirpanier.gif" width="197" height="36" border="0" alt="Voir votre panier" title="Voir votre panier" /></a></td>'
			+ '</tr>'
			+ '</table>'
			+ '</div>'
			;
				ZonePopup.innerHTML = HTML;
				 
				majpanier = document.getElementById('montantpanier');
				majpanier.innerHTML = Request.responseText;
	
				document.body.appendChild(FondMessage);
				document.body.appendChild(ZonePopup);
				

				
				if (navigator.appName=="Microsoft Internet Explorer")
				{	
					document.getElementById('visuel').className='cache';
					if ( document.getElementById('zoneliste') ) {
						document.getElementById('zoneliste').className='cache';
					} 
					document.getElementById('zonequantite').className='cache';
					ScrollY = document.documentElement.scrollTop + document.body.scrollTop;
					ScrollX = document.documentElement.scrollLeft + document.body.scrollLeft;
				}
				else
				{
					ScrollY = window.pageYOffset;
					ScrollX = window.pageXOffset;
				}
				var View = {
					width 	: (
						// W3C Compliant calculation
						window.innerWidth ? 
							window.innerWidth : 
							// IE 6 + 
							( document.documentElement && document.documentElement.clientWidth ) ?
								document.documentElement.clientWidth  : 
								// IE 4
								document.body.clientWidth
					),
					height  : (
						// W3C Compliant calculation
						window.innerHeight ? 
							window.innerHeight  : 
							// IE 6 + 
							( document.documentElement && document.documentElement.clientHeight ) ?
								document.documentElement.clientHeight  : 
								// IE 4
								document.body.clientHeight
					)
				}

				
				ZonePopup.style.left = (View.width / 2 	- ZonePopup.offsetWidth / 2 + ScrollX) + 'px';
				ZonePopup.style.top = (View.height / 2 	- ZonePopup.offsetHeight / 2 + ScrollY ) + 'px';
			
			}
		}
	}

	
	 var URL_ADD_TO_CART = "/php/main_new_api.php?";
    // Ajout des champs du formulaire qui vient d'être validé (format GET)
    if (FORM!=null) URL_ADD_TO_CART+=form_to_url(FORM);

	Request.open('GET', URL_ADD_TO_CART, true);
	Request.send(null);

}



function verspanier(etat,IDsession)
{

	if (!etat){
		location.href = '/php/commande/main_commande.php?EXEC=3&CLIENT=9000&NUM_SESSION='+IDsession;
	}else{
		if (navigator.appName=="Microsoft Internet Explorer")
		{	
			if ( document.getElementById('zoneliste') ) {
				document.getElementById('zoneliste').className='';
			} 
			document.getElementById('zonequantite').className='';
			document.getElementById('visuel').className='';
		}
		
		popup = document.getElementById('Popup');
		popup.parentNode.removeChild(popup);
		
		fondpopup = document.getElementById('FondPopup');
		fondpopup.parentNode.removeChild(fondpopup);
	}
}


function verspanier2(etat,URL)
{

	if (!etat){
		location.href = URL;
	}else{
		if (navigator.appName=="Microsoft Internet Explorer")
		{	
			if ( document.getElementById('zoneliste') ) {
				document.getElementById('zoneliste').className='';
			} 
			document.getElementById('zonequantite').className='';
			document.getElementById('visuel').className='';
		}
		
		popup = document.getElementById('Popup');
		popup.parentNode.removeChild(popup);
		
		fondpopup = document.getElementById('FondPopup');
		fondpopup.parentNode.removeChild(fondpopup);
	}
}
