ns4 = (document.layers) ? true:false
ns6 = (document.getElementById) ? true:false

function changeAcc() {
 acc = document.form1.account.value;
 
 ts = '';
 t = Math.round((acc * 0.3)/1000);
 for (i=1; i<=t; i++) {
  if (acc-i*1000<5000) { break; }
  ts += "<option value='"+i*1000+"'>&nbsp;"+i+".000 &euro;&nbsp;</option>";
 }
 ts = "<select onChange='changeTO()' name='takeout'><option value='0'>&nbsp;Keine </option>"+ts+"</select>";
 ih('tolist', ts);

 ih('scapital', dl(acc));
 ih('scapital2', "<br><br><br>"+dl(acc)+' &euro;');
 doCalc(acc);
}


function changeTO() {
 acc = document.form1.account.value;
 to =  document.form1.takeout.value;
 
 ih('scapital', dl(acc-to));
 ih('scapital2', "<br><br><br>"+dl(acc-to)+' &euro;');
 
 doCalc(acc-to);
}

function doCalc(sc) {
 sc = sc * 2;
 mf = Math.round(sc * 0.0035);

 ih('mfee', mf);
 ih('mfee2', mf);
 ih('yfee', mf*12);
 ih('a10', dl(mf*120));
 ih('a11', dl((sc-mf*120)/2));
 ih('a12', dl((sc-mf*120)/2));
 
 for (i=1; i<=10; i++) { ih('b'+i, dl(mf*12)+' &euro;'); }
 ih('b11', "<br>"+dl((sc-mf*120)/2)+' &euro;');
 ih('b12', "<br>"+dl((sc-mf*120)/2)+' &euro;');

 
 ih('total', dl(mf*120 + (sc-mf*120)));
 ih('total2', "<br><br><br><br><br><br><br>"+dl(mf*120 + (sc-mf*120))+" &euro;");
}

function dl(d) {
/* d2 = Number(d);
 return d2.toLocaleString();*/
 
 d = String(d);
 
 if (d.length>3) {
  d = d.replace(/(\d{3})$/, ".$1");
  if (d.length>7) { d = d.replace(/(\d{3}\.)/, ".$1"); }
  if (d.length>11) { d = d.replace(/(\d{3}\.)/, ".$1"); }
 }

 return d;
}

function ih(id, text) {
 if (ns4) {
	var lyr = (nestref)?
	eval('document.'+nestref+'.document.'+id+'.document') : document.layers[id].document
	lyr.open()
	lyr.write(text)
	lyr.close()
 }
 else if (ns6) { document.getElementById(id).innerHTML = text; }
 else { document.all[id].innerHTML = text; }
}


function pruefen() {
	if ((document.form1.message != undefined) && (document.form1.message.value == "")) {
		alert("Sie haben Ihre TexFeld nicht angegeben!");
		document.form1.message.focus();
		return false;
	}
	
	if (document.form1.name.value == "") {
		alert("Sie haben Ihren Namen nicht angegeben!");
		document.form1.name.focus();
		return false;
	}

	if ((document.form1.city != undefined) && (document.form1.city.value == "")) {
		alert("Sie haben Ihre Handy nicht angegeben!");
		document.form1.city.focus();
		return false;
	}

	if ((document.form1.mobile != undefined) && (document.form1.mobile.value == "")) {
		alert("Sie haben Ihre Handy nicht angegeben!");
		document.form1.mobile.focus();
		return false;
	}

	if ((document.form1.hotel != undefined) && (document.form1.hotel.value == "")) {
		alert("Sie haben Ihre Bevorzugtes Hotel nicht angegeben!");
		document.form1.hotel.focus();
		return false;
	}
	if ((document.form1.auto != undefined) && (document.form1.auto.value == "")) {
		alert("Sie haben Ihre Wunschauto nicht angegeben!");
		document.form1.auto.focus();
		return false;
	}
	if ((document.form1.email.value == "") || (document.forms[0].email.value.indexOf('@') == -1)) {
		alert("Sie haben Ihre Email-Adresse nicht angegeben!");
		document.form1.email.focus();
		return false;
	}
}


function ol(url, w, h, wname, simple) {
 if (w == '') { w = '850'; }
 if (h == '') { h = '800'; }
 if (wname == '') { wname = 'newwin'; }
 
 if (simple == true) {
  nw = window.open(url,wname,"width="+w+",height="+h+",left=0,top=0,scrollbars=1,resizable=1,status=0");
 }
 else {
  nw = window.open(url,wname,"width="+w+",height="+h+",left=0,top=0,scrollbars=1,menubar=1,resizable=1,status=1,location=1,toolbar=1");
 }

 nw.focus();
 return false;
}

function topCalc() {
 now = new Date();
 y2009 = new Date(2009, 0, 0, 0, 0, 0);
 
 csum = Math.round(433.937*(now.getTime() - y2009.getTime())/1000);

 ih('tcounter', dl(csum)+' &euro;');
 setTimeout('topCalc()', 1000);
}

function getCalcRes(f, y) {
 f = f * 30;
 m = 1;
 p2 = 12;
 z = (1 + (r/(100 * m)));

 return Math.round(f * (Math.pow(z,(y * m))-1) / (Math.pow(z, (m / p2))-1));
 
}

function tagCalc() {
 f = document.frmTag.seltag.options[document.frmTag.seltag.options.selectedIndex].text;
 r = document.frmTag.seljahr.options[document.frmTag.seljahr.options.selectedIndex].text;

 ih('y5', dl(getCalcRes(f, 5)));
 ih('y10', dl(getCalcRes(f, 10)));
 ih('y15', dl(getCalcRes(f, 15)));
 ih('y20', dl(getCalcRes(f, 20)));
 ih('y30', dl(getCalcRes(f, 30)));
}

