/* Fichiers de scripts pour le shop */

/* Fonctions communes à toutes les rubriques */

/* Fonctions de l'accueil */
function rechercheArticle(kw)
{
	if(kw=='')
		document.location.replace(".?rubrique=accueil");
	else
	{
		var span_object = document.getElementById("span_resultat");
		var xhr_object = null;

		if(window.XMLHttpRequest)
			xhr_object = new XMLHttpRequest();
		else if(window.ActiveXObject)
			xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
		else
			return;
		
		xhr_object.open("GET", "../scripts-shop/recherche_article.php?kw="+kw, false);
		xhr_object.send(null); 
		
		if(xhr_object.readyState == 4) { span_object.innerHTML=xhr_object.responseText; }
	}
}

function rechercheArticle2(kw,p)
{
	if(kw=='')
		document.location.replace(".?rubrique=accueil");
	else
	{
		var span_object = document.getElementById("span_resultat");
		var xhr_object = null;

		if(window.XMLHttpRequest)
			xhr_object = new XMLHttpRequest();
		else if(window.ActiveXObject)
			xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
		else
			return;
		
		xhr_object.open("GET", "../scripts-shop/recherche_article2.php?kw="+kw+"&p="+p, false);
		xhr_object.send(null); 
		
		if(xhr_object.readyState == 4) { span_object.innerHTML=xhr_object.responseText; }
	}
}

function rechercheDvd2(kw,p)
{
	if(kw=='')
		document.location.replace(".?rubrique=dvd");
	else
	{
		var span_object = document.getElementById("span_resultat");
		var xhr_object = null;

		if(window.XMLHttpRequest)
			xhr_object = new XMLHttpRequest();
		else if(window.ActiveXObject)
			xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
		else
			return;
		
		xhr_object.open("GET", "../scripts-shop/recherche_dvd2.php?kw="+kw+"&p="+p, false);
		xhr_object.send(null); 
		
		if(xhr_object.readyState == 4) { span_object.innerHTML=xhr_object.responseText; }
	}
}
function rechercheCd2(kw,p)
{
	if(kw=='')
		document.location.replace(".?rubrique=cd");
	else
	{
		var span_object = document.getElementById("span_resultat");
		var xhr_object = null;

		if(window.XMLHttpRequest)
			xhr_object = new XMLHttpRequest();
		else if(window.ActiveXObject)
			xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
		else
			return;
		
		xhr_object.open("GET", "../scripts-shop/recherche_cd2.php?kw="+kw+"&p="+p, false);
		xhr_object.send(null); 
		
		if(xhr_object.readyState == 4) { span_object.innerHTML=xhr_object.responseText; }
	}
}
function rechercheVinyl2(kw,p)
{
	if(kw=='')
		document.location.replace(".?rubrique=vinyl");
	else
	{
		var span_object = document.getElementById("span_resultat");
		var xhr_object = null;

		if(window.XMLHttpRequest)
			xhr_object = new XMLHttpRequest();
		else if(window.ActiveXObject)
			xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
		else
			return;
		
		xhr_object.open("GET", "../scripts-shop/recherche_vinyl2.php?kw="+kw+"&p="+p, false);
		xhr_object.send(null); 
		
		if(xhr_object.readyState == 4) { span_object.innerHTML=xhr_object.responseText; }
	}
}
function rechercheMerch2(kw,p)
{
	if(kw=='')
		document.location.replace(".?rubrique=merch");
	else
	{
		var span_object = document.getElementById("span_resultat");
		var xhr_object = null;

		if(window.XMLHttpRequest)
			xhr_object = new XMLHttpRequest();
		else if(window.ActiveXObject)
			xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
		else
			return;
		
		xhr_object.open("GET", "../scripts-shop/recherche_merch2.php?kw="+kw+"&p="+p, false);
		xhr_object.send(null); 
		
		if(xhr_object.readyState == 4) { span_object.innerHTML=xhr_object.responseText; }
	}
}
function rechercheCustom2(kw,p)
{
	if(kw=='')
		document.location.replace(".?rubrique=custom");
	else
	{
		var span_object = document.getElementById("span_resultat");
		var xhr_object = null;

		if(window.XMLHttpRequest)
			xhr_object = new XMLHttpRequest();
		else if(window.ActiveXObject)
			xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
		else
			return;
		
		xhr_object.open("GET", "../scripts-shop/recherche_custom2.php?kw="+kw+"&p="+p, false);
		xhr_object.send(null); 
		
		if(xhr_object.readyState == 4) { span_object.innerHTML=xhr_object.responseText; }
	}
}
function recherchePromo2(kw,p)
{
	if(kw=='')
		document.location.replace(".?rubrique=promo");
	else
	{
		var span_object = document.getElementById("span_resultat");
		var xhr_object = null;

		if(window.XMLHttpRequest)
			xhr_object = new XMLHttpRequest();
		else if(window.ActiveXObject)
			xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
		else
			return;
		
		xhr_object.open("GET", "../scripts-shop/recherche_promo2.php?kw="+kw+"&p="+p, false);
		xhr_object.send(null); 
		
		if(xhr_object.readyState == 4) { span_object.innerHTML=xhr_object.responseText; }
	}
}
function rechercheFrancais2(kw,p)
{
	if(kw=='')
		document.location.replace(".?rubrique=francais");
	else
	{
		var span_object = document.getElementById("span_resultat");
		var xhr_object = null;

		if(window.XMLHttpRequest)
			xhr_object = new XMLHttpRequest();
		else if(window.ActiveXObject)
			xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
		else
			return;
		
		xhr_object.open("GET", "../scripts-shop/recherche_francais2.php?kw="+kw+"&p="+p, false);
		xhr_object.send(null); 
		
		if(xhr_object.readyState == 4) { span_object.innerHTML=xhr_object.responseText; }
	}
}



