
<!--
// JavaScript Document

var min_date= new Array() ;
var max_date = new Array();
var i=0;
var txtShowDate = new Array();
var isPostBack = new Array();
var txtID = new Array();
var ControlID=new Array();
var datePickerWidth=175;

function CustomerDatePicker(ControlID,inputID,autoPostBack,minDate,maxDate,useRule,btnStyle,boardStyle,noBoardStyle,barStyle,dayStyle,dayNoStyle,Width){
		//类属性设置
		this.ControlID=ControlID;
		this.inputID = inputID;
		this.autoPostBack = autoPostBack;
		this.minDate = minDate;
		this.maxDate = maxDate;
		this.useRule=useRule;
		//样式
		this.btnStyle = btnStyle;
		this.barStyle = barStyle;
		this.boardStyle = boardStyle;
		this.noBoardStyle = noBoardStyle;
		//this.dayStyle = dayStyle;
		//this.dayNoStyle = dayNoStyle;
                            this.datePickerWidth=Width;
		//类方法设置
		this.showDatePicker = showDatePicker;
                           
}

function cmdImageOnClick(controlID) {
		var x=document.all.item(controlID+":tblTotalCalendar");
		if (x.style.display == '')
			{
			x.style.display='none';
			}
		else
			{
			x.style.display='';
			}
	} 


