function check_uid ( uid )
{
if( uid.length <= 0 )
return( "您的帳號還沒填呢 !\n" );
if( uid.length <3 || uid.length> 20 )
return( "您的帳號長度只能 3 至 20 個字元 !\n" );
for( idx = 0 ; idx <uid.length ; idx++ )
{
if( uid.charAt(idx)>= 'A' && uid.charAt(idx) <= 'Z' )
return( "帳號不可以含有大寫字元 !\n" );
if( !( ( uid.charAt(idx)>= 'a' && uid.charAt(idx) <= 'z' ) || ( uid.charAt(idx)>= '0' && uid.charAt(idx) <= '9' ) || ( uid.charAt(idx) == '_' ) ) )
return( "您的帳號只能是數字,英文字母及「_」等符號,其他的符號都不能使用 !\n" );
if( uid.charAt(idx) == '_' && uid.charAt(idx-1) == '_' )
return( "「_」符號不可相連 !\n" );
}
if( uid.charAt( uid.length - 1 ) == '_' )
return( "「_」符號不可在最後 !\n" );
return "";
}
function check_oldID ( uid )
{
if( uid.length <= 0 )
return( "您的帳號還沒填呢 !\n" );
if( uid.length > 12 || uid.length < 4 )
return( "您的帳號長度只能大於4 個字元 和 小於 12 個字元 !\n" );
for( idx = 0 ; idx <uid.length ; idx++ )
{
if( uid.charAt(idx)>= 'A' && uid.charAt(idx) <= 'Z' )
return( "帳號不可以含有大寫字元 !\n" );
if( !( ( uid.charAt(idx)>= 'a' && uid.charAt(idx) <= 'z' ) || ( uid.charAt(idx)>= '0' && uid.charAt(idx) <= '9' )  ) )
return( "您的帳號只能是數字,英文字母,其他的符號都不能使用 !\n" );
}
return "";
}

function check_passwd ( pw1, pw2 )
{
if( pw1 == '' ) {
return ("密碼不可以空白 !\n");
}
for( var idx = 0 ; idx <pw1.length ; idx++ ) {
	if( pw1.charAt(idx) == ' ' || pw1.charAt(idx) == '\"' ) {
		return ("密碼不可以含有空白或雙引號 !\n");
	}
	if(!((pw1.charAt(idx) >= "a" && pw1.charAt(idx) <= "z")||(pw1.charAt(idx) >= "0" && pw1.charAt(idx) <= "9"))){
        return "請輸入限用英文，數字組合的密碼!\n";
    }
}	
if( pw1.length < 6 || pw1.length > 12 )
return( "密碼長度只能 6 到 12 個字母 !\n" );
if( pw1 != pw2 )
return("密碼二次輸入不一樣,請重新輸入 !\n");
return "";
}

