function BMIcalc()
{
var varSinchou,varTaijyuu,varBMI;
varSinchou=window.document.frmBMI.Sinchou.value;
varSinchou=varSinchou/100;
varTaijyuu=window.document.frmBMI.Taijyuu.value;
varBMI=varTaijyuu/Math.pow(varSinchou,2);
varBMI=Math.round(varBMI*10)/10;
window.document.frmBMI.BMIresult.value=varBMI;
varTaijyuu=Math.round(varTaijyuu)
if (varBMI < 18){window.document.frmBMI.risouresult.value=varTaijyuu + 10;}
else if (varBMI >= 18 && varBMI <= 24){window.document.frmBMI.risouresult.value=varTaijyuu + 8;}
else {window.document.frmBMI.risouresult.value=varTaijyuu + 5;}
}
function BMIinit()
{
window.document.frmBMI.Sinchou.value="";
window.document.frmBMI.Taijyuu.value="";
window.document.frmBMI.BMIresult.value="";
window.document.frmBMI.risouresult.value="";
}

function bb(num){
	var today = new Date();
	var yyyy = today.getFullYear();
	var mm = today.getMonth()+1;
	var dd = today.getDate();
	var yobi = new Array("日","月","火","水","木","金","土");
	var yearbb = document.frmSample.selectOpty.value;
	var monthbb = document.frmSample.selectOptm.value;
	var datebb = document.frmSample.selectOptd.value;
	var n = 280;
	var m = 266;
	var fmt = "yyyy/m/d";
	if(document.frmSample.selectOpt1.value == 0){
		if(num == 0){
			cal(Keisan1(n,yearbb,monthbb,datebb,fmt));
		}
		else{
			n = n+ parseInt(document.frmSample.selectDays.options.value);
			cal(Keisan1(n,yearbb,monthbb,datebb,fmt));
		}
	}else{
		if(num == 0){
			cal(Keisan1(m,yearbb,monthbb,datebb,fmt));
		}
		
		else{
			m = m+ parseInt(document.frmSample.selectDays.options.value);
			cal(Keisan1(m,yearbb,monthbb,datebb,fmt));
		}
	}
}
function cal(n){
	today = new Date;
	var yearN;
	var monthN;
	var dateN;

	yearN = today.getFullYear();
	monthN = today.getMonth() + 1;
	dateN = today.getDate();
	
	a = n.split("/");
	document.frmSample.hidDummyY.value = a[0];
	document.frmSample.hidDummyM.value = a[1];
	document.frmSample.hidDummyD.value = a[2];
	dateChoise= new Date(a[0], a[1]-1, a[2]);
	
	var answer = Math.ceil((today.getTime()-(dateChoise.getTime()-(280*24*60*60*1000)))/(24*60*60*1000))-1;
	var month = answer /28+1;
	var week = answer / 7;
	var remain = answer % 7;
	month = parseInt(month);week= parseInt(week); remain = parseInt(remain);
	//document.frmSample.txtYotei.value =week+"weeks"+remain+"days";
	document.frmSample.txtMonths.value = month;
	document.frmSample.txtWeeks.value =week;
	document.frmSample.txtDays.value =remain;
	getDayInfo();
	document.frmSample.txtYoubiy.value = document.frmSample.hidDummy.value;
	//alert(document.frmSample.txtYeary.value +"年"+document.frmSample.hidDummyM.value+"月"+
	//document.frmSample.hidDummyD.value+"日"+document.frmSample.hidDummy.value);
}
function getDayInfo()
{
	aY = document.frmSample.hidDummyY.value;
	aM = document.frmSample.hidDummyM.value;
	aD = document.frmSample.hidDummyD.value;
	result = "";
	numStr = "0123456789";
	if ( ((aY >= 2000) && (aY < 2500)) && ((aM > 0) && (aM < 13)) && ((aD > 0) && (aD < 32)) )
	{
		dObj = new Date();
		dObj.setFullYear(aY);
		dObj.setMonth(aM - 1);
		dObj.setDate(aD);
		result = "日月火水木金土".charAt(dObj.getDay());
	}
	document.frmSample.hidDummy.value = result;
	document.frmSample.txtYeary.value = aY;
	document.frmSample.txtMonthy.value = aM;
	document.frmSample.txtDatey.value = aD;
}

function resetB() {
    if ( confirm ('リセットします。\nよろしければ[OK]を押してください。')) { 
		location.reload();
	}
	return false 
	}
