//Mouseover
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

MM_reloadPage(true);

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

//Input
function Check() {

	cyear=document.form1.year.options[document.form1.year.selectedIndex].value;
	cmonth=document.form1.month.options[document.form1.month.selectedIndex].value;
	cday=document.form1.day.options[document.form1.day.selectedIndex].value;
	
	chour=document.form1.hour.options[document.form1.hour.selectedIndex].value;
	cminute=document.form1.minute.options[document.form1.minute.selectedIndex].value;
	
	if(chour == 99){
		chour = 0;
		cminute = 0;
		document.form1.knowtime.value = 2; //出生時間不明
		
	} else if ( cminute == 99 ){
		cminute = 0;
		document.form1.knowtime.value = 1; //出生時間あいまい
	} else {
		document.form1.knowtime.value = 0; //出生時間判明
	}
	if (IsTrueDate( cyear,cmonth,cday)==false || IsTrueBirthDay( cyear,cmonth,cday,chour,cminute)==false) {
		alert("あなたの生年月日が正しく入力されていません");
		return false;
	}

	
	return true;
}

function CheckPair() {

	if (!Check()) return false;
		
	cyear2=document.form1.year2.options[document.form1.year2.selectedIndex].value;
	cmonth2=document.form1.month2.options[document.form1.month2.selectedIndex].value;
	cday2=document.form1.day2.options[document.form1.day2.selectedIndex].value;
	
	chour2=document.form1.hour2.options[document.form1.hour2.selectedIndex].value;
	cminute2=document.form1.minute2.options[document.form1.minute2.selectedIndex].value;
	
	if(chour2 == 99){
		chour2 = 0;
		cminute2 = 0;
		document.form1.knowtime2.value = 2; //出生時間不明
		
	} else if ( cminute2 == 99 ){
		cminute = 0;
		document.form1.knowtime2.value = 1; //出生時間あいまい
	} else {
		document.form1.knowtime2.value = 0; //出生時間判明
	}
	if (IsTrueDate( cyear2,cmonth2,cday2)==false || IsTrueBirthDay( cyear2,cmonth2,cday2,chour2,cminute2)==false) {
		alert("お相手の生年月日が正しく入力されていません");
		return false;
	}
	

	return true;
}

function IsTrueDate(year,month,day)
{
	if (month==2 || month==4 || month==6 || month==9 || month==11 )
		if(day==31)	return false;
	
	if (month !=2 ) return true;

	if ( IsLeap(year) ==false )
	{
		if ( day==29 || day==30 || day==31 )
			return false;
	}
	else
	{
		if (day==30 || day==31 )
			return false;
	}
	return true;
}

function IsTrueBirthDay(year,month,day,hour,minute) {
// 未来の生年月日を入れてないか？
	today=new Date();
	inpDate=year+"/"+month+"/"+day+" "+hour+":"+minute;
	chkDate=Date.parse(inpDate);
	curDate=today.getTime();
	if (chkDate>curDate)
		return false;
	return true;
}

function IsLeap(year)
// 閏年かどうかのﾁｪｯｸをする
// ４で割り切れる年は閏年、但し１００で割れたら違う。ただし４００で割れたら閏年
{
	
	flag=false;
	y=eval(year);
	if (((y%4==0) && (y%100 !=0)) || (y%400==0)) 
		return true;
	else
		return false;
}

function preCheck(iPerson) {
	if (iPerson == 2) {
		if (CheckPair()) return true;
	} else {
		if (Check()) return true;
	}
	return false;
}
	
function senddata(iPerson){

	if (iPerson == 2) {
		if (CheckPair()) return true;
	} else {
		if (Check()) return true;
	}
	return false;
	/*
	if( preCheck(iPerson) ) {
		document.form1.submit();
	} else {
		return false;
	}
	*/
}
