/* Fonction used by the opportunity's send mail overlay.
 * See the coproperty view. */

function opportunity_send_by_mail_overlay() {
  var mailfrom = $('#opportunity_mail_overlay_mailfrom').val();
  var mailto = $('#opportunity_mail_overlay_mailto').val();
  var errors = '';

  if (string_is_empty(mailfrom)) {
    errors += 'Votre adresse courriel est obligatoire.<br />';
  } else if (email_is_not_valid(mailfrom)) {
    errors += 'Votre adresse courriel n\'est pas valide.<br />';
  }
  if (string_is_empty(mailto)) {
    errors += 'L\'adresse courriel du destinataire est obligatoire.<br />';
  } else if (email_is_not_valid(mailto)) {
    errors += 'L\'adresse courriel du destinataire n\'est pas valide.<br />';
  }
  
  var div_errors = $('#opportunity_mail_overlay_errors');
  if (errors != '') {
    div_errors.html(errors);
    div_errors.show();
    return false;
  } else {
    div_errors.html('');
    div_errors.hide();
    return true;
  }
}

/* Fonction used by the "ask for phone call" overlay.
 * See master.cpt */
function phone_overlay() {
  var lastname = $('#phone_overlay_lastname').val();
  var firstname = $('#phone_overlay_firstname').val();
  var phonenumber = $('#phone_overlay_phonenumber').val();
  var slot = $('#phone_overlay_slot').val();
  var errors = '';

  if (string_is_empty(lastname)) {
    errors += 'Le champ "Nom" est obligatoire.<br />';
  } 
  if (string_is_empty(firstname)) {
    errors += 'Le champ "Prénom" est obligatoire.<br />';
  }
  if (string_is_empty(phonenumber)) {
    errors += 'Le champ "Téléphone" est obligatoire.<br />';
  } 
  if (string_is_empty(slot)) {
    errors += 'Le champ "Quand ?" est obligatoire.<br />';
  }
  
  var div_errors = $('#phone_overlay_errors');
  if (errors != '') {
    div_errors.html(errors);
    div_errors.show();
    return false;
  } else {
    div_errors.html('');
    div_errors.hide();
    return true;
  }
}

