var months=new Array("jan","feb","maa","apr","mei","jun","jul","aug","sep","okt","nov","dec");var mdays=new Array(31,28,31,30,31,30,31,31,30,31,30,31);var dayNames=new Array("M","T","W","T","F","S","S");var fancyObj=null;function getOffsetPos(a){var b=curtop=0;if(a.offsetParent){b=a.offsetLeft;curtop=a.offsetTop;while(a=a.offsetParent){b+=a.offsetLeft;curtop+=a.offsetTop}}return[b,curtop]}function fancydate(a){this.input=document.getElementById(a);this.input.readOnly="readonly";this.input.title="dd/mm/yyyy";this.input.value="";var b=getOffsetPos(this.input);this.posX=b[0]+this.input.scrollLeft;this.posY=b[1]+this.input.scrollTop+this.input.offsetHeight;this.iwidth=this.input.offsetWidth;this.oDiv=null;this.alterInput();this.state=false;this.overDiv=false;this.date=new Date();this.today=leadingZero(this.date.getDate())+"/"+leadingZero(this.date.getMonth()+1)+"/"+this.date.getUTCFullYear();this.month=this.date.getMonth();this.year=this.date.getUTCFullYear();this.input.onclick=bind(this,this.toggleCalender);this.input.onblur=bind(this,this.shouldHideCalender);this.createCalender()}fancydate.prototype={alterMonth:function(a){this.month+=a;if(this.month<0){this.month=11;this.year+=a}else{if(this.month>11){this.month=0;this.year+=a}}this.refillCalender()},alterInput:function(){this.input.style.backgroundImage="url('/assets/web/fancydate/calendar.png')";this.input.style.backgroundRepeat="no-repeat";this.input.style.backgroundPosition="right center";this.input.style.cursor="default"},toggleCalender:function(){if(this.state){this.hideCalender()}else{this.showCalender()}},mouseOut:function(){this.overDiv=false},mouseOver:function(){this.overDiv=true},shouldHideCalender:function(){if(!this.overDiv){this.hideCalender()}else{var a=this.input.id;window.setTimeout("document.getElementById('"+a+"').focus();",1)}},hideCalender:function(){document.getElementById("calender_"+this.input.id).style.display="none";this.state=false;this.overDiv=false;this.refillCalender()},showCalender:function(){if(!this.state){document.getElementById("calender_"+this.input.id).style.display="block";this.state=true}},createCalender:function(){var a=document.createElement("div");a.id="calender_"+this.input.id;a.className="calender";a.style.position="absolute";a.style.left=this.posX+"px";a.style.top=this.posY+"px";a.style.width=this.iwidth-2+"px";a.style.display="none";this.oDiv=a;this.fillCalender(this.oDiv);document.body.appendChild(this.oDiv);this.oDiv.onmouseover=bind(this,this.mouseOver);this.oDiv.onmouseout=bind(this,this.mouseOut)},refillCalender:function(){this.oDiv.innerHTML="";this.fillCalender()},fillCalender:function(){var d=new Date();var r=new Array(7);var a=new Array();var f=new Date();f.setMonth(this.month);f.setFullYear(this.year);for(var c=1;c<=mdays[this.month];c++){f.setDate(c);var m=f.getUTCDay();m-=1;if(m<0){m=6}r[m]=c;if(m==6){a.push(r);r=new Array(7)}}if(r){a.push(r)}ctable=document.createElement("table");ctable.width="100%";crow=document.createElement("tr");h=document.createElement("td");var e=new Selector("/assets/web/fancydate/previous.gif","month",-1,this);h.appendChild(e.img);crow.appendChild(h);h=document.createElement("td");h.setAttribute("colspan",2);ccoltxt=document.createTextNode(months[this.month]);h.appendChild(ccoltxt);crow.appendChild(h);h=document.createElement("td");var l=new Selector("/assets/web/fancydate/next.gif","month",1,this);h.appendChild(l.img);crow.appendChild(h);h=document.createElement("td");h.setAttribute("colspan",3);h.style.textAlign="right";ccoltxt=document.createTextNode(this.year);h.appendChild(ccoltxt);crow.appendChild(h);ctable.appendChild(crow);var q=document.createElement("tr");for(var k=0;k<dayNames.length;k++){var h=document.createElement("td");var o=document.createTextNode(dayNames[k]);h.appendChild(o);q.appendChild(h)}ctable.appendChild(q);for(var k=0;k<a.length;k++){q=document.createElement("tr");for(var g=0;g<a[k].length;g++){var b=document.createElement("td");if(a[k][g]){var p=leadingZero(a[k][g])+"/"+leadingZero(this.month+1)+"/"+this.year;b.title=p;b.style.cursor="pointer";new colClick(b,this);var s=document.createTextNode(a[k][g]);b.appendChild(s);if(p!=this.today){b.className="day"}else{b.className="day today"}if(g==6){b.className+=" sunday"}if(this.input.value==p){b.className+=" selected"}}else{b.innerHTML="&nbsp;"}q.appendChild(b)}ctable.appendChild(q)}this.oDiv.appendChild(ctable)}};function bind(a,b){return function(){b.call(a)}}function leadingZero(b){var a="";if(parseInt(b)<10){a="0"+b}else{a=b}return a}function doSomething(){fancyObj.input.value=this.title}function colClick(b,a){this.td=b;this.parent=a;this.td.onclick=bind(this,this.setValue)}colClick.prototype={setValue:function(){this.parent.input.value=this.td.title;this.parent.hideCalender()}};function Selector(b,c,a,d){this.img=new Image();this.img.src=b;this.img.style.width="6px";this.img.style.height="9px";this.img.style.marginRight="2px";this.img.style.cursor="pointer";this.img.alt="";this.img.title="";this.type=c;this.parent=d;this.move=a;this.img.onclick=bind(this,this.doMove)}Selector.prototype={doMove:function(){this.parent.alterMonth(this.move)}};
