// check number value
function CheckNumValue(p_str,p_value){
	var checkOK = p_value;
	var checkStr = p_str;
	var allValid = true;
	var decPoints = 0;
	for(i=0;i<checkStr.length;i++){
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++){
			if (ch == checkOK.charAt(j)){
				break;
			}
		}
		if (j == checkOK.length){
			allValid = false;
			break;
		}
	}
	if (!allValid){
		return false;
	}else{
		return true;
	}
}

// check member ID format
function CheckIDValue(p_id){
	var score_i=0,score_c=0;
	var l_str='abcdefghijklmnopqrstuvwxyz0123456789';
	for (var i=0;i<p_id.length;i++)	{
    		if (l_str.indexOf(p_id.charAt(i),0)>=0){
    			score_c+=1;
    		}
	}
	if (score_c == p_id.length){
		return true;
	}else{
		return false;
	}
}

// check password
function CheckPasswdValue(p_password){
	var score_i=0,score_c=0;
	var l_int='0123456789';
	var l_str='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
	p_password=p_password.toLowerCase();
	for (var i = 0;  i < p_password.length;  i++){
    		if (l_int.indexOf(p_password.charAt(i),0)>=0){
    			score_i+=1;
    		}else if (l_str.indexOf(p_password.charAt(i),0)>=0){
    			score_c+=1;
    		}
 	}
	if (score_c >=2 && score_i >=2){
		return true;
	}else{
		return false;
	}
}

// check Person ID
function CheckPIDValue(p_cid){
	p_cid=p_cid.toUpperCase();
	var l_idstr='          ABCDEFGHJKLMNPQRSTUVXYWZIO' ;
	var n=0;
	var tot1 = Math.floor((l_idstr.indexOf(p_cid.charAt(0),0)+0)/10) + ((parseFloat(l_idstr.indexOf(p_cid.charAt(0),0)+0)%10) * 9);
	var tot2 = 0;
	for(i=1;i<p_cid.length-1;i++){
		tot2 = tot2 + p_cid.charAt(i)*(9-i);
	}
	var tot3 = parseFloat(p_cid.charAt(9));
	var tot4 = tot1 + tot2 + tot3;
	if((tot4 % 10)!=0){
		return false;
	}else{
		return true;
	}
}

// check date format
function IsDate(p_Year,p_Month,p_Day){
	var l_LegalDay = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
	var Current_Date = new Date();
	var l_Month = Current_Date.getMonth();
	var l_Year = Current_Date.getYear();
	var l_Day=Current_Date.getDate();

	if (!CheckNumValue(p_Year,"0123456789")) return false;
	if (!CheckNumValue(p_Month,"0123456789")) return false;
	if (!CheckNumValue(p_Day,"0123456789")) return false;

	if ((p_Year % 400 == 0) || ((p_Year % 4 == 0) && (p_Year % 100 != 0))) l_LegalDay[1] = 29;
	if (p_Month > 12 || p_Month < 1 )  return false;
	if (p_Day > l_LegalDay[p_Month-1]  || p_Day < 1 )  return false;
	return true;
}

//判斷E-Mail格式是否正確
function CheckMailValue(p_str){
	var checkStr = p_str;
	for (i = 0;  i < checkStr.length;  i++)	{
    		if (checkStr.charAt(i)=="@") return true;
 	}
	return false;
}