/**************************************************************************
<MODULE NAME>
<FILENAME> scr_urne.c </FILENAME>
<HISTORY>
  <MODIFICATION>
<DATE> 060219 </DATE>
<AUTHOR>  </AUTHOR>
<DESCRIPTION>
The screens of the "ballot box" (urne)
</DESCRIPTION>
</MODIFICATION>
</HISTORY>
</MODULE NAME>
**************************************************************************/


/**************************************************************************
INCLUDE FILES
**************************************************************************/
#include <bios.h>
#include <io.h>
#include <fcntl.h>
#include <alloc.h>
#include <dos.h>
#include <conio.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <graphics.h>
#include "..\comp\graph\scr_urne.h"

/**************************************************************************
STATIC VARIABLES
**************************************************************************/
static int iX_V,   iY_V;
static int iX_H,   iY_H;
static int iX_I,   iY_I;
static int iX_C,   iY_C;
static int iX_B,   iY_B;
static int iX_D,   iY_D;
static int iX_SU,  iY_SU;
static int iX_SV,  iY_SV;
static int iX_OU,  iY_OU;
static int iX_OV,  iY_OV;
static int iX_CT,  iY_CT;
static int iX_CN,  iY_CN;
static int iX_CE,  iY_CE;
static int iX_CNX, iY_CNX;
static int iX_CEX, iY_CEX;
static int iX_VP,  iY_VP;
static int iX_VD,  iY_VD;
static int iX_PWD, iY_PWD;
static int iX_OG,  iY_OG;

static char sz_OG_LastValue[61] = {"\0"};

static int iX_OB,  iY_OB;
static int iValidatorStartY;
static char szBuff[32] = {"\0"};
static char szVersion[32] = {"\0"};
static char sz_V_LastValue[41] = {"\0"};
static char szHw[32] = {"\0"};
static char sz_H_LastValue[41] = {"\0"};
static char szId[32] = {"\0"};
static char sz_I_LastValue[41] = {"\0"};
static char szCommune[32] = {"\0"};
static char sz_C_LastValue[41] = {"\0"};
static char szBureau[32] = {"\0"};
static char sz_B_LastValue[41] = {"\0"};
static char szDate[32] = {"\0"};
static char sz_D_LastValue[41] = {"\0"};
static char szCarteEnreg[32] = {"\0"};
static char szCarteEnreg_Tot[32] = {"\0"};
static char sz_CT_LastValue[41] = {"\0"};
static char szCarteEnreg_Nat[32] = {"\0"};
static char sz_CN_LastValue[41] = {"\0"};
static char sz_CNX_LastValue[41] = {"\0"};
static char szCarteEnreg_Etr[32] = {"\0"};
static char sz_CE_LastValue[41] = {"\0"};
static char sz_CEX_LastValue[41] = {"\0"};
static char szValidProchaine[32] = {"\0"};
static char sz_VP_LastValue[41] = {"\0"};
static char szValidDerniere[32] = {"\0"};
static char sz_VD_LastValue[41] = {"\0"};
static char szUrne[32] = {"\0"};
static char sz_SU_LastValue[41] = {"\0"};
static char sz_OU_LastValue[41] = {"\0"};
static char szValidator[32] = {"\0"};
static char sz_SV_LastValue[41] = {"\0"};
static char sz_OV_LastValue[41] = {"\0"};
static char szPassword[32] = {"\0"};
//static char szFermeture[32] = {"\0"};
static char szRecomptage[32] = {"\0"};
static char szMulti;

/**************************************************************************
FUNCTION PROTOTYPES
**************************************************************************/
extern void  Wait_Loop(int);

/**************************************************************************
MACROS
**************************************************************************/
#define BORDURE            2
#define _HEIGHT          479
#define _WIDTH           639
#define TOP_HEIGHT        60
#define URNE_HEIGHT      180
#define VALIDATOR_HEIGHT 180

#define SET_FONT_TOP \
  settextstyle(DEFAULT_FONT, HORIZ_DIR, 1);

#define SET_FONT \
  settextstyle(DEFAULT_FONT, HORIZ_DIR, 1);

#define SET_FONT_CPT \
  settextstyle(DEFAULT_FONT, HORIZ_DIR, 2);

#define SET_FONT_STATUS \
  settextstyle(DEFAULT_FONT, HORIZ_DIR, 2);

#define SET_FONT_RECOMPT \
  settextstyle(DEFAULT_FONT, HORIZ_DIR, 2);

#define BAR_OUTPUT(WHICH, COLOR) \
void Bar_##WHICH(int _x1, int _y1, int _x2, int _y2) \
{ \
  static int x1, x2, y1, y2, color; \
  if(_x1) \
  { \
    x1 = _x1; \
    x2 = _x2; \
    y1 = _y1; \
    y2 = _y2; \
    color = COLOR; \
  } \
  setfillstyle(SOLID_FILL, color); \
  bar(x1, y1, x2, y2); \
  if(color == DARKGRAY) \
  { \
    setcolor(BLACK); \
    line(x1, y1, x1, y2); \
    line(x1, y1, x2, y1); \
    setcolor(LIGHTGRAY); \
    line(x2, y1, x2, y2); \
    line(x1, y2, x2, y2); \
  } \
  else \
  { \
    if(color == BLACK) \
    { \
      setcolor(BLACK); \
      line(x1, y1, x1, y2); \
      line(x1, y1, x2, y1); \
      setcolor(DARKGRAY); \
      line(x2, y1, x2, y2); \
      line(x1, y2, x2, y2); \
    } \
  } \
}

