//檢查是否為郵遞區號
function chk_zipcode(dstText){
	zipcode_num = dstText.match(/^\d{3,5}$/);
	if(!zipcode_num || !dstText) return false;
	return true;
}

//檢查是否為電話號碼
function chk_telno(dstText){
	phone_num = dstText.match(/^\d{6,8}$/);
	if(!phone_num || !dstText) {
		return false;
	}
	else{
		return true;
	}
}

//檢查是否為行動電話號碼
function chk_phone(dstText){
	data = dstText.match(/^\d{4}-\d{3}\d{3}$|^\d{10}$/);
	if(!data || !dstText) return false;
	return true;
}

//檢查數字
function chk_num(dstText){
	data_num = dstText.match(/[^0-9]/g);
	if (!data_num || !dstText) return false;
	return true;
}

//檢查密碼(6~30)
function chk_passwd(dstText){
	data_num = dstText.match(/^[a-zA-Z0-9]{6,30}$/);
	if (!data_num || !dstText){
		return false;
	}
	else{
		return true;
	}
}

//檢查帳號(3~30)
function chk_accname(dstText){
	data_num = dstText.match(/^[a-zA-Z0-9]{3,30}$/);
	if (!data_num || !dstText){
		return false;
	}
	else{
		return true;
	}
}

//檢查分機數字1~8碼
function chk_extno(dstText){
	phone_num = dstText.match(/^\d{1,10}$/);
	if(!phone_num || !dstText) return false;
	return true;
}

//新檢查是否為電子郵件地址
function chk_email(strEmail) {
  var objRe = /^[_\-a-z0-9\.]+@([_\-a-z0-9]+\.)+[_\-a-z0-9]{2,3}$/;
  if(objRe.test(strEmail)) {
	  return true;
  }
  else{
	  return false;
  }
}

//檢查日期-日數
function chk_day(dstText){
	day_num = dstText.match(/^\d{2}$/);
	if(!day_num || !dstText) return false;
	if(day_num>31 || day_num<0) return false;
	return true;
}

//檢查是否為英文字母
function chk_alphabet(dstText){
	data = dstText.match(/[^a-z]/gi);
	if (data || !dstText) return false;
	return true;
}

//檢查全部中文字串
function chk_chinese(str){
    var intCode = 0;
    var intPostion = 0;
    var intChinese = 0;
    var intLen = str.length;

    while (intPostion < intLen)    {
        intCode = str.charCodeAt(intPostion);
        if (intCode > 128)
            intChinese++;
        intPostion++;
    }

    if (intLen==intChinese){
        return true;
	}
    else{
        return false;
	}
}

function repl_chistr(str){//限制輸入中文
	str = str.replace(/[^\u4E00-\u9FA5]/g,'');
	return str;
}

function chk_busino(busi_no){ //檢查統編
	var cx = new Array;
	cx[0] = 1;
	cx[1] = 2;
	cx[2] = 1;
	cx[3] = 2;
	cx[4] = 1;
	cx[5] = 2;
	cx[6] = 4;
	cx[7] = 1;

	var sum = 0;

	busino_num = busi_no.match(/^\d{8}$/);
	if(!busino_num || !busi_no){
	   return false;
	}
	else{
		var cnum = busi_no.split("");
		for (i=0; i<=7; i++) {
			sum += cc(cnum[i] * cx[i]);
		}
	}

	if (sum % 10 == 0){
		return true;
	}
	else if(cnum[6] == 7 && (sum + 1) % 10 == 0){
			return true;
		}
		else{
			return false;
		}
}

function cc(n){
  if (n > 9) {
	var s = n + "";
	n1 = s.substring(0,1) * 1;
	n2 = s.substring(1,2) * 1;
	n = n1 + n2;
  }
  return n;
}


