// JavaScript Document

function parseInt0(s)
{
	if (s.value=''){return 0;}
	else{parseInt(s);}
}


function Age(n,y,m,d){
	
	if (n == 0){birthyear = y + 1988;}
	if (n == 1){birthyear = y + 1925;}
	if (n == 2){birthyear = y + 1911;}
	
	today = new Date();
	thisyear = today.getYear();
	
	if(m>=4){
		a = thisyear - birthyear -1;
		}
	else{
		a = thisyear - birthyear;
	}
	return a;
}


function setcost(A,R1,R2,R3,R4,R5,C){
	
	var costs = new Array(5);
	for(j = 0; j <= 5; j++){ 
		costs[j] = new Array(22); 
	}
	
	costs[0][0]  = 0;
	costs[0][1]  = 0;
	costs[0][2]  = 0;
	costs[0][3]  = 23;
	costs[0][4]  = 22;
	costs[0][5]  = 28;
	costs[0][6]  = 35;
	costs[0][7]  = 27;
	costs[0][8]  = 29;
	costs[0][9]  = 32;
	costs[0][10] = 36;
	costs[0][11] = 41;
	costs[0][12] = 48;
	costs[0][13] = 40;
	costs[0][14] = 53;
	costs[0][15] = 59;
	costs[0][16] = 49;
	costs[0][17] = 48;
	costs[0][18] = 197;
	costs[0][19] = 107;
	costs[0][20] = 107;
	costs[0][21] = 107;
	
	costs[1][0]  = 0;
	costs[1][1]  = 0;
	costs[1][2]  = 0;
	costs[1][3]  = 52;
	costs[1][4]  = 51;
	costs[1][5]  = 58;
	costs[1][6]  = 168;
	costs[1][7]  = 114;
	costs[1][8]  = 123;
	costs[1][9]  = 129;
	costs[1][10] = 141;
	costs[1][11] = 148;
	costs[1][12] = 153;
	costs[1][13] = 108;
	costs[1][14] = 119;
	costs[1][15] = 127;
	costs[1][16] = 91;
	costs[1][17] = 94;
	costs[1][18] = 242;
	costs[1][19] = 143;
	costs[1][20] = 143;
	costs[1][21] = 143;
	
	costs[2][0]  = 0;
	costs[2][1]  = 0;
	costs[2][2]  = 0;
	costs[2][3]  = 0;
	costs[2][4]  = 0;
	costs[2][5]  = 0;
	costs[2][6]  = 0;
	costs[2][7]  = 0;
	costs[2][8]  = 0;
	costs[2][9]  = 0;
	costs[2][10] = 0;
	costs[2][11] = 0;
	costs[2][12] = 0;
	costs[2][13] = 0;
	costs[2][14] = 0;
	costs[2][15] = 0;
	costs[2][16] = 0;
	costs[2][17] = 0;
	costs[2][18] = 282;
	costs[2][19] = 182;
	costs[2][20] = 182;
	costs[2][21] = 182;
	
	costs[3][0]  = 0;
	costs[3][1]  = 0;
	costs[3][2]  = 0;
	costs[3][3]  = 0;
	costs[3][4]  = 0;
	costs[3][5]  = 0;
	costs[3][6]  = 0;
	costs[3][7]  = 0;
	costs[3][8]  = 0;
	costs[3][9]  = 0;
	costs[3][10] = 0;
	costs[3][11] = 0;
	costs[3][12] = 0;
	costs[3][13] = 0;
	costs[3][14] = 0;
	costs[3][15] = 0;
	costs[3][16] = 0;
	costs[3][17] = 0;
	costs[3][18] = 231;
	costs[3][19] = 141;
	costs[3][20] = 0;
	costs[3][21] = 0;
	
	costs[4][0]  = 0;
	costs[4][1]  = 0;
	costs[4][2]  = 0;
	costs[4][3]  = 0;
	costs[4][4]  = 0;
	costs[4][5]  = 0;
	costs[4][6]  = 0;
	costs[4][7]  = 0;
	costs[4][8]  = 0;
	costs[4][9]  = 0;
	costs[4][10] = 0;
	costs[4][11] = 0;
	costs[4][12] = 0;
	costs[4][13] = 0;
	costs[4][14] = 0;
	costs[4][15] = 0;
	costs[4][16] = 0;
	costs[4][17] = 0;
	costs[4][18] = 231;
	costs[4][19] = 147;
	costs[4][20] = 0;
	costs[4][21] = 0;


		
	//自宅外
	Outside　= new Array(4);
		Outside[0] = 153;
		Outside[1] = 104;
		Outside[2] = 104;
		Outside[3] = 104;
		
	var Y = A;
	if (Y < 6){var X = R1;}
	else if (Y < 12){var X = R5;}
	else if (Y < 14){var X = R2;}
	else if (Y < 18){var X = R3;}
	else {var X = R4;}
	
	if ((C ==1)&&(Y>=18))
	{
		if ((X<2)||(Y<20)){R = costs[X][Y]+Outside[Y-18];}
	}
	else {R = costs[X][Y];}
	
	return R;
	
}



