function autocomplete() 
{
	$.ajax
	({
			type: "POST",
			url: "ajax.autocomplete.php",
			data: "mot_recherche="+$("#in_firstname").val(),
											   
			success: function(msg)
			{
            	if(msg == '1')	{
                	alert('Vous avez selectionnez le nombre maximum de sonneries');
			 		maj_affichage_selection();
                }	else	{
                	$("#autocomplete").html(msg);	 
                }				
			}
	});		

}

function autocomplete_blingo() 
{
	$.ajax
	({
			type: "POST",
			url: "ajax.autocomplete.php",
			data: "mot_recherche="+$("#in_firstname_blingo").val()+"&blingo=1",
											   
			success: function(msg)
			{
            	if(msg == '1')	{
                	alert('Vous avez selectionnez le nombre maximum de sonneries');
			 		maj_affichage_selection();
                }	else	{
                	$("#autocomplete_blingo").html(msg);	 
                }				
			}
	});		

}


function select_nom_blingo(id,nom)
{
	//A METTRE LID DANS UN COOKIE
	 $("#id_firstname_blingo").val(id);
	 $("#in_firstname_blingo").val(nom); 
	 $("#autocomplete_blingo").html("");		
}


function choix_pays(pays)
{ 
	/*
	 $.ajax
	({
			type: "GET",
			url: "ajax.choix_pays.php",
			data: "pays="+pays,
											   
			success: function(msg)
			{
				//pour eviter de quitter sans choisir de pays, la croix est masqué
				//on la ré affiche pour les autres lightbox
				$(".close").css("display","block");
				lb_close();
				if (pays!='fr')
				{$.('#right').html('<img style="margin-left:-5px;" src="img/blingo_soon.png">');}
			}
	});		
	*/
	setCookie('pays',pays);
	$(".close").css("display","block");
	lb_close();
	if (pays!='fr')
	{$('#right').html('<img style=\"margin-left:-5px;\" src=\"img/blingo_soon.png\">');}
}

/***********************************************************************************/
/***********************************************************************************/

function validation_codepromo(code) 
{
	$.ajax
	({
			type: "POST",
			url: "ajax.valid_codepromo.php",
			data: "code_promo="+code+"&ok=on",
											   
			success: function(msg)
			{
            	a=msg.split('///');
                /*on recoit un login on redirgie vers la commande client*/
               // if (a[0] == 1) 
               // {
                	//$(location).attr('href','history.php?code='+code);
                //}              
               // else /* on est dans le cas dun code promo valide ou non */
               // {
					//alert(a[1]);
					$("#promo").html(a[1]);	 
                	/*location.reload(); */
                //}
                 
			}
	});		

}	

function isInt(x) {
	var y=parseInt(x);
	if (isNaN(y)) return false;
	return x==y && x.toString()==y.toString();
}





function select_nom(id,nom)
{
	//A METTRE LID DANS UN COOKIE
	 $("#id_firstname").val(id);
	 $("#in_firstname").val(nom); 
	 $("#autocomplete").html("");
	 
	 $.ajax
	({
			type: "POST",
			url: "ajax.alimentation_flist.php",
			data: "id="+$("#id_firstname").val(),
											   
			success: function(msg)
			{
				$("#message_style").html(msg);	 
			}
	});		
}


function reset_composition_sonnerie()
{
	//A METTRE LID DANS UN COOKIE
	
	 $("#in_firstname").val("");
	 $("#id_firstname").val("");
	 $("#id_message_style").val(""); 
	 $("#id_message").val("");
	 $("#autocomplete").html("");
	 
	 var liste= "<select disabled='disabled' style='width:175px;'> <option value=''>Choisis un pr&eacute;nom</option>  </select>";
	 $("#message").html(liste);
	 $("#message_style").html(liste);

}




function play_selection(parent)
{
    //on vide le div parent pour enlever le contenu de la case dans selection
	$.ajax
	({
			type: "POST",
			url: "ajax.play_selection.php",
			data: "sel="+parent,
											   
			success: function(msg)
			{
				$("#mp3_selection<?php echo $TabConfig['nb_contenus'];?>").html(""+msg);	 
			}
	});	
}





