

$(document).ready(function() {  
        
		$('#slide_partners').cycle({
		    fx:     'fade',
        timeout: 5000,                            
        height: '60px'
	   }); 
        
		$('#overlay').bind('click', function() { $('#loadingMessage').slideUp(); $('#overlay').slideUp('800'); }); 
        
		$('#prix').cycle({
		    fx:     'scrollLeft',
        timeout:5000,  
        pager:  '#nav',
    		pauseOnPagerHover: true,
        height: '378px',
        pagerAnchorBuilder: function(idx, slide) { 
           if (idx == 0) return '<a href="#">'+(idx+1)+'<sup>er</sup> Prix</a>'; 
           else return '<a href="#">'+(idx+1)+'<sup>ème</sup> Prix</a>'; 
        } 
	   });
	   

});

/* functions bases ********************************************************************************************************************** */


function printLoadingMessage(loadingMessageText) {
  				$('#overlay').slideDown('500');
  				$('#loadingMessage').html(loadingMessageText);
  				$('#loadingMessage').slideDown();
				  setTimeout(function() {  $('#loadingMessage').slideUp('800'); $('#overlay').slideUp();  },5000);
}
          
function load(where,id) {  
      $('#'+id).slideUp(); 
			$.ajax({
					type: "GET", url: './?action='+where,
					success: function(msg){ $('#'+id).html(msg); $('#'+id).slideDown(); }
			});
}  


/* PARTICIPATIONS *********************************************************************************************************************** */

function loadparticiper(where) { 
      $('#game').html('<p class="center">&nbsp;<br><br><br><br><br><br><br><br><img src="./img/icon/loadingl.gif"></p>');
			$.ajax({
					type: "GET", url: './?action=play'+where,
					success: function(msg){ 
              $('#game').slideUp('500');
              setTimeout(function() {   
                  $('#game').html(msg); 
                  $('#game').slideDown(msg);    
                  $('.w').flash({
                      src: './swf/gratt_win.swf',
                      width: 200, height: 190, wmode : "transparent" 
                  });
                  $('.l').flash({
                      src: './swf/gratt_lost.swf',
                      width: 200, height: 190, wmode : "transparent" 
                  }); 
                  if (where == 'game') setTimeout(function() {  $('.btn').slideDown();  },14000);
              },500);
          }
			});
} 
    
    
/* INVITATIONS*** *********************************************************************************************************************** */

function sendinvit() { 
    printLoadingMessage('<img src="./img/icon/loading.gif">');    
    var valid = 0; $('.invitation .novalid').removeClass('novalid'); 
    var mailtype = /^[\w.-]+@[\w.-]+\.[a-zA-Z]{2,5}$/;
    $('.invitation .obligatoire').each(function() { 
        if (this.value != '' && mailtype.test(this.value) == false) { $(this).addClass('novalid'); valid++; } 
    });
    if (valid > 0) printLoadingMessage('<img src="./img/icon/error.png" alt="ERREUR" /> <b>L\'adresse email n\'est pas valide</b>, veuillez les corriger !');      
    else {   
			$.ajax({
					type: "POST", url: './?action=sendinvit',
					data:{ 'mail1': $('.invitation :input[name=email1]').val(),  'prenom1': $('.invitation :input[name=prenom1]').val(),  'nom1': $('.invitation :input[name=nom1]').val(),  
                 'mail2': $('.invitation :input[name=email2]').val(),  'prenom2': $('.invitation :input[name=prenom2]').val(),  'nom2': $('.invitation :input[name=nom2]').val(),  
                 'mail3': $('.invitation :input[name=email3]').val(),  'prenom3': $('.invitation :input[name=prenom3]').val(),  'nom3': $('.invitation :input[name=nom3]').val(),  
                 'mail4': $('.invitation :input[name=email4]').val(),  'prenom4': $('.invitation :input[name=prenom4]').val(),  'nom4': $('.invitation :input[name=nom4]').val()  },
					success: function(msg){  printLoadingMessage(msg); }
			});
    } 
}			
			

/* INSCRIPTION LOGIN ******************************************************************************************************************** */
			
