

/* <a-zone id="history"> */
/*
 * $Id: remoteCoffre.js,v 1.13 2008/08/20 09:18:29 fr18739 Exp $
 *
 * $Log: remoteCoffre.js,v $
 * Revision 1.13  2008/08/20 09:18:29  fr18739
 * Evolution DIGITAS
 *
 * Revision 1.12  2008/02/27 15:00:34  tmpacail
 * ajout aux listes en ajax
 *
 * Revision 1.11  2008/02/06 13:59:04  tmpacail
 * correction du probleme de retour vers la fiche produit quand on met
 * un produit dans une liste ( suite ? l'appel de la fiche produit en ajax )
 *
 * Revision 1.10  2008/02/05 15:17:21  tmpacail
 * dynamisation de la page des listes en ajax
 *
 * Revision 1.9  2008/01/16 11:14:07  fr18739
 * bug cq404-suppression dans mini coffre
 *
 * Revision 1.8  2007/12/04 10:51:20  fr18739
 * correction pbme mise au coffre
 *
 * Revision 1.7  2007/11/30 14:25:25  fr18739
 * cq353- modification ajax
 *
 * Revision 1.6  2007/10/19 14:37:03  fr18739
 * retours scripts non compress?s
 *
 * Revision 1.1  2007/10/17 11:09:14  fr18739
 * Scripts non compress?s
 *
 * Revision 1.4  2007/09/07 14:49:54  tmpacail
 * retir les alert en cas d'erreur
 *
 * Revision 1.3  2007/09/05 16:00:47  tmpacail
 * panier ajax : correction des bugs li?s ? l'affichage des popups lorsqu'il y a trois produits dans le panier
 *
 * Revision 1.1  2007/08/29 14:53:01  tmpacail
 * mise au coffre en ajax
 *
 *
*/
/* </a-zone> */


/**
 * This field is used to know if AJAX has already been initialized
 */
 var initDone = false;

/* <a-zone id="fields"> */
/* </a-zone> */

 function initAJAX() {
	jsonrpc = new JSONRpcClient("/coffre/components/remoteCoffre.jsp?ajax-call=true");
	initDone = true;
	/* <a-zone id="initAJAX"> */
	//if the log.js script file has been included in the HTML code, you can now use the LOG methods
	//LOG.info('Initialization done!');
	/* </a-zone> */
}

 function addProductRPC( idProd,  idProdFdr,  lieu,  quantite) {
	if (initDone == false) {
		initAJAX();
	}
	jsonrpc.remoteCoffre.addProductRPC(treatAddProductRPC, idProd, idProdFdr, lieu, quantite);
}

 function treatAddProductRPC( result,  exception) {
	/* <a-zone id="treatAddProductRPC"> */
	if (onAddProductRPCException != null && exception != null) {
		onAddProductRPCException(exception);
	}
	if (onAddProductRPCSuccess != null && result != null) {
		onAddProductRPCSuccess(result);
	}
	/* </a-zone> */
}

 function onAddProductRPCException( exception) {
	/* <a-zone id="onAddProductRPCException"> */
	if (exception) {
		if(exception.code==550) {
			// session expired
			window.location.replace("/accueil.jsp");
		}
		
	}
	/* </a-zone> */
}

 function onAddProductRPCSuccess( result) {
	/* <a-zone id="onAddProductRPCSuccess"> */
	if (result != null) {
		//alert(result);
		persistantSPC.majTopAffSlot(result);
	}
	/* </a-zone> */
}

 function addProductToListeRPC( creation,  listDescription,  listName,  productRef) {
	if (initDone == false) {
		initAJAX();
	}
	jsonrpc.remoteCoffre.addProductToListeRPC(treatAddProductToListeRPC, creation, listDescription, listName, productRef);
}

 function treatAddProductToListeRPC( result,  exception) {
	/* <a-zone id="treatAddProductToListeRPC"> */
	if (onAddProductToListeRPCException != null && exception != null) {
		onAddProductToListeRPCException(exception);
	}
	if (onAddProductToListeRPCSuccess != null && result != null) {
		onAddProductToListeRPCSuccess(result);
	}
	/* </a-zone> */
}

 function onAddProductToListeRPCException( exception) {
	/* <a-zone id="onAddProductToListeRPCException"> */
	if (exception) {
		if(exception.code==550) {
			// session expired
			window.location.replace("/accueil.jsp");
		}
		alert(e);
	}
	/* </a-zone> */
}

 function onAddProductToListeRPCSuccess( result) {
	/* <a-zone id="onAddProductToListeRPCSuccess"> */
	if (result != null) {
	}
	/* </a-zone> */
}

 function emptyBasketRPC() {
	if (initDone == false) {
		initAJAX();
	}
	jsonrpc.remoteCoffre.emptyBasketRPC(treatEmptyBasketRPC);
}

 function treatEmptyBasketRPC( result,  exception) {
	/* <a-zone id="treatEmptyBasketRPC"> */
	if (onEmptyBasketRPCException != null && exception != null) {
		onEmptyBasketRPCException(exception);
	}
	if (onEmptyBasketRPCSuccess != null && result != null) {
		onEmptyBasketRPCSuccess(result);
	}
	/* </a-zone> */
}

 function onEmptyBasketRPCException( exception) {
	/* <a-zone id="onEmptyBasketRPCException"> */
	if (exception) {
		if(exception.code==550) {
			// session expired
			window.location.replace("/accueil.jsp");
		}
	}
	/* </a-zone> */
}

 function onEmptyBasketRPCSuccess( result) {
	/* <a-zone id="onEmptyBasketRPCSuccess"> */
	if (result != null) {
		//alert(result);
		persistantSPC.majTopAffSlot(result);
		
	}
	/* </a-zone> */
}

 function removeProductFromListRPC( liste,  productId) {
	if (initDone == false) {
		initAJAX();
	}
	jsonrpc.remoteCoffre.removeProductFromListRPC(treatRemoveProductFromListRPC, liste, productId);
}

 function treatRemoveProductFromListRPC( result,  exception) {
	/* <a-zone id="treatRemoveProductFromListRPC"> */
	if (onRemoveProductFromListRPCException != null && exception != null) {
		onRemoveProductFromListRPCException(exception);
	}
	if (onRemoveProductFromListRPCSuccess != null && result != null) {
		onRemoveProductFromListRPCSuccess(result);
	}
	/* </a-zone> */
}

 function onRemoveProductFromListRPCException( exception) {
	/* <a-zone id="onRemoveProductFromListRPCException"> */
	if (exception) {
	}
	/* </a-zone> */
}

 function onRemoveProductFromListRPCSuccess( result) {
	/* <a-zone id="onRemoveProductFromListRPCSuccess"> */
	if (result != null) {
	}
	/* </a-zone> */
}

 function removeProductRPC( idProd,  idProdFdr,  lieu) {
	if (initDone == false) {
		initAJAX();
	}
	jsonrpc.remoteCoffre.removeProductRPC(treatRemoveProductRPC, idProd, idProdFdr, lieu);
}

 function treatRemoveProductRPC( result,  exception) {
	/* <a-zone id="treatRemoveProductRPC"> */
	if (onRemoveProductRPCException != null && exception != null) {
		onRemoveProductRPCException(exception);
	}
	if (onRemoveProductRPCSuccess != null && result != null) {
		onRemoveProductRPCSuccess(result);
	}
	/* </a-zone> */
}

 function onRemoveProductRPCException( exception) {
	/* <a-zone id="onRemoveProductRPCException"> */
	if (exception) {
		if(exception.code==550) {
			// session expired
			window.location.replace("/accueil.jsp");
		}
	}
	/* </a-zone> */
}

 function onRemoveProductRPCSuccess( result) {
	/* <a-zone id="onRemoveProductRPCSuccess"> */
	if (result != null) {
		//alert(result);
		persistantSPC.majTopAffSlot(result);
	}
	/* </a-zone> */
}

 function setPopupShownRPC() {
	if (initDone == false) {
		initAJAX();
	}
	jsonrpc.remoteCoffre.setPopupShownRPC(treatSetPopupShownRPC);
}

 function treatSetPopupShownRPC( result,  exception) {
	/* <a-zone id="treatSetPopupShownRPC"> */
	if (onSetPopupShownRPCException != null && exception != null) {
		onSetPopupShownRPCException(exception);
	}
	if (onSetPopupShownRPCSuccess != null && result != null) {
		onSetPopupShownRPCSuccess(result);
	}
	/* </a-zone> */
}

 function onSetPopupShownRPCException( exception) {
	/* <a-zone id="onSetPopupShownRPCException"> */
	if (exception) {
		if(exception.code==550) {
			// session expired
			window.location.replace("/accueil.jsp");
		}
	}
	/* </a-zone> */
}

 function onSetPopupShownRPCSuccess( result) {
	/* <a-zone id="onSetPopupShownRPCSuccess"> */
	if (result != null) {
		//alert(result);
	}
	/* </a-zone> */
}
/* <a-zone id="applicative-code"> */

