
//用途 檢查email格式
//建立 楊正誠 2004/8/3 03:19下午
function emailCheck (eMail) {

	//檢查空白字元
	re = /\s+/i;
	if (eMail.match(re)) {
		return -1;
	}

	re = /(.+)\@+([\w\.-]+)/i;
	found=eMail.match(re);
	if (!found) {
		return -1;
	}
	else {
		dot_array=found[2].split(/[\.]+/);
		if ( dot_array.length < 2) {
			return -1;
		}
	}

	return found[1]+'@'+dot_array.join('.');
}

//用途 檢查密碼
//建立 楊正誠 2005/7/14
function passwd_chk (pw1, pw2) {
	//檢查長度
	if (pw1.length <4 || pw1.length> 32)
		return("密碼長度只能 4 到 32 個字母 !\n");

	if (pw1 != pw2)
		return("密碼二次輸入不一樣,請重新輸入 !\n");

	//檢查是否有英文數字以外的字元
	re = /[^A-Za-z0-9]/i;
	if (pw1.match(re))
		return("密碼只能是英文字或數字 !\n");

	return "";
}

//需要修改
//用途 檢查密碼
//建立 楊正誠 2004/8/9 03:19下午
function passwd_chk___old (pw1, pw2) {
	//檢查空白字元
	re = /\s+/i;
	if (pw1.match(re))
		return ("密碼不可以有空白 !\n");

	//檢查雙引號字元
	re = /\"/i;
	if (pw1.match(re))
		return ("密碼不可以有雙引號 !\n");

	//檢查長度
	if (pw1.length <6 || pw1.length> 32)
		return ("密碼長度只能 6 到 32 個字母 !\n" );

	if (pw1 != pw2)
		return("密碼二次輸入不一樣,請重新輸入 !\n");

	//檢查數字
	re = /\d/i;
	if (!pw1.match(re))
		return ("密碼必須包含數字 !\n");

	//檢查英文
	re = /[A-Za-z]/i;
	if (!pw1.match(re))
		return ("密碼必須包含英文字 !\n");

	return "";
}

//用途 檢查生日
//建立 楊正誠 2004/8/9 03:19下午
function birthday_chk (year, month, day) {

	if (year == '')
		return ("請輸入生日的年份 !\n");
	re = /^[12][0-9]{3}/i;
	if (!year.match(re))
		return ("生日的年份格式錯誤 !\n");

	if (month == '')
		return ("請選擇生日的月份 !\n");
	re = /^[0-9]{2}/i;
	if (!month.match(re))
		return ("生日的月份格式錯誤 !\n");

	if (day == '')
		return ("請選擇生日的日期 !\n");
	re = /^[0-9]{2}/i;
	if (!day.match(re))
		return ("生日的日期格式錯誤 !\n");

	return "";
}

//用途 檢查選項按鈕是否被選取
//參數 radio  -> 選項按鈕名稱
//參數 name  -> 選項按鈕中文名稱
//建立 楊正誠 2004/8/9 03:19下午
function radio_chk (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 id_no_chk(id) {
	tab = "ABCDEFGHJKLMNPQRSTUVWXYZIO"
	//              A B C D E F G H J K L M N P Q R S T U V W X Y Z I O
	A1 = new Array (1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3 );
	A2 = new Array (0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,2,0,1,3,4,5 );
	Mx = new Array (9,8,7,6,5,4,3,2,1,0);
	if (id.length != 10)
		return false;
	i = tab.indexOf(id.charAt(0));
	if ( i == -1 )
		return false;

	sum = A1[i] + A2[i]*9;
	for ( i=1; i<10; i++ ) {
		v = parseInt( id.charAt(i) );
		if ( isNaN(v) )
			return false;
		sum = sum + v * Mx[i];
	}

	fix0 = sum % 10;
	fix1 = 10 - fix0;
	if (fix1 == 10)
		fix1 = 0;

	if (id.charAt(9) == fix1)
		return true;
	else
		return false;
}

//用途 檢查自然數
//建立 楊正誠 2004/8/10 03:19下午
function natural_number_chk (quota) {
	re = /^(0|([1-9][0-9]*))$/;
	if (quota.match(re))
		return true;

	return false;
}