function supprime_selection(parent)
{
	//on vide le div parent pour enlever le contenu de la case dans selection
	$.ajax
	({
			type: "POST",
			url: "ajax.sup_selection.php",
			data: "sel="+parent,
											   
			success: function(msg)
			{
				$("#"+parent).html(msg); 
				maj_affichage_selection();
			}
	});
	init_slideselection();		
}


function ajout_selection(num)
{
	if ( ($("#id_firstname").val() != "") && ($("#id_message_style").val() != "") && ($("#id_message").val() != "") ) //on opere le traitement uniquement si les champs ont été saisies
	{
    	init_slideselection();
		$.ajax
		({
				type: "POST",
				url: "ajax.add_selection.php",
				data: "prenom="+$("#id_firstname").val()+"&message_style="+$("#id_message_style").val()+"&message="+$("#id_message").val(),
												   
				success: function(msg)
				{
					if(msg != '1')	{
						$(".ul_selection"+num).html(msg);	 	
					}
				}
		});
		
		reset_composition_sonnerie(); //on remet tout a 0
	}
	else
	{
		alert("Veuillez saisir tous les champs");
	}
}



function ajout_selection_lien(lien,num)
{
	$.ajax
		({
				type: "POST",
				url: "ajax.add_selection.php",
				data: "lien="+lien,
												   
				success: function(msg)
				{
					$(".ul_selection"+num).html(msg);	 
				}
		});
		
		reset_composition_sonnerie(); //on remet tout a 0

}


function mp3_lien(lien,lecteur)
{
	
	$.ajax
			({
					type: "POST",
					url: "ajax.play_selection.php",
					data: "selection_entiere="+lien,
													   
					success: function(msg)
					{
						$("#"+lecteur).html(msg);	 
					}
			});
}






function init_homepage()
{
	$("input[type=text]").val("");
	$("#comment_form_pseudo").val("Votre pseudo");
}



function maj_affichage_selection()
{
				init_slideselection();
				$.ajax
				({
						type: "POST",
						url: "ajax.maj_selection.php",
														   
						success: function(msg)
						{
							$(".ul_selection<?php echo $TabConfig['nb_contenus'];?>").html(msg);	 
						}
				});
}





function validation_dl() 
{
	$.ajax
	({
			type: "POST",
			url: "ajax.valid_dl.php",
											   
			success: function(msg)
			{
				if (msg != 0)
                {
                	alert(msg);
                }
                else
                {
                	$(location).attr('href','conf_order.php');
                } 
			}
	});		

}	


function choix_bloc_paiement(pays) 
{
	$.ajax
	({
			type: "POST",
			url: "ajax.get_block_pay.php",
			data: "pays="+pays,
											   
			success: function(msg)
			{
              	$("#paiement").html(msg);
				$("#paiement").addClass('bloc_paiement');
				$("#choix_pays").html('');
			}
	});		

}


function validation_formulaire_paiement(code) 
{

 if (code == '0')
 {
	if ($("#code").val() == "")
    {
    	//alert("Please enter the code that you just received by SMS");
		alert('Veuillez entrer le code que vous avez reçu par SMS');
    }
	else if ($("#mobile").val() == "")
    {
    	//alert("Enter your cellphone number");
		alert('Veuillez entrer votre numéro de téléphone mobile');
    }
    else
    {
        
        var filter = /^((06)|(07))\d{8}$/;
		if (filter.exec($("#mobile").val()))
        {
        
            $("#image_dl").removeClass("telecharger");
            $("#image_dl").addClass("telecharger1")
            $("#image_dl").removeAttr("onclick");
            
         		$.ajax
                    ({
                            type: "POST",
                            url: "ajax.valid_dl.php",
                                                               
                            success: function(msg)
                            {
                                if (msg != 0)
                                {
                                    alert(msg);
                                }
                                else
                                {
                                    $("form").submit();
                                } 
                            }
                    });	
        }
        else
        {alert("The number isn't correct");}
    }
  }
  else  /* on est dans le cas d'un code promo */
  {
  
  		var filter = /^((06)|(07))\d{8}$/;
		if (filter.exec($("#mobile").val()))
        {
        
            $("#image_dl").removeClass("telecharger");
            $("#image_dl").addClass("telecharger1")
            $("#image_dl").removeAttr("onclick");
            
         		$.ajax
                    ({
                            type: "POST",
                            url: "ajax.valid_dl.php",
                                                               
                            success: function(msg)
                            {
                                if (msg != 0)
                                {
                                    alert(msg);
                                }
                                else
                                {
                                    $("form").submit();
                                } 
                            }
                    });	
        }
        else
        {alert("Le numéro de mobile entré est erroné");}
        
  }

}	

