function CheckSID(frm, fld) {
	var SID = document.forms[frm][fld].value;
	var FinalChkSum = SID.substr(SID.length-1,1); // 身份證字號最後一碼, 檢查碼
	var SID_ChkSum = new Array('1','9','8','7','6','5','4','3','2','1');
	var tempSID = new Array(10);
	var p = new Array(10);
	var sum = 0;
	var SID_City = new Array();
	SID_City[0] = new Array('A','10');
	SID_City[1] = new Array('B','11');
	SID_City[2] = new Array('C','12');
	SID_City[3] = new Array('D','13');
	SID_City[4] = new Array('E','14');
	SID_City[5] = new Array('F','15');
	SID_City[6] = new Array('G','16');
	SID_City[7] = new Array('H','17');
	SID_City[8] = new Array('J','18');
	SID_City[9] = new Array('K','19');
	SID_City[10] = new Array('L','20');
	SID_City[11] = new Array('M','21');
	SID_City[12] = new Array('N','22');
	SID_City[13] = new Array('P','23');
	SID_City[14] = new Array('Q','24');
	SID_City[15] = new Array('R','25');
	SID_City[16] = new Array('S','26');
	SID_City[17] = new Array('T','27');
	SID_City[18] = new Array('U','28');
	SID_City[19] = new Array('V','29');
	SID_City[20] = new Array('X','30');
	SID_City[21] = new Array('Y','31');
	SID_City[22] = new Array('W','32');
	SID_City[23] = new Array('Z','33');
	SID_City[24] = new Array('I','34');
	SID_City[25] = new Array('O','35');

	for (j=0; j<SID_City.length; j++) {
		if (SID_City[j][0] == SID.substr(0,1)) {
			tempSID[0] = SID_City[j][1].toString().substr(0,1);
			tempSID[1] = SID_City[j][1].toString().substr(1,1);
			break;
		}
		else {
			continue;
		}
	}

	for (k=1; k<SID.length-1; k++) {
		tempSID[k+1] = SID.substr(k,1);
	}

	sum = (parseInt(tempSID[0])+9*parseInt(tempSID[1])+8*parseInt(tempSID[2])+7*parseInt(tempSID[3])+6*parseInt(tempSID[4])+5*parseInt(tempSID[5])+4*parseInt(tempSID[6])+3*parseInt(tempSID[7])+2*parseInt(tempSID[8])+1*parseInt(tempSID[9])+parseInt(FinalChkSum));

	if ((parseInt(sum) % 10) == 0) {
		return true;
	}
	else {
		return false;
	}
}

function IsErrorSID() {
	sid = document.WarrantyRegister.LoginName.value.toUpperCase();

	if (CheckSID('WarrantyRegister','LoginName') == false) {
		return false;
	}
}

function checkFullname() {
	if (document.WarrantyRegister.Fullname.value == '') {
		alert('請輸入姓名');
		return false;
	}
}

function checkLoginName() {
	if (document.WarrantyRegister.LoginName.value == '') {
		alert('請輸入身份證字號');
		return false;
	}

	//if (IsErrorSID() == false) {
	//	alert('身份證字號有誤,請注意第一個字母需大寫!');
	//	return false;
//	}
}

function checkLoginPass() {
	if (document.WarrantyRegister.LoginPass.value == '') {
		alert('請輸入密碼');
		return 0;
	} else if (document.WarrantyRegister.LoginPass2.value == '') {
		alert('請再次確認密碼');
		return 1;
	} else if (document.WarrantyRegister.LoginPass.value != document.WarrantyRegister.LoginPass2.value) {
		alert('您兩次輸入的密碼不同，請重新輸入');
		return 2;
	}
}

function checkEmail() {
	var sample = /^(\w[-._\w]*\w@\w[-._\w]*\w\.\w{2,4})$/;

	if (document.WarrantyRegister.Email.value == '') {
		alert('請輸入電子郵件');
		return false;
	}
	else if (!sample.test(document.WarrantyRegister.Email.value)) {
		alert('請輸入正確的電子郵件');
		return false;
	}
}

function checkCity() {
	if (document.WarrantyRegister.City.value == '0') {
		alert('請輸入居住地區');
		return false;
	}
}

function checkDistrict() {
	if (document.WarrantyRegister.District.value == '0') {
		alert('請輸入鄉鎮市區');
		return false;
	}
}

function checkAddress() {
	if (document.WarrantyRegister.Address.value == '') {
		alert('請輸入完整地址');
		return false;
	}
}

function checkTel1() {
	if (document.WarrantyRegister.Tel1_Head.value == '') {
		alert('請輸入電話區域號碼');
		return 0;
	}

	if (document.WarrantyRegister.Tel1_Body.value == '') {
		alert('請輸入電話號碼');
		return 1;
	}

}

function checkEducation() {
	if (document.WarrantyRegister.Education.value == '') {
		alert('請輸入教育程度');
		return false;
	}
}

function checkIncome() {
	if (document.WarrantyRegister.Income.value == '') {
		alert('請輸入平均月收入');
		return false;
	}
}

function checkOccupation() {
	if (document.WarrantyRegister.Occupation.value == '') {
		alert('請輸入職業');
		return false;
	}
}

function check_all() {
	if (checkFullname() == false) {
		document.WarrantyRegister.Fullname.focus();
		return false;
	}

	if (checkLoginName() == false) {
		document.WarrantyRegister.LoginName.focus();
		return false;
	}

	switch (checkLoginPass()) {
		case 0:
			document.WarrantyRegister.LoginPass.focus();
			return false;
			break;

		case 1:
			document.WarrantyRegister.LoginPass2.focus();
			return false;
			break;
		
		case 2:
			document.WarrantyRegister.LoginPass.value = '';
			document.WarrantyRegister.LoginPass2.value = '';
			document.WarrantyRegister.LoginPass.focus();
			return false;
			break;

	}

	if (checkEmail() == false) {
		document.WarrantyRegister.Email.focus();
		return false;
	}

	if (checkCity() == false) {
		document.WarrantyRegister.City.focus();
		return false;
	}

	if (checkDistrict() == false) {
		document.WarrantyRegister.District.focus();
		return false;
	}

	if (checkAddress() == false) {
		document.WarrantyRegister.Address.focus();
		return false;
	}

	switch (checkTel1()) {
		case 0:
			document.WarrantyRegister.Tel1_Head.focus();
			return false;
			break;

		case 1:
			document.WarrantyRegister.Tel1_Body.focus();
			return false;
			break;

		//case 2:
		//	document.WarrantyRegister.Tel1_Ext.focus();
		//	return false;
		//	break;
	}

	
}

if (typeof(Option)+"" != "undefined") v = true;

if(v){
	a = new Array();
	aln = 0;
}