// JavaScript Document
String.prototype.trim = function() {
	return this.replace(/(^\s*)|(\s*$)/g, "");
}

String.prototype.ByteCount = function() {
	txt = this.replace(/(<.*?>)/ig,'');
	txt = txt.replace(/([\u0391-\uFFE5])/ig, '11');
	var count = txt.length;
	return count;
}

function click_tel_input(thisinput) {
	telmsg.className="box";
	telmsg.innerHTML="請輸入你的手機號碼，以便取得連絡";
}

function check_tel_input(thisinput) {
	var re = /^[0-9\-]{10}$/;
	if ( (thisinput.value.trim() == '') ) {
		telmsg.className="box_error";
		telmsg.innerHTML="系統檢查到你未有任何輸入，此項必須填寫內容，請重新填寫！";
	} else if (!thisinput.value.match(re)) {
		telmsg.className = 'box_error';
		telmsg.innerHTML = '手機號碼格式不符！未滿10位數字或超過10位數字！';
	} else  {
		telmsg.className="box_right";
		telmsg.innerHTML="手機號碼檢查，可以使用！";
	}
}

function click_name_input(thisinput) {
	namemsg.className="box";
	namemsg.innerHTML="請填 2 字以上中文！";
}

function check_name_input(thisinput) {
	var count = thisinput.value.trim().ByteCount();
	if( count == 0 ) {
		namemsg.className='box_error';
		namemsg.innerHTML="系統檢查到你未有任何輸入，此項必須填寫內容，請重新填寫！";
	} else if ((thisinput.value.trim() != '') && (count < 4 || count > 8)) {
		namemsg.className="box_error";
		namemsg.innerHTML="輸入的內容不可為空，同時只可以在 4-8 個字元之間，請重新填寫！";
	} else {
		namemsg.className="box_right";
		namemsg.innerHTML="聯絡人通過檢查，可以使用！";
	}
}


function click_email_input(thisinput) {
	mailmsg.className="box";
	mailmsg.innerHTML="請輸入你的電子信箱，用於傳送訂單，取得站內通知，建議輸入常用信箱";
}

function check_email_input(thisinput) {
	var re = /^[0-9a-zA-Z\-\.\_]+@[0-9a-zA-Z\-]+\.[0-9a-zA-Z\-\.]+$/;
	if ( (thisinput.value.trim() == '') ) {
		mailmsg.className="box_error";
		mailmsg.innerHTML="系統檢查到你未有任何輸入，此項必須填寫內容，請重新填寫！";
	} else if (!thisinput.value.match(re)) {
		mailmsg.className = 'box_error';
		mailmsg.innerHTML = '電子信箱格式不符！';
	} else  {
		mailmsg.className="box_right";
		mailmsg.innerHTML="電子信箱檢查，可以使用！";
	}
}

function chkform(objForm) {
	var objForm;
	var r = /^[a-z]\w{3,}$/i;
	var rm = /^[0-9a-zA-Z\-\.\_]+@[0-9a-zA-Z\-]+\.[0-9a-zA-Z\-\.]+$/;

	var password = objForm.password.value;
	var email = objForm.email.value;
	var tel = objForm.tel.value;
	var nickname = objForm.nickname.value;

	if( tel =='' || (!tel.match(r)) || (tel.length<1 || tel.length>10) ) {
		objForm.userid.focus();
		return false;
	}

	if( nickname ==''  || nickname.length<2 || nickname.length>16 ) {
		objForm.nickname.focus();
		return false;
	}

	if(email=='' || (!email.match(rm))) {
		objForm.email.focus();
		return false;
 	}
}