<!--

  // © 2007 Bitpalast GmbH. Alle Rechte vorbehalten.

	function numbersandcommasonly(e){
		var unicode=e.charCode? e.charCode : e.keyCode
		if ((unicode!=8) && (unicode!=44) && (unicode!=9)){ //if the key isn't the backspace key, tab key, or a comma (which we should allow)
		if (unicode<48||unicode>57) //if not a number
		return false //disable key press
		}
	}

	function removedivider(number) {
		var newvalue = number.replace(/\./g, "");
		return (newvalue);
	}

	function insertdivider(number) {

		// split decimal part
		parts = number.split(",");
		number = parts[0];

		number = '' + number;
		number = number.replace(/\./g, "");

		if (number.length>1) {
			number = number.replace(/^0+/,"");
		}

		if (number.length > 3) {
			var mod = number.length % 3;
			var output = (mod > 0 ? (number.substring(0,mod)) : '');
			for (i=0 ; i < Math.floor(number.length / 3); i++) {
				if ((mod == 0) && (i == 0))
				output += number.substring(mod+ 3 * i, mod + 3 * i + 3);
				else
				// set divider character '.'
				output+= '.' + number.substring(mod + 3 * i, mod + 3 * i + 3);
			}
			if (typeof(parts[1]) != 'undefined') {
				output = output+","+parts[1];
			}
			return (output);
		}
		else {
			if (typeof(parts[1]) != 'undefined') {
				number = number+","+parts[1];
			}
			return number;
		}
	}

	function calculaterunlength() {
		optionindex = document.forms['filmcalculator'].framespermeter.selectedIndex;
		meter = removedivider(document.forms['filmcalculator'].meter.value);
		meter = meter.replace(/\,/g, ".");
		totalframes = document.forms['filmcalculator'].framespermeter.options[optionindex].value * meter;

		optionindex = document.forms['filmcalculator'].framespersecond.selectedIndex;
		framespersecond = document.forms['filmcalculator'].framespersecond.options[optionindex].value;

		runlength = totalframes/framespersecond;

		runlengthhours = Math.floor(runlength/3600);
		if (runlengthhours>0) runlength = runlength-(3600*runlengthhours);

		runlengthminutes = Math.floor(runlength/60);
		if (runlengthminutes>0) {
			runlengthseconds = Math.ceil(runlength-(60*runlengthminutes));
		} else {
			runlengthseconds = Math.ceil(runlength);
		}

		if (runlengthhours<10) {
			$outrunlengthhours = '0'+runlengthhours;
		} else {
			$outrunlengthhours = runlengthhours;
		}
		if (runlengthminutes<10) {
			$outrunlengthminutes = '0'+runlengthminutes;
		} else {
			$outrunlengthminutes = runlengthminutes;
		}
		if (runlengthseconds<10) {
			$outrunlengthseconds = '0'+runlengthseconds;
		} else {
			$outrunlengthseconds = runlengthseconds;
		}
		$outstring = $outrunlengthhours+':'+$outrunlengthminutes+':'+$outrunlengthseconds;

		document.forms['filmcalculator'].runlength.value = $outstring;
	}

//-->