
//ACCOUNT
function accountLogin()
{
    $.nyroModalManual({
      url: 'account_login.php',
   	  minHeight: 120 // Hauteur minimale
    });
}


function accountComListe()
{
    $.nyroModalManual({
      url: 'account_com_liste.php',
   	  minHeight: 300 // Hauteur minimale
    });
}

//CADDY
function caddyUpdateInterface()
{
	$.ajax({
		  url: 'caddy_action.php',
		  type: "POST",
		  dataType: "json",
		  success: function(data) 
		  {
			    $('#barnavPanierMontant').html(data.prix+' &euro;');
		  }
	});
}

var cur_ID_pdt = 0;
function caddyAction(act, ID_pdt, qte, rechargInfoProduit, rechargCaddyShow)
{
	if(ID_pdt > 0)
	{
		$.ajax({
		  url: 'caddy_action.php',
		  type: "POST",
		  dataType: "json",
		  data: ({act : act, ID_produit : ID_pdt, qte : qte}),
		  success: function(data) 
		  {
			  	if(data.action_return_errmsg != '')
			  	{
			  		alert(data.action_return_errmsg);
			  	}
			  	else
			  	{		
				    $('#barnavPanierMontant').html(data.prix+' &euro;');
				    if(rechargInfoProduit == 1 && ID_pdt == cur_ID_pdt)
			    	{
			    		pdtInfos(ID_pdt);//Rechargement pour stocks
			    	}
			    	if(rechargCaddyShow == 1)
			    	{
			    		caddyShow();
			    	}
			    }
		    
		  }
		});	
	}
}

function caddyRefreshPrixOnDelArticle(ID_pdt)
{
	$.ajax({
      url: 'caddy_action.php',
      type: "POST",
      dataType: "json",
      data: ({}),
      success: function(data) 
      {
  		    $('#barnavPanierMontant').html(data.prix+' &euro;');
  		    if(ID_pdt > 0 && cur_ID_pdt == ID_pdt)
  	    	{
  	    		pdtInfos(ID_pdt);//Rechargement pour affichage stocks
  	    	}
      }
    });	
}


function caddyRecapDel(ID_pdt)
{
		$.ajax({
		  url: 'caddy_action.php',
		  type: "POST",
		  dataType: "json",
		  data: ({act : 'del', ID_produit : ID_pdt}),
		  success: function(data) {
		    
		    caddyShow();
		    caddyRefreshPrixOnDelArticle(ID_pdt);
		    
		  }
		});	
}

function caddyShow()
{
    $.nyroModalManual({
      url: 'caddy_recap.php'
    });
}

function caddyIdent()
{
    $.nyroModalManual({
      url: 'com_etap1_ident.php',
   	  minHeight: 220 // Hauteur minimale
    });	
}


function caddyCoord(createStatus)
{
    $.nyroModalManual({
      url: 'com_etap2_coord.php?create='+createStatus,
   	  minHeight: 370 // Hauteur minimale
    });
}

function caddyCoordSubmit(errDiv)
{
	var livr_nom = document.getElementById('livr_nom').value;
	var livr_prenom = document.getElementById('livr_prenom').value;
	var livr_addr = document.getElementById('livr_addr').value;
	var livr_cpost = document.getElementById('livr_cpost').value;
	var livr_ville = document.getElementById('livr_ville').value;
	
	var fact_nom = document.getElementById('fact_nom').value;
	var fact_prenom = document.getElementById('fact_prenom').value;
	var fact_addr = document.getElementById('fact_addr').value;
	var fact_cpost = document.getElementById('fact_cpost').value;
	var fact_ville = document.getElementById('fact_ville').value;

	$.ajax({
      url: 'com_etap2_coord_process.php',
      type: "POST",
      dataType: "json",
      data: ({livr_nom : livr_nom, livr_prenom : livr_prenom, livr_addr : livr_addr, livr_cpost : livr_cpost, livr_ville : livr_ville, fact_nom : fact_nom, fact_prenom : fact_prenom, fact_addr : fact_addr, fact_cpost : fact_cpost, fact_ville : fact_ville }),
      success: function(data) {

        if(data.retour == 1)
        {
        	//Retour OK => paiement
   			caddyCoordVerif('');
        }
        else
        {
        	//Retour ERR
    	    $('#'+errDiv).html("Merci de remplir tous les champs du formulaire");
        }
        
      }
    });	
}

function caddyCoordVerif()
{
    $.nyroModalManual({
      url: 'com_etap3_verif.php',
   	  minHeight: 200 // Hauteur minimale
    });
}

