function check_ID ( ID ){
    if( ID.length <= 0 )
        return( "您的帳號還沒填呢 !\n" );
    if( ID.length < 3 || ID.length > 16 )
        return( "您的帳號長度只能 3 至 16 個字元 !\n" );
    for( idx = 0 ; idx < ID.length ; idx++ )
    {
        if( !( ( ID.charAt(idx) >= 'a' && ID.charAt(idx) <= 'z' ) || ( ID.charAt(idx) >= 'A' && ID.charAt(idx) <= 'Z' ) || ( ID.charAt(idx) >= '0' && ID.charAt(idx) <= '9' ) || ( ID.charAt(idx) == '_' ) )  )

            return( "您的帳號只能是數字,英文字母及「_」等符號,其他的符號都不能使用 !\n" );
        if( ID.charAt(idx) == '_' && ID.charAt(idx-1) == '_' )
            return( "「_」符號不可相連 !\n" );
    }
    if( ID.charAt( ID.length - 1 ) == '_' )
        return( "「_」符號不可在最後 !\n" );
    return "";
}
 
function check_pwd ( 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.length < 4 || pw1.length > 32 )
        return( "密碼長度只能 4 到 32 個字母 !\n" );
    if( pw1 != pw2 )
        return("密碼二次輸入不一樣,請重新輸入 !\n");
    return "";
}

function check_job ( job ){
    if( job == "99" )  {
        return ("請選擇您的職業 !\n");
    }
    return "";
}

function check_telnumber ( number ){			//檢查聯絡電話
    var error = false;
    if( number.length <= 0 )
        return "聯絡電話不可以空白 !\n";
    //if( number.length < 9 && number.length >= 6)
    //    return "聯絡電話請輸入區碼 !\n";
    for( idx = 0 ; idx < number.length ; idx++ ) {
        if( !( ( number.charAt(idx) >= '0' && number.charAt(idx) <= '9' ) || ( number.charAt(idx) == '-' ) || ( number.charAt(idx) == '(' ) || ( number.charAt(idx) == ')' )) ) {
            error = true;
            break;
        }
    }
    if( error == true )
        return "您的聯絡電話只能是數字或()或-等符號, 其他的符號都不能使用 !\n";
    if( number.length < 6 || number.length > 25 )
        return "聯絡電話錯誤 !\n";
    return "";
}

 function check_email ( email ){
   var len = email.length;
   var ck =0;
    if( len <= 0 )
        return "Email不可以空白 !\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_null ( column, name ){
   var len = column.length;
    if(len == 0)
        return name + "不可以空白 !\n";
   var c= column.charAt(0);
    if( c == " "){
	return name + "不可以空白!\n";
    }
    return "";
 }

 function check_select ( select, name ){
    if( select.options[0].selected == true )
        return name + "必須選擇 !\n";
    return "";
}
 
 function check_JoyWork ( formname, name ){
    var error = true;
    for (i=0; i < formname.JoyWork.length; i++)
    if( formname.JoyWork[i].checked != "" || formname.BroadCast.checked !="" ){
	error = false;
        break;
    }
    if( error == 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 != 10 )
       return "您的行動電話有問題 !\n";
     if( number.substring( 0, 2 ) != "09" )
       return "您的行動電話有問題 !\n";
     for( idx = 0 ; idx < number.length ; idx++ ) {
       if( !( number.charAt(idx) >= '0' && number.charAt(idx) <= '9' ) ) {
         error = true;
         break;
     }
   }
   if( error == true )
     return "您的行動電話只能是數字, 其他的符號都不能使用 !\n";
   else
     return "";
 }
