
//basket ajax functions
if (typeof (ajaxObjects) == 'undefined')
                  var ajaxObjects = new Array();
  
  
  var shopPath = "/site/";

// =====================================================================

function ajaxSetFicheTech(ajaxIndex,dspObj){

	if (ajaxObjects[ajaxIndex].response != 'NOK') {		      
      dspObj.innerHTML = 	ajaxObjects[ajaxIndex].response;
	  dspObj.innerHTML += "<br /><br /><br /><div align='center'><u>Cliquez pour fermer</u></div>";
	  dspObj.style.display='block';
	  //alert("Displaying Fiche Tech");
	}
	else {
		alert("Produit none trouvé");
	}
}

function ajaxGetFicheTech(idprd,dspObj){
	//alert("calling Srvr for ajax fiche tech.");	
	if (dspObj.style.display != 'block') {	
		var ajaxIndex = ajaxObjects.length;
		ajaxObjects[ajaxIndex] = new sack();
		ajaxObjects[ajaxIndex].requestFile = shopPath + "ajaxGetFicheTech.php";	// file to exec to get colors
		ajaxObjects[ajaxIndex].setVar('productId',idprd);		
		ajaxObjects[ajaxIndex].onCompletion = 
				function(){ ajaxSetFicheTech(ajaxIndex,dspObj); };	// func-executed after ajaxCallCompletion
		ajaxObjects[ajaxIndex].runAJAX();		// Execute AJAX function	
	}
}



// ======================================================================
function ajaxGetBasketPrdCount(){

	var ajaxIndex = ajaxObjects.length;
	ajaxObjects[ajaxIndex] = new sack();
	ajaxObjects[ajaxIndex].requestFile = shopPath + "ajaxGetBasketPrdCount.php";	// file to exec to get colors
	ajaxObjects[ajaxIndex].onCompletion = 
            function(){ ajaxSetBasketPrdCount(ajaxIndex); };	// func-executed after ajaxCallCompletion
	ajaxObjects[ajaxIndex].runAJAX();		// Execute AJAX function	
	
}

function ajaxSetBasketPrdCount(ajaxIndex) {

      var el = document.getElementById('bsktda');
      var count = ajaxObjects[ajaxIndex].response;
      el.value = 	"   (" + count + ") article(s)";
}

//==============================================================================

function ajaxEmptyBasketContents(){
  
  if (nbrElemsInOrder > 0) { //nbrElemsInOrder set in Js via Php page startup code
  	var ajaxIndex = ajaxObjects.length;
  	ajaxObjects[ajaxIndex] = new sack();
  	ajaxObjects[ajaxIndex].requestFile = shopPath + "ajaxEmptyBasketContents.php";	// file to exec to get colors
  	ajaxObjects[ajaxIndex].onCompletion = 
              function(){ ajaxSetBasketIsEmpty(ajaxIndex); };	// func-executed after ajaxCallCompletion
  	ajaxObjects[ajaxIndex].runAJAX();		// Execute AJAX function	
  } 
}

function ajaxSetBasketIsEmpty(ajaxIndex) {     
  var rep = ajaxObjects[ajaxIndex].response;
      if (rep == 'OK') {
        var el = document.getElementById('bsktda');      
        el.value = 	"Panier : " + "0" + " article(s)";
        //alert("Votre panier est vide.");
        document.location.href="http://www.tshirt-personnalisation.fr/Tanit-GotoBasket/";
      } else {
        alert("Impossible de purger votre panier!");
      }
}

//==============================================================================

function ajaxDeleteBasketRow(rowIdx,idPrd) {
// deletes a row from basket lines and redraw the basket
    //
	// todo : 1. quel type de ligne en quest std/perso  2. a t-il des lignes perso si c'est std.	
	//
	// si std et a des lignes perso alors poser la confirmation :
    res = confirm("Voulez-vous supprimer cette ligne?\n\n Attention toute personnalisation doit etre supprimer manuelement."); 
	if (!res) return;
		
	
	var ajaxIndex = ajaxObjects.length;
	ajaxObjects[ajaxIndex] = new sack();
	ajaxObjects[ajaxIndex].requestFile = shopPath + "ajaxDeleteBasketRow.php";	// file to exec to get colors

	ajaxObjects[ajaxIndex].setVar('productId',idPrd);
	ajaxObjects[ajaxIndex].setVar('rowIdx',rowIdx);
	
	ajaxObjects[ajaxIndex].onCompletion = 
            function(){ ajaxSetBasketIsUpdated(ajaxIndex); };	// func-executed after ajaxCallCompletion
	ajaxObjects[ajaxIndex].runAJAX();		// Execute AJAX function	
	
}

function ajaxSetBasketIsUpdated(ajaxIndex) {     
  var rep = ajaxObjects[ajaxIndex].response;
      if (rep == 'OK') {
        document.location.href="http://www.tshirt-personnalisation.fr/Tanit-GotoBasket/";
      } else {
        alert("Impossible de modifier votre panier!");
      }
}

//==============================================================================



