// JavaScript Document
function getXhr(){ 
	var xhr = null;  
	if(window.XMLHttpRequest)  
		xhr = new XMLHttpRequest();  
	else if(window.ActiveXObject){  
		try {
			xhr = new ActiveXObject("Msxml2.XMLHTTP"); 
		} catch (e) {  
				xhr = new ActiveXObject("Microsoft.XMLHTTP"); 
		} 
	} else {
		alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");  
		xhr = false;  
	}  
	return xhr; 
} 

/* function maj_fav(nom, val){ */
function maj_fav(id, etat){
	var xhr = getXhr(); 
	xhr.onreadystatechange = function(){ 
		if(xhr.readyState == 4 && xhr.status == 200){ 
			/*document.getElementById('Resultat').innerHTML = xhr.responseText;*/ 
			if(etat==0) {
				document.getElementById('s'+id).src='images/coeur_vide.gif';
				document.getElementById('a'+id).href='javascript:maj_fav('+id+',1)';
			} else {
				document.getElementById('s'+id).src='images/coeur_plein.gif';
				document.getElementById('a'+id).href='javascript:maj_fav('+id+',0)';
			}

			
        } 
    } 
 
	xhr.open("POST","casecochee.php",true); 
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=iso-8859-1'); 
	xhr.send("id="+id+"&etat="+etat);         
} 

/* function maj_shop_fav(nom, val){ */
function maj_shop_fav(id, etat){
	var xhr = getXhr(); 
	xhr.onreadystatechange = function(){ 
		if(xhr.readyState == 4 && xhr.status == 200){ 
			/*document.getElementById('Resultat').innerHTML = xhr.responseText;*/ 
			if(etat==0) {
				document.getElementById('s2'+id).src='images/etoile_vide.png';
				document.getElementById('a2'+id).href='javascript:maj_shop_fav('+id+',1)';
				document.location.reload(true);
			} else {
				document.getElementById('s2'+id).src='images/etoile_pleine.png';
				document.getElementById('a2'+id).href='javascript:maj_shop_fav('+id+',0)';
			}

			
        } 
    } 
 
	xhr.open("POST","caseshopcochee.php",true); 
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=iso-8859-1'); 
	xhr.send("id="+id+"&etat="+etat);         
} 



function montre(id) {
		document.getElementById('sscat_'+id).style.display='block';
}

function cache(id) {
		document.getElementById('sscat_'+id).style.display='none';
}



function maj_march(){
	sel = document.getElementById('search_exp');
	idmarc = sel.options[sel.selectedIndex].value;
	
		var xhr = getXhr(); 
		xhr.onreadystatechange = function(){ 
			if(xhr.readyState == 4 && xhr.status == 200){ 
				leselect = xhr.responseText;
				// On se sert de innerHTML pour rajouter les options a la liste
				document.getElementById('rech_av_marc').innerHTML = leselect;
	
			} 
		} 
	 
		xhr.open("POST","aj_marque.php",true); 
		xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=iso-8859-1');
		sel = document.getElementById('search_cat');
		idcat = sel.options[sel.selectedIndex].value;
		sel = document.getElementById('search_exp');
		idmarc = sel.options[sel.selectedIndex].value;

		xhr.send("idcat="+idcat+"&idmarc="+idmarc);
} 

function maj_cat(){
	sel = document.getElementById('search_cat');
	idcat = sel.options[sel.selectedIndex].value;
		var xhr = getXhr(); 
		xhr.onreadystatechange = function(){ 
			if(xhr.readyState == 4 && xhr.status == 200){ 
				leselect = xhr.responseText;
				// On se sert de innerHTML pour rajouter les options a la liste
				document.getElementById('rech_av_cat').innerHTML = leselect;
	
			} 
		} 
	 
		xhr.open("POST","aj_cat.php",true); 
		xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=iso-8859-1');
		sel = document.getElementById('search_exp');
		idmarc = sel.options[sel.selectedIndex].value;
		sel = document.getElementById('search_cat');
		idcat = sel.options[sel.selectedIndex].value;

		xhr.send("idmarc="+idmarc+"&idcat="+idcat);
} 

function popup(url) {
  propriete = "top=0,left=0,resizable=yes, toolbar=no, scrollbars=yes, menubar=no, location=no, statusbar=no"
  propriete += ",width=" + screen.width + ",height=" + screen.height;
  win = window.open(url,"fenetre", propriete)
}
