﻿	$(function(){
		$.superbox();
	});
	$.superbox.settings = {
	boxId: "superbox", // Attribut id de l'élément "superbox"
	boxClasses: "", // Classes de l'élément "superbox"
	overlayOpacity: .8, // Opacité du fond
	boxWidth: "550", // Largeur par défaut de la box
	boxHeight: "400", // Hauteur par défaut de la box
	loadTxt: "Loading...", // Texte de loading
	closeTxt: "Fermer", // Texte du bouton "Close"
	prevTxt: "Previous", // Texte du bouton "previous"
	nextTxt: "Next" // Texte du bouton "Next"
};
    $(document).ready(function() { 
        $('ul.spmenu').superfish({ 
            delay:       1000,                            // one second delay on mouseout 
            animation:   {opacity:'show',height:'show'},  // fade-in and slide-down animation 
            speed:       'fast',                          // faster animation speed 
            autoArrows:  false,                           // disable generation of arrow mark-up 
            dropShadows: false                            // disable drop shadows 
        }); 
    }); 
	$(document).ready(function(){
		$("#example").treeview();
	});
	$(document).ready(function(){
		$('#slide_index ').galleryView({
			panel_width: 695,
			panel_height: 220,
			frame_width: 120,
			frame_height: 38
		});
	});
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 O(elem){
	return document.getElementById(elem);
}

function V(elem) {
	return O(elem).value;
}

function IsEmpty(string){
    return (string.trim()=='');
}

function IsMail(email){
    return (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email));
}

function IsNumeric(number){
    return (/^[0-9]+$/.test(number));
}

function Isdate(number){
	var re_date = /^\d{1,2}\/\d{1,2}\/\d{4}$/;
	return re_date.test(number);
}


function valider_inscri() {
	retour_mail         = IsMail(V('mail_inscri'));
	retour_pwd          = document.getElementById('champ_pwd_inscri').value; 
	retour_pwd_dbl      = document.getElementById('champ_dbl_pwd_inscri').value; 
	retour_nom          = document.getElementById('champ_nom_inscri').value; 
	retour_prenom       = document.getElementById('champ_prenom_inscri').value; 
	retour_date         = Isdate(V('champ_date_inscri'));
	retour_adresse      = document.getElementById('champ_adresse_inscri').value; 
	retour_ville        = document.getElementById('champ_ville_inscri').value; 
	retour_cp           = IsNumeric(V('champ_cp_inscri'));
	taille_cp           = document.getElementById('champ_cp_inscri').value;
	longeur_cp          =  taille_cp.length;
	retour_pays         = document.getElementById('champ_pays_inscri').value; 
	retour_tel          = IsNumeric(V('champ_tel_inscri'));
	retour_civilite1    = document.getElementById('choix1'); 
	retour_civilite2    = document.getElementById('choix2');
	retour_civilite3    = document.getElementById('choix3'); 
	ok = true ;
	civilite = '';
	if(retour_civilite1.checked != false){
		civilite = retour_civilite1.value;
		document.getElementById('civilite_inscri').style.display = 'none' ;
		
	}
	else if (retour_civilite2.checked != false){
		civilite = retour_civilite2.value;
		document.getElementById('civilite_inscri').style.display = 'none' ;
	}
	else if (retour_civilite3.checked != false){
		civilite = retour_civilite3.value
		document.getElementById('civilite_inscri').style.display = 'none' ;
	}
	else{
		document.getElementById('civilite_inscri').style.display = 'block' ;
		ok = false;
	}			
	if (retour_mail== false) {
		document.getElementById('champ_mail_inscri').style.display = 'block' ;
		ok = false ;
	}
	else
		document.getElementById('champ_mail_inscri').style.display = 'none' ;
	
	if (retour_pwd == ''){
		document.getElementById('pwd_inscri').style.display = 'block' ;
		ok = false ;
	}
	else
		document.getElementById('pwd_inscri').style.display = 'none' ;
	
	if (retour_pwd_dbl == '' || retour_pwd_dbl !=retour_pwd){
		document.getElementById('pwd_dbl_inscri').style.display = 'block' ;
		ok = false ;
	}
	else
		document.getElementById('pwd_dbl_inscri').style.display = 'none' ;
	
	if (retour_nom == ''){
		document.getElementById('nom_inscri').style.display = 'block' ;
		ok = false ;
	}
	else
		document.getElementById('nom_inscri').style.display = 'none' ;
	
	if (retour_prenom == ''){
		document.getElementById('prenom_inscri').style.display = 'block' ;
		ok = false ;
	}
	else
		document.getElementById('prenom_inscri').style.display = 'none' ;

	if (retour_adresse == ''){
		document.getElementById('adresse_inscri').style.display = 'block' ;
		ok = false ;
	}
	else
		document.getElementById('adresse_inscri').style.display = 'none' ;
		
	if (retour_cp == false){
		document.getElementById('cp_inscri').style.display = 'block' ;
		ok = false ;
	}
	else
		document.getElementById('cp_inscri').style.display = 'none' ;
	
	if (taille_cp < 1000 || taille_cp > 96000 )
		{
		document.getElementById('cp_inscri').style.display = 'block' ;
		ok = false ;
		}
	else
		document.getElementById('cp_inscri').style.display = 'none' ;
	if (longeur_cp != 5 )
		{
		document.getElementById('cp_inscri').style.display = 'block' ;
		ok = false ;
		}
	else
		document.getElementById('cp_inscri').style.display = 'none' ;
		
	if (retour_ville == ''){
		document.getElementById('ville_inscri').style.display = 'block' ;
		ok = false ;
	}
	else
		document.getElementById('ville_inscri').style.display = 'none' ;
		
	if (retour_pays == ''){
		document.getElementById('pays_inscri').style.display = 'block' ;
		ok = false ;
	}
	else
		document.getElementById('pays_inscri').style.display = 'none' ;

	if (retour_tel == false){
		document.getElementById('tel_inscri').style.display = 'block' ;
		ok = false ;
	}
	else
		document.getElementById('tel_inscri').style.display = 'none' ;
	
	
	if (retour_date == false){
		document.getElementById('date_inscri').style.display = 'block' ;
		ok = false ;
	}
	else
		document.getElementById('date_inscri').style.display = 'none' ;
	if (ok == true)
		document.forms['formul_inscri_new'].submit();
}

