<!--
var CheckInDate = '';

var isNoFirefox = (navigator.userAgent.indexOf('Firefox')==-1);
var isChrome = (navigator.userAgent.indexOf('Chrome')!=-1);
var isOpenInChrome = false;


var closeCalendarTimeOut = 0;
var activeCalendarName = '';

if(isChrome){
	addEvent(document, 'click', hideCalendarChrome);
}else{
	addEvent(document, 'click', hideCalendar);
}

addEvent(window, 'resize', hideCalendar);


var pixelSpacer = '<div style="width: 1px; height: 1px;"><spacer type="block" width="1" height="1" /><\/div>';




var LSCalendars=new Array();


//--------------------------------------------------------------------------------------------------------------------------


function getCalendarDate(name) {
    if (!LSCalendars[name].GetDate()) { return (new Date()); }
    else { return LSCalendars[name].GetDate(); }

//    return LSCalendars[name].GetDate();
}



function setDateForCalendar(dayToSet, monthToSet, yearToSet) {

    if (!LSCalendars[activeCalendarName].GetDate()) { var dateToSet = new Date(); }
    else { var dateToSet = LSCalendars[activeCalendarName].GetDate(); }

    dateToSet.setFullYear(yearToSet);
    dateToSet.setMonth(monthToSet,1);
    dateToSet.setDate(dayToSet);

	if (activeCalendarName.indexOf("checkin") != -1) CheckInDate = dateToSet;

    LSCalendars[activeCalendarName].SetDate(dateToSet);
    setInputByLSCalendar(activeCalendarName);   

    hideCalendar();
}



function setCalendarDateByStr(name, strDate) {
    if (strDate==null || strDate=="") { // если пустая строка
        LSCalendars[name].SetDate(null);
    } 
    else {
        MyCal=new LSCalendar();
        if (!MyCal.Validate(strDate)) {
            alert(calendarNames.bad_format + " - "+strDate);
            return false;
        }
        else {
            LSCalendars[name].SetDate(strDate);
            setInputByLSCalendar(name);
            return true;
        }
    }
    closeCalendarTimeOut = 0; 
}



function setInputByLSCalendar(name) {
    document.getElementsByName(name)[0].value=LSCalendars[name].GetStrDate();
    return true;
}



function setTodayFromCalendar() {
    var date=new Date();
    setDateForCalendar(date.getDate(),date.getMonth(),date.getFullYear());
}



function ChangeElVis(MyVisibility) {
    var calLeer = document.getElementById('candarLeer');
    
    if ((MyVisibility=='hide') || (MyVisibility=='hidden')) { MyVisibility='hidden'; }
    else { MyVisibility='visible'; }
    

    var calPosition = new getElementPosition(calLeer);
    
    CalTop=calPosition.y;
//    CalLeft=Math.round(calPosition.x-calLeer.offsetWidth/3*2);
    CalLeft=calPosition.x;
    CalBottom=CalTop+calLeer.clientHeight;
    CalRight=CalLeft+calLeer.clientWidth;
//    alert(CalTop+"x"+CalLeft+"x"+CalBottom+"x"+CalRight); 


    // select
    for (var i=0; i<document.getElementsByTagName("select").length; i++) {
        Cu=document.getElementsByTagName("select")(i);
        if (Cu.name=='calMonth') { continue; } 


        var CuPosition=new getElementPosition(Cu);
        CuTop=CuPosition.y;
        CuLeft=CuPosition.x;
        CuBottom=CuTop+Cu.clientHeight;
        CuRight=CuLeft+Cu.clientWidth;
//        alert(CuTop+"x"+CuLeft+"x"+CuBottom+"x"+CuRight); 

        if ((CuLeft<=CalLeft)&&(CuRight>=CalLeft)||
            (CuLeft>=CalLeft)&&(CuRight<=CalRight)||
            (CuLeft<=CalRight)&&(CuRight>=CalRight)) {

            if ((CuTop<=CalTop)&&(CuBottom>=CalTop)||
                (CuTop>=CalTop)&&(CuBottom<=CalBottom)||
                (CuTop<=CalBottom)&&(CuBottom>=CalBottom)) {
                Cu.style.visibility = MyVisibility;
            }
        }
    }


    // iframe
    for (var i=0; i<document.getElementsByTagName("iframe").length; i++) {
        Cu=document.getElementsByTagName("iframe")(i);


        var CuPosition=new getElementPosition(Cu);
        CuTop=CuPosition.y;
        CuLeft=CuPosition.x;
        CuBottom=CuTop+Cu.clientHeight;
        CuRight=CuLeft+Cu.clientWidth;
//        alert(CuTop+"x"+CuLeft+"x"+CuBottom+"x"+CuRight); 

        if ((CuLeft<=CalLeft)&&(CuRight>=CalLeft)||
            (CuLeft>=CalLeft)&&(CuRight<=CalRight)||
            (CuLeft<=CalRight)&&(CuRight>=CalRight)) {

            if ((CuTop<=CalTop)&&(CuBottom>=CalTop)||
                (CuTop>=CalTop)&&(CuBottom<=CalBottom)||
                (CuTop<=CalBottom)&&(CuBottom>=CalBottom)) {
                Cu.style.visibility = MyVisibility;
            }
        }
    }

    return true;
}


