var local=new Array(34)
local[10]='A'
local[11]='B'
local[12]='C'
local[13]='D'
local[14]='E'
local[15]='F'
local[16]='G'
local[17]='H'
local[18]='J'
local[19]='K'
local[20]='L'
local[21]='M'
local[22]='N'
local[23]='P'
local[24]='Q'
local[25]='R'
local[26]='S'
local[27]='T'
local[28]='U'
local[29]='V'
local[32]='W'
local[30]='X'
local[31]='Y'
local[33]='Z'

function checkid(id){	
id=id.toUpperCase()
if(lengtherr(id)){
alert('未輸入身分證字號或輸入的字號長度有誤！');
document.form1.idno.focus();
document.form1.idno.select();
event.returnValue= false;
}else 
if(firstlettererr(id)){
alert('身分證第一碼查無此英文字母:'+id.substring(0,1));
document.form1.idno.focus();
document.form1.idno.select();
event.returnValue= false;
}else if(numerr(id)){
alert('輸入的身分證後九碼應為數字！');
document.form1.idno.focus();
document.form1.idno.select();
event.returnValue= false;
}else if(checkerr(id)){
alert('您輸入的身分證檢查碼有誤！');
document.form1.idno.focus();
document.form1.idno.select();
event.returnValue= false;
}else{

}
}
function lengtherr(id){
if(id.length<10)
return 1
else 
return 0
}
function firstlettererr(id){
var fl=id.substring(0,1)
var haserr=1
for(i=10;i<=33;i++){
if(local[i]!=fl)
continue
else{ 
haserr=0
break
}
}
if(haserr==1)
return 1
else
return 0
}function numerr(id){
var haserr=0
for(i=1;i<=9;i++){
if(parseInt(id.substring(i,i+1))>0 || id.substring(i,i+1)=='0')
continue
else{
haserr=1
break}
}
if(haserr==1)
return 1
else
return 0
}
function checkerr(id){
var se=new Array(10)
var we=0
var checkcode=0
for(i=10;i<=33;i++){
if(local[i]==id.substring(0,1)){
se[0]=parseInt((i+'0').substring(0,1))
se[1]=parseInt((i+'0').substring(1,2))
break
} 
}
for(i=1;i<=9;i++){
se[i+1]=parseInt(id.substring(i,i+1))
}
for(i=0;i<=10;i++){
if(i==0)
we=we+se[i]
else
we=we+(se[i]*(10-i))
} 
if(mod(we,10)==0){checkcode=((10-mod(we,10)+'0')).substring(1,2)}
else
{checkcode=((10-mod(we,10)+'0')).substring(0,1)}

if(checkcode!=id.substring(9,10))
return 1
else
return 0

}
function mod(a,b){
var r
r=Math.round(a/b)
if((b*r)>a)
r-=1
return (a-(b*r))
}