function valider(){
	retour_mail = IsMail(V('loginn'));
	retour_pwd  = document.getElementById('pwd').value; 
	if (retour_mail== false)
		document.getElementById('champ_mail').style.display = 'block' ;
	else
		document.getElementById('champ_mail').style.display = 'none' ;
	if (retour_pwd == '')
		document.getElementById('champ_pwd').style.display = 'block' ;
	else
		document.getElementById('champ_pwd').style.display = 'none' ;
	if (retour_mail == true && retour_pwd != '')
		document.forms['inscription_formul'].submit();
}

function send_data_news()
	{
		retour_mail         = IsMail(V('mail_inscri_news'));
		mail        		= document.getElementById('mail_inscri_news').value; 
		retour_nom          = document.getElementById('champ_nom_inscri_news').value; 
		retour_prenom       = document.getElementById('champ_prenom_inscri_news').value; 
		retour_ville        = document.getElementById('champ_ville_inscri_news').value; 
		date		        = document.getElementById('champ_date_inscri_news').value; 
		retour_date         = Isdate(V('champ_date_inscri_news'));
		ok = true;
		var xhr = getXhr();
		xhr.onreadystatechange = function(){
			if(xhr.readyState == 4 && xhr.status == 200){
				alert(xhr.responseText);				
			}
		}
		if ( retour_mail == false || retour_nom == '' || retour_prenom == '' || retour_ville == '' || retour_date == false  )
			{
				alert("Veuillez véfier vos coordonnées !!");
				ok = false ;
			}
		if (ok == true)
			{
				user = mail + '|' + retour_nom + '|' + retour_prenom + '|' + retour_ville + '|' + date ;
				xhr.open("POST","ajax_front.php",true);
				xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
				xhr.send("user="+user);	
			}
			
	}
	
function change_qte(){
	cat = document.getElementById('name_categorie').value;
	tab = cat.split('|');
	if (tab[1] > 15 )
		max = 15 ;
	else
		max = tab[1];
		
	var form_d = '';
	var form_d  = 'Quantité : <select style = "width : 90px;" name="qte_categorie" id="qte_categorie">';
	for(opt=1;opt<=max;opt++)
	{
		form_d += '  <option value="'+ opt +'">'+ opt +'<\/option>';
	}
	form_d += '<\/select>';
	document.getElementById("qte_categorie_aff").innerHTML = form_d;

}

