var daysinmonth=new Array(31,28,31,30,31,30,31,31,30,31,30,31);

function getDays(month,year){
	if(2==month){
		return ((0 == year % 4) && (0 != (year % 100))) || (0 == year % 400) ? 29 : 28;
	}else{
		return daysinmonth[month-1];
	}
}
function addpestname(res1,res2)
{
  res2.value=res1.value;
}
function next()
{
 addresult();
 if(event.keyCode==13)event.keyCode=9;
 
}
function add(res1,res2,res)
{
   i=Math.abs(res1.value);
   j=Math.abs(res2.value);
   res.value=i+j;
}
function addresult()
{
  add(form1.field2,form1.field3,form1.field4);
  add(form1.field5,form1.field6,form1.field7);
}
function avg(res1,res2,res)
{
   i=Math.abs(res1.value);
   j=Math.abs(res2.value);
   res.value=(i+j)/2;
}



function getRegionid(regionres,res1,cityres,res2)
{
	 var r;
	 var c;
	 
	 r=regionres.options[regionres.selectedIndex].id;
	 c=cityres.options[cityres.selectedIndex].id;
	 //alert(r);
	 //alert(c);
	 res1.value=r;
	 res2.value=c;
}


function addnew(res,text,value,id){
	var el =document.createElement("OPTION");
	el.text=text;
	el.value=value;
	el.id=id;
	res.options.add(el);
}
function delitem(el){
	var len_op=el.options.length;
	for (var intloop=0;intloop<len_op;intloop++){
		el.options.remove(0);
	}
}

function initRegionItem(res1,res2)
{
	putRegionItem(res1);
	putCityItem(res2,0);
	
}
function putRegionItem(res)
{
	delitem(res);
	region=new Array("??????????","??????????","??????????","????????","??????????","????????","??????????????","??????","????????","????????","??????????","??????????????????","??????????????????","??????????","??????????????????????","????????","????????");
	
	for(var i in region)
	{
		addnew(res,region[i],region[i],i);
	}
	
}
function putCityItem(res,id)
{
	
	
	delitem(res);
	city=new Array(17);
	v=new Array(17);
	
   city[0]=new Array("????????");
	v[0]=new Array("00");
	city[1]=new Array("??????","??????????");
	v[1]=new Array("00","01");
	city[2]=new Array("??????");
	v[2]=new Array("00");
	city[3]=new Array("??????");
	v[3]=new Array("00");
	city[4]=new Array("??????","????????","??????","????????");
	v[4]=new Array("00","01","02","03");
	city[5]=new Array("??????","??????","??????","??????????????????");
	v[5]=new Array("00","01","02","03");
	city[6]=new Array("??????","??????","??????","??????","????????","????????","??????","??????????","????????????????");
	v[6]=new Array("00","01","02","03","04","05","06","07","08");
	city[7]=new Array("??????");
	v[7]=new Array("00");
	city[8]=new Array("??????","??????","??????","??????????????????","??????","??????","??????","??????","????????","????????");
	v[8]=new Array("00","01","02","03","04","05","06","07","08","09");
	city[9]=new Array("??????","??????","??????","??????","??????","??????","??????","????????????????????");
	v[9]=new Array("00","01","02","03","04","05","06","07");
    city[10]=new Array("??????","????????","????????","??????","??????","??????","??????","????????");
	v[10]=new Array("00","01","02","03","04","05","06","07");
	city[11]=new Array("??????","??????","??????","??????");
	v[11]=new Array("00","01","02","03");
	city[12]=new Array("??????","????????","??????","??????","??????","??????","??????????????","??????","??????","??????");
	v[12]=new Array("00","01","02","03","04","05","06","07","08","09");
	city[13]=new Array("??????","????????","??????","??????","??????","??????","??????","??????","????????","??????");
	v[13]=new Array("00","01","02","03","04","05","06","07","08","09");
	city[14]=new Array("??????","????????","????????","????????","??????");
	v[14]=new Array("00","01","02","03","04");
    city[15]=new Array("??????","??????","??????","??????","????????","??????","??????","??????","????????","????????","??????","??????","??????????????????????");
	v[15]=new Array("00","01","02","03","04","05","06","07","08","09","10","11","12");
	city[16]=new Array("??????","??????","??????","??????","??????","??????","??????","??????","??????");
	v[16]=new Array("00","01","02","03","04","05","06","07","08");
	
   c=city[id];
	vv=v[id];
	for (var j in c)
	{
		addnew(document.form1.cityname,c[j],c[j],vv[j]);
		
	}
	
}
function putYear(res)
{
	delitem(res);
	var d=new Date();
	year=d.getYear();
	addnew(res,year,year,year);
	for (var i=2006;i>=2004;i--)
	{
		addnew(res,i,i,i);
	}
}
function putMonth(res)
{
	delitem(res);
	var d=new Date();
	month=d.getMonth();
	addnew(res,month+1,month+1,month+1);
	for(var i=1;i<=12;i++)
	{
		addnew(res,i,i,i);
	}
}
function putDay(resyear,resmonth,res)
{
	delitem(res);
	var d=new Date();
	day=d.getDate();
        month=resmonth.value;
        year=resyear.value;
        days=getDays(month,year);
	addnew(res,day,day,day);
	for(var i=1;i<=days;i++)
	{
		addnew(res,i,i,i);
	}
}
function initDate(res1,res2,res3)
{
	 putYear(res1);
	 putMonth(res2);
	 putDay(res1,res2,res3);
}
function getName(res1,res2)
{
     if (res1.checked==true)
	 { name=res1.text;
	   //res2.value=name;
	   res2.value=res2.value+name;
	 }
}
//table????
function TableMouseOver(Obj){
	Obj.style.backgroundColor='#e2f9ff' ;
}
function TableMouseOut(Obj){
	Obj.style.backgroundColor='';
}
