// JavaScript Document
function pageStart()
{
	/* Header bekommt Flashinhalt*/
	document.getElementById('flashContainer').innerHTML =  AC_FL_RunContent( "codebase","http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0","width","770","height","371","src","flash/head","quality","high","pluginspage","http://www.macromedia.com/go/getflashplayer","movie","flash/head", "wmode", "transparent" );
	
	/* Menü bekommt Javascriptfunktionen */
	var Container = document.getElementById('menu_container');
	var index = 0;
	for(var i = 0; i < Container.childNodes.length; i++)
	{
		if(Container.childNodes[i].nodeName.toLowerCase() == 'a')
		{
			addEvent(Container.childNodes[i], 'mouseover', mainmenuover);
			addEvent(Container.childNodes[i], 'mouseout', mainmenuout);
			try
			{
				addEvent(document.getElementById('subnav_'+index), 'mouseover', submenuover);
				addEvent(document.getElementById('subnav_'+index), 'mouseout', submenuout);
			}catch(e){null;}
			index ++;
		}
	}
	
	/* Datumsauswahl bekommt Javascriptfunktionen */
	addEvent(document.getElementById('bookingDepartureField'),'focus',change_time_date_field);
	addEvent(document.getElementById('bookingArrivelField'),'focus',change_time_date_field);
	
	/* Buchungsanfrage Formular */
	addEvent(document.getElementById('bookingSubmit'),'click',send_booking);
	
	/* Kontaktformular */
	try{addEvent(document.getElementById('contact_send'),'click',send_contact)}catch(e){null;};
}
registerOnLoad(pageStart);

/* Buchungsanfrage */
function send_booking()
{
	var roomObj = document.getElementsByName('roomType');
	for(var i=0; i< roomObj.length; i++)
	{
		if(roomObj[i].checked)
		{
			roomObj = roomObj[i];
			break;
		}
	}	
	var nameObj = document.getElementById('bookingName');
	var phoneObj = document.getElementById('bookingPhone');
	var mailObj = document.getElementById('bookingMail');
	var departureObj = document.getElementById('bookingDepartureField');
	var arrivelObj = document.getElementById('bookingArrivelField');
	var adultObj = document.getElementById('bookingAdult');
	var childObj = document.getElementById('bookingChild');
	var messageObj = document.getElementById('bookingMessage');
	
	var errorReport = '';
	if(!check_length(nameObj.value, 3))
	{
		errorReport += "Bitte füllen Sie das Feld Name aus!<br />";
	}
	if((!check_length(mailObj.value, 3)||!check_mail(mailObj.value)) && !check_length(phoneObj.value, 3))
	{
		errorReport += "Bitte füllen Sie das Feld Email oder Telefon korrekt aus!<br />";
	}
	if(errorReport.length > 0)
	{
		my_alert("Achtung", errorReport, "");
		return false;	
	}
	postVars = "pass=tebebo&roomType="+roomObj.value+"&name="+nameObj.value+"&phone="+phoneObj.value+"&email="+mailObj.value+"&arrival="+arrivelObj.value+"&departure="+departureObj.value+"&numAdult="+adultObj.value+"&numChild="+childObj.value+"&message="+messageObj.value;
	request = new Http(
		"send_mail.php",
		null,
		'POST',
		postVars,
		['Content-Type', 'application/x-www-form-urlencoded']
	);
	request.onreadyst = function()
	{
		if (requestQue.List[0].req.readyState == 4)
		{
			if (requestQue.List[0].req.status == 200)
			{
				document.getElementById('bookingName').value = '';
				document.getElementById('bookingPhone').value = '';
				document.getElementById('bookingMail').value = '';
				document.getElementById('bookingDepartureField').value = '';
				document.getElementById('bookingArrivelField').value = '';
				document.getElementById('bookingAdult').value = '';
				document.getElementById('bookingChild').value = '';
				document.getElementById('bookingMessage').value = '';
				my_alert("Vielen Dank für Ihre Anfrage", "Wir werden uns umgehend um Ihre Anliegen bemühen", "");
				requestQue.requExecuted();
			}
			else
			{
				requestQue.requExecuted();
			}
		}
	}
	requestQue.add(request);
}
function send_contact()
{
	var nameObj = document.getElementById('contact_name');
	var phoneObj = document.getElementById('contact_phone');
	var mailObj = document.getElementById('contact_mail');
	var messageObj = document.getElementById('contact_message');
	var errorReport = '';
	
	if(!check_length(nameObj.value, 3))
	{
		errorReport += "Bitte füllen Sie das Feld Name aus!<br />";
	}
	if((!check_length(mailObj.value, 3)||!check_mail(mailObj.value)) && !check_length(phoneObj.value, 3))
	{
		errorReport += "Bitte füllen Sie das Feld Email oder Telefon korrekt aus!<br />";
	}
	if(!check_length(messageObj.value, 3))
	{
		errorReport += "Bitte füllen Sie das Feld Nachricht aus!<br />";
	}
	if(errorReport.length > 0)
	{
		my_alert("Achtung", errorReport, "");
		return false;	
	}
	postVars = "pass=tebeko&name="+nameObj.value+"&phone="+phoneObj.value+"&email="+mailObj.value+"&message="+messageObj.value;
	request = new Http(
		"send_mail.php",
		null,
		'POST',
		postVars,
		['Content-Type', 'application/x-www-form-urlencoded']
	);
	request.onreadyst = function()
	{
		if (requestQue.List[0].req.readyState == 4)
		{
			if (requestQue.List[0].req.status == 200)
			{
				document.getElementById('contact_name').value = '';
				document.getElementById('contact_phone').value = '';
				document.getElementById('contact_mail').value = '';
				document.getElementById('contact_message').value = '';
				my_alert("Vielen Dank für Ihre Anfrage", "Wir werden uns umgehend um Ihre Anliegen bemühen", "");
				requestQue.requExecuted();
			}
			else
			{
				requestQue.requExecuted();
			}
		}
	}
	requestQue.add(request);
}

