// JavaScript Document

function showLoading(zone) {
	//alert ("showLoading " +zone);
	document.getElementById(zone).innerHTML = '<img src="/images/loading_small.gif" />'
}

function resetMarques() {
		document.getElementById('marque').value='';
		document.getElementById('nom_marque').value='Tapez un nom de marque';
		// document.getElementById('refresh_marque').innerHTML = '<select class="recherche" name="marque" id="marque"><option value="">--</option></select>';
}

function resetKeywords() {
		document.getElementById('id_societe').value='';
		document.getElementById('keywords').value='Tapez le nom du grossiste';
}
function showmore(id,first,letter) {
	//alert("letter:"+letter);
	var d = document.getElementById(id);
	if (d) {d.style.display='block';}
	if(letter=='ca') {
		document.form1.totalca.value= first ;
		//alert(document.form1.totalca.value);
	}
}
/*
$which_div	= $_GET['which_div'];
$numero 	= $_GET['numero'];
$do_what	= $_GET['do_what'];
zone		= $_GET['zone'];
*/
function add_div(which_div,numero,z) {
	var zone = which_div ;
alert("test");
	if (which_div == 'produitsdeux') {
		// alert(which_div);
		zone = 'produits' ;
		// alert('zone_'+zone+'_'+numero);
	} 
	//alert("im in with values="+which_div+','+numero+','+zone)
	// Création de l'objet
	var XHR = new XHRConnection();
	// Zone a remplir
	XHR.setRefreshArea('zone_'+zone+'_'+numero);
	// Chargement de la page
	XHR.sendAndLoad("add_or_remove_div.php?which_div="+which_div+"&numero="+numero+"&zone="+zone+"&do_what=add", "GET");
	//alert("add_or_remove_div.php?which_div="+which_div+"&numero="+numero+"&zone="+which_div+"do_what=add");

	if(which_div=='responsables') {
		document.form1.totalresponsables.value= numero ;
		//alert(document.form1.totalresponsables.value);
	}
	if(which_div=='agences') {
		document.form1.totalagences.value= numero ;
		//alert(document.form1.totalagences.value);
	}
	if(which_div=='produits' || which_div=='produitsdeux') {
		document.form1.totalproducts.value= numero ;
		//alert(document.form1.totalproducts.value);
	}
	if(which_div=='specialites') {
		document.form1.totalspecialites.value= numero ;
		//alert(document.form1.totalspecialites.value);
	}
	if(which_div=='types_clients') {
		document.form1.totaltypesclients.value= numero ;
		//alert(document.form1.totaltypesclients.value);
	}
	return true;
}
function clear_div (id) {
	//alert(id);
	d = document.getElementById(id);
	d.innerHTML ='';
	//d.style.display='none;'
}

/* cache tous les div a partir de celui identifiés par id+first 
 * ex: id=a8 cache le div a8,a9...a100
 */

function showless(id,first) {

	//alert (document.form1.eval('categorie_'+ first).selectedIndex);
	var d = document.getElementById(id);
	if(id=='r') {
		document.form1.totalresponsables.value= first-1 ;
//		alert(document.form1.totalresponsables.value);
	}
	if(id=='a') {
		document.form1.totalagences.value= first-1 ;
//		alert(document.form1.totalagences.value);
	}
	if(id=='p') {
		document.form1.totalproducts.value= first-1 ;
//		alert(document.form1.totalproducts.value);
	}
	
	if(id=='ca_') {
		document.form1.totalca.value= first-1 ;
//		alert(document.form1.totalca.value);
	}
	if(id=='s') {
		document.form1.totalspecialites.value= first-1 ;
//		alert(document.form1.totalspecialites.value);
	}
	if(id=='t') {
		document.form1.totaltypesclients.value= first-1 ;
		//alert(document.form1.totaltypesclients.value);
	}
	for (var i = first; i<=100; i++) {
		if (document.getElementById(id+i)) {
			document.getElementById(id+i).style.display='none';

			/* Ne fonctionne pas avec IE qui ne gere le selectedIndex qu'en lecture :(
			if(id=='r') {
				document.form1.eval('fonction_'+ i).value='';
				document.form1.eval('emailr_'+ i).value='';
				document.form1.eval('prenom_'+ i).value='';
				document.form1.eval('nom_'+ i).value='';
			}
			if(id=='a') {
				document.form1.eval('ag_'+ i +'_adresse_1').value='';
				document.form1.eval('ag_'+ i +'_adresse_2').value='';
				document.form1.eval('ag_'+ i +'_code_postal').value='';
				document.form1.eval('ag_'+ i +'_ville').value='';
				document.form1.eval('ag_'+ i +'_tel').value='';
				document.form1.eval('ag_'+ i +'_fax').value='';
				document.form1.eval('ag_'+ i +'_email').value='';
				//document.form1.eval('ag_'+ i +'_type').selectedIndex='0';
			}
			if(id=='p') {
				//resetlist('categorie','refresh_categorie_'+i,i);
				//document.form1.eval('categorie_'+ i).selectedIndex=-1;
				//chargeListeProduits(0,i)
				//resetlist('marques','refresh_marque_'+i,i);
				//document.form1.eval('marque_'+ i).selectedIndex=-1;
			}
			*/
		}
	}
}

function show_payant(id,value) {
	document.getElementById(id).style.display=value;
}
function resetCategories(optcat) {

	document.getElementById('refresh_categorie').innerHTML ='<select name="categorie" class="recherche" onchange="chargeListeProduits(this.options[this.selectedIndex].value);resetMarques()" style="float:left;"><option value="0" selected="selected">Catégorie Produits</option>' + unescape(optcat) +'</select>';
	document.getElementById('refresh_type_produit').innerHTML ='<select class="recherche" name="types_produits" id="types_produits"  onchange="resetMarques();resetKeywords;"style="float:left;"><option value="">--</option></select>';
	
}
function resetSpecialites() {
	var XHR = new XHRConnection();
	// Zone a remplir
	XHR.setRefreshArea('refresh_specialite');
	// Chargement de la page
	XHR.sendAndLoad("show_specialites.php", "GET");
	return true;
	
}

function chargeListeProduits(id) {

	if (id=='none') {
		return false;
	} else {
	//alert("im in with value="+id)
	// Création de l'objet
	showLoading('refresh_type_produit');
	var XHR = new XHRConnection();
	// Zone a remplir
	XHR.setRefreshArea('refresh_type_produit');
	// Chargement de la page
	XHR.sendAndLoad("show_types_produits_by_categorie.php?id="+id, "GET");
	resetSpecialites()
	return true;
	}
}

function chargeListeMarques(id) {
	if (id=='none') {
		return false;
	} else {
	showLoading('refresh_marque');
	//alert("im in with value="+id)
	// Création de l'objet
	var XHR = new XHRConnection();
	// Zone a remplir
	XHR.setRefreshArea('refresh_marque');
	// Chargement de la page
	XHR.sendAndLoad("show_marques_by_types_produits.php?id="+id, "GET");
	return true;
	}
}

function sorry() {
	alert ("Bientôt disponible ! ");
}