function showCalendarForElement(elemName, evt, defaultDate, isLeft) {
    if(isChrome)
		isOpenInChrome=true;
	
	var calPtr = document.getElementById(elemName + 'Ptr');
    if (calPtr) {

        var calLeer = document.getElementById('candarLeer');
        if (!calLeer) {
            calLeer = document.createElement('div');
            calLeer.id = 'candarLeer';
            document.getElementsByTagName('body')[0].appendChild(calLeer);
        }
        

        if (calLeer.style.visibility=='visible' && activeCalendarName==elemName) {
            calLeer.style.visibility = 'hidden';
	if(isNoFirefox)            
	ChangeElVis('visible');
        }
        else {
            activeCalendarName = elemName;

            calLeer.style.visibility = 'hidden';

            var calPosition = new getElementPosition(calPtr);


            var currDate = getCalendarDate(elemName);


            CDate=currDate.getDate()+"-"+currDate.getMonth()+"-"+currDate.getFullYear();
            TDate=(new Date()).getDate()+"-"+(new Date()).getMonth()+"-"+(new Date()).getFullYear();
            if (CDate==TDate) {
                if (typeof(defaultDate)=="object" && defaultDate) { currDate=defaultDate; }
            }
                                    
		if (activeCalendarName.indexOf("checkout") != -1 && CheckInDate != '' && currDate < CheckInDate) currDate = CheckInDate;

            calLeer.innerHTML = calendarHTML(currDate.getMonth(), currDate.getFullYear(), currDate);

            if (isLeft==true) {
                calLeer.style.left = calPosition.x-calLeer.offsetWidth;
                calLeer.style.top = calPosition.y;
            }
            else {
                calLeer.style.left = calPosition.x+150;
//                calLeer.style.left = calPosition.x - calLeer.offsetWidth/3*2;
                calLeer.style.top = calPosition.y+30;
            }
                        

            calLeer.style.visibility = 'visible';
        	if(isNoFirefox)    
		ChangeElVis('hidden');


            if (evt) { evt.cancelBubble = true; }
            

            addEvent(calLeer, 'click', calendarClick);

            addEvent(calLeer, 'mouseover', calendarMouseOver);
            addEvent(calLeer, 'mouseout', calendarMouseOut);
        }
    }
}


function calendarClick(e) {
    evt = (e)? e : window.event;
    evt.cancelBubble = true;
}


function calendarMouseOver(e) {
    if (closeCalendarTimeOut) {
        clearTimeout(closeCalendarTimeOut);
        closeCalendarTimeOut = 0;
    }
}


function calendarMouseOut(e) {
    if (closeCalendarTimeOut) {
        clearTimeout(closeCalendarTimeOut);
    }
//    closeCalendarTimeOut = setTimeout('hideCalendar()', 5000);
}



