32 var calendarPopup_BORDER =
"1px solid #aaa";
33 var calendarPopup_BACKGROUND_COLOR =
"rgba(0,0,0,0.8)";
34 var calendarPopup_FONT_COLOR =
"white";
36 var calendarPopup_Z = 1000000;
37 var calendarPopup_W = 180;
38 var calendarPopup_H = 186;
39 var calendarPopup_CALID =
"calendarPopup";
40 var calendarPopup_MIN_YEAR = 2013;
41 var calendarPopup_MAX_YEAR = 0;
43 var calendarPopup_HEADER_H = 35;
44 var calendarPopup_DATES_H = 110;
45 var calendarPopup_DATES_OFFY = 28;
46 var calendarPopup_DATES_HDR_H = 15;
49 var calendarPopup_HANDLER;
68 function calendarPopup(x, y, calendarHandler) {
70 calendarPopup_HANDLER = calendarHandler;
75 el = document.createElement(
"div");
76 el.setAttribute(
"id", calendarPopup_CALID);
77 el.style.zIndex = calendarPopup_Z;
78 el.style.position =
"absolute";
79 el.style.overflow =
"hidden";
80 el.style.left = x +
"px";
81 el.style.top = y +
"px";
82 el.style.width = calendarPopup_W +
"px";
83 el.style.height = calendarPopup_H +
"px";
85 el.style.backgroundColor = calendarPopup_BACKGROUND_COLOR;
86 el.style.border = calendarPopup_BORDER;
87 el.style.color = calendarPopup_FONT_COLOR;
89 document.body.appendChild(el);
91 calendarPopupAddHeader();
92 calendarPopupAddMonthNav();
93 calendarPopupAddDates();
94 calendarPopupAddFooter();
99 function calendarPopupAddHeader() {
101 var calEl = document.getElementById(calendarPopup_CALID);
102 el = document.createElement(
"div");
103 el.setAttribute(
"id", calendarPopup_CALID +
"-header");
104 el.style.position =
"absolute";
105 el.style.left = 0 +
"px";
106 el.style.top = 0 +
"px";
107 el.style.width = calendarPopup_W +
"px";
108 el.style.height = calendarPopup_HEADER_H +
"px";
109 el.style.borderBottom = calendarPopup_BORDER;
111 calEl = calEl.appendChild(el);
115 el = document.createElement(
"select");
116 el.setAttribute(
"id", calendarPopup_CALID +
"-monthSelect");
117 el.style.color =
"black";
118 el.setAttribute(
"title",
"Select a month from the dropdown");
119 el.style.margin =
"5px";
120 el.style.cssFloat =
"left";
121 el.style.width = 70 +
"px";
122 el.onchange = handleSelection;
124 subCalEl = calEl.appendChild(el);
126 el = document.createElement(
"option");
127 el.style.color =
"black";
129 subCalEl.add(el,null);
131 var mDate = parseInt((
new Date(
"Jan 1, 2013")).getTime());
132 for(var i=0;i<12;++i, mDate += 1000*60*60*24*32)
134 el = document.createElement(
"option");
135 el.style.color =
"black";
136 el.text = (
new Date(mDate)).toDateString().split(
" ")[1];
137 subCalEl.add(el,null);
141 el = document.createElement(
"select");
142 el.setAttribute(
"id", calendarPopup_CALID +
"-yearSelect");
143 el.style.color =
"black";
144 el.setAttribute(
"title",
"Select a month from the dropdown");
145 el.style.margin =
"5px";
146 el.style.cssFloat =
"left";
147 el.style.width = 70 +
"px";
148 el.onchange = handleSelection;
150 subCalEl = calEl.appendChild(el);
152 el = document.createElement(
"option");
154 var yDate = parseInt((
new Date()).getFullYear());
156 var yMin = parseInt(calendarPopup_MIN_YEAR)?parseInt(calendarPopup_MIN_YEAR):yDate;
157 var yMax = parseInt(calendarPopup_MAX_YEAR)?parseInt(calendarPopup_MAX_YEAR):yDate;
158 for(var i=yMin;i<=yMax;++i)
160 el = document.createElement(
"option");
161 el.style.color =
"black";
163 subCalEl.add(el,null);
164 if(yDate == i) el.defaultSelected =
true;
168 el = document.createElement(
"div");
169 el.setAttribute(
"id", calendarPopup_CALID +
"-cancel");
170 el.setAttribute(
"title",
"Cancel date select");
171 el.style.margin =
"5px";
172 el.style.cssFloat =
"left";
173 el.style.width = 10 +
"px";
174 el.style.height = 10 +
"px";
175 el.innerHTML =
"<b>X</b>";
176 el.style.fontFamily =
"arial";
177 el.style.cursor =
"pointer";
179 el.onmouseup = cancelCalendar;
180 calEl.appendChild(el);
185 function cancelCalendar() {
186 var el = document.getElementById(calendarPopup_CALID);
188 el.parentNode.removeChild(el);
192 function calendarPopupAddMonthNav() {
194 var calEl = document.getElementById(calendarPopup_CALID);
196 el = document.createElement(
"div");
197 el.setAttribute(
"id", calendarPopup_CALID +
"-monthNav");
198 el.style.position =
"absolute";
199 el.style.left = 0 +
"px";
200 el.style.top = calendarPopup_HEADER_H +
"px";
201 el.style.width = calendarPopup_W +
"px";
203 calEl = calEl.appendChild(el);
208 el = document.createElement(
"div");
209 el.setAttribute(
"title",
"Prev Month");
210 el.style.margin =
"5px";
211 el.style.cssFloat =
"left";
212 el.style.width = navW +
"px";
213 el.innerHTML =
"<b><<<</b>";
214 el.style.fontFamily =
"arial";
215 el.style.cursor =
"pointer";
216 el.style.textAlign =
"center";
218 el.onmouseup = previousMonth;
219 calEl.appendChild(el);
222 el = document.createElement(
"div");
223 el.setAttribute(
"id", calendarPopup_CALID +
"-monthYearDisplay");
224 el.style.cssFloat =
"left";
225 el.style.width = (calendarPopup_W - navW*2 - 20) +
"px";
226 var todayArr = (
new Date()).toDateString().split(
" ");
227 el.innerHTML = todayArr[1] +
" " + todayArr[3];
228 el.style.fontWeight =
"800";
229 el.style.textAlign =
"center";
230 el.style.cursor =
"default";
231 el.style.marginTop =
"5px";
233 calEl.appendChild(el);
236 el = document.createElement(
"div");
237 el.setAttribute(
"title",
"Prev Month");
238 el.style.margin =
"5px";
239 el.style.cssFloat =
"right";
240 el.style.width = navW +
"px";
241 el.innerHTML =
"<b>>>></b>";
242 el.style.fontFamily =
"arial";
243 el.style.cursor =
"pointer";
244 el.style.textAlign =
"center";
246 el.onmouseup = nextMonth;
247 calEl.appendChild(el);
250 el = document.createElement(
"div");
251 el.setAttribute(
"id", calendarPopup_CALID +
"-currMonth");
252 el.style.display =
"none";
253 el.innerHTML = (
new Date()).getMonth();
254 calEl.appendChild(el);
255 el = document.createElement(
"div");
256 el.setAttribute(
"id", calendarPopup_CALID +
"-currYear");
257 el.style.display =
"none";
258 el.innerHTML = (
new Date()).getFullYear();
259 calEl.appendChild(el);
265 function previousMonth() {
266 var el = document.getElementById(calendarPopup_CALID +
"-currMonth");
267 var newMo = parseInt(el.innerHTML)-1;
268 var yel = document.getElementById(calendarPopup_CALID +
"-currYear");
272 yel.innerHTML = parseInt(yel.innerHTML)-1;
274 el.innerHTML = newMo;
275 el = document.getElementById(calendarPopup_CALID +
"-monthYearDisplay");
276 var dayArr = (
new Date(yel.innerHTML,newMo,1)).toDateString().split(
" ");
277 el.innerHTML = dayArr[1] +
" " + dayArr[3];
282 function nextMonth() {
283 var el = document.getElementById(calendarPopup_CALID +
"-currMonth");
284 var newMo = parseInt(el.innerHTML)+1;
285 var yel = document.getElementById(calendarPopup_CALID +
"-currYear");
289 yel.innerHTML = parseInt(yel.innerHTML)+1;
291 el.innerHTML = newMo;
292 el = document.getElementById(calendarPopup_CALID +
"-monthYearDisplay");
293 var dayArr = (
new Date(yel.innerHTML,newMo,1)).toDateString().split(
" ");
294 el.innerHTML = dayArr[1] +
" " + dayArr[3];
299 function calendarPopupAddDates() {
300 var calEl = document.getElementById(calendarPopup_CALID);
302 el = document.createElement(
"div");
303 el.setAttribute(
"id", calendarPopup_CALID +
"-dates");
304 el.style.position =
"absolute";
305 el.style.left = 0 +
"px";
306 el.style.top = calendarPopup_HEADER_H + calendarPopup_DATES_OFFY +
307 calendarPopup_DATES_HDR_H +
"px";
308 el.style.width = calendarPopup_W +
"px";
309 el.style.height = calendarPopup_DATES_H +
"px";
310 el.style.paddingTop =
"2px";
312 calEl.appendChild(el);
314 el = document.createElement(
"div");
315 el.setAttribute(
"id", calendarPopup_CALID +
"-datesHeader");
316 el.style.position =
"absolute";
317 el.style.left = 0 +
"px";
318 el.style.top = calendarPopup_HEADER_H + calendarPopup_DATES_OFFY +
"px";
319 el.style.width = calendarPopup_W +
"px";
320 el.style.height = calendarPopup_DATES_HDR_H +
"px";
321 el.style.borderBottom =
'1px solid #aaa';
323 calEl = calEl.appendChild(el);
325 var w = parseInt(calendarPopup_W/7);
326 var firstMargin = parseInt((calendarPopup_W - w*7)/2);
328 var day =
new Date(
"Jun 9, 2013");
329 for(var i=0;i<7;++i, day =
new Date(day.getTime() + 1000*60*60*24))
331 el = document.createElement(
"div");
332 el.setAttribute(
"class", calendarPopup_CALID +
"-dayHdr");
333 el.style.cssFloat =
"left";
334 el.style.width = w +
"px";
335 el.style.height = calendarPopup_DATES_HDR_H +
"px";
336 el.style.color =
"white";
337 el.style.textAlign =
"center";
338 if(!i) el.style.marginLeft = firstMargin +
"px";
339 el.innerHTML = day.toDateString()[0];
340 calEl.appendChild(el);
347 function calendarPopupAddFooter() {
349 var calEl = document.getElementById(calendarPopup_CALID);
353 function redrawDates() {
354 var calEl = document.getElementById(calendarPopup_CALID +
"-dates");
355 calEl.innerHTML =
"";
360 var mo = document.getElementById(calendarPopup_CALID +
"-currMonth").innerHTML;
362 document.getElementById(calendarPopup_CALID +
"-currYear").innerHTML,
365 while(day.getDay()) day =
new Date(day.getTime() - 1000*60*60*24);
368 var w = parseInt(calendarPopup_W/7);
369 var h = parseInt(calendarPopup_DATES_H/6);
371 var firstMargin = parseInt((calendarPopup_W - w*7)/2);
373 var todayDate = (
new Date()).getDate();
374 var todayMonth = (
new Date()).getMonth();
375 var todayYear = (
new Date()).getFullYear();
376 for(var i=0;i<7*6;++i, day =
new Date(day.getTime() + 1000*60*60*24))
378 el = document.createElement(
"div");
379 el.setAttribute(
"class", calendarPopup_CALID +
"-day");
381 el.setAttribute(
"id", calendarPopup_CALID +
"-day-" + parseInt(day.getTime()/(1000*60*60*24)));
383 el.style.cssFloat =
"left";
384 el.style.width = w +
"px";
385 el.style.height = h +
"px";
386 el.style.textAlign =
"center";
387 el.style.cursor =
"pointer";
388 el.style.color = mo == day.getMonth()?
"white":
"gray";
389 el.style.backgroundColor = (
390 todayYear == day.getFullYear() &&
391 todayMonth == day.getMonth() &&
392 todayDate == day.getDate())?
"#458":
"auto";
394 if(!(i%7)) el.style.marginLeft = firstMargin +
"px";
395 el.innerHTML = day.getDate();
397 el.onmouseup = selectDate;
399 calEl.appendChild(el);
403 var head = document.getElementsByTagName(
'head')[0];
404 var style = document.createElement(
'style');
405 var declarations = document.createTextNode(
"." + calendarPopup_CALID +
"-day:hover { background-color: #A10 }");
406 style.type =
'text/css';
407 if (style.styleSheet) {
408 style.styleSheet.cssText = declarations.nodeValue;
410 style.appendChild(declarations);
413 head.appendChild(style);
419 function handleSelection() {
420 var el = document.getElementById(calendarPopup_CALID +
"-monthSelect");
421 var newMo = el.value;
422 el = document.getElementById(calendarPopup_CALID +
"-monthYearDisplay");
423 el.innerHTML = newMo;
424 newMo = (
new Date(newMo +
" 1 2013")).getMonth();
425 el = document.getElementById(calendarPopup_CALID +
"-currMonth");
426 el.innerHTML = newMo;
428 el = document.getElementById(calendarPopup_CALID +
"-yearSelect");
430 el = document.getElementById(calendarPopup_CALID +
"-monthYearDisplay");
431 el.innerHTML +=
" " + newMo;
432 el = document.getElementById(calendarPopup_CALID +
"-currYear");
433 el.innerHTML = newMo;
438 function selectDate() {
439 calendarPopup_HANDLER(parseInt(this.
id.split(
"-")[2])+1);