var Calendar = function () {
	
};


YAHOO.namespace("name1");
YAHOO.util.Event.addListener(window, "load", initCal);

function initCal() {
  today = new Date();
  YAHOO.name1.cal1 = new YAHOO.widget.Calendar("cal1","cal1Container", 
	{ 
	  selected: today,
	  START_WEEKDAY: 0,
	  close:true,
	  title:"日付を選択してください"
	});

  YAHOO.name1.cal1.selectEvent.subscribe(handleSelect, YAHOO.name1.cal1, true);

  YAHOO.name1.cal1.cfg.setProperty("MDY_YEAR_POSITION", 1);
  YAHOO.name1.cal1.cfg.setProperty("MDY_MONTH_POSITION", 2);
  YAHOO.name1.cal1.cfg.setProperty("MDY_DAY_POSITION", 3);

  YAHOO.name1.cal1.cfg.setProperty("MY_YEAR_POSITION", 1);
  YAHOO.name1.cal1.cfg.setProperty("MY_MONTH_POSITION", 2);

  YAHOO.name1.cal1.cfg.setProperty("MONTHS_SHORT",   ["1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"]);
  YAHOO.name1.cal1.cfg.setProperty("MONTHS_LONG",    ["1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"]);
  YAHOO.name1.cal1.cfg.setProperty("WEEKDAYS_1CHAR", [Dict.SUN, Dict.MON, Dict.TUE, Dict.WED, Dict.THU, Dict.FRI, Dict.SAT]);
  YAHOO.name1.cal1.cfg.setProperty("WEEKDAYS_SHORT", [Dict.SUN, Dict.MON, Dict.TUE, Dict.WED, Dict.THU, Dict.FRI, Dict.SAT]);
  YAHOO.name1.cal1.cfg.setProperty("WEEKDAYS_MEDIUM",[Dict.SUN, Dict.MON, Dict.TUE, Dict.WED, Dict.THU, Dict.FRI, Dict.SAT]);
  YAHOO.name1.cal1.cfg.setProperty("WEEKDAYS_LONG",  [Dict.SUN, Dict.MON, Dict.TUE, Dict.WED, Dict.THU, Dict.FRI, Dict.SAT]);

  YAHOO.name1.cal1.cfg.setProperty("MY_LABEL_YEAR_POSITION",  1);
  YAHOO.name1.cal1.cfg.setProperty("MY_LABEL_MONTH_POSITION",  2);
  YAHOO.name1.cal1.cfg.setProperty("MY_LABEL_YEAR_SUFFIX",  "\u5E74");
  YAHOO.name1.cal1.cfg.setProperty("MY_LABEL_MONTH_SUFFIX",  "");

  YAHOO.name1.cal1.render();
  YAHOO.util.Event.addListener("sinceDateStr", "focus", handleFocus, YAHOO.name1.cal1, true);
  YAHOO.util.Event.addListener("untilDateStr", "focus", handleFocus, YAHOO.name1.cal1, true);
  YAHOO.util.Event.addListener("fetcherSinceStr", "focus", handleFocus, YAHOO.name1.cal1, true);
  YAHOO.util.Event.addListener("fetcherUntilStr", "focus", handleFocus, YAHOO.name1.cal1, true);

};

var lastFocusName = "";
function setLastFocusName(val, obj) {
	lastFocusName = val;
	adjustObjectOffset (obj);
}

function adjustObjectOffset (obj) {
	var areaOffset = Element.cumulativeOffset(obj);
	
	document.getElementById('cal1Container').style.top = (areaOffset[1]) + 'px';
	document.getElementById('cal1Container').style.left = (areaOffset[0]) + 'px';
    YAHOO.name1.cal1.show();
}

function handleFocus(type,args,obj) {
}

function handleSelect(type,args,obj) {
  var dates = args[0]; 
  var date = dates[0];
  var year = date[0], month = date[1], day = date[2];
  YAHOO.name1.cal1.hide();
  urlInfo.targetDate.setFullYear(year);
  urlInfo.targetDate.setMonth(month-1);
  urlInfo.targetDate.setDate(day);
  urlInfo.targetDate.setHours(0);
  urlInfo.targetDate.setMinutes(0);
  urlInfo.refresh(false);
}