//FUNCTION AJAX XHR enable
function getXhr(){
			var xhr = null; 
			if(window.XMLHttpRequest) // Firefox et autres
				xhr = new XMLHttpRequest(); 
				else if(window.ActiveXObject){ // Internet Explorer 
				   try {
			                xhr = new ActiveXObject("Msxml2.XMLHTTP");
			            } catch (e) {
			                xhr = new ActiveXObject("Microsoft.XMLHTTP");
			            }
				}
				else { // XMLHttpRequest non supporté par le navigateur 
				   alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
				   xhr = false; 
				} 
    return xhr;
}


var Inclus_Slimbox = function(){
	var source_script = '';
	$(document.html).getElements('script').each(function(item){
		source_script = item.src;
		// si trouve slimbox le supprimer
		if(source_script.search('slimbox.js')!= -1){
			item.dispose();
		}
	});
	//injecter slimbox:
	var myScript = new Asset.javascript('js/slimbox.js');
}

//Function ShowThisBox
function ShowThisBox(id){
	document.getElementById(id).style.display='block';
	}

//Function HideThisBox
function HideThisBox(id){
	document.getElementById(id).style.display='none';
	}

//Function HideThisBox
function ClosePanier(){
	document.getElementById('AjaxPanier').style.display='none';
	document.getElementById('AjaxPanierTrans').style.display='none';
	}


//Function NextGamme
function MoveGamme(sens,lang){
				var xhr = getXhr();
				xhr.onreadystatechange = function(){
					if(xhr.readyState == 4 && xhr.status == 200){
					document.getElementById('GammesAjax').innerHTML = xhr.responseText;
					}
				}
				xhr.open("POST", "Ajax/Ajax_MoveGamme.php",true);
				xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
				xhr.send("sens="+sens+"&lang="+lang);
}

//Function MoveSpecifique
function MoveSpecifique(sens,SpecId,lang){
				var xhr = getXhr();
				xhr.onreadystatechange = function(){
				if(xhr.readyState == 4 && xhr.status == 200){
					document.getElementById('SpecAjax_'+SpecId).innerHTML = xhr.responseText;
					Inclus_Slimbox();
					}
				}
				xhr.open("POST", "Ajax/Ajax_MoveSpecifique.php",true);
				xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
				xhr.send("sens="+sens+"&lang="+lang+"&SpecId="+SpecId);
}

//Function change actu
function ChangeActuPage(limit,lang){
				var xhr = getXhr();
				xhr.onreadystatechange = function(){
					if(xhr.readyState == 4 && xhr.status == 200){
						document.getElementById('AjaxActu').innerHTML = xhr.responseText;
					}
				}
				xhr.open("POST", "Ajax/ChangeActuPage.php",true);
				xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
				xhr.send("limit="+limit+"&lang="+lang);
}

//Function change GammePro
function ChangePro(id,lang,univ){
				var xhr = getXhr();
				xhr.onreadystatechange = function(){
					if(xhr.readyState == 4 && xhr.status == 200){
						document.getElementById('Ajax').innerHTML = xhr.responseText;
					}
				}
				xhr.open("POST", "Ajax/Ajax_ProGamme.php",true);
				xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
				xhr.send("id="+id+"&lang="+lang+"&univ="+univ);
}

//Function PanierAjax
function PanierAjax(pid){
	ShowThisBox('AjaxPanierTrans');
	ShowThisBox('AjaxPanier');
	var xhr = getXhr();
		xhr.onreadystatechange = function(){
			if(xhr.readyState == 4 && xhr.status == 200){
				window.scrollTo(0,0);
				document.getElementById('AjaxPanierTxt').innerHTML = xhr.responseText;
			}
		}	
	xhr.open("POST", "Ajax/Ajax_ChoixPanier.php",true);
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr.send("pid="+pid);
}

//Function change GammePro
function AddPanier(pid){
				var xhr = getXhr();
				xhr.onreadystatechange = function(){
					if(xhr.readyState == 4 && xhr.status == 200){
						document.getElementById('panier').innerHTML = xhr.responseText;
						PanierAjax(pid);
					}
				}
				xhr.open("POST", "Ajax/Ajax_Panier.php",true);
				xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
				xhr.send("pid="+pid);
}


//Function UpdatePanier 
function UpdatePanier(pid,quantity,act){
				var xhr = getXhr();
				xhr.onreadystatechange = function(){
					if(xhr.readyState == 4 && xhr.status == 200){
						document.getElementById('panier').innerHTML = xhr.responseText;
						if(act=='Continuer'){
							ClosePanier();
							}else{
							document.location.replace('votre-panier_pan_57_fr.html');
							}
					}
				}
				xhr.open("POST", "Ajax/Ajax_Panier.php",true);
				xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
				xhr.send("pid="+pid+"&quantity="+quantity);
}

//Function change GammePro
function RazPanier(){
				var xhr = getXhr();
				xhr.onreadystatechange = function(){
					if(xhr.readyState == 4 && xhr.status == 200){
						window.location.reload();
				}
			}
		xhr.open("POST", "Ajax/Ajax_ViderPanier.php",true);
		xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		xhr.send("test");
}

//Function Suppr Objet Panier
function SupprPrd(id){
				var xhr = getXhr();
				xhr.onreadystatechange = function(){
					if(xhr.readyState == 4 && xhr.status == 200){
						window.location.reload();
				}
			}
		xhr.open("POST", "Ajax/Ajax_SupprObjetPanier.php",true);
		xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		xhr.send("SupprId="+id);
}

//Function Maj Quantity
function AddQ(id,PlusMoins){
		if(PlusMoins=='+'){
			if(document.getElementById(id).value=='999'){ return; } else { document.getElementById(id).value++; }
			} else {
			if(document.getElementById(id).value=='1'){ return; } else { document.getElementById(id).value--; }
		}
}

