﻿// RAD CONTROLS
  
var calendar, popup, calendarContainer, activeInput, isVisible;

function InitCalendar(inputId) {
    calendar = document.getElementById(inputId);
}

function ToggleCalendar(e, inputId)
{
	ShowCalendar(inputId);

	e.cancelBubble = true;
}

function ShowCalendar(inputId)
{
    if (!popup)
        popup = new RadCalendar.Popup();
        
    if (!calendarContainer)
        calendarContainer = document.getElementById("calendarContainer");
        
    if (activeInput
		&& activeInput.id == inputId
		&& popup.IsVisible())
	{
		popup.Hide();
	}			
	else
	{        
		activeInput = document.getElementById(inputId);
		var x = positionX(activeInput);
		var y = positionY(activeInput) + activeInput.offsetHeight;
        
		popup.Show(x, y, calendarContainer);
	}
}

function ChangeInput(renderDay)
{     
    var dateArray = renderDay.Date;  
    
    // UK format
    
    var dateString = integerPad(dateArray[2], 2) + "/" + integerPad(dateArray[1], 2) + "/" + dateArray[0];
    activeInput.value = dateString;
    
	if (popup.IsVisible())
	{
		popup.Hide();
	}
}