function check_length(string, minLength)
{
	if (string.length < minLength){return false;}
	return true;
}
function check_mail(string)
{
	var re = /^[a-zA-Z0-9_\.\-]+@([a-zA-Z0-9\-_]|\.)*[a-zA-Z0-9]{2,3}\.[a-zA-Z0-9]{2,4}/;
	if (!re.test(string)){return false;}
	return true;
}

/* DHTML Menü*/
function mainmenuover()
{
	var Obj = this;
	try
	{
		window.clearTimeout(mainmenuoutInterval);
		mainmenuoutInterval = false;
		mainMenuOutObj = false;
	}catch(e){null;}
	var Container = Obj.parentNode;
	pos = return_absolute_pos(Obj);
	var index = 0;
	for(var i = 0; i < Container.childNodes.length; i++)
	{
		if(Container.childNodes[i].nodeName.toLowerCase() == 'a')
		{
			if(Container.childNodes[i].innerHTML == Obj.innerHTML)
			{
				try
				{
					var element = document.getElementById('subnav_'+index);
					element.style.top = (pos.top-30)+'px';
					element.style.display = 'block';
					Container.childNodes[i].style.backgroundImage = "url(pix/menupoint_over.gif)";
					Container.childNodes[i].style.color = "#FFFFFF";
				}catch(e){null}
			}
			else
			{
				try
				{
					var element = document.getElementById('subnav_'+index);
					element.style.display = 'none';
					if(Container.childNodes[i].className != 'active')
					{
						Container.childNodes[i].style.backgroundImage = "url(pix/t.gif)";
						Container.childNodes[i].style.color = "#3D2300";
					}
				}catch(e){null}
			}
			index++;
		}
	}
}
var mainmenuoutInterval = false;
var mainMenuOutObj = false;
var submenuOver = false;
function mainmenuout()
{
	var Obj = this;
	if(mainmenuoutInterval === false)
	{
		mainMenuOutObj = Obj;
		mainmenuoutInterval = window.setTimeout('Mainmenuout()',1000);
	}
}
function Mainmenuout()
{
	if(mainMenuOutObj !== false)
	{
		mainmenuoutInterval = false;
		var Container = mainMenuOutObj.parentNode;
		var index = 0;
		for(var i = 0; i < Container.childNodes.length; i++)
		{
			if(Container.childNodes[i].nodeName.toLowerCase() == 'a')
			{
				try
				{
					var element = document.getElementById('subnav_'+index);
					element.style.display = 'none';
					if(Container.childNodes[i].className != 'active')
					{
						Container.childNodes[i].style.backgroundImage = "url(pix/t.gif)";
						Container.childNodes[i].style.color = "#3D2300";
					}
				}catch(e){null}
				index++;
			}
		}
		mainMenuOutObj = false;
	}
}
function submenuover()
{
	try
	{
		window.clearTimeout(mainmenuoutInterval);
		mainmenuoutInterval = false;
	}catch(e){null;}

}
function submenuout()
{
	mainMenuOutObj.mainmenuout = mainmenuout;
	mainMenuOutObj.mainmenuout();
}

