// JavaScript Document
var errores="";
/*EL CONTADOR DEBE TENER EL ID contador_idtexto*/
function LimitarCaracteres(texto, maxlong) {
	var tecla, in_value, out_value;
	var idcontador= "contador_" + texto;
	try{
		
	  texto= document.getElementById(texto);
	  
	  if (texto.value.length > maxlong) {
		  in_value = texto.value;
		  out_value = in_value.substring(0, maxlong);
		  texto.value = out_value;
		  
		  document.getElementById(idcontador).innerHTML="No quedan caracteres.";
		  return false;
	  }
	  else
	  {
		  document.getElementById(idcontador).innerHTML="Quedan " + (maxlong - texto.value.length) + " caracteres";
		  return true;
	  }	
	}
	catch(ex){;};
	
}




/*
Funcion para cambiar de color a un campo, el campo es el nombre y la imagen indica si tiene asociada una imagen
El nombre del campo imagen debe ser: img_nombrecampo
*/
function Cambiar_Color (campo, imagen){
	try {
		
		elemento= document.getElementById(campo);
		
		if (elemento != null){
			if (elemento.value!="" && elemento.value != null) {
				Cambiar_Color_Campo_Negro(campo, imagen);
				return true;
				
			}
			else {
				Cambiar_Color_Campo_Rojo(campo, imagen);
				return false;
			}
		}
		
	}
	catch (error){ return false;}
};

function Cambiar_Color_Campo_Rojo (campo, imagen){
	try
	{
		if (campo != null && imagen!=null){
			var elemento = document.getElementById(campo);
		
			elemento.style.backgroundColor= "#ffCCCC";
			
			if (imagen) {
				var nom_im = "img_" + campo;
				document.getElementById(nom_im).src= "imgs/error.png";
			}
			
		
		
			return true;
		}
	
	
		return false;
	}
	catch (error){ ;}
	
};

function Cambiar_Color_Campo_Negro (campo, imagen){
	
	try
	{
		if (campo != null && imagen!=null){
			var elemento = document.getElementById(campo);
		
			elemento.style.backgroundColor= "#ffffff";
			
			if (imagen) {
				var nom_im = "img_" + campo;
				document.getElementById(nom_im).src= "imgs/correcto.png";
			}
			
		
		
			return true;
		};
	
	
		return false;
	}
	catch (error){ ;}
	
};

function Comprobar_Nombre(){
	if(document.getElementById("txt_nombre").value!=""){
		Cambiar_Color_Campo_Negro("txt_nombre", false);
		return true;
	}
	errores +="El campo nombre es requerido.\r\n";
	Cambiar_Color_Campo_Rojo("txt_nombre", false);
	document.getElementById("txt_nombre").focus();
	return false;
}

function Comprobar_Mail(){
	if(document.getElementById("txt_mail").value!=""){
		Cambiar_Color_Campo_Negro("txt_mail", false);
		return true;
	}
	Cambiar_Color_Campo_Rojo("txt_mail", false);
	errores +="El campo mail es requerido.\r\n";
	document.getElementById("txt_mail").focus();
	return false;
}

function Comprobar_Testimonio(){
	if(document.getElementById("txt_testimonio").value!=""){
		Cambiar_Color_Campo_Negro("txt_testimonio", false);
		return true;
	}
	Cambiar_Color_Campo_Rojo("txt_testimonio", false);
	errores +="Debes escribir un testimonio que enviar.\r\n";
	document.getElementById("txt_testimonio").focus();
	return false;
}

function Enviar_Formulario(){
	errores="";
	Comprobar_Testimonio();
	Comprobar_Mail();
	Comprobar_Nombre();
	
	
	
	if(errores==""){
		document.getElementById("frm_testimonio").submit();
	}
	else {
		alert(errores);
	}
}