init = function(){
	var dialog, calendar;
	var curTextfeldID = "AnreiseDatum";
  	//calendar = new YAHOO.widget.Calendar("cal", {LOCALE_WEEKDAYS:"short", START_WEEKDAY: 1, iframe:false, hide_blank_weeks:true });
  	calendar = new YAHOO.widget.Calendar("calendar","cal", {LOCALE_WEEKDAYS:"short", START_WEEKDAY: 1, iframe:false, hide_blank_weeks:true });
	//dialog = new YAHOO.widget.Dialog("conCal","container", {context:["show", "tl", "bl"], buttons:[ {text:"[ Eingabe abbrechen ]", handler: cancelHandler}], width:"16em", draggable:false, close:true });
	dialog = new YAHOO.widget.Dialog("conCal","container", {draggable:false, close:true });

	function localize(){
		// Correct formats for Germany: dd.mm.yyyy, dd.mm, mm.yyyy   
		calendar.cfg.setProperty("DATE_FIELD_DELIMITER", ".");   
		calendar.cfg.setProperty("MDY_DAY_POSITION", 1);   
		calendar.cfg.setProperty("MDY_MONTH_POSITION", 2);   
		calendar.cfg.setProperty("MDY_YEAR_POSITION", 3);   
		calendar.cfg.setProperty("MD_DAY_POSITION", 1);   
		calendar.cfg.setProperty("MD_MONTH_POSITION", 2);   
		// Date labels for German locale   
		calendar.cfg.setProperty("MONTHS_SHORT",   ["Jan", "Feb", "M\u00E4r", "Apr", "Mai", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dez"]);   
		calendar.cfg.setProperty("MONTHS_LONG",    ["Januar", "Februar", "M\u00E4rz", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"]);   
		calendar.cfg.setProperty("WEEKDAYS_1CHAR", ["S", "M", "D", "M", "D", "F", "S"]);   
		calendar.cfg.setProperty("WEEKDAYS_SHORT", ["So", "Mo", "Di", "Mi", "Do", "Fr", "Sa"]);   
		calendar.cfg.setProperty("WEEKDAYS_MEDIUM",["Son", "Mon", "Die", "Mit", "Don", "Fre", "Sam"]);   
		calendar.cfg.setProperty("WEEKDAYS_LONG",  ["Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag"]);   
	}
	
	function okHandler() {
	   	if (calendar.getSelectedDates().length > 0) {
			var selDate = calendar.getSelectedDates()[0];
			var wStr = calendar.cfg.getProperty("WEEKDAYS_LONG")[selDate.getDay()];
			var dStr = selDate.getDate();
			var mStr = calendar.cfg.getProperty("MONTHS_LONG")[selDate.getMonth()];
			var yStr = selDate.getFullYear();
			YAHOO.util.Dom.get("AnreiseDatum").value = wStr + ", " + dStr + " " + mStr + " " + yStr;
		} 
		else { YAHOO.util.Dom.get("AnreiseDatum").value = ""; }
		this.hide();
   }

	function cancelHandler() {this.hide();}

	function handleSelect(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(curTextfeldID);
		txtDate1.value = day + "." + month + "." + year;
		txtDate1.focus(); //dialog.hide();
	}
	
	function updateCal() {
		var txtDate1 = document.getElementById(curTextfeldID);
		if (txtDate1.value != "") {
			calendar.select(txtDate1.value);
			var selectedDates = calendar.getSelectedDates();
			if (selectedDates.length > 0) {
				var firstDate = selectedDates[0];
				calendar.cfg.setProperty("pagedate", (firstDate.getMonth()+1) + "." + firstDate.getFullYear());
				calendar.render(); dialog.show();
			} else {}
		}
	}
	
	localize();	calendar.render(); dialog.render(); //dialog.hide();
	calendar.renderEvent.subscribe(function() {dialog.fireEvent("changeContent");});
	calendar.selectEvent.subscribe(handleSelect, calendar, true);
		
	YAHOO.util.Event.on("show", "click", function() {
		dialog.show();
		if (YAHOO.env.ua.opera && document.documentElement) { // Opera needs to force a repaint
			document.documentElement.style += "";
		} 
	});
	YAHOO.util.Event.on("AnreiseDatum", "focus", function() {
		dialog.show();curTextfeldID = "AnreiseDatum";
		if (document.getElementById(curTextfeldID).value != "") {updateCal();}
	});
	YAHOO.util.Event.on("AbreiseDatum", "focus", function() {
		dialog.show();curTextfeldID = "AbreiseDatum";
		if (document.getElementById(curTextfeldID).value != "") {updateCal();}
	});
};

YAHOO.util.Event.onDOMReady(init);
YAHOO.util.Event.onDOMReady(initForm);

function initForm(){
	var curObjectID;
	for (i=0;i<document.getElementsByTagName("input").length;i++){
		curObjectID = document.getElementsByTagName("input")[i].id;
		if((curObjectID.slice(0,2)=="__") || (curObjectID.slice(0,3)=="hdn") || (curObjectID.slice(0,3)=="btn")){}
		else{
			YAHOO.util.Event.addListener(document.getElementsByTagName("input")[i].id,"focus",drin);
			YAHOO.util.Event.addListener(document.getElementsByTagName("input")[i].id,"blur",raus);
		}
	}	
}
function drin(){this.className="drin";}
function raus(){this.className="";}

