function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

function show(layer) {	
	MM_showHideLayers(layer,'','show')
}
	
function hide(layer) {	
	MM_showHideLayers(layer,'','hide')
}

function showtext(lay,html) {
	writelayer(lay,html);
	show(lay);
}

function writelayer(lay,html) {
	if (document.all) { 
		document.all[lay].innerHTML = html; 
	} else if (document.getElementById) {
		document.getElementById(lay).innerHTML = html; 
	} else if (document.layers) { 
		with (document.layers[lay]) { 
		   visibility = "hide";
		    document.open(); 
		    document.write(html+"\n"); 
		    document.close();
		   visibility = "show";
		}
	} 
}

function repositionTo(obj,xL,yL) {
	if ( (ns4) || (ie4) ) {
	        obj.left = xL;
	        obj.top = yL;
	} else if (ns6) {
		obj.style.left = xL + "px";
		obj.style.top = yL+ "px";
	}
}

function layerWrite(txt) {
	txt += "\n";
	
        if (ns4) {
                var lyr = o3_frame.document.overDiv.document

                lyr.write(txt)
                lyr.close()
        } else if (ie4) {
		o3_frame.document.all["overDiv"].innerHTML = txt
	} else if (ns6) {
		range = o3_frame.document.createRange();
		range.setStartBefore(over);
		domfrag = range.createContextualFragment(txt);
		while (over.hasChildNodes()) {
			over.removeChild(over.lastChild);
		}
		over.appendChild(domfrag);
	}
}

function calculate(field,faktor) {
	var name = field.name;
	var index = name.slice(1,3);
	var cname = 'c' + index;
	var calc = toN(field.value) * faktor;
	var round = Math.round(calc * 1000) / 1000;
	window.form[cname].value = round;
}

function weightDifference() {
	window.form['difference'].value = (window.form['weight01'].value - window.form['weight02'].value)*(-1);
}
	
function prozent(sum, value) {
	return value * 100 / sum;
}
	
function calculateWeek(field) {
	var name = field.name;
	var index = eval(name.slice(1,3));
	var row = name.slice(0,1);

	var ksum=0;
	var esum=0;
	var fsum=0;
	for (i=1; i<=7; i++) {
		ksum = ksum + toN(window.form['t10'+i].value);
		esum = esum + toN(window.form['t20'+i].value);
		fsum = fsum + toN(window.form['t30'+i].value);
		window.form['t0'+i].value = toN(window.form['t10'+i].value) + toN(window.form['t20'+i].value) + toN(window.form['t30'+i].value);
	}
	window.form['summe1'].value = ksum;
	window.form['summe2'].value = esum;
	window.form['summe3'].value = fsum;
	var tsum = ksum + esum + fsum;
	window.form['summe'].value = tsum;
	window.form['prozent1'].value = Math.round(prozent(tsum, ksum) * 100) / 100;
	window.form['prozent2'].value = Math.round(prozent(tsum, esum) * 100) / 100;
	window.form['prozent3'].value = Math.round(prozent(tsum, fsum) * 100) / 100;
}	

function toN(s) {
	s=s.replace(/,/g,'.');
	s=s.replace(/[^0-9\.]/g,'');
	return Number(s);
}