function change_img(img,marque,nom)
{
	document.getElementById("prod_img").innerHTML = '<img src = "http://www.sportendance.com/photos/produits/bigs/'+marque+'/'+img+'" alt="'+nom+'" width="499" height = "390">' ;
}

function back_photo(img,marque,nom)
{
	document.getElementById("prod_img").innerHTML = '<img src = "http://www.sportendance.com/photos/produits/bigs/'+marque+'/'+img+'" alt="'+nom+'" width="499" height = "390">' ;
}

function valider_mdp(){
	retour_mail = IsMail(V('name_mail'));
	
	if (retour_mail== false)
		document.getElementById('champ_mail').style.display = 'block' ;
	else
		document.forms['update_data'].submit();
}

function valider_mail(){
	retour_mail = IsMail(V('name_mail'));
	
	if (retour_mail== false)
		document.getElementById('champ_mail').style.display = 'block' ;
	else
		document.forms['update_data'].submit();
}

function go_cat(id) {
	document.getElementById('select'+id).style.display='none';
	document.getElementById('selectsize'+id).style.display='block';
	document.getElementById('change'+id).style.display='none';
}

function add(id) {
	var xhr = getXhr();
				xhr.onreadystatechange = function(){
					if(xhr.readyState == 4 && xhr.status == 200){
						leselect = xhr.responseText;
						window.location.replace(document.URL);
						
					}
				}
	val_max = parseInt(document.getElementById('qte_max_cat'+id).value)
	added = parseInt(document.getElementById('qte_panier_prod'+id).value) + 1 ;
	if (added <= val_max) {
		document.getElementById('qte_panier_prod'+id).value = added;
		liste = added + '|' + id ;
		xhr.open("POST","../ajax_front.php",true);
		xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		xhr.send("qte="+liste);	
	}
}

function moins(id) {
	var xhr = getXhr();
			xhr.onreadystatechange = function(){
				if(xhr.readyState == 4 && xhr.status == 200){
					leselect = xhr.responseText;
					window.location.replace(document.URL);
					
				}
			}
	verif_plus = document.getElementById('plus'+id) ;
	moinss = parseInt(document.getElementById('qte_panier_prod'+id).value) - 1 ;
	if (moinss != 0) {
	document.getElementById('qte_panier_prod'+id).value = moinss;
	liste = moinss + '|' + id ;
	xhr.open("POST","../ajax_front.php",true);
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr.send("qte_moins="+liste);		
	}
}
function change_adresse(id) {
	var xhr = getXhr();
				xhr.onreadystatechange = function(){
					if(xhr.readyState == 4 && xhr.status == 200){
						leselect = xhr.responseText;
						document.getElementById('adresse_ajax_livraison').innerHTML = leselect;
						document.getElementById("adresse_liste").style.display = 'none';
						
					}
				}
	if ( id != '-1' ) {
		xhr.open("POST","ajax_front.php",true);
		xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		xhr.send("id_adresse="+id);	
	}

}

function verif_send() 
	{
		retour_mail      = IsMail(V('email_contact'))   ;
		retour_nom       = V('nom')                     ;
		retour_prenom    = V('prenom')                  ;
		retour_objet     = V('objet')                   ;
		retour_message   = V('message')                 ;
		ok = true ;
		
		if (retour_mail == false )
			{
				document.getElementById('champ_mail_contact').style.display = 'block' ; 
				ok = false ;
			}
		else
			document.getElementById('champ_mail_contact').style.display = 'none' ; 
		
		if (retour_objet == 0 )
			{
				document.getElementById('objet_contact').style.display = 'block' ; 
				ok = false ;
			}
		else
			document.getElementById('objet_contact').style.display = 'none' ; 
		
		if (retour_nom == '' )
			{
				document.getElementById('nom_contact').style.display = 'block' ; 
				ok = false ;
			}
		else
			document.getElementById('nom_contact').style.display = 'none' ; 
			
		if (retour_message == '' )
			{
				document.getElementById('message_contact').style.display = 'block' ; 
				ok = false ;
			}
		else
			document.getElementById('message_contact').style.display = 'none' ; 	
		
		if (retour_prenom == '' )
			{
				document.getElementById('prenom_contact').style.display = 'block' ; 
				ok = false ;
			}
		else
			document.getElementById('prenom_contact').style.display = 'none' ; 	
			
		if (ok == true)
			document.forms["formul_contact"].submit();
	}

