document.DocumentReady=false;
function oe(Fehler,Datei,Zeile){
	alert('Es ist der JS- Fehler: '+Fehler+', in der Datei: '+Datei+', in der Zeile: '+Zeile+'Aufgetreten.');
}
function oe2(){
	return true;	
}
if(navigator.appVersion.indexOf('MSIE')!=-1&&navigator.appVersion.indexOf('Mac')==-1)var IE=true; else IE=false;

window.onerror=oe;

var tmr = null;
var actual=null;

function objId(a){
	var d=document;
	var x=d.getElementById(a);
	return x;
}
function objName(a,b){
	var d=document;
	var x=d.getElementsByName(a)[b];
	return x;
}

function Style(a){
	return objId(a).style;	
}

var theDay=0;
var theMonth=0;
var theCount=1;
var zimmerId=1;
function init(){
	var a=document.getElementsByTagName('a');
	var inp=document.getElementsByTagName('input');
	var spn=document.getElementsByTagName('span');
	var dvi=document.getElementsByTagName('div');
	var toMov = false;
	for(var i=0;i<spn.length;i++){
		if(spn[i].id=='text1')toMov=true;
	}
	for(i=0;i<a.length;i++){
		a[i].onmousedown=new Function("this.onfocus=new Function('this.blur()');");
		a[i].onmouseout =  new Function ("this.onfocus=new Function('');");
		a[i].onmousemove = new Function ("this.onfocus=new Function('');");
		if(a[i].id=='pfeil2' && objId('text2') && objId('text2').style.display=='none'){
			a[i].style.display='';Style('pfeil1').display='none';
		}
		if(a[i].id=='pfeil1' && !objId('text2')){
			a[i].style.display='none';	
		}
	}
	
	for(i=0;i<inp.length;i++){
		if(inp[i].type=='submit'){
			inp[i].onmousedown=Function("this.onfocus=Function('this.blur()');");
			inp[i].onmouseout=Function("this.onfocus=Function('');");
			inp[i].onmousemove=Function("this.onfocus=Function('');");
		}
	}
	document.DocumentReady=true;
	for(i=0;i<document.getElementsByTagName('select').length;i++){
		document.getElementsByTagName('select')[i].id=document.getElementsByTagName('select')[i].name;	
	}
	if(objId('GueltigVonMonth')&&objId('GueltigBisMonth')){
		objId('GueltigVonMonth').onchange=new Function("switchDays(this.options[this.selectedIndex].value,this.id);");
		objId('GueltigBisMonth').onchange=new Function("switchDays(this.options[this.selectedIndex].value,this.id);");
	}
	if(document.firstDate)makeFrom(document.firstDate);
}

function makeFrom(date){
	theDay=date.substr(0,2);
	theMonth=date.substr(3,2);
	objId('GueltigVonDay').options[(theDay-1)].selected='true';
	objId('GueltigVonMonth').options[(theMonth-1)].selected='true';
	switchDays(objId('GueltigVonMonth').options[(theMonth-1)].value,objId('GueltigVonMonth').id);
	countDays();
}

function moveFfd(obj){
	if(!objId('text3')){
		Style('text1').display='none';
		Style('text2').display='';
		obj.style.display='none';
		Style('pfeil1').display='';
	}
	else{
		if(Style('text2').display=='none'){
			Style('text1').display='none';
			Style('text2').display='';
		}
		else{
			Style('text2').display='none'
			Style('text3').display='';
			obj.style.display='none';
			Style('pfeil1').display='';
		}
	}
	return false;
}

function moveBck(obj){
	if(!objId('text3')){
		Style('text1').display='';
		Style('text2').display='none';
		obj.style.display='none';
		Style('pfeil2').display='';
	}
	else{
		if(Style('text2').display=='none'){
			Style('text2').display='';
			Style('text3').display='none';
		}
		else{
			Style('text2').display='none'
			Style('text1').display='';
			obj.style.display='none';
			Style('pfeil2').display='';	
		}
	}
	return false;
}