function sendlogin() {  
    printLoadingMessage('<img src="./img/icon/loading.gif">');    
    $('.login .novalid').removeClass('novalid');
    $('.login .obligatoire').each(function() { if (this.value == '') { $(this).addClass('novalid'); }  });
    if ($('.login :input[name=login]').val() == '') printLoadingMessage('<img src="./img/icon/error.png" alt="ERREUR" /> <b>Veuillez entrer votre adresse email.</b>');
    else if ($('.login :input[name=mdp]').val() == '') printLoadingMessage('<img src="./img/icon/error.png" alt="ERREUR" /> <b>Veuillez entrer votre mot de passe.</b> Vous l\'avez reçu par mail.'); 
    else {   
			$.ajax({
					type: "POST", url: './?action=login',
					data:{ 'login': $('.login :input[name=login]').val(),  'mdp': $('.login :input[name=mdp]').val()  },
					success: function(msg){  printLoadingMessage(msg); }
			});
    } 
}					
function sendmdp() {  
    printLoadingMessage('<img src="./img/icon/loading.gif">');
		$.ajax({
					type: "POST", url: './?action=sendmdp',
					data:{ 'nom': $('.login :input[name=nom]').val(),  'prenom': $('.login :input[name=prenom]').val(),  'mail': $('.login :input[name=mail]').val()  },
					success: function(msg){  printLoadingMessage(msg); }
		});
}			       
			
function sendinscription() {  
    printLoadingMessage('<img src="./img/icon/loading.gif">');    
    var valid = 0; $('.inscription .novalid').removeClass('novalid');
    var mailtype = /^[\w.-]+@[\w.-]+\.[a-zA-Z]{2,5}$/;
    // champs vide
    $('.inscription .obligatoire').each(function() { if (this.value == '') { $(this).addClass('novalid'); valid++; }  });
    if (valid > 0) printLoadingMessage('<img src="./img/icon/error.png" alt="ERREUR" /> <b>Le formulaire est incomplet.</b> Veuillez le compléter.');      
    // mails
    else if (mailtype.test($('.inscription :input[name=aail]').val()) == false) { $('.inscription :input[name=aail]').addClass('novalid'); printLoadingMessage('<img src="./img/icon/error.png" alt="ERREUR" /> <b>Votre adresse email est invalide.</b> Veuillez corriger le formulaire.'); valid++; }
    else if ($('.inscription :input[name=aail]').val() != $('.inscription :input[name=aailbis]').val()) { $('.inscription :input[name=aail]').addClass('novalid'); $('.inscription :input[name=aailbis]').addClass('novalid'); printLoadingMessage('<img src="./img/icon/error.png" alt="ERREUR" /> <b>Vos adresses emails ne correspondent pas.</b> Veuillez corriger le formulaire.'); valid++; }
    else {   
			$.ajax({
					type: "POST", url: './?action=inscription',
					data:{ 'nom': $('.inscription :input[name=nom]').val(),     'prenom': $('.inscription :input[name=prenom]').val(),
                 'jour': $('.inscription :input[name=jour]').val(),   'mois': $('.inscription :input[name=mois]').val(),
                 'annee': $('.inscription :input[name=annee]').val(), 'adresse': $('.inscription :input[name=adresse]').val(),
                 'tel': $('.inscription :input[name=tel]').val(),     'cp': $('.inscription :input[name=cp]').val(),
                 'ville': $('.inscription :input[name=ville]').val(), 'mail': $('.inscription :input[name=aail]').val()
           },
					success: function(msg){  printLoadingMessage(msg); }
			});
    } 
}    
			
function modifinfo() {  
    printLoadingMessage('<img src="./img/icon/loading.gif">');    
    var valid = 0; $('.modifinfos .novalid').removeClass('novalid');
    // champs vide
    $('.modifinfos .obligatoire').each(function() { if (this.value == '') { $(this).addClass('novalid'); valid++; }  });
    if (valid > 0) printLoadingMessage('<img src="./img/icon/error.png" alt="ERREUR" /> <b>Le formulaire est incomplet.</b> Veuillez le compléter.');      
    // mails            
    else if ($('.modifinfos :input[name=mdp]').val() != $('.modifinfos :input[name=mdpbis]').val()) { $('.modifinfos :input[name=mdp]').addClass('novalid'); $('.modifinfos :input[name=mdpbis]').addClass('novalid'); printLoadingMessage('<img src="./img/icon/error.png" alt="ERREUR" /> <b>Vos deux mots de passe ne correspondent pas.</b> Veuillez corriger le formulaire.'); }  
    else {   
			$.ajax({
					type: "POST", url: './?action=playmodifok',
					data:{ 'nom': $('.modifinfos :input[name=nom]').val(),     'prenom': $('.modifinfos :input[name=prenom]').val(),
                 'jour': $('.modifinfos :input[name=jour]').val(),   'mois': $('.modifinfos :input[name=mois]').val(),
                 'annee': $('.modifinfos :input[name=annee]').val(), 'adresse': $('.modifinfos :input[name=prenom]').val(),
                 'tel': $('.modifinfos :input[name=tel]').val(),     'cp': $('.modifinfos :input[name=cp]').val(),
                 'ville': $('.modifinfos :input[name=ville]').val(), 'mdp': $('.modifinfos :input[name=mdp]').val()
           },
					success: function(msg){  printLoadingMessage(msg); }
			});
    } 
}