function hideCalendarChrome() {
	var calLeer = document.getElementById('candarLeer');	
	if(calLeer.style.visibility=='visible' && isOpenInChrome==false){        			
			calLeer.style.visibility = 'hidden';
	}
	
	if(isOpenInChrome==true) isOpenInChrome=false;
}


function hideCalendar() {
    var calLeer = document.getElementById('candarLeer');
    if (calLeer) {
		
		
		if(isChrome && calLeer.style.visibility=='visible'){        
			calLeer.style.visibility = 'hidden';
		}
		
				
	if(isNoFirefox)        
	ChangeElVis('show');
        calLeer.style.visibility = 'hidden';							
    }			
    closeCalendarTimeOut = 0;
}


function switchMonthTo(month, year) {
    var calLeer = document.getElementById('candarLeer');
    if (calLeer) {
        var currDate = getCalendarDate(activeCalendarName);

        calLeer.innerHTML = calendarHTML(month, year, currDate);
    }
	if(isChrome) isOpenInChrome=true;
}


function calendarHTML(month, year, currDate) {

    var isThisMonth = (currDate)? (currDate.getMonth() == month && currDate.getFullYear() == year) : false;
    var drawMonth = new Date();
    drawMonth.setMonth(month, 1);
    drawMonth.setYear(year);
    drawMonth.setDate(1);
    

    var thisMonth = drawMonth.getMonth();
    var nextMonth = (thisMonth == 11)? 0 : thisMonth + 1;
    var prevMonth = (thisMonth == 0)? 11 : thisMonth - 1;
    
    var thisYear = drawMonth.getFullYear();
    var nextYear = thisYear + 1;
    var prevYear = thisYear - 1;
    var nextMonthYear = (thisMonth == 11)? thisYear + 1 : thisYear;
    var prevMonthYear = (thisMonth == 0)? thisYear - 1 : thisYear;
    

    // #D7D7D7
    var calendarCode = '<div style="width: 176px;background: #fff;border: solid 3px #DF0004;">';
	
	calendarCode += '<table cellspacing="0" cellpadding="0" align="center"><tr><td>';	
     calendarCode += '<table border="0" width="100%"><tr>';

    calendarCode += '<td align="left" class="arrowMonth"><a href="javascript:void(0);" onClick="switchMonthTo(' + prevMonth + ', ' + prevMonthYear + ')">&#8592;</a><\/td>';

    calendarCode += '<td class="monthYear" align="center">' + calendarNames.month[thisMonth] + '&nbsp;'+thisYear+'<\/td>';
    //calendarCode += '<td align="center">' + thisYear + '<\/td>';


    calendarCode += '<td align="right" class="arrowMonth"><a href="javascript:void(0);" onClick="switchMonthTo(' + nextMonth + ', ' + nextMonthYear + ')"/>&#8594;<\/a><\/td>';
    calendarCode += '<\/tr><\/table>';

  
    calendarCode += '<table border="0" cellspacing="2" cellpadding="0" align="center" width="100%"><tr>';
    /*calendarCode += '<th><br />s<\/th><th>d<br /><\/th>';*/


     for (var i = 0; i < calendarNames.weekday.length; i++) {
        var styleClass = (i < calendarNames.weekday.length - 1)? 'whiteCell' : 'sundayCell';
        calendarCode += '<th class="'+styleClass+'">' + calendarNames.weekday[i] + '<\/th>';
    }

    calendarCode += '<tr>';
	
	
	var prevMonthDaysNumber = daysInMonth( thisMonth,  year );//1-January

    var daysToStart = (drawMonth.getDay() == 0)? 7 : drawMonth.getDay();
    for (var i = daysToStart - 2; i >= 0; i--) calendarCode += '<td class="emptyCell">'+(prevMonthDaysNumber-i)+'<\/td>';


    for (var i = 1; i < 33; i++) {
        drawMonth.setDate(i);
        if (isThisMonth && i == currDate.getDate()) {
            calendarCode += '<td  class="currDayCell" align="right" onMouseOver="this.style.background = \'#DF0004\';this.style.color=\'#fff\'" onMouseOut="this.style.background = \' #DF0004\';this.style.color=\'#fff\'" onClick="setDateForCalendar(' + i + ', ' + month + ', ' + year + ');" style="cursor: pointer; cursor: hand;">' + i + '<\/td>'
        }
        else {
            if (drawMonth.getMonth() == thisMonth) {
                var styleClass = (drawMonth.getDay() == 0)? 'justCell' : 'justCell'
                calendarCode += '<td class="' + styleClass + '" align="right" onMouseOver="this.style.background = \'#DF0004\';this.style.color=\'#fff\'" onMouseOut="this.style.background = \' #ECECBB\';this.style.color=\'#555555\'" onClick="setDateForCalendar(' + i + ', ' + month + ', ' + year + ');" style="cursor: pointer; cursor: hand;">' + i + '<\/td>';								
            }
            else {
                break;
            }
        }
        /*if (drawMonth.getDay() == 0) calendarCode += '<td>as<br /><\/td><td>sa<br /><\/td><\/tr><tr><td>sa<br /><\/td><td>sa<br /><\/td>';*/
        if (drawMonth.getDay() == 0) calendarCode += '<\/tr><tr>';
    }


    if (drawMonth.getDay() != 1) {
        var daysToEnd = 8 - ((drawMonth.getDay() == 0)? 7 : drawMonth.getDay());
        for (var i = 0; i < daysToEnd; i++) calendarCode += '<td class="emptyCell" align="right">'+(i+1)+'<\/td>';
    }
   /* calendarCode += '<td><br /><\/td><td><br /><\/td><\/tr><\/table>';*/
    calendarCode += '<\/tr><\/table>';	
	calendarCode += '<\/td><\/tr><\/table>';
	calendarCode += '<\/div>';

    return calendarCode;
}


