var HuangLi = {};
var calData = new Array();
var currentDate = new Date();
var rows;
var showingToday = true; //显示的是今天
var taskHover_inblock = false;
var taskHover_inhover = false;
var madeRiliDate = new Date();
var record = {
elem_id : "",
nav_date : new Date()
};
var timeSelf = 0; //本地时间
var timeBeijing; //北京时间
function clock(time){
timeSelf = (new Date()).getTime();jprestWork
timeBeijing = time*1000;
}
Number.prototype.toPercent = function(n){
n = n || 0;
return ( Math.floor( this * Math.pow( 10, n + 2 ) ) / Math.pow( 10, n ) ).toFixed( n ) + '%';
}
var calander = {
//initialization the calender
init:function()
{
makeCal.pareData(new Date());
makeCal.showCal(new Date());
//init初始化的功能只需要初始化一次
makeCal.initAction();
makeCal.makeHuangli(currentDate);
//CallData(currentDate);
},
//make the calender of `date`
pareData:function(date)
{
date = makeCal.setTimeZero(date);
madeRiliDate = new Date(date);
//the first of this month
var monthFirstD = makeCal.getMonthFirst(date);
//the first in the table
var tableFirstD = makeCal.getWeekFirst(monthFirstD);
//the first of next month
var nextMonthFirstD = makeCal.addTime(monthFirstD, 1, "month");
//last day of this month
var monthLastD = makeCal.addTime(nextMonthFirstD, -1, "day");
//get the rows
rows = Math.ceil((nextMonthFirstD.valueOf()-tableFirstD.valueOf())/(60*60*24*1000*7));
//loop to calculate the data
var indexDay = new Date(tableFirstD);
var nowDay = makeCal.setTimeZero(new Date());
makeCal.fillCalData(indexDay, monthFirstD, monthLastD, nowDay);
},
fillCalData:function(indexDay, monthFirstD, monthLastD, nowDay){
calData = [];
for ( var i = 0; i < rows; i++){
var week = [];
for ( var j = 0; j < 7; j++){
var aDay = makeCal.createDay();
//set mode
if ( indexDay.getTime() < monthFirstD.getTime()){
aDay.before = true;
//aDay=null;
}
else if ( indexDay.getTime() > monthLastD.getTime()){
aDay.after = true;
//aDay=null;
}
//set year month date
aDay.year = indexDay.getFullYear();
aDay.month = indexDay.getMonth();
aDay.date = indexDay.getDate();
if ( indexDay.getTime() == nowDay.getTime()){
aDay.today = true;
}
if ( j == 0 || j == 6){
aDay.weekend = true;
}
aDay.rows = rows;
aDay.inrow = i+1;
aDay.value = indexDay;
aDay.china = templates.lunar_Info(aDay.value);
//临时调整节气
//var date_detail = aDay.value.getFullYear()+"-"+(aDay.value.getMonth()+1)+"-"+aDay.value.getDate();
week.push(aDay);
indexDay = makeCal.addTime(indexDay, 1, "day");
}
calData.push(week);
}
},
showCal:function(selectDate){
var is5Row = (rows<=5?true:false);
if ( typeof(selectDate) == "undefined" ){
selectDate = date = makeCal.setTimeZero(new Date());
}
selectDate = makeCal.setTimeZero(selectDate);
var cldCache = null;//月份为转换后的月
$('#month_num').text(selectDate.getMonth()+1);
$('#year_num').text(selectDate.getFullYear());
var table = "
');
for(var i in festival_main){
str.append('
').append(festival_main[i]+'
');
}
str.append('
');
}
//$("#festival_sel_div").html(str.toString());
$("#festival_sel_body>div").each(function(){
$(this).click(function(){
var y = $(this).attr("date").split("_");
record.nav_date.setFullYear(y[0]);
record.nav_date.setMonth(Number(y[1])-1);
generic_cal(record.nav_date,record.elem_id);
$("#festival_sel_div").hide();
});
$(this).hover(function(){
$(this).addClass("year_bg");
},
function(){
$(this).removeClass("year_bg");
});
});
},
init_sel_year : function(){
var str = new StringBuffer();
str.append('');
for(var i=1900;i<2050;i++)
{
str.append('
').append(i).append('
');
}
str.append('
');
// 设置日期选择的初始位置
//var scroll_top = record.nav_date.getFullYear()-1900;
$("#open_sel_div").html(str.toString());
$("#sel_body>div").each(function(){
$(this).click(function(){
var y = $(this).html();
record.nav_date.setFullYear(y);
generic_cal(record.nav_date,record.elem_id);
$("#open_sel_div").hide();
});
$(this).hover(function(){
$(this).addClass("year_bg");
},
function(){
$(this).removeClass("year_bg");
});
});
},
mousedown_hide_ele : function(id){
$(document).bind("mousedown."+id, function(r) {
var p = r.target;
var q = document.getElementById(id);
while (true)
{
if (p == q)
{
return true;
}
else
{
if (p == document)
{
$(document).unbind("mousedown."+id);
$("#"+id).hide();
return false;
}
else
{
p = $(p).parent()[0];
}
}
}
});
}
};
var cacheMgr = {
cldCache : {}, // 注意!这里存的是calendarObj.js中定义的calendar对象,不是数据文件载入的cldObj
getCld : function(year, month) {
var key = getMonthKey(year, month);
var cld = this.cldCache[key];
if (typeof cld == 'undefined')
{
cld = new calendar(year, month);
this.cldCache[key] = cld;
}
return cld;
}
};
function getRelativePath(sRelative) {// shawl.qiu code, return string
var sUrl = document.URL;
sUrl = sUrl.replace(/^.*?\:\/\/[^\/]+/, "").replace(/[^\/]+$/, "");
if (!sRelative) { return sUrl; }
if (!/\/$/.test(sUrl)) { sUrl += "/"; }
if (/^\.\.\//.test(sRelative)) {
var Re = new RegExp("^\\.\\.\\/"), iCount = 0;
while (Re.exec(sRelative) != null) {
sRelative = sRelative.replace(Re, "");
iCount++;
}
for (var i = 0; i < iCount; i++) { sUrl = sUrl.replace(/[^\/]+\/$/, ""); }
if (sUrl == "") return "/";
return sUrl + sRelative;
}
sRelative = sRelative.replace(/^\.\//, "");
return sUrl + sRelative;
} // end function fRelativePath(sRelative)
function getMonthKey(year, month)
{ // 传入的month为0-11的数值
return year.toString() + (month + 1).toString().leftpad(2); // 返回yyyyMM格式的字符串
}
String.prototype.leftpad = function(len, str)
{
if (!str)
{
str = '0';
}
var s = '';
for (var i = 0; i < len - this.length; i++)
{
s += str;
}
return s + this;
};
window.makeCal = calander;
function getMonthDateStr(date)
{
month = date.getMonth()+1;
day = date.getDate();
if ( month < 10 )
{
month = "0"+month;
}
if ( day < 10 )
{
day = "0" + day;
}
return month+""+day;
}
function getFullDateStr(date)
{
month = date.getMonth()+1;
day = date.getDate();
year = date.getFullYear();
return year+"-"+month+"-"+day;
}