

var leftMargin = 730; // Annette 11.08.06
var topMargin = 0;
var minScrollDist = 550;
var slideTime = 1000;
var ns6 = (!document.all && document.getElementById);
var ie4 = (document.all);
var ns4 = (document.layers);

function layerObject(id,left) {
	if (ns6) {
		this.obj = document.getElementById(id).style;
		this.obj.left = left + 'px';
		return this.obj;
	}
	else if(ie4) {
		this.obj = document.all[id].style;
		this.obj.left = left;
		return this.obj;
	}
	else if(ns4) {
		this.obj = document.layers[id];
		this.obj.left = left;
		return this.obj;
   }
}

function layerSetup() {
	floatLyr = new layerObject('floatLayer', leftMargin);
	window.setInterval("main()", 10)
}

function floatObject() {
	if (ns4 || ns6) {
		findHt = window.innerHeight;
	} else if(ie4) {
		findHt = document.body.clientHeight;
   }
}

function main() {
	if (ns4) {
		this.currentY = document.layers["floatLayer"].top;
		this.scrollTop = window.pageYOffset;
		mainTrigger();
	}
	else if(ns6) {
		this.currentY = parseInt(document.getElementById('floatLayer').style.top);
		this.scrollTop = scrollY;
		mainTrigger();
	} else if(ie4) {
		this.currentY = floatLayer.style.pixelTop;
		//läuft der Explorer im Standart-Modus? -Annette 21.08.
		if (typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat'){
			this.scrollTop = document.documentElement.scrollTop;
		}else {
			this.scrollTop = document.body.scrollTop;
		}
		mainTrigger();
   	}
}

function mainTrigger() {
	var newTargetY = Math.max(this.scrollTop + this.topMargin, 0);
	if ( this.currentY != newTargetY ) {
		if ( newTargetY != this.targetY ) {
			this.targetY = newTargetY;
			floatStart();
		}
		animator();
   	}
}

function floatStart() {
	var now = new Date();
	this.A = this.targetY - this.currentY;
	this.B = Math.PI / ( 2 * this.slideTime );
	this.C = now.getTime();
	if (Math.abs(this.A) > this.findHt) {
		this.D = this.A > 0 ? this.targetY - this.findHt : this.targetY + this.findHt;
		this.A = this.A > 0 ? this.findHt : -this.findHt;
	}
	else {
		this.D = this.currentY;
   }
}

function animator() {
	var now = new Date();
	var newY = this.A * Math.sin( this.B * ( now.getTime() - this.C ) ) + this.D;
	newY = Math.round(newY);
	if (( this.A > 0 && newY > this.currentY ) || ( this.A < 0 && newY < this.currentY )) {
		if ( ie4 )document.all.floatLayer.style.pixelTop = newY;
		if ( ns4 )document.layers["floatLayer"].top = newY;
		if ( ns6 )document.getElementById('floatLayer').style.top = newY + "px";
   	}
}

function start() {
	if(ns6||ns4) {
		if (ns4) {
			topMargin = 0 - minScrollDist - document.layers["floatLayer"].top;
		}
		else {
			topMargin = 0 - minScrollDist - parseInt(document.getElementById('floatLayer').style.top);
		}
		pageWidth = innerWidth;
		pageHeight = innerHeight;
		layerSetup();
		floatObject();
	}
	else if(ie4) {
		topMargin = 0 - minScrollDist - floatLayer.style.pixelTop;
		pageWidth = document.body.clientWidth;
		pageHeight = document.body.clientHeight;
		layerSetup();
		floatObject();
   	}
}






function PopupAttributesOption(option_id) {
	var nw = window.open( '/products_attributes_popup.php?option_id=' + option_id, 'tnw', 'width=475,height=250,scrollbars=yes,menubar=no,status=no,top=50,left=50' );
	nw.focus();
}

function toggleAttributesContent(option_no, attribute_no)
{
	var content = document.getElementById('content' + option_no + '_' + attribute_no);

	if (content.style.display=='none')
	{
		content.style.display = 'block';
	} else {
		content.style.display = 'none';
	}

	mouseoutAttribute(option_no, attribute_no);
}

function setImage(label, path)
{
	var image = document.getElementById(label);
	if (image) {
		image.src = path;
	}
}

function hoverAttribute(row, button_name)
{
	var button = document.getElementById(button_name);

	if (button.checked==true) {
		row.className = 'AttributActive';
	} else {
		row.className = 'AttributHover';
	}
}

function mouseoutAttribute(option_no, attribute_no)
{
	var row = document.getElementById('row' + option_no + '_' + attribute_no);
	var button = document.getElementById('button' + option_no + '_' + attribute_no);

	if (button.checked==true) {
		row.className = 'AttributActive';
	} else {
		var content = document.getElementById('content' + option_no + '_' + attribute_no);
		if (content) {
			if (content.style.display=='block')	{
				row.className = 'AttributActive';
			} else {
				row.className = 'AttributStandart';
			}
		} else {
			row.className = 'AttributStandart';
		}
	}
}

function checkAttribute(type, option_no, attribute_no, attribute_price)
{
	var table = document.getElementById('option_table' + option_no);
	var row = document.getElementById('row' + option_no + '_' + attribute_no);
	var button = document.getElementById('button' + option_no + '_' + attribute_no);

	if (table && row && button) {

		if (type=='checkbox') {
   			if (button.checked==true) {
				button.checked = false;
			} else {
				button.checked = true;
			}
		}
		else if (type=='radio') {
			button.checked = true;
		}

		setAttributePrice(type, option_no, attribute_no, attribute_price);

		var rows = table.getElementsByTagName('input');
   		for (var i = 0; i < rows.length -1; i++) {
			mouseoutAttribute(option_no, i);
   		}
   	}
}

