String.prototype.trim = function (){
	return this.replace(/^\s+|\s+$/g, "");
}

function trimall(m){
	for(i=0;i<m.elements.length;i++)
		m.elements[i].value=m.elements[i].value.trim();
}

function chkpass(m,m1,n,n1){
	if(m.value=="")
		return n+" is empty.\n";
	if(m.value.length <6 || m.value.length> 12)
		return n+" must be over 6 characters, but not more than 12 characters.\n";
	if(m.value!=m1.value)
		return n+" must be the same as "+n1+".\n";
	return "";
}

function chktext(m,n){
	if(m.value=="")
		return n+" is empty.\n";
	return "";
}
function chknum(m,n,s){
	if(m.value==""&&s==1)
		return n+" is empty.\n";
	if(m.value!=""&&s>1 && m.value.length != s)
		return n+" must be "+s+" characters.\n";
	if(isNaN(m.value))
		return n+" is not number.\n";
	return "";
}
function chkemail(m,n){
	if(m.value=="")
		return n+" is empty.\n";
	else
	if((m.value.indexOf ('@',0) == -1 || m.value.indexOf ('.',0) == -1))
		return n+" is not correct.\n";
	return "";
}
function chkradio(m,n){
	fg=true;
	if(m.checked){
		fg=false;
	}else{
		for(i=0;i<m.length;i++)
			if(m[i].checked) fg=false;
	}
	if(fg) return n+" is empty.\n";
	return "";
}

function setradio(m){
	for(i=0;i<m.length;i++){
		m[i].checked=false;
		}
}

function chkcheckbox(m,n,maxnum){
	fg=0;
	for(i=0;i<m.length;i++)
			if(m[i].checked) fg++;
	if(fg==0) return n+" should be chosen.\n";
	if(fg>maxnum) return n+" is up to "+ maxnum +" key words.\n";
	return "";
}

function chkdate(m,n){
	inix = /^\d{4}-\d{2}-\d{2}$/;
	if (inix.test(m.value)){
		return "";
	}else{
		return n+" format is not correct.\n";
	}
}

function chkidno(s) {
	var c, n, i;
	var t= "ABCDEFGHJKLMNPQRSTUVXYWZIO";

	c= s.value.substring(0,1);
	c= t.indexOf(c.toUpperCase());
	if(s.value.length!= 10) return "身份證號碼長度不足.\n";
	if(c<0) return "身份證號碼第一字不是英文.\n";
	else{
		n= parseInt(c/10)+ c%10*9+ 1;
		for(i=1; i<9; i++) n= n+ parseInt(s.value.substring(i,i+1))* (9-i);
		n= (10- (n% 10))% 10;
		if(n!= parseInt(s.value.substring(9,10))) return "身份證號資料錯誤.\n";
	}
	return "";
}

