
function lock_products(pid)
  	{
	agent.call('','lock_products','lock_products_return', pid);
	}

function lock_products_return(str) {
	document.getElementById('cartcontent').innerHTML = str;
	}	

function update_secteurs()
  	{
	agent.call('','find_criteres_dependance','update_secteurs_return', document.quick_find.C_65.value);
	}

function update_secteurs_return(str) {
	document.getElementById('show_secteurs').innerHTML = str;
	}

function update_ville(agence)
  	{
	agent.call('','find_ville','update_ville_return', agence);
	}

function update_ville_return(str) {
	document.getElementById('show_ville').innerHTML = str;
	}

///////////////// PARTIE LOCATION ////////////////	

/**************************/	
function calendrier_disponibilite(annee, mois,products)
  	{
	document.getElementById('loader').style.display = "block";	
	document.getElementById('loader').style.visibility = "visible";	
	document.getElementById('calendrier_disponibilite').style.display = "none";
	document.getElementById('calendrier_disponibilite').style.visibility = "hidden";	
  	agent.call('','calendrier_disponibilite','update_calendrier_disponibilite',annee, mois, products);
	}
	
function calendrier_disponibilite_autre(products)
  	{
	document.getElementById('loader').style.display = "block";	
	document.getElementById('loader').style.visibility = "visible";	
	document.getElementById('calendrier_disponibilite').style.display = "none";
	document.getElementById('calendrier_disponibilite').style.visibility = "hidden";		
	agent.call('','calendrier_disponibilite','update_calendrier_disponibilite', document.cal_product.liste_annee.value, document.cal_product.liste_mois.value, products);
	}

function update_calendrier_disponibilite(str)
	{
	document.getElementById('loader').style.display = "none";	
	document.getElementById('loader').style.visibility = "hidden";	
	document.getElementById('calendrier_disponibilite').style.display = "block";
	document.getElementById('calendrier_disponibilite').style.visibility = "visible";	
	document.getElementById('calendrier_disponibilite').innerHTML = str;
	}	
	
function modif_date(jour,mois,annee)
{
	
	
	
		if(debutfin==0)
		{
			document.period_search.date_debut.value=jour+"/"+mois+"/"+annee;
					
			if(jour<10)
			document.period_search.date_debut.value="0"+jour+"/"+mois+"/"+annee;
		
			if(mois<10)
			document.period_search.date_debut.value=jour+"/0"+mois+"/"+annee;
	
			if((jour<10)&&(mois<10))
			document.period_search.date_debut.value="0"+jour+"/0"+mois+"/"+annee;
			
			debutfin=1;
			
		}else{
			
			document.period_search.date_fin.value=jour+"/"+mois+"/"+annee;
		
			if(jour<10)
			document.period_search.date_fin.value="0"+jour+"/"+mois+"/"+annee;
		
			if(mois<10)
			document.period_search.date_fin.value=jour+"/0"+mois+"/"+annee;
	
			if((jour<10)&&(mois<10))
			document.period_search.date_fin.value="0"+jour+"/0"+mois+"/"+annee;
			
			debutfin=0;
		}
		
		
		efface_tarif_location();
}

function efface_tarif_location()
{
		affiche_bouton_reservation_return("");
		if((!isDate(document.period_search.date_debut.value))||(!isDate(document.period_search.date_fin.value)))
			alert("Veuillez saisir une date correcte!");
		
		
		document.getElementById('liste_des_forfaits').innerHTML = "";
		
}

function isDate(d) {
 // Cette fonction permet de vérifier la validité d'une date au format jj/mm/aa ou jj/mm/aaaa
 // Par Romuald

 if (d == "") // si la variable est vide on retourne faux
 return false;

 e = new RegExp("^[0-9]{1,2}\/[0-9]{1,2}\/([0-9]{2}|[0-9]{4})$");

 if (!e.test(d)) // On teste l'expression régulière pour valider la forme de la date
 return false; // Si pas bon, retourne faux

 // On sépare la date en 3 variables pour vérification, parseInt() converti du texte en entier
 j = parseInt(d.split("/")[0], 10); // jour
 m = parseInt(d.split("/")[1], 10); // mois
 a = parseInt(d.split("/")[2], 10); // année

 // Si l'année n'est composée que de 2 chiffres on complète automatiquement
 if (a < 1000) {
 if (a < 89) a+=2000; // Si a < 89 alors on ajoute 2000 sinon on ajoute 1900
 else a+=1900;
 }

 // Définition du dernier jour de février
 // Année bissextile si annnée divisible par 4 et que ce n'est pas un siècle, ou bien si divisible par 400
 if (a%4 == 0 && a%100 !=0 || a%400 == 0) fev = 29;
 else fev = 28;

 // Nombre de jours pour chaque mois
 nbJours = new Array(31,fev,31,30,31,30,31,31,30,31,30,31);

 // Enfin, retourne vrai si le jour est bien entre 1 et le bon nombre de jours, idem pour les mois, sinon retourn faux
 return ( m >= 1 && m <=12 && j >= 1 && j <= nbJours[m-1] );
 } 

