// $Id: tekster.js,v 1.14 2006/10/16 12:47:10 xjtm0101 Exp $
    /* 
     *  Trimmer en given streng for white spaces of new line foran og bagved.
     */
    function trim(obj) {
    	var resultStr = "";
      	var str = obj.value;
      
      	if (str == null || str.length == 0) {
        	obj.value = "";
      	} else {
	  		var begin = 0;
		
       		for (var i = begin; i < str.length; i++) {
				if (str.charAt(i) == ' ') {
					begin++;
					continue;
				}
			
				if (str.charCodeAt(i) != '13' && str.charCodeAt(i+1) != '10'  && str.charAt(i) != ' ') {
					break;
				}

        		if (str.charCodeAt(i) == '13' && str.charCodeAt(i+1) == '10') {
            		begin+=2;
            		i++;
            	}
        	}   
             
	  		var end = str.length-1;
        
			for (var j = end; j >= 0; j--) {
				if (str.charAt(j) == ' ') {
					end--;
					continue;
				}	
			
				if (str.charCodeAt(j) != '10' && str.charCodeAt(j-1) != '13' && str.charAt(j) != ' ') {
					break;
				}
			
				if (str.charCodeAt(j) == '10' && str.charCodeAt(j-1) == '13') {
            		end-=2;   
            		j--;   
	            } 
    	    }
			resultStr = str.substring(begin, end+1);
	    }
        obj.value = resultStr; 
    }