function Keisan1(n,ybb,mbb,dbb,fmt){
	if (ybb == ""||mbb == ""||dbb == ""){
		alert("日付を記入してください。");
	}else{
		if (checkNum(parseInt(ybb),parseInt(mbb),parseInt(dbb))){ 
			var w = new Date(ybb+"/"+mbb+"/"+dbb);}
		else{
			alert("記入された日は正しくありません。半角数字であるか確認して、入力し直してください。");
		}
	}
	var cY = w.getFullYear();
	var cM = w.getMonth() + 1;
	var cD = w.getDate();
	return Keisan2(n,cY,cM,cD,fmt);
	
}
function Keisan2(n,cY,cM,cD,fmt){
	if (cY == ""||cM == ""||cD == ""){
		alert("日付を記入してください。");
	}else{
		if (checkNum(parseInt(cY),parseInt(cM),parseInt(cD))){ 
			var cDate = new Date(cY+"/"+cM+"/"+cD);}
		else{
			alert("記入された日は正しくありません。半角数字であるか確認して、入力し直してください。");
		}
	}
/*	if (fmt == "yyyy/m/d" || fmt == "yyyy/mm/dd" || fmt == "yyyymmdd"){
		wfmt = fmt;
	}else{
		wfmt = "yyyy/m/d";
	}*/

	var sec = n * 1000 * 60 * 60 * 24;
	var dateYotei = cDate.getTime();
	
	dateYotei += sec;
	cDate.setTime(dateYotei);
	
	var tYear = cDate.getFullYear();
	var tMonth = cDate.getMonth() + 1;
	var tDate = cDate.getDate();

	return (tYear + "/" + tMonth + "/" + tDate);
}

function checkNum(year,month,date){
	if(month >=1 && month <=12){
		if(date >=1 && date <=31)
		{
			if(month == 2 && date > 28)
			{
				return false;				
			}
			else if((month == 2 || month == 4 || month == 6 || month == 9 || month ==11) 
			&& date > 30)
			{
				return false;
			}
			else
			{ 
				return true;
			}
		}
		else
		{
			return false;
		}
	}else{
		return false;
	}
}
//****************************

menuItem = [	["5日","4日"],
			["7日",""],
			["7日",""] ];
itemNum = 2;	//　項目数
function setMenuItem(n)
{
	for (i=0; i<itemNum; i++)
	{
		document.frm.selectDay.options[i] = new Option(menuItem[n][i],menuItem[n][i]);
	}
	if(n == 0){
		getData2('name=futu');
		document.frm.txtJihi.value="";
		document.frm.txtTotal.value="";
		
	}
	else{
		getData2('name=teiou');
		document.frm.txtJihi.value="";
		document.frm.txtTotal.value="";

	}

	
}
function calCost(){//alert(document.frm.selectBunben.selectedIndex);
	var bunben = document.frm.selectBunben.selectedIndex;
	var room = document.frm.selectRoom.selectedIndex;
	var days = document.frm.selectDay.selectedIndex;
	
	if(bunben == 0){
		if(room ==0){//b
			if(days == 0){document.frm.hidDummy.value = 380000};//5     //000
			else{document.frm.hidDummy.value = 355000};//4   //001
			//else {alert("入院日数をお選び下さい。");}//002
		}
		if(room == 1){
			
			if(days == 0){document.frm.hidDummy.value = 395000};//010
			else{document.frm.hidDummy.value = 365000};//011
			//else {alert("入院日数をお選び下さい。");}//012
			

		}
		if(room == 2){
			if(days == 0){document.frm.hidDummy.value = 355000};//020
			else {document.frm.hidDummy.value = 335000};//021
			//else {alert("入院日数をお選び下さい。");}//022
		}
	}
	
	if(bunben == 1){
		if(room == 0){document.frm.hidDummy.value = 450000;}//10
		else if(room == 1){document.frm.hidDummy.value = 480000;}//11
		else {document.frm.hidDummy.value = 410000;}//12
	}
	
	document.frm.txtJihi.value = document.frm.hidDummy.value;
	if(document.frm.txtYoyakukin.value==0){
		document.frm.txtTotal.value = document.frm.txtJihi.value;
	}
	else{
		document.frm.txtTotal.value = document.frm.txtJihi.value - document.frm.txtYoyakukin.value;
	}
}

function change(n)
{
	
	if(n==0){
		getData1('name=broom');
		document.roomPic.src = "images/broom.jpg";
		document.frm.txtJihi.value="";
		document.frm.txtTotal.value="";
		
	}
	else if(n == 1){
		getData1('name=aroom');
		document.roomPic.src = "images/aroom.jpg";
		document.frm.txtJihi.value="";
		document.frm.txtTotal.value="";
		
	}
	else{
		getData1('name=4room');
		document.roomPic.src = "images/4room.jpg"; 
		document.frm.txtJihi.value="";
		document.frm.txtTotal.value="";
		
	}
	//document.roomPic.src = n+".gif";
}

function clear_cost()
{
	
	document.frm.txtJihi.value="";
	document.frm.txtTotal.value="";
}


function getData1(sentence)
{
	
	database.Filter =sentence;
	database.reset();
}

function getData2(sentence)
{
	
	database2.Filter =sentence;
	database2.reset();
}