function rechercheDvd(kw, l, p, nb)
{
	if(kw=='' && l=='')
		document.location.replace(".?rubrique=dvd");
	else
	{
		var span_object = document.getElementById("span_resultat");
		var xhr_object = null;

		if(window.XMLHttpRequest)
			xhr_object = new XMLHttpRequest();
		else if(window.ActiveXObject)
			xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
		else
			return;
		
		xhr_object.open("GET", "../scripts-shop/recherche_dvd.php?kw="+kw+"&label="+l+"&p="+p+"&nb="+nb, false);
		xhr_object.send(null); 
		
		if(xhr_object.readyState == 4) { span_object.innerHTML=xhr_object.responseText; }
	}
}

function rechercheCd(kw, l, s, p, nb)
{
	if(kw=='' && l=='' && s=='')
		document.location.replace(".?rubrique=cd");
	else
	{
		var span_object = document.getElementById("span_resultat");
		var xhr_object = null;

		if(window.XMLHttpRequest)
			xhr_object = new XMLHttpRequest();
		else if(window.ActiveXObject)
			xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
		else
			return;
		
		xhr_object.open("GET", "../scripts-shop/recherche_cd.php?kw="+kw+"&label="+l+"&style="+s+"&p="+p+"&nb="+nb, false);
		xhr_object.send(null); 
		
		if(xhr_object.readyState == 4) { span_object.innerHTML=xhr_object.responseText; }
	}
}

function rechercheVinyl(kw, l, s, p, nb)
{
	if(kw=='' && l=='' && s=='')
		document.location.replace(".?rubrique=vinyl");
	else
	{
		var span_object = document.getElementById("span_resultat");
		var xhr_object = null;

		if(window.XMLHttpRequest)
			xhr_object = new XMLHttpRequest();
		else if(window.ActiveXObject)
			xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
		else
			return;
		
		xhr_object.open("GET", "../scripts-shop/recherche_vinyl.php?kw="+kw+"&label="+l+"&style="+s+"&p="+p+"&nb="+nb, false);
		xhr_object.send(null); 
		
		if(xhr_object.readyState == 4) { span_object.innerHTML=xhr_object.responseText; }
	}
}

function rechercheMerch(kw, t, p, nb)
{
	if(kw=='' && t=='')
		document.location.replace(".?rubrique=merch");
	else
	{
		var span_object = document.getElementById("span_resultat");
		var xhr_object = null;

		if(window.XMLHttpRequest)
			xhr_object = new XMLHttpRequest();
		else if(window.ActiveXObject)
			xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
		else
			return;
		
		xhr_object.open("GET", "../scripts-shop/recherche_merch.php?kw="+kw+"&type="+t+"&p="+p+"&nb="+nb, false);
		xhr_object.send(null); 
		
		if(xhr_object.readyState == 4) { span_object.innerHTML=xhr_object.responseText; }
	}
}