function check_ht ( ht )
{
if( ht == '' )
return( "密碼提示不可以空白 !\n" );
return "";
}
function check_telephonenumber ( number )
{
var error = false;
if( number.length <= 0 )
return "您的通訊電話還沒填呢 !\n";
for( idx = 0 ; idx <number.length ; idx++ ) {
if( !( ( number.charAt(idx)>= '0' && number.charAt(idx) <= '9' ) || ( number.charAt(idx) == '-' ) ) ) {
error = true;
break;
}
}
if( error == true )
return "您的通訊電話只能是數字及'-'等符號, 其他的符號都不能使用 !\n";
return "";
}
function check_email ( email, emop )
{
var alt = check_radio( emop, "聯絡信箱" );
if( alt.length> 0 )
return alt;
var len = email.length;
if( emop[1].checked == true && len == 0 )
return "您的聯絡信箱選擇備用電子信箱, 所以備用電子信箱不可以空白 !\n";
var ck =0;
if(len==0)
return "";
for(var i=0;i<len;i++)
{ var c= email.charAt(i);
if(!((c>="A"&&c<="Z")||(c>="a"&&c<="z")||(c>="0"&&c<="9")||(c=="-")||(c=="_")||(c==".")||(c=="@")))
return "您的電子郵件地址只能是數字,英文字母及'-','_'等符號,其他的符號都不能使用 !\n";
}
if((email.indexOf("@")==-1)||(email.indexOf("@")==0)||(email.indexOf("@")==(len-1)))
return "您的電子郵件地址不合法 !\n";
if((email.indexOf("@")!=-1)&&(email.substring(email.indexOf("@")+1,len).indexOf("@")!=-1))
return "您的電子郵件地址不合法 !\n";
if((email.indexOf(".")==-1)||(email.indexOf(".")==0)||(email.lastIndexOf(".")==(len-1)))
return "您的電子郵件地址不完全 !\n";
var idx = email.indexOf("@");
var name = email.substring( 0, idx );
var domain = email.substring( idx+1, email.length).toLowerCase();
email = name + "@" + domain;
if((email.indexOf("@kimo.com")>=0) || (email.indexOf("@yahoo.com")>=0))
return "您的備用電子信箱不能是Yahoo!奇摩電子信箱 !\n";
if( email == "tw-abuse@yahoo-inc.com" )
return "您的電子郵件地址不合法 !\n";
return "";
}
function check_amail ( email, emop )
{
var len = email.length;
if( emop.type == "checkbox" ) {
if( !emop.checked && len == 0 )
return "您的聯絡信箱選擇備用電子信箱, 所以備用電子信箱不可以空白 !\n";
}
if(len==0)
return "";
for(var i=0;i<len;i++)
{ var c= email.charAt(i);
if(!((c>="A"&&c<="Z")||(c>="a"&&c<="z")||(c>="0"&&c<="9")||(c=="-")||(c=="_")||(c==".")||(c=="@")))
return "您的電子郵件地址只能是數字,英文字母及'-','_'等符號,其他的符號都不能使用 !\n";
}
if((email.indexOf("@")==-1)||(email.indexOf("@")==0)||(email.indexOf("@")==(len-1)))
return "您的電子郵件地址不合法 !\n";
if((email.indexOf("@")!=-1)&&(email.substring(email.indexOf("@")+1,len).indexOf("@")!=-1))
return "您的電子郵件地址不合法 !\n";
if((email.indexOf(".")==-1)||(email.indexOf(".")==0)||(email.lastIndexOf(".")==(len-1)))
return "您的電子郵件地址不完全 !\n";
return "";
}
function check_email1 ( email )
{
var len = email.length;
if(len==0)
return "您的電子郵件地址不能為空白!\n";
for(var i=0;i<len;i++)
{ var c= email.charAt(i);
if(!((c>="A"&&c<="Z")||(c>="a"&&c<="z")||(c>="0"&&c<="9")||(c=="-")||(c=="_")||(c==".")||(c=="@")))
return "您的電子郵件地址只能是數字,英文字母及'-','_'等符號,其他的符號都不能使用 !\n";
}
if((email.indexOf("@")==-1)||(email.indexOf("@")==0)||(email.indexOf("@")==(len-1)))
return "您的電子郵件地址不合法 !\n";
if((email.indexOf("@")!=-1)&&(email.substring(email.indexOf("@")+1,len).indexOf("@")!=-1))
return "您的電子郵件地址不合法 !\n";
if((email.indexOf(".")==-1)||(email.indexOf(".")==0)||(email.lastIndexOf(".")==(len-1)))
return "您的電子郵件地址不完全 !\n";
return "";
}
function check_identity ( id, radio )
{
if( ! (radio[0].checked || radio[1].checked) )
return '您的身分證字號（護照號碼）還沒填呢 !\n';
if( radio[0].checked == true ) {
var myid = id;
myid = myid.toUpperCase();
id = myid;
if(myid.length>10)
return "您的身分證字號超過10個字 !\n";
if(myid.length<10)
return "您的身分證字號不滿10個字 !\n";
var c = myid.charAt(0);
if(c<"A" || c> "Z")
return "您的身分證字號第一碼必須是大寫的英文字母 !\n";
c = myid.charAt(1);
if(c!="1" && c!="2")
return "您的身分證字號第二碼有問題 !\n";
for(i=1;i<10;i++)
if(isNaN(parseFloat(myid.charAt(i))))
return "您的身分證字號第二到十碼有問題 !\n";
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(myid.charAt(0)==alph[i])
n=i;
var tot1 = parseFloat(num[n].charAt(0)) + (parseFloat(num[n].charAt(1)) * 9);
var tot2 = 0;
for(i=1;i<myid.length-1;i++)
tot2 = tot2 + parseFloat(myid.charAt(i))*(9-i);
var tot3 = parseFloat(myid.charAt(9));
var tot4 = tot1 + tot2 + tot3;
if((tot4 % 10)!=0)
return "您的身分證字號有問題 !\n";
} else {
if ( id.length <= 0 ) return '您的身分證字號（護照號碼）還沒填呢 !\n';
}
return "";
}

