var lunarInfo=new Array( 
0x04bd8,0x04ae0,0x0a570,0x054d5,0x0d260,0x0d950,0x16554,0x056a0,0x09ad0,0x055d2, 
0x04ae0,0x0a5b6,0x0a4d0,0x0d250,0x1d255,0x0b540,0x0d6a0,0x0ada2,0x095b0,0x14977, 
0x04970,0x0a4b0,0x0b4b5,0x06a50,0x06d40,0x1ab54,0x02b60,0x09570,0x052f2,0x04970, 
0x06566,0x0d4a0,0x0ea50,0x06e95,0x05ad0,0x02b60,0x186e3,0x092e0,0x1c8d7,0x0c950, 
0x0d4a0,0x1d8a6,0x0b550,0x056a0,0x1a5b4,0x025d0,0x092d0,0x0d2b2,0x0a950,0x0b557, 
0x06ca0,0x0b550,0x15355,0x04da0,0x0a5d0,0x14573,0x052b0,0x0a9a8,0x0e950,0x06aa0, 
0x0aea6,0x0ab50,0x04b60,0x0aae4,0x0a570,0x05260,0x0f263,0x0d950,0x05b57,0x056a0, 
0x096d0,0x04dd5,0x04ad0,0x0a4d0,0x0d4d4,0x0d250,0x0d558,0x0b540,0x0b5a0,0x195a6, 
0x095b0,0x049b0,0x0a974,0x0a4b0,0x0b27a,0x06a50,0x06d40,0x0af46,0x0ab60,0x09570, 
0x04af5,0x04970,0x064b0,0x074a3,0x0ea50,0x06b58,0x055c0,0x0ab60,0x096d5,0x092e0, 
0x0c960,0x0d954,0x0d4a0,0x0da50,0x07552,0x056a0,0x0abb7,0x025d0,0x092d0,0x0cab5, 
0x0a950,0x0b4a0,0x0baa4,0x0ad50,0x055d9,0x04ba0,0x0a5b0,0x15176,0x052b0,0x0a930, 
0x07954,0x06aa0,0x0ad50,0x05b52,0x04b60,0x0a6e6,0x0a4e0,0x0d260,0x0ea65,0x0d530, 
0x05aa0,0x076a3,0x096d0,0x04bd7,0x04ad0,0x0a4d0,0x1d0b6,0x0d250,0x0d520,0x0dd45, 
0x0b5a0,0x056d0,0x055b2,0x049b0,0x0a577,0x0a4b0,0x0aa50,0x1b255,0x06d20,0x0ada0, 
0x14b63); 


/***************************************************************************** 
                                      日期计算 
*****************************************************************************/ 

//====================================== 传回农历 y年的总天数 
function lYearDays(y) { 
   var i, sum = 348; 
   for(i=0x8000; i>0x8; i>>=1) sum += (lunarInfo[y-1900] & i)? 1: 0; 
   return(sum+leapDays(y)); 
} 

//====================================== 传回农历 y年闰月的天数 
function leapDays(y) { 
   if(leapMonth(y))  return((lunarInfo[y-1900] & 0x10000)? 30: 29); 
   else return(0); 
} 

//====================================== 传回农历 y年闰哪个月 1-12 , 没闰传回 0 
function leapMonth(y) { 
   return(lunarInfo[y-1900] & 0xf); 
} 

//====================================== 传回农历 y年m月的总天数 
function monthDays(y,m) { 
   return( (lunarInfo[y-1900] & (0x10000>>m))? 30: 29 ); 
} 


//====================================== 算出农历, 传入日期物件, 传回农历日期物件 
//                                       该物件属性有 .year .month .day .isLeap 
function Lunar(tempDate2) { 
   //objDate=new Date(tempDate2) 
   objDate=new Date(tempDate2) 
   var i, leap=0, temp=0; 
   var offset   = (Date.UTC(objDate.getFullYear(),objDate.getMonth(),objDate.getDate()) - Date.UTC(1900,0,31))/86400000; 

   for(i=1900; i<2050 && offset>0; i++) { temp=lYearDays(i); offset-=temp; } 

   if(offset<0) { offset+=temp; i--; } 

   this.year = i; 

   leap = leapMonth(i); //闰哪个月 
   this.isLeap = false; 

   for(i=1; i<13 && offset>0; i++) { 
      //闰月 
      if(leap>0 && i==(leap+1) && this.isLeap==false) 
         { --i; this.isLeap = true; temp = leapDays(this.year); } 
      else 
         { temp = monthDays(this.year, i); } 

      //解除闰月 
      if(this.isLeap==true && i==(leap+1)) this.isLeap = false; 

      offset -= temp; 
   } 

   if(offset==0 && leap>0 && i==leap+1) 
      if(this.isLeap) 
         { this.isLeap = false; } 
      else 
         { this.isLeap = true; --i; } 

   if(offset<0){ offset += temp; --i; } 
   this.month = i; 
   this.day = offset + 1; 
   nongligan=(this.year-1900)%10+7; 
   nongzhi=(this.year-1900)%12+1; 
   if (nongligan>10) nongligan=nongligan-10; 
   if (nongzhi>12) nongzhi=nongzhi-12; 
   document.najia.nongligan.value=nongligan; 
   document.najia.nongzhi.value=nongzhi; 
   document.najia.nongmonth.value=this.month; 
   document.najia.nongday.value= this.day; 
   if (this.isLeap) 
	document.najia.isLeap.value= "1"; 
   else 
   	document.najia.isLeap.value= "0"; 
}


