// docwrite.js

function HideMail() {
var anchortext = "Email";
var mailpart1 = "mail";
var mailpart2 = "hotelstadtnah.de";
document.write("<a href=" + "mail" + "to:" + mailpart1 +
"@" + mailpart2 + ">" + anchortext + "</a>")
}

function HideMail2() {
var anchortext = "Email";
var mailpart1 = "mail";
var mailpart2 = "hotel-ambahnhof.de";
document.write("<a href=" + "mail" + "to:" + mailpart1 +
"@" + mailpart2 + ">" + anchortext + "</a>")
}

function ouvrir(cebloc) {
styleObj = document.getElementById(cebloc).style;
if (styleObj.display=='none') {styleObj.display = '';}
else {styleObj.display = 'none';}
}



function SetPreis (ub) {
 if (ub!="") {
				document.L.preis.value="á "+ub+" €";
			} else
					{
			document.L.preis.value="";
			}	
}

function CalcGPreis (epr,naechte) {
 if (epr=="") { alert("Bitte wählen Sie ein Hotel und ein Zimmer aus."); document.L.A_120.focus(); return false;
 }
 if ((epr!="") && (naechte!="")) {
 //alert(document.L.zimmer.value+" * "+epr+" * "+naechte);
				document.L.gpreis.value=kaufm(document.L.zimmer.value*epr*naechte)+" €";
 }
}

function SetGPreis (epr,naechte) {
 if ((epr!="") && (naechte!="")) {
	document.L.gpreis.value=kaufm(document.L.zimmer.value*epr*naechte)+" €";
	SetPreis(document.L.A_120.options[document.L.A_120.options.selectedIndex].value);
 }
 if ((document.L.D_VOM.value!="") && (document.L.D_BIS.value!="")) {
	days_between(document.L.D_VOM.value,document.L.D_BIS.value,epr);
 }
 if ((document.L.D_VOM.value=="") || (document.L.D_BIS.value=="")) { alert("Geben Sie bitte Ihr An- und Abreisedatum ein."); return false;
 }
 if (epr=="") { alert("Bitte treffen Sie eine Auswahl in unserem Zimmerangebot"); document.L.A_120.focus(); return false;
 }

}

function checkroom() {
 if ((document.L.D_VOM.value!="") && (document.L.D_BIS.value!="")) {
	days_between(document.L.D_VOM.value,document.L.D_BIS.value,document.L.preis.value);
 }
}

function StartCalender(bak,vdat)
{
 URL="kalender/cal_show.asp?wohin="+bak+"&VONDATUM="+vdat;
 //fxfC = window.open(URL ,"NVHET","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=800,height=200")
 //fxfC
 //fxfC.focus();   
 top.date.location.href=URL;
}

//var vard=0


function kaufm(x) {
  var k = (Math.round(x * 100) / 100).toString();
  k += (k.indexOf('.') == -1)? '.00' : '00';
  var p = k.indexOf('.'), m = k.indexOf('-.');
  var f = (p == 0 || m == 0)? '0,' : ',';
  return k.substring(0, p) + f + k.substring(p+1, p+3);
}





var one_day=1000*60*60*24
var one_month=1000*60*60*24*30
var one_year=1000*60*60*24*30*12


function displayage(yr,mon,day,yrb,mnb,dyb, unit, decimal, round, epreis) {

	var bisdate=new Date(yrb,mnb-1,dyb)
	var pastdate=new Date(yr,mon-1,day)
	
	var countunit=unit
	var decimals=decimal
	var rounding=round
	
	finalunit=(countunit=="days")? one_day : (countunit=="months")? one_month : one_year
	decimals=(decimals<=0)? 1 : decimals*10
	
	vard=(Math.floor((bisdate.getTime()-pastdate.getTime())/(finalunit)*decimals)/decimals)
	
	if (vard<1) { alert("Der Abreisetag liegt vor dem Anreisetag!\n\nBitte geben Sie den Abreisetag erneut ein."); document.L.D_BIS.value=""; document.L.D_BIS.focus(); return false}
	else {
		if (document.L.zimmer.value==1){		document.L.naechte.value=vard;document.L.anaechte.value=vard;}
		if (document.L.zimmer.value>1){		document.L.anaechte.value=vard+" x "+document.L.zimmer.value;
		 document.L.naechte.value=vard;
		}
		//alert(vard+" Nächte á\n"+epreis+" EUR/Nacht")
		if (epreis!="") {
			//alert(document.L.zimmer.value+" mal "+epreis+" mal "+document.L.naechte.value)
			gespreis=kaufm(document.L.naechte.value*document.L.A_120.options[document.L.A_120.options.selectedIndex].value*document.L.zimmer.value);
			document.L.gpreis.value=gespreis+" €";
		}
	}
}



function check_days_between(date1,date2,epreis) {
if (date1=="")	{alert("Bitte geben Sie an, wann Sie anreisen möchten..."); document.L.D_VOM.focus(); return false}
if (date2=="")	{alert("Bitte Enddatum eingeben..."); document.L.D_BIS.focus(); return false}
//if (epreis=="")	{alert("Wenn Sie Angaben zum Zimmer machen, dann wird Ihnen der Gesamtbetrag für den Zeitraum Ihres Besuches angezeigt..."); document.L.A_120.focus();}
//alert(date1+" # "+date2+" # "+epreis)
days_between(date1,date2,epreis)
}

function days_between(date1,date2,epreis) {

	tempv=date1.split(".");
	vt=tempv[0];
	vm=tempv[1];
	vj=tempv[2];

	tempb=date2.split(".");
	bt=tempb[0];
	bm=tempb[1];
	bj=tempb[2];


  displayage(vj,vm,vt,bj,bm,bt,"days",0,"rounddown",epreis)
}

function add_value(field, maxAmount) {
	i = parseInt(field.value) + 1;
	if(i > maxAmount) 
		i = maxAmount;
	if(isNaN(i)) {
		field.value = 1;
	} else {
		field.value = i;
		if ((document.L.D_VOM.value!="") && (document.L.D_BIS.value!="") && (document.L.preis.value!="")) {
		days_between(document.L.D_VOM.value,document.L.D_BIS.value,document.L.preis.value);
	 }
	}
}

function reduce_value(field) {

	i = parseInt(field.value) - 1;
	if(i < 0)
		i = 0;
	if(isNaN(i)) {
		field.value = 1;
	} else {
		field.value = i;
		if ((document.L.D_VOM.value!="") && (document.L.D_BIS.value!="") && (document.L.preis.value!="")) {
		days_between(document.L.D_VOM.value,document.L.D_BIS.value,document.L.preis.value);
	 }
	}
}