function countDays(){
	var tmp=0;
	for(var i=0;i<theCount;i++){
		if(objId('GueltigBisDay').options[(parseInt(theDay,10)+parseInt(i,10))]&&objId('GueltigBisDay').options[(parseInt(theDay,10)+parseInt(i,10))].text){
			objId('GueltigBisDay').options[(parseInt(theDay,10)+parseInt(i,10))].selected='true';
			objId('GueltigBisMonth').options[(parseInt(theMonth,10)-1)].selected='true';
			switchDays(objId('GueltigBisMonth').options[(parseInt(theMonth,10)-1)].value,objId('GueltigBisMonth').id);
		}
		else{
			objId('GueltigBisDay').options[tmp].selected='true';
			objId('GueltigBisMonth').options[parseInt(theMonth,10)].selected='true';
			switchDays(objId('GueltigBisMonth').options[parseInt(theMonth,10)].value,objId('GueltigBisMonth').id);
			tmp++;
		}
	}
	//checkSumm();
}

function checkSumm(subm){
	var Standardpreis=parseFloat(document.zimmer[zimmerId]['0']);
	var zz=0;
	var Preise=new Array();
	var Gesamtpreis=0;
	var Startdatum='';
	var Daycounter=parseInt(objId('Daysctr').value,10);
	var tmp='';
	var tmp2;
	
	for(var i in document.zimmer[zimmerId]){
		if(i=='0')continue;
		if((zz>0)||(i==(objId('GueltigVonDay').options[objId('GueltigVonDay').selectedIndex].value+'.'+objId('GueltigVonMonth').options[objId('GueltigVonMonth').selectedIndex].value+'.'+objId('GueltigVonYear').options[objId('GueltigVonYear').selectedIndex].value))){
			if(zz==0){
				Startdatum=i;
			}
			Preise[zz]=document.zimmer[zimmerId][i];
			zz++;
		}}
		for(var q=0;q<Daycounter;q++){
			if(Preise[q]&&(parseFloat(Preise[q])>0)){
				Gesamtpreis+=parseFloat(Preise[q]);
			}
			else {
				Gesamtpreis+=Standardpreis;
			}
		}
		if(isNaN(parseInt(Daycounter,10))){
			Daycounter=1;
		}
		tmp=Math.round((Gesamtpreis/Daycounter)*100).toString();
		objId('preis').value=(tmp!='0')?(tmp.substr(0,(tmp.length-2))+','+tmp.substr((tmp.length-2),2)):tmp;
	if(subm=='sub'){
		postValues('post','/reservierung.php','frmRes','ra','lastminute','pr',objId('preis').value+',-€','zk',zimmerId,'dt',Startdatum,'lang',document.languag,'ah',Daycounter);
	}
	return false;
}

