#include "infopanel.h"
#include "shenyumu.h"
#include "tile_rectangle.h"
#include "checkcard.h"
#include "status_zh.c"

#ifdef DEBUG_CURSOR
int xcursoroffset ;
int ycursoroffset ;
int xcursordelay  ;
int ycursordelay  ;
int whichparameter;
Gfx* drawCursorParameter(Gfx** glistp);
#endif
int CEdit_ForwardCursor (CEdit * edit);
int CEdit_BackCursor (CEdit * edit);
int CEdit_ResetPoschar (CEdit *);
void buildRefereceChinese (void);
void playSound(int id, int waitFinish);
Gfx* displayError(Gfx** glistp, CMessage* cmessage);
Gfx* validExit(Gfx** glistp, CMessage* cmessage);
int CEdit_RepChar (CEdit * edit, unsigned char s);
int doAction_RButton (CMessage *cmessage);
int insertpinyin(CEdit *pinyin, int pos);
int deletepinyin(int pos);
int CEdit_PutCursorLast(CEdit*);
Gfx* CDraw_Glyph(Gfx** glisp,const char *s, const char *img,int x, int y, int spacex,int spacey ,float ratio ,int utol);
Gfx* CDraw_GlyphIndex(Gfx** glisp,const unsigned char *s, const char *img,int x, int y, int spacex,int spacey ,float ratio );

extern CUserRegData curd;

/*Global data       */
#define gxoffset  0
#define gyoffsets  0
#define gyoffset   0
#define gfxoffset 0
#define gfsoffset 4
#define gframewidth  260
#define gframeheight  25
#define gelxoffset 45
#define gexoffset 30		/*130 */
#define gesoffset 5
#define geyoffset 8
#define geditwidth 185
#define geditheight 20
#define geditnumdisp 13
#define gstrux   2
#define gstruy   1
static unsigned char gcsa[200];
static int shenoryun = 0;	/*0 shenmu,1 yumu */
/*static int focusPanel = 0; 0 MAIN , 1 keyborad ,2 chinese reference , 3 input */

/*register data edit */
static CEdit CE_name =
  { CHINESE, 1, 1, curd.name, 0, 0, 0, CUR_NAME_LEN - 1, 0,17,
gexoffset, geyoffset, 384, 32, NAME, gstruy, (u32)0};/* &editn_tex };*/
static CEdit CE_namelabel =
  { CEDITNONE, 0, 0, 0, 0, 0, 0, 0, 0, 0, gelxoffset, geyoffset, 48, 32,
LABEL, gstruy, (u32) &namelabel_tex };
static CEdit CE_birthdate_year_e =
  { DIGITAL, 1, 1, curd.birthdate, 0, 0, 0, 1, 0, 4, gexoffset ,
geyoffset, 64, 32, BIRTHDATE, gstruy, (u32)0};/* &edit2n_tex };*/
/*static CEdit CE_birthdate_year_f =
  { DIGITAL, 1, 1, curd.birthdate + 2, 0, 0, 0, 1, 0, 1, gesoffset-10, geyoffset,
32, 32, 602, gstruy, (u32)0};*//* &edit2n_tex };*/
static CEdit CE_birthdate_year_s =
  { CEDITNONE, 0, 0, 0, 0, 0, 0, 0, 0, 0, gesoffset+20, geyoffset, 32, 32,
LABEL, gstruy, (u32) &year_tex };
static CEdit CE_birthdate_month_e =
  { DIGITAL, 1, 1, curd.birthdate + 6, 0, 0, 0, 1, 0, 2, gesoffset-10, geyoffset,
64, 32, BIRTHDATE, gstruy, (u32)0};/* &edit2n_tex };*/
/*static CEdit CE_birthdate_month_f =
  { DIGITAL, 1, 1, curd.birthdate + 6, 0, 0, 0, 1, 0, 1, gesoffset-10, geyoffset,
32, 32, 604, gstruy, (u32)0};*//* &edit2n_tex };*/
static CEdit CE_birthdate_month_s =
  { CEDITNONE, 0, 0, 0, 0, 0, 0, 0, 0, 0, gesoffset-15, geyoffset, 32, 32,
LABEL, gstruy, (u32) &month_tex };
static CEdit CE_birthdate_day_e =
  { DIGITAL, 1, 1, curd.birthdate + 10, 0, 0, 0, 1, 0, 2, gesoffset-10, geyoffset,
64, 32, BIRTHDATE, gstruy, (u32)0};/* &edit2n_tex };*/
/*static CEdit CE_birthdate_day_f =
  { DIGITAL, 1, 1, curd.birthdate + 10, 0, 0, 0, 1, 0, 1, gesoffset-10,
geyoffset, 32, 32, 606, gstruy, (u32)0};*//* &edit2n_tex };*/
static CEdit CE_birthdate_day_s =
  { CEDITNONE, 0, 0, 0, 0, 0, 0, 0, 0, 0, gesoffset-15, geyoffset, 32, 32,
LABEL, gstruy, (u32) &day_tex };
static CEdit CE_birthdate_label =
  { CEDITNONE, 0, 0, 0, 0, 0, 0, 1, 0, 0, gelxoffset, geyoffset, 48, 32,
LABEL, gstruy, (u32) &birthdaylabel_tex };
static CEdit CE_address =
  { CHINESE, 1, 1, curd.address, 0, 0, 0, CUR_ADDRESS_LEN - 1, 0, 16,
gexoffset, geyoffset, 384, 32, ADDRESS, gstruy, (u32)0};/* &editn_tex };*/
 static CEdit CE_addresslabel =
  { CEDITNONE, 0, 0, 0, 0, 0, 0, 0, 0, 0, gelxoffset, geyoffset, 48, 32,
LABEL, gstruy, (u32) &addresslabel_tex };
/*static*/ CEdit CE_phone =
  { DIGITAL, 1, 1, curd.phone, 0, 0, 0, CUR_PHONE_LEN-1, 0, CUR_PHONE_LEN,
gexoffset, geyoffset, 384, 32, gstrux, gstruy, (u32)0};/* &editn_tex };*/
static CEdit CE_phonelabel =
  { CEDITNONE, 0, 0, 0, 0, 0, 0, 0, 0, 0, gelxoffset, geyoffset, 48, 32,
LABEL, gstruy, (u32) &phonelabel_tex };
/*static CEdit CE_desired_email=     {ENGLISH,  1,1,0,0,0,0,UR_EMAIL_LEN,    0,geditnumdisp,gexoffset,geyoffset,384,  	   	    32,gstrux,gstruy, (u32)editn_tex};
static CEdit CE_desired_emaillabel={CEDITNONE,0,0,0       ,         0,0,0,0,               0,0,           gelxoffset,geyoffset,104,                  32,gstrux,gstruy,(u32)maillabel_tex };
static CEdit CE_lucky_number =     {DIGITAL,  1,1,0, 0,0,0,UR_LUCKY_LEN,    0,geditnumdisp,gexoffset,geyoffset,384,  		    32,gstrux,gstruy, (u32)editn_tex};
static CEdit CE_lucky_numberlabel= {CEDITNONE,0,0,0       ,         0,0,0,0,               0,0,           gelxoffset,geyoffset,104,                  32,gstrux,gstruy,(u32)luckynumberlabel_tex};*/
/*static CEdit CE_clubid =
  { DIGITAL, 1, 0, curd.gBbClubId, 0, 0, 0, CUR_EMAIL_LEN, 0, geditnumdisp,
gexoffset, geyoffset, 384, 32, gstrux, gstruy, (u32)0};
static CEdit CE_clubidlabel =
  { CEDITNONE, 0, 0, 0, 0, 0, 0, 0, 0, 0, gelxoffset, geyoffset, 104, 32,
gstrux, gstruy, (u32) &clubidlabel_tex };*/
/*static CEdit CE_sex_femal_e =
  { CHECK, 1, 1, &curd.sex, 0, 0, 0, 1, 0, 0, 30, geyoffset, 32, 32, gstrux,
gstruy, (u32) &sex_ok_tex };*/
static CEdit CE_sex_femal_s =
  { CHECK, 0, 0, &curd.sex, 0, 0, 0, 0, 0, 1, 88, geyoffset, 32, 32, 1,
2, (u32) &girl_tex };
/*
static CEdit CE_sex_male_e =
  { CHECK, 1, 1, &curd.sex, 0, 0, 0, 1, 0, 1, gexoffset -50, geyoffset, 32, 32, gstrux,
gstruy, (u32) &boy_tex };*/
static CEdit CE_sex_male_s =
   { CHECK, 0, 0, &curd.sex, 0, 0, 0, 0, 0, 1, 0, geyoffset, 32, 32, 1,
2, (u32) &girl_tex };
static CEdit CE_sexlabel =
  { CEDITNONE, 0, 0, 0, 0, 0, 0, 0, 0, 0, gelxoffset - 10, geyoffset, 104, 32,
LABEL, gstruy, (u32) &sexlabel_tex };
/*
static CEdit CE_okbutton =
  { TEXTCO, 1, 0, 0, 1, 0, 0, 1, 0, 1, 50, geyoffset , 64, 32, 0,
(int) &okn_tex, (u32) &okn_tex };
static CEdit CE_discardbutton =
  { TEXTCO, 1, 0, 0, 2, 0, 0, 1, 0, 2, 50, geyoffset - 4, 56, 40, 0,
(int) &discardn_tex, (u32) &discardh_tex };

*/


static CEdit *GCE_name[] = { &CE_namelabel, &CE_name,0 };
static CEdit *GCE_birthdate[] = {
  &CE_birthdate_label,
  &CE_birthdate_year_e,
  /*&CE_birthdate_year_f,*/
  &CE_birthdate_year_s,
  &CE_birthdate_month_e,
  /*&CE_birthdate_month_f,*/
  &CE_birthdate_month_s,
  &CE_birthdate_day_e,
  /*&CE_birthdate_day_f,*/
  &CE_birthdate_day_s,
  &CE_sexlabel,
  &CE_sex_male_s,
  0,
 /* &CE_sex_male_e,
  &CE_sex_femal_s,
  &CE_sex_femal_e,*/
};

static CEdit *GCE_address[] = {
  &CE_addresslabel,
  &CE_address,
  0
};
static CEdit *GCE_phone[] = {
  &CE_phonelabel,
  &CE_phone,
  0,
};
/*static CEdit* GCE_desired_email[] = {
	&CE_desired_emaillabel,
	&CE_desired_email,
	0
	};
static CEdit* GCE_lucky_number[] = {
	&CE_lucky_numberlabel,
	&CE_lucky_number,
	0
	
	};*/

/*static CEdit *GCE_clubid[] = {
  &CE_clubidlabel,
  &CE_clubid,
  0,
};*/
/*static CEdit *GCE_sex[] = {*/
 /* &CE_sexlabel,
  &CE_sex_male_s,
  &CE_sex_male_e,
  &CE_sex_femal_s,
  &CE_sex_femal_e,*/
  /*&CE_okbutton,
  0,
  0
};*/
/*
static CEdit *GCE_mainbutton[] = {
  &CE_okbutton,
  &CE_discardbutton,
  0,
  0,
};*/
#define mainframex  640
#define mainframey  32
/*register data frame*/
static CFrame CF_name =
  { GCE_name, 2, 1, 0, gxoffset, gyoffsets, mainframex, mainframey,
PARENTLEFT, PARENTBUTTON, 0,0};/*(u32) &framen_tex, (u32) &frameh_tex };*/
static CFrame CF_birthdate =
  { GCE_birthdate, 9, 1, 0, gxoffset, gyoffset, mainframex, mainframey,
BIRTHDATE, PREBUTTON, (u32)0,0};/*(u32) &framen_tex, (u32) &frameh_tex };*/
static CFrame CF_address =
  { GCE_address, 2, 1, 0, gxoffset, gyoffset, mainframex, mainframey,
PARENTLEFT, PREBUTTON, (u32)0,0};/*(u32) &framen_tex, (u32) &frameh_tex };*/
static CFrame CF_phone =
  { GCE_phone, 2, 1, 0, gxoffset, gyoffset, mainframex, mainframey,
PARENTLEFT, PREBUTTON, (u32)0,0};/*(u32) &framen_tex, (u32) &frameh_tex };*/
/*static CFrame CF_desired_email = {GCE_desired_email,2,1,desired_email,gxoffset,gyoffset,	mainframex,	      mainframey,PARENTLEFT,PREBUTTON,   (u32)framen_tex,        (u32)frameh_tex};
static CFrame CF_lucky_number =  {GCE_lucky_number, 2,1,lucky_number, gxoffset,gyoffset,	mainframex,	      mainframey,PARENTLEFT,PREBUTTON,   (u32)framen_tex,        (u32)frameh_tex};*/
/*static CFrame CF_clubid =
  { GCE_clubid, 0, 0, 0, gxoffset, gyoffset, mainframex, mainframey,
PARENTLEFT, PREBUTTON, (u32) &clubtitle_tex, (u32) &clubtitle_tex };*/
/*static CFrame CF_sex =
  { GCE_sex, 1, 1, 0, gxoffset, gyoffset, mainframex, mainframey, SEXTYPE,
PREBUTTON, (u32) &framen_tex, (u32) &frameh_tex };*/
/*static CFrame CF_mainbutton =
  { GCE_mainbutton, 2, 1, 0, gxoffset, gyoffset, mainframex, mainframey,
PARENTLEFT, PREBUTTON, (u32) &framen_tex, (u32) &frameh_tex };*/
static CFrame *mainpanel[] = {
  /*&CF_clubid,*/
  &CF_name,
  
  &CF_phone,
  /*&CF_desired_email,
     &CF_lucky_number, */
  &CF_birthdate,
  &CF_address,
  /*&CF_sex,*/
  /*&CF_mainbutton,*/
  0
};
static CEdit *GCE_editable[] = {
  0,
  0
};


static CFrame CF_editable =
  { GCE_editable, 1, 0, 0, gxoffset, gyoffset, gframewidth, gframeheight,
PARENTLEFT, PARENTBUTTON, 0, 0 };


/*birthdate input panel*/
static CEdit ICE_birthdate_year_s =
  { CEDITNONE, 0, 0, 0, 0, 0, 0, 0, 0, 0, gesoffset+100, geyoffset, 32, 32,
LABEL, gstruy, (u32) &year_tex };
static CEdit ICE_birthdate_month_s =
  { CEDITNONE, 0, 0, 0, 0, 0, 0, 0, 0, 0, gesoffset+100, geyoffset, 32, 32,
LABEL, gstruy, (u32) &month_tex };
static CEdit ICE_birthdate_day_s =
  { CEDITNONE, 0, 0, 0, 0, 0, 0, 0, 0, 0, gesoffset+100, geyoffset, 32, 32,
LABEL, gstruy, (u32) &day_tex };
static CEdit CE_leftarrow =
  { CEDITNONE, 0, 0, 0, 0, 0, 0, 0, 0, 0, gelxoffset, geyoffset+4, 24, 24,
ARROW, gstruy, (u32) &leftarrow_tex };
static CEdit CE_rightarrow =
  { CEDITNONE, 0, 0, 0, 0, 0, 0, 0, 0, 0, gelxoffset, geyoffset+4, 24, 24,
ARROW, gstruy, (u32) &rightarrow_tex };
static CEdit CE_yeardi =
  { DIGITAL, 0, 0, curd.birthdate+2, 0, 0, 0, 0, 0, 2, gelxoffset+30, geyoffset+4, 104, 32,
0, 99, (u32) 0 };
static CEdit CE_monthdi =
  { DIGITAL, 0, 0, curd.birthdate+6, 0, 0, 0, 0, 0, 2, gelxoffset+30, geyoffset, 104, 32,
1, 12, (u32) 0};
static CEdit CE_daydi =
  { DIGITAL, 0, 0, curd.birthdate+10, 0, 0, 0, 0, 0, 2, gelxoffset+30, geyoffset, 104, 32,
1, 31, (u32)0 };

static CEdit *IGCE_Year[] = {
	&ICE_birthdate_year_s,
	&CE_leftarrow,
	&CE_yeardi,
	&CE_rightarrow,
	0,	
	};
static CEdit *IGCE_Month[] = {
	&ICE_birthdate_month_s,
	&CE_leftarrow,
	&CE_monthdi,
	&CE_rightarrow,
	0,
};
static CEdit *IGCE_Day[] = {
	&ICE_birthdate_day_s,
	&CE_leftarrow,
	&CE_daydi,
	&CE_rightarrow,
	0,
	};

static CFrame IGCF_Year = { IGCE_Year, 4, 1, 0, gxoffset, gyoffset+66, mainframex, mainframey,
BIRTHDATE, PREBUTTON, /*(u32) &framen_tex, (u32) &frameh_tex };*/ 0,0};
static CFrame IGCF_Month = {IGCE_Month, 4, 1, 0, gxoffset, gyoffset, mainframex, mainframey,
BIRTHDATE, PREBUTTON,  /*(u32) &framen_tex, (u32) &frameh_tex };*/ 0,0};
static CFrame IGCF_Day = {  IGCE_Day,    4, 1, 0,    gxoffset, gyoffset, mainframex, mainframey,
BIRTHDATE, PREBUTTON,  /*(u32) &framen_tex, (u32) &frameh_tex };*/ 0,0};
/* sex type panel */
static CEdit CE_sexleftarrow =
  { CEDITNONE, 0, 0, 0, 0, 0, 0, 0, 0, 0, gelxoffset+32 - 104, geyoffset+4, 24, 24,
ARROW, gstruy, (u32) &leftarrow_tex };
static CEdit CE_sexrightarrow =
  { CEDITNONE, 0, 0, 0, 0, 0, 0, 0, 0, 0, gelxoffset+104 - 40, geyoffset+4, 24, 24,
ARROW, gstruy, (u32) &rightarrow_tex };
static CEdit ICE_sexlabel =
  { CEDITNONE, 0, 0, 0, 0, 0, 0, 0, 0, 0,gesoffset+100, geyoffset, 104, 32,
LABEL, gstruy, (u32) &sexlabel_tex };
static CEdit *IGCE_femal[] = {
	&ICE_sexlabel,
	&CE_sexleftarrow,
	&CE_sex_femal_s,
	&CE_sexrightarrow,
	0,
	};
/*static CEdit *IGCE_male[] = {
	&CE_sex_male_s,
	0,
	};*/

static CFrame IGCF_femal =  { IGCE_femal, 4, 1, 0, gxoffset, gyoffset, mainframex, mainframey,
BIRTHDATE, PREBUTTON,  /*(u32) &framen_tex, (u32) &frameh_tex };*/ 0,0};
#if 0
static CFrame IGCF_male  =  { IGCE_male , 1, 1, 0, gxoffset+300, gyoffset, mainframex, mainframey,
BIRTHDATE, PREBUTTON,  /*(u32) &framen_tex, (u32) &frameh_tex };*/ 0,0};
#endif
/* valid exit panel*/
static CEdit CE_exitwarning =
  { CEDITNONE, 0, 0, 0, 0, 0, 0, 0, 0, 0, 200, geyoffset+4,112,24,
gstrux, gstruy, (u32) &wsave_tex };
static CEdit CE_saveyes =
  { CEDITNONE, 0, 0, 0, 0, 0, 0, 0, 0, 0, 200, geyoffset+4, 32, 24,
LABEL, gstruy, (u32) &wy_tex };
static CEdit CE_saveno =
  { CEDITNONE, 0, 0, 0, 0, 0, 0, 0, 0, 0, 200, geyoffset,32,24,
LABEL, gstruy, (u32) &wn_tex };
static CEdit CE_dropwarning = {
	 CEDITNONE, 0, 0, 0, 0, 0, 0, 0, 0, 0, 192, geyoffset,48,24,
LABEL, gstruy, (u32) &wdrop_tex };
static CEdit *IGCE_exitwarning[] = {
	&CE_exitwarning,
	0,
	};