function setAttributePrice(type, option_no, attribute_no, attribute_price)
{
	button_name = 'button' + option_no + '_' + attribute_no;
	var button = document.getElementById(button_name);

	if (type=='checkbox') {
   		if (button.checked==false) {
			attribute_price = 0;
		}
		price_name = 'aprice' + option_no + '_' + attribute_no;
	}
	else if (type=='radio') {
		price_name = 'aprice' + option_no;
	}

	document.getElementById(price_name).value = attribute_price;

	calcPrice();
}

// add pandaro 29.10.2006

function pf_restwert(anfang, monat)
{
	pf_zinssatz = 1.0122;
	tilgung = Math.max(13, Math.ceil(anfang / 40));
	ergebnis = (anfang * Math.pow(pf_zinssatz,monat)) - (tilgung * ((Math.pow(pf_zinssatz,monat))-1) / (pf_zinssatz-1));
	return ergebnis;
}

function pf_laufzeit(anfang)
{
	tilgung = Math.max(13, Math.ceil(anfang / 40));
	lauf = Math.ceil( anfang / tilgung );
	while (pf_restwert(anfang, lauf) > 0) { lauf++; };
	return lauf;
}
function calcGE(s,p,n)
{
	p=parseFloat(p);
	n=parseFloat(n);
	s=parseFloat(s);
	rate=s*(Math.pow(1+p,1/12)-1)/(1-Math.pow(1+p,-n/12));
	return Math.round(rate*100)/100;

}
// add end.
function monatsrate(betrag, lz, effz)
{
	proz = Math.pow( (1+(effz/100)), (1/12));
	ergebnis = (betrag * (1 - proz)) * ( Math.pow(proz,lz) / (1 - Math.pow(proz,lz) ));
	return ergebnis;
}
function calcPrice()
{
	var aprice_total = 0;
	var aprice = document.getElementsByName("aprice");
	for (var i = 0; i < aprice.length; i++) {
		aprice_total = aprice_total + parseFloat(aprice[i].value);
	}
	var pnormal_total = pnormal + aprice_total;

	if (pnormal_total > 1000) {
		var effz = 15.9;
	} else {
		var effz = 9.9;
	}
	var laufz = 1;
	var dcRate = pnormal_total;
//	for (i=0; i<8; i++){
//		var resultat = monatsrate(pnormal_total, (i+1)*6, effz);
//		if (parseFloat(resultat) > 15) {
//			laufz = (i+1)*6;
//			dcRate = resultat;
//		}
//	}	
	dcRate = Math.max(9, Math.ceil(pnormal_total/100)*3);
	
/*	pfinanzierung = Math.max(Math.ceil(pnormal_total / 40), 13);
	zins = 1.0122;
	fLauf = 0;
	rest = pnormal_total;
	while (rest > 0)
	{
		rest = Math.round( ((rest*zins)-pfinanzierung) * 100) / 100 ;
		fLauf++;
	}
	
*/
	document.getElementById('preis_total').firstChild.nodeValue = number_format(pnormal_total,2,',','.') + ' EUR';
	document.getElementById('preis_finanzierung').firstChild.nodeValue = number_format(dcRate,2,',','.');
	if (document.getElementById('preis_finanzierung_laufzeit')) {
		document.getElementById('preis_finanzierung_laufzeit').firstChild.nodeValue =  laufz;
	}
	if (document.getElementById('preis_finanzierung_zinssatz')) {
		document.getElementById('preis_finanzierung_zinssatz').firstChild.nodeValue =  number_format(effz,2,',','')+' %';
	}

	var uvpElement;
	uvpElement = document.getElementById("preis_uvp");
	if (uvpElement) {
   		uvpElement.firstChild.nodeValue = number_format((puvp + aprice_total),2,',','.');
	}
}

function number_format( /* in: float   */ number,
                      	/* in: integer */ laenge,
                        /* in: String  */ sep,
                        /* in: String  */ th_sep )
{
	number = Math.round( number * Math.pow(10, laenge) ) / Math.pow(10, laenge);
	str_number = number+"";
	arr_int = str_number.split(".");
	if(!arr_int[0]) arr_int[0] = "0";
	if(!arr_int[1]) arr_int[1] = "";
	if(arr_int[1].length < laenge) {
   		nachkomma = arr_int[1];
		for(i=arr_int[1].length+1; i <= laenge; i++) {  nachkomma += "0";  }
		arr_int[1] = nachkomma;
	}
	if(th_sep != "" && arr_int[0].length > 3) {
   		Begriff = arr_int[0];
   		arr_int[0] = "";
   		for(j = 3; j < Begriff.length ; j+=3) {
   			Extrakt = Begriff.slice(Begriff.length - j, Begriff.length - j + 3);
   			arr_int[0] = th_sep + Extrakt +  arr_int[0] + "";
   		}
  		str_first = Begriff.substr(0, (Begriff.length % 3 == 0)?3:(Begriff.length % 3));
   		arr_int[0] = str_first + arr_int[0];
	}
	return arr_int[0]+sep+arr_int[1];
}


var oElement;
if (document.getElementById) {
  oElement = document.getElementById("floatLayer");
  if (oElement) {
    if (oElement.style) {
      oElement.style.left = leftMargin;
    }
  }
}

/* Die Initialisierung befindet sich in 'templates/xtc4/javascript/general.js.php'*/