/************LISTE DES TARIFS**************/	
function affiche_liste_tarifs(products)
	{
		agent.call('','affiche_liste_tarifs','affiche_liste_tarifs_return', document.period_search.date_debut.value, document.period_search.date_fin.value,document.period_search.heure_debut.value, document.period_search.heure_fin.value, products);
		
	}

function affiche_liste_tarifs_return(str1)
	{
		var pos = str1.indexOf('a', 0);
		var str = str1.substr(pos,str1.length-pos);
	
		var res = str.substr(1,12);
		res = parseInt(res);
		
		document.getElementById('liste_des_forfaits').innerHTML = str.substr(12,str.length-12);
		
		if(res == 1)
		affiche_bouton_reservation()
		
	}	
	

	
/************* BOUTON RESERVATION *************/		
function affiche_bouton_reservation()
	{
	agent.call('','affiche_bouton_reservation','affiche_bouton_reservation_return');
	}
	
function affiche_bouton_reservation_return(str)
	{
	document.getElementById('bouton_reservation').innerHTML = str;
	}
	
///////////////// PARTIE LISTE DES COURSES ////////////////	

function affiche_liste_produits(categories)
	{
	agent.call('','affiche_liste_produits','affiche_liste_produits_return',categories);
	agent.call('','affiche_nom_rayon','affiche_nom_rayon_return',categories);
	}

function affiche_nom_rayon_return(str)
	{
	document.getElementById('nom_rayon').innerHTML = str;
	}
		
function affiche_liste_produits_return(str)
	{
	document.getElementById('liste_produits').innerHTML = str;
	}


function affiche_liste_courses()
	{
	agent.call('','affiche_liste_courses','affiche_liste_courses_return',document.le_formulaire.e_mail.value);
	}
	
function affiche_liste_courses_return(str)
	{
	document.getElementById('liste_courses').innerHTML = str;
	}

function ajouter_courses(products)
	{
		if(document.le_formulaire.e_mail.value=="")
		{alert("Veuillez saisir votre e-mail!");
			
		}else{
			agent.call('','ajouter_courses','ajouter_courses_return',document.le_formulaire.e_mail.value,products);
		}
	}
	
function ajouter_courses_return(str)
	{
	document.getElementById('liste_courses').innerHTML = str;
	}
	
function supprimer_courses(products)
	{
		if(document.le_formulaire.e_mail.value=="")
		{alert("Veuillez saisir votre e-mail!");
			
		}else{
			agent.call('','supprimer_courses','supprimer_courses_return',document.le_formulaire.e_mail.value,products);
		}
	}
	
function supprimer_courses_return(str)
	{
	document.getElementById('liste_courses').innerHTML = str;
	}
	
	
//----------------------------------------------------------------------------------

  var requests_running = 0;
  function products_listing_update() {
   var intY = parseInt(document.getElementById("products_listing").scrollTop);
   var hauteur = parseInt(document.getElementById("products_listing").scrollHeight );
   if ( (intY > (hauteur * 0.10)) && (requests_running == 0) )
   		{
   		requests_running = 1;
   		document.products_lock.pageactuelle.value = parseInt(document.products_lock.pageactuelle.value) + 1;
   		if (parseInt(document.products_lock.pageactuelle.value) <= parseInt(document.products_lock.pagemax.value))
   			{
   			agent.call('','products_listing_update','products_listing_receive', document.products_lock.pageactuelle.value);
   			}
		}
  }

//----------------------------------------------------------------------------------
  function products_listing_receive(str) {
 	var str2 = document.getElementById('products_listing').innerHTML;
    document.getElementById('products_listing').innerHTML = str2.substr(0, str2.length-8) + str;
    requests_running = 0;
   	}


//----------------------------------------------------------------------------------

  function test(type) {
   		if (type == "liste")
   			agent.call('','products_listing','test_return');
   		else if (type = "map")
   			agent.call('','map_listing','test_return');
  }
function test_return(str)
	{
	alert(str);
	document.getElementById('map_listing').innerHTML = str;
	}