function getElementPosition(elemPtr) {
    var posX = elemPtr.offsetLeft;
    var posY = elemPtr.offsetTop;

    while (elemPtr.offsetParent != null) {
        elemPtr = elemPtr.offsetParent;
        posX += elemPtr.offsetLeft;
        posY += elemPtr.offsetTop;
    }
    this.x = posX;
    this.y = posY;
    
    return this;
}


function addEvent(Obj, eventType, eventFunc) {
    if (Obj.addEventListener) { Obj.addEventListener(eventType, eventFunc, false); }
    else if (Obj.attachEvent) { Obj.attachEvent('on'+eventType, eventFunc); }
    else {

    }
}


function LSCalendar() {

    this.date=null;
    this.format='dd-mm-yyyy';
    

    this.SetDate=_SetDate;
    this.GetStrDate=_GetStrDate;
    this.GetDate=_GetDate;
    this.Str2Date=_Str2Date;
    this.zeroFill=_zeroFill;
    this.Validate=_Validate;
    this.SetFormat=_SetFormat;
    
    return true;
}


function _SetDate(Date) {
    if (Date==null || Date=="") { this.date=null; }
    else if (typeof(Date)=="object") { this.date=Date; }
    else { this.date=this.Str2Date(Date)?this.Str2Date(Date):(new Date()); }

    return true;
}


function _GetDate() {
    return this.date;
}

//
function _zeroFill(value) {
    return (value<10?'0':'')+value;
}



function _GetStrDate() {
    if (!this.date) {
        return "";
    }
    else {
        var Day=this.zeroFill(this.date.getDate());
        var Month=this.zeroFill(this.date.getMonth()+1);
        var Year=this.date.getFullYear();
        var shortYear=this.date.getYear();

        if (shortYear>=2000) { shortYear-=2000; } 
        else if (shortYear>=100) { shortYear-=100; } 

        shortYear=this.zeroFill(shortYear);
    
        if (this.format=='dd-mm-yy') { return Day+'-'+Month+'-'+shortYear; }
        else if (this.format=='dd.mm.yy') { return Day+'.'+Month+'.'+shortYear; }
        else if (this.format=='yyyy-mm-dd') { return Year+'-'+Month+'-'+Day; }
        else if (this.format=='yyyy.mm.dd') { return Year+'.'+Month+'.'+Day; }
        else if (this.format=='dd.mm.yyyy') { return Day+'.'+Month+'.'+Year; }
        else if (this.format=='mm/dd/yy') { return Month+'/'+Day+'/'+shortYear; }
        else { return Day+'-'+Month+'-'+Year; }
    }
}