function checkFrueh(){
	var vonDatum=parseFloat(objId('GueltigVonYear').options[objId('GueltigVonYear').selectedIndex].value+objId('GueltigVonMonth').options[objId('GueltigVonMonth').selectedIndex].value+objId('GueltigVonDay').options[objId('GueltigVonDay').selectedIndex].value);
	var bisDatum=parseFloat(objId('GueltigBisYear').options[objId('GueltigBisYear').selectedIndex].value+objId('GueltigBisMonth').options[objId('GueltigBisMonth').selectedIndex].value+objId('GueltigBisDay').options[objId('GueltigBisDay').selectedIndex].value);
	
	if(vonDatum<document.today['n']){
		var zzMesse=(document.messe1 && (vonDatum<parseFloat(document.sixM)))?'regulären Preisen':'Messepreisen';
		var messName=document.messe1?((vonDatum<parseFloat(document.sixM))?'vor der 6 - Monatigen Mindestfrist':'zwar nach der 6 - Monatigen Mindestfrist, aber während der ' + document.messe1):'vor der 6 - Monatigen Mindestfrist';
		alert('Den Anreisetag, den Sie sich ausgesucht haben, können wir Ihnen nicht zu den Frühbucherpreisen anbieten,'+"\n"+'weil dieser ' + messName + ' stattfinden würde!'+"\n"+'Das Anreisedatum wird jetzt wieder auf den '+document.today['d']+'.'+document.today['m']+'.'+document.today['y']+', das frühstmögliche Datum zurückgesetzt.'+"\n"+'Falls Sie dennoch unbedingt zum von Ihnen angegebenen Datum anreisen möchten, klicken Sie bitte oben in der Navigation "Reservierung" an und buchen von dort aus zu unseren ' + zzMesse + '. Wir bitten wegen der Unannehmlichkeiten um Entschuldigung.'); 	
		for(var i=0;i<objId('GueltigVonYear').options.length;i++){
			if(objId('GueltigVonYear').options[i].text==document.today['y']){
				objId('GueltigVonYear').selectedIndex=i;
			}
		}
		objId('GueltigVonMonth').selectedIndex=(parseInt(document.today['m'],10)-1);
		objId('GueltigVonDay').selectedIndex=(parseInt(document.today['d'],10)-1);
		if(bisDatum<=parseFloat(objId('GueltigVonYear').options[objId('GueltigVonYear').selectedIndex].value+objId('GueltigVonMonth').options[objId('GueltigVonMonth').selectedIndex].value+objId('GueltigVonDay').options[objId('GueltigVonDay').selectedIndex].value)){
			for(var i=0;i<objId('GueltigBisYear').options.length;i++){
				if(objId('GueltigBisYear').options[i].text==document.tomorrow['y']){
					objId('GueltigBisYear').selectedIndex=i;
				}
			}
			objId('GueltigBisMonth').selectedIndex=(parseInt(document.tomorrow['m'],10)-1);
			objId('GueltigBisDay').selectedIndex=(parseInt(document.tomorrow['d'],10)-1);
		}
		if(checkFrueh())calkC(objId('preis'),'just');
		return false;
	}
	else if(bisDatum<vonDatum){
			alert('Den Abreisetag, den Sie sich ausgesucht haben, findet vor dem Anreisetag statt,'+"\n"+'bitte vergewissern Sie sich die Angaben richtig gemacht zu haben' );
		return false;
	}
	else if(bisDatum==vonDatum){
		return confirm('Der An- und Abreisetag sind der selbe, wollen Sie wirklich nicht übernachten? Bitte ändern Sie zunächst das Datum, falls Ihnen ein Fehler unterlaufen ist. Falls nicht, setzen Sie sich bitte mit uns telefonisch in Verbindung. Tel: 0511 65 65 97-0');
		return false; 
	}
	//else if(document.denied.length){
//		var alertText='';
//		var vonDeny=0;
//		var bisDeny=0;
//		
//		for(var ch=0;ch<document.denied.length;ch++){
//			vonDeny=parseFloat(document.denied[ch][0].substr(0,4)+document.denied[ch][0].substr(4,2)+document.denied[ch][0].substr(6,2));
//			bisDeny=parseFloat(document.denied[ch][1].substr(0,4)+document.denied[ch][1].substr(4,2)+document.denied[ch][1].substr(6,2));
//			
//			alertText='vom '+ document.denied[ch][0].substr(6,2)+'.'+document.denied[ch][0].substr(4,2)+'.'+document.denied[ch][0].substr(0,4)+' bis zum '+document.denied[ch][1].substr(6,2)+'.'+document.denied[ch][1].substr(4,2)+'.'+document.denied[ch][1].substr(0,4)+'.';
//		
//			if((((vonDatum+1) >= vonDeny) && ((bisDatum-1) <= bisDeny))||((vonDatum < vonDeny) && (bisDatum > bisDeny))){
//				alert(alertText+' findet die ' + document.messen[ch] + ' statt. Deshalb können wir Ihnen den gesamten Wunschzeitraum nicht vergünstigt anbieten. Bitte haben Sie dafür Verständnis. Falls Sie Ihrem angegebenen Wunschdatum bei uns verweilen möchten, klicken Sie bitte auf "Reservierung" und buchen Sie bitte zu unseren Messepreisen. Ansonsten wählen Sie bitte einen anderen Termin. Für die Unannehmlichkeiten bitte wir um Entschuldigung.');
//			return false;
//			}
//			else if((vonDatum >= vonDeny) && (vonDatum <= bisDeny) &&  (bisDatum > (bisDeny+1))){
//				alert(alertText+' findet die ' + document.messen[ch] + ' statt. Deshalb können wir Ihnen den gesamten Wunschzeitraum nicht vergünstigt anbieten. Das Anreisedatum wird jetzt im Rahmen des Frühbucherangebots korrigiert. Bitte haben Sie dafür Verständnis. Falls Sie Ihrem vorher angegebenen Wunschdatum bei uns verweilen möchten, klicken Sie bitte auf "Reservierung" und buchen Sie bitte die restlichen Tage zu unseren Messepreisen. Ansonsten wählen Sie bitte einen anderen Termin. Für die Unannehmlichkeiten bitte wir um Entschuldigung.');
//				for(var i=0;i<objId('GueltigVonYear').options.length;i++){
//					if(objId('GueltigVonYear').options[i].text==document.denied[ch][1].substr(0,4)){
//						objId('GueltigVonYear').selectedIndex=i;
//					}
//				}
//				objId('GueltigVonMonth').selectedIndex=parseFloat(document.denied[ch][1].substr(4,2)-1);
//				objId('GueltigVonDay').selectedIndex=parseFloat(document.denied[ch][1].substr(6,2));
//				if(checkFrueh())calkC(objId('preis'),'just');
//				return false;
//			}
//			else if((bisDatum >= vonDeny) && (bisDatum <= bisDeny) && (vonDatum < (vonDeny-1))){
//				alert(alertText+' findet die ' + document.messen[ch] + ' statt. Deshalb können wir Ihnen den gesamten Wunschzeitraum nicht vergünstigt anbieten. Das Abreisedatum wird jetzt im Rahmen des Frühbucherangebots korrigiert. Bitte haben Sie dafür Verständnis. Falls Sie Ihrem vorher angegebenen Wunschdatum bei uns verweilen möchten, klicken Sie bitte auf "Reservierung" und buchen Sie bitte die restlichen Tage zu unseren Messepreisen. Ansonsten wählen Sie bitte einen anderen Termin. Für die Unannehmlichkeiten bitte wir um Entschuldigung.');
//				for(var i=0;i<objId('GueltigBisYear').options.length;i++){
//					if(objId('GueltigBisYear').options[i].text==document.denied[ch][0].substr(0,4)){
//						objId('GueltigBisYear').selectedIndex=i;
//					}
//				}
//				objId('GueltigBisMonth').selectedIndex=parseFloat(document.denied[ch][0].substr(4,2)-1);
//				objId('GueltigBisDay').selectedIndex=parseFloat(document.denied[ch][0].substr(6,2)-2);
//				if(checkFrueh())calkC(objId('preis'),'just');
//				return false;
//			}
//		}
//	}
	return true;
}
function postValues(Meth,Act,Id,Name,Value){
	var Names 	= 	[Name];
	var Values 	= 	[Value];
	if(arguments.length>5){
		for (var i=3;i<arguments.length;i++){
			if ((i%2)==0){//alert(arguments[i])
				Values=Values.concat([arguments[i]]);
			}
			else{//alert(arguments[i])
				Names=Names.concat([arguments[i]]);
			}
		}
	}
	var Form = makeForm(Meth,Act,Id);
	for(i=0;i<Names.length;i++){
		makeHiddenField(Form,Names[i],Values[i]);
	}
	Form.submit();
}
function makeForm(Meth,Act,Id){
	var frmElem=document.createElement('form');
	var myForm=document.getElementsByTagName('body')[0].appendChild(frmElem);
	myForm.name=Id;
	myForm.id=Id;
	myForm.action=Act;
	myForm.method=Meth;
	return myForm;
}

