$(document).ready(function(){

$('input[type=text],input[type=password]').focus(function(){
  
  if(!$(this).data('value')){
    $(this).data('value',$(this).attr('value'));
    $(this).attr('value','');
    }
    
  }).blur(function(){
  if($(this).attr('value')==''){
    $(this).attr('value',$(this).data('value'));
    }
  
  });


$('#condition div a').click(function(){$('#condition').css('display','none');$('#ID_GROUP').css('visibility','');});
$('#openc').click(function(){

  //if(jQuery.browser.msie && jQuery.browser.version.substr(0,1)=="6"){$('#lastpost').css('margin-top','-318px');}
  
  if($('#condition').css('display')=='none'){
    $('#condition').css('display','block');
    $('#ID_GROUP').css('visibility','hidden'); 
    }
  else {
    $('#condition').css('display','none');
    $('#ID_GROUP').css('visibility','');
    }
  
  });

$('.password').each(function(){
  var html=$(this).html();
  var val=$(this).children('input').attr('value');
  
  html=html.replace(/type\=\"password\"/g,'type="text"');  
  html=html.replace(/type\=password/g,'type=text');
  html=html.replace(/value\=\"[^\"]*\"/g,'value="'+val+'"');
  $(this).replaceWith('<div class="password">'+html+'</div>');
  });

 
$('.password input').focus(function(){  
  var html=$(this).parent('div').html();
  
  var index=$('.password input').index($(this));
  html=html.replace(/type\=\"text\"/g,'');
  html=html.replace(/>/g,' type="password" />');  
  html=html.replace(/value\=\"[^\"]*\"/g,'value=""');
  $(this).replaceWith(html);
  
  $('.password input').eq(index).focus();
  });


$('#creator').submit(function(){

var erreur='';

if($('#user').attr('value').length<2)
  {
  var erreur=erreur+'- Votre Pseudo est invalide\r\n';

  }


var new_string = new String($('#email').attr('value'));  
if($('#email').attr('value').length<2 || !new_string.match("^[_\.0-9a-zA-Z-]*@[-_\.0-9a-zA-Z-]*[\.][0-9a-zA-Z]{2,5}$"))
  {
  var erreur=erreur+'- Votre Email est invalide\r\n';
  }

  
if($('#passwrd1').attr('value').length<4)
  {
  var erreur=erreur+'- Votre mot de passe est trop court (minimum 4 charactère)\r\n';
  }

if($('#passwrd2').attr('value').length<4)
  {
  var erreur=erreur+'- Votre "retaper" est trop court (minimum 4 charactère)\r\n';
  }
  
if($('#passwrd2').attr('value')!=$('#passwrd1').attr('value'))
  {
  var erreur=erreur+'- Votre mot de passe n\'est pas identique au "retaper" est invalide\r\n';
  }
  
if($('#regagree').attr('checked')!=true)
  {
  var erreur=erreur+'- Veuillez lire les conditions d\'utilisation et cocher la case en rapport\r\n';
  }

if(erreur){alert(erreur); return false;}
else {return true;}
});

});

