$(document).ready(function() {

  value = new Array();

  $(".in_form").each(function() {
    initInput($(this));
  });

  $('#title').bind("keyup",function(e) {
    $('#annonce_title').html($('#title').val());
  });
  $('#ligne1').bind("keyup",function(e) {
    $('#annonce_ligne1').html($('#ligne1').val());
  });
  $('#ligne2').bind("keyup",function(e) {
    $('#annonce_ligne2').html($('#ligne2').val());
  });
  $('#url').bind("keyup",function(e) {
    $('#annonce_url').html($('#url').val());
  });
});

function initInput(id) {
  value[id.attr('id')] = id.val();
  id.bind("focus",function(e) {
    id.addClass('normal');
    if(id.val() == value[id.attr('id')]) {
      id.val('');
    }
  });
  $(id).bind("blur",function(e) {
    if($(id).val() == '') {
      $(id).val(value[id.attr('id')]);
      id.removeClass('normal');
    }
  });
}

function checkTest(B) {
  var E=true;
  for(var C=0;C<B.length;C++){
    var id = B[C];
    var A = $('#'+id);
    if(A.val() == value[id] || A.val() == '') {
      document.getElementById(id).style.backgroundColor="#ffffcc";
      //if(E)
        //document.getElementById(id).focus();
      E = false;
    }
    else {
      document.getElementById(id).style.backgroundColor="#ffffff";
    }
  }

  if(!E) {
    alert('Merci de completer l\'ensemble des champs demandes');
  }

  return E;
}

function checkRequired(D,B){
  var E=true;
  for(var C=0;C<B.length;C++){
    var A=D[B[C]];
    if(!A){continue}
    if(!A.value){
      A.style.backgroundColor="#ffffcc";
      if(E){
        A.focus()
      }
      E=false
    }
    else{A.style.backgroundColor="white"}
  }
  if(!E) {
    alert('Merci de completer l\'ensemble des champs demandes');
  }
  return E;
}