function makeHiddenField(Form,Name,Value){
	var myHidd=Form.appendChild(IE==true?document.createElement('<INPUT TYPE=HIDDEN />'):document.createElement('input'));
	if(IE==false){
		myHidd.setAttribute('type','hidden');
	}
	myHidd.id=Name;
	myHidd.name=Name;
	myHidd.value=Value;
}


		var vonDay=0;
		var vonMonth=0;
		var vonYear=0;
		var bisDay=0;
		var bisMonth=0;
		var bisYear=0;


function calkC(Obj, Do){
		var ddays=0;
		var mmonths=0;
		vonDay=parseInt(objId('GueltigVonDay').options[objId('GueltigVonDay').selectedIndex].value,10);
		vonMonth=parseInt(objId('GueltigVonMonth').options[objId('GueltigVonMonth').selectedIndex].value,10);
		vonYear=parseInt(objId('GueltigVonYear').options[objId('GueltigVonYear').selectedIndex].value,10);
		bisDay=parseInt(objId('GueltigBisDay').options[objId('GueltigBisDay').selectedIndex].value,10);
		bisMonth=parseInt(objId('GueltigBisMonth').options[objId('GueltigBisMonth').selectedIndex].value,10);
		bisYear=parseInt(objId('GueltigBisYear').options[objId('GueltigBisYear').selectedIndex].value,10);
		
		var vonMonthMaxDays=monthDays(objId('GueltigVonMonth').options[objId('GueltigVonMonth').selectedIndex].value);
		
		for (var i=0;i<(bisYear-vonYear);i++){
			ddays+=365;
		}
		
		if((vonMonth<bisMonth)||(bisMonth<vonMonth)){
			if((vonMonth<bisMonth)){
				ddays+=bisDay-vonDay;
				mmonths=(bisMonth-vonMonth);	
				for(i=0;i<mmonths;i++){
					ddays+=monthDays((vonMonth+i));
				}
			}
			else if((vonMonth>bisMonth)){
				ddays+=bisDay-vonDay;
				mmonths=(vonMonth-bisMonth);
				for(i=0;i<mmonths;i++){
					ddays-=monthDays((bisMonth+i));
				}
			}
		}
		else {
			ddays+=bisDay-vonDay;
		}
	
		objId('Daysctr').value=ddays;
		document.Days=ddays;
	if(document.einTag>0){
		var ttmp=Math.round(document.Days*document.einTag*100);
		ttmp=ttmp.toString();
		var ttmp2=ttmp.substr(0,ttmp.length-2);
		var ttmp3=ttmp.substr(ttmp.length-2,2);
		Obj.value=ttmp2+','+ttmp3;
	}
	if(Do!='just' && ((document.Days*document.einTag)>0)){
		postValues('post','/reservierung.php','frmRes','ra','frühbucher','pr',(document.Days*document.einTag)+',-€','zk',zimmerId,'dt',vonDay+'.'+vonMonth+'.'+vonYear,'lang',document.languag,'ah',document.Days);
	}
}

