function IDCkSum( id )
{
	var i;
	// 身分證字號檢查

	// 長度必須為10碼
	if(id.length>10)
		return (-6);

	if(id.length<10)
		return (-1);

	// 第一碼須為A到Z
	var c = id.charAt(0);
	if(c<"A" || c> "Z")
		return (-2);

	// 第二碼必須為1或2
	c = id.charAt(1);
	if(c!="1" && c!="2")
		return (-3);
  
	// 第二碼至第十碼必須為數字
	for(i=1;i<10;i++)
		if(isNaN(parseFloat(id.charAt(i))))
			return(-4);
  
	// 計算一:將第一碼英文轉數字A=10,B=11,C=12,.....
	// ABCDEFGHJKLMNPQRSTUVXYWZIO, please notice the sequence of I, O, W 
	// 10 ~35
	var alph = new Array("A","B","C","D","E","F","G","H","J","K","L","M","N","P","Q","R","S","T","U","V","X","Y","W","Z","I","O");
	var num  = new Array("10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35");
	var n=0;
	for(i=0;i<alph.length;i++)
		if(id.charAt(0)==alph[i])
			n=i;

	var tot1 = parseFloat(num[n].charAt(0)) + (parseFloat(num[n].charAt(1)) * 9);
  
	// 計算二:第2碼*8 + 第3碼*7 + .....
	var tot2 = 0;
	for(i=1;i<id.length-1;i++)
		tot2 = tot2 + parseFloat(id.charAt(i))*(9-i);
  
	// 計算三:第10碼數字
	var tot3 = parseFloat(id.charAt(9));
  
	var tot4 = tot1 + tot2 + tot3;
  
	// 總合除以10餘數必須為0
	if((tot4 % 10)!=0)
		return (-5);

	return (0);
}
function check_id( id )
{
	var ck = IDCkSum(id);
	if(ck==-6)
	{
		alert("您的身分證號碼超過10個字 !\n");
		return false;
	}
	if(ck==-1)
	{
		alert("您的身分證號碼不滿10個字 !\n");
		return false;
	}
	if(ck==-2)
	{
		alert("您的身分證號碼第一碼必須是大寫的英文字母 !\n");
		return false;
	}
	if(ck==-3)
	{
		alert("您的身分證號碼第二碼有問題 !\n");
		return false;
	}
	if(ck==-4)
	{
		alert("您的身分證號碼第二到十碼有問題 !");
		return false;
	}
	if(ck==-5)
	{
		alert("您的身分證號碼有問題 !");
		return false;
	}
	return true;
}

function chkemail(z)
{
    for ( i=0; i<= z.value.length - 1 ;i++ )
    {
    x = z.value.charAt(i);
    y = escape( x);
	if ( y != x && y !='%40')
		{
			alert('電子信箱錯誤');
			z.focus();
			return false;
			i = z.value.length;
		}
	}
	
	if ( z.value.indexOf('@') == -1 )
		{
			alert('電子信箱格式錯誤');
			z.focus();
			return false;
		}
	if ( z.value.indexOf('.') == -1 )
		{
			alert('電子信箱格式錯誤');
			z.focus();
			return false;
		}
	if (z.value.charAt(0)=='@') 
	{
		alert('電子信箱格式錯誤');
		z.focus();
		return false; //Email 第一個字不可為'@'	
	}	
		return true;
}
function chkbyr(y)
{
 	if(( y.value  < '1911' )|| ( y.value > '1997' ))
	{	
		y.focus();
		return false;
	}
}
function chkbmonth(b)
{
 	if( b.value > '12' )
	{	
		b.focus();
		return false;
	}
}
function chkday(d)
{
 	if(d.value > '31')
	{	
		d.focus();
		return false;
	}
}
function chkselect(E)
{
 	if(E.options[0].selected)
 	{
   		E.focus();
   		return false;
 	}
}
function isFilled(key)
{     
	if(key.value == "" || key.value == null) 
	{
		key.focus();
		return false;
	}
	else      
	return true;
}
function checkform( form )
{
	if(chkselect(form.Q1) == false)
	{
		alert("請選擇您偏好的場次??");
             return false;
	}
	if(isFilled(form.club_name) == false) 
	{
        	alert("請輸入您的家族名稱??");
             return false;
	}
	if(isFilled(form.club_url) == false) 
	{
        	alert("請輸入您的家族網址??");
             return false;
	}
	if(isFilled(form.club_topic) == false) 
	{
        	alert("請輸入您的家族上台演出主題??");
             return false;
	}
	if(isFilled(form.club_desc) == false) 
	{
        	alert("請輸入您的家族上台演出說明??");
             return false;
	}
	if(isFilled(form.name) == false) 
	{
        	alert("請輸入您的姓名??");
             return false;
	}
	if(isFilled(form.byear) == false) 
	{
        	alert("請輸入您出生年(西元)??");
             return false;
	}
	if(chkbyr(form.byear) == false)
	{
		alert("年份超出(請寫阿拉伯數字)??");
		return false;
	}
	if(chkselect(form.bmonth) == false)
	{
		alert("請選擇出生月份??");
             return false;
	}
	if(chkselect(form.bday) == false)
	{
		alert("請選擇出生日期??");
             return false;
	}
	if(isFilled(form.email) == false) 
	{
        	alert("請輸入您的電子信箱");
            return false;
	}
	if(chkemail(form.email) == false) 
        {
             return false;
        } 
        if(check_id(form.elements['id'].value) == false) 
       {
        	
             return false;
       }	
	return ture;
}