var fangfa;
function DateDemo(){
   var d, s = "Today's date is: ";
   d = new Date();
   var c = ":";
 
   s += (d.getMonth() + 1) + "/";
   s += d.getDate() + "/";
   s += d.getYear() + "  ";

   s += d.getHours() + c;
   s += d.getMinutes() + c;
   s += d.getSeconds() + c;
   s += d.getMilliseconds();



   var tyear=d.getYear();
   for (i=0;i<=document.najia.sely.length-1;i++)
   {
	if ((document.all.sely.options[i].text*1)==(tyear*1))
		document.all.sely.selectedIndex=i;
   }

   var tmo=d.getMonth()+1;
   for (i=0;i<=document.najia.selmo.length-1;i++)
   {
	if ((document.all.selmo.options[i].text*1)==(tmo*1))
		document.all.selmo.selectedIndex=i;
   }

   var tdate=d.getDate();
   for (i=0;i<=document.najia.seld.length-1;i++)
   {
	if ((document.all.seld.options[i].text*1)==(tdate*1))
		document.all.seld.selectedIndex=i;
   }

   var th=d.getHours();
   for (i=0;i<=document.najia.selh.length-1;i++)
   {
	if ((document.all.selh.options[i].text*1)==(th*1))
		document.all.selh.selectedIndex=i;
   }

   var tm=d.getMinutes();
   for (i=0;i<=document.najia.selm.length-1;i++)
   {
	if ((document.all.selm.options[i].text*1)==(tm*1))
		document.all.selm.selectedIndex=i;
   }

   //alert(s);
   //return(s);
}
function getDate()
{

var temph=document.najia.selh.options[document.najia.selh.selectedIndex].text*1;
var tempy=document.najia.sely.options[document.najia.sely.selectedIndex].text*1;
var tempmo=document.najia.selmo.options[document.najia.selmo.selectedIndex].text*1;
var tempd=document.najia.seld.options[document.najia.seld.selectedIndex].text*1;
var ischanged=0;


if(document.najia.name.value=="")
{alert("请输入您的姓名。");
document.najia.name.focus();
return false;
}
if(document.najia.birthyear.value=="")
{alert("请选择您的出生时间");
document.najia.birthyear.focus();
return false;
}
if(document.najia.sex.value=="")
{alert("请选择您的性别");
document.najia.sex.focus();
return false;
}
if(document.najia.reason.value=="")
{alert("请输入你所需占事情");
document.najia.reason.focus();
return true;
}


if (((tempmo==4)||(tempmo==6)||(tempmo==9)||(tempmo==11))&&(tempd>30))
{
	alert("您输入的日期无效，请输入有效的日期！")	;
	return;
}

if (tempmo==2)	
{
	if ((tempy%4)==0)
	{
		if  (tempd>29)
		{
			alert("您输入的日期无效，请输入有效的日期！")	;
			return;
		}		
	}
	else
	{
		if  (tempd>28)
		{
			alert("您输入的日期无效，请输入有效的日期！")	;
			return;
		}
	}
}

if (fangfa==5)
{
	var tempnumber=document.najia.bsnums_up.value;
	if (tempnumber.length==0)
	{
		alert("请输入有效的整数");
		document.najia.bsnums_up.focus();
		return;
	}
	else
	{
		for (i=0;i<tempnumber.length;i++)
		{
			if ((tempnumber.charAt(i)!="1")&&(tempnumber.charAt(i)!="2")&&(tempnumber.charAt(i)!="3")&&(tempnumber.charAt(i)!="4")&&(tempnumber.charAt(i)!="5")&&(tempnumber.charAt(i)!="6")&&(tempnumber.charAt(i)!="7")&&(tempnumber.charAt(i)!="8")&&(tempnumber.charAt(i)!="9")&&(tempnumber.charAt(i)!="0"))
			{
				alert("请输入有效的整数");
				document.najia.bsnums_up.focus();
				return;
			}
		}
	}

	var tempnumber=document.najia.bsnums_down.value;
	if (tempnumber.length==0)
	{
		alert("请输入有效的整数");
		document.najia.bsnums_down.focus();
		return;
	}
	else
	{
		for (i=0;i<tempnumber.length;i++)
		{
			if ((tempnumber.charAt(i)!="1")&&(tempnumber.charAt(i)!="2")&&(tempnumber.charAt(i)!="3")&&(tempnumber.charAt(i)!="4")&&(tempnumber.charAt(i)!="5")&&(tempnumber.charAt(i)!="6")&&(tempnumber.charAt(i)!="7")&&(tempnumber.charAt(i)!="8")&&(tempnumber.charAt(i)!="9")&&(tempnumber.charAt(i)!="0"))
			{
				alert("请输入有效的整数");
				document.najia.bsnums_down.focus();
				return;
			}
		}
	}
}

if ( temph==23)
{
	 
	if ((tempmo==1)||(tempmo==3)||(tempmo==5)||(tempmo==7)||(tempmo==8)||(tempmo==10))
	{
			if  (tempd==31)
			{

				tempmo=tempmo+1;
				tempd=1;
			}		
			else
				tempd=tempd+1;
			 ischanged=1
	}	
          	
	if (( ischanged==0)&&((tempmo==4)||(tempmo==6)||(tempmo==9)||(tempmo==11)))
	{
			if  (tempd==30)
			{
				tempmo=tempmo+1;
				tempd=1;
			}		
			else
				tempd=tempd+1;
	}
	if (( ischanged==0)&&(tempmo==12))
	{
		if  (tempd==31)
		{
			tempmo=1;
			tempd=1;
			tempy=tempy+1;
		}		
		else
			tempd=tempd+1;
	}
	if (( ischanged==0)&&(tempmo==2))	
	{
		if ((tempy%4)==0)
		{
			if  (tempd==29)
			{
				tempmo=tempmo+1;
				tempd=1;
			}		
			else
				tempd=tempd+1;
		}
		else
		{
			if  (tempd==28)
			{
				tempmo=tempmo+1;
				tempd=1;
			}		
			else
				tempd=tempd+1;
		}
		
	}

}

	var tempdate=tempy+"/"+tempmo+ "/"+ tempd;
	//objDate=new Date(tempdate);
	Lunar(tempdate);
	document.najia.submit();
}


