// JavaScript Document
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); };

var supportsKeys = false

function calcCharLeft(f,campo,qtd) {
			
		lenUSig = f.lenSSig.value

		maxLength = qtd - f.lenSysSig.value - lenUSig

        if (campo.value.length > maxLength) {

	        campo.value = campo.value.substring(0,maxLength)

		    charleft = 0

        } else {

			charleft = maxLength - campo.value.length

		}
		
        

}



function textKey(f,campo,qtd) {

	supportsKeys = true	

	calcCharLeft(f,campo,qtd)

}

function BreakUpLine(line, size)
{  
  line = line.trim();
  var words = line.split(" ");
  var disp = "";
  var cola="";
  var ofst1 = 0;
  var ofst2 = size;
  var divisao;  
  if ((words.length) <= 1){
	if (line.length>size){
	  divisao = parseInt(line.length)/size;
	  
	  for (i=0;i<(divisao);i++){
  	    disp = line.substr(ofst1,ofst2) + " ";
		cola +=disp;
  	    ofst1  = ofst1 + size;  
	  }
      return cola;
    }else{
	  return line;
	}
  }else{
	for(i=0; i<words.length; i++){
	  ofst1 = 0;	  
	  if (words[i].length>size){
	    divisao = parseInt(words[i].length)/size;
	  
	    for (j=0;j<(divisao);j++){
  	      disp = words[i].substr(ofst1,ofst2) + " ";
		  cola +=disp;
  	      ofst1  = ofst1 + size;  
	    }        
      }else{
	    cola += words[i] + " ";	
	  }
	}
	return cola.trim();	
  }
}