function caddyPaiement()
{
    $.nyroModalManual({
      url: 'com_etap4_paiement.php',
   	  minHeight: 200 // Hauteur minimale
    });
}

function comConfirmPaiement(ID_com)
{
    $.nyroModalManual({
      url: "com_confirm.php?com="+ID_com,
   	  minHeight: 200 // Hauteur minimale
    });
}

//USERS
function userIdent(login, pwd, pageRetour, errDiv)
{
	$.ajax({
      url: 'account_login_process.php',
      type: "POST",
      dataType: "json",
      data: ({login : login, pwd : pwd}),
      success: function(data) {
        
        if(data.retour == 1)
        {
        	//Retour OK
        	switch(pageRetour)
        	{
        		case '1'://Commande, on renvoie vers saisie coordonnees
        			caddyCoord('0');
        		break;
        		default://Espace client : liste des commandes
    	    		accountComListe();
        		break;
        	}
        }
        else
        {
        	//Retour ERR
    	    $('#'+errDiv).html('E-mail ou mot de passe incorrect. Merci de contr&ocirc;ler votre saisie.');
        }
        
      }
    });	
}


function userCreateProfil(email, pwd, pageRetour, errDiv)
{
		$.ajax({
		  url: 'com_etap1_ident_process.php',
		  type: "POST",
		  dataType: "json",
		  data: ({email : email, pwd : pwd}),
		  success: function(data) {

		    if(data.retour == 1)
		    {
		    	//Retour OK
		    	switch(pageRetour)
		    	{
		    		case '1'://Commande, on renvoie vers saisie coordonnees
		    			caddyCoord('1');
		    		break;
		    		default://Espace client : liste des commandes
			    		userAccountComListe();
		    		break;
		    	}
		    }
		    else
		    {
		    	//Retour ERR
			    $('#'+errDiv).html(data.err);
		    }
		    
		  }
		});
}

//PRODUITS
function pdtInfos(ID_pdt)
{
	
	cur_ID_pdt = ID_pdt;//MAJ variable globale pour ajout caddy
	$.ajax({
	  url: 'produits_lst_bg_infos.php',
	  type: "POST",
	  dataType: "json",
	  data: ({ID : ID_pdt}),
	  success: function(data) 
	  {
	    
	    $('#footerPanierDetailTitre').html(data.pdt_name);
	    $('#footerPanierDetailTxt').html(data.pdt_txt);
	    $('#collecLstPdtDetailColors').html(data.pdt_colors);//couleurs
	    
	    //Gestion Prix Solde
	    if(data.pdt_remise_solde > 0)
	    {
		    $('.footerPanierDetailPrix').html(data.pdt_prix_solde+' &euro;');
		    $('#footerPanierDetailSoldePrixDeBase').html(data.pdt_price+' &euro;');
		    $('#footerPanierDetailSoldeRemise').html('-'+data.pdt_remise_solde+' %');
	    	$('#footerPanierDetailSolde').show();
	    }
	    else
	    {
	    	$('#footerPanierDetailSolde').hide();
		    $('.footerPanierDetailPrix').html(data.pdt_price+' &euro;');	    
	    }
	    
	    if(data.pdt_stocks > 0)
	    {
	    	document.getElementById('footerPanierNoStock').style.display = 'none';
	    	document.getElementById('footerPanierAddLink').style.display = '';
	    	/*document.getElementById('footerPanierAddLink').style.visibility = 'visible';*/
	    	document.getElementById('footerPanierAddLinkImg').style.display = '';
	    	document.getElementById('footerPanierAddLinkImgNoStock').style.display = 'none';
	    	
	    }
	    else
	    {
	    	document.getElementById('footerPanierAddLink').style.display = 'none';
	    	document.getElementById('footerPanierNoStock').style.display = '';
	    	/*document.getElementById('footerPanierNoStock').style.visibility = 'visible';*/
   	    	/*document.getElementById('footerPanierAddLink').style.visibility = 'hidden';*/
	    	document.getElementById('footerPanierAddLinkImg').style.display = 'none';
	    	document.getElementById('footerPanierAddLinkImgNoStock').style.display = '';
	    }

		//liens prev / next
		if(data.pdt_prev != '0')
	    {
	    	ID_pdt_prev	= data.pdt_prev;
	        document.getElementById('collecLstPdtDetailNavPrev').style.visibility = 'visible';//lienprec
	    }
	    else
	    {
	        document.getElementById('collecLstPdtDetailNavPrev').style.visibility = 'hidden';//lienprec
	    	ID_pdt_prev	= 0;
	    }
	    
	    if(data.pdt_next != '0')
	    {
	    	ID_pdt_next	= data.pdt_next;

	        document.getElementById('collecLstPdtDetailNavNext').style.visibility = 'visible';//lienprec
	    }
	    else
	    {
	    	ID_pdt_next	= 0;
	        document.getElementById('collecLstPdtDetailNavNext').style.visibility = 'hidden';//lienprec
	    }
	    
	  }
	});
}

