// 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));
}


var menu_affiche = 0;

function ouvre_menu(i,type)
	{
		
	if(i!=menu_affiche)
		{
		
		
			var sousnav = $('#sousnav');
			
			
				//alert(sousnav.css("height"));
			
				
			if(sousnav.css("height")=="0px")
				{
				sousnav.animate({height: "140px"}, {queue:false, duration:250});				
				}
			
			sousnav.html('');
			
			
			if(menu_parents[i])
				{
				for(x=0; x< menu_parents[i].length ; x++)
					{			
					//text = menu_parents[i][x] + ' - ';
					//sousnav.append(text);		
					//alert(i + ":" + x + ':' + menu_parents[i][x] + ' : ' + $("#menu"+menu_parents[i][x]).html());
					text = '<div class="sm" id="sm'+menu_parents[i][x]+'">'+$("#menu"+menu_parents[i][x]).html()+'</div>' ;
					sousnav.append(text);
					
					
					$('#lien'+menu_parents[i][x]).addClass('rub ov');
					
					if(menu_parents[i][x]<7)
						{
						$('#sm'+menu_parents[i][x]).css("border","none");
						$('#sm'+menu_parents[i][x]).css("font-size","15px");		
						$('#sm'+menu_parents[i][x]+ ' li').css("padding-bottom","3px");				
						}

					
					}
				}
					
			if(type=='rub')
				{
					if($("#menu"+i).html())
						{
						text = '<div class="sm" id="sm'+i+'">'+$("#menu"+i).html()+'</div>' ;
				
						sousnav.append(text);	
						}
					else
						{
							if(i!=5)
								{
								text = '<div class="sm" id="sm'+i+'">Aucune vari&eacute;t&eacute; trouv&eacute;e</div>' ;
								}
							else
								{
								text ='<div class="sm" id="sm8">NOUS NE PROPOSONS PAS DE GRAINES A GERMER CETTE ANN&Eacute;E...<br />Les graines germ&eacute;es font partie de l\'alimentation humaine depuis la nuit des temps.<br />Avec l\'apparition, l\'&eacute;t&eacute; dernier en Allemagne, d\'une souche virulente de la bact&eacute;rie Escherichia Coli, ces graines, pr&eacute;sum&eacute;es coupables sont aujourd\'hui suspectes.<br />C\'est dans ce climat de confusion que les pouvoirs publics ont exerc&eacute; une pression sanitaire exceptionnelle sur la production et la distribution des graines &agrave; germer.<br />En attendant un climat plus serein profitable &agrave; leur d&eacute;veloppement, nous suspendons la vente de ces articles.<br />Les vari&eacute;t&eacute;s de graines disponibles par le pass&eacute; dans notre catalogue &agrave; la page Graines &agrave; Germer, sont distribu&eacute;es <strong>uniquement</strong> pour l\'usage d\'engrais verts.</div>';
								}
				
						sousnav.append(text);	
						}
				}
				
			
			if(i<7)
				{
				$('#sm'+i).css("border","none");
				$('#sm'+i).css("font-size","15px");		
				$('#sm'+i+ ' li').css("padding-bottom","3px");				
				}
			
			
			//alert($('#lien'+i).attr('href'));
			$('#lien'+i).addClass(type + ' ov');
			
				
			if($('#sousnav').css("display")=="none")
			$('#sousnav').slideToggle('slow');
			
			
			menu_affiche = i;
	}

			
		
	}

function ferme_menu(niv)
	{
		//alert()
		/*
		if(niv<niv_encour)
			$('#sm'+nav_encour+niv_encour+rang_encour).remove(); 
			
			niv_encour = niv;
			*/
	}


function afficher_prix(id)
	{
		//alert("#tarifs"+id);
		$("#tarifs"+id).css("display","");
	}


function afichier_panier()
	{
		
	$.ajax({
  		url: 'inc/xhr/panier_cold.inc.php',
  		success: function(data) {
   			 $('#panier').html(data);
    		// alert('Load was performed.');
  			}
		});
	}
	
function afficher_fiche(id)
	{			
	
			fermer_fiche();
			$('body').append('<div class="fichevariete" id="fichevariete"></div>');
			
			var fichevariete = $('.fichevariete');
			
			var posScroll = parseInt($(document).scrollTop())+25;	
	
			var h1 = $("h1:first");
			var offset = h1.offset();
			var posleft = offset.left;
			
			var posH1 = Math.round(offset.top)-150;
			
				
			var posfiche = (posH1>posScroll) ? posH1 : posScroll;
	
			fichevariete.css({
					  top: posfiche,
					  left: posleft});/**/
			
			
		
			$.ajax({
				url: 'fiche_variete.php?id='+id,
				success: function(data) {
					 fichevariete.html(data);
					// alert('Load was performed.');
					}
				});
	}
	
