function Calendar(id,lang,popupFunction) {
this.Id = id;
this.Lang = lang;
this.PopupFunction = popupFunction;
this.mnn=new Array('31','28','31','30','31','30','31','31','30','31','30','31');
this.mnl=new Array('31','29','31','30','31','30','31','31','30','31','30','31');
this.calvalarr=new Array(42);
this.now=new Date();
this.sccm=this.now.getMonth();
this.sccy=this.now.getFullYear();
this.ccm=this.now.getMonth();
this.ccy=this.now.getFullYear();
this.cnt=0;
this.lastDay=0;
if (this.Lang=="DK")
this.mn=new Array('JAN','FEB','MAR','APR','MAJ','JUN','JUL','AUG','SEP','OKT','NOV','DEC');
else
this.mn=new Array('JAN','FEB','MAR','APR','MAY','JUN','JUL','AUG','SEP','OCT','NOV','DEC');
this.PrintCal();
this.PrepCalendar('',this.ccm,this.ccy);
}
Calendar.prototype.Init = function(errTxtRoute,errTxtDate,urlNoBookingInfo,ie6hack,days,dayDD,monthDD,yearDD,testDD,routeDD) {
this.ErrTxtRoute = errTxtRoute;
this.ErrTxtDate = errTxtDate;
this.UrlNoBookingInfo = urlNoBookingInfo;
this.ie6hackFunction = ie6hack;
this.DisableIE6HackOnPageClick = false;
this.AvailableDays=days;
this.DayDD=dayDD;
this.MonthDD=monthDD;
this.YearDD=yearDD;
this.TestDD=testDD;
this.RouteDD=routeDD;
if (this.AvailableDays != null)
this.InitDropDowns();
this.now=new Date();
var nextDate = this.GetNextDate();
this.TestDD.value=nextDate.getDate()+"/"+(nextDate.getMonth()+1)+"/"+nextDate.getFullYear();
this.UpdateDD();
}
Calendar.prototype.FrontpageHack = function(top,left,disableIE6HackOnPageClick) {
this.Top = top;
this.Left = left;
this.DisableIE6HackOnPageClick = disableIE6HackOnPageClick;
}
Calendar.prototype.PrintCal = function() {
document.write('
');
document.write(' | |  |
');
if (this.Lang=="DK")
document.write('| M | T | O | T | F | L | S |
');
else
document.write('| M | T | W | T | F | S | S |
');
for(var kk=1;kk<=6;kk++) {
document.write('');
for(var tt=1;tt<=7;tt++) {
num=7 * (kk-1) - (-tt);
document.write('| | ');
}
document.write('
');
}
document.write('
');
addEventListener(document.body, "click", this.checkClick, this);
}
Calendar.prototype.PrepCalendar = function(hd,cm,cy) {
this.now=new Date();
this.sd=this.now.getDate();
this.td=new Date();
this.td.setDate(7);
this.td.setFullYear(cy);
this.td.setMonth(cm);
this.cd=this.td.getDay();
getObj(this.Id + '_mns').innerHTML=this.mn[cm]+ ' ' + cy;
this.marr=((cy%4)==0)?this.mnl:this.mnn;
for(var d=1;d<=42;d++) {
var x=getObj(this.Id + '_v'+parseInt(d));
f_cps(x);
if ((d >= (this.cd -(-1))) && (d<=this.cd-(-this.marr[cm]))) {
var dip=((d-this.cd < this.sd)&&(cm==this.sccm)&&(cy==this.sccy));
var htd=((hd!='')&&(d-this.cd==hd));
if (dip)
f_cpps(x);
else if (!this.DayAvailable(new Date(cy, cm, d-this.cd)))
{
f_cpps(x);
dip = true;
}
else if (htd)
f_hds(x);
else
f_cps(x);
x.onmouseover=(dip)?null:cs_over;
x.onmouseout=(dip)?null:cs_out;
if (!dip)
addEventListener(x, "click", this.cs_click, this);
x.style.height = 18 + "px";
x.style.width = 23 + "px";
x.innerHTML=d-this.cd;
this.calvalarr[d]=''+(d-this.cd)+'/'+(cm-(-1))+'/'+cy;
this.lastDay = (d-this.cd);
}
else
{
x.innerHTML=' ';
x.onmouseover=null;
x.onmouseout=null;
x.style.cursor='default';
}
if((d < 7) && (x.innerHTML == ' '))this.cnt++;
if((d > 7) && (x.innerHTML == ' '))
{
x.innerHTML='';
x.style.height = 0;
x.style.width = 0;
}
}
var fill = 7 - (this.lastDay+this.cnt)%7;
if(fill != 7)
{
var temp = fill+1;
while(temp-- != 0)
{
x=getObj(this.Id + '_v'+(this.lastDay+this.cnt+temp));
x.style.height = 18 + "px";
x.style.width = 23 + "px";
}
}
this.cnt=0;
}
Calendar.prototype.UpdateHiddenField = function()
{
this.TestDD.value = this.DayDD.value + '/' + this.MonthDD.value + '/' + this.YearDD.value;
}
Calendar.prototype.UpdateDD = function()
{
var x = this.TestDD.value.split('/');
var day = x[0];
var month = x[1];
var year = x[2];
SetDropDown(this.YearDD, year);
if (this.DayAvailable != null)
this.InitDropDownMonths();
SetDropDown(this.MonthDD, month);
if (this.DayAvailable != null)
this.InitDropDownDays();
SetDropDown(this.DayDD, day);
}
Calendar.prototype.SetDate = function(day, month, year) {
this.TestDD.value=day+"/"+month+"/"+year;
this.UpdateDD();
}
Calendar.prototype.lcs = function() {
this.ie6hackFunction(false);
var x = getObj(this.Id + '_fc').style;
if (this.Left == null)
x.left=Left(this.DayDD)-30 + "px";
else
x.left=this.Left + "px";
if (this.Top == null)
x.top=Top(this.DayDD)-50 + "px";//+posElm.offsetHeight;
else
x.top=this.Top + "px";
x.display='';
// First check date is valid
var curdt=this.TestDD.value;
var curdtarr=curdt.split('/');
var isdt=true;
for(var k=0;k=12) {
this.ccm=0;
this.ccy++;
}
this.cdayf();
this.PrepCalendar('',this.ccm,this.ccy);
}
Calendar.prototype.csubm = function() {
this.marr=((this.ccy%4)==0)?this.mnl:this.mnn;
this.ccm-=1;
if (this.ccm<0) {
this.ccm=11;
this.ccy--;
}
this.cdayf();
this.PrepCalendar('',this.ccm,this.ccy);
}
Calendar.prototype.cdayf = function() {
if ((this.ccy>this.sccy)|((this.ccy==this.sccy)&&(this.ccm>=this.sccm)))
return;
else {
this.ccy=this.sccy;
this.ccm=this.sccm;
//this.cfd=this.scfd;
}
}
Calendar.prototype.DayAvailable = function(obj){
if (this.AvailableDays == null)
return true;
var i = this.AvailableDays.length;
while (i--){
var date = new Date(Date.parse(this.AvailableDays[i]));
if (date.toString() == obj.toString())
return true;
}
return false;
}
Calendar.prototype.InitDropDowns = function(){
if (this.AvailableDays == null)
return;
addEventListener(this.YearDD, "change", this.InitDropDownMonths, this);
addEventListener(this.MonthDD, "change", this.InitDropDownDays, this);
this.InitDropDownYears();
}
Calendar.prototype.InitDropDownYears = function(){
if (this.AvailableDays == null)
return;
this.YearDD.options.length = 0;
// Fill years
for (var i = 0; i < this.AvailableDays.length; i++)
{
var date = new Date(Date.parse(this.AvailableDays[i]));
var year = date.getFullYear();
AppendInDropDown(this.YearDD, year, year);
}
this.InitDropDownMonths();
}
Calendar.prototype.InitDropDownMonths = function(){
if (this.AvailableDays == null)
return;
this.MonthDD.options.length = 0;
var selectedYear = GetSelectedValue(this.YearDD);
// Fill months
for (var i = 0; i < this.AvailableDays.length; i++)
{
var date = new Date(Date.parse(this.AvailableDays[i]));
var month = date.getMonth()+1;
var year = date.getFullYear();
if (year == selectedYear)
AppendInDropDown(this.MonthDD, month, month);
}
this.InitDropDownDays();
}
Calendar.prototype.InitDropDownDays = function(){
if (this.AvailableDays == null)
return;
this.DayDD.options.length = 0;
var selectedYear = GetSelectedValue(this.YearDD);
var selectedMonth = GetSelectedValue(this.MonthDD);
// Fill days
for (var i = 0; i < this.AvailableDays.length; i++)
{
var date = new Date(Date.parse(this.AvailableDays[i]));
var day = date.getDate();
var month = date.getMonth()+1;
var year = date.getFullYear();
if (month == selectedMonth && year == selectedYear)
AppendInDropDown(this.DayDD, day, day);
}
}
Calendar.prototype.GetNextDate = function(){
var today = new Date();
today.setFullYear(today.getFullYear(), today.getMonth(), today.getDay());
today.setHours(0,0,0,0);
if (this.AvailableDays == null)
return today;
for (var i = 0; i < this.AvailableDays.length; i++)
{
var date = new Date(Date.parse(this.AvailableDays[i]));
if (date >= today)
return date;
}
return today;
}
function addEventListener(element, eventName, eventHandler, scope) {
var scopedEventHandler = scope ? function(e) { eventHandler.apply(scope, [e]); } : eventHandler;
if(element.addEventListener)
element.addEventListener(eventName, scopedEventHandler, false);
else if(element.attachEvent)
element.attachEvent("on"+eventName, scopedEventHandler);
}
function getObj(objID)
{
if (document.getElementById) {return document.getElementById(objID);}
else if (document.all) {return document.all[objID];}
else if (document.layers) {return document.layers[objID];}
}
function f_cps(obj) {
obj.style.background='#C2C9DD';
obj.style.font='10px Arial';
obj.style.color='#1B295A';
obj.style.textAlign='center';
obj.style.textDecoration='none';
obj.style.border='1px solid #FFFFFF';
obj.style.cursor='pointer';
}
function f_cpps(obj) {
obj.style.background='#C2C9DD';
obj.style.font='10px Arial';
obj.style.color='#ABABAB';
obj.style.textAlign='center';
obj.style.textDecoration='line-through';
obj.style.border='1px solid #FFFFFF';
obj.style.cursor='default';
}
function f_hds(obj) {
obj.style.background='#F2C800';
obj.style.font='bold 10px Arial';
obj.style.color='#1B295A';
obj.style.textAlign='center';
obj.style.border='1px solid #FFFFFF';
obj.style.cursor='pointer';
}
function cs_over(e) {
x = evtTgt(EvtObj(e)).style;
x.background='#C2C9DD';
x.textDecoration='underline';
}
function cs_out(e) {
x=evtTgt(EvtObj(e)).style;
x.background='#C2C9DD';
x.textDecoration='none';
}
function Z(n){
return (n<10) ? "0"+n : n;
}
function evtTgt(e)
{
var el;
if(e.target)el=e.target;
else if(e.srcElement)el=e.srcElement;
if(el.nodeType==3)el=el.parentNode; // defeat Safari bug
return el;
}
function EvtObj(e){if(!e)e=window.event;return e;}
function isChild(s,d) {
while(s) {
if (s==d)
return true;
s=s.parentNode;
}
return false;
}
function Left(obj)
{
var curleft = 0;
if (obj.offsetParent)
{
while (obj.offsetParent)
{
curleft += obj.offsetLeft
obj = obj.offsetParent;
}
}
else if (obj.x)
curleft += obj.x;
return curleft;
}
function Top(obj)
{
var curtop = 0;
if (obj.offsetParent)
{
while (obj.offsetParent)
{
curtop += obj.offsetTop
obj = obj.offsetParent;
}
}
else if (obj.y)
curtop += obj.y;
return curtop;
}
function SetDropDown(dropdown, value)
{
var foundValue = false;
for(var i = 0; i < dropdown.options.length; i++)
{
if(dropdown.options[i].value == value)
{
dropdown.selectedIndex = i;
foundValue = true;
}
}
if (!foundValue)
dropdown.selectedIndex = 0;
}
function DropDownContains(dropdown, value)
{
for(var i = 0; i < dropdown.options.length; i++)
{
if(dropdown.options[i].value == value)
return true;
}
return false;
}
function AppendInDropDown(dropdown, text, value)
{
if (DropDownContains(dropdown, value))
return;
var option = document.createElement("option");
option.text = text;
option.value = value;
try {
dropdown.add(option, null); // standards compliant; doesn't work in IE
}
catch(e) {
dropdown.add(option); // IE only
}
}
function GetSelectedValue(dropdown)
{
var index = dropdown.selectedIndex;
return dropdown[index].value;
}