function recherchePromo(kw)
{
	if(kw=='')
		document.location.replace(".");
	else
	{
		var span_object = document.getElementById("span_resultat");
		var xhr_object = null;

		if(window.XMLHttpRequest)
			xhr_object = new XMLHttpRequest();
		else if(window.ActiveXObject)
			xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
		else
			return;
		
		xhr_object.open("GET", "../scripts-shop/recherche_promo.php?kw="+kw, false);
		xhr_object.send(null); 
		
		if(xhr_object.readyState == 4) { span_object.innerHTML=xhr_object.responseText; }
	}
}

function rechercheCustom(kw)
{
	if(kw=='')
		document.location.replace(".");
	else
	{
		var span_object = document.getElementById("span_resultat");
		var xhr_object = null;

		if(window.XMLHttpRequest)
			xhr_object = new XMLHttpRequest();
		else if(window.ActiveXObject)
			xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
		else
			return;
		
		xhr_object.open("GET", "../scripts-shop/recherche_custom.php?kw="+kw, false);
		xhr_object.send(null); 
		
		if(xhr_object.readyState == 4) { span_object.innerHTML=xhr_object.responseText; }
	}
}

function rechercheFrancais(kw)
{
	if(kw=='')
		document.location.replace(".");
	else
	{
		var span_object = document.getElementById("span_resultat");
		var xhr_object = null;

		if(window.XMLHttpRequest)
			xhr_object = new XMLHttpRequest();
		else if(window.ActiveXObject)
			xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
		else
			return;
		
		xhr_object.open("GET", "../scripts-shop/recherche_francais.php?kw="+kw, false);
		xhr_object.send(null); 
		
		if(xhr_object.readyState == 4) { span_object.innerHTML=xhr_object.responseText; }
	}
}

function checkLogin()
{
	if(document.f_log.f_login.value=="" || document.f_log.f_pass.value=="")
	{
		document.f_log.f_login.value="";
		document.f_log.f_pass.value="";
		document.getElementById("err").className="err_connexion";
		document.getElementById("err").innerHTML="Erreur! Vous devez remplir les 2 champs.";
	}
	else
	{
		var xhr_object = null;
		var l = document.f_log.f_login.value;
		var p = document.f_log.f_pass.value;
		
		if(window.XMLHttpRequest)
			xhr_object = new XMLHttpRequest();
		else if(window.ActiveXObject)
			xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
		else
			return;
		
		xhr_object.open("GET", "../scripts-shop/verif_connexion.php?l="+l+"&p="+p, false);
		xhr_object.send(null); 
		
		if(xhr_object.readyState == 4)
		{
			if(xhr_object.responseText=="err")
			{
				document.f_log.f_login.value="";
				document.f_log.f_pass.value="";
				document.getElementById("err").className="err_connexion";
				document.getElementById("err").innerHTML="Erreur! Mauvaise identification.";
			}
			else
				document.location.replace("index.php?rubrique=mydeadrock");
		}	
	}
}

function newuser(){
	for(i=0;i<document.user.length;i++){
		if(document.user.elements[i].type!="hidden" && document.user.elements[i].type!="checkbox" && document.user.elements[i].type!="password"){
			if(document.user.elements[i].value==""  && document.user.elements[i].title!=""){
				document.getElementById("err").className="Style3";
				document.getElementById("err").innerHTML="Attention. Vous devez remplir le champ "+document.user.elements[i].title+"!";
				document.user.elements[i].focus();
				return;
			}
		}
	}
	
	
	if(document.user.pass1.value!="" || document.user.passwd.value!=""){
		if(document.user.pass1.value!=document.user.passwd.value){
			document.getElementById("err").className="Style3";
			document.getElementById("err").innerHTML="Attention. Vous devez rentrer votre nouveau mot de passe 2 fois!";
			document.user.pass1.value="";
			document.user.passwd.value="";
			document.user.passwd.focus();
			return;
		}
	}
	document.user.submit();
}

function modifuser(){
	for(i=0;i<document.user.length;i++){
		if(document.user.elements[i].type!="hidden" && document.user.elements[i].type!="checkbox" && document.user.elements[i].type!="password"){
			if(document.user.elements[i].value==""  && document.user.elements[i].title!=""){
				alert("Attention. Vous devez remplir le champ "+document.user.elements[i].title+"!");
				document.user.elements[i].focus();
				return;
			}
		}
	}
	document.user.submit();
}