function dl_sonnerie_vocale(selection, id_demande)
{
	 $.ajax
	({
			type: "POST",
			url: "ajax.dl_sonneries_vocales.php",
			data: "selection="+selection+"&id_demande="+id_demande,
											   
			success: function(msg)
			{
				a=msg.split('/');
				if (a[0]=='0')
				{alert('Appel pour enregistrer ton message avant tout !');}
				else
				{$("#contenu_enregistre").html(msg);} 
			}
	});		
}



function enregistre_mail()
{
	var mail=$("#mail").val();
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.exec(mail))
	{
			$.ajax
				({
						type: "POST",
						url: "ajax.enregistrement_email.php",
						data: "email="+mail,
														   
						success: function(msg)
						{$("#enreg_mail").html(msg);}
				});	
	}
	else
	{
		alert('Email incorrect');
	}

}



function affiche_liste_commentaire()
{
	$.ajax
	({
			type: "POST",
			url: "comments/ajax.affichage_liste_com.php",
											   
			success: function(msg)
			{	
				lb_open();
				$("#playerBox").html(msg);
				$('#playerBox').css('height','650px');
			}
	});	
}




function init_slideselection()
{

    $jScroller.add("#scroller_container","#scroller61","left",1,1);
    $jScroller.add("#scroller_container","#scroller62","left",1,1);
    $jScroller.add("#scroller_container","#scroller63","left",1,1);	
    $jScroller.add("#scroller_container","#scroller61","left",1,1);
    $jScroller.add("#scroller_container","#scroller62","left",1,1);
    $jScroller.add("#scroller_container","#scroller63","left",1,1);	
    $jScroller.add("#scroller_container","#scroller64","left",1,1);
    $jScroller.add("#scroller_container","#scroller65","left",1,1);
    $jScroller.add("#scroller_container","#scroller66","left",1,1);
    $jScroller.start();

}


function valid_pay_blingo(id_demande) 
{
		if( $('#cp_blingo').val()=='' ) 
		{
			alert('Ce code promo n\'est pas valide. Le code promo doit être composé de 5 lettres.','Attention');
			return false;
			
		} else {
			var mask_code = /^[a-zA-Z]{5}$/;
			
			if( $('#cp_blingo').val().match(mask_code) ) {
				// check code
				$.get('ajax.check_code_promo.php', { code_promo: $("#cp_blingo").val(), blingo: '_blingo' }, function(data) {
					if( data == "0" ) {
						alert("Ce code promo est invalide.","Attention");
						return false;
					} else {
						var url_redir = "valid_pay_blingo.php?mode=m&id_cp=" + data + "&id_com="+ id_demande;
						document.location.href = url_redir;					
					}
				});
				
			} else {
				alert("Ce code promo n'est pas valide. Le code promo doit &ecirc;tre compos&eacute; de 5 lettres.","Attention");
				return false;
			}
		}
}


/**
 *
 *	POSITIONNE UN COOKIE
 *
**/
function setCookie(name,value) {
	var time = 1;
	if(setCookie.arguments.length == 3)	{
		time = setCookie.arguments[2];
	}
	
	var date = new Date();
	date.setDate(date.getDate()+(time));
	var expires = "; expires="+date.toGMTString();
	
	document.cookie = name+"="+value+expires+"; path=/";
}
/**
 *
 *	RECUPERE LA VALEUR DU COOKIE CHOISI
 *
**/
function getCookie(name) {
	var nameCookie = name + "=";
	//alert(document.cookie);
	var arrayCookie = decodeURIComponent(document.cookie).split(';');
	for(var i=0;i < arrayCookie.length;i++) {
		var cookie = arrayCookie[i];
		//alert(cookie);
		while (cookie.charAt(0)==' ') cookie = cookie.substring(1,cookie.length);
		if (cookie.indexOf(nameCookie) == 0) return cookie.substring(nameCookie.length,cookie.length);
	}
	return null;
}
/**
 *
 *	TUE UN COOKIE
 *
**/
function killCookie()	{
	createCookie(name,"",-1);
}