function disp(){
	//西暦
	today = new Date();
	thisyear = today.getYear();
	for (i=0;i<25;i++)
	{
		var year = thisyear + i;
		Costs.rows[1].cells[i + 2].innerText = year;
	}
	
	//父の年令
	var FatherN = document.F1.nengo.selectedIndex;
	var FatherY = parseInt(document.F1.year.value);
	var FatherM = document.F1.month.selectedIndex+1;
	var FatherD = document.F1.day.selectedIndex+1;
	var FatherA = Age(FatherN,FatherY,FatherM,FatherD);
	
	for (i=0;i<25;i++)
	{
		Costs.rows[2].cells[i + 2].innerText = FatherA + i;
	}
	
	//母の年令
	var MotherN = document.F2.nengo.selectedIndex;
	var MotherY = parseInt(document.F2.year.value);
	var MotherM = document.F2.month.selectedIndex+1;
	var MotherD = document.F2.day.selectedIndex+1;
	var MotherA = Age(MotherN,MotherY,MotherM,MotherD);
	

	for (i=0;i<25;i++)
	{ 
		Costs.rows[3].cells[i + 2].innerText = MotherA + i;
		
	}
	

	
 	//子1
	if (document.F3.C1.checked){
	var Child1N = document.F3.nengo.selectedIndex;
	var Child1Y = parseInt(document.F3.year.value);
	var Child1M = document.F3.month.selectedIndex+1;
	var Child1D = document.F3.day.selectedIndex+1;
	var Child1A = Age(Child1N,Child1Y,Child1M,Child1D);
	
		if (document.F3.R1[0].checked) {var FR1 = 0;}
			else						{var FR1 = 1;}
			
		if (document.F3.R5[0].checked) {var FR5 = 0;}
			else						{var FR5 = 1;}
			
		if (document.F3.R2[0].checked) {var FR2 = 0;}
			else						{var FR2 = 1;}
			
		if (document.F3.R3[0].checked) {var FR3 = 0;}
			else						{var FR3 = 1;}
		
		if (document.F3.R4[0].checked) 		 {var FR4 = 0;}
		else if (document.F3.R4[1].checked) {var FR4 = 1;}
		else if (document.F3.R4[2].checked) {var FR4 = 2;}
		else if (document.F3.R4[3].checked) {var FR4 = 3;}
		else 								 {var FR4 = 4;}
		
		
		if (document.F3.C2.checked){var FC = 1;}
		else {var FC = 0;}
	
	var SumCost = 0;
	
	for (i=0;i<25;i++)
	{
		FA = Child1A + i;
		if(FA<0){FA=0;}
		Costs.rows[4].cells[i + 2].innerText = FA;
		
		if (FR4 > 2){Amax = 19;}
		else {Amax = 21;}
		
		if (FA <= Amax){
			Costs.rows[5].cells[i + 2].innerText = setcost(FA,FR1,FR2,FR3,FR4,FR5,FC);
			}
		else {Costs.rows[5].cells[i + 2].innerText = 0;}
		
		SumCost = SumCost + parseInt(Costs.rows[5].cells[i + 2].innerText);
			
	}
		Costs.rows[5].cells[27].innerText = SumCost;
	}
	
	
	//子2
	if (document.F4.C1.checked){
	var Child2N = document.F4.nengo.selectedIndex;
	var Child2Y = parseInt(document.F4.year.value);
	var Child2M = document.F4.month.selectedIndex+1;
	var Child2D = document.F4.day.selectedIndex+1;
	var Child2A = Age(Child2N,Child2Y,Child2M,Child2D);
	
		if (document.F4.R1[0].checked) {var FR1 = 0;}
			else						{var FR1 = 1;}
			
		if (document.F4.R5[0].checked) {var FR5 = 0;}
			else						{var FR5 = 1;}
			
		if (document.F4.R2[0].checked) {var FR2 = 0;}
			else						{var FR2 = 1;}
			
		if (document.F4.R3[0].checked) {var FR3 = 0;}
			else						{var FR3 = 1;}
		
		if (document.F4.R4[0].checked) 		 {var FR4 = 0;}
		else if (document.F4.R4[1].checked) {var FR4 = 1;}
		else if (document.F4.R4[2].checked) {var FR4 = 2;}
		else if (document.F4.R4[3].checked) {var FR4 = 3;}
		else 								 {var FR4 = 4;}
		
		
		if (document.F4.C2.checked){var FC = 1;}
		else {var FC = 0;}
	
	var SumCost = 0;
	
	for (i=0;i<25;i++)
	{
		FA = Child2A + i;
		if(FA<0){FA=0;}
		Costs.rows[6].cells[i + 2].innerText = FA;
		
		if (FR4 > 2){Amax = 19;}
		else {Amax = 21;}
		
		if (FA <= Amax){
			Costs.rows[7].cells[i + 2].innerText = setcost(FA,FR1,FR2,FR3,FR4,FR5,FC);
			}
		else {Costs.rows[7].cells[i + 2].innerText = 0;}
		
		SumCost = SumCost + parseInt(Costs.rows[7].cells[i + 2].innerText);
			
	}
		Costs.rows[7].cells[27].innerText = SumCost;
	}
	
	//子3
	if (document.F5.C1.checked){
	var Child3N = document.F5.nengo.selectedIndex;
	var Child3Y = parseInt(document.F5.year.value);
	var Child3M = document.F5.month.selectedIndex+1;
	var Child3D = document.F5.day.selectedIndex+1;
	var Child3A = Age(Child3N,Child3Y,Child3M,Child3D);
	
		if (document.F5.R1[0].checked) {var FR1 = 0;}
			else						{var FR1 = 1;}
			
		if (document.F5.R5[0].checked) {var FR5 = 0;}
			else						{var FR5 = 1;}
			
		if (document.F5.R2[0].checked) {var FR2 = 0;}
			else						{var FR2 = 1;}
			
		if (document.F5.R3[0].checked) {var FR3 = 0;}
			else						{var FR3 = 1;}
		
		if (document.F5.R4[0].checked) 		 {var FR4 = 0;}
		else if (document.F5.R4[1].checked) {var FR4 = 1;}
		else if (document.F5.R4[2].checked) {var FR4 = 2;}
		else if (document.F5.R4[3].checked) {var FR4 = 3;}
		else 								 {var FR4 = 4;}
		
		
		if (document.F5.C2.checked){var FC = 1;}
		else {var FC = 0;}
	
	var SumCost = 0;
	
	for (i=0;i<25;i++)
	{
		FA = Child3A + i;
		if(FA<0){FA=0;}
		Costs.rows[8].cells[i + 2].innerText = FA;
		
		if (FR4 > 2){Amax = 19;}
		else {Amax = 21;}
		
		if (FA <= Amax){
			Costs.rows[9].cells[i + 2].innerText = setcost(FA,FR1,FR2,FR3,FR4,FR5,FC);
			}
		else {Costs.rows[9].cells[i + 2].innerText = 0;}
		
		SumCost = SumCost + parseInt(Costs.rows[9].cells[i + 2].innerText);
			
	}
		Costs.rows[9].cells[27].innerText = SumCost;
	}
	
	maxCost =0;
	
	for (i=0;i<25;i++)
	{
		Costs.rows[10].cells[i + 2].innerText = (Costs.rows[5].cells[i + 2].innerText-0)
												+(Costs.rows[7].cells[i + 2].innerText-0)
												+(Costs.rows[9].cells[i + 2].innerText-0);
		maxCost = Math.max((Costs.rows[10].cells[i + 2].innerText-0),maxCost);
	}
	
	Costs.rows[10].cells[27].innerText = (Costs.rows[5].cells[27].innerText-0)
												+(Costs.rows[7].cells[27].innerText-0)
												+(Costs.rows[9].cells[27].innerText-0);
												
	maxCost = Math.ceil(maxCost*0.1)*10;
		
	Costs.rows[0].cells[1].innerHTML ='<TABLE><TR valign=bottom><TD>'+maxCost+'</TD><TD><img src="L.gif" WIDTH=20 HEIGHT=2/></TD></TR><TR valign=bottom><TD></TD><TD><div align="right"><img src="L.gif" WIDTH=2 HEIGHT=123/></div></TD></TR><TR valign=bottom><TD>'+maxCost/2+'</TD><TD><img src="L.gif" WIDTH=20 HEIGHT=2/></TD></TR><TR valign=bottom><TD></TD><TD><div align="right"><img src="L.gif" WIDTH=2 HEIGHT=123/></div></TD></TR><TR valign=bottom><TD>0</TD><TD><img src="L.gif" WIDTH=20 HEIGHT=2/></TD></TR>';
										
	for (i=0;i<25;i++)
	{
		GY1 = Math.floor((Costs.rows[5].cells[i + 2].innerText-0)/maxCost*300);
		GY2 = Math.floor((Costs.rows[7].cells[i + 2].innerText-0)/maxCost*300);
		GY3 = Math.floor((Costs.rows[9].cells[i + 2].innerText-0)/maxCost*300);
		SUM = (Costs.rows[10].cells[i + 2].innerText-0)
		Costs.rows[0].cells[i + 2].innerHTML =''+SUM+'<br/><img src="C3.gif"WIDTH=30 HEIGHT='+GY3+'/><br/><img src="C2.gif"WIDTH=30 HEIGHT='+GY2+'/><br/><img src="C1.gif"WIDTH=30 HEIGHT='+GY1+'/><br/>';
	}
	
}
