$(document).ready(function(){
   
        //Quand  
		// bind pour affeceter la fonction sur plusieurs events : keyup et blur (deselection)
        $('#rcon').bind("blur", function(){  
            //Vérification de la validité du port  
             if (($('#rcon').val().length == 0)  || ($('#ip').val().length > 15) || ($('#port').val().length == 0))
			 {         
               // Si = 0 affichage de l'erreur
                 $('#status_rcon').html('<img src="/images/cross.png" height="16" width="16" /> Vous n\'avez pas rentré de password RCON ou d\'adresse IP');  
             }
			 else
			 {  
                 // Sinon affichage du statut de la recherche puis lance la recherche en appellant la fonction verification_rcon
                 
				 $('#status_rcon').html('<img src="/images/chargement.gif" height="16" width="16" /> Vérification en cours...');  
                 verification_rcon();  
             }  
         });  
   
 
   
  function verification_rcon(){  
  
	var rcon = $('#rcon').val();
	var ip = $('#ip').val();
	var port = $('#port').val();
	var jeu = $('#jeux').val();
	
	
   //utilisation d'ajax pour faire le test de la présence d'un serveur de jeu possédant cette ip et étant encore sous contrat  
         $.post("/validation/validerRcon.php", { ip: ip, port: port, rcon: rcon, jeu: jeu},  
             function(result)
			 {  
                 //Si le résultat est 1
                 if(result == 1)
				 {  
                     $('#status_rcon').html( '<img src="/images/accept.png" height="16" width="16" /> Vous êtes bien le propriétaire du serveur');  
                 }
				 else
				 {  
                     $('#status_rcon').html( '<img src="/images/cross.png" height="16" width="16" /> Vous n\'êtes pas propriétaire du serveur  [erreur rcon ou le serveur est offline]');  
                 }  
         });  
}

   });   
   
   		$(document).ready(function(){


   
        //Quand  
        $('#port, #ip').blur(function(){  
            // Validation de l'ip lorsque on quitte le focus, pas besoin de plus de validation car si authentification rcon échoue, pas d'ajout dans la BDD
            
			 if (($('#ip').val().length == 0) || ($('#port').val().length == 0) )
			 {         
              	$('#status_ip').html('<img src="/images/cross.png" height="16" width="16" /> Veuilez renseigner l\'adresse IP & le port svp'); 			 
             }
			 else if (($('#ip').val().length > 15) || ($('#port').val().length > 5)  )
			 {  
                 $('#status_ip').html('<img src="/images/cross.png" height="16" width="16" /> L\'adresse IP / Le port renseignée n\'est pas valide'); 
             } 
			else 
			  {
                 $('#status_ip').html('<img src="/images/chargement.gif" height="16" width="16" /> Vérification en cours...');  
                 verification_serveur();  
			  }
         });  
   
   });  
 //function to check username availability  
 function verification_serveur(){  
   
         //get the username  
         var ip = $('#ip').val();
		 var port = $('#port').val();
		 
   
         //utilisation d'ajax pour faire le test de la présence d'un serveur de jeu possédant cette ip et étant encore sous contrat  
         $.post("/validation/validerServeur.php", { ip: ip, port: port},  
             function(result){  
                 if(result == 1)
				 {  
               
                     $('#status_ip').html('<img src="/images/accept.png" height="16" width="16" /> Le serveur est noté comme disponible dans notre base de données ');  
                 }
				 else
				 {  
                    $('#status_ip').html('<img src="/images/accept.png" height="16" width="16" /> Le serveur est noté comme disponible dans notre base de données ');  
					//$('#status_ip').html('<img src="images/cross.png" height="16" width="16" /> Le serveur est encore sous un autre contrat, veuillez consultez la <a href="FAQ.php">FAQ</a> svp ');  
                 }  
         });

  
 }  		 