function handleSelect(type,args,obj) 
{  					
	var dates = args[0];   
	var date = dates[0];   
	var year = date[0], month = date[1], day = date[2];					
	if(!isNaN(date[0]) && !isNaN(date[1]) && !isNaN(date[2])) 
		document.getElementById(obj.tField).value = day + '/' + month + '/' + year;
	YAHOO.util.Dom.setStyle(obj.oDomContainer.id, 'display', 'none');
}

function updateCal(e, obj) 
{   		
	field=document.getElementById(obj.tField);
	field.value=field.value.replace(/-/g,'/');				
	textDate=field.value;
	document.getElementById(obj.tField).value
	obj.select(textDate);	
	var firstDate = obj.getSelectedDates()[0];  
	if (!isNaN(firstDate)) 
	{
		firstDateMonth=( (firstDate.getMonth()+1) + '/' + ( firstDate.getFullYear() ) );
							
		// Set the Calendar's page to the earliest selected date   
		obj.cfg.setProperty('pagedate', firstDateMonth);  
	}
	obj.render();
}

function createCalendar(cDId, ccDId, dFId, bId, title, closeIcon)
{
	var cal = new YAHOO.widget.Calendar(cDId, ccDId, { title:title, close:closeIcon } );   
	cal.tField = dFId;
	cal.render();
	
	YAHOO.util.Event.addListener(bId, 'click', cal.show, cal, true);
	YAHOO.util.Event.addListener(dFId, 'change', updateCal, cal, true);	
	 
	cal.selectEvent.subscribe(handleSelect, cal, true);
	cal.cfg.setProperty("MDY_DAY_POSITION", 1);
	cal.cfg.setProperty("MDY_MONTH_POSITION", 2);
	cal.cfg.setProperty("MDY_YEAR_POSITION", 3);
	cal.cfg.setProperty("MD_DAY_POSITION", 1);
	cal.cfg.setProperty("MD_MONTH_POSITION", 2);
	cal.cfg.setProperty("iframe", true);
		
	updateCal('change', cal);	
	
	return cal;
}

