﻿function formatDate(date)
{
    if(date==null)return "";
    var longYear=date.getYear();
    if(longYear<1000)longYear+=1900;
    var shortYear=longYear;
    while(shortYear>100)
        shortYear-=100;
    if(shortYear<10)shortYear="0"+shortYear;
    var month=date.getMonth()+1;
    if(month<10)month="0"+month;
    var day=date.getDate();
    if(day<10)day="0"+day;
    shortYear=""+shortYear;
    return dateFormat.replace(/yyyy/g,shortYear).replace(/yy/g,shortYear).replace(/MMMM/g,month).replace(/MM/g,month).replace(/M/g,date.getMonth()).replace(/dd/g,day).replace(/d/g,date.getDate());
}

var inputDateFormat1=/^(..)\/(..)\/(....)/;
var inputDateFormat2=/^(..)\/(..)\/(..)/;
function parseDateOld(s){try{var sd;if(s.length==8)sd=s.replace(inputDateFormat2,"$2/$1/20$3");else sd=s.replace(inputDateFormat1,"$2/$1/$3");return new Date(sd);}catch(e){return null;}}
function parseDate(dateAsString)
{
    var dfy,dfm,dfd;
    if(dateAsString && (dateAsString.length==6 || dateAsString.length==8) && dateAsString.indexOf('/')<0)
    { //format ddmmyy or ddmmyyyy
        dfy="^"+ dateFormat.replace(/dd/g,"d").replace(/d/gi,"\\d?\\d").replace(/yyyy/g,"((?:\\d\\d)?\\d\\d)").replace(/yy/g,"(\\d\\d)").replace(/mm/gi,"\\d?\\d").replace(/m/gi,"\\d").replace(/\//g,"") + "$";
        dfm="^"+ dateFormat.replace(/dd/g,"d").replace(/d/gi,"\\d?\\d").replace(/yyyy/g,"(?:\\d\\d)?\\d\\d").replace(/yy/g,"\\d\\d").replace(/mm/gi,"(\\d?\\d)").replace(/m/gi,"(\\d)").replace(/\//g,"") + "$";
        dfd="^"+ dateFormat.replace(/dd/g,"d").replace(/d/gi,"(\\d?\\d)").replace(/yyyy/g,"(?:\\d\\d)?\\d\\d").replace(/yy/g,"\\d\\d").replace(/mm/gi,"\\d?\\d").replace(/m/gi,"\\d").replace(/\//g,"") + "$";
    }
    else
    {
        dfy="^"+ dateFormat.replace(/dd/g,"d").replace(/d/gi,"\\d?\\d").replace(/yyyy/g,"((?:\\d\\d)?\\d\\d)").replace(/yy/g,"(\\d\\d)").replace(/mm/gi,"\\d?\\d").replace(/m/gi,"\\d") + "$";
        dfm="^"+ dateFormat.replace(/dd/g,"d").replace(/d/gi,"\\d?\\d").replace(/yyyy/g,"(?:\\d\\d)?\\d\\d").replace(/yy/g,"\\d\\d").replace(/mm/gi,"(\\d?\\d)").replace(/m/gi,"(\\d)") + "$";
        dfd="^"+ dateFormat.replace(/dd/g,"d").replace(/d/gi,"(\\d?\\d)").replace(/yyyy/g,"(?:\\d\\d)?\\d\\d").replace(/yy/g,"\\d\\d").replace(/mm/gi,"\\d?\\d").replace(/m/gi,"\\d") + "$";
    }
    var dateFormatRegExYear=new RegExp(dfy,"g");
    var dateFormatRegExMonth=new RegExp(dfm,"g");
    var dateFormatRegExDay=new RegExp(dfd,"g");
    var yRes=dateFormatRegExYear.exec(dateAsString);
    var mRes=dateFormatRegExMonth.exec(dateAsString);
    var dRes=dateFormatRegExDay.exec(dateAsString);
    if(yRes!=null && mRes!=null && dRes!=null)
    {
        try
        {
        var date=new Date();
        var year=parseInt(yRes[1],10);
        if(year<100)year=year+2000;
        date.setFullYear(year,parseInt(mRes[1],10)-1,parseInt(dRes[1],10));
        date.setHours(0, 0, 0, 0);
        return date;
    } catch (e) { return undefined; }
    }
    else
        return undefined;
}

function OnQBLocationChange(hotelCode)
{

	qbResort.style.display="none";
	qbResortLabel.style.display="none";
	qbResortLabel.innerHTML="";
	try{while(qbResort.options.length>1){qbResort.remove(1);}}catch(ee){}
	var displayedResorts=0;
	for(var resortInd=0;resortInd<qbObj.resorts.length;resortInd++)
	{
		if(qbObj.resorts[resortInd].city==qbCity.value)
		{
			var opt=document.createElement('option');
			opt.innerHTML=qbObj.resorts[resortInd].name;
			opt.value=qbObj.resorts[resortInd].code;
			qbResortLabel.innerHTML=opt.innerHTML;
			qbResort.appendChild(opt);
			displayedResorts++;
			if(hotelCode && hotelCode==opt.value){qbResort.selectedIndex=displayedResorts;}
		}
	}
	if(displayedResorts>1)
	{qbResort.style.display="block";}
	else
	{
		if(displayedResorts>0)
		{
			qbResortLabel.style.display="block";
			qbResort.selectedIndex=1;
		}
	}
}

var qbCity;
var qbResort;
var qbResortLabel;
var qbAdults,qbChildren;
var qbRooms,qbIata,qbBlock;
var qbReserve;
var qbCalendar;
var longDateFormat,dateFormat;
var qbCheckIn,qbCheckOut;
var qbRateCode, qbCcn;

function QBInit(hotelCode,locale,dateFmt,longDateFmt,rate,ccn,iata,block){
	dateFormat=dateFmt;
	longDateFormat=longDateFmt;
	qbResort=document.getElementById("qbResort");
	qbResortLabel=document.getElementById("qbResortLabel");
	qbCity=document.getElementById("qbCity");
	qbAdults=document.getElementById("qbAdults");
	qbChildren=document.getElementById("qbChildren");
	qbRooms=document.getElementById("qbRooms");
	qbReserve=document.getElementById("qbReserve");
	qbIata=document.getElementById("qbIATA");
	if(block!=null && typeof(block)!="undefined")
		qbBlock=block;
	else
		qbBlock=null;

	if(rate!=null && typeof(rate)!="undefined" && rate.length)qbRateCode=rate;
	if(ccn!=null && typeof(ccn)!="undefined" && ccn.length)qbCcn=ccn;

	qbCity.onchange=OnQBLocationChange;
	qbReserve.onclick=function(){GoSearch(locale);};

	OnQBLocationChange(hotelCode);
	qbCheckIn=document.getElementById("qbCheckIn");
	qbCheckOut=document.getElementById("qbCheckOut");
	var qbCheckInI=document.getElementById("qbCheckInI");
	var qbCheckOutI=document.getElementById("qbCheckOutI");
	qbCalendar=new Calendar(qbCheckIn,qbCheckInI, qbCheckOut,qbCheckOutI, null, locale,true,"01234567");

	try{

	if(childrenInfoNotice.length>0){
		var qbChildrenNotice=document.getElementById("qbChildrenNotice");
		var notice=document.createElement("div");notice.innerHTML=childrenInfoNotice;
		notice.style.display="none";notice.className="childrenNotice";
		notice.style.position="absolute";notice.style.padding="5px";
		qbChildrenNotice.parentNode.insertBefore(notice,qbChildrenNotice);
		Observe(qbChildrenNotice, "mouseover", function(){notice.style.display="block";});
		Observe(qbChildrenNotice, "mouseout", function(){notice.style.display="none";});

	}
		}catch(ex){alert(ex.message)}
	RestaurantInit();
}
function RestaurantInit(options){
	if(typeof(restaurant)!="undefined")
	{
		var months=2;
		if(typeof(options)!="undefined" && options!==null){
			months=options.numberOfMonths;
		}
		var calendar=new Calendar(document.getElementById("restaurantdate"),document.getElementById("restaurantdateI"), null,null, null, locale,false,restaurant.days,months,restaurant.excludeFrom,restaurant.excludeTo);
		if(months==1){
			var combosToHide=["resthour","covers"];
			calendar.detach=function(){
				Calendar.prototype.detach.apply(calendar,[]);
				for(var cI=0;cI<combosToHide.length;cI++)
					document.getElementById(combosToHide[cI]).style.visibility="visible";
				
			};
		    calendar.attachTo=function(ctrl) {
				Calendar.prototype.attachTo.apply(calendar,[ctrl]);
				for(var cI=0;cI<combosToHide.length;cI++)
					document.getElementById(combosToHide[cI]).style.visibility="hidden";
		    };
		}
	}
}
function GoSearch(locale)
{
	var locationParameter=null;
	if(qbResort.selectedIndex<=0)
	{
		var cityEnglishName=qbCity.options[qbCity.selectedIndex].getAttribute("english");
		if(cityEnglishName)
		{locationParameter="&city="+encodeURIComponent(cityEnglishName);}
		else
		{
			window.alert(qbResortWarningText);
			return;
		}
	}
	else
	{
		var hotel=qbResort.options[qbResort.selectedIndex].value;
		if(hotel){locationParameter="&h="+encodeURIComponent(hotel);}
	}
	var blockParam;
	if(typeof(qbBlock)!="undefined" && qbBlock!=null)
		blockParam="&block="+encodeURIComponent(qbBlock);
	else
		blockParam="";
	var rateParam;
	if(typeof(qbRateCode)!="undefined" && qbRateCode!=null)
		rateParam="&rc="+encodeURIComponent(qbRateCode);
	else
		rateParam="";
	var ccnParam;
	if(typeof(qbCcn)!="undefined" && qbCcn!=null)
		ccnParam="&c="+encodeURIComponent(qbCcn);
	else
		ccnParam="";
	if(locationParameter)
	{document.location.href="http://webbooking.concorde-hotels.fr/?f="+encodeURIComponent(FormatDateIso(qbCheckIn.date))+"&d="+encodeURIComponent(FormatDateIso(qbCheckOut.date))+
    locationParameter+"&ro="+qbRooms.value+"&a="+qbAdults.value+"&k="+qbChildren.value+"&gtr=1&l="+locale+"&i="+encodeURIComponent(qbIata.value)+blockParam+ccnParam+rateParam;}
}
function FormatDateIso(date) {
	if(typeof(date)=="undefined" || date==null)return "";
    var longYear = date.getYear();
    if (longYear < 1000) longYear += 1900;
    var month = date.getMonth() + 1;
    if (month < 10) month = "0" + month;
    var day = date.getDate();
    if (day < 10) day = "0" + day;
    return ""+longYear + month + day;
}




function AttachCalendar(ctrl,ctrlI,locale,combosToHide){
	var calendar=new Calendar(document.getElementById(ctrl),document.getElementById(ctrlI), null,null, null, locale,false,"01234567");
	calendar.canGoInPast=true;
	if(typeof(combosToHide)!="undefined"){
		calendar.detach=function(){
			Calendar.prototype.detach.apply(calendar,[]);
	        if (this.containerClickedTimestamp != null && this.containerClickedTimestamp + 500 < (new Date().getTime())) {
			 	for(var cI=0;cI<combosToHide.length;cI++)
					document.getElementById(combosToHide[cI]).style.visibility="visible";
				this.containerClickedTimestamp=null;
			}
		};
	    calendar.attachTo=function(ctrl) {
			Calendar.prototype.attachTo.apply(calendar,[ctrl]);
						for(var cI=0;cI<combosToHide.length;cI++){
				document.getElementById(combosToHide[cI]).style.visibility="hidden";
				}
	    };
	}
}



var firstDayOfWeek=1;
var daysNames, fullDaysNames;
var monthsNames;
function CreateDelegate(object, method){var shim = function(){method.apply(object, arguments);};return shim;}
function $A(iterable) {if (!iterable) return [];if (iterable.toArray) return iterable.toArray();var length = iterable.length || 0, results = new Array(length);while (length--) results[length] = iterable[length];return results;}

Function.prototype.bindAsEventListener=function() {var __method = this, args = $A(arguments), object = args.shift();
  return function(event) {
        var rr=[event || window.event];
        for(var argsI=0;argsI<args.length;argsI++) {rr.push(args[argsI]);}
  	return __method.apply(object, rr)};};

Function.prototype.bind=function() {
	if (arguments.length < 2 && typeof(arguments[0])=="undefined") {return this;}
        var __method = this, args = $A(arguments), object = args.shift();
        return function() {
        var rr=$A(arguments);
        for(var rrI=0;rrI<rr.length;rrI++) {args.push(rr[rrI]);}
            return __method.apply(object, args);
        };
    };


function Observe(element, eventName, handler) {
if(element==null)return;
if (element.addEventListener) element.addEventListener(eventName, handler, false);
else element.attachEvent("on" + eventName, handler);
};
var Calendar = function(minDateCtrl,minDateCtrlI, maxDateCtrl,maxDateCtrlI, nightsCtrl, culture, displayStatus,days,numberOfMonths,excludeFrom,excludeTo) {
	if(typeof(numberOfMonths)!="undefined" && numberOfMonths!=null)	this.numberOfMonths=numberOfMonths;
    this.culture = culture.toLowerCase();
    if (this.culture == "jp") {firstDayOfWeek = 0;isYearBeforeMonth=true;}
    this.minDateCtrl = minDateCtrl;
    this.maxDateCtrl = maxDateCtrl;
    this.days=days;
    this.excludeFrom=excludeFrom;
    this.excludeTo=excludeTo;
    if(typeof(displayStatus)!="undefined")this.displayStatus=displayStatus;else this.displayStatus=true;
    if(minDateCtrl!=null)minDateCtrl.date = parseDate(minDateCtrl.value);
    if(maxDateCtrl!=null)maxDateCtrl.date = parseDate(maxDateCtrl.value);
    
    this.nightsCtrl = nightsCtrl;
    var table = document.createElement("table");
    table.cellSpacing = 0;
    var nextCell, previousCell, monthName, closeCell;
    this.monthLabelRow = table.insertRow(-1);
    var monthShift;
    for (monthShift = 0; monthShift < this.numberOfMonths; monthShift++) {
        if (monthShift === 0) {
            previousCell = this.monthLabelRow.insertCell(-1);
            previousCell.className = "lstcolor";
            Observe(previousCell, "click", CreateDelegate(this, this.previousMonth));
        }

        monthName = this.monthLabelRow.insertCell(-1);
        monthName.className = "lstcolor";

        if (monthShift === this.numberOfMonths - 1) {
            monthName.colSpan = 4+this.numberOfMonths;
            nextCell = this.monthLabelRow.insertCell(-1);
            nextCell.className = "lstcolor";
            nextCell.innerHTML = "<img src=\"/sharedImages/icons/right.wh.gif\" alt=\"\" width=\"13\" height=\"13\" />";
            nextCell.style.cursor = "pointer";
            Observe(nextCell, "click", CreateDelegate(this, this.nextMonth));

            closeCell = this.monthLabelRow.insertCell(-1);
            closeCell.className = "lstcolor";
            closeCell.innerHTML="<img src=\"/sharedImages/icons/close.wh.gif\" alt=\"\" width=\"13\" height=\"13\" />";
            Observe(closeCell, "click", CreateDelegate(this, this.detach));
        }
        else
            monthName.colSpan = 7;
    }
    if(this.numberOfMonths==1)monthName.colSpan=4;
    this.daysLabelRow = table.insertRow(-1);
    this.daysLabelRow.className = "daysLabelRow";

    this.daysRows = {};
    this.daysRows[0] = table.insertRow(-1);
    this.daysRows[1] = table.insertRow(-1);
    this.daysRows[2] = table.insertRow(-1);
    this.daysRows[3] = table.insertRow(-1);
    this.daysRows[4] = table.insertRow(-1);
    this.daysRows[5] = table.insertRow(-1);

    this.statusRow = table.insertRow(-1);
    this.statusRow.className = "statusRow";
    this.statusCell = this.statusRow.insertCell(-1);
    this.statusCell.colSpan = this.numberOfMonths * 8;

    var cellWidth = (100.0 / this.numberOfMonths / (7 + 1 / 3)) + "%";

    var mySelf = this;
    var sepCell;
    var dayCell;
    for (monthShift = 0; monthShift < this.numberOfMonths; monthShift++) {
        if (monthShift > 0) {
            sepCell = this.daysLabelRow.insertCell(-1);
            sepCell.width = (100.0 / this.numberOfMonths / (8 + 1 / 3) / 3) + "%";
            sepCell.innerHTML = "&nbsp;";
            for (var weekI = 0; weekI < 6; weekI++) {
                this.daysRows[weekI].insertCell(-1);
            }
            sepCell = this.daysLabelRow.insertCell(-1);
            sepCell.className = "separator";
            sepCell.width = (100.0 / this.numberOfMonths / (8 + 1 / 3) / 3) + "%";
            sepCell.innerHTML = "&nbsp;";
            for (var weekI = 0; weekI < 6; weekI++) {
                this.daysRows[weekI].insertCell(-1).className = "separator";
            }
        }
        for (var d = 1; d <= 7; d++) {
            dayCell = this.daysLabelRow.insertCell(-1);
            dayCell.innerHTML = daysNames[(d + firstDayOfWeek - 1) % 7];
            dayCell.width = cellWidth;

            for (var weekI = 0; weekI < 6; weekI++) {
                dayCell = this.daysRows[weekI].insertCell(-1);
                Observe(dayCell, "click", Calendar.prototype.cellClicked.bindAsEventListener(this,dayCell));
                Observe(dayCell, "mouseover", Calendar.prototype.cellOver.bindAsEventListener(this,dayCell));
                Observe(dayCell, "mouseout", Calendar.prototype.cellOut.bindAsEventListener(this,dayCell));
            }
        }
    }

    this.table = table;

    var bgDiv = document.createElement("div");

    bgDiv.style.height = table.style.height = "160px";
    bgDiv.style.width = table.style.width =(this.numberOfMonths*200)+"px";
    table.style.position = bgDiv.style.position = "absolute";
    bgDiv.style.zIndex = 2;
    bgDiv.style.background = "white";
    table.style.zIndex = 3;
    table.className = "calendar";

    this.container = document.createElement("div");
    this.container.appendChild(bgDiv);
    this.container.appendChild(table);
    this.container.style.width = table.style.width;
    this.container.style.position = "absolute";
    this.container.style.zIndex = 1;
    this.container.id="calendarContainer";

    var bodyClickedFx = Calendar.prototype.bodyClicked.bind(this);
    var mySelf = this;
    var bodyClickedFxTimeout = function() { window.setTimeout(Calendar.prototype.bodyClicked.bind(mySelf), 300); };
    Observe(document.body, "click", bodyClickedFx);
    Observe(minDateCtrl, "focus", Calendar.prototype.open.bind(this, true));
    Observe(minDateCtrlI, "click", Calendar.prototype.open.bind(this, true));
    Observe(minDateCtrl, "keyup", Calendar.prototype.detach.bind(this));
    Observe(minDateCtrl, "change", Calendar.prototype.inputChanged.bind(this, true, false));
    Observe(minDateCtrl, "keyup", Calendar.prototype.inputChanged.bind(this, true, true));
    Observe(minDateCtrl, "blur", bodyClickedFxTimeout);
    if(maxDateCtrl!=null){
    Observe(maxDateCtrl, "focus", Calendar.prototype.open.bind(this, false));
    Observe(maxDateCtrlI, "click", Calendar.prototype.open.bind(this, false));
    Observe(maxDateCtrl, "keyup", Calendar.prototype.detach.bind(this));
    Observe(maxDateCtrl, "change", Calendar.prototype.inputChanged.bind(this, false, false));
    Observe(maxDateCtrl, "keyup", Calendar.prototype.inputChanged.bind(this, false, true));
    Observe(maxDateCtrl, "blur", bodyClickedFxTimeout);
    }

    Observe(this.container, "click", Calendar.prototype.containerClicked.bind(this));
    Observe(this.container, "mouseout", Calendar.prototype.mouseOut.bind(this));

};

Calendar.prototype =
{
    numberOfMonths: 2,
    onDateClick: null,
    minDateCtrl: null,
    maxDateCtrl: null,
    nightsCtrl: null,
    excludeFrom:undefined,
    excludeTo:undefined,
    onMinDate: true,
    target: null,
    culture: "",
    days:"",
    displayStatus:null,
    containerClickedTimestamp: null,
    containerClicked: function() {
        this.containerClickedTimestamp = new Date().getTime();
    },
    inputChanged: function(onMin, noUIchange) {
        var field = onMin ? this.minDateCtrl : this.maxDateCtrl;
        field.date = parseDate(field.value);
        if (typeof (field.date) != "undefined")
            field.parentNode.className = "field";
        else {
            if (noUIchange !== true) {
                field.value = "";
                field.parentNode.className = "field error";
            }
        }
        if (onMin && typeof (field.date) != "undefined" && this.maxDateCtrl!=null) {
            if (typeof (this.maxDateCtrl.date) != "undefined" && field.date.getTime() >= this.maxDateCtrl.date.getTime()) {
                this.maxDateCtrl.date = undefined;
                this.maxDateCtrl.value = "";
            }
            if (typeof (this.maxDateCtrl.date) == "undefined" && noUIchange !== true) {
                this.maxDateCtrl.date = new Date(field.date.getTime() + 24 * 3600000);
                this.maxDateCtrl.date.setHours(0, 0, 0, 0);
                this.maxDateCtrl.value = formatDate(this.maxDateCtrl.date);
            }
        }
        this.detach();
    },
    bodyClicked: function() {
        if (this.containerClickedTimestamp == null || this.containerClickedTimestamp + 300 < (new Date().getTime())) {
            this.detach();
        }
    },

    getParent: function() {
        return this.container.parentNode;
    },
    detach: function() {
        this.target = null;
        if (this.container.parentNode) { this.container.parentNode.removeChild(this.container); }
        this.container.style.display = "none";
    },
    open: function(onMinDate) {
        this.onMinDate = onMinDate;
        this.attachTo(onMinDate ? this.minDateCtrl : this.maxDateCtrl);
    },
    attachTo: function(ctrl) {
        this.containerClicked();
        this.container.style.display = "block";
        this.target = ctrl;
        if (this.container.parentNode == ctrl.parentNode) return;
        if (this.container.parentNode) this.container.parentNode.removeChild(this.container);
        if (!ctrl.date) {
			this.displayedDate = new Date();
			this.displayedDate.setHours(0,0,0,0);
            this.displayedDate = this.displayedDate.getTime() + 24 * 60 * 60 * 1000;
            if (ctrl == this.maxDateCtrl && typeof (this.minDateCtrl.date) != "undefined") {
                this.displayedDate = this.minDateCtrl.date;
            }
        }
        else this.displayedDate = ctrl.date;
        this.refresh(this.displayedDate);
        if(this.numberOfMonths!=1){
	        this.container.style.marginLeft = (ctrl.parentNode.clientWidth||83) + "px";
	    }
        ctrl.parentNode.insertBefore(this.container, ctrl.parentNode.firstChild);
        this.containerClickedTimestamp = new Date().getTime();
    },
    nextMonth: function() {
        this.displayedDate = new Date(this.displayedDate);
        this.displayedDate.setDate(15);
        this.displayedDate = new Date(this.displayedDate.getTime() + 20 * 24 * 60 * 60 * 1000);
        this.displayedDate.setDate(15);
        this.containerClicked();
        this.refresh();
    },
    canGoInPast:false,
    previousMonth: function() {
        var possibleDate = new Date(this.displayedDate);
        possibleDate.setDate(15);
        possibleDate = new Date(possibleDate.getTime() - 20 * 24 * 3600000);
        possibleDate.setDate(1);

		if(!this.canGoInPast){
		        var minLocalDate = new Date();
		        minLocalDate.setDate(1);
		        minLocalDate.setHours(0, 0, 0, 0);
		        this.containerClicked();
		        if (possibleDate < minLocalDate) return;
		}
        this.displayedDate = possibleDate;
        this.refresh();
    },
    checkDates: function() {
        var arrv = this.minDateCtrl.date;
        var dept = this.maxDateCtrl.date;
        this.minDateCtrl.parentNode.className = "field";
        this.maxDateCtrl.parentNode.className = "field";
        var ok = true;
        if (typeof (arrv) == "undefined") {
            this.minDateCtrl.parentNode.className = "field error";
            ok = false;
        }
        if (typeof (dept) == "undefined") {
            this.maxDateCtrl.parentNode.className = "field error";
            ok = false;
        }
        if (typeof (arrv) != "undefined" && typeof (dept) != "undefined" && dept <= arrv) {
            this.maxDateCtrl.parentNode.className = "field error";
            alert(invalidDepartureDate);
            ok = false;
        }
        return ok;
    },
    cellClicked: function(evt,src) {
        if (this.target != null && typeof (src.date) != "undefined") {
            this.target.value = formatDate(src.date);
            this.target.date = src.date;
            this.target.parentNode.className = "field";
			if(this.onMinDate && this.maxDateCtrl!=null && typeof(this.maxDateCtrl.date )=="undefined"){
                this.maxDateCtrl.date = new Date(src.date.getTime() + 24 * 3600000);
                this.maxDateCtrl.date.setHours(0, 0, 0, 0);
                this.maxDateCtrl.value = formatDate(this.maxDateCtrl.date);
			}
            this.containerClickedTimestamp = new Date().getTime();
            this.detach();
        }
    },
    cellOver: function(evt,src) {
        if (src.date != undefined) {
            src.className = "over";
        }
        this.setStatus(src.date);
    },
    cellOut: function(evt,src) {
        src.className = src.standardClassName;
    },
    mouseOut: function() {
        this.setStatus(this.onMinDate ? this.minDateCtrl.date : this.maxDateCtrl.date);
    },
    isDateVisible: function(date) {
        if (!this.displayedDate) return false;
        var firstDisplayedDate = new Date(this.displayedDate.getTime() + 20 * 24 * 60 * 60 * 1000);
        firstDisplayedDate.setDate(1);
        var lastDisplayedDateExcluded = new Date(this.displayedDate.getTime() + (30.5 * this.numberOfMonths + 20) * 24 * 60 * 60 * 1000);
        lastDisplayedDateExcluded.setDate(1);
        return date.getTime() >= firstDisplayedDate.getTime() && date.getTime() <= lastDisplayedDateExcluded.getTime();
    },
    ensureDateIsVisible: function(date) {
        if (this.isDateVisible(date))
            this.refresh();
        else
            this.refresh(date);
    },
    setStatus: function(date) {
        if (date != null && typeof (date) != "undefined") {
            var longYear = date.getYear(); if (longYear < 1000) longYear += 1900;
            var shortYear = longYear; while (shortYear > 1000) shortYear -= 1000;
            var month = date.getMonth() + 1; if (month < 10) month = "0" + month;
            var day = date.getDate(); if (day < 10) day = "0" + day;
            var monthName = monthsNames[date.getMonth()];
            var dayName = fullDaysNames[date.getDay()];
            var dateFormatted = longDateFormat.replace(/{dddd}/g, dayName).replace(/{yyyy}/g, longYear).replace(/{yy}/g, shortYear).replace(/{MMMM}/g, monthName).replace(/{MM}/g, month).replace(/{M}/g, date.getMonth() + 1).replace(/{dd}/g, day).replace(/{d}/g, date.getDate())
            var label;
            if(this.displayStatus)label=this.onMinDate ? arrivalLongLabel : departureLongLabel;
            else label="{0}";
            this.statusCell.innerHTML = label.replace(/\{0\}/g, dateFormatted);
        }
        else
            this.statusCell.innerHTML = "&nbsp;";
    },
    refresh: function(displayedDateAtLeft) {

        if (!displayedDateAtLeft) displayedDateAtLeft = this.displayedDate;
        else this.displayedDate = new Date(displayedDateAtLeft);
        this.displayedDate.setDate(15);
        this.displayedDate.setHours(0, 0, 0, 0); //Remove the time component
        var targetTime = 0, spanStartTime = NaN, spanEndTime = NaN;
        var targetDate = null;
        if (this.onMinDate) {
            if (typeof (this.minDateCtrl.date) != "undefined") {
                targetDate = this.minDateCtrl.date;
                spanStartTime = targetTime = this.minDateCtrl.date.getTime();
                if (this.maxDateCtrl!=null && typeof (this.maxDateCtrl.date) != "undefined")
                    spanEndTime = this.maxDateCtrl.date.getTime();
            }
        } else {
            if (typeof (this.maxDateCtrl.date) != "undefined") {
                targetDate = this.maxDateCtrl.date;
                spanEndTime = targetTime = this.maxDateCtrl.date.getTime();
                if (typeof (this.minDateCtrl.date) != "undefined")
                    spanStartTime = this.minDateCtrl.date.getTime();
            }
        }
        this.setStatus(targetDate);
        var displayedDateTime = this.displayedDate.getTime();

        var minTime = new Date();
        if(this.canGoInPast)
	        minTime=new Date(new Date().getTime()-365*24*3600000);
        else
	        minTime = new Date();
        if (this.target == this.maxDateCtrl && typeof (this.minDateCtrl.date) != "undefined" && this.minDateCtrl.date > minTime)
            minTime = new Date(this.minDateCtrl.date.getTime() + 24 * 3600000);
        minTime.setHours(0, 0, 0, 0);
        
        var excludeFromTime,excludeToTime;
        if(typeof(this.excludeFrom)!="undefined")excludeFromTime=this.excludeFrom;
        else excludeFromTime=new Date(2000,0,1);
        if(typeof(this.excludeTo)!="undefined")excludeToTime=this.excludeTo;
        else excludeToTime=new Date(2000,0,1);
        excludeFromTime.setHours(0, 0, 0, 0);
        excludeToTime.setHours(0, 0, 0, 0);

        var firstDisplayedDate = new Date(displayedDateTime);
        firstDisplayedDate.setDate(1);
        var previousCell = this.monthLabelRow.cells[0];
        if ((firstDisplayedDate.getTime() - (24 * 60 * 60 * 1000) > minTime)) {//Add the previous month link
            previousCell.innerHTML = "<img src=\"/sharedImages/icons/left.wh.gif\" alt=\"\" width=\"13\" height=\"13\" />";
            previousCell.style.cursor = "pointer";
        }
        else {
            previousCell.innerHTML = "";
            previousCell.style.cursor = "default";
        }

        var cellInactive,cellTime;

        for (var monthShift = 0; monthShift < this.numberOfMonths; monthShift++) {
            firstDisplayedDate = new Date(displayedDateTime + monthShift * 20 * 24 * 60 * 60 * 1000);
            firstDisplayedDate.setDate(1);
            var year = (firstDisplayedDate.getYear() < 1000) ? firstDisplayedDate.getYear() + 1900 : firstDisplayedDate.getYear();
            var monthCell = this.monthLabelRow.cells[monthShift + 1];
            if (typeof(isYearBeforeMonth)!="undefined" && isYearBeforeMonth) {
                if (this.culture == "jp")
                    monthCell.innerHTML = year + "年 " + monthsNames[firstDisplayedDate.getMonth()];
                else
                    monthCell.innerHTML = year + " " + monthsNames[firstDisplayedDate.getMonth()];
            }
            else {
                monthCell.innerHTML = monthsNames[firstDisplayedDate.getMonth()] + " " + year;
            }
            monthCell.style.textAlign = "center";


            if (firstDisplayedDate.getDay() != firstDayOfWeek) {//Go to the first day of the week that is before the first day of the month
                firstDisplayedDate.setHours(0, 0, 0, 0);
                if (firstDisplayedDate.getDay() == ((firstDayOfWeek + 6) % 7))
                    firstDisplayedDate = new Date(firstDisplayedDate - 6 * 24 * 60 * 60 * 1000 + 120 * 60 * 1000);
                else
                    firstDisplayedDate = new Date(firstDisplayedDate - (firstDisplayedDate.getDay() - firstDayOfWeek) * 24 * 60 * 60 * 1000 + 120 * 60 * 1000);
            }
            firstDisplayedDate.setHours(0, 0, 0, 0);
            for (var d = 1; d <= 7; d++) {
                for (var weekI = 0; weekI < 6; weekI++) {
                    var cell = this.daysRows[weekI].cells[d - 1 + monthShift * 9];
                    var cellDate = new Date(firstDisplayedDate.getTime() + (weekI * 7 + d - 1) * 24 * 60 * 60 * 1000 + 120 * 60 * 1000);
                    cellDate.setHours(0, 0, 0, 0);
                    var cellTime = cellDate.getTime();
                    var cellIsEmpty = false;
                    if (cellDate.getMonth() != (this.displayedDate.getMonth() + monthShift) % 12) {
                        cell.className = "otherMonth";
                        cellIsEmpty = true;
                        //if (cellDate.getMonth() == (this.displayedDate.getMonth() + monthShift + 11) % 12 && monthShift != 0)
                        //    cellIsEmpty = true; //Previous month
                        //if (cellDate.getMonth() == (this.displayedDate.getMonth() + monthShift + 1) % 12 && monthShift != this.numberOfMonthsDisplayed - 1)
                        //    cellIsEmpty = true; //Next month
                    }
                    else
                        cell.className = "";
                    if (!cellIsEmpty) {
                        cell.innerHTML = cellDate.getDate();
                    }
                    else {
                        cell.innerHTML = "&nbsp;";
                    }
                    cell.style.cursor = "default";

                    if (!cellIsEmpty) {

                        if (targetTime == cellTime)
                            cell.className = "selDate";
                        else {
                            if (spanStartTime <= cellTime && cellTime <= spanEndTime) {
                                if (d == 1 || spanStartTime == cellTime){
	                                if (d == 7 || spanEndTime == cellTime)
	                                    cell.className = "firstAltDate lastAltDate altDate";
                                    else
	                                    cell.className = "firstAltDate altDate";
                                }
                                else if (d == 7 || spanEndTime == cellTime)
                                    cell.className = "lastAltDate altDate";
                                else
                                    cell.className = "altDate";
                            }
                        }
                    }
                    cellTime=cellDate.getTime();
                    if (cellTime < minTime || this.days.indexOf(""+((d+firstDayOfWeek-1)%7))<0 || cellTime>=excludeFromTime && cellTime<=excludeToTime) {
                        cellInactive = true;
                        if (cell.className != "firstAltDate altDate")
                            cell.className = "disabledDate";
                    }
                    else {
                        cellInactive = false;
                    }
                    cell.standardClassName = cell.className;

                    if (!cellIsEmpty && !cellInactive) {
                        cell.style.cursor = "pointer";
                        cell.date = cellDate;
                    }
                    else
                        cell.date = undefined;
                }
            }
        }
    }
};