function monthDays(Month){
	var Days=0;
	Month=parseInt(Month,10);
	switch(Month){
		case  1:Days=31;break;
		case  2:Days=28;break;
		case  3:Days=31;break;
		case  4:Days=30;break;
		case  5:Days=31;break;
		case  6:Days=30;break;
		case  7:Days=31;break;
		case  8:Days=31;break;
		case  9:Days=30;break;
		case 10:Days=31;break;
		case 11:Days=30;break;
		case 12:Days=31;break;
	}
	return Days;
}

function switchDays(Month,Id){
	var Days=monthDays(Month);
	
	var obj=objId(Id.replace(/Month/,'Day'));
	var Current=obj.options.length;
	if(Current!=Days){
		if(Days>Current){
			for(var i=(Current+1);i<=Days;i++){
				obj.options[i-1]=new Option(i,i,false,false);
			}	
		}
		else if(Days<Current){
			if((obj.selectedIndex+1)>Days){
				obj.selectedIndex=(Days-1);
				
			}
			for(i=Current;i>Days;i--){
				obj.options[i-1]=null;
			}
		}
	}
}

var Obj2='', Vis2='';

function hideLayer(Obj,Vis){
	window.clearTimeout(tmr);
Style(Obj).visibility=Vis;
}

var tmr2='',mom=100,mmom=0;



function showHideLayers(Obj,Vis) {
	if(Obj2 && (Obj!=Obj2 && Vis == 'visible'))
	{Style(Obj2).visibility='hidden';window.clearTimeout(tmr);} 
	Obj2=Obj;
	Vis2=Vis;
	if(Vis=='hidden'){
		tmr=window.setTimeout('hideLayer(Obj2,Vis2)',1000);
		return;
	}
	Style(Obj).visibility=Vis;
}
window.onload=init;
//window.onresize=makeLayerPosition;