 var numCalendars = 2;
        var rightNow = new Date();
        var today = new Date( rightNow.getFullYear(), rightNow.getMonth(), rightNow.getDate() );
        var chk_in = new Date (today);
        var chk_out = new Date (today);
        var maxDate = new Date (today.getFullYear() + 1, today.getMonth(), today.getDate() - 1);
        var daysInMonth = [31,daysInFeb(today.getFullYear()),31,30,31,30,31,31,30,31,30,31];
        var fullMonthNames = ['January','February','March','April','May','June','July','August','September','October','November','December'];
        var shortMonthNames = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
        
        function printMonths (minDate, drawDate, maxDate, drawBlank)
        {
            var result = '';
            var year = minDate.getFullYear();
            var printDate = new Date(minDate.getFullYear(), minDate.getMonth(), maxDate.getDate());
            if ( drawBlank )
            {
                result = '<option>Month</option><option>&nbsp;</option>';
            }
            
            while ( printDate <= maxDate )
            {
                result += '<option';
                if ( printDate.getMonth() == drawDate.getMonth() && printDate.getFullYear() == drawDate.getFullYear() && drawBlank == false )
                    result += ' selected=SELECTED';
                result += ' value="' + printDate.getMonth() + '-' + printDate.getFullYear() + '">' + shortMonthNames[printDate.getMonth()] + ' `' + printDate.getFullYear().toString().slice(2,4) + '</option>';
                printDate.setMonth( printDate.getMonth() + 1);
            }
            
            return result;
        }
        
        function daysInFeb( year )
        {
            if ( new Date(year,1,29).getDate()==29 )
                return 29;
            else
                return 28;
        }
        
        function drawPrev ( month, year, type )
        {
            var drawDate = new Date ( year, month, 1 );
            drawDate.setMonth ( drawDate.getMonth() -  1 );
            drawCalendar ( drawDate, today, chk_in, chk_out, type, true );
        }
        
        function drawNext ( month, year, type )
        {
            var drawDate = new Date ( year, month, 1 );
            drawDate.setMonth ( drawDate.getMonth() + 1 );
            if ( type == 'rs_calendar_in' )
                drawCalendar ( drawDate, today, chk_in, chk_out, type, true );
            else
                drawCalendar ( drawDate, chk_in, chk_out, chk_in, type, true );
        }
        
        function setDay ( day, type )
        {
            if ( type == 'rs_calendar_in' )
                setDate ( chk_in.getFullYear(), chk_in.getMonth(), day, 'rs_calendar_in' );
            else
                setDate ( chk_out.getFullYear(), chk_out.getMonth(), day, 'rs_calendar_out' );
        }
        
        function setMonth ( month, type )
        {
            var newMonth = month.split('-')[0];
            var newYear = month.split('-')[1];
            if ( type == 'rs_calendar_in' )
                setDate ( newYear, newMonth, 1, 'rs_calendar_in' );
            else
                setDate ( newYear, newMonth, 1, 'rs_calendar_out' );
        }
        
        function setDate ( year, month, day, type )
        {
            $('.rs_calendar').hide();
            
            if ( type == 'rs_calendar_in' )
            {
                chk_in = new Date ( year, month, day );
                if ( chk_in < today )
                    chk_in = new Date ( today.getFullYear(), today.getMonth(), today.getDate() );
                if ( chk_out <= chk_in )
                {
                    chk_out = new Date ( chk_in.getFullYear(), chk_in.getMonth(), chk_in.getDate() );
                    chk_out.setDate ( chk_out.getDate() + 1 );
                }
                drawCalendar ( chk_out, chk_in, chk_out, chk_in, 'rs_calendar_out', false );
                drawCalendar ( chk_in, today, chk_in, chk_out, type, false );
            }
            else
            {
                chk_out = new Date ( year, month, day );
                if ( chk_in < today )
                    chk_in = new Date ( today.getFullYear(), today.getMonth(), today.getDate() );
                if ( chk_out <= chk_in )
                {
                    chk_out = new Date ( chk_in.getFullYear(), chk_in.getMonth(), chk_in.getDate() );
                    chk_out.setDate ( chk_out.getDate() + 1 );
                }
                drawCalendar ( chk_out, chk_in, chk_out, chk_in, type, false );
                drawCalendar ( chk_in, today, chk_in, chk_out, 'rs_calendar_in', false );
            }
            
            $('#rs_chk_in').val( (chk_in.getMonth()+1) + '/' + chk_in.getDate() + '/' + chk_in.getFullYear() );
            $('#rs_chk_out').val( (chk_out.getMonth()+1) + '/' + chk_out.getDate() + '/' + chk_out.getFullYear() );
            $('#rs_chk_in2').val( (chk_in.getMonth()+1) + '/' + chk_in.getDate() + '/' + chk_in.getFullYear() );
            $('#rs_chk_out2').val( (chk_out.getMonth()+1) + '/' + chk_out.getDate() + '/' + chk_out.getFullYear() );
            
            
            document.getElementById("doa_mm").value=chk_in.getMonth()+1;
            document.getElementById("doa_dd").value=chk_in.getDate();
            document.getElementById("doa_yy").value=chk_in.getFullYear();

            document.getElementById("dod_mm").value=chk_out.getMonth()+1;
            document.getElementById("dod_dd").value=chk_out.getDate();
            document.getElementById("dod_yy").value=chk_out.getFullYear();
            
            
        }
        
        function printDays ( drawDate, minDate, maxDate, drawBlank )
        {
            return true;
        }
        
        function drawCalendar ( drawDate, minDate, date, otherDate, type, skipSelect )
        {
            var html = '<div class="closerBar"><span onclick="$(\'.rs_calendar\').hide();" class="closeSquare">x</span></div>';
            var daysLeftInWeek = 7;
            var weeksToPrint = 6;
            
            var buttonsHMTL = '';
            if (!(drawDate.getFullYear() == maxDate.getFullYear() && drawDate.getMonth() == maxDate.getMonth()))
                buttonsHMTL += "<span class='calendarNext' onclick='drawNext(" + drawDate.getMonth() + ", " + drawDate.getFullYear() + ", \"" + type + "\"); return false;'></span>";
            if (!(drawDate.getFullYear() == minDate.getFullYear() && drawDate.getMonth() == minDate.getMonth()))
                buttonsHMTL += "<span class='calendarPrev' onclick='drawPrev(" + drawDate.getMonth() + ", " + drawDate.getFullYear() + ", \"" + type + "\"); return false;'></span>";
            
            if ( type == 'rs_calendar_out' )
                minDate = new Date ( minDate.getFullYear(), minDate.getMonth(), (minDate.getDate() + 1) );
            
            if ( skipSelect == false )
            {
                if ( type == 'rs_calendar_in' )
                {
                    if ( $('#rs_chk_in_month option').html() == null )
                    {
                        $('#rs_chk_in_month').html( printMonths(minDate, drawDate, maxDate, true) );
                        $('#rs_chk_in_day').html( printDays(drawDate, minDate, maxDate, true) );
                    }
                    else
                    {
                        $('#rs_chk_in_month').html( printMonths(minDate, drawDate, maxDate, false) );
                        $('#rs_chk_in_day').html( printDays(drawDate, minDate, maxDate, false) );
                    }
                }
                else
                {
                    if ( $('#rs_chk_out_month option').html() == null )
                    {
                        $('#rs_chk_out_month').html( printMonths(minDate, drawDate, maxDate, true) );
                        $('#rs_chk_out_day').html( printDays(drawDate, minDate, maxDate, true) );
                    }
                    else
                    {
                        $('#rs_chk_out_month').html( printMonths(minDate, drawDate, maxDate, false) );
                        $('#rs_chk_out_day').html( printDays(drawDate, minDate, maxDate, false) );
                    }
                }
            }
            
            drawDate = new Date (drawDate.getFullYear(), drawDate.getMonth() - 1, 1);
                        
            for ( var counter=0; counter<numCalendars; counter++ )
            {
                drawDate = new Date (drawDate.getFullYear(), drawDate.getMonth() + 1, 1);
                html += "<table ";
                if ( (numCalendars-1) == counter )
                {
                    html += "style='float: right' ";
                }
                html += "cellspacing=0 cellpadding=0 border=0><tr class='topRow'><td colspan=7>";
                if ( counter == 0 )
                    html += "<select onchange='updateCalendar($(this).val(), \"" + type + "\");'>" + printMonths(minDate, drawDate, maxDate, false) + "</select>";
                if ( counter != 0 )
                    html += "<span class='calendarTitle'>" + fullMonthNames[drawDate.getMonth()] + " " + drawDate.getFullYear() + "</span>";
                if ( counter == (numCalendars-1) )
                {
                    html += "<span class='calendarButtons'>";
                    html += buttonsHMTL;
                    html += "</span>";
                }
                html += "</td></tr><tr class='weekRow'><th>sun</th><th>mon</th><th>tue</th><th>wed</th><th>thu</th><th>fri</th><th>sat</th></tr><tr>";
                daysLeftInWeek = 7;
                weeksToPrint = 6;
                
                html += printBlanks ( new Date(drawDate.getFullYear(), drawDate.getMonth(), 1).getDay() );
                daysLeftInWeek -= new Date(drawDate.getFullYear(), drawDate.getMonth(), 1).getDay();
                
                for (var i=1; i<=daysInMonth[drawDate.getMonth()]; i++)
                {
                    var printingDate = new Date ( drawDate.getFullYear(), drawDate.getMonth(), i );
                    var clickAdd = 'onclick="setDate(' + drawDate.getFullYear() + ', ' + drawDate.getMonth() + ', ' + i + ', \'' + type + '\'); return false;"';
                    if ( printingDate.toDateString() == date.toDateString() )
                        html += '<td class="dateSquare currDate" ' + clickAdd + '>' + i + '</td>';
                    else if ( printingDate.toDateString() == otherDate.toDateString() )
                    {
                        if ( type == 'rs_calendar_out' )
                            html += '<td class="dateSquare otherDate">' + i + '</td>';
                        else
                            html += '<td class="dateSquare otherDate" ' + clickAdd + '>' + i + '</td>';
                    }
                    else if ( printingDate < minDate || printingDate > maxDate )
                    {
                        html += '<td class="dateSquare disabledDate">' + i + '</td>';
                    }
                    else if ( (printingDate > date && printingDate < otherDate) || (printingDate < date && printingDate > otherDate) )
                    {
                        html += '<td class="dateSquare betweenDate" ' + clickAdd + '>' + i + '</td>';
                    }
                    else
                        html += '<td class="dateSquare" ' + clickAdd + '>' + i + '</td>';
                    daysLeftInWeek --;
                    if ( daysLeftInWeek == 0 )
                    {
                        html = html + '</tr><tr>';
                        daysLeftInWeek = 7;
                        weeksToPrint --;
                    }
                }
                
                if ( daysLeftInWeek != 7 )
                {
                    html += printBlanks ( daysLeftInWeek ) + '</tr>';
                    weeksToPrint --;
                }
                
                for ( var i=weeksToPrint; i>0; i-- )
                    html += '<tr>' + printBlanks ( 7 ) + '</tr>';
                
                html += '</table>';
            }

            $('#' + type).html ( html );            
        }
        
        function updateCalendar ( drawVal, type )
        {
            if ( type == 'rs_calendar_in' )
                drawCalendar ( new Date(drawVal.split('-')[1],drawVal.split('-')[0],1), today, chk_in, chk_out, type, true );
            else
                drawCalendar ( new Date(drawVal.split('-')[1],drawVal.split('-')[0],1), chk_in, chk_out, chk_in, type, true );
        }
        
        function printBlanks ( count )
        {
            var result = "";
            for ( var i=1; i<=count; i++ )
                result += "<td class='dateSquare blank'>&nbsp;</td>";
            return result;
        }
        
        $(document).ready (
            function()
            {
                drawCalendar ( chk_in, today, chk_in, chk_out, 'rs_calendar_in', false );
                drawCalendar ( chk_out, chk_in, chk_out, chk_in, 'rs_calendar_out', false );
                $('#rs_calendar_in').css('left',($('#rs_chk_in_show').offset().left));
                $('#rs_calendar_out').css('left',($('#rs_chk_out_show').offset().left));
                $('#rs_calendar_in').css('top',($('#rs_chk_in_show').offset().top - 60));
                $('#rs_calendar_out').css('top',($('#rs_chk_out_show').offset().top - 60));
                
                $('#rs_chk_in_show').click ( function() { $('.rs_calendar').hide(); $('#rs_calendar_in').show(); } );
                $('#rs_chk_out_show').click ( function() { $('.rs_calendar').hide(); $('#rs_calendar_out').show(); } );
                $('#rs_chk_in').click ( function() { $('.rs_calendar').hide(); $('#rs_calendar_in').show(); } );
                $('#rs_chk_out').click ( function() { $('.rs_calendar').hide(); $('#rs_calendar_out').show(); } );
                $('#rs_chk_in_show2').click ( function() { $('.rs_calendar').hide(); $('#rs_calendar_in').show(); } );
                $('#rs_chk_out_show2').click ( function() { $('.rs_calendar').hide(); $('#rs_calendar_out').show(); } );
                $('#rs_chk_in2').click ( function() { $('.rs_calendar').hide(); $('#rs_calendar_in').show(); } );
                $('#rs_chk_out2').click ( function() { $('.rs_calendar').hide(); $('#rs_calendar_out').show(); } );
                $('.rs_calendar .closeSquare').click ( function() { $('.rs_calendar').hide(); } );
                
                $('.rs_calendar').bgiframe();
            }
        );
		
		
		// used to hide and show elements. 
		function show(idLayer) { document.getElementById(idLayer).style.display='block'; }
		function showInline(idLayer) { document.getElementById(idLayer).style.display='inline'; }
		function hide(idLayer) { document.getElementById(idLayer).style.display='none'; }
		
		
		//Children selector.
		function displayages(childobj)
		{
		if (childobj.options[0].selected){hide('children_box'); hide('minorsAge1'); hide('minorsAge2'); hide('minorsAge3'); hide('minorsAge4');}
		if (childobj.options[1].selected){show('children_box'); showInline('minorsAge1'); hide('minorsAge2'); hide('minorsAge3'); hide('minorsAge4');}
		if (childobj.options[2].selected){show('children_box'); showInline('minorsAge1'); showInline('minorsAge2'); hide('minorsAge3'); hide('minorsAge4');}
		if (childobj.options[3].selected){show('children_box'); showInline('minorsAge1'); showInline('minorsAge2'); showInline('minorsAge3'); hide('minorsAge4');}
		if (childobj.options[4].selected){ show('children_box'); showInline('minorsAge1'); showInline('minorsAge2'); showInline('minorsAge3'); showInline('minorsAge4');}
		}
		
		//Children selector.
		function displayvages(childobj)
		{
		if (childobj.options[0].selected){hide('vchildren_box'); hide('minorsAgeRoom1'); hide('minorsAgeRoom2'); hide('minorsAgeRoom3'); hide('minorsAgeRoom4');}
		if (childobj.options[1].selected){show('vchildren_box'); showInline('minorsAgeRoom1'); hide('minorsAgeRoom2'); hide('minorsAgeRoom3'); hide('minorsAgeRoom4');}
		if (childobj.options[2].selected){show('vchildren_box'); showInline('minorsAgeRoom1'); showInline('minorsAgeRoom2'); hide('minorsAgeRoom3'); hide('minorsAgeRoom4');}
		if (childobj.options[3].selected){show('vchildren_box'); showInline('minorsAgeRoom1'); showInline('minorsAgeRoom2'); showInline('minorsAgeRoom3'); hide('minorsAgeRoom4');}
		if (childobj.options[4].selected){ show('vchildren_box'); showInline('minorsAgeRoom1'); showInline('minorsAgeRoom2'); showInline('minorsAgeRoom3'); showInline('minorsAgeRoom4');}
		}
		
		function verifyForm(strID)
		{
			var blnPass = false;
			var objF = document.getElementById(strID);
			if(objF.rschk_in.value=="mm/dd/yyyy"||objF.rschk_in.value=="")
			{
				alert("Please select a check in date.");
				objF.chk_in.focus();
			}
			else if(objF.rschk_out.value=="mm/dd/yyyy"||objF.rschk_out.value=="")
			{
				alert("Please select a check out date.");
				objF.chk_out.focus();
			}
			else
			{
				if(strID=="airHotelSearch")
				{
					
					if(objF.leavingFrom.value=="")
					{
						alert("Please enter the city you are leaving from.");
						objF.leavingFrom.focus();
					}
					else if(objF.goingTo.value=="")
					{
						alert("Please enter the city you are going to.");
						objF.goingTo.focus();
					}
					else
					{
						objF.dateLeavingMonth.value = objF.doa_mm.value;
						objF.dateLeavingDay.value = objF.doa_dd.value;
						objF.dateReturningMonth.value = objF.dod_mm.value;
						objF.dateReturningDay.value = objF.dod_dd.value;
						blnPass = true;
					}
				}
				else
					blnPass = true;
			}
			return blnPass;
			
		}