function _Validate(Str) {
    return this.Str2Date(Str)?true:false;
}


function _Str2Date(Str) {
    if (Str) {
        var RegYMDHIS = /^(\d{4})[-|.|\/](\d+)[-|.|\/](\d+)\s+(\d+):(\d+):(\d+)$/i; // yyyy-mm-dd hh:ii:ss
        var RegDMYHIS = /^(\d+)[-|.|\/](\d+)[-|.|\/](\d{4})\s+(\d+):(\d+):(\d+)$/i; // dd-mm-yyyy hh:ii:ss
        var RegYMD = /^(\d{4})[-|.|\/](\d+)[-|.|\/](\d+)$/i; // yyyy-mm-dd
        var RegDMY = /^(\d+)[-|.|\/](\d+)[-|.|\/](\d{4})$/i; // dd-mm-yyyy

        var RegDMY2 = /^(\d+)[.](\d+)[.](\d{2})$/i; // dd.mm.yy
        var RegMDY2 = /^(\d+)[-|\/](\d+)[-|\/](\d{2})$/i; // mm/dd/yy or mm-dd-yy

        var date = RegYMDHIS.exec(Str);
        if (date) { return (new Date(date[1],date[2]-1,date[3],date[4],date[5],date[6])); }

        var date = RegDMYHIS.exec(Str);
        if (date) { return (new Date(date[3],date[2]-1,date[1],date[4],date[5],date[6])); }

        var date = RegYMD.exec(Str);
        if (date) { return (new Date(date[1],date[2]-1,date[3])); }

        var date = RegDMY.exec(Str);
        if (date) { return (new Date(date[3],date[2]-1,date[1])); }

        var date = RegMDY2.exec(Str);
        if (date) {
            Year=Number(date[3]);
            if (Year<10) { Year+=2000; }
            else { Year+=2000; }
            return (new Date(Year, date[1]-1, (date[2])));
        }

        var date = RegDMY2.exec(Str);
        if (date) {
            Year=Number(date[3]);
            if (Year<10) { Year+=2000; }
            else { Year+=2000; }
            return (new Date(Year, (date[2]-1), date[1]));
        }
    }
    
    return null;
}

function _SetFormat(Str) {
    if (Str=='dd-mm-yy') { this.format='dd-mm-yy'; }
    else if (Str=='dd.mm.yy') { this.format='dd.mm.yy'; }
    else if (Str=='yyyy-mm-dd') { this.format='yyyy-mm-dd'; }
    else if (Str=='yyyy.mm.dd') { this.format='yyyy.mm.dd'; }
    else if (Str=='dd.mm.yyyy') { this.format='dd.mm.yyyy'; }
    else if (Str=='mm/dd/yy') { this.format='mm/dd/yy'; }
    else { this.format='dd-mm-yyyy'; }

    return true;
}
// *********************************** LSCalendar ***********************************


function daysInMonth( monthNum,  yearNum )
{
	// if monthNum or yearNum are not specified, set them to the current month/yearNum
	if( monthNum==undefined && yearNum==undefined )
	{
		now = new Date();
		monthNum = now.getMonth()+1;
		yearNum = now.getFullYear();
	}
	else if( monthNum || yearNum || monthNum=="" || yearNum == "" )
	{
		now = new Date();
		if( monthNum==undefined || monthNum=="" )
			monthNum = now.getMonth()+1;
		if( yearNum==undefined || yearNum=="" )
			yearNum = now.getFullYear();
	}
	// turn 01 into 1
	monthNum = Number(monthNum);
	yearNum = Number(yearNum);
	
	// check if monthNum and yearNum are numbers and whole numbers and monthNum is between 1 and 12
	if( isNaN(monthNum) || isNaN(yearNum) || monthNum%1!=0 || yearNum%1!=0 || monthNum<1 || monthNum>12 ){
		return false;
	}
	// create date
	var d = new Date(yearNum, monthNum, 0);
	return d.getDate();
}

// -->