var times=0;    
var yao=0;    
function yaogua(ok)
         
{  if(document.najia.b1.value=='停 止')
   ok=0;
   if(times==0)
   document.najia.b1.value="第一次";
   if(ok!=0)
    document.najia.b1.value='停 止';
	if(times==6)
	{document.najia.b1.value='第一次';
	}
	if (ok==1)				//开始摇     
	{     
		times++;     
		document.q1.src="./img/qian/qian2.gif"
		document.q2.src="./img/qian/qian2.gif"
		document.q3.src="./img/qian/qian2.gif"
	}	     
	else					//停止     
	{     
		document.q1.src="./img/qian/qian3.gif"
		document.q2.src="./img/qian/qian3.gif"
		document.q3.src="./img/qian/qian3.gif"
		yao1 = Math.round(Math.random());   
		yao2 = Math.round(Math.random());   
		yao3 = Math.round(Math.random());		   
		if (yao1+yao2+yao3==0)   
			yao=3;   
		else if (yao1+yao2+yao3==1)   
			yao=0;   
		else if (yao1+yao2+yao3==2)   
			yao=1;   
		else if (yao1+yao2+yao3==3)   
			yao=2;				   
		switch(times)     
		{     
			case 1:     
				document.najia.Y1.options[yao].selected=true;    
				document.najia.b1.value="第二次"    
				break;     
			case 2:     
				document.najia.Y2.options[yao].selected=true;     
				document.najia.b1.value="第三次"				   
				break;     
			case 3:     
				document.najia.Y3.options[yao].selected=true;     
				document.najia.b1.value="第四次"				   
				break;     
			case 4:     
				document.najia.Y4.options[yao].selected=true;     
				document.najia.b1.value="第五次"				   
				break;     
			case 5:     
				document.najia.Y5.options[yao].selected=true;     
				document.najia.b1.value="第六次"   
				break;     
			case 6:     
				document.najia.Y6.options[yao].selected=true;     
				document.getElementById('yg2').style.display='none';    
				break;			     
		}    
		if (times>=6) times=0;     
	}	     
	return true;     
}