﻿if(typeof Soobb=="undefined"){Soobb={}};if(typeof Soobb.Labs=="undefined"){Soobb.Labs={}};if(typeof Soobb.Labs.UI=="undefined"){Soobb.Labs.UI={}};Soobb.Labs.UI.Calendar=new(function(){this.lan_columns=new Array("日","一","二","三","四","五","六");this.lan_column1="日";this.lan_column2="一";this.lan_column3="二";this.lan_column4="三";this.lan_column5="四";this.lan_column6="五";this.lan_column7="六";this.lan_nowtime="";this.lan_unit1="年";this.lan_unit2="月";this.lan_previewmonth="上月";this.lan_nextmonth="下月";this.rootNode=document.body;this.Container=document.createElement("DIV");this.NowYear=0;this.NowMonth=0;this.nowObj=null;this.isshowing=false;this.left=0;this.top=0;this.width=180;this.height=140;this.clickSelf=false;this.OnChange=function(Year,Month,Day){};this.GetOffset=function(e){var t=0;var l=0;if(document.all){t=e.getBoundingClientRect().top-2;l=e.getBoundingClientRect().left-2;}else{t=e.offsetTop;l=e.offsetLeft;};var rec=new Array(1);rec["top"]=t;rec["left"]=l;return rec;};this.Create=function(Inputer,X,Y){this.Container.style.width=this.width+"px";this.Container.style.height=this.height+"px";this.Container.style.display="none";this.rootNode.appendChild(this.Container);if(isNaN(X)){var w=Inputer.offsetWidth;var h=Inputer.offsetHeight;var rect=this.GetOffset(Inputer);if(X=="up"){this.left=rect.left;this.top=rect.top-this.height-h;}else if(X=="left"){this.left=rect.left-this.width;this.top=rect.top;}else if(X=="right"){this.left=rect.left+w;this.top=rect.top;}else{this.left=rect.left;this.top=rect.top+h;};}else{this.left=X;this.top=Y;};if(this.top<0){this.top=0;};if(this.left<0){this.left=0;};var c=this;this.nowObj=Inputer;Inputer.readOnly=true;Inputer.onfocus=function(){c.Container.style.display="";};Inputer.onclick=function(){c.Container.style.display="";};Inputer.onblur=function(){if(c.clickSelf){c.clickSelf=false;return;};c.Container.style.display="none";};this.Container.onmouseout=function(){c.clickSelf=false;};var Today=new Date();this.DisplayCalender(Today.getYear(),Today.getMonth(),Today.getDate());this.Container.style.left=this.left+"px";this.Container.style.top=this.top+"px";this.Container.style.position="absolute";this.Container.style.background="#FFFFFF";this.Container.style.borderColor="#0353ce";this.Container.style.borderWidth="1px";this.Container.style.borderStyle="solid";this.Container.style.fontSize="12px";};this.DisplayCalender=function(Year,Month){this.Container.innerHTML="";if(Year<1900){Year+=1900};var theDay=new Date(Year,Month,1);this.NowYear=Year;this.NowMonth=Month;this.CreateTitle();this.CreateBody(theDay);this.CreateBottom();if(document.all){var L=document.createElement("IFRAME");L.width=this.Container.style.width;L.height=this.Container.style.height;L.style.borderWidth="0";L.frameborder="0";L.marginwidth="0";L.framespacing="0";L.marginheight="0";L.src="about:blank";this.Container.appendChild(L);};};this.CreateTitle=function(){for(var i=0;i<7;i++){var tdiv1=this.CreateTitleDiv();tdiv1.innerHTML=this.lan_columns[i];tdiv1.style.left=(this.width/7*i)+"px";this.Container.appendChild(tdiv1);}};this.CreateTitleDiv=function(){var tdiv=document.createElement("DIV");tdiv.style.top="0px";tdiv.style.backgroundColor="#0353ce";tdiv.style.fontWeight="bold";tdiv.style.color="#ffffff";tdiv.style.position="absolute";tdiv.style.paddingTop="2px";tdiv.style.paddingBottom="2px";tdiv.style.width=(this.width/7+1)+"px";tdiv.setAttribute("align","center");return tdiv;};this.CreateBody=function(theday){var start=theday.getDay();var totaldays=this.GetDayNumber(this.NowYear,this.NowMonth+1);var counter=0;var mleft=0;var mtop=27;var c=this;var Today=new Date();var isJudgeToday=false;var CurYear=Today.getYear()>1900?Today.getYear():Today.getYear()+1900;var CurMonth=Today.getMonth();if(this.NowYear==CurYear&&this.NowMonth==CurMonth){isJudgeToday=true;};for(var ii=0;ii<6;ii++){if(counter>=totaldays)break;mtop=27+(this.height-50)/6*ii;mleft=0;for(var i=0;i<7;i++){if(ii*7+i<start){mleft+=this.width/7;}else if(counter>=totaldays){}else{var tdiv=this.CreateBodyDiv();var tday=ii*7+i-start+1;tdiv.setAttribute("Day",tday);if(isJudgeToday&&tday==Today.getDate()){tday="<div style=\"color:#0353ce; font-weight: bold;\">"+tday+"</div>";};tdiv.style.left=mleft+"px";tdiv.style.top=mtop+"px";tdiv.onmousedown=function(){this.style.borderColor="#ffffff";if(this.innerText){c.ChoiceIt(parseInt(this.innerText));}else{c.ChoiceIt(parseInt(this.getAttribute("Day")));};};if((isJudgeToday&&tday<Today.getDate())||this.NowYear<CurYear||(this.NowYear==CurYear&&this.NowMonth<CurMonth)){tday="<strike style=\"color: #666\">"+tday+"</strike>";tdiv.onmousedown=null;};tdiv.innerHTML=tday;this.Container.appendChild(tdiv);counter++;mleft+=this.width/7;}}if(counter>=totaldays)break;}};this.CreateBodyDiv=function(){var tdiv=document.createElement("DIV");tdiv.style.position="absolute";tdiv.style.height=((this.height-54)/6)-6+"px";tdiv.style.width=(this.width/7)-7+"px";tdiv.setAttribute("align","center");this.CreateBorderStyle(tdiv);return tdiv;};this.CreateBottom=function(){var tdiv1=this.CreateBottomDiv();tdiv1.style.width=(this.width/1.5)+"px";tdiv1.style.left="0px";tdiv1.innerHTML=this.lan_nowtime+this.NowYear+this.lan_unit1+(this.NowMonth+1)+this.lan_unit2;var tdiv2=this.CreateBottomDiv();tdiv2.style.left=(this.width/1.5)+"px";tdiv2.innerHTML=this.lan_previewmonth;var tdiv3=this.CreateBottomDiv();tdiv3.style.left=(this.width/1.5+30)+"px";tdiv3.innerHTML=this.lan_nextmonth;this.CreateBorderStyle(tdiv2);this.CreateBorderStyle(tdiv3);var obj=this;tdiv2.onmousedown=function(){obj.clickSelf=true;if(obj.NowMonth==0){obj.NowMonth=11;obj.NowYear--;}else{obj.NowMonth--;}obj.DisplayCalender(obj.NowYear,obj.NowMonth,1);};tdiv3.onmousedown=function(){obj.clickSelf=true;if(obj.NowMonth==11){obj.NowMonth=0;obj.NowYear++;}else{obj.NowMonth++;}obj.DisplayCalender(obj.NowYear,obj.NowMonth,1);};this.Container.appendChild(tdiv1);this.Container.appendChild(tdiv2);this.Container.appendChild(tdiv3);};this.CreateBorderStyle=function(tdiv){try{tdiv.style.cursor="pointer";}catch(e){};};this.CreateBottomDiv=function(){var tdiv=document.createElement("DIV");tdiv.style.backgroundColor="";tdiv.style.color="#0353ce";tdiv.style.position="absolute";tdiv.style.height="18px";tdiv.style.top=(this.height-25)+"px";tdiv.setAttribute("align","left");tdiv.style.fontSize="12px";tdiv.style.marginLeft="4px";return tdiv;};this.ChoiceIt=function(which){var m=this.NowMonth<9?"0"+(this.NowMonth+1):""+(this.NowMonth+1);var d=which<10?"0"+which:""+which;this.nowObj.value=this.NowYear+"-"+m+"-"+d;this.OnChange(this.NowYear,m,d);this.Container.style.display="none";};this.GetDayNumber=function(year,month){if(month==2){if(year%4==0&&year%100!=0||year%400==0){return 29;}else{return 28;};};if(month==1||month==3||month==5||month==7||month==8||month==10||month==12){return 31;}else{return 30;};};})();
