//é“¶è¡Œå¡å·æ ¡éªŒ
//Description: é“¶è¡Œå¡å·Luhmæ ¡éªŒ
//Luhmæ ¡éªŒè§„åˆ™ï¼š16ä½é“¶è¡Œå¡å·ï¼ˆ19ä½é€šç”¨ï¼‰:
// 1.å°†æœªå¸¦æ ¡éªŒä½çš„ 15ï¼ˆæˆ–18ï¼‰ä½å¡å·ä»Žå³ä¾æ¬¡ç¼–å· 1 åˆ° 15ï¼ˆ18ï¼‰ï¼Œä½äºŽå¥‡æ•°ä½å·ä¸Šçš„æ•°å­—ä¹˜ä»¥ 2ã€‚
// 2.å°†å¥‡ä½ä¹˜ç§¯çš„ä¸ªåä½å…¨éƒ¨ç›¸åŠ ï¼Œå†åŠ ä¸Šæ‰€æœ‰å¶æ•°ä½ä¸Šçš„æ•°å­—ã€‚
// 3.å°†åŠ æ³•å’ŒåŠ ä¸Šæ ¡éªŒä½èƒ½è¢« 10 æ•´é™¤ã€‚
function luhmCheck(bankno){
	if (bankno.length < 15 && bankno.length > 20) {
		//$("#banknoInfo").html("é“¶è¡Œå¡å·é•¿åº¦å¿…é¡»åœ¨16åˆ°19ä¹‹é—´");
		return false;
	}
	var num = /^\d*$/; //å…¨æ•°å­—
	if (!num.exec(bankno)) {
		//$("#banknoInfo").html("é“¶è¡Œå¡å·å¿…é¡»å…¨ä¸ºæ•°å­—");
		return false;
	}
	//å¼€å¤´6ä½
	var strBin="10,18,30,35,37,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,58,60,62,65,68,69,84,87,88,94,95,98,99";
	if (strBin.indexOf(bankno.substring(0,2))== -1) {
		//$("#banknoInfo").html("é“¶è¡Œå¡å·å¼€å¤´6ä½ä¸ç¬¦åˆè§„èŒƒ");
		return false;
	}
	var lastNum=bankno.substr(bankno.length-1,1);//å–å‡ºæœ€åŽä¸€ä½ï¼ˆä¸Žluhmè¿›è¡Œæ¯”è¾ƒï¼‰
	var first15Num=bankno.substr(0,bankno.length-1);//å‰15æˆ–18ä½
	var newArr=new Array();
	for(var i=first15Num.length-1;i>-1;i--){ //å‰15æˆ–18ä½å€’åºå­˜è¿›æ•°ç»„
		newArr.push(first15Num.substr(i,1));
	}
	var arrJiShu=new Array(); //å¥‡æ•°ä½*2çš„ç§¯ <9
	var arrJiShu2=new Array(); //å¥‡æ•°ä½*2çš„ç§¯ >9
	var arrOuShu=new Array(); //å¶æ•°ä½æ•°ç»„
	for(var j=0;j<newArr.length;j++){
		if((j+1)%2==1){//å¥‡æ•°ä½
			if(parseInt(newArr[j])*2<9){
				arrJiShu.push(parseInt(newArr[j])*2);
			}else{
				arrJiShu2.push(parseInt(newArr[j])*2);
			}
		}else{ //å¶æ•°ä½
		arrOuShu.push(newArr[j]);
		}
    }
	var jishu_child1=new Array(); //å¥‡æ•°ä½*2 >9 çš„åˆ†å‰²ä¹‹åŽçš„æ•°ç»„ä¸ªä½æ•°
	var jishu_child2=new Array(); //å¥‡æ•°ä½*2 >9 çš„åˆ†å‰²ä¹‹åŽçš„æ•°ç»„åä½æ•°
	for(var h=0;h<arrJiShu2.length;h++){
		jishu_child1.push(parseInt(arrJiShu2[h])%10);
		jishu_child2.push(parseInt(arrJiShu2[h])/10);
	}
	var sumJiShu=0; //å¥‡æ•°ä½*2 < 9 çš„æ•°ç»„ä¹‹å’Œ
	var sumOuShu=0; //å¶æ•°ä½æ•°ç»„ä¹‹å’Œ
	var sumJiShuChild1=0; //å¥‡æ•°ä½*2 >9 çš„åˆ†å‰²ä¹‹åŽçš„æ•°ç»„ä¸ªä½æ•°ä¹‹å’Œ
	var sumJiShuChild2=0; //å¥‡æ•°ä½*2 >9 çš„åˆ†å‰²ä¹‹åŽçš„æ•°ç»„åä½æ•°ä¹‹å’Œ
	var sumTotal=0;
	for(var m=0;m<arrJiShu.length;m++){
		sumJiShu=sumJiShu+parseInt(arrJiShu[m]);
	}
	for(var n=0;n<arrOuShu.length;n++){
		sumOuShu=sumOuShu+parseInt(arrOuShu[n]);
	}
	for(var p=0;p<jishu_child1.length;p++){
		sumJiShuChild1=sumJiShuChild1+parseInt(jishu_child1[p]);
		sumJiShuChild2=sumJiShuChild2+parseInt(jishu_child2[p]);
	}
	//è®¡ç®—æ€»å’Œ
	sumTotal=parseInt(sumJiShu)+parseInt(sumOuShu)+parseInt(sumJiShuChild1)+parseInt(sumJiShuChild2);
	//è®¡ç®—Luhmå€¼
	var k= parseInt(sumTotal)%10==0?10:parseInt(sumTotal)%10;
	var luhm= 10-k;
	if(lastNum==luhm){
		//$("#banknoInfo").html("LuhméªŒè¯é€šè¿‡");
		return true;
	}
	else{
		//$("#banknoInfo").html("é“¶è¡Œå¡å·å¿…é¡»ç¬¦åˆLuhmæ ¡éªŒ");
		return false;
	}
}                    