//=====check 身分證字號 return true or false
function IDcheck(idno){
  if (idno.length == 10) {
	var compstr,pos,checksum;
	checksum = 0;
	cmpstr="ABCDEFGHJKLMNPQRSTUVXYWZIO";
	pos=cmpstr.indexOf((idno.charAt(0)).toUpperCase());
	if(pos == -1 || isNaN(idno.substring(1,9)))
	   return "您身份証字號有問題!\n";
	else   {
		pos = pos + 10;
		checksum = Math.floor(pos/10) + (pos - (Math.floor(pos/10)*10) )*9;
		var checksum = checksum+8*parseInt(idno.charAt(1))+7*parseInt(idno.charAt(2))+6*parseInt(idno.charAt(3))+5*parseInt(idno.charAt(4))+4*parseInt(idno.charAt(5))+3*parseInt(idno.charAt(6))+2*parseInt(idno.charAt(7))+1*parseInt(idno.charAt(8))+1*parseInt(idno.charAt(9));
		var check1 = parseInt(checksum/10);
		var check2 = checksum/10;
		var check3 = (check2-check1)*10;
		if (checksum == check1*10) { return ""; }
		else {
		  if (parseInt(idno.charAt(9)) == (10-check3)) { return ""; }
		  else { return "您身份証字號有問題!\n";}
		}
	}
  }
  else
	return "您身份証字號有問題!\n";
}

function check_null ( column, name )
{
if( column.length == 0 )
return name + "不可以空白 !\n";
return "";
}
function check_select ( select, name )
{
if( select.options[0].selected == true )
return name + "必須選擇 !\n";
return "";
}
function check_radio ( radio, name )
{
var error = true;
for( i=0; i <radio.length; i++ )
if( radio[i].checked == true ) {
error = false;
break;
}
if( error == true )
return name + "必須選擇 !\n";
return "";
}
function check_birthday_year( year )
{
var error = false;
if( year.length != 4 )
return ("您的生日年份必須是四個數字, 例如 1980 年 !\n");
for( idx = 0 ; idx <year.length ; idx++ ) {
if( !( year.charAt(idx)>= '0' && year.charAt(idx) <= '9' ) ) {
error = true;
break;
}
}
if( error == true )
return ("您的生日年份必須是四個數字, 例如 1980 年 !\n");
return "";
}

function check_mobilephone ( number )
{
var error = false;
if( number.length <= 0 )
return "您的行動電話還沒填呢 !\n";
if( number.length >= 24 )
return "您的行動電話有問題 !\n";
for( idx = 0 ; idx <number.length ; idx++ ) {
if( !( number.charAt(idx)>= '0' && number.charAt(idx) <= '9' ) && number.charAt(idx)!='-' && number.charAt(idx)!='+' ) {
error = true;
break;
}
}

if( error == true )
return "您的行動電話只能是數字, 其他的符號都不能使用 !\n";
else
return "";
}

function check_nan( num ,name )
{
	if( Math.round( new Number(num) ) < 1 ) 
		return name + "不能設定小於1!\n";
	else
		return "";
}
function check_nan1( num ,name )
{
	if( Math.round( new Number(num) ) < 0 ) 
		return name + "不能設定為負數!\n";
	else
		return "";
}

function check_nan2( num ,name )
{
	if( Math.round( new Number(num) ) < 0 ) 
		return name + "不能設定小於0!\n";
	else
		return "";
}


function check_number_YN( number , name)
{
var error = false;
if( number.length <= 0 )
return name + "不能為空白!\n";

for( idx = 0 ; idx <number.length ; idx++ ) {
if( !( number.charAt(idx)>= '0' && number.charAt(idx) <= '9' ) ) {
error = true;
break;
}
}

if( error == true )
return name + " 只能是數字型態, 其他的符號都不能使用 !\n";
else
return "";
}
//四捨五入
function  ForDight(Dight,How)  
{  
           Dight  =  Math.round  (Dight*Math.pow(10,How))/Math.pow(10,How);  
           return  Dight;  
} 

function check_number( number, name )
{	
	if( number.length <= 0 )
		return name + "不能為空白!\n";
		
	if( isNaN( number ) == true )
		return name + "不是一個正確的數字形態!\n";
	else
		return "";
}	