//////////////// PARTIE CATEGORIE OFFICE ///////////////////////	
	
  function update_models_advanced_search(cpath, form)
  	  {
//	  alert(cpath);
      agent.call('','get_models_auto_array','update_models_return_advanced_search', cpath, true, form);
	  }

  function update_models_return_advanced_search(str)
	  {
//	  alert('retour');
	  document.getElementById('show_model_advanced_search').innerHTML = str;
	  }	

  function update_models_quick_find(cpath, form, afficher_version)
  	  {
      agent.call('','get_models_auto_array','update_models_return_quick_find', cpath, true, form, afficher_version);
	  }

  function update_models_return_quick_find(str)
	  {
		document.getElementById('show_model_quick_find').innerHTML = str;
	  }	

  function show_count(cpath, C_1004)
  	  {
      agent.call('','show_count','show_count_return', cpath, C_1004);
	  }

  function show_count_return(str)
	  {
		document.getElementById('show_count_quick_find').innerHTML = str;
	  }	

  function update_models_goto(cpath, form)
  	  {
      agent.call('','get_models_auto_array','update_models_return_goto', cpath, 'false', form);
	  }

  function update_models_return_goto(str)
	  {
		document.getElementById('show_model_goto').innerHTML = str;
	  }	
	  
	  
///////////////// PARTIE MOTEUR DE RECHERCHE CUSTOMERS OFFICE ////////////////	
	
	
  function update_models_search_form(cpath,form)
  	  {
      agent.call('','get_models_auto_array','update_models_return_search_form', cpath,form);
	  }

  function update_models_return_search_form(str)
	  {
		document.getElementById('show_model_search_form').innerHTML = str;
	  }	

  function update_info(value)
  	  {
  	  if (value != "undefined")
	  value = document.manufacturers_info.coordonnees.value;
	  
	  document.getElementById('photo_agence').innerHTML = '<img src="../office/maisonrouge/catalog/images/agence_' + value + '.jpg" width="210" height="175">';
      agent.call('','select_manufacturer_info','update_info_return', value);
	  }
  function update_info_return(str)
	  {
		document.getElementById('manufacturers_info').innerHTML = str;
	  }	

  function loginzone(products_id)
  	  {
      agent.call('','loginzone','loginzone_return', products_id);
	  }

  function loginzone_return(str)
	  {
		document.getElementById('login_zone').innerHTML = str;
	  }
	  
function lostFocus()
	{
	if(document.getElementById('display_country').style.display == "block")
		{
		if(document.getElementById('select_country').selectedIndex>-1)
			{				
			document.getElementById('C_65').value = document.getElementById('select_country').options[document.getElementById('select_country').selectedIndex].value;			
			}
		}		
	}

function suggereListeVille(valeur)
	{		
	if(valeur.length>=3)
		{
		agent.call('','suggest_country_ajax','suggest_country_ajax_return',valeur);	
		}
	}	

function suggereListeVille2(valeur)
	{		
	if(valeur.length>=3)
		{
		agent.call('','suggest_country_ajax2','suggest_country_ajax_return',valeur);	
		}
	}	

function suggereListeVille3(valeur)
	{		
	if(valeur.length>=3)
		{
		agent.call('','suggest_country_ajax3','suggest_country_ajax_return',valeur);	
		}
	}	

function suggest_country_ajax_return(str)
	{	
	document.getElementById('display_country').style.display = "block";	
	document.getElementById('display_country').innerHTML = str;
	}

function affectValue(selectValue)
	{
	document.getElementById('display_country').style.display = "none";		
	document.getElementById('C_65').value=selectValue;				
	}


  function products_info_fnaim_bzh(products_id)
  	  {
     agent.call('','products_info_fnaim_bzh','products_info_fnaim_bzh_return', products_id);
	  }

  function products_info_fnaim_bzh_return(str)
	  {
		var id = str.substr(0,12);
		id = parseInt(id);
		if(id) {
			document.getElementById('annonce_detail_' + id).innerHTML = str.substr(12,str.length-12);
			div_head_detail = document.getElementById('detail_head_'+id);
			div_annonce_detail = document.getElementById('annonce_detail_'+id);
			div_total_annonce = document.getElementById('total_annonce_'+id);
			table_annonce = document.getElementById('table_annonce_'+id);
			//div_detail = document.getElementById(id);
			display(div_head_detail);
			display(div_annonce_detail);
			nodisplay(id);
			//display(div_total_annonce);
			table_annonce.style.border=0;
			table_annonce.style.width="570px";
			//table_annonce.style.borderBottom="#aaa 2px dotted";
			div_total_annonce.style.border="#abd601 2px solid";
			div_total_annonce.style.backgroundColor="#f7fbd7";
			var nbx;
			nbx = document.getElementById('x'+id);
			var name = nbx.src;
			var end_name = name.substring(name.length-8 , name.length);
			
			if (name.substring(name.length-8 , name.length) == 'plus.gif') {
				nbx.src='../office/fnaim-bretagne/catalog/images/savoir_moins.gif';
			} else {
				nbx.src='../office/fnaim-bretagne/catalog/images/savoir_plus.gif';
			}
	tb_init('a.thickbox, area.thickbox, input.thickbox');//pass where to apply thickbox
		}
	  }