static CEdit *IGCE_saveyes[] = {
	&CE_saveyes,
	0,
	};
static CEdit *IGCE_saveno[] = {
	&CE_saveno,
	0,
	};
static CEdit *IGCE_dropwarning[] = {
	&CE_dropwarning,
	0,
	};
static CFrame ferrorread  = {0,0,0,0,0,0,240,32,0,0,(u32)&errorread_tex,   (u32)&errorread_tex,      0 };
static CFrame ferrorwrite = {0,0,0,0,0,0,240,32,0,0,(u32)&errorwrite_tex,  (u32)&errorwrite_tex,     0 };
static CFrame fmainbg	 = {0,0,0,0,0,0,640,480,0,0,(u32)&mainbg_tex,      (u32)&mainbg_tex,         0 };
static CFrame fwarningbg = {0,0,0,0,0,0,312,128,0,0,(u32)&warningbg_tex,   (u32)&warningbg_tex,      0 };	
static CFrame IGCF_waring = { IGCE_exitwarning,1, 1, 0, gxoffset+20, gyoffset+60, 200, 32,
PREBUTTON, PREBUTTON, /*(u32) &framen_tex, (u32) &frameh_tex };*/ 0,0};
static CFrame IGCF_saveyes = {IGCE_saveyes, 1, 1, 0, gxoffset+190, gyoffset - 60, 200, 32,
PREBUTTON, PREBUTTON,  /*(u32) &framen_tex, (u32) &frameh_tex };*/ 0,0};
static CFrame IGCF_saveno = { IGCE_saveno,    1, 1, 0,    gxoffset+190, gyoffset-4, 200, 32,
PREBUTTON, PREBUTTON,  /*(u32) &framen_tex, (u32) &frameh_tex };*/ 0,0};
static CFrame IGCF_dropwarning = { IGCE_dropwarning,    1, 1, 0,    gxoffset+190, gyoffset-8, 200, 32,
PREBUTTON, PREBUTTON,  /*(u32) &framen_tex, (u32) &frameh_tex };*/ 0,0};

static CFrame *wanringpanel[] = {
	&IGCF_waring,
	&IGCF_saveyes,
	&IGCF_saveno,
	&IGCF_dropwarning,
	0,
	};
	
	
	

/*pinying input panel*/
#define pycharx 104
#define pychary 32
#define pycharcx 384
#define pycharcy 32
#define pycharfx 640
#define pycharfy 40
#define pychardis 13
static CEdit CE_pyleftarrow =
  { CEDITNONE, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 0, 24, 24,
ARROW, TEXTL1, (u32) &leftarrow_tex };
static CEdit CE_pyrightarrow =
  { CEDITNONE, 0, 0, 0, 0, 0, 0, 0, 0, 0,   0, 0, 24, 24,
ARROW, TEXTL2, (u32) &rightarrow_tex };
char pychar_c[9] = {0,0,0,0,0,0,0,0,0};
CEdit pychar = 		{INPUTPY, 0,0,pychar_c,0,0,0,0, 0,6,         116,8,pycharx, pychary, 0,0,0};
CEdit pychinese = 	{INPUTREF,1,0,0,       0,0,0,20,0,pychardis, -5,0,pycharcx+147,pycharcy,0,0,0};/*(u32)&editn_tex};*/

CEdit *pychar_e[] = {
	&pychar,
	0,	
};
CEdit *pyref_e[] = {
	&CE_pyleftarrow,
	&pychinese,
	&CE_pyrightarrow,
	0,
	};
CFrame pychar_f = {pychar_e,1,0,0,0,0,pycharfx,pycharfy,0,0,(u32)0,0};/*(u32) &framen_tex, (u32) &frameh_tex };*/
CFrame pyrefc_f = {pyref_e, 3,1,0,0,0,pycharfx,pycharfy,0,0,(u32)0,0};/*(u32) &framen_tex, (u32) &frameh_tex };*/

/*bg for input panle*/
CFrame bgalphanum_f = {0,0,0,0,0,0,536,304,0,0,/*(u32)bgalphanum_tex*/0,   /*(u32)bgalphanum_tex*/0,   0 };
/*CFrame bgchinese_f  = {0,0,0,0,0,0,536,240,0,0,(u32)bgchinese_tex,    (u32)bgchinese_tex,   0 };*/
/******************************************************************************************************
*
*
*/
/*
static CFrame *sexpanel[] = {
	&CF_editable,
	&IGCF_femal,
	&IGCF_male,
	0,
	};*/
static CFrame *brithdatepanel[] = {
	&CF_editable,
	&IGCF_Year,
	&IGCF_Month,
	&IGCF_Day,
	&IGCF_femal,
/*	&IGCF_male,*/
	0,
	};

static CFrame *chinesepanel[] = {

  &CF_editable,
  &pychar_f,
  &pyrefc_f,
  /*&CF_lowletter1,
     &CF_lowletter2,
     &CF_pyinput,
     &CF_pyreference, */
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
};
static CFrame *englishpanel[] = {
  &CF_editable,
  /*&CF_lowletter1,
     &CF_lowletter2,
     &CF_upletter1,
     &CF_upletter2,
     &CF_misc, */
  &cfledit1,
  &cfledit2,
  &cfuedit1,
  &cfuedit2,
  &cfdigital1,
  0
};
static CFrame *digitalpanel[] = {
  &CF_editable,
  /*&CF_digital, */
  &cfdigitals1,
  &cfdigitals2,
  &cfdigitals3,
  &cfdigitals4,
  0
};







/*TOP BUTTOM and HELP*/
#define hbuttomx   56
#define hbuttomy   32
#define hbuttomhx  40
#define hbuttomhy  32
CEdit CEA_Buttom =
  { CEDITNONE, 0, 0, 0, 0, 0, 0, 0, 0, 1, 35, 0, 32, 32, 0, 0,
(u32) &a_helpb_tex };
CEdit CEA_Buttom_h =
  { CEDITNONE, 0, 0, 0, 0, 0, 0, 0, 0, 1, 5, 8, 32, 16, 0, 0,
(u32) &a_helpt_tex };
CEdit CEB_Buttom =
  { CEDITNONE, 0, 0, 0, 0, 0, 0, 0, 0, 1, 5, 0, 32, 32, 0, 0,
(u32) &b_helpb_tex };
CEdit CEB_Buttom_hd =
  { CEDITNONE, 0, 0, 0, 0, 0, 0, 0, 0, 1, 5, 8, 32, 16, 0, 0,
(u32) &b_helpdelete_tex };
CEdit CEB_Buttom_hr =
  { CEDITNONE, 0, 0, 0, 0, 0, 0, 0, 0, 1,5, 8, 32, 16, 0, 0,
(u32) &b_helpreturn_tex };
CEdit CERD_Buttom =
  { CEDITNONE, 0, 0, 0, 0, 0, 0, 0, 0, 1, 5 , 0 ,72, 32, 0, 0,
(u32) &rd_helpb_tex };
CEdit CERD_Buttom_h =
  { CEDITNONE, 0, 0, 0, 0, 0, 0, 0, 0, 1, 5, 8 , 32, 16, 0, 0,
(u32) &b_helpdelete_tex };
CEdit CER_Buttom =
  { CEDITNONE, 0, 0, 0, 0, 0, 0, 0, 0, 1, 5 , 0 - 350,24, 24, 0, 0,
(u32) &r_helpb_tex };
CEdit CER_Buttom_h =
  { CEDITNONE, 0, 0, 0, 0, 0, 0, 0, 0, 1, 5, 8 - 350, 32, 16, 0, 0,
(u32) &r_helpt_tex };
CEdit CEL_Buttom =
  { CEDITNONE, 0, 0, 0, 0, 0, 0, 0, 0, 1, 5+150  , 0 - 350,24, 24, 0, 0,
(u32) &l_helpb_tex };
CEdit CEL_Buttom_h =
  { CEDITNONE, 0, 0, 0, 0, 0, 0, 0, 0, 1, 5, 8 - 350, 32, 16, 0, 0,
(u32) &l_helpt_tex };

CEdit CEU_Buttom =
  { CEDITNONE, 0, 0, 0, 0, 0, 0, 0, 0, 1, 5-128 , 0 - 292,24, 24, 0, 0,
(u32) &u_helpb_tex };
CEdit CEU_Buttom_h =
  { CEDITNONE, 0, 0, 0, 0, 0, 0, 0, 0, 1, 5, 8 - 292, 32, 16, 0, 0,
(u32) &u_helpt_tex };
CEdit CED_Buttom =
  { CEDITNONE, 0, 0, 0, 0, 0, 0, 0, 0, 1, 5  , 0 - 292,24, 24, 0, 0,
(u32) &d_helpb_tex };
CEdit CED_Buttom_h =
  { CEDITNONE, 0, 0, 0, 0, 0, 0, 0, 0, 1, 5, 8 - 292, 32, 16, 0, 0,
(u32) &d_helpt_tex };
CEdit *CE_GenelHelp[] = {
  &CEA_Buttom,
  &CEA_Buttom_h,
  &CEB_Buttom,
  &CEB_Buttom_hr,
  /*&CER_Buttom,
  &CER_Buttom_h,*/
  0,
};
CEdit *CE_topHelp[] = {
  &CEA_Buttom,
  &CEA_Buttom_h,
  &CEB_Buttom,
  &CEB_Buttom_hr,
  &CERD_Buttom,
  &CERD_Buttom_h,
  &CEL_Buttom,
  &CEL_Buttom_h,
  &CER_Buttom,
  &CER_Buttom_h,
  0,
};

 CEdit *CE_toprefHelp[] = {
  &CEA_Buttom,
  &CEA_Buttom_h,
  &CEB_Buttom,
  &CEB_Buttom_hr,
  &CERD_Buttom,
  &CERD_Buttom_h,
  &CEL_Buttom,
  &CEL_Buttom_h,
  &CER_Buttom,
  &CER_Buttom_h,
  &CEU_Buttom,
  &CEU_Buttom_h,
  &CED_Buttom,
  &CED_Buttom_h,
  0,
};
/*
CFrame topframe =
  { 0, 0, 0, 0, 0, 0, 640, 88, 0, 0, (u32) &club_tex, (u32) &club_tex, 0 };
  CFrame buttomid = { 0, 0, 0, 0, 0, 0, 640, 40, 0, 0, (u32) &clubidframe_tex, (u32) &clubidframe_tex, 0 };*/
CFrame buttomframe =
  { 0, 0, 0, 0, 0, 0, 640, 72, 0, 0, (u32) 0, (u32) 0, 0 };
/*panel data*/
/*
CFrame *MainPanel[] = {
&topframe,
  &CF_name,
  &buttomframe,
  0
};

*/
CPanel GC_panel[] = {
  {CHINESE, 2, 0, chinesepanel},
  {ENGLISH, 6, 0, englishpanel},
  {DIGITAL, 5, 0, digitalpanel},
  {MAIN, 4, 0, mainpanel},
  {DIGITAL, 5, 0, brithdatepanel},
  /*{SEXTYPE,3,0,sexpanel},*/
  {WARNING,4,1,wanringpanel},
};
CPanel *currentpanel = &GC_panel[3];