/* Datumsauswahl */
Date.prototype.getMonthString = function()
{
	var monthString = new Array('Jänner','Februar','März','April','Mai','Juni','Juli','August','September','Oktober','November','Dezember');
	return monthString[this.getMonth()];
}
Date.prototype.getDayString = function()
{
	var dayString = new Array('Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag');
	return dayString[this.getDay()];
}
Date.prototype.getDayOfWeekIndex = function()
{
	var dayString = new Array(6,0,1,2,3,4,5);
	return dayString[this.getDay()];
}
Date.prototype.getDaysInMonth = function()
{
	var year = this.getFullYear();
    var daysInMonth = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
	daysInMonth[1] = ((year & 3) == 0 && (year % 100 || (year % 400 == 0 && year))) ? 29 : 28; //if is LeapYear
    return daysInMonth[this.getMonth()];
}

function change_time_date_field()
{
	var input = this;
	try
	{
		DateTimeChooser.destruct();
	}
	catch(e)
	{
		null;	
	}
	input.blur();
	DateTimeChooser = new Date_Time_Chooser('DateTimeChooser', 'pix/img_timeDatechooser/');
	DateTimeChooser.construct(input);
}
function Date_Time_Chooser(name, imgPath)
{
	this.name = name;
	this.imgPath = imgPath;
	this.callingInput = false;
	this.gloabalContainer = null;
	this.top = null;
	this.left = null;
	this.shaddow = null;
	this.contentContainer = null;
	this.timeContent = null;
	this.dateContent = null;
	this.totalWidth = 223;
	this.dateHeight = 230;
	this.totalHeight = null;
	this.id = 'timeDateChooserContainer';
	this.isOpen = false;
	this.today = new Date();
	this.selectedDate = null;
	
	this.construct = function(input)
	{
		this.callingInput = input;
		this.setDateByInput();
		this.isOpen = true;
		var pos = return_absolute_pos(input);
		this.top = pos.top+20;
		this.left = pos.left-30;

		this.totalHeight = this.dateHeight + 3;
		this.createContent();
		this.createDateContent();
	}
	this.createContent = function()
	{
		this.gloabalContainer = document.createElement('div');
		this.gloabalContainer.id = this.id;
		this.gloabalContainer.style.position = 'absolute';
		this.gloabalContainer.style.top = this.top+'px';
		this.gloabalContainer.style.left = this.left+'px';
		this.gloabalContainer.style.height = this.totalHeight+'px';
		this.gloabalContainer.style.width = this.totalWidth+'px';
		this.shaddow = document.createElement('div');
		this.shaddow.style.position = 'absolute';
		this.shaddow.style.top = '-2px';
		this.shaddow.style.left = '-2px';
		this.shaddow.style.height = this.totalHeight-1+'px';
		this.shaddow.style.width = this.totalWidth-1+'px';
		this.shaddow.style.backgroundColor = '#F5F2EB';
		this.shaddow.style.border = '1px solid #E8E1D1';
		this.contentContainer = document.createElement('div');
		this.contentContainer.style.position = 'absolute';
		this.contentContainer.style.top = '0px';
		this.contentContainer.style.left = '0px';
		this.contentContainer.style.height = this.totalHeight-3+'px';
		this.contentContainer.style.width = this.totalWidth-3+'px';
		this.contentContainer.style.backgroundColor = '#E8E1CF';
		this.contentContainer.style.lineHeight = '23px';
		this.contentContainer.style.color = '#ffffff';
		this.contentContainer.style.fontSize = '12px';
		this.contentContainer.className = 'timeContentContainer';
		
		this.gloabalContainer.appendChild(this.shaddow);
		this.gloabalContainer.appendChild(this.contentContainer);
		document.body.appendChild(this.gloabalContainer);
	}
	this.blurTimeInput = function()
	{
		try
		{
			this.callingInput.blur();
		}
		catch(e){void(null);}
	}
	this.changeCalenderMonth = function(type)
	{
		switch(type)
		{
			case'+':
				var nextMonth = this.selectedDate.getMonth()+1;
				this.selectedDate.setMonth(nextMonth);
				break;
			case'-':
				var lastMonth = this.selectedDate.getMonth()-1;
				this.selectedDate.setMonth(lastMonth);
				break;
		}
		this.dateContent.childNodes[1].childNodes[2].innerHTML = this.selectedDate.getMonthString();
		this.dateContent.childNodes[1].childNodes[3].innerHTML = this.selectedDate.getFullYear();
		this.dateContent.childNodes[2].innerHTML = this.createCalenderContent();
		this.callingInput.value = this.createInputString();
	}
	this.changeCalenderYear = function(type)
	{
		switch(type)
		{
			case'+':
				var nextYear = this.selectedDate.getFullYear()+1;
				this.selectedDate.setFullYear(nextYear);
				break;
			case'-':
				var lastYear = this.selectedDate.getFullYear()-1;
				this.selectedDate.setFullYear(lastYear);
				break;
		}
		this.dateContent.childNodes[1].childNodes[2].innerHTML = this.selectedDate.getMonthString();
		this.dateContent.childNodes[1].childNodes[3].innerHTML = this.selectedDate.getFullYear();
		this.dateContent.childNodes[2].innerHTML = this.createCalenderContent();
		this.callingInput.value = this.createInputString();
	}
	this.changeCalenderDay = function(obj)
	{
		this.selectedDate.setDate(obj.innerHTML*1);
		this.callingInput.value = this.createInputString();
		this.destruct();		
	}
	this.createDateContent = function()
	{
		this.dateContent = document.createElement('div');
		this.dateContent.style.position = 'absolute';
		this.dateContent.style.top = '0px';
		this.dateContent.style.left = '0px';
		this.dateContent.style.height = this.dateHeight+'px';
		this.dateContent.style.width = this.totalWidth-3+'px';
		var HTML = '<img style="margin:auto; display:block" src="pix/subnav_bg_top.gif" alt="" /><div class="dateMonthYearSelectContainer"><img title="ein Jahr zurück" onclick="'+this.name+'.changeCalenderYear(\'-\');" style="left:8px; top:0px;" src="'+this.imgPath+'/arrow_year_down.gif" /><img title="ein Monat zurück" onclick="'+this.name+'.changeCalenderMonth(\'-\');" style="left:24px; top:0px;" src="'+this.imgPath+'/arrow_month_down.gif" /><span style="color:#3D2300">'+this.selectedDate.getMonthString()+'</span><span>'+this.selectedDate.getFullYear()+'</span><img title="ein Monat weiter" onclick="'+this.name+'.changeCalenderMonth(\'+\');" style="right:24px; top:0px;" src="'+this.imgPath+'/arrow_month_up.gif" /><img title="ein Jahr weiter" onclick="'+this.name+'.changeCalenderYear(\'+\');" style="right:8px; top:0px;" src="'+this.imgPath+'/arrow_year_up.gif" /></div><div class="calenderConteiner">'+this.createCalenderContent()+'</div>';
		HTML += '<img title="schließen" style="position:absolute; top:0px; right:0px; cursor:pointer" onclick="'+this.name+'.destruct()"src="'+this.imgPath+'/close.gif" />';	
		this.dateContent.innerHTML = HTML;
		this.contentContainer.appendChild(this.dateContent);
	}
	this.createCalenderContent = function()
	{
		var html = '<div class="headline">M</div><div class="headline">D</div><div class="headline">M</div><div class="headline">D</div><div class="headline">F</div><div class="headline">S</div><div class="headline">S</div>';
		var cacheDate = this.selectedDate;
		var cacheDay = this.selectedDate.getDate();
		cacheDate.setDate(1);
		for(var i = 0; i < 7; i ++)
		{
			if(cacheDate.getDayOfWeekIndex()==i)
			{
				cacheDate.setDate(cacheDay);
				var maxDays = this.selectedDate.getDaysInMonth();
				for(var x = 1; x <= maxDays; x++)
				{
					if(x != this.selectedDate.getDate())
					{
						html += '<div style="cursor:pointer; color:#3D2300; background-color:#F5F2EB" onmouseover="this.style.backgroundColor =\'#07730D\'; this.style.color=\'#ffffff\'; '+this.name+'.blurTimeInput();" onmouseout="this.style.backgroundColor =\'#F5F2EB\'; this.style.color=\'#3D2300\';" onclick="'+this.name+'.changeCalenderDay(this)">'+x+'</div>';
					}
					else
					{
						html += '<div style="cursor:pointer; color:#07730D; font-weight:bold; background-color:#F5F2EB; position:relative">'+x+'</div>';
					}

					i ++;
				}
				var rest = Math.ceil(i/7)*7 - i;
				for(var x = 1; x <= rest; x++)
				{
					html += '<div style="background-color:#F5F2EB; position:relative"></div>';
				}

				break;
			}
			html += '<div style="background-color:#F5F2EB; position:relative" ></div>';
		}
		this.createInputString();
		return html;
	}
	this.createInputString = function()
	{
		return str = this.addNull(this.selectedDate.getDate())+'.'+this.addNull(this.selectedDate.getMonth()+1)+'.'+this.selectedDate.getFullYear();
	}
	this.setDateByInput = function()
	{
		this.selectedDate = new Date();
		var value = this.callingInput.value;
		if(value.length == 10)
		{
			this.selectedDate.setFullYear(value.substring(6,10)*1);
			this.selectedDate.setMonth(value.substring(3,5)*1-1);
			this.selectedDate.setDate(value.substring(0,2)*1);
		}
		this.callingInput.value = this.createInputString();	
	}
	this.addNull = function(num)
	{
		if(num < 10)
		{
			return ('0'+num).toString();
		}
		return num;
	}
	this.destruct = function()
	{
		document.body.removeChild(this.gloabalContainer);
		this.id = null;
		this.isOpen = false;
		this.callingInput = false;
		this.gloabalContainer = null;
		this.top = null;
		this.left = null;
		this.shaddow = null;
		this.contentContainer = null;
		this.timeContent = null;
		this.dateContent = null;
		this.totalHeight = null;
		this.selectedDate = null;
	}	
}
var DateTimeChooser;