function showDatePicker(){
	var testDate = /^(19[0-9]\d|2[0-2]\d\d)\-(0?\d|1[0-2])\-([0-2]?\d|3[01])$/;
	if ( testDate.test(this.minDate)){
		
		var minDates = this.minDate.split("-");
		var minYear = parseInt(minDates[0],10);
		var minMonth = parseInt(minDates[1],10);
		var minDate = parseInt(minDates[2],10);
		
	}
	else{
		var minYear = today.getFullYear();
		var minMonth = today.getMonth()+1;
		var minDate = today.getDate();
	}
	
	if( testDate.test(this.maxDate)){
		var maxDates = this.maxDate.split("-");
		var maxYear = parseInt(maxDates[0],10);
		var maxMonth = parseInt(maxDates[1],10);
		var maxDate = parseInt(maxDates[2],10);
	}
	else{
		var maxYear = today.getFullYear();
		var maxMonth = today.getMonth()+1;
		var maxDate = today.getDate();
	}
	
	 i += 1;
	 min_date[i] = new Date(minYear,minMonth -1,minDate);
	 max_date[i] = new Date(maxYear,maxMonth -1,maxDate);
	
	 txtShowDate[i] = document.all(this.inputID);
	 isPostBack[i] = this.autoPostBack;
	 txtID[i] = this.inputID;
               datePickerWidth=this.datePickerWidth;
	//设置样式属性

	
		var today = new Date();
		var year = today.getFullYear();
		var month = today.getMonth()+1;
		var mday = today.getDate();
	
	//这个月的最后一天
	var lastDay = new Date(year,month,0);
	lastDay = lastDay.getDate();
	var firstDay = new Date(year,month -1 ,1);
	firstDay = firstDay.getDay();

	var btnEvent =" onmouseover=\" this.childNodes[1].style.display=''; this.style.zIndex=100; \""+
				   " onmouseout=\" this.childNodes[1].style.display='none';this.style.zIndex=99;\"";		   
	
	var btnClickEvent = " onclick=\" if (event.srcElement.tagName=='IMG' ){ " +
	" var x=document.all.item(controlID+\":tblTotalCalendar\");" +
	"if (x.style.display == '' ) " +
	"	{x.style.display='none';}else{x.style.display='';}} \"";
	

	
	var changeMdays =
					" var year = parseInt(this.parentNode.cells[2].childNodes[0].innerText);"+
					" var month = parseInt(this.parentNode.cells[2].childNodes[2].innerText);"+
					" var firstDay = new Date(year,month -1,1); firstDay = firstDay.getDay();"+
					" var lastDay = new Date(year,month,0); lastDay = lastDay.getDate();"+
					" var tab = this.parentNode.parentNode,day=1; "+
					" for(var row =3; row<9;row++){"+
					"	for(var col=0;col<7;col++){"+
					"		if( row==3 && col<firstDay){"+
					"			tab.rows[3].cells[col].innerHTML='&nbsp;';"+
					"			tab.rows[3].cells[col].isDay=0;"+
					"		}else if ( day <= lastDay){"+
					"           var curDateChange = new Date(year,month-1,day);"+
					"			if( curDateChange - min_date["+i+"] < 0  ){ "+
					"				tab.rows[row].cells[col].innerHTML=day;"+
					"				tab.rows[row].cells[col].style.color = 'gray';"+
					"				tab.rows[row].cells[col].isDay = 0;day++;"+
					"			}else if( curDateChange - max_date["+i+"] > 0){"+
					"				tab.rows[row].cells[col].innerHTML=day;"+
					"				tab.rows[row].cells[col].style.color = 'gray';"+
					"				tab.rows[row].cells[col].isDay = 0;day++;"+
					"			}else{"+
					"				if (curDateChange.getDate() == (new Date()).getDate() && curDateChange.getFullYear() == (new Date()).getFullYear() && curDateChange.getMonth() == (new Date()).getMonth() ){"+
			"tab.rows[row].cells[col].style.color='Red';}else{tab.rows[row].cells[col].style.color='blue';}"+
					"				tab.rows[row].cells[col].innerHTML=day;"+
					"				tab.rows[row].cells[col].style.background ='#FCFCFC';"+
					"				tab.rows[row].cells[col].isDay = 1;day++;"+
					"			}"+
					"		}else{ "+
					"			tab.rows[row].cells[col].innerHTML='';"+
					"			tab.rows[row].cells[col].isDay=0;"+
					"		}"+
					"	}"+
					" }";
					
	var changeMdaysByTextBox =
					" var year = parseInt(document.all('txtSelYear').value);"+
					" var month = parseInt(document.all('txtSelMonth').value);"+
					" var y=this.parentNode.parentNode.parentNode.parentNode.rows[0].cells[2].childNodes[0]; m = this.parentNode.parentNode.parentNode.parentNode.rows[0].cells[2].childNodes[2];y.innerText = year;m.innerText=month;"+
					" var firstDay = new Date(year,month -1,1); firstDay = firstDay.getDay();"+
					" var lastDay = new Date(year,month,0); lastDay = lastDay.getDate();"+
					" var tab = this.parentNode.parentNode.parentNode,day=1; "+
					" for(var row =3; row<9;row++){"+
					"	for(var col=0;col<7;col++){"+
					"		if( row==3 && col<firstDay){"+
					"			tab.rows[3].cells[col].innerHTML='&nbsp;';"+
					"			tab.rows[3].cells[col].isDay=0;"+
					"		}else if ( day <= lastDay){"+
					"           var curDateChange = new Date(year,month-1,day);"+
					"			if( curDateChange - min_date["+i+"] < 0  ){ "+
					"				tab.rows[row].cells[col].innerHTML=day;"+
					"				tab.rows[row].cells[col].style.color = 'gray';"+
					"				tab.rows[row].cells[col].isDay = 0;day++;"+
					"			}else if( curDateChange - max_date["+i+"] > 0){"+
					"				tab.rows[row].cells[col].innerHTML=day;"+
					"				tab.rows[row].cells[col].style.color = 'gray';"+
					"				tab.rows[row].cells[col].isDay = 0;day++;"+
					"			}else{"+
					"				if (curDateChange.getDate() == (new Date()).getDate() && curDateChange.getFullYear() == (new Date()).getFullYear() && curDateChange.getMonth() == (new Date()).getMonth() ){"+
			"tab.rows[row].cells[col].style.color='Red';}else{tab.rows[row].cells[col].style.color='blue';}"+
					"				tab.rows[row].cells[col].innerHTML=day;"+
					"				tab.rows[row].cells[col].style.background ='#FCFCFC';"+
					"				tab.rows[row].cells[col].isDay = 1;day++;"+
					"			}"+
					"		}else{ "+
					"			tab.rows[row].cells[col].innerHTML='';"+
					"			tab.rows[row].cells[col].isDay=0;"+
					"		}"+
					"	}"+
					" }";
					
	var keyPressEvent = " onkeypress=\"if (event.keyCode == 13 ){  var testYear = /^19\\d\\d|2[0-2]\\d\\d$/; var testMonth = /^(0?\\d|1[0-2])$/; if(testYear.test(document.all('txtSelYear').value) && testMonth.test(document.all('txtSelMonth').value)){}else{alert('Make Sure your inputing Char is right!');document.all('txtSelYear').value= this.parentNode.parentNode.parentNode.parentNode.rows[0].cells[2].childNodes[0].innerText; document.all('txtSelMonth').value=this.parentNode.parentNode.parentNode.parentNode.rows[0].cells[2].childNodes[2].innerText;return false;} " + changeMdaysByTextBox 
	+ " return false;}\"";
	
	
	var pyEvent = 	" onmouseover=\" event.srcElement.style.color='#336699';\" onmouseout=\" event.srcElement.style.color='#FFFFCC';\""
					+" onclick=\" var y=this.parentNode.cells[2].childNodes[0];y.innerText=parseInt(y.innerText)-1; " 
					+changeMdays+" \"";
	var pmEvent = 	" onmouseover=\" event.srcElement.style.color='#336699';\" onmouseout=\" event.srcElement.style.color='#FFFFCC';\""
					+" onclick=\" var y=this.parentNode.cells[2].childNodes[0]; m = this.parentNode.cells[2].childNodes[2];"+
					" m.innerText= parseInt(m.innerText)-1; if(m.innerText == '0'){m.innerText = 12;y.innerText = parseInt(y.innerText)-1;}"
					+changeMdays+" \"";
	var nyEvent = " onmouseover=\" event.srcElement.style.color='#336699';\" onmouseout=\" event.srcElement.style.color='#FFFFCC';\""
					+" onclick=\" var y=this.parentNode.cells[2].childNodes[0];y.innerText=parseInt(y.innerText)+1;"
					+changeMdays+" \"";
	var nmEvent = 	" onmouseover=\" event.srcElement.style.color='#336699';\" onmouseout=\" event.srcElement.style.color='#FFFFCC';\""
					+" onclick=\" var y= this.parentNode.cells[2].childNodes[0];m= this.parentNode.cells[2].childNodes[2];"+
					" m.innerText = parseInt(m.innerText) +1;if(m.innerText == '13'){m.innerText = 1;y.innerText=parseInt(y.innerText)+1;}" 
					+changeMdays+" \"";
					
	var mdayEvent =" onmouseover=\" if(event.srcElement.tagName=='TD' && event.srcElement.isDay ==1){"+
					"                 event.srcElement.style.cursor='hand';event.srcElement.style.backgroundColor='#FFCC66';"+
					"                 var ym = event.srcElement.parentNode.parentNode.rows[0].cells[2].childNodes;"+
					"                 event.srcElement.title = ym[0].innerText+'-'+ym[2].innerText+'-'+event.srcElement.innerText;} "+
					"               else if(event.srcElement.isDay ==2) {"+
					"                   var curDay = new Date(); event.srcElement.title = curDay.getFullYear()+'-'+(curDay.getMonth() +1) + '-' + curDay.getDate();}"+
					"                \""+
					"onmouseout=\"  if(event.srcElement.tagName=='TD' && event.srcElement.isDay ==1){" +
					"                event.srcElement.style.backgroundColor='#FCFCFC';" +
					"                event.srcElement.style.cursor='default';}\" " +
					" onclick=\" if(event.srcElement.tagName=='TD'&&event.srcElement.isDay ==1){"+
					"	var showDate = txtShowDate["+i+"];"+
					"	showDate.value=this.rows[0].cells[2].childNodes[0].innerText+'-'+this.rows[0].cells[2].childNodes[2].innerText+'-'+event.srcElement.innerText;"+
					"	this.parentNode.parentNode.style.display = 'none';" +
					"   this.parentNode.parentNode.style.zIndex=99;" + 
					"	if(isPostBack["+i+"]==1){ __doPostBack(txtID["+i+"],'');}}"+
					"   else if( event.srcElement.isDay == 2){" +
					"        var showDate = txtShowDate["+i+"];"+
					"        var curDay = new Date(); showDate.value=curDay.getFullYear()+'-'+(curDay.getMonth() + 1)+'-'+curDay.getDate();"+
					"        this.parentNode.parentNode.style.display = 'none';" +
					"        this.parentNode.parentNode.style.zIndex=99;" +
					"        if (isPostBack["+i+"]==1){ __doPostBack(txtID["+i+"],'');}}"+
					"\"";
					
	/*var mdayEvent =" onmouseover=\" if(event.srcElement.tagName=='TD' && event.srcElement.isDay ==1){"+
					" event.srcElement.style.cursor='hand';"+
					" var ym = event.srcElement.parentNode.parentNode.rows[0].cells[2].childNodes;"+
					" event.srcElement.title = ym[0].innerText+'-'+ym[2].innerText+'-'+event.srcElement.innerText;}\""+
					" onclick=\" if(event.srcElement.tagName=='TD'&&event.srcElement.isDay ==1){"+
					" var inpShow = this.parentNode.parentNode.parentNode.previousSibling.childNodes[0];"+
					" inpShow.value=this.rows[0].cells[2].childNodes[0].innerText+'-'+this.rows[0].cells[2].childNodes[2].innerText+'-'+event.srcElement.innerText;"+
					" this.parentNode.style.display = 'none';this.parentNode.style.zIndex=99;}"+
					"\"";*/
					
	var output = "";
	output +=  " <iframe frameborder=0 width=177px  height=" +  datePickerWidth  + "px\"></iframe>";
	output +=  " <div style=\"position:absolute;top:0;left:2;\">";
	output +=  "		<table style=\"width:175px;\"  cellpadding =1 cellspacing= 1 "+mdayEvent+" >";
	output +=  "               <tr height=20px align=center >";
	output +=  "                  <td title='上一年' class=\"" +this.barStyle+ "\"  " +pyEvent+" >&lt;&lt;</td>";	
	output +=  "                  <td title='上个月' class=\"" +this.barStyle+ "\"  "+pmEvent+">&lt;</td>";
	output +=  "                  <td colspan=3 valign=bottom style='background-color:#808080;color:#ffffff;font-size:10px;font-family:Arial;' >";
	output +=  "                      <span>"+year+"</span><span>年</span><span>"+ month + "</span><span>月</span></td>";
	output +=  "                  <td title='下一月' class=\"" +this.barStyle+ "\"  "+nmEvent+">&gt;</td>";
	output +=  "                  <td title='下一年' class=\"" +this.barStyle+ "\"  "+nyEvent+">&gt;&gt;</td>";
	output +=  "               </tr>";
	//here add a row for update
	output +=  "				<tr height=16px align=center style='display:none;'>";
	output +=  "				<td  style='color:white;background-color:#fcfcfc;font-size:12;font-family:Arial;' colspan=7><input type=text name='txtSelYear'  value='" + (new Date()).getFullYear() +"' size='4' style='height:16.5px;background-color:#FCFCFC; width=32px; border:#ffffff 1px solid' " + keyPressEvent+" />&nbsp;年&nbsp;<input style='height:16.5px; width=20px;background-color:#FCFCFC; border:#ffffff 1px solid' type=text name='txtSelMonth' value='" + ((new Date()).getMonth() + 1 )+ "' size='3' " + keyPressEvent+ " />&nbsp;月&nbsp;</td>";
	output +=  "               </tr>";
	output +=  "               <tr height=17px><td colspan=7 style='border-bottom-width: 1px;border-bottom-style: solid;border-bottom-color: #000000;'>";
	output +=  "                 <table width=100% stype='background-color:#fcfcfc'>";
 	output +=  "                  <tr height=16px align=center style='font-size:12px;background-color:#fcfcfc;color:black;'>";
	output +=  "                  <td width=15% style='color:red;'>日</td>";
	output +=  "                  <td width=14%>一</td>";
	output +=  "	       <td width=14%>二</td>";
	output +=  "                  <td width=14%>三</td>";
	output +=  "                  <td width=14%>四</td>";
	output +=  "                  <td width=14%>五</td>";
	output +=  "                  <td width=15% style='color:red;'>六</td>";
	output +=  "                  </tr>";
	output +=  "                  </table>";
	output +=  "          </td></tr>";
	
	
	var day = 1;var todayStyle = "";
		for(row =0 ;row< 6 ;row++){
			output += "<tr align=center height=14px>";
			for(col = 0 ;col<7 ;col++){
				if( row ==0 && col <firstDay){
					output += "<td style='background-color:#FCFCFC;color: gray;font-size:10px;font-family:Arial;'>&nbsp;</td>"
				}
				else if(day <= lastDay){
					var curDate = new Date(year,month-1,day);
					
					
					
					//if( curDate - min_date < 0  ){
					if( curDate - min_date[i] < 0  ){
						
						output += "<td style='font-size:10px;font-family:Arial; color='Gray' isDay=0 >" + day + "</td>";
						day++;
					//}else if( curDate - max_date > 0){
					}else if( curDate - max_date[i] > 0){
						
						output += "<td style='font-size:10px;font-family:Arial;color='Gray' isDay=0  >" + day + "</td>";
						day++;
					}
					else{
						
						if (curDate.getDate() == (new Date()).getDate() && curDate.getFullYear() == (new Date()).getFullYear() && curDate.getMonth() == (new Date()).getMonth() ){
							todayStyle=" color:Red; ";
						}
						else{
							todayStyle=" color:blue; ";
						}
						output += "<td isDay=1 style='font-size:10px;font-family:Arial; " + todayStyle+ "' >" + day + "</td>";
						day++;
					}
				}else{
					output += "<td style='color: gray;font-size:10px;font-family:Arial;'></td>";
				}
			}
			
			output += "</tr>";
		}
	
	output += "<tr align=center height=20><td style='background-color:#CCCCCC;font-size:10px;font-family:Arial;'></td>";
	output += "<td style='color:Red;background-color:#CCCCCC;font-size:10px;font-family:Arial;cursor:hand' colspan=5  isDay=2>今天</td>";
	output += "<td style='background-color:#CCCCCC;font-size:10px;font-family:Arial;'></td><tr>";
	
	output +=  "        </table>";
	output +=  "</div>";

	document.write(output);
}
// -->