function verifier() {
	retour_mail         = IsMail(V('name_mail'));
	retour_old_code     = document.getElementById('old_code').value;
	retour_new_code_one = document.getElementById('new_code_one').value;
	retour_new_code_two = document.getElementById('new_code_two').value;
	ok = true;
	if (retour_mail == false) {
		document.getElementById('champ_mail').style.display = 'block' ;
		ok = false ;
	}
	else
		document.getElementById('champ_mail').style.display = 'none' ;
	if (retour_old_code == '') {
		document.getElementById('champ_code_old').style.display = 'block' ;
		ok = false ;
	}
	else
		document.getElementById('champ_code_old').style.display = 'none' ;
	if (retour_new_code_one == '' || retour_new_code_two == '' || retour_new_code_one != retour_new_code_two) {
		document.getElementById('champ_code_new').style.display = 'block' ;
		ok = false ;
	}
	else
		document.getElementById('champ_code_new').style.display = 'none' ;
		if (ok == true)
		document.forms['update_data'].submit();
}

function add_new_line ()
	{
		var t = new Array();
		index = parseInt(document.getElementById('index_mail').value)+1 ;
		for( i = 1; i < index ; i++)
			 t[i] = document.getElementById('text'+i).value ;
		html = document.getElementById('liste_mail') ;
		htmlg = '<div style="display:block; float:left; margin:10px 0 0 10px; width:500px; height:50px;  position:relative;"><LABEL STYLE="color:#333; font-weight:bold; display:block; width:170px; height:50px;  float:left; line-height:50px;  ">mail de votre ami(e) :</LABEL> <input  style="float:left; border:1px solid #333; margin-top:16px;  width:200px;"  type ="text" id="text' + index + '"/> <input style="float:left; margin:16px 0 10px 10px; " onclick=\'send_mail_parrainage(' + index + ')\' type = "image" src="../images/btn_valider.jpg"  id="bouton' + index + '" value = "valider"/><div style="display:none;" id="euro' + index + '"><img style="float:left; margin:-5px 0 0 15px;" src="../images/3euro.gif" height="50" width="50"></div></div>';
		//htmlg = '<br />mail de votre ami(e) : <input type ="text" id="text' + index + '"/> <input onclick=\'send_mail_parrainage('+ index +');\' type = "button" id="bouton' + index +'" value = "valider"/><div style="display:none;" id="euro'+ index +'"><img  src="../images/3euro.gif" height="50" width="50"></div>';
		html.innerHTML=html.innerHTML+htmlg;
		document.getElementById('index_mail').value = index;
		for( i = 1; i < index ; i++)
			document.getElementById('text'+i).value = t[i] ;
	}
// fonction pour IE 6 7 8 afin qu il puisse accéder au differentes div ( Majdi 14/01/2010 )
function ShowElementInfo( iElementId )
{
	if( typeof(iElementId) == "string" && iElementId.length > 0 )
		{
			var element = document.getElementById(iElementId);
			if( element )
				return element.value ;
			else
				alert("ERROR: could not find the requested element");
		}
} 
function verif_cp(id)
	{
		cp = ShowElementInfo('cp'+id) ; 
		if (cp < 1000 || cp > 96000 )
			{
				document.getElementById('cp'+id).value = "";
				document.getElementById('ok'+id).disabled=true;
			}
		else
			{
				document.getElementById('ok'+id).disabled=false;
			}
		if (cp.length != 5 )
			{
				document.getElementById('cp'+id).value = "";
				document.getElementById('ok'+id).disabled=true;
			}
		else
			document.getElementById('ok'+id).disabled=false;
	}
function show_bon(id)	
	{
		
		document.getElementById('detail_bon').style.visibility= "visible";
		document.getElementById('detail_bon').innerHTML  =  '<span style="color: rgb(8, 7, 111); background-color: rgb(192, 191, 255); border: 1px solid rgb(192, 191, 255); font-variant: small-caps; font-size: 0.8em; letter-spacing: 1px;"> Détails :</span><br/><br/><p style="font-size: 12px; text-align: center; border: 1px solid rgb(221, 238, 255);padding:5px; width:500px;">' + id + "</p>";
	}
function relance_parrainage(mail)
	{
		var xhr = getXhr();
			xhr.onreadystatechange = function(){
					if(xhr.readyState == 4 && xhr.status == 200){
						//leselect = xhr.responseText;
						alert("Une relance par mail a été envoyé à votre ami !!");					
					}
				}
		xhr.open("POST","ajax_front.php",true);
		xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		xhr.send("relance="+mail);	
	}