//常量定义区
var Day_28=new Array("01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28");
var Day_29=new Array("01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29");
var Day_30=new Array("01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30");
var Day_31=new Array("01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31");

//常量定义区

//重填页面表单.
function formReset(frm){ 	               
	var i,form=frm;

	for (i=0;i< form.elements.length;i++){
		switch (form.elements[i].type){
			case "text":
				form.elements[i].value='';
				break;
			case "hidden":
				form.elements[i].value='';
				break;

			case "select-one":
				form.elements[i].options[0].selected = true;
				break;
			case "checkbox":
				form.elements[i].checked=false;
			case "textarea":
				form.elements[i].value='';

		}
	}

}



//打开一个新窗口,并显示在屏幕中央.
function openNewWindow(theURL,winName,features,width,height) { 
	
	var top,left,style;
	left=(window.screen.width-width)/2;
	top=(window.screen.height-height)/2;
	style="width="+width+",height="+height+",top="+top+",left="+left;
	if (features!="")
	{
		style=style+","+features;
	}

   window.open(theURL,winName,style);
}

//打开一个新窗口,并显示在屏幕中央.
function openModalWindow(theURL,width,height) { 
	
	var top,left,style;
	left=(window.screen.width-width)/2;
	top=(window.screen.height-height)/2;

   window.showModalDialog(theURL,"","dialogWidth="+width+",dialogHeight="+height+",dialogTop="+top+",dialogLeft="+left);
}


//打开一个没有边框的新窗口,并显示在屏幕中央.
function openNewFrame(theURL,winName,width,height) { 
	
	var top,left,style;
	left=(window.screen.width-width)/2;
	top=(window.screen.height-height)/2;
	style="fullscreen=1,window.screen.width="+width+",window.screen.height="+height+",top="+top+",left="+left;

   newFrame=window.open(theURL,winName,style);
   //newFrame.resizeTo( Math.ceil( width ), Math.ceil( height ) );
   //newFrame.moveTo  ( Math.ceil( left ) , Math.ceil( top ) );

}

//润年判断
function isRunYear(year)
{
  if ((year%4 == 0) && (year%100 != 0) || (year%400 == 0)){
	 return true;		
  }else{
	 return false;
  }
}//End isRunYear.


//返回本月的天数
function returnMonth(TTmonth,TTisRun)
{
	var TTmonth,TTisRun;		
	if (TTisRun){

		switch(TTmonth)
		{			  			  	
		  case 3:	  
		  case 5:
		  case 8:
		  case 10:			  
			 return 30;
			 break;			  
		  case 0:
		  case 2:
		  case 4:	  
		  case 6:
		  case 7:
		  case 9:
		  case 11:		  
			 return 31;
			 break;
		  case 1:
			 return 29;
			 break;
		}

	}else{

		switch(TTmonth)
		{		      
		  case 3:	  
		  case 5:
		  case 8:
		  case 10:		  
			 return 30;
			 break;
		  case 0:
		  case 2:
		  case 4:	  
		  case 6:
		  case 7:
		  case 9:
		  case 11:			  
			 return 31;
			 break;
		  case 1:
			 return 28;
			 break;
		}
		
	}
}//End returnTTmonth.



//修改日期下拉框

function ChangeCombo(isOption,AllData){

	for (var i=isOption.options.length; i > 0; i--)
		  isOption.options[i] = null;

	for (var i=0; i<AllData.length; i++){
		
		var aOption = new Option(AllData[i],AllData[i]);
		isOption.options[isOption.options.length]=aOption;
		
	}
}



//时间比较函数	
function dataBool(type,baseDate,compareDate)
{
	var type,baseDate,compareDate;
	var baseYear,baseMonth,baseDay;
	var compYear,compMonth,compDay;

	type=type.toLowerCase();

	baseYear = adjustment(baseDate.substring(0,4));
	baseMonth = adjustment(baseDate.substring(5,7));
	baseDay = adjustment(baseDate.substring(8,10));
	
	compYear = adjustment(compareDate.substring(0,4));
	compMonth = adjustment(compareDate.substring(5,7));
	compDay = adjustment(compareDate.substring(8,10));

	var baseValue=new Date(baseYear,baseMonth-1,baseDay);
	var compValue=new Date(compYear,compMonth-1,compDay);
	
	var baseTime=baseValue.getTime();  
	var compTime=compValue.getTime();

	if (type=='small'){
		
		if (compTime >= baseTime)
			return true;
		else
			return false;
	
	}        

	if (type=='big'){
	   
	   if (compTime <= baseTime)
			return true;
		else
			return false;		   

	}
   
}


//设置下拉框控件值, Obj 为控件对象 , SetObjValue 值.
function SetDropDown(Obj,SetObjValue){
	     
		 var y="";

		 if (SetObjValue == "")
			SetObjValue="NULL";   
		 
		 rows=Obj.length;
		 for (i=0;i<rows;i++){
			if (Obj.options[i].value == SetObjValue){
			   y=i;
			}	 
		 }
		 if (y!="")
		 Obj.options[y].selected = true;   
}

function get_Day(year,month){
	var Last_Mon = new Array(31,29,31,30,31,30,31,31,30,31,30,31);
	var Mon2;

	if(year%4==0){
		Mon2 = true;
	}else{
		Mon2 = false;
	}

	Last_Mon[1] = (Mon2)?29:28;

	return Last_Mon[month];
}

 function adjustment(input)
   {
     var output;
     if (input=='08')
          output=8;
        else if (input=='09')
          output=9;
             else output=parseInt(input);
     return output;
   }//end of adjustment()

//小数点四舍五入 n 为小数位数
function rounddigital(input,n){
	var output;
	output = Math.round(input*(Math.pow(10,n)))/Math.pow(10,n);
	return output;
}


/*	设置小日历的值
	dateVal			日期数值 eg. 2002-07-20 , 07.10.2002, 06/05/2001
	calendarName	小日历控件的名称
	dateFormat		日期的格式
*/
function SetCalendarVal(dateVal,calendarName,dateFormat){

	var dateVal,calendarName,dateformat;
	
	var yearObj = eval(calendarName+"year");
	var monthObj = eval(calendarName+"month");
	var dayObj = eval(calendarName+"day");


	switch (dateFormat.toUpperCase()){
		case "YYYY-MM-DD":
			dateArray = dateVal.split("-");
			SetDropDown(yearObj,dateArray[0]);
			SetDropDown(monthObj,dateArray[1]);
			SetDropDown(dayObj,dateArray[2]);
			break;
	}//end switch.

}//end function.