function pdtSelect (ID_pdt)
{
    pdtInfos(ID_pdt);//Infos produit
    document.getElementById('produitDetailZoomLink').href = 'datas/produits/'+ID_pdt+'_big.jpg';
    $('div#collecLstConteneur').stop().scrollTo( $('#collecLstPdt'+ID_pdt), 500, {axis:'x',offset:-560} );//Scrolling

}

function pdtKeyNavigate ()
{
	var keyNav = false;$(document).keyup(function (e) {
		switch(e.which)
		{
			case 37://gauche
				if(ID_pdt_prev > 0)
				{
					pdtSelect(ID_pdt_prev);
				}
			break;
			case 39://droite
				if(ID_pdt_next > 0)
				{
					pdtSelect(ID_pdt_next);
				}
			break;
		}
	});
}

function boutiqueScroll(ID_boutique)
{
	$('div#boutiqueConteneur').stop().scrollTo( $('#boutique_'+ID_boutique), 500, {axis:'x'} );//Scrolling
}

//ADMIN
function comDelete( queryStr, ID_com_del )
{
	if(confirm("Etes vous sur de vouloir supprimer cette commande ? En cas d'erreur, vous devrez contacter votre interlocuteur technique pour la reactiver. Pour annuler simplement cette commande en informant l'utilisateur, passez le statut de la commande => annulée."))
	{
		window.location = 'admin_liste_com.php?del='+ID_com_del+'&'+queryStr;
	}
}

function comUpdateStatus(ID_com, status)
{
	$('#detailComStatusUpdate').html("Enregistrement...");
	$.ajax({
	  url: 'admin_detail_com_update.php',
	  type: "POST",
	  dataType: "json",
	  data: ({ID_com : ID_com, status: status}),
	  success: function(data) {	    
			$('#detailComStatusUpdate').html("Modification enregistr&eacute;es !");
	  }
	});
}

function comUpdateNumcolis(ID_com, numcolis)
{
	$('#detailComNumcolisUpdate').html("Enregistrement...");
	$.ajax({
	  url: 'admin_detail_com_update_numcolis.php',
	  type: "POST",
	  dataType: "json",
	  data: ({ID_com : ID_com, numcolis: numcolis}),
	  success: function(data) {	    
			$('#detailComNumcolisUpdate').html("Modification enregistr&eacute;es !");
	  }
	});
}

//DIV
function comDetail(ID_com)
{
    $.nyroModalManual({
      url: 'admin_detail_com.php?ID_com='+ID_com,
	  minHeight: 200 // Hauteur minimale
    });	
}

function cgv()
{
    $.nyroModalManual({
      url: 'cgv.php',
      minWidth: 200, // Largeur minimale
	  minHeight: 250 // Hauteur minimale
    });
}

function eBoutiqueTmp()
{
    $.nyroModalManual({
      url: 'e-boutique.php',
      minWidth: 200, // Largeur minimale
	  minHeight: 150 // Hauteur minimale
    });
}

function Contact()
{
    $.nyroModalManual({
      url: 'contact.php',
      minWidth: 400, // Largeur minimale
	  minHeight: 400 // Hauteur minimale
    });
}

function noStock()
{
    $.nyroModalManual({
      url: 'caddy_nostock.php',
      minWidth: 300, // Largeur minimale
	  minHeight: 50 // Hauteur minimale
    });
}

function eBoutiqueTmpProcess(nom, prenom, mail)
{
	if(mail.indexOf('@') == -1 || mail.indexOf('.') == -1)
	{
		$('#eBoutiqueErr').html("Adresse e-mail incorrecte !");
	}
	else
	{
	    $.nyroModalManual({
	      url: 'e-boutique_process.php?mail='+mail+'&nom='+nom+'&prenom='+prenom,
	      minWidth: 200, // Largeur minimale
		  minHeight: 150 // Hauteur minimale
	    });
    }
}