function isUnique()
{
 	var xhr_object = null;
	var l = document.user.login.value;
	
	if(window.XMLHttpRequest)
		xhr_object = new XMLHttpRequest();
	else if(window.ActiveXObject)
		xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
	else
		return;
	
	xhr_object.open("GET", "../scripts-shop/unicite_mail.php?l="+l, false);
	xhr_object.send(null); 
	
	if(xhr_object.readyState == 4)
	{
		if(xhr_object.responseText=="err")
		{
			document.user.login.value="";
			document.getElementById("err").className="Style3";
			document.getElementById("err").innerHTML="Attention. Cette email est déjà utilisé!";
			document.user.login.submit();
		}
	}	

}

function sendPasswd()
{
 	if(document.f.e.value=='')
	{
		document.f.e.focus();
		return;
	}
	
	var xhr_object = null;
	
	if(window.XMLHttpRequest)
		xhr_object = new XMLHttpRequest();
	else if(window.ActiveXObject)
		xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
	else
		return;
	
	xhr_object.open("GET", "../scripts-shop/send_passwd.php?e="+document.f.e.value, false);
	xhr_object.send(null); 
	
	if(xhr_object.readyState == 4)
	{
		//alert(document.f.e.value);
		str='<table cellpadding="5" cellspacing="3" border="0" align="center">';
		str+='	<tr><td height="8"></td></tr>';
		str+='	<tr>';
		str+='		<td align="center">Votre mot de passe vient de vous être envoyé!</td>';
		str+='	</tr>';
		str+='	<tr><td height="8"></td></tr>';
		str+='	<tr>';
		str+='		<td align="center">Cliquez <a href=".?rubrique=mydeadrock" style="color:#F28D00">ici</a> pour vous connecter.</td>';
		str+='	</tr>';
		str+='</table>';
		document.getElementById("code").innerHTML=str;
	}	
}


function delItem(cmd,art)
{
 	var agree=confirm("Voulez-vous vraiment supprimer cet article de votre panier?");
	if(agree)
	{
		
		var xhr_object = null;
		
		if(window.XMLHttpRequest)
			xhr_object = new XMLHttpRequest();
		else if(window.ActiveXObject)
			xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
		else
			return;
		
		xhr_object.open("GET", "../scripts-shop/delItem.php?cmd="+cmd+"&art="+art, false);
		xhr_object.send(null); 
		
		if(xhr_object.readyState == 4)
		{
			document.location.replace(".?rubrique=cmd");
		}
	}
}

function updateItem(cmd,art,n,p)
{
	var xhr_object = null;
	
	if(window.XMLHttpRequest)
		xhr_object = new XMLHttpRequest();
	else if(window.ActiveXObject)
		xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
	else
		return;
	
	xhr_object.open("GET", "../scripts-shop/updateItem.php?cmd="+cmd+"&art="+art+"&n="+n+"&p="+p, false);
	xhr_object.send(null); 
	
	if(xhr_object.readyState == 4)
	{
		//alert(xhr_object.responseText);
		if(xhr_object.responseText=="")
			document.location.replace(".?rubrique=cmd");
		else
		{
			alert(xhr_object.responseText);
			document.location.replace(".?rubrique=cmd");
		}
	}
}

function majPort(pays, poids, prix)
{
	var xhr_object = null;
	
	if(window.XMLHttpRequest)
		xhr_object = new XMLHttpRequest();
	else if(window.ActiveXObject)
		xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
	else
		return;

	xhr_object.open("GET", "../scripts-shop/majPort.php?pays="+pays+"&poids="+poids, false);
	xhr_object.send(null); 
	
	if(xhr_object.readyState == 4)
	{
		document.getElementById("port").innerHTML=xhr_object.responseText;
		document.getElementById("total").innerHTML=parseInt(prix,10)+parseInt(xhr_object.responseText,10);
		
		document.cmd.port.value=xhr_object.responseText;
		document.cmd.total.value=parseInt(prix,10)+parseInt(xhr_object.responseText,10);
	}
}

function confirmSuppCmd(id)
{
 	var agree=confirm("Voulez-vous vraiment supprimer cette commande?");
	if(agree)
	{
		var xhr_object = null;
		
		if(window.XMLHttpRequest)
			xhr_object = new XMLHttpRequest();
		else if(window.ActiveXObject)
			xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
		else
			return;
		
		xhr_object.open("GET", "../scripts-shop/delCmd.php?id="+id, false);
		xhr_object.send(null); 
		
		if(xhr_object.readyState == 4)
		{
			//alert(xhr_object.responseText);
			document.location.replace(".?rubrique=accueil");
		}
	}
}

