// JavaScript Document
var nav_encour = 0;
var niv_encour = 0;
var rang_encour = 0;

function alert_supp_client(monurl,monaction,monaction_id,moncomplement_alerte)
	{
	if(confirm("Etes-vous certain de vouloir supprimer définitivement " + moncomplement_alerte + " ?"))
		{
			window.location.href = monurl+"&useraction="+monaction+"&action_id="+monaction_id;

		}
	}

jQuery.expr[':'].regex = function(elem, index, match) {
    var matchParams = match[3].split(','),
        validLabels = /^(data|css):/,
        attr = {
            method: matchParams[0].match(validLabels) ? 
                        matchParams[0].split(':')[0] : 'attr',
            property: matchParams.shift().replace(validLabels,'')
        },
        regexFlags = 'ig',
        regex = new RegExp(matchParams.join('').replace(/^\s+|\s+$/g,''), regexFlags);
    return regex.test(jQuery(elem)[attr.method](attr.property));
}




function afichier_panier()
	{
		
	$.ajax({
  		url: 'inc/xhr/panier_cold.inc.php',
  		success: function(data) {
   			 $('#panier').html(data);
    		// alert('Load was performed.');
  			}
		});
	}
	

function changer_variable(variable,value)
	{
	$.ajax({
  		url: 'inc/xhr/changer_variables.inc.php?variable='+variable+'&value='+value,
		  async: false,

  		success: function(data) {
			
			history.go(0);
   			 //$('#panier').html(data);
    		// alert('Load was performed.');
  			}
		});
	}


function verif_adresse(address) {

    if(!geocoder) {
        // si le geocoder n'a pas été utilisé, on l'instancie
        geocoder = new GClientGeocoder();
    }
    if(geocoder) {
        geocoder.getLatLng(address, function(point) {
                if(!point) {

                	// alert(address +' : est introuvable sur GoogleMap');
			return false;

            } else {
                	alert('oui'); 
			return true;
           	 }
        });
    }
}

function affichage_panier(action)
	{
		//alert('oui');
	$.ajax({
  		url: 'inc/xhr/changer_variables.inc.php?variable=panier_cold&value='+action,
		  async: false,

  		success: function(data) {
			
			history.go(0);
   			 //$('#panier').html(data);
    		//alert(data);
  			}
		});		
	}


function ajouter_article(id)
	{
   	$('#titrecold').html('<h4><strong>Mise &agrave; jour du panier...</strong></h4>');
	q_article = $('#q_article'+id).val();
	$.ajax({
  		url: 'inc/xhr/panier_cold.inc.php?id='+id+'&q_ajouter='+q_article,
  		success: function(data) {
   			 $('#panier').html(data);
			 //alert(data);
    		// alert('Load was performed.');
  			}
		});
	}
	
	
function valid_quantite(value,id_maj,coldroite,tranche)
	{
	if(!tranche)
		tranche = 1;
	if(value==-1)
		{
			
			
		result = prompt('Choisissez une quantité', '');
		if (result != null && result != "" && Math.abs(result)==result)
			{
				
				//alert((result/tranche)+"/"+Math.round(result/tranche));
				
			if (tranche && (result/tranche) != Math.round(result/tranche))
				{
				alert("Vous devez saisir un multiple de "+tranche);
				valid_quantite(value,id_maj,coldroite,tranche);
				}
			else
				value = result;
			}
		else
			{
			alert("Vous devez saisir un entier");
			valid_quantite(value,id_maj,coldroite);
			}
			
			
		}
		//alert(value);
	if(value !=-1 )
		{
		if(coldroite)
			{
			
			$.ajax({
			url: 'inc/xhr/panier_cold.inc.php?id_maj='+id_maj+"&quantite="+value,
			success: function(data) {
				 $('#panier').html(data);
				// alert('Load was performed.');
				}
			});
				
			}
		else
			window.location.href="espace-client_100.php&corp=client_panier&useraction=modif_quantite&id_maj="+id_maj+"&quantite="+value;
		}			
	}
	
	
function valid_gramage(value,id_maj,coldroite)
	{
		//alert(id_maj);
		
		if(coldroite)
			{
			
			$.ajax({
			url: 'inc/xhr/panier_cold.inc.php?id_ligne='+id_maj+"&id_article_new="+value,
			success: function(data) {
				 $('#panier').html(data);
				// alert('Load was performed.');
				}
			});
				
			}
		else
			window.location.href="espace-client_100.php&corp=client_panier&useraction=modif_grammage&id_ligne="+id_maj+"&id_article_new="+value;
	}
	
function photo_variete(ref)
	{
		
	//var texthtml = "<a href=\"images/varietes/"+ref+"_T4.jpg\" class=\"highslide\" onClick=\"return hs.expand(this)\" style=\"margin-left: 0;\"><img src=\"images/varietes/"+ref+"_T3.jpg\" border=\"0\" style=\"border: none;\" /></a>";
	
	$('#photovariete').attr("src", "images/varietes/"+ref+"_T3.jpg"); 
	$('#lienphotovariete').attr("href", "images/varietes/"+ref+"_T4.jpg"); 
	}
	
function ajouter_ref_commande()
	{
		
	//var texthtml = "<a href=\"images/varietes/"+ref+"_T4.jpg\" class=\"highslide\" onClick=\"return hs.expand(this)\" style=\"margin-left: 0;\"><img src=\"images/varietes/"+ref+"_T3.jpg\" border=\"0\" style=\"border: none;\" /></a>";
	
	ref = $('#ajout_ref').val(); 
	if(ref != '')
			window.location.href="espace-client_100.php&corp=client_panier&useraction=ajout_ref&ref="+ref;
		
	}
	
	
function check_pro(statut)
	{
	
		$('.ligne_pro').each(function () {
											$(this).hide();})
			
	if(statut=="R")
		{
		$('#lignesiret').show();
		$('#lignesiteweb').show();
		}
	if(statut != "P" && pays_ue_tva[document.forms['formu'].elements['code_pays'].value])
		$('#lignetva').show();
	
	}
	
function afficher_detail_liste()
	{
		$('#chapeauliste').css('height','inherit');
		$('#pluschapeauliste').hide();
	}
	

	

jQuery.cookie = function (key, value, options) {

    // key and value given, set cookie...
    if (arguments.length > 1 && (value === null || typeof value !== "object")) {
        options = jQuery.extend({}, options);

        if (value === null) {
            options.expires = -1;
        }

        if (typeof options.expires === 'number') {
            var days = options.expires, t = options.expires = new Date();
            t.setDate(t.getDate() + days);
        }

        return (document.cookie = [
            encodeURIComponent(key), '=',
            options.raw ? String(value) : encodeURIComponent(String(value)),
            options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
            options.path ? '; path=' + options.path : '',
            options.domain ? '; domain=' + options.domain : '',
            options.secure ? '; secure' : ''
        ].join(''));
    }

    // key and possibly options given, get cookie...
    options = value || {};
    var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
    return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
};


