//---------------------------------------------------------------------------
//	<input
//		name="preis" 
//		value="" 
//		onblur="input_number_format(this,2,'.',',','','$')"
//		onchange="input_number_format(this,2,'.',',','','$')"
//	>
//---------------------------------------------------------------------------

	function findObj(n,d){
  		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=findObj(n,d.layers[i].document);
  		return x;
	}

	function input_numeric(objname) {
		obj = findObj(objname);
		whichASC = (document.layer) ? e.which : event.keyCode;
		whichKey = String.fromCharCode(whichASC).toLowerCase();
		if (whichASC!=13) {
			if (whichKey==',') whichKey='.';
			if ( ((whichKey<'0') || (whichKey>'9')) && (whichKey!='.') ) {
				tmp = obj.value;
				setTimeout("obj.value = tmp",0);
			} else {
				if (whichKey=='.') {
					tmp = obj.value;
					if ( (tmp.indexOf(".")<0) && (tmp.indexOf(",")<0) ){
						if (tmp.length==0) {
							tmp = '0.';
							setTimeout("obj.value = tmp",0);
						}
					} else
						setTimeout("obj.value = tmp",0);
	}	}	}	}

	function input_numeric_clean(objname) {
		obj = findObj(objname);
		res = '';
		pt = 0;
		if (obj.value.indexOf(".")==0)
			obj.value = "0"+obj.value;
		for(i=0;i<obj.value.length;i++) {
			tmp = obj.value.substr(i,1);
			if ( ((tmp>='0') && (tmp<='9')) || (tmp=='.') || (tmp==',') ) {
				if ( (tmp=='.') || (tmp==',') ){
					if (pt!=1)
						res += '.';
					pt = 1;
				} else {
					res += tmp;
		}	}	}
		obj.value = res;
	}



	//
	// use onblur and onchange in combination is safe
	//
	function input_number_format(obj_or_name,dec,pnt,sep,pre,suf) {
		obj = (typeof(obj_or_name) == 'object') ? obj_or_name : findObj(obj_or_name);
		obj.value = number_format(obj.value,dec,pnt,sep,pre,suf,false);
	}

	//
	//	format a number
	//
	function number_format(sValue, iDecimals, sPoint, sSeperator, sPrefix, sSuffix, bRawinput) {
	    //
		if (iDecimals==null || iDecimals=='null' || iDecimals=='') iDecimals = -1;
		else iDecimals *= 1;

	    if (sPoint==null) sPoint='.';
	    if (sSeperator==null) sSeperator='';
		if (sPrefix==null) sPrefix='';
		if (sSuffix==null) sSuffix='';
		//
	 	if (bRawinput==null || bRawinput==false || bRawinput==0 || bRawinput=='') {
	    	//
	    	sValue = sValue.replace(sPrefix,'');
	    	sValue = sValue.replace(sSuffix,'');
	    	//
	    	if (sSeperator!='')
	    		while(sValue.indexOf(sSeperator)>-1)
	    			sValue = sValue.replace(sSeperator,'');
	    	//
	    	sValue = sValue.replace(sPoint,'.');
		}
		//
		if (isNaN(sValue))
		    sValue = '0';
	    var z = 0;    
	    for(i=0;i<iDecimals;i++)
	        z = (z<1) ? (10) : (z * 10);    
	    if (iDecimals>=0)
	        sValue = '' + ((iDecimals==0) ? (Math.round(sValue)) : ((Math.round(sValue*z))/z));
		if (iDecimals>0) {
			if (sValue.indexOf('.')==-1) sValue += '.';					
			while (sValue.indexOf('.')+iDecimals>=sValue.length) sValue += '0';
	 	}
	 	if (iDecimals<0) {
	 		var x = sValue;
	 		x = x * 1;
	 		sValue = '' + x;
	 		if (sValue.indexOf('.')==0) sValue = '0' + sValue;	 	
	 		if (sValue.indexOf('.')==sValue.length-1) sValue = sValue.substr(0,sValue.length-1);
		}
		
		//
		sValue = sValue.replace('.',sPoint);
		
		//
		var vz = ((sValue.substr(0,1)=='-') || (sValue.substr(0,1)=='+')) ? 1 : 0;
		var res = '';
		var pt = sValue.indexOf(sPoint);
		var tp = 0;
		if (pt>-1) {
			for(i=0;i<=sValue.length;i++) {
				if (((pt-i)%3 == 0) && (i<pt) && (i>0+vz))
					res += sSeperator;
				res += sValue.substr(i,1);
			}
			sValue = res;
		} else {
			for(i=0;i<=sValue.length;i++) {
				if (((sValue.length-i)%3 == 0) && (i<sValue.length) && (i>0+vz))
					res += sSeperator;
				res += sValue.substr(i,1);
			}
			sValue = res;			
		}

    	//
    	sValue = (sPrefix.length>0 ? sPrefix + ' ' : '') 
    	       + sValue 
    	       + (sSuffix.length>0 ? ' ' + sSuffix : '');

	 	//
	 	return sValue;
	}