function RPCcall(){
	
	/* Initialisation of the Connexion*/
	try {
		initAJAX();
	} catch(e) {
	}
	
	this.majTopAffSlot = function( topPremVisite) {
		//alert ( "topPremVisite :"+topPremVisite);
		if (topPremVisite==1) {
			if (document.getElementById("listArtTopAffSlot"))
				document.getElementById("listArtTopAffSlot").style.display = "none";
			if (document.getElementById("MEATopAffSlot"))
				document.getElementById("MEATopAffSlot").style.display = "none";
			}
		else {
			if (topPremVisite==2) {
				if (document.getElementById("listArtTopAffSlot"))
					document.getElementById("listArtTopAffSlot").style.display = "none";
				if (document.getElementById("MEATopAffSlot"))
					document.getElementById("MEATopAffSlot").style.display = "block";
				} else {
				if (topPremVisite==3) {
					if (document.getElementById("listArtTopAffSlot"))
						document.getElementById("listArtTopAffSlot").style.display = "block";
					if (document.getElementById("MEATopAffSlot"))
						document.getElementById("MEATopAffSlot").style.display = "none";
					}
				}
			}
	}
	
	
	this.addProduct = function(idProd,idProdFdr,lieu,qte){
		//alert("--- remote Coffre :"+idProd+"/"+idProdFdr+"/"+qte);
		try{
			addProductRPC(idProd,idProdFdr,lieu,qte);
		}
		catch(e){
		}
	}
	
	this.removeProductFromList = function(liste,  productId){
		try{
			removeProductFromListRPC(liste,productId);
		}
		catch(e){
			throw e;
		}
	}
	
	this.removeProduct = function(idProd,idProdFdr,lieu){
		try{
			removeProductRPC(idProd,idProdFdr,lieu);
		}
		catch(e){
		}
	}
	
	this.emptyBasket = function(){
		try{
			emptyBasketRPC();
		}
		catch(e){
			//alert("bipbip est mort");
			//alert(e.message);
			//alert(e.code);
		//	alert(e.name);
		}
	}
	
	this.setPopupShown = function(){
		try{
			setPopupShownRPC();
		}
		catch(e){
		}
	}
	
	this.addProductToList = function( creation, listDescription,  listName,  productRef){
		try{
			addProductToListeRPC( creation, listDescription, listName,  productRef);
		} catch(e) {
			throw e;
		}	
	}

}

/* </a-zone> */

