function resetB() {
    if ( confirm ('リセットします。\nよろしければ[OK]を押してください。')) { 
		location.reload();
	}
	return false 
	}
	
	
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 = 13 + parseInt(document.frmSample.selectDays.options.value);
	var n2 = 14 + parseInt(document.frmSample.selectDays.options.value);
	
	var fmt = "yyyy/m/d";
	
	cal(Keisan1(n,yearbb,monthbb,datebb,fmt));
	cal2(Keisan1(n2,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 year = answer /28+1;
	var month = answer /28+1;
	var week = answer / 7;
	var remain = answer % 7;

	month = parseInt(month);week= parseInt(week); remain = parseInt(remain);
	getDayInfo();
	
	document.frmSample.txtweek1.value = document.frmSample.hidDummy.value;
	document.frmSample.txtYear1.value =  document.frmSample.hidDummyY.value;
	document.frmSample.txtMonthy1.value = document.frmSample.hidDummyM.value;
	document.frmSample.txtDay1.value = document.frmSample.hidDummyD.value;

}

function cal2(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 year = answer /28+1;
	var month = answer /28+1;
	var week = answer / 7;
	var remain = answer % 7;

	month = parseInt(month);week= parseInt(week); remain = parseInt(remain);
	getDayInfo();
	document.frmSample.txtweek2.value = document.frmSample.hidDummy.value;
	
	document.frmSample.txtMonthy2.value = document.frmSample.hidDummyM.value;
	document.frmSample.txtDay2.value = document.frmSample.hidDummyD.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;
}

function Keisan1(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("記入された日は正しくありません。半角数字であるか確認して、入力し直してください。");
		}
	}

	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;
	}
}