/*texture map */
CImg decop[] = {
{ &addresslabel_size , addresslabel_img,&addresslabel_tex },
{ &a_helpb_size , a_helpb_img, &a_helpb_tex}, 
{ &a_helpt_size , a_helpt_img, &a_helpt_tex,}, 
{ &b_helpb_size , b_helpb_img, &b_helpb_tex,}, 
{ &b_helpt_size , b_helpt_img, &b_helpt_tex,}, 
{ &birthdaylabel_size , birthdaylabel_img, &birthdaylabel_tex,}, 
{ &day_size , day_img, &day_tex,}, 
/*{ &discardh_size , discardh_img, &discardh_tex,}, 
{ &discardn_size , discardn_img, &discardn_tex,}, */
/*{ &edit2n_size ,  edit2n_img, &edit2n_tex,}, 
{ &editn_size ,   editn_img, &editn_tex,}, */
/*{ &femal_size , femal_img, &femal_tex,}, */
/*{ &frameh_size , frameh_img, &frameh_tex,}, 
{ &framen_size ,  framen_img, &framen_tex,}, */
/*{ &male_size , male_img, &male_tex,}, */
{ &month_size , month_img, &month_tex,}, 
{ &namelabel_size , namelabel_img, &namelabel_tex,}, 
{ &phonelabel_size , phonelabel_img, &phonelabel_tex,}, 
/*{ &r_helpb_size , r_helpb_img, &r_helpb_tex,}, 
{ &r_helpt_size , r_helpt_img, &r_helpt_tex,}, */
{ &sexlabel_size , sexlabel_img, &sexlabel_tex,}, 
/*{ &sex_no_size , sex_no_img, &sex_no_tex,}, 
{ &sex_ok_size ,  sex_ok_img, &sex_ok_tex,}, */
/*{ &shenmubuttonh_size , shenmubuttonh_img, &shenmubuttonh_tex,}, 
{ &shenmubutton_size , shenmubutton_img, &shenmubutton_tex,}, */
{ &t0_size , t0_img, &t0_tex,}, 
{ &t1_size , t1_img, &t1_tex,}, 
{ &t2_size ,  t2_img, &t2_tex,}, 
{ &t3_size , t3_img, &t3_tex,}, 
{ &t4_size , t4_img, &t4_tex,}, 
{ &t5_size , t5_img, &t5_tex,}, 
{ &t6_size ,t6_img, &t6_tex,}, 
{ &t7_size , t7_img, &t7_tex,}, 
{ &t8_size ,t8_img, &t8_tex,}, 
{ &t9_size , t9_img, &t9_tex,}, 
{ &tch_size ,  tch_img, &tch_tex,}, 
{ &tla_size , tla_img, &tla_tex,}, 
{ &tlb_size , tlb_img, &tlb_tex,}, 
{ &tlc_size , tlc_img, &tlc_tex,}, 
{ &tld_size , tld_img, &tld_tex,}, 
{ &tle_size , tle_img, &tle_tex,}, 
{ &tlf_size , tlf_img, &tlf_tex,}, 
{ &tlg_size , tlg_img, &tlg_tex,}, 
{ &tlh_size , tlh_img, &tlh_tex,}, 
{ &tli_size , tli_img, &tli_tex,}, 
{ &tlj_size , tlj_img, &tlj_tex,}, 
{ &tlk_size , tlk_img, &tlk_tex,}, 
{ &tll_size , tll_img, &tll_tex,}, 
{ &tlm_size , tlm_img, &tlm_tex,}, 
{ &tln_size , tln_img, &tln_tex,}, 
{ &tlo_size , tlo_img, &tlo_tex,}, 
{ &tlp_size , tlp_img, &tlp_tex,}, 
{ &tlq_size , tlq_img, &tlq_tex,}, 
{ &tlr_size , tlr_img, &tlr_tex,}, 
{ &tls_size , tls_img, &tls_tex,}, 
{ &tlt_size , tlt_img, &tlt_tex,}, 
{ &tlu_size , tlu_img, &tlu_tex,}, 
{ &tlv_size , tlv_img, &tlv_tex,}, 
{ &tlw_size , tlw_img, &tlw_tex,}, 
{ &tlx_size , tlx_img, &tlx_tex,}, 
{ &tly_size , tly_img, &tly_tex,}, 
{ &tlz_size , tlz_img, &tlz_tex,}, 
{ &top_size , top_img, &top_tex,}, 
{ &tsh_size , tsh_img, &tsh_tex,}, 
{ &tua_size , tua_img, &tua_tex,}, 
{ &tub_size , tub_img, &tub_tex,}, 
{ &tuc_size , tuc_img, &tuc_tex,}, 
{ &tud_size , tud_img, &tud_tex,}, 
{ &tue_size , tue_img, &tue_tex,}, 
{ &tuf_size , tuf_img, &tuf_tex,}, 
{ &tug_size , tug_img, &tug_tex,}, 
{ &tuh_size , tuh_img, &tuh_tex,}, 
{ &tui_size , tui_img, &tui_tex,}, 
{ &tuj_size , tuj_img, &tuj_tex,}, 
{ &tuk_size , tuk_img, &tuk_tex,}, 
{ &tul_size , tul_img, &tul_tex,}, 
{ &tum_size , tum_img, &tum_tex,}, 
{ &tun_size , tun_img, &tun_tex,}, 
{ &tuo_size , tuo_img, &tuo_tex,}, 
{ &tup_size , tup_img, &tup_tex,}, 
{ &tuq_size , tuq_img, &tuq_tex,}, 
{ &tur_size , tur_img, &tur_tex,}, 
{ &tus_size , tus_img, &tus_tex,}, 
{ &tut_size , tut_img, &tut_tex,}, 
{ &tuu_size , tuu_img, &tuu_tex,}, 
{ &tuv_size , tuv_img, &tuv_tex,}, 
{ &tuw_size , tuw_img, &tuw_tex,}, 
{ &tux_size , tux_img, &tux_tex,}, 
{ &tuy_size , tuy_img, &tuy_tex,}, 
{ &tuz_size , tuz_img, &tuz_tex,}, 
{ &tyai_size, tyai_img,&tyai_tex,}, 
{ &tyang_size ,tyang_img, &tyang_tex,}, 
{ &tyan_size , tyan_img, &tyan_tex,}, 
{ &tyao_size , tyao_img, &tyao_tex,}, 
{ &tya_size , tya_img, &tya_tex,}, 
{ &tyei_size , tyei_img, &tyei_tex,}, 
{ &tyeng_size , tyeng_img, &tyeng_tex,}, 
{ &tyen_size , tyen_img, &tyen_tex,}, 
{ &tye_size , tye_img, &tye_tex,}, 
{ &tyiang_size , tyiang_img, &tyiang_tex,}, 
{ &tyian_size , tyian_img, &tyian_tex,}, 
{ &tyiao_size , tyiao_img, &tyiao_tex,}, 
{ &tyia_size , tyia_img, &tyia_tex,}, 
{ &tyie_size , tyie_img, &tyie_tex,}, 
{ &tying_size , tying_img, &tying_tex,}, 
{ &tyin_size , tyin_img, &tyin_tex,}, 
{ &tyiong_size , tyiong_img, &tyiong_tex,}, 
{ &tyi_size , tyi_img, &tyi_tex,}, 
{ &tyiu_size , tyiu_img, &tyiu_tex,}, 
{ &tyng_size , tyng_img, &tyng_tex,}, 
{ &tyn_size , tyn_img, &tyn_tex,}, 
{ &tyong_size ,tyong_img, &tyong_tex,}, 
{ &tyo_size , tyo_img, &tyo_tex,}, 
{ &tyou_size , tyou_img, &tyou_tex,}, 
{ &tyuai_size , tyuai_img, &tyuai_tex,}, 
{ &tyuang_size , tyuang_img, &tyuang_tex,}, 
{ &tyuan_size , tyuan_img, &tyuan_tex,}, 
{ &tyua_size , tyua_img, &tyua_tex,}, 
{ &tyue_size , tyue_img, &tyue_tex,}, 
{ &tyui_size , tyui_img, &tyui_tex,}, 
{ &tyun_size , tyun_img, &tyun_tex,}, 
{ &tyuo_size , tyuo_img, &tyuo_tex,}, 
{ &tyu_size , tyu_img,  &tyu_tex,}, 
{ &tyve_size , tyve_img, &tyve_tex,}, 
{ &tyvn_size , tyvn_img, &tyvn_tex,}, 
{ &tyv_size , tyv_img, &tyv_tex,}, 
{ &tzh_size , tzh_img, &tzh_tex,}, 
{ &year_size , year_img, &year_tex,}, 
{ &yunmubuttonh_size , yunmubuttonh_img, &yunmubuttonh_tex,}, 
{ &yunmubutton_size , yunmubutton_img, &yunmubutton_tex,}, 
/*{ &z_helpb_size , z_helpb_img, &z_helpb_tex,}, 
{ &z_helpt_size , z_helpt_img, &z_helpt_tex,}, */
{&errorwrite_size ,errorwrite_img,&errorwrite_tex},
{&errorread_size , errorread_img, &errorread_tex },
{&boy_size,boy_img,&boy_tex},
{&girl_size,girl_img,&girl_tex},
/*{&club_size,club_img,&club_tex},*/
{&leftarrow_size,leftarrow_img,&leftarrow_tex},
{&rightarrow_size,rightarrow_img,&rightarrow_tex},
{&returncursor_size,returncursor_img,&returncursor_tex},
{&wy_size,wy_img,&wy_tex},
{&wn_size,wn_img,&wn_tex},
{&wsave_size,wsave_img,&wsave_tex},
{&switchEnglish_size,switchEnglish_img,&switchEnglish_tex},
{&b_helpdelete_size,b_helpdelete_img,&b_helpdelete_tex},
{&b_helpreturn_size,b_helpreturn_img,&b_helpreturn_tex},
{&l_helpb_size,l_helpb_img,&l_helpb_tex},
{&l_helpt_size,l_helpt_img,&l_helpt_tex},
{&r_helpb_size,r_helpb_img,&r_helpb_tex},
{&r_helpt_size,r_helpt_img,&r_helpt_tex},
/*{&clubidframe_size,clubidframe_img,&clubidframe_tex},*/
/*{&space_size,space_img,&space_tex},*/
{&warningbg_size,warningbg_img,&warningbg_tex},
{&mainbg_size,mainbg_img,&mainbg_tex},
{&glyph16x16_size,glyph16x16_img,&glyph16x16_tex},
{&wdrop_size,wdrop_img,&wdrop_tex},
{&switchChinese_size,switchChinese_img,&switchChinese_tex},
{&rd_helpb_size,rd_helpb_img,&rd_helpb_tex},
{&u_helpb_size,u_helpb_img,&u_helpb_tex},
{&u_helpt_size,u_helpt_img,&u_helpt_tex},
{&d_helpb_size,d_helpb_img,&d_helpb_tex},
{&d_helpt_size,d_helpt_img,&d_helpt_tex},
{&glyph_size,glyph_img,&glyph_tex},
{&defocuscursor_size,defocuscursor_img,&defocuscursor_tex},
{0,0,0},
};
/* format 0 :GB2312 ,1 digital ,2 english,3 alphanum*/
int getrightformat(const unsigned char *source,unsigned char *dest, int format,int limit) {
	
	const unsigned char *psource = source;
	unsigned char *pdest = dest;
	for(;*psource&&(psource-source)<limit;psource++) {
		switch(format) {
		case 0:
			if(*psource<0xa1) {
				if((pdest-dest)+1<limit) {
				 *pdest++ = 0xa1;
				 *pdest++ = 0xa1;	
				}
				else  {
				 
				 goto end;
				}
				
				
			}
			else if(*psource>=0xa1) {
				if(*(psource+1)>=0xa1) {
						if((psource-source)+1<limit&&(pdest-dest)+1<limit) {
							*pdest++ = *psource++;
							*pdest++ = *psource;
						}
						else {
						
						goto end;	
						}
				}
				else {
					if((pdest-dest)+1<limit) {
						*pdest++ = 0xa1;
						*pdest++ = 0xa1;
					}
					else {
					goto end;	
					}
						
				}
		
				
			}
			
				
			break;
		case 1:
			if('0'<=*psource&&*psource<='9') {
			*pdest++ = *psource; 	
			}
			else {
			*pdest++ = '0';	
			}
			
			break;
		case 2:
			if(('a'<=*psource&&*psource<='z')||('A'<=*psource&&*psource<='Z')) {
				
				*pdest++ = *psource;
			}
			else {
			 	*pdest++ = 'a';	
			}
			
			break;
		case 3:	
			if(('a'<=*psource&&*psource<='z')||('A'<=*psource&&*psource<='Z')||('0'<=*psource&&*psource<='9')
			    ||'@' == *psource || '.' == *psource || '_' == *psource || '-' == *psource)
			{
				*pdest++ = *psource;	
			}
			else {
				*pdest++ = '0';	
			}
			
			
			break;
		default:
			break;	
		}
		
			
	}
	end:
		*pdest = 0;
		return pdest - dest;
	
};
;
int
bbtolocal ()
{
#if 0
  int i , j ;
  int ij = 1;
#endif 
  char tdata[200];
  bcopy(gBbUserRegInfo.name,tdata,UR_NAME_LEN);
  getrightformat(tdata,curd.name,0,UR_NAME_LEN);
  /*bcopy (gBbUserRegInfo.name, curd.name, UR_NAME_LEN);*/
  CEdit_ResetPoschar (&CE_name);
  CEdit_PutCursorLast(&CE_name);
  /*bcopy (gBbUserRegInfo.address, curd.address, UR_ADDRESS_LEN);*/
  bcopy (gBbUserRegInfo.address, tdata, UR_ADDRESS_LEN);
  getrightformat(tdata,curd.address,0,UR_ADDRESS_LEN);
  CEdit_ResetPoschar (&CE_address);
  CEdit_PutCursorLast(&CE_address);
  /*bcopy (gBbUserRegInfo.phone, curd.phone, UR_PHONE_LEN);*/
  bcopy (gBbUserRegInfo.phone, tdata, UR_PHONE_LEN);
  getrightformat(tdata,curd.phone,1,UR_PHONE_LEN);
  CEdit_ResetPoschar (&CE_phone);
  CEdit_PutCursorLast(&CE_phone);
  
  /*bcopy (gBbClubId, curd.gBbClubId, UR_EMAIL_LEN);*/
  bcopy (gBbClubId, tdata, UR_EMAIL_LEN);
  getrightformat(tdata,curd.gBbClubId,3,UR_EMAIL_LEN);
   curd.gBbClubId[UR_EMAIL_LEN] = '\0';
    
#if 0
#ifdef YZ
  for(i = 0;i<UR_PINYIN_LEN&&ij; ) {
  	for(j = 0;gBbUserRegInfo.pinyin[i+j]&&gBbUserRegInfo.pinyin[i+j]!=' ';j++) {
  		curd.pinyin[i+j]=gBbUserRegInfo.pinyin[i+j];
  		};
  	if(!gBbUserRegInfo.pinyin[i+j]) {
  		ij = 0; 	
  		}
  		
  	
  	for(;j&&j<7;j++) {/* if the gBbUserRegInfo.pinyin[i+j] is zero and j == 0;we neednt fix 7 '0'*/
  		curd.pinyin[i+j] = ' ';
  		}
  	if(j)i+=7;
  	
  	};
#else
    /* Use i as pointer for gBbUserRegInfo.pinyin,
       and j as pointer for curd.pinyin 

       Function: 
       Convert any string into YZ's internal 16 X 7 pinyin format */

#define MAX_PY_LEN 7

    i = j = 0;
    while ((i < UR_PINYIN_LEN) && (j < UR_PINYIN_LEN)) {
        if (gBbUserRegInfo.pinyin[i] == '\0') 
            break;

        for (ij=0; ij<MAX_PY_LEN; ij++) {
            if (gBbUserRegInfo.pinyin[i+ij] != ' ') {
                curd.pinyin[j+ij] = gBbUserRegInfo.pinyin[i+ij];
            } else break;
        }

        i += ij;
        j += ij; /* Update pointer */
        for ( ; ij<MAX_PY_LEN; ij++, j++)
            curd.pinyin[j] = ' ';

        /* skip to next non-space charactor */
        while (i < UR_PINYIN_LEN) {
           if (gBbUserRegInfo.pinyin[i] != ' ')
               break;
           else
               i++;
        }
    } 
    if (j < UR_PINYIN_LEN)
        bzero(curd.pinyin+j, UR_PINYIN_LEN-j); 
#endif
     
 curd.pinyin[i] = '\0';
#endif
/*  CEdit_ResetPoschar (&CE_clubid);*/
  /*CEdit_ResetPoschar(edit); */
  curd.birthdate[0] = gBbUserRegInfo.birthdate[0];
  curd.birthdate[1] =gBbUserRegInfo.birthdate[1];
  curd.birthdate[2] = gBbUserRegInfo.birthdate[2];
  curd.birthdate[3] = gBbUserRegInfo.birthdate[3];
  
  curd.birthdate[4] = 0;
  curd.birthdate[5] = 0;
  curd.birthdate[6] = gBbUserRegInfo.birthdate[4];
  curd.birthdate[7] = gBbUserRegInfo.birthdate[5];
  curd.birthdate[8] = 0;
  curd.birthdate[9] = 0;
  curd.birthdate[10] = gBbUserRegInfo.birthdate[6];
  curd.birthdate[11] = gBbUserRegInfo.birthdate[7];
  curd.birthdate[12] = 0;
  
  bcopy(gBbUserRegInfo.pinyin,curd.pinyin,UR_PINYIN_LEN);
  curd.pinyin[UR_PINYIN_LEN] = '\0';
  /*
  test
  */	
  /*gBbUserRegInfo.sex = 1;*/
  if(gBbUserRegInfo.sex == '0' || gBbUserRegInfo.sex == '2') {
  	/*CE_sex_male_e.numdisp = 1;
	CE_sex_femal_e.numdisp = 0;*/
	curd.sex = 0x32;
  }
  else {
  	/*CE_sex_male_e.numdisp = 0;
	CE_sex_femal_e.numdisp = 1;*/
	curd.sex = 0x31;
  }


  return 1;

};
int
localtobb ()
{
#if 0
  int i,j ;
  int ij = 1;
#endif 
  bcopy (curd.name, gBbUserRegInfo.name, UR_NAME_LEN);
  bcopy (curd.address, gBbUserRegInfo.address, UR_ADDRESS_LEN);
  bcopy (curd.phone, gBbUserRegInfo.phone, UR_PHONE_LEN);
  bcopy (curd.gBbClubId, gBbClubId, UR_EMAIL_LEN);
  gBbUserRegInfo.sex = curd.sex;
  gBbUserRegInfo.encoding = '1';
  gBbUserRegInfo.birthdate[0] = curd.birthdate[0]?curd.birthdate[0]:0;
  gBbUserRegInfo.birthdate[1] = curd.birthdate[1]?curd.birthdate[1]:0;
  gBbUserRegInfo.birthdate[2] = curd.birthdate[2]?curd.birthdate[2]:0;
  gBbUserRegInfo.birthdate[3] = curd.birthdate[3]?curd.birthdate[3]:0;
  gBbUserRegInfo.birthdate[4] = curd.birthdate[6]?curd.birthdate[6]:0;
  gBbUserRegInfo.birthdate[5] = curd.birthdate[7]?curd.birthdate[7]:0;
  gBbUserRegInfo.birthdate[6] = curd.birthdate[10]?curd.birthdate[10]:0;
  gBbUserRegInfo.birthdate[7] = curd.birthdate[11]?curd.birthdate[11]:0;
#if 0
 /* if(!*gBbClubId)*/ {
  	for(i=0;i<UR_PINYIN_LEN&&ij;) {
  		
  		for(j = 0;curd.pinyin[i+j]&&curd.pinyin[i+j]!=' ';j++) {
  		 	gBbUserRegInfo.pinyin[i+j] = curd.pinyin[i+j];
  		}
  		if(curd.pinyin[i+j]) {
  		gBbUserRegInfo.pinyin[i+j] = ' ';
  		i+=j+1;	
  		}
  		else {
  		i+=j;
  		ij = 0;	
  		}
  		
  	        
  		
  		
  	}
  	
  	curd.pinyin[i] = '\0';
#endif 
  bcopy(curd.pinyin,gBbUserRegInfo.pinyin,UR_PINYIN_LEN);
  curd.pinyin[UR_PINYIN_LEN] = '\0';
  /*}*/
  return 1;

};

int
compstr (const unsigned char *source, const unsigned char *dest)
{
  const unsigned char *sa, *da;
  sa = source;
  da = dest;
  for (; *sa && *da && (*sa == *da); sa++, da++);
  if (!(*sa) && !(*da))
    return 1;
  else
    return 0;
};

int
copystr (const unsigned char *source, unsigned char *dest)
{
  unsigned char *edest;
  const unsigned char *esource;
  edest = dest;
  esource = source;
  for (;*esource;)
    {
      *edest++ = *esource++;
    };
  *edest = 0;
  return (edest-dest);
}

int
lenstr (const unsigned char *string)
{
  int i = 0;
  for (; *string; string++, i++);
  return i;

};


int insertpinyin(CEdit *pinyin, int pos) {
	/*this will not check the beyond and some other illege problem, 
	I assume that all the check have done out of the function
	*/
#if 1	
	int i;
	char gsa[200];
	
	if(*(curd.pinyin+7*pos)) {
		copystr(curd.pinyin+7*pos,gsa);
		copystr(gsa,curd.pinyin+(pos+1)*7);
	}
	i = copystr(pinyin->string,curd.pinyin+7*pos);
	for(;i<7;i++) {
		*(curd.pinyin+7*pos+i) = ' ';
		};
#endif
	return 0;
	};
	
int deletepinyin(int pos) {
	/*this will not check the beyond and some other illege problem, 
	I assume that all the check have done out of the function
	*/
/*	char gsa[200];*/
#if 1
	/*if(pos) {*/
	copystr(curd.pinyin+(pos+1)*7,curd.pinyin+7*pos);
	/*}*/
#endif
	return 0;

	};

void
constructShenmu (void)
{
  int ne, nf, cef;
  CEdit **pcedit;
  pcedit = shenmulist;
  ne = nf = 0;
  cef = 3;

  for (; *pcedit; pcedit++)
    {
      if (ne < shenmune - 1)
	{
	  yumuedit_c[nf][ne++] = *pcedit;
	}
      else
	{

	  yumuedit_c[nf][ne] = 0;
	  yumuframe_c[nf] = yumuftemplate;
	  yumuframe_c[nf].edit = yumuedit_c[nf];
	  yumuframe_c[nf].numedit = ne;
	  chinesepanel[cef++] = &yumuframe_c[nf];
	  nf++;
	  ne = 0;
	  pcedit--;
	}


    }
  if (ne)
    {
      yumuedit_c[nf][ne] = 0;
      yumuframe_c[nf] = yumuftemplate;
      yumuframe_c[nf].edit = yumuedit_c[nf];
      yumuframe_c[nf].numedit = ne;
      chinesepanel[cef++] = &yumuframe_c[nf];

    }
  chinesepanel[cef] = 0;
  GC_panel[0].numframe = cef;
  GC_panel[0].focusframe = 3;
 *(pychar.string) = 0;
  shenoryun = 0;
  buildRefereceChinese ();

};
void
constructYumu (const unsigned char *shenmu)
{
  unsigned char ***psytab;
  unsigned char **p_shenmu;
  int ne, nf, cef;
  CEdit *pcedit;
  psytab = (unsigned char ***) sytable;
  ne = nf = 0;
  cef = 3;
  for (; (p_shenmu = *psytab); psytab++)
    {
      if (compstr (shenmu, *p_shenmu))
	{
	  for (p_shenmu++; *p_shenmu; p_shenmu++)
	    {
	      pcedit = (CEdit *) (*p_shenmu);
	      if (ne < numedit_c - 1)
		{
		 /* if(!nf&&ne == 1) {
		  	pcedit->ux = 0;
		  	}*/
		  yumuedit_c[nf][ne++] = pcedit;
		  
		}
	      else
		{
		  yumuedit_c[nf][ne] = 0;
		  yumuframe_c[nf] = yumuftemplate;
		  yumuframe_c[nf].edit = yumuedit_c[nf];
		  yumuframe_c[nf].numedit = ne;
		  chinesepanel[cef++] = &yumuframe_c[nf];
		  nf++;
		  ne = 0;
		  p_shenmu--;
		}

	    }
	  if (ne)
	    {
	      yumuedit_c[nf][ne] = 0;
	      yumuframe_c[nf] = yumuftemplate;
	      yumuframe_c[nf].edit = yumuedit_c[nf];
	      yumuframe_c[nf].numedit = ne;
	      chinesepanel[cef++] = &yumuframe_c[nf];

	    }
	  chinesepanel[cef] = 0;
	  GC_panel[0].numframe = cef;
	  GC_panel[0].focusframe = 3;
	  /*in this position to adust the position*/
	  /*yumuframe_c[nf].edit  = 0; */
	  break;
	}

    }
  shenoryun = 1;
  buildRefereceChinese ();
};





void
setshenmu (CEdit * cedit)
{
  unsigned char *sour = cedit->string;
  unsigned char *dest = pychar.string;
#ifdef CDEBUG
  osSyncPrintf ("\n**Start setshenmu\n");
#endif
  initChineseInput ();
  if (sour&&cedit->cet == TEXTCO)
    {
      for (; *sour;)
	{
#ifdef CDEBUG
	  osSyncPrintf ("%c\n", (*sour) + 32);
#endif
	  
	  *dest++ = *sour++;


	}
      *dest = 0;
    }
    dest = pychar.string;
    for(;*dest;dest++) {
    	addNameChar ((*dest) + 32);
    	}
#ifdef CDEBUG
  osSyncPrintf ("\n**End setshenmu\n");
#endif

};
void
setyumu (CEdit * cedit)
{
  unsigned char *source = cedit->string;
  unsigned char *dest = pychar.string;
  unsigned char ts[12];
  unsigned char *pts = ts;
  initChineseInput ();
  if (cedit->cet == TEXTCO)
    {
      for (; *dest && ('A' <= *dest && *dest <= 'Z'); dest++)
	{
	  /*addNameChar (*dest + 32);*/
	  *pts++ = *dest; 
	}
	*pts = 0;
	/**dest = 0;*/
	if(!compstr(source,ts)) {
	      for (; *source;)
		{
		  /**dest++ = *source;*/
		  *pts++ = *source++;  
		  /**dest = 0;*/
		  /*addNameChar (*source++);*/
		}
		*pts = 0;
	}
	/**(pychar.string+8) = '\0';*/
    	copystr(ts,pychar.string);
    	pts = ts;
    	for(;*pts;pts++) {
    	if('A' <= *pts && *pts <= 'Z')	{
    	  addNameChar( *pts+32);  	
    	}
    	else {
    		addNameChar(*pts);
    	}
    	
    	
    		
    	}
    	
    /*  *dest = 0;*/
    };

};

void
buildRefereceChinese (void)
{
  CFrame *nfr;
  CEdit *ner;
  if (currentpanel->paneltype == CHINESE && 3 <= currentpanel->focusframe &&
      currentpanel->focusframe <= currentpanel->numframe - 1)
    {
      nfr = *(currentpanel->focusframe + currentpanel->cframe);
      ner = *(nfr->edit + nfr->focusedit);

      if (shenoryun)
	{

	  setyumu (ner);
	}
      else
	{

	  setshenmu (ner);

	};


    };

}


#define  GBCODE_START 0xA1
CString
constructDrawStr (const unsigned char *s, int limit)
{
  const unsigned char *ps;
  unsigned char *pcsa, *pws;
  short ws;
  CString cs = { gcsa, 0 };
  int i, j;
  i = limit == -1 ? 201 : limit;
  ps = s;
  pcsa = gcsa;
  bzero(gcsa,200);
  for (j = 0; j < i && *ps && (*ps != '\\'); j++)
    {
      if (*ps >= GBCODE_START)
	{
	  *pcsa++ = *ps++;
	  /*pcsa++;
	     ps++; */
	  *pcsa++ = *ps++;
	  /*pcsa++;
	     ps++; */
	}
      else
	{
	  if ('a' <= *ps && *ps <= 'z')
	    {			/*low letter */
	      ws = 0xa3e1 + *ps - 'a';

	    }
	  else if ('A' <= *ps && *ps <= 'Z')
	    {			/*up letter */
	      ws = 0xa3c1 + *ps - 'A';
	    }
	  else if ('0' <= *ps && *ps <= '9')
	    {			/*digital */
#ifdef CDEBUG
	      osSyncPrintf ("The number is 0!\n");
#endif
	      ws = 0xa3b0 + *ps - '0';
	    }
	  else
	    {			/* "@_." */
	      switch (*ps)
		{
		case '@':
		  ws = 0xa3c0;
		  break;
		case '.':
		  ws = 0xa3b0 - 2;
		  break;
		case '_':
		  ws = 0xa3da + 5;
		  break;
		 case ' ':
		  ws = 0xa1a1;
		  break;
		 case '-':
		  ws = 0xa3ad;
		  break;
		default:
		  ws = 0xa3b0;
		  break;

		};
	    }
	  pws = (unsigned char *) &ws;
	  *pcsa++ = *pws++;
	  *pcsa++ = *pws++;
	  ps++;

	}

    }
  cs.length = j;
  *pcsa = 0;
  /**(cs.s+j*2) = '\0';*/
  return cs;
};




void
ClearMessage (CMessage * cmessage)
{

  cmessage->CUP_CURSOR = 0;
  cmessage->CDOWN_CURSOR = 0;
  cmessage->CFORWARD_CURSOR = 0;
  cmessage->CBACK_CURSOR = 0;
  cmessage->CSTART_BUTTON = 0;	/*is the start button */

  cmessage->CA_BUTTON = 0;	/*is the A Button */

  cmessage->CB_BUTTON = 0;	/*is the B Button */

  cmessage->CU_CBUTTONS = 0;	/* is the C Button Up */

  cmessage->CD_CBUTTONS = 0;	/* is the C Button Down */

  cmessage->CL_CBUTTONS = 0;	/*is the C Button Left */

  cmessage->CR_CBUTTONS = 0;	/*is the C Button Right */

  cmessage->CU_JPAD = 0;	/* is the Control Stick Up */

  cmessage->CD_JPAD = 0;	/* is the Control Stick Down */

  cmessage->CL_JPAD = 0;	/* is the Control Stick Left */

  cmessage->CR_JPAD = 0;	/* is the Control Stick Right */

  cmessage->CZ_TRIG = 0;	/* is the Z Button */

  cmessage->CL_TRIG = 0;	/* is the L Button */

  cmessage->CR_TRIG = 0;	/* is the R Button  */
 
};

void
GetMessage (CMessage * cmessage, OSContPad ** pad)
{

  	ClearMessage (cmessage);
  #ifdef DEBUG_CURSOR
  if (pad[0]->button & U_JPAD && !(cmessage->oldbut & U_JPAD))
    {
	switch (whichparameter) {
	case 0:
		if(xcursoroffset<100)xcursoroffset++;
		
	break;
	case 1:
		if(xcursordelay <100)xcursordelay++;
	break;
	case 2:
		if(ycursoroffset<100)ycursoroffset++;
	break;
	case 3:
		if(ycursordelay <100)ycursordelay++;
	break;
	default:
	break;	
		
	}
	
      /*cmessage->CU_JPAD = 1;*/
      
    };
    if (pad[0]->button & D_JPAD && !(cmessage->oldbut & D_JPAD))
    {
	switch (whichparameter) {
	case 0:
		if(xcursoroffset>0)xcursoroffset--;
		
	break;
	case 1:
		if(xcursordelay >0)xcursordelay--;
	break;
	case 2:
		if(ycursoroffset>0)ycursoroffset--;
	break;
	case 3:
		if(ycursordelay >0)ycursordelay--;
	break;
	default:
	break;	
		
	}
      /*cmessage->CD_JPAD = 1;*/
    };
    if (pad[0]->button & L_JPAD && !(cmessage->oldbut & L_JPAD))
    {
	if(whichparameter == 0)whichparameter = 3;
	else whichparameter--;
      /*cmessage->CL_JPAD = 1;*/
    };
    if (pad[0]->button & R_JPAD && !(cmessage->oldbut & R_JPAD))
    {
	if(whichparameter == 3)whichparameter = 0;
	else whichparameter++;
      /*cmessage->CR_JPAD = 1;*/
    };
/*int xcursoroffset =  25;
int ycursoroffset =  30;
int xcursordelay  =   6;
int ycursordelay  =   6;*/
#endif
 	 if(cmessage->cursoroffset >= cmessage->cursordelay )
 	{
  	cmessage->cursoroffset = 0;
  	cmessage->CDIS_CURSOR = 1 - cmessage->CDIS_CURSOR;
	}
	else {
	cmessage->cursoroffset++;	
	}

	if(pad&&pad[0]) {
  if (pad[0]->stick_x <= -cmessage->xoffset)
    {
      if (cmessage->xdelaytime >= cmessage->xdelay)
	{
	  cmessage->xdelaytime = 0;
	  cmessage->CBACK_CURSOR = 1;
	}
      else
	cmessage->xdelaytime++;
    }
  else if (pad[0]->stick_x >= cmessage->xoffset)
    {
      if (cmessage->xdelaytime >= cmessage->xdelay)
	{
	  cmessage->xdelaytime = 0;
	  cmessage->CFORWARD_CURSOR = 1;
	}
      else
	cmessage->xdelaytime++;
    }

  if (pad[0]->stick_y <= -cmessage->yoffset)
    {

      if (cmessage->ydelaytime >= cmessage->ydelay)
	{

	  cmessage->ydelaytime = 0;
	  cmessage->CDOWN_CURSOR = 1;
	}
      else
	cmessage->ydelaytime++;
    }
  else if (pad[0]->stick_y >= cmessage->yoffset)
    {

      if (cmessage->ydelaytime >= cmessage->ydelay)
	{

	  cmessage->ydelaytime = 0;
	  cmessage->CUP_CURSOR = 1;
	}
      else
	cmessage->ydelaytime++;
    };
  if (pad[0]->button & CONT_G && !(cmessage->oldbut & CONT_G))
    {

      cmessage->CZ_TRIG = 1;
    }
  if (pad[0]->button & CONT_A && !(cmessage->oldbut & CONT_A))
    {
      cmessage->CA_BUTTON = 1;
    };
  if (pad[0]->button & CONT_B && !(cmessage->oldbut & CONT_B))
    {
      cmessage->CB_BUTTON = 1;
    }
  if (pad[0]->button & CONT_R && !(cmessage->oldbut & CONT_R))
    {
      cmessage->CR_TRIG = 1;
    }
    
    if (pad[0]->button & U_CBUTTONS && !(cmessage->oldbut & U_CBUTTONS))
    {
      cmessage->CU_CBUTTONS = 1;
    }
    if (pad[0]->button & D_CBUTTONS && !(cmessage->oldbut & D_CBUTTONS))
    {
      cmessage->CD_CBUTTONS = 1;
    }
    if (pad[0]->button & L_CBUTTONS && !(cmessage->oldbut & L_CBUTTONS))
    {
      cmessage->CL_CBUTTONS = 1;
    }
    if (pad[0]->button & R_CBUTTONS && !(cmessage->oldbut & R_CBUTTONS))
    {
      cmessage->CR_CBUTTONS = 1;
    }
    
    };
};

void CMessage_UpDigital(CMessage *cmessage) {
	/*if(cmessage->enterdigital >= cmessage->digitalmax) cmessage->enterdigital = cmessage->digitalmin;
	else cmessage->enterdigital += 1;
	 	*((cmessage->edit)->string + (cmessage->edit)->poscur) = cmessage->enterdigital;*/
	
	};

void CMessage_DownDigital(CMessage *cmessage) {
	/*if(cmessage->enterdigital <= cmessage->digitalmin) cmessage->enterdigital = cmessage->digitalmax;
	else cmessage->enterdigital -= 1;
	 	*((cmessage->edit)->string + (cmessage->edit)->poscur) = cmessage->enterdigital;
	*/
	};



Gfx* CDraw_Glyph(Gfx** glisp,const char *s, const char *img,int x, int y, int spacex,int spacey ,float ratio ,int utol) {
		Gfx* gl = *glisp;
		const char *rs = s;
		const char *imgpos;
		int lx,ly ,ux ,uy;
		int offset;
		gDPPipeSync (gl++);
		gDPSetCycleType(gl++,G_CYC_1CYCLE);
		gDPSetTexturePersp (gl++,G_TP_NONE);
	 	gDPSetTextureLOD (gl++,G_TL_TILE);
	  	gDPSetTextureFilter (gl++,G_TF_BILERP);
	  	gDPSetTextureConvert(gl++,G_TC_FILT);
	  	gDPSetTextureLUT (gl++,G_TT_NONE);
	  	gDPSetPrimColor(gl++,255,255,255,255,255,255);	
		gDPSetRenderMode(gl++,G_RM_TEX_EDGE,G_RM_TEX_EDGE2);
		gDPSetCombineMode(gl++,G_CC_MODULATEIA_PRIM,G_CC_MODULATEIA_PRIM);
		lx = x;
		ly = y;
		ux = x + 16*ratio;
		uy = y + 16*ratio;
		for(;*rs;rs++) {
			offset = 0;
			
			if    ('0'<=*rs&&*rs<='9') {
			imgpos = img +  (*rs - '0')*512;/*  16*16*2 */		
			}
			else if('a'<=*rs&&*rs<='z'){
			imgpos = img +  (*rs - 'a' + 10)*512;
			if(*rs == 'g'||*rs == 'p'||*rs == 'q') {
				offset = 1;
			}
			
			}
			else if('A'<=*rs&&*rs<='Z') {
				if(utol) {
				imgpos = img + (*rs+32-'a'+10)*512;	
				if(*rs +32 == 'g'||*rs +32 == 'p' || *rs +32 == 'q') {
					offset = 1;
				}
				
				}
				else {
				imgpos = img + (*rs - 'A' + 36)*512;
				}
			
		
			}
			else if(*rs == '-') {
				imgpos = img+62*512;
				
			}
			else if(*rs == '_') {
				imgpos = img +63*512;
			}
			else if(*rs == '.') {
				imgpos = img+64*512;
			}
			else if(*rs == '@') {
				imgpos = img+65*512;
			}
			
			else {
			imgpos =(const char *) -1;	
			};
			
			if(imgpos>=0) {
				
				gDPLoadTextureBlock (gl++,imgpos, G_IM_FMT_RGBA,G_IM_SIZ_16b , 16, 16, 0,
   	 			G_TX_WRAP | G_TX_NOMIRROR, G_TX_WRAP | G_TX_NOMIRROR,
    				G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD);
				gSPTextureRectangle(gl++,lx<<2,offset?((ly+(int)(ratio*3))<<2):(ly<<2),ux<<2,offset?((uy+(int)(ratio*3))<<2):(uy<<2),G_TX_RENDERTILE,
				0<<6,0<<6,((1.0)/((float)ratio))*(1<<10),((1.0)/((float)ratio))*(1<<10));	
				gDPPipeSync (gl++);
				lx += ratio*16+spacex;
				ux = lx + 16*ratio;
				
			}
			else {/*that all other character we use space*/
			lx += ratio*16+spacex;	
			ux = lx + 16*ratio;
			}
			
			
			
			
			
			}
		return gl;
	
	};


Gfx* CDraw_GlyphIndex(Gfx** glisp,const unsigned char *s, const char *img,int x, int y, int spacex,int spacey ,float ratio ) {
	Gfx *gl = *glisp;
	int ix ,iy ,ux ,uy;
	const unsigned char *ps;
	const char* ipos ;
	ps = s;
	 ix =0;
	 iy =0;
	 
	 ix = x;
	 iy = y;
	 
		gDPPipeSync (gl++);
		gDPSetCycleType(gl++,G_CYC_1CYCLE);
		gDPSetTexturePersp (gl++,G_TP_NONE);
	 	gDPSetTextureLOD (gl++,G_TL_TILE);
	  	gDPSetTextureFilter (gl++,G_TF_BILERP);
	  	gDPSetTextureConvert(gl++,G_TC_FILT);
	  	gDPSetTextureLUT (gl++,G_TT_NONE);
	  	gDPSetPrimColor(gl++,255,255,255,255,255,255);	
		gDPSetRenderMode(gl++,G_RM_TEX_EDGE,G_RM_TEX_EDGE2);
		gDPSetCombineMode(gl++,G_CC_MODULATEIA_PRIM,G_CC_MODULATEIA_PRIM);
		#if 1
		for(;*ps;) {
			if(*ps ==  0xa1) {
			ipos =( *(ps+1))*24*24*2+img;
			ux = ix + 24*ratio;
			uy = iy +24*ratio;
			gDPLoadTextureBlock (gl++,ipos, G_IM_FMT_RGBA,G_IM_SIZ_16b , 24, 24, 0,
   	 			G_TX_WRAP | G_TX_NOMIRROR, G_TX_WRAP | G_TX_NOMIRROR,
    				G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD);
				gSPTextureRectangle(gl++,ix<<2,iy<<2,ux<<2,uy<<2,G_TX_RENDERTILE,
				0<<6,0<<6,((1.0)/((float)ratio))*(1<<10),((1.0)/((float)ratio))*(1<<10));	
				gDPPipeSync (gl++);
			ps+=2; 	
			ix += 24*ratio + spacex;
			
			 			
			}
			else if(*ps ==  '\n') {
				
				ps++;
				iy += 24*ratio + spacey;
				ix = x;
				
			}
			else {
			ps++;
			}
			
			
			
		}
		#endif 
		/*gDPLoadTextureBlock (gl++,ipos, G_IM_FMT_RGBA,G_IM_SIZ_16b , 24, 24, 0,
   	 			G_TX_WRAP | G_TX_NOMIRROR, G_TX_WRAP | G_TX_NOMIRROR,
    				G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD);
				gSPTextureRectangle(gl++,ix<<2,iy<<2,ux<<2,uy<<2,G_TX_RENDERTILE,
				0<<6,0<<6,((1.0)/((float)ratio))*(1<<10),((1.0)/((float)ratio))*(1<<10));*/
			
		return gl;
};
int
CEdit_ResetPoschar (CEdit * edit)
{
  unsigned char *s, *ps;
  int i;
  s = edit->string;
  ps = s;
  #ifdef DEBUG
osSyncPrintf("CEdit ResetPoschar  Cursor\n");
#endif
  for (; *s;)
    {
      ps = s;
      if (*s >= GBCODE_START)
	s += 2;
      else
	s++;
    };
  if (*ps)
    {
      i = ps - edit->string;
      if (*ps >= GBCODE_START)
	{
	 /* if (i + 2 >= edit->max)
	    edit->poschar = i;
	  else*/
	    edit->poschar = i + 2;

	}
      else
	{
	  /*if (i + 1 >= edit->max)
	    edit->poschar = i;
	  else*/
	    edit->poschar = i + 1;

	}


    }
  else
    edit->poschar = 0;

  return 1;

};

int
CEdit_ResetPoscur (CEdit * edit)
{
	
  unsigned char *s, *ps;
  int i;
  s = edit->string;
  ps = s;
  #ifdef DEBUG
osSyncPrintf("CEdit ResetPoscur  Cursor\n");
#endif
  for (; *s;)
    {
      ps = s;
      if (*s >= GBCODE_START)
	s += 2;
      else
	s++;
    };
  if (*ps)
    {
      i = ps - edit->string;
      if (*ps >= GBCODE_START)
	{
	 /* if (i + 2 >= edit->max)
	    edit->poschar = i;
	  else*/
	    edit->poschar = i + 2;

	}
      else
	{
	  /*if (i + 1 >= edit->max)
	    edit->poschar = i;
	  else*/
	    edit->poschar = i + 1;

	}


    }
  else
    edit->poschar = 0;

  return 1;

};

int
CEdit_AddChar (CEdit * edit, unsigned char s)
{

  /*if(edit->poschar+1<=edit->max) {
     if(edit->editable&&edit->string)
     {
     *(edit->string+edit->cur+edit->curchar) = s;
     if(edit->cur == edit->poschar)
     edit->poschar++;
     if(edit->poschar<edit->max)
     CEdit_ForwardCursor(edit);
     return 1;
     }
} */
#if 0
  if (edit->string && edit->editable)
    {
      /*if (edit->poschar <= edit->max - 1 && edit->poscur == edit->poschar)*/
      if (edit->poschar <= edit->max - 1 && edit->poscur <= edit->poschar)
	{
	  /**(edit->string + edit->poschar) = s;
	  if (edit->poschar < edit->max - 1)
	    {
	      edit->poschar++;
	      *(edit->string + edit->poschar) = '\0';
	      *(edit->poschar + edit->string + 1) = '\0';
	    }
	  else
	    {
	      *(edit->poschar + edit->string + 1) = '\0';
	    }*/
	    *(edit->string+edit->poscur) = s;
	    if(edit->poscur == edit->poschar && edit->poschar < edit->max - 1) {
	    	edit->poschar++;
	      *(edit->string + edit->poschar) = '\0';
	      *(edit->poschar + edit->string + 1) = '\0';
	    	}
	  CEdit_ForwardCursor (edit);


	}

}
#endif
  return 0;
};

void CEdit_DataSync(unsigned char c,CEdit *f,CEdit *s) {
	*(f->string) = (c/10) + 30;
	*(s->string) = (c%10) + 30;
	}

int
CEdit_RepChar (CEdit * edit, unsigned char s)
{

  /*if(edit->poschar+1<=edit->max) {
     if(edit->editable&&edit->string)
     {
     *(edit->string+edit->cur+edit->curchar) = s;
     if(edit->cur == edit->poschar)
     edit->poschar++;
     if(edit->poschar<edit->max)
     CEdit_ForwardCursor(edit);
     return 1;
     }
} */
#if 0
  if (edit->string && edit->editable)
    {
      /*if (edit->poschar <= edit->max - 1 && edit->poscur == edit->poschar)*/
      if (edit->poschar <= edit->max - 1 && edit->poscur <= edit->poschar)
	{
	  /**(edit->string + edit->poschar) = s;
	  if (edit->poschar < edit->max - 1)
	    {
	      edit->poschar++;
	      *(edit->string + edit->poschar) = '\0';
	      *(edit->poschar + edit->string + 1) = '\0';
	    }
	  else
	    {
	      *(edit->poschar + edit->string + 1) = '\0';
	    }*/
	    *(edit->string+edit->poscur) = s;
	    if(edit->poscur == edit->poschar && edit->poschar < edit->max - 1) {
	    	edit->poschar++;
	      *(edit->string + edit->poschar) = '\0';
	      *(edit->poschar + edit->string + 1) = '\0';
	    	}
	 /* CEdit_ForwardCursor (edit);*/


	}

}
#endif 
  return 0;
};
int
CEdit_AddWChar (CEdit * edit, short s)
{
  /*if(edit->poschar+2<=edit->max) {
   *((short *)(edit->string+edit->cur+edit->curchar)) = s; 
   edit->poschar+=2;
   CEdit_ForwardCursor(edit);
   return 1;
   }
   return 0;*/
 
  unsigned char *m;
   CFrame** nfr = currentpanel->cframe;
  m = (unsigned char *) &s;
  if (edit->string && edit->editable)
    {
      /*if (edit->poschar <= edit->max - 1 && edit->poscur == edit->poschar)*/
      if (edit->poschar <= edit->max - 1 && edit->poscur <= edit->poschar)
	{

		/**((short *)(edit->string+edit->poschar)) = s;*/
		/*
	  *(edit->string + edit->poschar) = *m++;
	  *(edit->string + edit->poschar + 1) = *m;
	  if (edit->poschar < edit->max - 1
	      && (edit->poschar + 2 < edit->max))
	    edit->poschar += 2;*/
	    *(edit->string + edit->poscur)  	= *m++;
	    *(edit->string + edit->poscur+1)	= *m;
	    if (edit->poschar < edit->max - 1
	      && (edit->poschar + 2 < edit->max)&&(edit->poschar == edit->poscur)) {
	      	edit->poschar += 2;
	      	}
	  CEdit_ForwardCursor (edit);
	 if(!*curd.pinyin&&edit->strux == ADDRESS) {
	 	 insertpinyin(*((*(nfr+1))->edit),(edit->poscur-2)/2);
	 	
	 	}
	  return 1;
	}

    };
  return 0;

};

int CEdit_InsertChar(CEdit* edit,unsigned char c) {
	unsigned char s[100];
	
	#ifdef DEBUG
osSyncPrintf("CEdit InsertChar  Cursor\n");
#endif
	if (edit->string && edit->editable) {
		if(edit->poschar <=edit->max-1) {
			copystr(edit->string+edit->poscur,s);
			copystr(s,edit->string+edit->poscur+1);
			*(edit->string+edit->poscur) = c;
			edit->poscur++;
			edit->poschar++;
			/*move the cursor*/
			if(edit->cur<edit->numdisp)edit->cur++;
			else edit->curchar++;
			
			return 1;
			}
	}
	return 0;
	};

int CEdit_InsertWChar(CEdit* edit ,unsigned short s) {
	unsigned char sa[180];
	unsigned char *m;
	/*int pyp;*/
	    CFrame* nfr;
	    CEdit* nedit;
        m = (unsigned char *) &s;
        #ifdef DEBUG
osSyncPrintf("CEdit InsertWChar  Cursor\n");
#endif
	if (edit->string && edit->editable) {
		if(edit->poschar<=edit->max-1) {
			copystr(edit->string+edit->poscur,sa);
			copystr(sa,edit->string+edit->poscur+2);
			*(edit->string + edit->poscur)  	= *m++;
	    		*(edit->string + edit->poscur+1)	= *m;
	    		/*if(!*curd.gBbClubId&&edit->strux == ADDRESS) {
				pyp = edit->poscur/2;				
				copystr(curd->pinyin+pyp*7,sa);
				copystr(sa,curd->pinyin+pyp*8);
			}*/
		#if 1
			/*if(!*curd.gBbClubId&&edit->strux == NAME) {*/
				if(edit->strux == NAME) {
				if(currentpanel->paneltype == ENGLISH) {
					nfr = *(currentpanel->cframe+currentpanel->focusframe);	
					nedit = *(nfr->edit+nfr->focusedit);
					
				}
				else {/*chinese reference input*/
				nfr = *(currentpanel->cframe+1);
				nedit = *(nfr->edit);
				}
				
	 	 /*insertpinyi(*((*(nfr+1))->edit),(edit->poscur-2)/2);*/
	 			insertpinyin(nedit,(edit->poscur)/2);
	 			
	 	 }
	 	 #endif
			edit->poscur+=2;
			edit->poschar+=2;
			if(edit->cur<edit->numdisp)edit->cur++;
			else edit->curchar+=2;
			
			return 1; 
			}
	 }
	return 0;
	};

int
CEdit_DelChar (CEdit * edit)
{
  /*int i; */
  #ifdef DEBUG
osSyncPrintf("CEdit DelChar  Cursor\n");
#endif
  if (edit->string && edit->editable)
    {
      if (*(edit->string + edit->poscur))
	{
	  if (*(edit->string + edit->poscur) >= GBCODE_START)
	    {/*delete Chinese character*/
	    
		
	      if(edit->poscur + 2 >= edit->max||edit->poscur+2 == edit->poschar) 
	        {/*if the delete position is the last position ,then I only make them zeor*/
	        	*(edit->string+edit->poscur) =   '\0';
	        	*(edit->string+edit->poscur+1) = '\0';
	        }
	        else {/* if the delete position is middle of the edit, so I must copy the follow 
	        	character to the delete position
	        	*/
	      		copystr (edit->string + edit->poscur + 2,
		       		 edit->string + edit->poscur);
		       		 
		      }
	    	/*The last position want change to repose the new position*/
	      CEdit_ResetPoschar (edit);
	      return 1;
	    }
	  else
	    {/*delete English character*/
	      /*copystr(edit->string+edit->poscur+1,edit->string+edit->poscur);
	         if(edit->poscur<edit->max-1){*(edit->string+edit->poschar) = '\0';edit->poschar--;} */
	      if(edit->poscur + 1 >= edit->max)
	      {
	      	*(edit->string+edit->poscur) = '\0';	
	      }
	      else 
	      {
		      copystr (edit->string + edit->poscur + 1,
			       edit->string + edit->poscur);
	      }
	      CEdit_ResetPoschar (edit);
	      return 1;

	    }




	}


    };
  return 0;
}

int CEdit_PutCursorLast(CEdit *edit) {
	int i ;
	int num = 0;
	if(edit) {
		edit->poscur = edit->poschar;
		for(i = edit->poschar;i > 0&&num<edit->numdisp-1;) {
		i = i - 1;
		if( *(edit->string+i)>=GBCODE_START) {
		i = i - 1;
		}
		num++;
		}
		edit->curchar = i;
		edit->cur = num;
		return 1;
		};
		
	return 0;
	};

int CEdit_BackChar(CEdit *edit) {
	int is , pos;
	int curs , ccurs;
	if(edit->poscur) {
	pos = edit->poscur;
	CEdit_BackCursor(edit);
	is =  CEdit_DelChar(edit);
	if(is  &&edit->strux == NAME) {
		/*if(is && !*curd.gBbClubId &&edit->strux == NAME) {*/
		deletepinyin((pos-2)/2);
	}
	/*if(edit->poschar&&!edit->cur) {
	CEdit_putCursorLast(edit);	
	}*/
	if(edit->curchar&&!edit->cur) {
	pos = edit->poscur;
	CEdit_PutCursorLast(edit);
	curs = 0;
	for(ccurs = edit->curchar ;ccurs < pos;) {
		if(*(ccurs+edit->string)>= GBCODE_START) {
		ccurs+=2;	
		}
		else {
			ccurs++;
	}
	curs++;
		
	}
	edit->cur = curs;
	edit->poscur = pos;
	
	}
	/*CEdit_PutCursorLast(edit);*/
	return is;
	}
	else {
		return 0;
		}
	
	};

int
CEdit_ForwardCursor (CEdit * edit)
{

  /*if(edit->curchar+edit->cur<edit->poschar&&edit->curchar+edit->cur<edit->max-1) {
     if(edit->cur < edit->numdisp-1) {edit->cur++;edit->poscur++;}
     else edit->curchar++;
     return 1;

} */
#ifdef DEBUG
osSyncPrintf("CEdit Forward  Cursor\n");
#endif
  if (edit->cet == TEXTCO)
    return 0;

  else if (edit->cet == INPUTREF)
    {
      if (titleGetNumberString ())
	nextTitleLetter ();
	playSound(3,0);
	return 1;
    }
  else
    {
      if (edit->poscur < edit->poschar)
	{
	  if (edit->cur < edit->numdisp - 1)
	    {			/*move the cursor */

	      edit->cur++;
	      if (*(edit->string + edit->poscur) >= 0xA1)
		{
		  edit->poscur += 2;
		}
	      else
		{
		  edit->poscur++;
		}

	    }
	  else
	    {			/*move the curchar */
	      if (*(edit->string + edit->curchar) >= 0xA1)
		{
		  edit->curchar += 2;

		}
	      else
		{
		  edit->curchar++;
		}
	      if (*(edit->string + edit->poscur) >= 0xA1)
		{
		  edit->poscur += 2;
		}
	      else
		{
		  edit->poscur++;
		}
	    }
	playSound(3,0);
	  return 1;
	}
    }
  return 0;
};

int
CEdit_BackCursor (CEdit * edit)
{
  /*if(edit->cur>0) {  edit->cur--; edit->poscur-- ;return 1;}
     else if(edit->curchar >0) {edit->curchar--;return 1;} */
     #ifdef DEBUG
osSyncPrintf("CEdit back  Cursor\n");
#endif
  if (edit->cet == TEXTCO)
    return 0;
  else if (edit->cet == INPUTREF)
    {
      upTitleLetter ();
      playSound(3,0);
      return 1;
    }
  else
    {
      if (edit->cur > 0)
	{			/*move the cursor */
	  edit->cur--;
	  if (edit->poscur >= 2 && *(edit->string + edit->poscur - 2) >= 0xA1
	      && *(edit->string + edit->poscur - 1) >= 0xA1)
	    {
	      edit->poscur -= 2;
	    }
	  else
	    edit->poscur--;
	  /*if(*(edit->string+edit->poscur)>=0xA1){
	     edit->poscur-=2;     
	     }
	     else  {
	     edit->poscur--;
	} */
	playSound(3,0);
	  return 1;
	}
      else
	{			/*move the curchar */
	  if (edit->curchar > 0)
	    {

	      /*if(*(edit->string+edit->curchar)>=0xA1){
	         edit->curchar-=2;
	         edit->poscur-=2;     
	         } */
	      if (edit->curchar >= 2
		  && *(edit->string + edit->curchar - 2) >= 0xA1
		  && *(edit->string + edit->curchar - 1) >= 0xA1)
		{
		  edit->curchar -= 2;
		  edit->poscur -= 2;
		}
	      else
		{
		  edit->curchar--;
		  edit->poscur--;
		}
		playSound(3,0);
	      return 1;
	    }

	}
    }


  return 0;

}


Gfx *
CEdit_DrawString (CEdit * edit, Gfx ** glistp, int focus, int ux, int uy )
{
  Gfx *gl;
  CString csa;
  int m ,n ;
  
#ifdef CDEBUG
  static int i, j;
#endif
  gl = *glistp;

  if (edit->cet == INPUT)
    {
      /*csa = constructDrawStr (pyGetString (), edit->numdisp);
      gl = ShowString (&gl, (char *) csa.s, csa.length, ux + 2, uy + 5, 5 ,255,255,255,-1,255,255,255);*/
    }
  else if (edit->cet == INPUTPY)
    {
      /*csa = constructDrawStr (edit->string + edit->curchar, edit->numdisp);*/
      /*gl = ShowString (&gl, (char *) csa.s, csa.length, ux + 2, uy + 5, 0 , 255,255,255,-1,255,255,255);*/
      gl = CDraw_Glyph(&gl,edit->string, glyph16x16_tex,ux+2, uy+5, -4,0 ,1.4 ,1.4);
    }
  else if (edit->cet == INPUTREF )
    {
#if  1
/*#ifdef CDEBUG
osSyncPrintf("**Start CEdit_DrawString\n");
#endif*/
      /*csa = constructDrawStr (titleGetString (), edit->numdisp);*/
#ifdef CDEBUG
      j = 1000000;
      if (j == 1000000)
	{
	  /*osSyncPrintf("\n**Start CEdit_DrawString\n"); */
	  for (i = 0; i < csa.length; i += 2)
	    {
	      osSyncPrintf ("0x%04x    ", *(u16 *) (csa.s + i));
	    }

/*osSyncPrintf("**\nStart CEdit_DrawString\n");*/
	}
      j = (++j) % 1000001;

#endif
      	gDPSetCycleType (gl++, G_CYC_1CYCLE);
	  gDPPipelineMode (gl++, G_PM_1PRIMITIVE);
	  /*gsDPSetScissor(G_SC_NON_INTERLACE, 0, 0, SCREEN_WD, SCREEN_HT), */
	  gDPSetTextureLOD (gl++, G_TL_TILE);
	  gDPSetTextureLUT (gl++, G_TT_NONE);
	  gDPSetTextureDetail (gl++, G_TD_CLAMP);
	  gDPSetTexturePersp (gl++, G_TP_NONE);
	  gDPSetTextureFilter (gl++, G_TF_POINT);
	  gDPSetCombineMode (gl++, G_CC_DECALRGBA, G_CC_DECALRGBA);
	  /*gDPSetCombineMode(gl++,G_CC_MODURGBA, G_CC_DECALRGBA); */
	  gDPSetCombineKey (gl++, G_CK_NONE);
	  gDPSetAlphaCompare (gl++, G_AC_NONE);
	  gDPSetRenderMode (gl++, G_RM_TEX_EDGE, G_RM_TEX_EDGE2);
	  for(m = 0;m<titleGetNumberString()/2;m++) {
	  	
	  	tileRectangle (&gl,
			(focus&&m ==titleGetCursor()/2 )?(void *)yunmubuttonh_tex:(void *)yunmubutton_tex, G_IM_FMT_RGBA, 16, 40,
			 32, 32, 32, 0, 0, 40,
			 32, m*40+ux + 2, uy);
	}
	;
      gl = ShowString (&gl, titleGetString (), titleGetNumberString()/2, ux + 2+12, uy + 6, 24,255,255,255,focus?(titleGetCursor()/2):-1,100,65,30, 1.8);
/*#ifdef CDEBUG
osSyncPrintf("**\nStart CEdit_DrawString\n");
#endif*/
#endif
}
else if (edit->cet == CHINESE)
    {
    	if(currentpanel->paneltype == MAIN&&edit->strux == ADDRESS) {
    		n = 0;
    		for(m = 0;m<edit->poschar;n++) {
    		csa = 	constructDrawStr(edit->string+m,edit->numdisp);
    		if(focus) {
    		gl = ShowString (&gl, (char *) csa.s, csa.length, ux + 2, n*32+uy + 5, 12,100,65,30,-1,255,255,255,1.8);
    		}
    		else {
    			gl = ShowString (&gl, (char *) csa.s, csa.length, ux + 2, n*32+uy + 5, 12,255,255,255,-1,255,255,255,1.8);
    		}
    		
    		m += csa.length*2;
    			
    		}
    		
    			
    	}
    	else {
      csa = constructDrawStr (edit->string + edit->curchar, edit->numdisp);
      if(currentpanel->paneltype == MAIN&&focus) {/*in main panel*/
      	
      	
      gl = ShowString (&gl, (char *) csa.s, csa.length, ux + 2, uy + 5, 12,100,65,30,-1,255,255,255 , 1.8);
      }
      else {
      	gl = ShowString (&gl, (char *) csa.s, csa.length, ux + 2, uy + 5, 12,255,255,255,-1,255,255,255 ,1.8);
	}
	}

    }
  else if (edit->cet == TEXTCO)
    {
      csa = constructDrawStr (edit->string + edit->curchar, edit->numdisp);
      gl = ShowString (&gl, (char *) csa.s, csa.length, ux + 2, uy + 5, -2,255,255,255,-1,255,255,255 ,1.8);
    }
  else if (edit->string)
    {
      csa = constructDrawStr (edit->string + edit->curchar, edit->numdisp);
        if(currentpanel->paneltype == MAIN&&focus) {
        	gl = ShowString (&gl, (char *) csa.s, csa.length, ux + 2, uy + 5, 5,100,65,30,-1,255,255,255 , 1.8);
        	}
        		else {
      gl = ShowString (&gl, (char *) csa.s, csa.length, ux + 2, uy + 5, 5,255,255,255,-1,255,255,255 ,1.8);
      }
    }
  return gl;

}

Gfx *
CEdit_DrawCursor (CEdit * edit, Gfx ** glistp, int ux, int uy,
		  CMessage * message)
{
  Gfx *gl;
  int curs;
  int mul;
  gl = *glistp;
  if(message->CDIS_CURSOR&&edit->strux!=BIRTHDATE) {
  	
  gDPPipeSync (gl++);

  /*gDPSetCycleType (gl++, G_CYC_FILL);
  gDPSetFillColor (gl++, GPACK_RGBA5551 (200, 50, 50, 255) << 16 |
		   GPACK_RGBA5551 (200, 50, 50, 255));*/
  
	  gDPSetCycleType (gl++, G_CYC_1CYCLE);
	  gDPPipelineMode (gl++, G_PM_1PRIMITIVE);
	  /*gsDPSetScissor(G_SC_NON_INTERLACE, 0, 0, SCREEN_WD, SCREEN_HT), */
	  gDPSetTextureLOD (gl++, G_TL_TILE);
	  gDPSetTextureLUT (gl++, G_TT_NONE);
	  gDPSetTextureDetail (gl++, G_TD_CLAMP);
	  gDPSetTexturePersp (gl++, G_TP_NONE);
	  gDPSetTextureFilter (gl++, G_TF_POINT);
	  gDPSetCombineMode (gl++, G_CC_DECALRGBA, G_CC_DECALRGBA);
	  /*gDPSetCombineMode(gl++,G_CC_MODURGBA, G_CC_DECALRGBA); */
	  gDPSetCombineKey (gl++, G_CK_NONE);
	  gDPSetAlphaCompare (gl++, G_AC_NONE);
	  gDPSetRenderMode (gl++, G_RM_TEX_EDGE, G_RM_TEX_EDGE2);
     
      	  curs = titleGetNumberString ();
      	  curs = titleGetCursor ();
      	  curs /= 2;
      	  mul = 28;
      	  if(edit->cet == INPUTREF ) {
      			tileRectangle (&gl, cursor_tex, G_IM_FMT_RGBA, 32, 32,
			 32, 32, 32, 0, 0, 32,
			 32, ux + edit->ux + curs * 28, uy + edit->uy);
}
else if (edit->cet == TEXTCO) {
      	
      tileRectangle (&gl, cursor_tex, G_IM_FMT_RGBA, 32, 32,
			 32, 32, 32, 0, 0, 32,
			 32, ux + edit->ux , uy + edit->uy);
			}
else if(edit->cet == CHINESE){
	tileRectangle (&gl, cursor_tex, G_IM_FMT_RGBA, 32, 32,
			 32, 32, 32, 0, 0, 32,
			 32, ux + edit->ux + edit->cur * 28, uy + edit->uy);
	
}
else {
	tileRectangle (&gl, cursor_tex, G_IM_FMT_RGBA, 32, 32,
			 32, 32, 32, 0, 0, 32,
			 32, ux + edit->ux + edit->cur * 21, uy + edit->uy);
	
	};
      /*gDPFillRectangle (gl++, ux + edit->ux + curs * 28, uy + edit->uy,
			ux + edit->ux + 28 + curs * 28,
			uy + edit->uy + edit->height);*/
   
  gDPPipeSync (gl++);
  };
  return gl;

};

Gfx *
CEdit_DrawDefocusCursor (CEdit * edit, Gfx ** glistp, int ux, int uy,
			 CMessage * message)
{
  Gfx *gl;
  gl = *glistp;
  if( edit->strux != BIRTHDATE) {
  gDPPipeSync (gl++);
  /*gDPSetCycleType (gl++, G_CYC_FILL);
  gDPSetFillColor (gl++, GPACK_RGBA5551 (0, 0, 0, 255) << 16 |
		   GPACK_RGBA5551 (0, 0, 0, 255));
  gDPFillRectangle (gl++, ux + edit->ux + edit->cur * 28, uy + edit->uy,
		    ux + edit->ux + 28 + edit->cur * 28,
		    uy + edit->uy + edit->height);*/
		    
	  gDPSetCycleType (gl++, G_CYC_1CYCLE);
	  gDPPipelineMode (gl++, G_PM_1PRIMITIVE);
	  /*gsDPSetScissor(G_SC_NON_INTERLACE, 0, 0, SCREEN_WD, SCREEN_HT), */
	  gDPSetTextureLOD (gl++, G_TL_TILE);
	  gDPSetTextureLUT (gl++, G_TT_NONE);
	  gDPSetTextureDetail (gl++, G_TD_CLAMP);
	  gDPSetTexturePersp (gl++, G_TP_NONE);
	  gDPSetTextureFilter (gl++, G_TF_POINT);
	  gDPSetCombineMode (gl++, G_CC_DECALRGBA, G_CC_DECALRGBA);
	  /*gDPSetCombineMode(gl++,G_CC_MODURGBA, G_CC_DECALRGBA); */
	  gDPSetCombineKey (gl++, G_CK_NONE);
	  gDPSetAlphaCompare (gl++, G_AC_NONE);
	  gDPSetRenderMode (gl++, G_RM_TEX_EDGE, G_RM_TEX_EDGE);
	  /*gDPSetRenderMode(gl++,G_RM_OPA_SURF, G_RM_OPA_SURF2); */
	  if(edit->cet == CHINESE) {
	  tileRectangle (&gl, defocuscursor_tex, G_IM_FMT_RGBA, 16, 32,
			 32, 32, 32, 0, 0, 32, 32, ux + edit->ux + edit->cur * 28, uy + edit->uy);
			}
			else if(edit->cet == DIGITAL ||edit->cet == ENGLISH){
				
				tileRectangle (&gl, defocuscursor_tex, G_IM_FMT_RGBA, 16, 32,
			 32, 32, 32, 0, 0, 32, 32, ux + edit->ux + edit->cur * 21, uy + edit->uy);
				}
  gDPPipeSync (gl++);
  };
  return gl;
};

Gfx *
CEdit_Draw (CEdit * edit, Gfx ** glistp, int focus, int focusedit, int ux,
	    int uy, CMessage * message)
{
  Gfx *gl;
 /* float pulse = 0;*/
  gl = *glistp;
#if 1
  
  
  gDPPipeSync (gl++);
  if (edit->cet != TEXTCO)
    {
      if (!edit->img)
	{
	  /*gDPSetCycleType(gl++,G_CYC_FILL);
	     if(focus&&focusedit) gDPSetFillColor(gl++,GPACK_RGBA5551(255,0,255,255) << 16 | 
	     GPACK_RGBA5551(255,0,255,255))
	     else if(edit->cet == CHECK) {
	     if(edit->editable)
	     gDPSetFillColor(gl++,GPACK_RGBA5551(255,255,0,255) << 16 | 
	     GPACK_RGBA5551(255,255,0,255))
	     else 
	     gDPSetFillColor(gl++,GPACK_RGBA5551(0,255,0,255) << 16 | 
	     GPACK_RGBA5551(0,255,0,255));
	     }
	     else 
	     gDPSetFillColor(gl++,GPACK_RGBA5551(0,255,0,255) << 16 | 
	     GPACK_RGBA5551(0,255,0,255));
	     gDPFillRectangle(gl++,ux+edit->ux, uy+edit->uy, ux+edit->ux+edit->width, uy+edit->uy+edit->height); */
	}
      else
	{
	

	  gDPSetCycleType (gl++, G_CYC_1CYCLE);
	  /*gDPPipelineMode (gl++, G_PM_1PRIMITIVE);*/
	  /*gsDPSetScissor(G_SC_NON_INTERLACE, 0, 0, SCREEN_WD, SCREEN_HT), */
	  gDPSetTextureLOD (gl++, G_TL_TILE);
	  gDPSetTextureLUT (gl++, G_TT_NONE);
	  gDPSetTextureDetail (gl++, G_TD_CLAMP);
	  gDPSetTexturePersp (gl++, G_TP_NONE);
	  gDPSetTextureFilter (gl++, G_TF_POINT);
	  gDPSetPrimColor(gl++,255,255,(currentpanel->paneltype==MAIN&&focus)?100:255,(currentpanel->paneltype==MAIN&&focus)?66:255,(currentpanel->paneltype == MAIN&&focus)?30:255,255);
	/*  gDPSetCombineMode (gl++, G_CC_DECALRGBA_PRIM, G_CC_DECALRGBA_PRIM);*/
	 gDPSetCombineMode(gl++,G_CC_MODULATEIA_PRIM,G_CC_MODULATEIA_PRIM);
	
	  /*gDPSetCombineMode(gl++,G_CC_MODURGBA, G_CC_DECALRGBA); */
	  gDPSetCombineKey (gl++, G_CK_NONE);
	  gDPSetAlphaCompare (gl++, G_AC_NONE);
	  gDPSetRenderMode (gl++, G_RM_TEX_EDGE, G_RM_TEX_EDGE2);
	  /*gDPSetRenderMode(gl++,G_RM_OPA_SURF, G_RM_OPA_SURF2); */
	  if(edit->strux == ARROW) {
	  	if(focus&&message->CDIS_CURSOR) {
	  		if(edit->struy == TEXTL1 ||edit->struy == TEXTL2) {
	  		if(edit->struy == TEXTL1 && haveUpPage()) {
	  			tileRectangle (&gl,
			 *(void **)(edit->img), G_IM_FMT_RGBA, 16, edit->width,
			 edit->height, 32, 32, 0, 0, edit->width,
			 edit->height, ux + edit->ux, uy + edit->uy+4);
	  		}
	  		else if(edit->struy == TEXTL2&&haveNextPage()) {
	  			tileRectangle (&gl,
			 *(void **)(edit->img), G_IM_FMT_RGBA, 16, edit->width,
			 edit->height, 32, 32, 0, 0, edit->width,
			 edit->height, ux + edit->ux, uy + edit->uy+4);
	  		}
	  		}
	  		else {
	  		tileRectangle (&gl,
			 *(void **)(edit->img), G_IM_FMT_RGBA, 16, edit->width,
			 edit->height, 32, 32, 0, 0, edit->width,
			 edit->height, ux + edit->ux, uy + edit->uy);
			 }
			
	  		}
	  	
	}
	else {
	  tileRectangle (&gl,
			 edit->cet ==
			 CHECK ? *(edit->string)==0x31 ? (void *)girl_tex : (void *)boy_tex : 
			 *(void **)(edit->img), G_IM_FMT_RGBA, 16, edit->width,
			 edit->height, 32, 32, 0, 0, edit->width,
			 edit->height, ux + edit->ux, uy + edit->uy);
			 }
		

	}
      gDPPipeSync (gl++);
      if (focus && focusedit&&edit->strux!=ARROW&&currentpanel->paneltype!=MAIN)
	{	
	if (edit->cet == CHINESE || edit->cet == ENGLISH
	      || edit->cet == DIGITAL) {
	      	/*gl = CEdit_DrawDefocusCursor (edit, &gl, ux+8, uy, message);*/
	      	 gl = CEdit_DrawCursor (edit, &gl, ux-8, uy, message);
	}
	else if(edit->cet!=INPUTREF&&currentpanel->paneltype !=MAIN) {
	  gl = CEdit_DrawCursor (edit, &gl, ux-8, uy, message);
	  }
	  

	}



      else if (currentpanel->paneltype != MAIN)
	{
	  if (edit->cet == CHINESE || edit->cet == ENGLISH
	      || edit->cet == DIGITAL)
	    {
	      if (*
		  ((*currentpanel->cframe)->edit +
		   (*(currentpanel->cframe))->focusedit) == edit)
		gl = CEdit_DrawDefocusCursor (edit, &gl, ux-8, uy, message);
	    };
	    

	}
    }
  else
    {
     	gDPSetCycleType (gl++, G_CYC_1CYCLE);
	  /*gDPPipelineMode (gl++, G_PM_1PRIMITIVE);*/
	  /*gsDPSetScissor(G_SC_NON_INTERLACE, 0, 0, SCREEN_WD, SCREEN_HT), */
	  gDPSetTextureLOD (gl++, G_TL_TILE);
	  gDPSetTextureLUT (gl++, G_TT_NONE);
	  gDPSetTextureDetail (gl++, G_TD_CLAMP);
	  gDPSetTexturePersp (gl++, G_TP_NONE);
	  gDPSetTextureFilter (gl++, G_TF_POINT);
	  gDPSetPrimColor(gl++,255,255,255,255,255,255);
	/*  gDPSetCombineMode (gl++, G_CC_DECALRGBA_PRIM, G_CC_DECALRGBA_PRIM);*/
	 gDPSetCombineMode(gl++,G_CC_MODULATEIA_PRIM,G_CC_MODULATEIA_PRIM);
	
	  /*gDPSetCombineMode(gl++,G_CC_MODURGBA, G_CC_DECALRGBA); */
	  gDPSetCombineKey (gl++, G_CK_NONE);
	  gDPSetAlphaCompare (gl++, G_AC_NONE);
	  gDPSetRenderMode (gl++, G_RM_TEX_EDGE, G_RM_TEX_EDGE2);
      /*gDPSetRenderMode(gl++,G_RM_OPA_SURF, G_RM_OPA_SURF2); */
     /* tileRectangle (&gl, focus
		     && focusedit ? *(void **)edit->struy : *(void **)edit->img,
		     G_IM_FMT_RGBA, 16, edit->width, edit->height, 32, 32, 0,
		     0, edit->width, edit->height, ux + edit->ux,
		     uy + edit->uy);*/
		     if(edit->struy&&edit->img) {
		     	
		     	tileRectangle (&gl, focus
		     && focusedit ? *(void **)edit->img   : *(void **)edit->struy,
		     G_IM_FMT_RGBA, 16, edit->width, edit->height, 32, 32, 0,
		     0, edit->width, edit->height, ux + edit->ux,
		     uy + edit->uy);
		     	};
	
		     
	#if 0 
	tileRectangle (&gl, *(void **)edit->struy,
		     G_IM_FMT_RGBA, 16, edit->width, edit->height, 32, 32, 0,
		     0, edit->width, edit->height, ux + edit->ux,
		     uy + edit->uy);
	
	
	if(focus&& focusedit) {
		
		gl = CEdit_DrawCursor (edit, &gl, ux+8, uy, message);
	}
	#endif
      if (edit->strux){
      	gDPPipeSync (gl++);
      	gDPSetPrimColor(gl++,255,255,(focus&&focusedit)?100:255,(focus&&focusedit)?66:255,(focus&&focusedit)?30:255,255);
	tileRectangle (&gl, *(void **)edit->strux,
		       G_IM_FMT_RGBA, 16,
		       edit->width, edit->height,
		       32, 32,
		       0, 0,
		       edit->width, edit->height,
		       ux + edit->ux, uy + edit->uy);
		       
		       }
      /*if(focus&&focusedit) {
         gl = CEdit_DrawCursor(edit,&gl,ux,uy,message);

         } */
    };
  if (edit->cet != CHECK && edit->cet != TEXTCO) {
    gl = CEdit_DrawString (edit, &gl, focus&&(currentpanel->paneltype == MAIN?1:focusedit), ux + edit->ux+8, uy + edit->uy+1);
    }
#endif
  return gl;

};
#define yearcap  30
void CEdit_UpDigital(CEdit* edit) {
	unsigned int sa ,tsa;
	int i;
	sa = 1;
	tsa = 0;
	if(!*(edit->string)) {
	*edit->string = 0x30;
	*(edit->string+1) = 0x30;	
	}
	for(i = edit->numdisp-1;i >= 0;i--) {
		tsa+= (*(edit->string+i) - 0x30)*sa;
		sa*=10;
	}
	if(tsa<edit->struy)tsa++;
	else  tsa = edit->strux;
	sa = 10;
	/*now year 2 byte to 4 byte so I insert code*/
	if(edit->struy == 99) {
		if(tsa >= yearcap) {
		*(edit->string-2) = '1';
		*(edit->string-1)  ='9';
		
	}
	else {
		*(edit->string-2) = '2';
		*(edit->string-1)  ='0';
		}
	}
	for(i = edit->numdisp-1;i>=0;i--) {
		*(edit->string+i) = ((unsigned char)(tsa%sa)+0x30);
		tsa/=10;
		sa*=10;
	}

	
	};
void CEdit_DownDigital(CEdit *edit) {
	unsigned int sa ,tsa;
	int i;
	sa = 1;
	tsa = 0;
	if(!*(edit->string)) {
	*edit->string = 0x30;
	*(edit->string+1) = 0x30;	
	}
	
	for(i = edit->numdisp-1;i >= 0;i--) {
		tsa+= (*(edit->string+i) - 0x30)*sa;
		sa*=10;
	}
	if(tsa>edit->strux)tsa--;
	else tsa = edit->struy;
	
	if(edit->struy == 99) {
		if(tsa >= yearcap) {
		*(edit->string-2) = '1';
		*(edit->string-1)  ='9';
		
	}
	else {
		*(edit->string-2) = '2';
		*(edit->string-1)  ='0';
		}
	}
	sa = 10;
	for(i = edit->numdisp-1;i>=0;i--) {
		*(edit->string+i) = ((unsigned char)(tsa%sa)+0x30);
		tsa/=10;
		sa*=10;
		}
	
	};

int
CFrame_ForwardCursor (CFrame * frame ,CMessage *cmessage)
{
  CEdit **edit;
  CEdit *pedit;
  int i, num, j;
  if(cmessage->digitalstate) {
  	CMessage_UpDigital(cmessage);
  	
}
else if(cmessage->errorcode == 3) {
	
	
	}
else if(frame->uxref == BIRTHDATE&&currentpanel->paneltype != MAIN) {
	CEdit_UpDigital(*(frame->edit+2));
	
}
else {
  j = frame->focusedit;
  edit = frame->edit;
  num = frame->numedit;
  if(currentpanel->paneltype!=MAIN) {
  i = CEdit_ForwardCursor (*(edit + j));
  if (!i)
    {
      for (i = j + 1; i % num != j; ++i)
	{
	  pedit = *(edit + (i % num));
	  if (pedit->focusable)
	    {

	      frame->focusedit = i % num;
	      (*(frame->edit + frame->focusedit))->cur = 0;
	      playSound(3,0);
	      return 1;

	    };
	}

    }
  else
    return 1;
    
    };
    };
  return 0;

}

int
CFrame_BackCursor (CFrame * frame,CMessage *cmessage)
{
  CEdit **edit;
  CEdit *pedit;
  int i, j, num;
  if (cmessage->digitalstate) {
  	CMessage_DownDigital(cmessage);
  	
}
else if(cmessage->errorcode == 3) {
	
	
	}
else if(frame->uxref == BIRTHDATE&&currentpanel->paneltype != MAIN) {
	CEdit_DownDigital(*(frame->edit+2));
	
}

else {
  j = frame->focusedit;
  edit = frame->edit;
  num = frame->numedit;
  if(currentpanel->paneltype != MAIN) {
  i = CEdit_BackCursor (*(edit + j));
  if (!i)
    {

      for (i = num + j - 1; i % num != j; --i)
	{
	  pedit = *(edit + (i % num));
	  if (pedit->focusable)
	    {
	      frame->focusedit = i % num;
	      edit = frame->edit;
	      pedit = *(edit + frame->focusedit);
	      if (pedit->curchar + pedit->numdisp - 1 < pedit->poschar)
		pedit->cur = pedit->poschar;
	      else
		pedit->cur = pedit->numdisp - 1;
		playSound(3,0);
	      return 1;
	    }

	};
    }
  else
    return 1;
    };
    };
  return 0;

};
int
CFrame_GetFocus (CFrame * frame, int editpos)
{
  CEdit **pedit;
  int num = 0;
  pedit = frame->edit;
  for (; *pedit; pedit++)
    {
      if ((*pedit)->focusable)
	{

	  if (editpos == num || editpos == -1)
	    {
	      frame->focusedit = num;
	      return 1;
	    }
	}
      num++;
    }
  if (num)
    {
      frame->focusedit = num - 1;
      return 1;
    }
  frame->focusedit = -1;
  return 0;

};
Gfx *
CFrame_DrawBackground (CFrame * frame, Gfx ** glistp, int foucs)
{
  return *glistp;

};
Gfx *
CFrame_DrawLabel (CFrame * frame, Gfx ** glistp, int foucs, int ux, int uy)
{
  Gfx *gl;
  CString csf;
  gl = *glistp;
  if (frame->labelname)
    {
      csf = constructDrawStr (frame->labelname, -1);

      gl = ShowString (&gl, csf.s, csf.length, ux, uy, -2,255,255,255,-1,255,255,255 , 2.0);


    }
  return gl;

};

Gfx *
CFrame_Draw (CFrame * frame, Gfx ** glistp, int focus, int ux, int uy,
	     CMessage * message)
{
  Gfx *gl;
  gl = *glistp;
  gDPPipeSync (gl++);
  if (!frame->img)
    {
      /*gDPSetCycleType(gl++,G_CYC_FILL);
         if(focus)  
         {gDPSetFillColor(gl++,GPACK_RGBA5551(255,0,0,255) << 16 | 
         GPACK_RGBA5551(255,0,0,255));

         }
         else 
         gDPSetFillColor(gl++,GPACK_RGBA5551(0,0,255,255) << 16 | 
         GPACK_RGBA5551(0,0,255,255));
         gDPFillRectangle(gl++,ux+frame->ux, uy+frame->uy, ux+frame->ux+frame->width, uy+frame->uy+frame->height);
         gDPPipeSync(gl++); */
    }
  else
    {

      gDPSetCycleType (gl++, G_CYC_1CYCLE);
      gDPPipelineMode (gl++, G_PM_1PRIMITIVE);
      /*gsDPSetScissor(G_SC_NON_INTERLACE, 0, 0, SCREEN_WD, SCREEN_HT), */
      gDPSetTextureLOD (gl++, G_TL_TILE);
      gDPSetTextureLUT (gl++, G_TT_NONE);
      gDPSetTextureDetail (gl++, G_TD_CLAMP);
      gDPSetTexturePersp (gl++, G_TP_NONE);
      gDPSetTextureFilter (gl++, G_TF_POINT);
      gDPSetCombineMode (gl++, G_CC_DECALRGBA, G_CC_DECALRGBA);
      gDPSetCombineKey (gl++, G_CK_NONE);
      gDPSetAlphaCompare (gl++, G_AC_NONE);
      /*gDPSetRenderMode (gl++, G_RM_OPA_SURF, G_RM_OPA_SURF2);*/
      gDPSetRenderMode (gl++, G_RM_TEX_EDGE, G_RM_TEX_EDGE2);
      tileRectangle (&gl, (focus ? *(void **)frame->hiimg : *(void **)frame->img),
		     G_IM_FMT_RGBA, 16,
		     frame->width, frame->height,
		     32, 32,
		     0, 0,
		     frame->width, frame->height,
		     ux + frame->ux, uy + frame->uy);

    }

  /*gl = CFrame_DrawLabel(frame,&gl,1,ux+frame->ux, uy+frame->uy+5); */
  return gl;
};

Gfx *
CPanel_Draw (CPanel * panel, Gfx ** glistp,CMessage *cmessage ,int pbutton,int pleft)
{
  Gfx *gl;
  int numframe;
  int numedit;
  CFrame **fr;
  CEdit **ce;
  CFrame *cfr;
  /*CFrame* ncfr; */
  CEdit *cce;
  /*int pbutton = 90;
  int pleft = 15;*/
  int ebutton;
  int eleft;
  gl = *glistp;
  numframe = 0;
  fr = panel->cframe;
  ebutton = pbutton;
  /*pleft = gfxoffset;*/
  for (; fr && (cfr = *fr); fr++)
    {
      pleft = gfxoffset + cfr->ux;
      gl =
	CFrame_Draw (cfr, &gl, numframe == panel->focusframe ? 1 : 0, pleft,
		     pbutton, cmessage);
      numedit = 0;
      ce = cfr->edit;
      ebutton = pbutton + cfr->uy;
      eleft = pleft;
      for (; ce && (cce = *ce); ce++)
	{
	  gl = CEdit_Draw (cce, &gl, numframe == panel->focusframe ? 1 : 0,
			  numedit == cfr->focusedit ? 1 : 0, eleft, ebutton,
			   cmessage);
	  eleft += cce->width + cce->ux;
	  numedit++;
	}
      pbutton += cfr->height +1+ /*gfsoffset +*/ cfr->uy;
      numframe++;
    }
  return gl;

};

int doAction_CButton (CMessage *cmessage,int d) {
CFrame *frame;
CEdit *fedit;
frame = *currentpanel->cframe;
fedit = *(frame->edit+1);
if(!cmessage->errorcode&&currentpanel->paneltype != MAIN && fedit->strux!=BIRTHDATE) {
	 switch(d) {
	 	case CFORWARD:
	 	 	CEdit_ForwardCursor(fedit);
	 	break;
	 	case CBACK:
	 		CEdit_BackCursor(fedit);
	 	break;
	 	case CUP:
	 		if(currentpanel->paneltype == CHINESE&&shenoryun&&currentpanel->focusframe == 2) {
	 		upTitlePage();	
	 		}
	 		
	 	break;
	 	case CDOWN:
	 	if(currentpanel->paneltype == CHINESE&&shenoryun&&currentpanel->focusframe == 2) {
	 		nextTitlePage();	
	 		}
	 		
	 	break;
	 	default:
	 	break;
	 	
	 	};
	
	};
	return 0;
};


int
doAction_AButton (CMessage *cmessage)
{
  int numframe;
  int numedit;
  int numfedit;
  unsigned short s;
  short is;
/*  int pos;*/
  CString cstring;
  CFrame **fr;
  CFrame **nfr;
  CEdit **ce;
  /*CFrame* cfr;
     CFrame* ncfr; */
  CEdit *cce;
  CEdit **pcce;
  CPanel *nextpanel;
  int errorstate;
  fr = currentpanel->cframe;
  numframe = currentpanel->focusframe;
  pcce = (*(fr + numframe))->edit;
  numedit = (*(fr + numframe))->focusedit;
  cce = *(pcce + numedit);
  nextpanel = 0;
  if(cmessage->errorcode == 3) {
  	switch (GC_panel[5].focusframe ) { 
		case 1:
				#ifdef DEBUG
				osSyncPrintf("saved and exit\n");
				#endif
				localtobb();
				errorstate = bbWriteRegFile();
			if(!errorstate) {
				#ifdef DEBUG
				osSyncPrintf("saved and exit\n");
				#endif
				bbClubExit();
			}
			else {
				#ifdef DEBUG
				osSyncPrintf("saved error\n");
				#endif
				cmessage->errorcode = 2;
			
				}
		break;
		case 2:
			#ifdef DEBUG
			osSyncPrintf("discard and exit\n");
			#endif
			bbClubExit();
		break;
		case 3:
			cmessage->errorcode = 0;
			
		break;
		default:
		 break;
		} 
	playSound(2,0);
  	
}
else {
  if (currentpanel->paneltype == MAIN)
    {
      if (cce->editable)
	{
	  switch (cce->cet)
	    {
	    case CHINESE:
	      nextpanel = &GC_panel[0];
	      if(cce->strux == NAME) {
	      	  cfdigital1.edit = rdigital; 
	      	  cfdigital1.numedit  = 2;
		}
	      else /*if((cce->strux == ADDRESS)) */{
	      	 cfdigital1.edit = digital1;
	      	 cfdigital1.numedit = 12;
	      	} 	
	      break;
	    case DIGITAL:
	      if((*(fr + numframe))->uxref == BIRTHDATE) nextpanel = &GC_panel[4];	
	      else nextpanel = &GC_panel[2];
	      break;
	    case ENGLISH:
	    	
	    	 nextpanel = &GC_panel[1];
	      break;


	    case CHECK:
	     /* cce->numdisp = 1;
	      *cce->string = 1 - *cce->string;
	      for (; pcce && *pcce; pcce++)
		{
		  if (*pcce != cce && (*pcce)->cet == CHECK)
		    (*pcce)->numdisp = 0;
		}*/
		nextpanel = &GC_panel[4];

	    default:
	      break;
	    };
	  if (nextpanel)
	    {
		
	      *nextpanel->cframe = *(fr + numframe);
	     /* *((*nextpanel->cframe)->edit+(*nextpanel->cframe)->numedit) = &ReturnCursor;
	      (*nextpanel->cframe)->numedit+=1;*/
	      currentpanel = nextpanel;
	      if (cce->cet == CHINESE)
		{
		  nextpanel->focusframe = 3;

		  initChineseInput ();
		  constructShenmu ();
		}
	      else {
		currentpanel->focusframe = 1;
	}
		/*CEdit_PutCursorLast(cce);*/
		playSound(1,0);
	    };
	}
      else
	{
	  if (cce->cet == TEXTCO)
	    {
	      if (cce->numdisp == 1)
		{
#ifdef DEBUG
		  osSyncPrintf ("press ok!\n");
#endif
		  errorstate = localtobb ();
		  errorstate = bbWriteRegFile ();
		  if(errorstate) {
		  	
		  	cmessage->errorcode = 2;
    			/*osCreateViManager(OS_PRIORITY_VIMGR);
   			osViSetMode(&osViModeTable[OS_VI_NTSC_LAN1]);
   			osViSetSpecialFeatures(OS_VI_DITHER_FILTER_ON | OS_VI_DIVOT_OFF | OS_VI_GAMMA_ON);*/
		  	
		  	}
		 /* bbClubExit ();*/
		}
	      else if (cce->numdisp == 2)
		{
#ifdef DEBUG
		  osSyncPrintf ("press discard!\n");
#endif
		  bbClubExit ();
		}
	    }
	}
    }
  else if (currentpanel->paneltype == ENGLISH
	   || currentpanel->paneltype == DIGITAL)
    {
      nfr = currentpanel->cframe;
      ce = (*fr)->edit;
      numfedit = (*fr)->focusedit;
      switch (cce->cet)
	{
	case TEXTL1:
	  CEdit_AddChar (*(ce + numfedit), 'a' + cce->cur);
	  break;
	case TEXTL2:
	  CEdit_AddChar (*(ce + numfedit), 'n' + cce->cur);
	  break;
	case TEXTU1:
	  CEdit_AddChar (*(ce + numfedit), 'A' + cce->cur);
	  break;
	case TEXTU2:
	  CEdit_AddChar (*(ce + numfedit), 'N' + cce->cur);
	  break;
	case TEXTDI:
	  CEdit_AddChar (*(ce + numfedit), '0' + cce->cur);
	  break;
	case TEXTMI:
	  if (cce->cur == 10)
	    CEdit_AddChar (*(ce + numfedit), '@');
	  else if (cce->cur == 11)
	    CEdit_AddChar (*(ce + numfedit), '_');
	  else if (cce->cur == 12)
	    CEdit_AddChar (*(ce + numfedit), '.');
	  else
	    CEdit_AddChar (*(ce + numfedit), '0' + cce->cur);
	case TEXTCO:
		if(cce->numdisp == BUTTON) {
			if(cce->max == SWITCHENGLISH) {
				
			currentpanel = &GC_panel[0];	
			}
			else {
			currentpanel = &GC_panel[3];
			};
			playSound(2,0);		
			
			
		}
		
	  else {
	  	if((*(ce+numfedit))->cet == CHINESE) {
	  	cstring = constructDrawStr(cce->string,1);
	  	/*CEdit_AddWChar(*(ce + numfedit),*(short *)(cstring.s));*/
	  	is = CEdit_InsertWChar(*(ce + numfedit),*(short *)(cstring.s));
	  	/*if(is && !*curd.gBbClubId && (*((*nfr)->edit+1))->strux == ADDRESS){
	      	pos = ((*((*nfr)->edit+1))->poschar-2)/2;
	      	insertpinyin( *((*(nfr+1))->edit),pos);
	      	
	      	}*/
	  	/*clearPYTitle ();*/
	  	/*constructShenmu ();*/
	  	
	  	/*currentpanel->focusframe  =2;
	  	fr = currentpanel->cframe;
 	  	numframe = currentpanel->focusframe;
 	  	pcce = (*(fr + numframe))->edit;
  	  	numedit = (*(fr + numframe))->focusedit;
  	  	cce = *(pcce + numedit);
	  	setshenmu (cce);*/
	  }
	  else {
	  /*CEdit_AddChar (*(ce + numfedit), *(cce->string));*/
	 CEdit_InsertChar (*(ce + numfedit), *(cce->string));
	
}
	playSound(3,0);
	/*currentpanel->focusframe = 0;*/
	}
	  /*CFrame_ForwardCursor (*fr);*/
	  break;
	case DIGITAL:
	case ENGLISH:
	case CHINESE:
	  currentpanel->focusframe = 1;
	  CEdit_ResetPoschar (*(ce + numfedit));
	  break;
	default:
	  break;
	};

    }
  else
    {				/*currentpanel->paneltype == CHINESE */
      nfr = currentpanel->cframe;
      ce = (*fr)->edit;
      numfedit = (*fr)->focusedit;
      switch (cce->cet)
	{
	case TEXTCO:
	  if(cce->numdisp == BUTTON) {
	  	 if(cce->max == SWITCHENGLISH) {
	  	 	*(GC_panel[1].cframe) = *nfr;
	  	 	currentpanel = &GC_panel[1]; 
	  	 	currentpanel->focusframe = 1;
	  	 	playSound(1,0);
	  	}
	  	else {
	  	 currentpanel = &GC_panel[3];
	  	 playSound(2,0);
	  	 }
	  	 
	  	}
	  else if (shenoryun)
	    {
	      setyumu (cce);
	      currentpanel->focusframe = 2;
	      playSound(1,0);
	    }
	  else
	    {
	      setshenmu (cce);
	      constructYumu (cce->string);
	      playSound(1,0);	
		
	    }
	  break;
	case TEXTL1:
	  addNameChar ('a' + cce->cur);
	  break;
	case TEXTL2:
	  addNameChar ('n' + cce->cur);
	  break;
	case INPUTREF:
	  is = getSelectTitleCharacter (&s);
	  if (is)
	    {
	      /*CEdit_AddWChar (*(ce + numfedit), s);*/
	     is =  CEdit_InsertWChar (*(ce + numfedit), s);
	     /* if(is && !*curd.gBbClubId && (*((*nfr)->edit+1))->strux == ADDRESS){
	      	pos = ((*((*nfr)->edit+1))->poschar-2)/2;
	      	insertpinyin( *((*(nfr+1))->edit),pos);
	      	
	      	}*/



	}

	  clearPYTitle ();
	  constructShenmu ();
	  /*currentpanel->focusframe = 2;
	  fr = currentpanel->cframe;
 	  numframe = currentpanel->focusframe;
 	  pcce = (*(fr + numframe))->edit;
  	  numedit = (*(fr + numframe))->focusedit;
  	  cce = *(pcce + numedit);*/
	  /*setshenmu (cce);*/
	  playSound(2,0);
	  break;
	case CHINESE:
	  currentpanel->focusframe = 3;
	  CEdit_ResetPoschar (*(ce + numfedit));
	  fr = currentpanel->cframe;
 	  numframe = currentpanel->focusframe;
 	  pcce = (*(fr + numframe))->edit;
  	  numedit = (*(fr + numframe))->focusedit;
  	  cce = *(pcce + numedit);
	  setshenmu (cce);
	  /*constructYumu (cce->string);*/
	  break;
	default:
	  break;
	};

    }

  }

  return 1;
};




int
panel_Up_Cursor (CMessage *cmessage)
{
  int i, j;
  if(cmessage->digitalstate) {
  	CMessage_UpDigital(cmessage);
}
else if(cmessage->errorcode == 3) {
	
	switch (GC_panel[5].focusframe ) { 
		case 1:
			GC_panel[5].focusframe = 3;
		break;
		case 2:
			
	
		case 3:
			GC_panel[5].focusframe -= 1;
		break;
		default:
			GC_panel[5].focusframe = 1;
		 break;
		}
		playSound(3,0);
	}
	else {
	
  i = -1;
  j = (*(currentpanel->cframe + currentpanel->focusframe))->focusedit;
  if(currentpanel->focusframe||currentpanel->paneltype == MAIN) {
  switch(currentpanel->paneltype) {
  	case ENGLISH:
  	case DIGITAL:
  		if(currentpanel->focusframe == 1) currentpanel->focusframe = currentpanel->numframe - 1;
  		else currentpanel->focusframe -- ;
  		break;
  	case CHINESE:
  		if(currentpanel->focusframe == 3) currentpanel->focusframe = currentpanel->numframe - 1;
  		else if(currentpanel->focusframe > 3)currentpanel->focusframe -- ;
  		break;
  	default:
  		if(currentpanel->focusframe == 0) currentpanel->focusframe = currentpanel->numframe - 1;
  		else currentpanel->focusframe -- ;
  	    	break;
  	
  	
  	};
  	playSound(3,0);
  	};
  if (currentpanel->paneltype == CHINESE)
    {
      if (3 <= currentpanel->focusframe
	  && currentpanel->focusframe <= currentpanel->numframe - 1)
	{
	  i = j;
	}
    }
  else if (currentpanel->paneltype == ENGLISH||currentpanel->paneltype == DIGITAL)
    {
      if (1 <= currentpanel->focusframe
	  && currentpanel->focusframe <= currentpanel->numframe - 1)
	{
	  i = j;
	}

    }
  CFrame_GetFocus (*(currentpanel->cframe + currentpanel->focusframe), i);
  if (currentpanel->paneltype == CHINESE && 3 <= currentpanel->focusframe &&
      currentpanel->focusframe <= currentpanel->numframe - 1)
    {

      buildRefereceChinese ();

    };
    
    }
  return 1;
};

int
panel_Down_Cursor (CMessage *cmessage)
{
  int i, j;
  if(cmessage->digitalstate) {
  	CMessage_DownDigital(cmessage);
}
else if(cmessage->errorcode == 3) {
	switch (GC_panel[5].focusframe ) { 
		case 1:
			
		case 2:
			GC_panel[5].focusframe += 1;
			playSound(3,0);
		break;
		case 3:
			GC_panel[5].focusframe = 1;
			playSound(3,0);
		default:
			GC_panel[5].focusframe = 1;
			playSound(3,0);
		 break;
		} 
	
	}
else {
  i = -1;
  j = (*(currentpanel->cframe + currentpanel->focusframe))->focusedit;
  if(currentpanel->focusframe ||currentpanel->paneltype == MAIN) {
  if (currentpanel->focusframe == currentpanel->numframe - 1)
    {
    	switch(currentpanel->paneltype) {
    	case DIGITAL:
    	case ENGLISH:
    		currentpanel->focusframe = 1;
    		break;
    	case MAIN:	
    		currentpanel->focusframe = 0;
    		break;
    	case CHINESE:
    		currentpanel->focusframe = 3;
    		break;
    	default:
    		currentpanel->focusframe = 0;
    		break;
    	}
    	playSound(3,0);
    	}
  else
    {
    	if(!(currentpanel->paneltype == CHINESE&&currentpanel->focusframe == 2))
    	currentpanel->focusframe++;
    	playSound(3,0);
    }

  if (currentpanel->paneltype == CHINESE)
    {

      if (3 <= currentpanel->focusframe
	  && currentpanel->focusframe <= currentpanel->numframe - 1)
	{
	  i = j;
	}
    }
  else if (currentpanel->paneltype == ENGLISH||currentpanel->paneltype == DIGITAL)
    {

      if (1 <= currentpanel->focusframe
	  && currentpanel->focusframe <= currentpanel->numframe - 1)
	{
	  i = j;
	}
    }

  CFrame_GetFocus (*(currentpanel->cframe + currentpanel->focusframe), i);
  if (currentpanel->paneltype == CHINESE && 3 <= currentpanel->focusframe &&
      currentpanel->focusframe <= currentpanel->numframe - 1)
    {

      buildRefereceChinese ();

    };
    };
    };
  return 1;
};
int
panel_Build_Help ()
{
	
/*CE_GenelHelp
  
CE_deleteHelp
 

CE_returnHelp*/
  
CFrame *cframe = *currentpanel->cframe;
CEdit  *cedit =  *(cframe->edit+1);
switch(currentpanel->paneltype) {
	case MAIN:
		buttomframe.edit = CE_GenelHelp;
		break;
	case DIGITAL:
		if(cedit->strux == BIRTHDATE) {
			
			buttomframe.edit = CE_GenelHelp;
		
		}
		else {
			buttomframe.edit = CE_topHelp;
		}
		/*
		else if(!cedit->poscur){
			buttomframe.edit = CE_returnHelp;
			
		}
		else {
			buttomframe.edit = CE_deleteHelp;
		}*/
		break;
	case ENGLISH:
		/*if(cedit->cet == CHINESE) {
			buttomframe.edit = CE_returnHelp;
			
		}
		else*/ /*if(!cedit->poscur) {
			
			buttomframe.edit = CE_returnHelp;
		}
		else {
			buttomframe.edit = CE_deleteHelp;
			
		}*/
		buttomframe.edit = CE_topHelp;
		break;
	case CHINESE:
		if(shenoryun &&currentpanel->focusframe == 2) {
			buttomframe.edit = CE_toprefHelp;
		}
		else {/*
			if(!cedit->poscur) {
			buttomframe.edit = CE_returnHelp;	
			}
			else {
			buttomframe.edit = CE_deleteHelp;
			}*/
			buttomframe.edit = CE_topHelp;
			
		}
		break;
	default:
		break;     
	
	
	};
 /* if ((*((*(currentpanel->cframe))->edit + 1))->cet == CHINESE
      && currentpanel->paneltype != MAIN)
    {
      buttomframe.edit = CE_ChineseHelp;
      buttomframe.numedit = 8;
    }
  else
    {
      buttomframe.edit = CE_GenelHelp;
      buttomframe.numedit = 6;
    }*/
  return 1;

}


#define ppex    60
#define ppey    20
#define ppdx    100
#define ppdy    100
#define ppsx    120
#define ppsy    30
#define ppyx    50
#define ppyy    40
void
panel_position_text ()
{
  int i, j;
  switch (currentpanel->paneltype)
    {
    case DIGITAL:
      cfdigital1.ux = ppdx+30;
      cfdigital1.uy = ppdy;
      break;
    case CHINESE:
      j = currentpanel->numframe - 1 - 2;
      #if 0
      /*
      if (shenoryun)
	{
	  for (i = 3; i <= currentpanel->numframe - 1; i++)
	    {
	      (*(currentpanel->cframe + i))->ux = i == 2 ?ppyx+45;
	      (*(currentpanel->cframe + i))->uy = i == 2 ? 24 : -8;

	    };

	}
      else
	{
	  for (i = 3; i <= currentpanel->numframe - 1; i++)
	    {
	      (*(currentpanel->cframe + i))->ux = ppsx;
	      (*(currentpanel->cframe + i))->uy = i == 2 ? ppsy - 4 : -8;

	    };

	}*/
	#endif
	if (shenoryun)
	{
	  for (i = 3; i <= currentpanel->numframe - 1; i++)
	    {
	      (*(currentpanel->cframe + i))->ux = i == 3?ppsx + 100:ppsx + 100;
	      (*(currentpanel->cframe + i))->uy = i == 3 ? -8 : -8;

	    };

	}
      else
	{
	  for (i = 3; i <= currentpanel->numframe - 1; i++)
	    {
	      (*(currentpanel->cframe + i))->ux = ppsx + 100;
	      (*(currentpanel->cframe + i))->uy = i == 3 ? -8:  -8;

	    };

	}
      break;
    case ENGLISH:
      cfledit1.ux = ppex + 60;
      cfledit1.uy = ppey + 56;
      cfledit2.ux = ppex +60;
      cfledit2.uy = -8;
      cfuedit1.ux = ppex + 60;
      cfuedit1.uy = -8;
      cfuedit2.ux = ppex + 60;
      cfuedit2.uy = -8;
      cfdigital1.ux = ppex + 60;
      cfdigital1.uy = -8;
      break;
    default:
      break;
    };

};
int
doAction_BButton (CMessage* cmessage)
{
  /*int errorstate; */
/*  int i;*/
  CFrame *fr;
  CEdit *fedit;
  fr = *(currentpanel->cframe+currentpanel->focusframe);
  fedit =  *(fr->edit+fr->focusedit);
  if(cmessage->errorcode == 1 || cmessage->errorcode == 2) {/*read and write error*/
  #ifdef DEBUG
  	 osSyncPrintf("Press B and exit to main screen!\n");
  	
  #endif
  	 bbClubExit();
  	}
  	else if(cmessage->errorcode == 3) {/*return to main screen warning*/
  		
  		
  		}
  else if(cmessage->digitalstate) {
  	        cmessage->digitalstate = 0;
	      	cmessage->digitalmax = 0;
	      	cmessage->digitalmin = 0;
	      	*((cmessage->edit)->string+(cmessage->edit)->poscur) = cmessage->digital;
	      	cmessage->edit = 0;
	      	
	      	cmessage->enterdigital = 0;
	      	cmessage->digital = 0;
  	}
  	else {/*   */
  if (currentpanel->paneltype != MAIN)/* */
    {
      if (currentpanel->paneltype == CHINESE)/*chinese input*/
	{
	if(shenoryun) {	/*yumu panel*/
	 if(currentpanel->focusframe == 2) {
	 	currentpanel->focusframe = 3;
	 	playSound(3,0);
	}
	else {
	  initChineseInput ();
	  constructShenmu ();
	  playSound(1,0);
	}
	}
	else {/*shenmu panel*/
		/*if(currentpanel->focusframe) {
			currentpanel->focusframe = 0;
		}
		else 
		{*/
			/*fr = *(currentpanel->cframe);
  			fedit =  *(fr->edit+1);
			if(!fedit->poscur||fr->uxref == BIRTHDATE) {
			  currentpanel = &GC_panel[3];
			  playSound(1,0);
			}
			else {
			CEdit_BackChar(fedit);
			};*/
			
			currentpanel = &GC_panel[3];
			  playSound(1,0);
		
		/*}*/
		
		
	}
	}/*End of chinese panel*/
      else {/*english or digital panel*/
      	/*if(currentpanel->focusframe) {
      		currentpanel->focusframe = 0;
      	}
	 else {*/
	 	/* if focusframe == 0 ,we need backspace the character, if null, then return */
	 	/*
	 	fr = *(currentpanel->cframe);
  			fedit =  *(fr->edit+1);
  			
  			if(fedit->cet == CHINESE) {
  				
  				if(!fedit->poscur) {
  				
  				currentpanel = &GC_panel[3];
  				playSound(1,0);
  			}
  			else {
  			CEdit_BackChar(fedit);	
  			}
  			
  					
  			}
  			else {
			if(!fedit->poscur||fr->uxref == BIRTHDATE) {
			  currentpanel = &GC_panel[3];
			  playSound(1,0);
			}
			else {
			
			CEdit_BackChar(fedit);
			};
			};*/
			currentpanel = &GC_panel[3];
  				playSound(1,0);
	 	/*}*/
	}
    }
    else {/*at main screen press B*/
    	#ifdef DEBUG
  	 osSyncPrintf("Press B and exit to main screen!\n");
  	#endif
  	cmessage->errorcode = 3;
  	GC_panel[5].focusframe = 1;
  	playSound(2,0);
  	 /*bbClubExit();*/
    	}
    }
  /*else {
     errorstate = localtobb();
     errorstate =  bbWriteRegFile();
     bbClubExit();

     } */
  return 1;

};
int
doAction_RButton (CMessage *cmessage)
{
  /*int numfedit;
     unsigned short s;
     short is; */
  CFrame *fr;
  /*CFrame** nfr;
     CEdit** ce;
     CFrame* cfr;
     CFrame* ncfr; */
  CEdit *cce;
  fr = *(currentpanel->cframe);
  cce = *(fr->edit +1);
  if(!cmessage->errorcode&&fr->uxref != BIRTHDATE&&currentpanel->paneltype != MAIN ){
  /*CPanel* nextpanel; */
  CEdit_BackChar (cce);
   return 1;
  }
  return 0;
};
Gfx *
doAction (Gfx ** glistp, OSContPad ** pad, CMessage *cmessage)
{
  Gfx *gl;
  int numframe;
  int numedit;
  CFrame **fr;
/*  CFrame **nfr;*/
  CEdit **ce;
  /*CFrame* cfr;
     CFrame* ncfr; */
  CEdit *cce;
  CEdit **pcce;
/*  CPanel *nextpanel;*/
  /*int pbutton = 55;
     int pleft = 15; */
  int ebutton;
  int eleft;
  int bstate;	
	/*****************************************/
  gl = *glistp;
  /*Get Controller information */
  GetMessage (cmessage, pad);
  bstate = checkCard();
  /*bstate = BB_CARD_INVALID;*/
  /*if(bstate == BB_CARD_OK) {
	cmessage->bbcardstate = BB_CARD_OK;
  }
  else*/ if(bstate == BB_CARD_NOT_EXIST) {
	/*gl = CDraw_Glyph(&gl, "bbcardnotexist",glyph16x16_tex,100,200,0,0,1.0,1);	*/
	cmessage->bbcardstate = BB_CARD_NOT_EXIST;
	gl =  validExit(&gl,cmessage);
  }
  else if(bstate == BB_CARD_INVALID) {
  	cmessage->bbcardstate = BB_CARD_INVALID;
	gl =  validExit(&gl,cmessage);
	/*gl = CDraw_Glyph(&gl ,"bbcardmismatch",glyph16x16_tex,100,200,0,0,1.0,1);*/
  }
  
  /*error check*/
  else {
	cmessage->bbcardstate = BB_CARD_OK;  
	  if(cmessage->errorcode == 2 || cmessage->errorcode == 1) {
  	if (cmessage->CB_BUTTON)
    {
      doAction_BButton (cmessage);
    };
    
   /*gl = CFrame_Draw (&topframe, &gl, 0, 0, 0, cmessage);
  gl = CFrame_Draw (&buttomframe, &gl, 0, 0, 410, cmessage);
  ce = buttomframe.edit;
  eleft = 20;
  ebutton = 410;
  for (; ce && (cce = *ce); ce++)
    {
      gl = CEdit_Draw (cce, &gl, 0, 0, eleft, ebutton, cmessage);
      eleft += cce->width + cce->ux;

    };*/
    /*gl =  displayError(&gl,  cmessage);*/
    gl = validExit(&gl,cmessage); 
    
  }
else {
  /*Cursor move down or up,this is between the frame */
  if (cmessage->CUP_CURSOR)
    {
      /*if(currentpanel->focusframe == 0)currentpanel->focusframe = currentpanel->numframe-1;
         else currentpanel->focusframe--;
         CFrame_GetFocus(*(currentpanel->cframe+currentpanel->focusframe)); */
      panel_Up_Cursor (cmessage);
    }
  else if (cmessage->CDOWN_CURSOR)
    {

      /*if(currentpanel->focusframe == currentpanel->numframe-1) currentpanel->focusframe = 0;
         else currentpanel->focusframe++;
         CFrame_GetFocus(*(currentpanel->cframe+currentpanel->focusframe)); */
      panel_Down_Cursor (cmessage);

}

else if (cmessage->CL_CBUTTONS ) {
doAction_CButton(cmessage,CBACK);	
}
else if (cmessage->CR_CBUTTONS) {
	doAction_CButton(cmessage,CFORWARD);
}
else if (cmessage->CU_CBUTTONS) {
	doAction_CButton(cmessage,CUP);	
}
else if (cmessage->CD_CBUTTONS) {
	doAction_CButton(cmessage,CDOWN);
}

;

  fr = currentpanel->cframe;
  numframe = currentpanel->focusframe;
  pcce = (*(fr + numframe))->edit;
  numedit = (*(fr + numframe))->focusedit;
  cce = *(pcce + numedit);
  /*press the A Button */
  if (cmessage->CA_BUTTON)
    {
      doAction_AButton (cmessage);
    };
  /*press the B Button */
  if (cmessage->CB_BUTTON)
    {
      doAction_BButton (cmessage);
    };
  

  if (cmessage->CR_TRIG)
    {
     doAction_RButton (cmessage);
    }
  /*Cursor move forward or back,this is between the edit belong one frame,or in a edit */
  if (cmessage->CFORWARD_CURSOR)
    {

      CFrame_ForwardCursor (*(fr + numframe),cmessage);

      buildRefereceChinese ();
    }
  else if (cmessage->CBACK_CURSOR)
    {
      CFrame_BackCursor (*(fr + numframe),cmessage);
      buildRefereceChinese ();
    };
 osWritebackDCacheAll();

  /*press the Z Button switch the  chinese and english  panel,if the panel is the 
     digital panel ,will ingorl the message
   */
  #if 0 
  if (cmessage->CZ_TRIG&&cmessage->errorcode!=3)
    {
      /*constructYumu("CH");
         setshenmu(&S_CH); */
      if (currentpanel->paneltype == CHINESE
	  || currentpanel->paneltype == ENGLISH)
	{
	  /*if(currentpanel->paneltype == ENGLISH) initChineseInput(); */
	  fr = currentpanel->cframe;
	  if ((*((*(currentpanel->cframe))->edit + 1))->cet == CHINESE)
	    {
	      nextpanel =
		&GC_panel[currentpanel->paneltype == CHINESE ? 1 : 0];
	      nfr = nextpanel->cframe;
	      *nfr = *fr;
			/**fr = 0;*/
			if(currentpanel->focusframe&&!nextpanel->focusframe ) {
				nextpanel->focusframe =
		currentpanel->paneltype == CHINESE ? 1 : 2;
		}
		else if(!currentpanel->focusframe&&nextpanel->focusframe) {
			
			nextpanel->focusframe = 0;
			}
	      currentpanel = nextpanel;
	     /* currentpanel->focusframe =
		currentpanel->paneltype == CHINESE ? 2 : 1;*/
	    }



	}


    };
 #endif 
  panel_Build_Help ();
  panel_position_text ();
  /*tileRectangle(&gl,bg_tex,G_IM_FMT_RGBA,16,640,480,32,32,0,0,640,480,0,0); */
  /*do the draw job,this is the last task */
/*  gl = CFrame_Draw (&topframe, &gl, 0, 0, 0, cmessage);*/
  /*gl = CFrame_Draw (&buttomid,     &gl,0,  0,385,cmessage);*/
  gl = CFrame_Draw (&fmainbg ,&gl,0,0,0,cmessage);
  /*csa = constructDrawStr (curd.gBbClubId, -1);
  gl = ShowString (&gl, (char *) csa.s, csa.length, 125, 380, 1 ,0,0,255,-1,255,255,255);*/
  gl = CDraw_Glyph(&gl, curd.gBbClubId,glyph16x16_tex,106,380,-1,0 , 1.0,0);
  /*csa = constructDrawStr(curd.pinyin,-1);
  gl = ShowString (&gl, (char *) csa.s, csa.length, 40, 410, 1 ,0,0,255,-1,255,255,255);*/
  /*gl = CFrame_Draw (&buttomframe, &gl, 0, 0, 0, cmessage);*/
  
  ce = buttomframe.edit;
  eleft = 10;
  ebutton = 415;
  for (; ce && (cce = *ce); ce++)
    {
      gl = CEdit_Draw (cce, &gl, 0, 0, eleft, ebutton, cmessage);
      eleft += cce->width + cce->ux;

    };
#ifdef BACKIMG
  if (currentpanel->paneltype != MAIN)
    {
      if (currentpanel->paneltype == CHINESE)
	{
	  /*gl = CFrame_Draw(&bgchinese_f,&gl,0,55,170,&cmessage); */
	  gl = CFrame_Draw (&bgalphanum_f, &gl, 0, 55, 110, cmessage);
	}
      else
	{
	  gl = CFrame_Draw (&bgalphanum_f, &gl, 0, 55, 110, cmessage);

	}

    }
#endif
  gl = CPanel_Draw (currentpanel, &gl,cmessage,80,gfxoffset);
  if(cmessage->errorcode == 3) {
  	gl = validExit(&gl,cmessage);
}
  #ifdef DEBUG_CURSOR
  
  gl = drawCursorParameter(&gl);
  #endif
  /*gl = CPanel_Draw(currentpanel,&gl); */
  /*numframe = 0;
     fr = currentpanel->cframe;
     ebutton = pbutton;
     pleft = gfxoffset;
     for(;fr&&(cfr = *fr);fr++) {
     pleft = gfxoffset+cfr->ux;
     gl = CFrame_Draw(cfr,&gl,numframe == currentpanel->focusframe?1:0,pleft,pbutton,&cmessage);
     numedit = 0;
     ce = cfr->edit;
     ebutton = pbutton+cfr->uy;
     eleft = pleft;
     for(;ce&&(cce=*ce);ce++) {
     gl = CEdit_Draw(cce,&gl,numframe == currentpanel->focusframe?1:0,
     numedit == cfr->focusedit?1:0,eleft,ebutton,&cmessage);
     eleft+=cce->width+cce->ux;
     numedit++;           
     }
     pbutton+=cfr->height+gfsoffset+cfr->uy;
     numframe++;
} */
};
};
  return gl;
};

int CValidField() {/*return 0 :success ,1 the name field wrong ,2 the birthdate wrong ,3 the name
		  and the birthdate both wrong
		  */
	int result = 0;
	if(curd.name[0] == '\0') result = 1;
	if(curd.birthdate[0] == '\0'||curd.birthdate[6]== '\0'||curd.birthdate[10] == '\0') {
		result +=2;
	}
	return result;
	};

Gfx* validExit(Gfx** glistp, CMessage* cmessage) {
	Gfx* gl = *glistp;
	static int i = 1;
	int validfield = 0;
	  /*gDPPipeSync (gl++);
	gDPSetCycleType(gl++,G_CYC_FILL);
         gDPSetFillColor(gl++,GPACK_RGBA5551(0,0,255,255) << 16 | 
         GPACK_RGBA5551(0,0,255,255));
         gDPFillRectangle(gl++,150, 100, 390, 340);*/
        if(cmessage->bbcardstate == BB_CARD_NOT_EXIST
	 ||cmessage->bbcardstate == BB_CARD_INVALID
	 ||cmessage->errorcode   == 1
	 ||cmessage->errorcode   == 2) gl = CFrame_Draw (&fmainbg ,&gl,0,0,0,cmessage);
         gl = CFrame_Draw(&fwarningbg,&gl , 0 ,160,150,cmessage);
         if(cmessage->bbcardstate == BB_CARD_NOT_EXIST) {
         	
         	if(i > 0)gl = CDraw_GlyphIndex(&gl,gsError_5, glyph_tex,200, 180, 0,0 ,1.0 );
        }
        else if (cmessage->bbcardstate == BB_CARD_INVALID ) {
        	if (i > 0)gl = CDraw_GlyphIndex(&gl,gsError_4, glyph_tex,200, 180, 0,0 ,1.0 );
        }
        
        else if(cmessage->errorcode == 1) {
		 if(i > 0)gl = CFrame_Draw(&ferrorread,&gl , 0 ,200,200,cmessage);
	}
	else if(cmessage->errorcode == 2) {
		if(i>0) gl = CFrame_Draw(&ferrorwrite,&gl , 0 ,200,200,cmessage);
		}
	else if(cmessage->errorcode == 3) {
	if(curd.gBbClubId[0] == '\0') {
	 validfield = CValidField();
	}
         
        if(validfield) {
        	IGCF_waring.uy = gyoffset+65;
        	IGCF_saveyes.uy = gyoffset - 85;
        	#if 0/*now we will only pop one message for all staus*/
        	if	(validfield == 1)  {
			   gl = CDraw_GlyphIndex(&gl,gsError_11, glyph_tex,200, 180, 0,0 ,1.0 );     		
        	}
        	else if (validfield == 2)  {
        		gl = CDraw_GlyphIndex(&gl,gsError_11, glyph_tex,200, 180, 0,0 ,1.0 );
        	}
        	else if (validfield == 3)  {
        		gl = CDraw_GlyphIndex(&gl,gsError_11, glyph_tex,200, 180, 0,0 ,1.0 );
        	
        	}
        	#endif
        	
        
	}
	else {
	IGCF_waring.uy = gyoffset+40;
        IGCF_saveyes.uy = gyoffset - 60;	
	}
	
         gl = CPanel_Draw(&GC_panel[5],&gl,cmessage,150,260);
         if(i>0&&validfield) {
         	
         	gl = CDraw_GlyphIndex(&gl,gsError_11, glyph_tex,185, 170, 0,0 ,1.0 );
         	}
         }
        
        if(i >= 70) {i = -20;}
        else i++;
	return gl;
	};

Gfx* displayError(Gfx** glistp, CMessage* cmessage) {
	Gfx* gl = *glistp;
	 gl = CFrame_Draw(&fwarningbg,&gl , 0 ,160,150,cmessage);
	 /* tileRectangle (&gl,
			 cmessage->errorcode==1?(void *)namelabel_tex:(void *)addresslabel_tex, G_IM_FMT_RGBA, 16, 240,
			 32, 32, 32, 0, 0, 240,
			 32, 200, 200);*/
	if(cmessage->errorcode == 1&&cmessage->CDIS_CURSOR) {
		 gl = CFrame_Draw(&ferrorread,&gl , 0 ,200,200,cmessage);
	}
	else if(cmessage->errorcode == 2&&cmessage->CDIS_CURSOR) {
		 gl = CFrame_Draw(&ferrorwrite,&gl , 0 ,200,200,cmessage);
		}
	return gl;	
	};


#ifdef DEBUG_CURSOR
  
  Gfx* drawCursorParameter(Gfx** glistp) {
  	unsigned char gsb[4][10] = {{"xo"},
  				    {"xd"},   	
				    {"yo"},
				    {"yd"},
				   };
	unsigned int gsi[4] ;
	int i , j  , m = 100 ,f ,b;
	Gfx* gl = *glistp;
	gsi[0] =  xcursoroffset ;
	gsi[1] =  xcursordelay ;
	gsi[2] =  ycursoroffset ;
	gsi[3] =  ycursordelay ; 
  	
  	for(i = 0;i<4;i++) {
  		f = gsi[i];
  		m = 100;
  		for(j = 0;j<3;j++) {
  			b = f/m;
  			f = f - b*m;
  			b+=0x30;
  			gsb[i][2+j] = b;
  			m /= 10;
  				
  			}
  			gsb[i][2+j] = '\0';
  			/*csa = constructDrawStr(gsb[i],-1);*/
  			gl = CDraw_Glyph(&gl,gsb[i], glyph16x16_tex,50+i*80,65 , -4,0 ,1.0 ,1.0);
  	}
  	
  	
  	return gl;
  	
  	}
  #endif
