// javascript document


//create the name space for calender
YAHOO.namespace("calendar");

function ftnAddFirstZero(numberVal){
	if(numberVal<10)numberVal = "0" + numberVal;	
	return numberVal;
}

//this handles what to do when the "from" calender is subscribed (clicked)
function handleSelectFrom(type,args,obj) { 
	var dates = args[0]; 
	var date = dates[0]; 
	var year = date[0], month = date[1], day = date[2]; 
 
	var txtDate1 = document.getElementById("dateFrom"); 
	
	txtDate1.value = ftnAddFirstZero(day) + "/" + ftnAddFirstZero(month) + "/" + year; 
} 

//this handles what to do when the "to" calender is subscribed (clicked)
function handleSelectTo(type,args,obj) { 
	var dates = args[0]; 
	var date = dates[0]; 
	var year = date[0], month = date[1], day = date[2]; 
 
	var txtDate1 = document.getElementById("dateTo"); 
	txtDate1.value = ftnAddFirstZero(day) + "/" + ftnAddFirstZero(month) + "/" + year; 
} 

function initCal() {
	
	 var todate = new Date() ; with (todate) setDate(getDate()+1)
	
	dateFrom = new YAHOO.widget.Calendar("cal1","cal1Container", { pagedate:(todate.getMonth()-1)+"/"+todate.getFullYear(), maxdate:(todate.getMonth()+1)+"/"+(todate.getDate()-1)+"/"+todate.getFullYear(), title:"jobs posted from:", close:true } );
	dateFrom.render();

	// Listener to show the 3-up Calendar when the button is clicked
	YAHOO.util.Event.addListener("selectDateFrom", "click", dateFrom.show, dateFrom, true);
	
	//get the calender to update the text filed on click
	dateFrom.selectEvent.subscribe(handleSelectFrom, dateFrom, true);
	dateFrom.selectEvent.subscribe(dateFrom.hide, dateFrom, true); 

	dateTo = new YAHOO.widget.Calendar("cal2","cal2Container", { pagedate:"5/2007", maxdate:(todate.getMonth()+1)+"/"+todate.getDate()+"/"+todate.getFullYear(), title:"jobs date range:", close:true } );
	dateTo.render();

	// Listener to show the 1-up Calendar when the button is clicked
	YAHOO.util.Event.addListener("selectDateTo", "click", dateTo.show, dateTo, true);
	
	//get the calender to update the text filed on click
	dateTo.selectEvent.subscribe(handleSelectTo, dateTo, true); 
	dateTo.selectEvent.subscribe(dateTo.hide, dateTo, true); 
	
	
}

function ftnCalListener(objName){
	function TestObj(id) { 
  YAHOO.util.Event.onContentReady (id, this.handleOnAvailable, this);  
	} 
	 
	TestObj.prototype.handleOnAvailable = function(me) { 
	 initCal()
	} 
	 
	var obj = new TestObj(objName); 
}

YAHOO.util.Event.addListener(window, "load", initCal);