/** * Default values should be changed to fit the current datePicker. */ DatePicker.dateFormat="DD MM YYYY"; DatePicker.weekDays = ['s','m','t','w','t','f','s']; DatePicker.months = ['January','February','March','April','May','June','Juli','August','September','October','November','December']; DatePicker.weekStart = 1; DatePicker.notWorkingDay = [0,6]; /** * DatePicker class. */ function DatePicker(inpDate,doc){ doc=doc?doc:document; this.setDateFormat(); this.date=inpDate?inpDate:new Date(); // Find the date to set this.datePicker = doc.createElement("div"); //this.datePicker.style="z-index:30" this.datePicker.className = "datePicker"; this.datePicker.style.zIndex = 20; this.datePicker.setAttribute('style', 'z-index:30') this.datePicker.onselectstart = function () { return false; }; /* User select off in IE */ this.datePicker.style.MozUserSelect = "none"; /* User select none in NS */ /***************************************************************************/ // Append Header div = this.datePicker.appendChild(doc.createElement("div")); div.className = "header"; table = div.appendChild(doc.createElement("table")); table.className = "headerTable"; table.cellSpacing = 0; tbody = table.appendChild(doc.createElement("tbody")); tr = tbody.appendChild(doc.createElement("tr")); // Button Back td = tr.appendChild(doc.createElement("td")); buttonBack = td.appendChild(doc.createElement("button")); imgBack = buttonBack.appendChild(doc.createElement("img")); imgBack.setAttribute('src',FillFormDatePickerImagesPath+"arrow.left.gif") buttonBack.className = "previousButton"; // Header td = tr.appendChild(doc.createElement("td")); td.className = "labelContainer"; a = td.appendChild(doc.createElement("a")) a.className = "topLabel" this.header = a.appendChild(doc.createTextNode("Label")); // Button Next td = tr.appendChild(doc.createElement("td")); buttonNext = td.appendChild(doc.createElement("button")); imgNext = buttonNext.appendChild(doc.createElement("img")); imgNext.setAttribute('src',FillFormDatePickerImagesPath+"arrow.right.gif") buttonNext.className = "nextButton"; /***************************************************************************/ //Create the table displaying the dates and weekdays div = this.datePicker.appendChild(doc.createElement("div")); div.className = "grid"; this.table = div.appendChild(doc.createElement("table")); this.table.className = "gridTable"; this.table.cellSpacing = 0; var tbody1 = this.table.appendChild(doc.createElement("tbody")); var tbody2 = this.table.appendChild(doc.createElement("tbody")); // Append weekdays table tr = tbody1.appendChild(doc.createElement("tr")); tr.className = "daysRow"; for(var j=0;j<7;j++){ td = tr.appendChild(doc.createElement("td")); td.appendChild(doc.createTextNode("")); td.className = ""; } tr = tbody1.appendChild(doc.createElement("tr")); td = tr.appendChild(doc.createElement( "td" )); td.className= "upperLine"; td.colSpan = 7; // Append dates table for(var i=0;i<6;i++){ tr = tbody2.appendChild(doc.createElement("tr")); for(var j=0;j<7;j++){ td = tr.appendChild(doc.createElement("td")); td.appendChild(doc.createTextNode("")); } } /***************************************************************************/ // events var dp = this; // event hook to this date object this.table.onclick = function(e){ e=e==null?doc.parentWindow.event:e; var el = e.target != null ? e.target : e.srcElement; while(el.nodeType != 1) el = el.parentNode; while(el!=null && el.tagName && el.tagName.toLowerCase()!="td") el= el.parentNode; if( el == null || el.tagName == null || el.tagName.toLowerCase() !="td") return; var d = new Date( dp.date ); var n = Number( el.firstChild.data ); if(isNaN(n) || n<=0 || n==null) return; d.setDate(n); dp.setDate(d); dp.returnDate(); } buttonNext.onclick = function(){ dp.setDate(new Date(dp.date.getFullYear(),dp.date.getMonth()+1,dp.date.getDate())) } buttonBack.onclick = function(){ dp.setDate(new Date(dp.date.getFullYear(),dp.date.getMonth()-1,dp.date.getDate())) } this.datePicker.onkeydown = function (e){ e=e==null?doc.parentWindow.event:e; var kc = e.keyCode!=null ? e.keyCode : e.charCode; if(kc==13||kc==32){ if ( typeof this.onchange == "function" ) this.onchange(); dp.returnDate(); return false; } if(kc<37||kc>40) return true; var d = new Date(dp.date).valueOf(); if(kc==37) //left d-=24*60*60*1000; else if(kc==39) //right d+=24*60*60*1000; else if(kc==38) //up d-=7*24*60*60*1000; else if(kc==40) //down d+=7*24*60*60*1000; dp.setDate(new Date( d )); return false; } /***************************************************************************/ this.setDate(inpDate); return this; } /** * Getters */ DatePicker.prototype.getDOMElement = function(){ return this.datePicker;} DatePicker.prototype.getDate = function(){return eval(this.dateFormat);}; /** * Show and hide the datePicker, when it is shown the focus is set, and * when it is hidden it is blurred. */ DatePicker.prototype.show = function(){ this.datePicker.style.visibility="visible"; this.datePicker.focus(); } DatePicker.prototype.hide = function(){ this.datePicker.style.visibility="hidden"; } /** * Return date calls the onchnge event set by the caller. */ DatePicker.prototype.returnDate = function(){ if ( typeof this.onchange == "function" ) this.onchange(); }; /** * The default onchange function is set to do nothing, the calling programm * chould implement this funciton. */ DatePicker.prototype.onchange = function () {}; DatePicker.prototype.onblur = function () {}; /** * Function used to check if a value is in an array. */ Array.prototype.contains = function(val){ for(var i=0;i