#define UPD_OUTPUT(WHICH) \
void Upd_##WHICH(char *_pzBuff) \
{ \
  Bar_##WHICH(0,0,0,0); \
  Print_String(iX_##WHICH, iY_##WHICH, _pzBuff, WHITE, CENTER_TEXT); \
}

/**************************************************************************
<FUNCTION>
  <NAME> Remove_Blanks </NAME>
  <TYPE> LOCAL </TYPE>
  <DESCRIPTION>
  Remove blanks "    this is a string    " -> "this is a string"
  </DESCRIPTION>
  <PARAMETERS>
    <PARAMETER>
      <NAME> _str_before </NAME>
      <TYPE> char * </TYPE>
      <IO> IN </ IO >
      <DESCRIPTION>
      The string with blanks
      </DESCRIPTION>
    </PARAMETER>
    <PARAMETER>
      <NAME> _str_after </NAME>
      <TYPE> char </TYPE>
      <IO> OUT </ IO >
      <DESCRIPTION>
      The string without blanks
      </DESCRIPTION>
    </PARAMETER>
  </PARAMETERS>
</FUNCTION>
**************************************************************************/
void Remove_Blanks(char *_str_before, char _str_after[128])
{
	int i, j, ln;

	ln = strlen(_str_before);
	memset(_str_after, 0x00, 128);
	j = 0;

	/* Left */
	for(i=0; i<ln; ++i)
	{
		if(_str_before[i] != ' ' || _str_after[0])
			_str_after[j++] = _str_before[i];
	}

	/* Right */
	ln = strlen(_str_after);
	for(i=ln-1; i>-1; --i)
	{
		if(_str_after[i] == ' ')
			_str_after[i] = 0x00;
		else
			break;
	}
}

/**************************************************************************
<FUNCTION>
  <NAME> Init_Msg </NAME>
  <TYPE> GLOBAL </TYPE>
  <DESCRIPTION>
  Initialization of output strings (Labels)
  </DESCRIPTION>
  <PARAMETERS>
    <PARAMETER>
      <NAME> _iLg </NAME>
      <TYPE> int </TYPE>
      <IO> IN </ IO >
      <DESCRIPTION>
      Specifies the language (1-> French, 2-> Dutch)
      </DESCRIPTION>
    </PARAMETER>
    <PARAMETER>
      <NAME> _iNb </NAME>
      <TYPE> int </TYPE>
      <IO> IN </ IO >
      <DESCRIPTION>
      The number of ballots (if 1 -> only one type of voter)
      </DESCRIPTION>
    </PARAMETER>
  </PARAMETERS>
</FUNCTION>
**************************************************************************/
void Init_Msg(int _iLg, int _iNb)
{
  if(_iNb != 1)
    szMulti = 1;
  else
    szMulti = 0;

  switch(_iLg)
  {
    case 1:
      strcpy(szVersion,  "Version:  ");
      strcpy(szHw, "Hardware:  ");
      strcpy(szId, "Id:  ");
      strcpy(szCommune, "Commune:  ");
      strcpy(szBureau, "Bureau:  ");
      strcpy(szDate, "Date:  ");
      strcpy(szCarteEnreg, "Carte(s) enregistree(s)");
      strcpy(szCarteEnreg_Tot, "ToTal");
      strcpy(szCarteEnreg_Nat, "Belge");
      strcpy(szCarteEnreg_Etr, "Etranger");
      strcpy(szValidProchaine, "Prochaine Validation");
      strcpy(szValidDerniere,  "Derniere Validation");
      strcpy(szUrne, "Urne");
      strcpy(szValidator, "Valideuse");
      strcpy(szPassword, "Mot de passe");
      strcpy(szRecomptage, "Mode Recomptage");
      break;
    case 2:
      strcpy(szVersion,  "Versie:  ");
      strcpy(szHw, "Hardware:  ");
      strcpy(szId, "Id:  ");
      strcpy(szCommune, "Gemeente:  ");
      strcpy(szBureau, "Bureau:  ");
      strcpy(szDate, "Datum:  ");
      strcpy(szCarteEnreg, "Aantal kaarten in de stembus");
      strcpy(szCarteEnreg_Tot, "Totaal");
      strcpy(szCarteEnreg_Nat, "Belg");
      strcpy(szCarteEnreg_Etr, "Niet-Belg");
      strcpy(szValidProchaine, "Volgende validering");
      strcpy(szValidDerniere,  "Vorige validering");
      strcpy(szUrne, "Stembus");
      strcpy(szValidator, "Validering");
      strcpy(szPassword, "Geef uw code in");
      strcpy(szRecomptage, "Hertellen");
      break;
    case 3:
      strcpy(szVersion,  "Version:  ");
      strcpy(szHw, "Hardware:  ");
      strcpy(szId, "Id:  ");
      strcpy(szCommune, "Commune:  ");
      strcpy(szBureau, "Bureau:  ");
      strcpy(szDate, "Date:  ");
      strcpy(szCarteEnreg, "Carte(s) enregistree(s)");
      strcpy(szCarteEnreg_Tot, "ToTal");
      strcpy(szCarteEnreg_Nat, "Belge");
      strcpy(szCarteEnreg_Etr, "Etranger");
      strcpy(szValidProchaine, "Prochaine Validation");
      strcpy(szValidDerniere,  "Derniere Validation");
      strcpy(szUrne, "Urne");
      strcpy(szValidator, "Valideuse");
      strcpy(szPassword, "Mot de passe");
      strcpy(szRecomptage, "Mode Recomptage");
      break;
  }
}

/**************************************************************************
<FUNCTION>
  <NAME> Init_Graph </NAME>
  <TYPE> GLOBAL </TYPE>
  <DESCRIPTION>
  Initialization of the graphical mode (drivers, fonts, ...)
  </DESCRIPTION>
</FUNCTION>
**************************************************************************/
void Init_Graph(void)
{
  int GraphDriver = 9;  /* The Graphics device driver */
  int GraphMode = 2;    /* The Graphics mode value    */

  registerbgidriver(EGAVGA_driver);
  registerbgifont(small_font);
  registerbgifont(sansserif_font);
  initgraph( &GraphDriver, &GraphMode, "" );
}

/**************************************************************************
<FUNCTION>
  <NAME> Draw_Rect </NAME>
  <TYPE> GLOBAL </TYPE>
  <DESCRIPTION>
  </DESCRIPTION>
  <PARAMETERS>
    <PARAMETER>
      <NAME> _iX1,_iX2,_iY1,_iY2 </NAME>
      <TYPE> int </TYPE>
      <IO> IN </ IO >
      <DESCRIPTION>
      The coordinates of the rectangle
      </DESCRIPTION>
    </PARAMETER>
    <PARAMETER>
      <NAME> _iCol </NAME>
      <TYPE> int </TYPE>
      <IO> IN </ IO >
      <DESCRIPTION>
      The color id
      </DESCRIPTION>
    </PARAMETER>
  </PARAMETERS>
</FUNCTION>
**************************************************************************/
void Draw_Rect(int _iX1 , int _iX2 , int _iY1 , int _iY2, int _iCol)
{
  setcolor(_iCol) ;
  rectangle(_iX1 , _iY1 , _iX2 , _iY2) ;
}

/**************************************************************************
<FUNCTION>
  <NAME> Print_String </NAME>
  <TYPE> GLOBAL </TYPE>
  <DESCRIPTION>
  Displays a string
  </DESCRIPTION>
  <PARAMETERS>
    <PARAMETER>
      <NAME> _iX, _iY </NAME>
      <TYPE> int </TYPE>
      <IO> IN </ IO >
      <DESCRIPTION>
      Coordinates
      </DESCRIPTION>
    </PARAMETER>
    <PARAMETER>
      <NAME> _pzBuff </NAME>
      <TYPE> char * </TYPE>
      <IO> IN </ IO >
      <DESCRIPTION>
      The string to display
      </DESCRIPTION>
    </PARAMETER>
    <PARAMETER>
      <NAME> _iColor </NAME>
      <TYPE> int </TYPE>
      <IO> IN </ IO >
      <DESCRIPTION>
      Color id
      </DESCRIPTION>
    </PARAMETER>
    <PARAMETER>
      <NAME> _iMode </NAME>
      <TYPE> int </TYPE>
      <IO> IN </ IO >
      <DESCRIPTION>
      LEFT_TEXT, CENTER_TEXT
      </DESCRIPTION>
    </PARAMETER>
  </PARAMETERS>
</FUNCTION>
**************************************************************************/
void Print_String(int _iX, int _iY, char *_pzBuff, int _iColor, int _iMode)
{
  setcolor(_iColor);
  settextjustify(_iMode, CENTER_TEXT);
  outtextxy(_iX, _iY, _pzBuff);
}

/*
void Bar_CT(int _x1, int _y1, int _x2, int _y2) -> draws a bar (background area)
void Upd_CT(char *_pzBuff) -> calls Bar_CT() + Print_String(CT, ...)
void Bar_CE()
void Upd_CE()
idem ... for all the variable strings
To update a text: 1) clear background
                  2) write text
*/
BAR_OUTPUT(CT,  8)      UPD_OUTPUT(CT)
BAR_OUTPUT(CE,  8)      UPD_OUTPUT(CE)
BAR_OUTPUT(CEX, 8)      UPD_OUTPUT(CEX)
BAR_OUTPUT(CN,  8)      UPD_OUTPUT(CN)
BAR_OUTPUT(CNX, 8)      UPD_OUTPUT(CNX)
BAR_OUTPUT(OU,  8)      UPD_OUTPUT(OU)
BAR_OUTPUT(SU,  WHITE)  UPD_OUTPUT(SU)
BAR_OUTPUT(OV,  8)      UPD_OUTPUT(OV)
BAR_OUTPUT(SV,  WHITE)  UPD_OUTPUT(SV)
BAR_OUTPUT(VP,  8)      UPD_OUTPUT(VP)
BAR_OUTPUT(VD,  8)      UPD_OUTPUT(VD)
BAR_OUTPUT(PWD, WHITE)  UPD_OUTPUT(PWD)
BAR_OUTPUT(PWD2,WHITE)
BAR_OUTPUT(OG,  8)      UPD_OUTPUT(OG)
BAR_OUTPUT(OB,  WHITE)  UPD_OUTPUT(OB)


/**************************************************************************
<FUNCTION>
  <NAME> ScreenU_Base </NAME>
  <TYPE> GLOBAL </TYPE>
  <DESCRIPTION>
  Just one output area (at the middle of the screen)
  </DESCRIPTION>
  <PARAMETERS>
    <PARAMETER>
      <NAME>  </NAME>
      <TYPE>  </TYPE>
      <IO> IN | OUT | INOUT</ IO >
      <DESCRIPTION>
      </DESCRIPTION>
    </PARAMETER>
  </PARAMETERS>
  <RETURNS>
    <TYPE>  </TYPE>
    <DESCRIPTION>
    </DESCRIPTION>
  </RETURNS>
</FUNCTION>
**************************************************************************/
void ScreenU_Base(void)
{
  iX_OB = _WIDTH/2;
  iY_OB = _HEIGHT/2;

  Bar_OB(BORDURE*2, iY_OB-10, _WIDTH-BORDURE*2, iY_OG-20);
}


/**************************************************************************
<FUNCTION>
  <NAME> ScreenU_Validator_Top </NAME>
  <TYPE> GLOBAL </TYPE>
  <DESCRIPTION>
  Title + Status Area + Output Area (for the "ballot box" and the validator)
  </DESCRIPTION>
  <PARAMETERS>
    <PARAMETER>
      <NAME> _iType </NAME>
      <TYPE>  </TYPE>
      <IO> IN </ IO >
      <DESCRIPTION>
      "Ballot box" or Validator
      </DESCRIPTION>
    </PARAMETER>
  </PARAMETERS>
    <PARAMETER>
      <NAME> _piY </NAME>
      <TYPE> int * </TYPE>
      <IO> INOUT </ IO >
      <DESCRIPTION>
      Input:  the Y coord from where we can start drawing
      Output: the Y coord til where we have drawn
      </DESCRIPTION>
    </PARAMETER>
  </PARAMETERS>
  <RETURNS>
    <TYPE>  </TYPE>
    <DESCRIPTION>
    </DESCRIPTION>
  </RETURNS>
</FUNCTION>
**************************************************************************/
void ScreenU_Validator_Top(int _iType, int *_piY)
{
  int y;

  /* Font */
  SET_FONT

  /* Title */
  y = (*_piY) + 25;

  if(!_iType) /* Urne */
  {
    /* Status */
    iY_SU = y;
    Print_String(_WIDTH/2, iY_SU, szUrne, BLACK, CENTER_TEXT);
    Draw_Rect((_WIDTH/2)-120, (_WIDTH/2)+120, y-10, y+10, BLACK);
    Bar_SU((_WIDTH/2)+130, y-10, _WIDTH-20, y+10);
    iX_SU = (_WIDTH/2)+140;
    ScreenU_WriteText(SU, "");
    ScreenU_WriteText(SU, sz_SU_LastValue);

    /* Output */
    iX_OU = _WIDTH/2;
    iY_OU = y+40;

    Bar_OU(20, iY_OU-10, _WIDTH-20, iY_OU+10);
    (*_piY) = iY_OU+40;
  }
  else /* Validator */
  {
    /* Status */
    iY_SV = y;
    Print_String(_WIDTH/2, iY_SV, szValidator, BLACK, CENTER_TEXT);
    Draw_Rect((_WIDTH/2)-120, (_WIDTH/2)+120, y-10, y+10, BLACK);
    Bar_SV((_WIDTH/2)+130, y-10, _WIDTH-20, y+10);
    iX_SV = (_WIDTH/2)+140;
    ScreenU_WriteText(SV, "");
    ScreenU_WriteText(SV, sz_SV_LastValue);

    /* Output */
    iX_OV = _WIDTH/2;
    iY_OV = y+40;

    Bar_OV(20, iY_OV-10, _WIDTH-20, iY_OV+10);
    (*_piY) = iY_OV+40;
  }
}

/**************************************************************************
<FUNCTION>
  <NAME> ScreenU_Top </NAME>
  <TYPE> GLOBAL </TYPE>
  <DESCRIPTION>
  The top screen (Version, date ...)
  </DESCRIPTION>
  <PARAMETERS>
    <PARAMETER>
      <NAME>  </NAME>
      <TYPE>  </TYPE>
      <IO> IN | OUT | INOUT</ IO >
      <DESCRIPTION>
      </DESCRIPTION>
    </PARAMETER>
  </PARAMETERS>
  <RETURNS>
    <TYPE>  </TYPE>
    <DESCRIPTION>
    </DESCRIPTION>
  </RETURNS>
</FUNCTION>
**************************************************************************/
void ScreenU_Top(void)
{
  int iWidthElt;

  /* Font */
  SET_FONT_TOP

  iWidthElt = (_WIDTH - 2*BORDURE)/3;
  Draw_Rect(BORDURE, _WIDTH-BORDURE, BORDURE, TOP_HEIGHT, BLACK);

  /* Version, Hardware, Id */
  /* Separation Lines */
  line(iWidthElt, BORDURE, iWidthElt, BORDURE+TOP_HEIGHT/2);
  line(iWidthElt*2, BORDURE, iWidthElt*2, BORDURE+TOP_HEIGHT/2);
  line(BORDURE, BORDURE+TOP_HEIGHT/2, _WIDTH-BORDURE, BORDURE+TOP_HEIGHT/2);
  /* Version */
  iX_V = BORDURE*3;
  Print_String(iX_V, BORDURE+TOP_HEIGHT/4, szVersion, BLACK, LEFT_TEXT);
  iY_V = BORDURE+TOP_HEIGHT/4;
  /* HW */
  iX_H = BORDURE*2 + iWidthElt;
  Print_String(iX_H, BORDURE+TOP_HEIGHT/4, szHw, BLACK, LEFT_TEXT);
  iY_H = iY_V;
  /* ID */
  iX_I = BORDURE*2+ iWidthElt*2;
  Print_String(iX_I, BORDURE+TOP_HEIGHT/4, szId, BLACK, LEFT_TEXT);
  iY_I = iY_V;

  /* Commune */
  iX_C = iX_V;
  iY_C = iY_V + TOP_HEIGHT/2;
  Print_String(iX_C, iY_C, szCommune, BLACK, LEFT_TEXT);
  /* Bureau */
  iX_B = iX_H;
  iY_B = iY_C;
  Print_String(iX_B, iY_B, szBureau, BLACK, LEFT_TEXT);
  /* Date */
  iX_D = iX_I;
  iY_D = iY_C;
  Print_String(iX_D, iY_D, szDate, BLACK, LEFT_TEXT);

  /* Values */
  ScreenU_WriteText(V, sz_V_LastValue);
  ScreenU_WriteText(H, sz_H_LastValue);
  ScreenU_WriteText(I, sz_I_LastValue);
  ScreenU_WriteText(C, sz_C_LastValue);
  ScreenU_WriteText(B, sz_B_LastValue);
  ScreenU_WriteText(D, sz_D_LastValue);
}

/**************************************************************************
<FUNCTION>
  <NAME> ScreenU_Tot_Cards </NAME>
  <TYPE> GLOBAL </TYPE>
  <DESCRIPTION>
  Displays the counters (Total, National, Stranger)
  </DESCRIPTION>
  <PARAMETERS>
    <PARAMETER>
      <NAME> _iType </NAME>
      <TYPE> int </TYPE>
      <IO> IN </ IO >
      <DESCRIPTION>
      1 -> tot (nationals + strangers)
      2 -> nationals
      3 -> strangers
      </DESCRIPTION>
    </PARAMETER>
    <PARAMETER>
      <NAME> _iY </NAME>
      <TYPE> int </TYPE>
      <IO> IN </ IO >
      <DESCRIPTION>
      The Y coord from where we can start drawing
      </DESCRIPTION>
    </PARAMETER>
  </PARAMETERS>
  <RETURNS>
    <TYPE>  </TYPE>
    <DESCRIPTION>
    </DESCRIPTION>
  </RETURNS>
</FUNCTION>
**************************************************************************/
void ScreenU_Tot_Cards(int _iType, int _iY)
{
  int x = (_WIDTH/4)*_iType;

  /* Font */
  SET_FONT

  switch(_iType)
  {
    case 1:
      Print_String(x, _iY+10, szCarteEnreg_Tot, BLACK, CENTER_TEXT);
      iX_CT = x;
      iY_CT = _iY+40;
      /* Frame */
      Bar_CT(x-50, iY_CT-15, x+50, iY_CT+15);
      /* Value */
      ScreenU_WriteText(CT, sz_CT_LastValue);
      break;

    case 2:

      if(szMulti) /* Several types of voter */
      {
        Print_String(x, _iY-10, szCarteEnreg, BLACK, CENTER_TEXT);
        Print_String(x, _iY+10, szCarteEnreg_Nat, BLACK, CENTER_TEXT);
      }
      else
      {
        Print_String(x, _iY, szCarteEnreg, BLACK, CENTER_TEXT);
      }
      iX_CN = x;
      iY_CN = _iY+40;
      /* Frame */
      Bar_CN(x-50, iY_CN-15, x+50, iY_CN+15);
      /* Value */
      if(szMulti) /* Several types of voter */
      {
        ScreenU_WriteText(CN, sz_CN_LastValue);
      }
      else
      {
        ScreenU_WriteText(CT, sz_CN_LastValue);
      }
      /* Check */
      if(szMulti) /* Several types of voter */
      {
        iX_CNX = x+70;
        iY_CNX = iY_CN+7;
        Bar_CNX(x+60, iY_CN-5, x+80, iY_CN+15);
        /* Value */
        ScreenU_WriteText(CNX, sz_CNX_LastValue);
      }
      break;

    case 3:
      Print_String(x, _iY+10, szCarteEnreg_Etr, BLACK, CENTER_TEXT);
      iX_CE = x;
      iY_CE = _iY+40;
      /* Frame */
      Bar_CE(x-50, iY_CE-15, x+50, iY_CE+15);
      /* Value */
      ScreenU_WriteText(CE, sz_CE_LastValue);
      /* Check */
      iX_CEX = x+70;
      iY_CEX = iY_CN+7;
      Bar_CEX(x+60, iY_CN-5, x+80, iY_CN+15);
      /* Value */
      ScreenU_WriteText(CEX, sz_CEX_LastValue);
      break;
  }
}

/**************************************************************************
<FUNCTION>
  <NAME> ScreenU_Validation </NAME>
  <TYPE> GLOBAL </TYPE>
  <DESCRIPTION>
  Displays the type of validations (previous and next one)
  </DESCRIPTION>
  <PARAMETERS>
    <PARAMETER>
      <NAME> _iType </NAME>
      <TYPE> int </TYPE>
      <IO> IN </ IO >
      <DESCRIPTION>
      _iType == 1 -> next validation type
      _iType == 2 -> previous validation type
      </DESCRIPTION>
    </PARAMETER>
    <PARAMETER>
      <NAME> _iY </NAME>
      <TYPE> int </TYPE>
      <IO> IN </ IO >
      <DESCRIPTION>
      The Y coord from where we can start drawing
      </DESCRIPTION>
    </PARAMETER>
  </PARAMETERS>
  <RETURNS>
    <TYPE>  </TYPE>
    <DESCRIPTION>
    </DESCRIPTION>
  </RETURNS>
</FUNCTION>
**************************************************************************/
void ScreenU_Validation(int _iType, int _iY)
{
  int x1 = 100;
  int x2 = (_WIDTH/4)*3;

  /* Font */
  SET_FONT

  switch(_iType)
  {
    case 1:
      iX_VP = x2;
      iY_VP = _iY;
      Print_String(x1, iY_VP, szValidProchaine, BLACK, LEFT_TEXT);
      /* Frame */
      Bar_VP(_WIDTH/2, iY_VP-10, _WIDTH-20, iY_VP+10);
      /* Value */
      ScreenU_WriteText(VP, sz_VP_LastValue);
      break;

    case 2:
      iX_VD = x2;
      iY_VD = _iY+40;
      Print_String(x1, iY_VD, szValidDerniere, BLACK, LEFT_TEXT);
      /* Frame */
      Bar_VD(_WIDTH/2, iY_VD-10, _WIDTH-20, iY_VD+10);
      /* Value */
      ScreenU_WriteText(VD, sz_VD_LastValue);
      break;
  }
}

/**************************************************************************
<FUNCTION>
  <NAME> ScreenU_Urne </NAME>
  <TYPE> GLOBAL </TYPE>
  <DESCRIPTION>
  Displays the ballot box's area
  </DESCRIPTION>
</FUNCTION>
**************************************************************************/
void ScreenU_Urne(void)
{
  int y;
  y = TOP_HEIGHT+BORDURE*2;
  Draw_Rect(BORDURE, _WIDTH-BORDURE, y, y+URNE_HEIGHT, BLACK);

  y += BORDURE;
  ScreenU_Validator_Top(0, &y);
  if(szMulti)
  {
    ScreenU_Tot_Cards(1, y);
    ScreenU_Tot_Cards(2, y);
    ScreenU_Tot_Cards(3, y);
  }
  else /* One type of voter */
  {
    ScreenU_Tot_Cards(2, y);
  }
}

/**************************************************************************
<FUNCTION>
  <NAME> ScreenU_Recompt </NAME>
  <TYPE> GLOBAL </TYPE>
  <DESCRIPTION>
  Displays the ballot box's area + recount mode
  </DESCRIPTION>
</FUNCTION>
**************************************************************************/
void ScreenU_Recompt(void)
{
  SET_FONT_RECOMPT
  Print_String(iX_PWD, (_HEIGHT/3)*2, szRecomptage, BLACK, CENTER_TEXT);
}

/**************************************************************************
<FUNCTION>
  <NAME> ScreenU_Validator </NAME>
  <TYPE> GLOBAL </TYPE>
  <DESCRIPTION>
  Displays the validator's area
  </DESCRIPTION>
</FUNCTION>
**************************************************************************/
void ScreenU_Validator(void)
{
  int y = iValidatorStartY;

  /* Reset Bottom */
  setfillstyle(SOLID_FILL,WHITE);
  bar(BORDURE, y, _WIDTH-BORDURE, y+VALIDATOR_HEIGHT);

  Draw_Rect(BORDURE, _WIDTH-BORDURE, y, y+VALIDATOR_HEIGHT, BLACK);

  y += BORDURE;
  if(!szMulti) /* One type of voter */
    y += 35;

  ScreenU_Validator_Top(1, &y);

  /* Validations */
  if(szMulti) /* Several types of voter */
  {
    ScreenU_Validation(1, y);
    ScreenU_Validation(2, y);
  }
}

/**************************************************************************
<FUNCTION>
  <NAME> ScreenU_Pwd </NAME>
  <TYPE> GLOBAL </TYPE>
  <DESCRIPTION>
  Displays the password's area
  </DESCRIPTION>
  <PARAMETERS>
    <PARAMETER>
      <NAME> _cType </NAME>
      <TYPE> char </TYPE>
      <IO> IN </ IO >
      <DESCRIPTION>
        -> SCR_START: PWD -> Middle of the screen
        -> SCR_URNE:  PWD -> Validator's area
      </DESCRIPTION>
    </PARAMETER>
  </PARAMETERS>
</FUNCTION>
**************************************************************************/
void ScreenU_Pwd(char _cType)
{
  int x1, y1, x2, y2;

  /* Font */
  SET_FONT

  iX_PWD = _WIDTH/2;
  if(_cType == SCR_START) iY_PWD = _HEIGHT/2;
  else if(_cType == SCR_URNE) iY_PWD = (_HEIGHT/3)*2;
  x1 = iX_PWD-100;
  y1 = iY_PWD-10;
  x2 = iX_PWD+100;
  y2 = iY_PWD+10;
  setfillstyle(SOLID_FILL, 8);
  bar3d(x1, y1, x2, y2, (x2-x1)/8, 1);
  Print_String(iX_PWD, iY_PWD, szPassword, WHITE, CENTER_TEXT);

  iY_PWD += 40;
  Bar_PWD(BORDURE*2, iY_PWD-10, _WIDTH-BORDURE*2, iY_PWD+5);
  Bar_PWD2(BORDURE*2, iY_PWD+10,_WIDTH-(BORDURE*2), iY_PWD+50);
}

/**************************************************************************
<FUNCTION>
  <NAME> ScreenU_Output_General </NAME>
  <TYPE> GLOBAL </TYPE>
  <DESCRIPTION>
  Displays the Output LineEdit (at the bottom of the screen)
  </DESCRIPTION>
</FUNCTION>
**************************************************************************/
void ScreenU_Output_General(void)
{
  iX_OG = _WIDTH/2;
  iY_OG = _HEIGHT-(_HEIGHT-(iValidatorStartY+VALIDATOR_HEIGHT))/2;

  Bar_OG(20, iY_OG-10, _WIDTH-20, iY_OG+10);
}

/**************************************************************************
<FUNCTION>
  <NAME> ScreenU_Clear_Middle </NAME>
  <TYPE> GLOBAL </TYPE>
  <DESCRIPTION>
  Clear the area which is used for displaying the password, the urne - validator...
  (= the middle of the screen)
  </DESCRIPTION>
</FUNCTION>
**************************************************************************/
void ScreenU_Clear_Middle(void)
{
  setfillstyle(SOLID_FILL,WHITE);
  bar(0,TOP_HEIGHT+2,_WIDTH,iY_OG-12);
}

/**************************************************************************
<FUNCTION>
  <NAME> ScreenU_Clear_Validator </NAME>
  <TYPE> GLOBAL </TYPE>
  <DESCRIPTION>
  Clear the area which is used by the validator
  </DESCRIPTION>
</FUNCTION>
**************************************************************************/
void ScreenU_Clear_Validator(void)
{
  setfillstyle(SOLID_FILL,WHITE);
  bar(0,iValidatorStartY-1,_WIDTH,iValidatorStartY+VALIDATOR_HEIGHT-1);
}

/**************************************************************************
<FUNCTION>
  <NAME> ScreenU </NAME>
  <TYPE> GLOBAL </TYPE>
  <DESCRIPTION>
  Displays the top and the bottom parts of the screen (of the "ballot box")
  (ready to write at the middle of the screen)
  </DESCRIPTION>
</FUNCTION>
**************************************************************************/
void ScreenU(void)
{
  iValidatorStartY = TOP_HEIGHT+URNE_HEIGHT+BORDURE*3;

  setfillstyle(SOLID_FILL,WHITE);
  bar(0,0,_WIDTH,_HEIGHT);

  ScreenU_Top();
  ScreenU_Output_General();
  ScreenU_Base(); /* Called after ScreenU_Output_General to know iY_OG */
}

/**************************************************************************
<FUNCTION>
  <NAME> ScreenU_WriteText </NAME>
  <TYPE> GLOBAL </TYPE>
  <DESCRIPTION>
  Displays a text at a specific position
  </DESCRIPTION>
  <PARAMETERS>
    <PARAMETER>
      <NAME> _iType </NAME>
      <TYPE> int </TYPE>
      <IO> IN </ IO >
      <DESCRIPTION>
      Specifies the nature of the text (-> it's position)
      </DESCRIPTION>
    </PARAMETER>
  </PARAMETERS>
</FUNCTION>
**************************************************************************/
void ScreenU_WriteText(int _iType, char *_szBuff)
{
  char buff[128];
  int i, j, l, y, iScreenType;

  if(!szMulti) /* One type of voter */
  {
    switch(_iType)
    {
      case CN:
      case CE:
      case CNX:
      case CEX:
      case VP:
      case VD:
        return;

      case CT:
        _iType = CN;
        break;
    }
  }

  /* Font */
  switch(_iType)
  {
    case V:
    case H:
    case I:
    case C:
    case B:
    case D:
      SET_FONT_TOP
      break;
    case OU:
    case OV:
    case VP:
    case VD:
    case PWD:
    case OB:
    case OG:
      SET_FONT
      break;
    case CT:
    case CN:
    case CNX:
    case CE:
    case CEX:
      SET_FONT_CPT
      break;
    case SU:
    case SV:
      SET_FONT_STATUS
      break;
  }

  /* Areas */
  switch(_iType)
  {
    case V:  /* Version */
      memset(szBuff, ' ', sizeof(szBuff));
      szBuff[strlen(szVersion)] = '\0';
      strcat(szBuff, _szBuff);
      Print_String(iX_V, iY_V, szBuff, 7, LEFT_TEXT);
      /* Keep in mind */
      strcpy(sz_V_LastValue, _szBuff);
      break;
    case H:  /* Hardware */
      memset(szBuff, ' ', sizeof(szBuff));
      szBuff[strlen(szHw)] = '\0';
      strcat(szBuff, _szBuff);
      Print_String(iX_H, iY_H, szBuff, 7, LEFT_TEXT);
      /* Keep in mind */
      strcpy(sz_H_LastValue, _szBuff);
      break;
    case I:  /* Id */
      memset(szBuff, ' ', sizeof(szBuff));
      szBuff[strlen(szId)] = '\0';
      strcat(szBuff, _szBuff);
      Print_String(iX_I, iY_I, szBuff, 7, LEFT_TEXT);
      /* Keep in mind */
      strcpy(sz_I_LastValue, _szBuff);
      break;
    case C:  /* Commune */
      memset(szBuff, ' ', sizeof(szBuff));
      szBuff[strlen(szCommune)] = '\0';
      strcat(szBuff, _szBuff);
      Print_String(iX_C, iY_C, szBuff, 7, LEFT_TEXT);
      /* Keep in mind */
      strcpy(sz_C_LastValue, _szBuff);
      break;
    case B:  /* Bureau */
      memset(szBuff, ' ', sizeof(szBuff));
      szBuff[strlen(szBureau)] = '\0';
      strcat(szBuff, _szBuff);
      Print_String(iX_B, iY_B, szBuff, 7, LEFT_TEXT);
      /* Keep in mind */
      strcpy(sz_B_LastValue, _szBuff);
      break;
    case D:  /* Date */
      memset(szBuff, ' ', sizeof(szBuff));
      szBuff[strlen(szDate)] = '\0';
      strcat(szBuff, _szBuff);
      Print_String(iX_D, iY_D, szBuff, 7, LEFT_TEXT);
      /* Keep in mind */
      strcpy(sz_D_LastValue, _szBuff);
      break;
    case SU: /* Status Urne */
      if(!strcmp(sz_SU_LastValue, _szBuff)) break;
      Bar_SU(0,0,0,0);
      Print_String(iX_SU, iY_SU, _szBuff, BLACK, LEFT_TEXT);
      /* Keep in mind */
      strcpy(sz_SU_LastValue, _szBuff);
      break;
    case SV: /* Status Validator */
      if(!strcmp(sz_SV_LastValue, _szBuff)) break;
      Bar_SV(0,0,0,0);
      Print_String(iX_SV, iY_SV, _szBuff, BLACK, LEFT_TEXT);
      /* Keep in mind */
      strcpy(sz_SV_LastValue, _szBuff);
      break;
    case OU: /* Output Urne */
      Remove_Blanks(_szBuff, buff);
      Upd_OU(buff);
      /* Keep in mind */
      strcpy(sz_OU_LastValue, buff);
      break;
    case OV: /* Output Validator */
      Remove_Blanks(_szBuff, buff);
      Upd_OV(buff);
      /* Keep in mind */
      strcpy(sz_OV_LastValue, buff);
      break;
    case CT: /* Nb cartes totales */
      Upd_CT(_szBuff);
      /* Keep in mind */
      strcpy(sz_CT_LastValue, _szBuff);
      break;
    case CN: /* Nb cartes nationales */
      Upd_CN(_szBuff);
      /* Keep in mind */
      strcpy(sz_CN_LastValue, _szBuff);
      break;
    case CE: /* Nb cartes etrangers */
      Upd_CE(_szBuff);
      /* Keep in mind */
      strcpy(sz_CE_LastValue, _szBuff);
      break;
    case CNX: /* Cartes nationales (last) */
      Upd_CNX(_szBuff);
      /* Keep in mind */
      strcpy(sz_CNX_LastValue, _szBuff);
      break;
    case CEX: /* Cartes etrangers (last)  */
      Upd_CEX(_szBuff);
      /* Keep in mind */
      strcpy(sz_CEX_LastValue, _szBuff);
      break;
    case VP: /* Prochaine Validation */
      Upd_VP(_szBuff);
      /* Keep in mind */
      strcpy(sz_VP_LastValue, _szBuff);
      break;
    case VD: /* Derniere Validation */
      Upd_VD(_szBuff);
      /* Keep in mind */
      strcpy(sz_VD_LastValue, _szBuff);
      break;
    case PWD: /* Password */
      Bar_PWD(0,0,0,0);
      Print_String(iX_PWD, iY_PWD, _szBuff, BLACK, CENTER_TEXT);
      break;
    case PWD2: /* Password (Second line <> Validation) */
      Bar_PWD2(0,0,0,0);
      Print_String(iX_PWD, iY_PWD+30, _szBuff, BLACK, CENTER_TEXT);
      break;
    case OG: /* Output General (bottom) */

      if(!strcmp(sz_OG_LastValue, _szBuff)) break;
      /* Keep in mind */
      strcpy(sz_OG_LastValue, _szBuff);

      Upd_OG(_szBuff);
      break;
    case OB: /* Output Base (middle of the screen) */
      iScreenType = GetVideoScreen();
      switch(iScreenType)
      {
        case SCR_START:
          Bar_OB(0,0,0,0);
          y = iY_OB;
          break;
        case SCR_URNE:
          ScreenU_Clear_Validator();
          y = (_HEIGHT/3)*2;
          break;
      }
      if(!strstr(_szBuff, "\n")) /* Just one line */
      {
        Print_String(iX_OB, y, _szBuff, BLACK, CENTER_TEXT);
      }
      else /* Several lines (split) */
      {
        j=l=0;
        for(i=0; i<(int)strlen(_szBuff); ++i, ++j)
        {
          if(_szBuff[i]!='\n')
            buff[j]=_szBuff[i];
          else /* _szBuff[i]=='\n' */
          {
            buff[j]='\0';
            Print_String(iX_OB, y+l*15, buff, BLACK, CENTER_TEXT);
            ++l;
            j=-1;
          }
        }
        buff[j]='\0';
        Print_String(iX_OB, y+l*15, buff, BLACK, CENTER_TEXT);
      }
      break;
  }
}
