/* 
　JRAのフォーメーション組み合わせ計算スクリプトです。
　このスクリプトを使いたい方はご自由にどうぞ。
　ただ、このコメント欄は変更禁止とします。
　ぶるばか(http://www5a.biglobe.ne.jp/~rintarou/burubaka/)
　NATURE's WORLD(http://neon.cside4.com/)
*/

function calcFormation(){
	var trifecta   = 0;
	var exacta     = 0;
	var quinella   = 0;
	var trio       = 0;
	var new_trio   = 0;
	var trio_sort  = 0;
	var trio_array = new Array(1);
	
	for(i=0;i<document.f.oneCal.length;i++){
		if(document.f.oneCal[i].checked){
			for(j=0;j<document.f.twoCal.length;j++){
				if(document.f.twoCal[j].checked
				&& document.f.oneCal[i].value != document.f.twoCal[j].value){
					exacta++;
					
					if(document.f.oneCal[i].value < document.f.twoCal[j].value){
						quinella++;
					}
					else if(!document.f.oneCal[j].checked){
						quinella++;
					}
					else if(!document.f.twoCal[i].checked){
						quinella++;
					}
					
					for(k=0;k<document.f.threeCal.length;k++){
						if(document.f.threeCal[k].checked
						&& document.f.oneCal[i].value != document.f.threeCal[k].value
						&& document.f.twoCal[j].value != document.f.threeCal[k].value){
							trifecta++;
							
							trio_sort = new Array(document.f.oneCal[i].value,document.f.twoCal[j].value,document.f.threeCal[k].value);
							trio_sort = trio_sort.sort();
							var trio_value = trio_sort[0] + trio_sort[1] + trio_sort[2];
							
							for(l=0;l<trio_array.length;l++){
								if(trio_array[l] == trio_value){
									new_trio++;
								}
							}
							
							if(!new_trio){
								trio++;
								trio_array.push(trio_value);
							}
							new_trio = 0;
						}
					}
				}
			}
		}
	}
	
	document.f.txtQuinella.value  = quinella;
	document.f.txtExacta.value    = exacta;
	document.f.txtTrio.value      = trio;
	document.f.txtTrifecta.value  = trifecta;

}