function afficher_infos_fiche(id)
	{			
	
			fermer_fiche();
			$('body').append('<div class="fichevariete" id="fichevariete"></div>');
			
			var fichevariete = $('.fichevariete');
			
			var posScroll = parseInt($(document).scrollTop())+25;	
	
			var h1 = $("h1:first");
			var offset = h1.offset();
			var posleft = offset.left;
			
			var posH1 = Math.round(offset.top)-150;
			
				
			var posfiche = (posH1>posScroll) ? posH1 : posScroll;
	
			fichevariete.css({
					  top: posfiche,
					  left: posleft});/**/
			
			
		
			$.ajax({
				url: 'fiche_variete.php?id='+id+"&masquerpanier",
				success: function(data) {
					 fichevariete.html(data);
					// alert('Load was performed.');
					}
				});
	}

function fermer_fiche()
	{	
			$('.fichevariete').remove();
	}



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)
	{
		
	$.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('Load was performed.');
  			}
		});		
	}


function ajouter_article(id)
	{
   	$('#titrecold').html('<span class="rouge"><strong>Mise &agrave; jour du panier...</strong></span>');	
	$.ajax({
  		url: 'inc/xhr/panier_cold.inc.php?id='+id,
  		success: function(data) {
   			 $('#panier').html(data);
			 //alert(data);
    		// alert('Load was performed.');
  			}
		});
	}

function prix_formate(prix)
	{
	prix = Math.round(prix*100)/100;
		
	dec = prix - Math.round(prix);	
	
	if(dec==0)
		return prix + '.00';
	else
		{
		dec2 = 	Math.round(100*dec)/10
		//alert(dec2);
		dec = dec2 - Math.round(dec2);
		//alert(prix+'->'+dec)
			if(dec==0)
				return prix + '0';	
			else
				return prix;
		}
		
	}




function calculer_bc_rev()
	{
	total = 0;
		
	$(".q_bc_rev").each(function () {
								  
				
			id = $(this).attr("id");				
			idnum = id.substr(1,15)				  
			$('#totalligne'+idnum).html("&nbsp;");
								  
		quantite = $(this).val();
		if(quantite>20)
				{
				quantite = 20;
				$(this).val('20');
				alert('Quantité maximum par article : 20');
				}
								  
		if(quantite>0)
		
			{
			
			
				
			
			prix = $('#p'+idnum).val();
			
			//alert(prix+' - '+quantite);
			
			totalL = quantite*prix;
			
			total += 1*totalL;
			
			$('#totalligne'+idnum).html(prix_formate(totalL));
			
			}
	
	
	});
	
	
			$('#totalHT').html(prix_formate(total));
		
	}
	
function valid_quantite(value,id_maj,coldroite)
	{
	
		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_501.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_501.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_501.php&corp=client_panier&useraction=ajout_ref&ref="+ref;
		
	}
	
function check_statut(statut)
	{
	
	if(statut=="particulier" || statut=="")
		$('#liggne_rs').hide();
	else
		$('#liggne_rs').show();
	
	}
	
function check_pro(statut)
	{
	
		$('.ligne_pro').each(function () {
											$(this).hide();})
			
	if(statut=="R")
		{
		$('#lignesiret').show();
		$('#lignetva').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();
	}
	

	
	/*jslint browser: true */ /*global jQuery: true */

/**
* jQuery Cookie plugin
*
* Copyright (c) 2010 Klaus Hartl (stilbuero.de)
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
*/

// TODO JsDoc

/**
* Create a cookie with the given key and value and other optional parameters.
*
* @example $.cookie('the_cookie', 'the_value');
* @desc Set the value of a cookie.

* @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
* @desc Create a cookie with all available options.

* @example $.cookie('the_cookie', 'the_value');
* @desc Create a session cookie.

* @example $.cookie('the_cookie', null);
* @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
* used when the cookie was set.
*
* @param String key The key of the cookie.
* @param String value The value of the cookie.
* @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
* @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
* If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
* If set to null or omitted, the cookie will be a session cookie and will not be retained
* when the the browser exits.
* @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
* @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
* @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
* require a secure protocol (like HTTPS).
* @type undefined
*
* @name $.cookie
* @cat Plugins/Cookie
* @author Klaus Hartl/klaus.hartl@stilbuero.de
*/

/**
* Get the value of a cookie with the given key.
*
* @example $.cookie('the_cookie');
* @desc Get the value of a cookie.
*
* @param String key The key of the cookie.
* @return The value of the cookie.
* @type String
*
* @name $.cookie
* @cat Plugins/Cookie
* @author Klaus Hartl/klaus.hartl@stilbuero.de
*/
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;
};
