<?php
header('Content-Type: text/html; charset=utf-8');
require 'database.inc.php';
if (Test_User($lg_user, $lg_password) == TRUE) {
  $ligne = Client::getClientByNoClient($NoClient);
  $result = "";
  if ($Mode == 5) {
    $result .= "document.forms['$Form'].NoClient2.value = '" . $ligne['NoClient'] . "';";
    $result .= "document.forms['$Form'].Nom2.value = '" . addslashes($ligne['Nom']) . "';";
    $result .= "document.forms['$Form'].Prenom2.value = '" . addslashes($ligne['Prenom']) . "';";
  } else {
    $result .= "document.forms['$Form'].NoClient.value = '" . $ligne['NoClient'] . "';";
    $result .= "document.forms['$Form'].Nom.value = '" . addslashes($ligne['Nom']) . "';";
    $result .= "document.forms['$Form'].Prenom.value = '" . addslashes($ligne['Prenom']) . "';";
  }
  if ($Mode < 3) {
    if (!empty($ligne['Natel'])) {
      $result .= "document.forms['$Form'].Telephone.value = '" . $ligne['Natel'] . "';";
    } else if (!empty($ligne['TelPriv'])) {
      $result .= "document.forms['$Form'].Telephone.value = '" . $ligne['TelPriv'] . "';";
    } else if (!empty($ligne['TelProf'])) {
      $result .= "document.forms['$Form'].Telephone.value = '" . $ligne['TelProf'] . "';";
    } else {
      $result .= "document.forms['$Form'].Telephone.value = '';";
    }
  }
  switch ($Mode) {
    case 2:
      $result .= "efface_vhc();";
      $result .= "recherche_vhc_ajax(0);";
      break;
    case 4:
      $result .= "recherche_vhc_ajax(1);";
      break;
    default:
      $result .= "$('#dialog').dialog('close');";
      break;
  }
  echo $result;
}
