/*
 * Resource : /javascript/cleanForm.js
 */

function pk_fixnewlines_textarea (val) {             
  // Adjust newlines so can do correct character counting for MySQL. MySQL counts a newline as 2 characters.
  if (val.indexOf('\r\n')!=-1)
    ; // this is IE on windows. Puts both characters for a newline, just what MySQL does. No need to alter
  else if (val.indexOf('\r')!=-1)
  {
    val = val.replace ( /\r/g, "\r\n" );        // this is IE on a Mac. Need to add the line feed
  }
  else if (val.indexOf('\n')!=-1)
  {
    val = val.replace ( /\n/g, "\r\n" );        // this is Firefox on any platform. Need to add carriage return
  }
  else 
    ;                                           // no newlines in the textarea  
  return val;
  }
  
function text_limit_new(len, language )
{
	//on doit stocker le contenu dans une variable pour un decompte correct par javascript
	var textarea = document.getElementById('message');
	var texteareaValue = textarea.value;
	var nbcar = document.getElementById('nbcar');
	var max = 0;
	if (len == 0 || len == null) {
		max = 500;
	} else {
		max = len;
	}
	
	//on ajoute une methode qui remplace les sauts de ligne pour obtenir un fonctionnement
	//correct du decompte des caracteres sur les differents navigateurs
	//comportement souhaité: 2 caracteres comptés par saut de ligne (idem comportement de la base)
	texteareaValue = pk_fixnewlines_textarea(texteareaValue);
	
	
	if (texteareaValue.length > max)
	{
		texteareaValue = texteareaValue.substring(0, max);
		textarea.value = texteareaValue;
	}		
	//taille.value =  max-textearea.value.length;
	var translate = new Array("" + formatInteger( language, max-texteareaValue.length ) + "");
	nbcar.innerHTML = replaceAllVar(translate, lang["testimonials.info.char"]);
}


