Javascript Error: Undefined variable batval At line 213, line => if (batval==

__header("Content-Type","text/html; charset=gb2312");
var serr="{\"op\":\"op err\"}";
var tbname = "";
var ikind = itype / 256;
var imode=0;
if (ikind == 1) 
{
	if (itype==259)  tbname = "tbTransf";
	else if (itype==260)  tbname = "tbPowSCADA";
	else if (itype==261)  tbname = "tbFBJK002G3S";
	else if (itype==262)  tbname = "tbHC311A";
	else if (itype==264)  tbname = "tbPsmE10c";
	else if (itype==265)  tbname = "tbElecDeepSeaDynemo";
	else if (itype==266)  tbname = "tbElecUpsEast";
	else if (itype==267)  tbname = "tbWaterMeter";
	else if (itype==268)  tbname = "tbElecJpmcwb";
	else if (itype==269)  tbname = "tbElecJSYMK141";
	else if (itype==270)  tbname = "tbElecCUC06H";
	else if (itype==271)  tbname = "tbElecAcsws";
	else if (itype==272)  tbname = "tbElecXuanYue";
	else if (itype==273)  tbname = "tbElecCur";
	else if (itype==274)  tbname = "tbElecCUC12H";
	else if (itype==276)  tbname = "tbElecIDCA21x6";
	else if (itype==277)  tbname = "tbElecPS48600";
	else tbname = "tbElec";
}
else if (ikind == 2)
{
	if (itype == 513)
		tbname = "tbElcSwA1086";
	else if (itype == 514)
		tbname = "tbElecSwTime12";
	else if (itype == 515){
		tbname = "tbElcSwTrans";
		if (batval==1) tbname="tbTransBaseInfo";
		else if (batval==2) tbname="tbTransMachineInfo";
		else if (batval==3) tbname="tbTransExcitateInfo";
		else if (batval==4) tbname="tbTransAmplifierInfo";
		else if (batval==5) tbname="tbTransPowerInfo";
	}
	else if (itype == 516)
		tbname = "tbElcSwIDCA21";
	else if (itype == 517)
		tbname = "tbElcSwRelay";
	else
		tbname = "tbOnOff";
}
else if (ikind == 3) 
{
	 if (itype < 788) 
		tbname = "tbUps";
	 else if (itype==788) 
		tbname = "tbUpsGXE";
	 else
		tbname = "tbUpsEx";
}
else if (ikind == 4)
{
  if (itype==1024) tbname = "tbBattDb100";
  else if (itype==1025) tbname = "tbBattAdu1000";
  else if (itype==1027) tbname = "tbBattRTVS";
  else if (itype==1028) {
    tbname = "tbBatt100";
    if (batval==1) tbname="tbBattVal";
  }
  else if (itype==1029) {
    tbname = "tbBattEB90";
    if (batval==1) tbname="tbBattEb90Val";
  }
  else if (itype==1030) {
    tbname = "tbBattBms";
    if (batval==1) tbname="tbBattBMSVal";
  }
  else if (itype==1031) tbname = "tbBattH3GTV";
  else if (itype==1032) tbname = "tbBattH3GTC";
  else if (itype==1033) tbname = "tbBattA60";
}
else if (ikind == 5)
{
  if (itype == 1282) tbname = "tbEnvirPm";
  else if (itype == 1283) tbname = "tbEnvirNHFS45";
  else if (itype == 1284) tbname = "tbEnvirLaserPM";
  else if (itype == 1285) tbname = "tbEnvirYS8159B";
  else if (itype == 1286) tbname = "tbEnvirT3";
  else if (itype == 1287) tbname = "tbEnvirJxbs";
  else if (itype==1288) {
    tbname = "tbSitePro";
    if (batval==1) tbname="tbSiteProTemHum";
    if (batval==2) tbname="tbSiteProLeak";
    if (batval==3) tbname="tbSiteProDi";
    if (batval==4) tbname="tbSiteProAirc";
  }
  else if (itype == 1289) tbname = "tbEnvirLightning";
  else if (itype == 1291) tbname = "tbEnvirO3";
  else if (itype == 1292) tbname = "tbEnvirBWDK3208E";
  else if (itype == 1293) tbname = "tbEnvirEx";
  else if (itype == 1300) tbname = "tbEnvirSobey";
  else if (itype == 1301) tbname = "tbXF";
  else if (itype == 1303) tbname = "tbEnvirJXBS3001QY";
  else if (itype == 1304) tbname = "tbEnvirJXBS4001O2";
  else if (itype == 1305) tbname = "tbEnvirWHCO";
  else if (itype == 1306) tbname = "tbEnvirVoice";
  else if (itype == 1307) tbname = "tbEnvirWindSpeed";
  else if (itype == 1308) tbname = "tbEnvirWindDir";
  else if (itype == 1308) tbname = "tbEnvirNew";
  else if (itype == 1310) tbname = "tbEnvirCPL";
  else tbname = "tbEnvir";
}
else if (ikind == 6) 
{
	tbname = "tbLeak";
}
else if (ikind == 7)
{
	if (itype == 1794) tbname = "tbAircLcpDx";
	else if (itype == 1795) tbname = "tbAircRS816";
	else if (itype == 1796) tbname = "tbAircIACRx0";
	else if (itype == 1797) tbname = "tbAircMitsubishi";
	else if (itype == 1798) tbname = "tbAircDeHumer";
	else if (itype == 1799) tbname = "tbAircEK3030E";
	else tbname = "tbAirc";
}
else if (ikind == 8)
{
  if (itype==2048) tbname = "tbCyberMate";
  else if (itype==2049) tbname = "tbEmerson";
  else if (itype==2050) tbname = "tbCybStulz";
  else if (itype==2052) tbname = "tbPlc";
  else if (itype==2053) tbname = "tbLinegt";
  else if (itype==2054) tbname = "tbLinegi";
  else if (itype==2055) tbname = "tbCanatal";
  else if (itype==2056) tbname = "tbPex";
  else if (itype==2057) tbname = "tbDME3000";
  else if (itype==2058) tbname = "tbMatrix";
  else if (itype==2059) tbname = "tbStation";
  else if (itype==2060) tbname = "tbTEMaster";
  else if (itype==2061) tbname = "tbCyberHiross";
  else if (itype==2062) tbname = "tbEvoCyberDx";
  else if (itype==2063) tbname = "tbRDA050CXTILI";
  else if (itype==2064) tbname = "tbSunrise";
  else if (itype==2065) tbname = "tbDF34BMS";
  else if (itype==2066) tbname = "tbAircK200";
  else if (itype==2067) tbname = "tbCyberDaiKin";
  else if (itype==2068) tbname = "tbCyberDataCool";
  else if (itype==2069) tbname = "tbCyberHairf";
  else if (itype==2070) tbname = "tbCyberCanatalKN10";
  else if (itype==2071) tbname = "tbCyberUG40";
  else if (itype==2072) tbname = "tbCyberInRowRD";
  else if (itype==2073) tbname = "tbCyberHstx";
  else if (itype==2074) tbname = "tbCyberPcos";
  else if (itype==2075) tbname = "tbCyberSCA";
  else if (itype==2076) tbname = "tbCyberJADC0110b";
  else if (itype==2077) tbname = "tbCyberCoolSmart";
  else if (itype==2078) tbname = "tbCyberDelta";
  else if (itype==2079) tbname = "tbCyberEcDx";
  else if (itype==2080) tbname = "tbCyberCSHH";
  else if (itype==2081) tbname = "tbCoolMaster7000Dx";
  else if (itype==2082) tbname = "tbCoolMaster7000Jd";
  else if (itype==2083) tbname = "tbCyberHirolink";
  else if (itype==2084) tbname = "tbCybIR33";
  else if (itype==2085) tbname = "tbCybAcxHpr";
  else if (itype==2086) tbname = "tbCybHserial";
  else if (itype==2087) tbname = "tbCyberMateDX";
  else if (itype==2088) tbname = "tbCyberHFSerial";
  else if (itype==2089) tbname = "tbCybMideaCN16";
  else if (itype==2090) tbname = "tbCybMideaUT204E";
  else if (itype==2091) tbname = "tbCybBlackShidlds";
  else if (itype==2092) tbname = "tbCyberZhX12";
  else if (itype==2093) tbname = "tbAircICX";
  else if (itype==2094) tbname = "tbCyberEk503";
  else if (itype==2095) tbname = "tbCyberSL1600F";
  else if (itype==2096) tbname = "tbCyberDeHumer";
  else if (itype==2097) tbname = "tbCyberStulzC7000CPDU_A";
  else if (itype==2099) tbname = "tbCyberZLU09D2HEAC";
  else if (itype==2100) tbname = "tbAircCM";
  else if (itype==2101) tbname = "tbCyberHaier";
  else if (itype==2102) tbname = "tbCyberClimente";
  else if (itype==2104) tbname = "tbCyberGDHW";
  else if (itype==2108) tbname = "tbCyberStulzC";
  else if (itype==2109) tbname = "tbCyberEmersonC";
  else tbname = "tbCyb";
}
else if (ikind == 9)
{
  if (itype == 2313) tbname = "tbMlan7vxpxj";
  else tbname = "tbDio";
}
else if (ikind == 10) tbname = "tbAlm";
else if (ikind == 11) tbname = "tbMon";
else if (ikind == 12) tbname = "tbCamera";
else if (ikind == 13) 
{
	if (itype==3332) tbname = "tbCXV6V8";
	else if (itype==3333) tbname = "tbCardRS485reader";
	else if (itype==3334) tbname = "tbCard20x0";
	else if (itype==3335) tbname = "tbPingNet";
	else
	tbname = "tbCardLog";
}
else if (ikind == 14)
{
	tbname = "tbSvr";
	imode=0;
}
else if (ikind==16 || ikind==17)
{
	tbname = "tbSnmpDat";
	imode=0;
}
else if (ikind==18 || ikind==19)
{
	tbname = "tbModbus";
	if (batval==1)
		tbname = "tbModbusDat";
	imode=0;
}
else if (ikind==20 || ikind==21)
{
	tbname = "tbYdt1363Dat";
	imode=0;
}

if (tbname=="")
  write(serr);
else
{
  db_Open("/NandFlash/tmp/dbDat0.db3");
  if (sid==0)
    db_QryAdv("select * from "+tbname+" where Type="+itype,itype);
  else
    db_QryAdv("select * from "+tbname+" where SID="+sid,sid,imode);
  db_Close();
}