function check_netid(netid) {

  if( netid.length <= 0 )
    return( "您的帳號還沒填呢 !\n" );
    
  if( netid.length < 4 || netid.length > 16 )
    return( "您的帳號長度只能 4 至 16 個字元 !\n" );
    
  if ( !(netid.charAt(0) >= 'a' && netid.charAt(0) <= 'z') ) {
        return( "您的帳號第一字元只能為小寫字母 !\n" );
  }
  
  for( idx = 0 ; idx < netid.length ; idx++ )
  {
    if( netid.charAt(idx) >= 'A' && netid.charAt(idx) <= 'Z' )
      return( "帳號不可以含有大寫字元 !\n" );
      
    if( !( ( netid.charAt(idx) >= 'a' && netid.charAt(idx) <= 'z' ) || ( netid.charAt(idx) >= '0' && netid.charAt(idx) <= '9' ) || ( netid.charAt(idx) == '_' ) )  )
      return( "您的帳號只能是數字,英文字母及「_」等符號,其他的符號都不能使用 !\n" );
        
    if( netid.charAt(idx) == '_' && netid.charAt(idx-1) == '_' )
            return( "「_」符號不可相連 !\n" );
  }
    

  if( netid.charAt( netid.length - 1 ) == '_' )
    return( "「_」符號不可在最後 !\n" );
    
  return "";
}

function check_netpwd( pwd1, pwd2 )
{
    if( pwd1 == '' )
        return ("密碼不可以空白 !\n");
    
    for( var idx = 0 ; idx < pwd1.length ; idx++ )
        if( pwd1.charAt(idx) == ' ' || pwd1.charAt(idx) == '\"' )
            return ("密碼不可以含有空白或雙引號 !\n");
            
    if( pwd1.length > 14 )
        return( "密碼最多只能輸入20個字 !\n" );

    if( pwd1.length < 4 )
        return( "密碼最少要輸入4個字 !\n" );
        
    if( pwd1 != pwd2 )
        return("密碼二次輸入不一樣,請重新輸入 !\n");
        
    return "";
}

function check_same( netid, netpwd )
{

    if( netid == netpwd )
        return("帳號和密碼不可以相同 !\n");
    if( netpwd.indexOf(netid)!=-1 )
        return("密碼中不可以含有帳號 !\n");
        
    return "";
}

function check_email ( 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 ( sid )
{
  
  if ( sid.length <= 0 ) 
    return '您的身分證字號還沒填呢 !\n';
  
  var myid = sid;
  myid = myid.toUpperCase();
  sid = 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";

  return "";
}

function check_phonenumber ( number, name, method )
{
    var error = false;

    if ( method == 'notnull' ) {
      if( number.length <= 0 )
        return name + "還沒填呢 !\n";
    }

    if ( number.length > 0 ){

      for( idx = 0 ; idx < number.length ; idx++ ) {
        if( !( ( number.charAt(idx) >= '0' && number.charAt(idx) <= '9' ) || ( number.charAt(idx) == '-' ) ) ) {
          error = true;
          break;
        }
      }
    } else {
      error = false;
    }

    if( error == true )
        return "您的" + name + "只能是數字及'-'等符號, 其他的符號都不能使用 !\n";
    return "";
}

function check_mobilephone ( number, radio )
{
   var alt = check_radio( radio, "行動電話" );
   if( alt.length > 0 )
     return alt;
   var error = false;
   if( radio[1].checked == true ) {
     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";
   else
     return "";
}

function check_null ( str, name )
{
    if( str.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_ou( ou, name)
{
  if( ou.length <= 0 )
    return( name+"還沒填呢 !\n" );

  if( ou.length < 10 )
    return( "請用\"查機關代號\"的方式選擇正確的機關代號 !\n" );

  for( idx = 0 ; idx < ou.length ; idx++ )
  {

    if( !( ( ou.charAt(idx) >= 'A' && ou.charAt(idx) <= 'Z' ) || ( ou.charAt(idx) >= '0' && ou.charAt(idx) <= '9' )  )  )
      return( "請用\"查機關代號\"的方式選擇正確的機關代號 !\n" );

  }
  return "";
}

function printOut() {
var msg="";
if (!parent.window.print){
msg += "You need NS4.x to use this print button!\n";
msg += "Or please press Ctrl-P to print.";
alert(msg);
return;}
window.print();
}

