function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else 
countfield.value = maxlimit - field.value.length;
}

function limita(maximoCaracteres,texto,inpunt) {
  var elemento = texto;
   if( elemento.length>= maximoCaracteres ) {
    return false;
  }
  else {
    document.getElementById(inpunt).value=texto;
	return true;
  }
}


function reiniciar_formulario()
{
 document.getElementById("email_bien").style.visibility="hidden";
 
}
 
function escribir(texto,inpunt)
{
  document.getElementById(inpunt).value=texto;
}

function comprobar_formulario(idioma)
{
	//alert (idioma);
switch (idioma) { 	
 case "es": 
 var text="Han ocurrido los siguientes errores: ";
 var nombre="\n   * Escribir su nombre.";
 var mail="\n   * Escribir su e-mail.";
 var mailerror="\n   * Formato de su e-mail es incorrecto.";
 var destino="\n   * Escribir e-mail destino.";
 var destinoerror="\n   * Formato de e-mail destino es incorrecto.";
 var comentariotxt="\n   * Escribir comentario."; 
 break 
 
 case "en": 
 var text="The following errors have occurred: "
 var nombre="\n   * Enter your name.";
 var mail="\n   * Enter your e-mail address.";
 var mailerror="\n   * Your e-mail address is wrong.";
 var destino="\n   * Enter the addressee’s e-mail.";
 var destinoerror="\n   * Your e-mail destination is wrong.";
 var comentariotxt="\n   * Write a comment."; 
 break 
 
 case "fr": 
 var text="Les erreurs suivantes se sont produites: "
 var nombre="\n   * Saisir votre nom.";
 var mail="\n   * Saisir votre e-mail.";
 var mailerror="\n   * Format d’e-mail est incorrect.";
 var destino="\n   * Saisir e-mail de destination.";
 var destinoerror="\n   * Format destination d'e-mail est incorrect.";
 var comentariotxt="\n   * Ecrire un commentaire."; 
 break 
 
 case "de": 
 var text="Folgende Fehler sind aufgetreten: "
 var nombre="\n   * Eingabe Ihres Namens.";
 var mail="\n   * Eingabe Ihrer E-Mail-Adresse.";
 var mailerror="\n   * Die Email-Adresse ist nicht korrekt.";
 var destino="\n   * Eingabe der E-Mail-Adresse des Empfängers.";
 var destinoerror="\n   * Die Email-Adresse des Empfängers ist nicht korrekt.";
 var comentariotxt="\n   * Schreiben Sie einen Kommentar."; 
 break 
}
 var bien=true;
 var formulario=window.document.frm_enviar_foto;
 
 var su_nombre=document.getElementById("su_nombre").value;
 

 var su_email=document.getElementById("su_email").value;
 var email_destino=document.getElementById("email_destino").value;
 var comentario=document.getElementById("comentario").value;
 /*
 var imagen_mandar_grande=document.getElementById("imagen_mandar_grande").value;
 var imagen_mandar_mediana=document.getElementById("imagen_mandar_mediana").value;
 var url_email_fotos=document.getElementById("url_email_fotos").value;
*/

 if (su_nombre.length==0){
	     bien=false;
		 text+=nombre; 
 }
 
 

if (su_email.length==0){
	   bien=false;
	   text+=mail;
	 }else{
		 if (!validarEmail_fotos(su_email)){
				bien=false;
				text+=mailerror;
			 }
	 } 
 
 
 
  if (email_destino.length==0){
	   bien=false;
	   text+=destino;
	 }else{
		 if (!validarEmail_fotos(email_destino)){
				bien=false;
				text+=destinoerror;
			 }
	 }


 if (comentario.length==0){
	 	alert("error");
	     bien=false;
		 text+=comentariotxt; 
 }

 
 if (bien==true){
	 // Poner datos en el formulario verdadero que se manda
	 /*
	  document.getElementById("su_nombre").value=su_nombre;
      document.getElementById("su_email").value=su_email;
      document.getElementById("email_destino").value=email_destino;
      document.getElementById("comentario").value=comentario;
	  
      document.getElementById("imagen_mandar_grande").value=imagen_mandar_grande;
      document.getElementById("imagen_mandar_mediana").value=imagen_mandar_mediana;
      document.getElementById("url_email_fotos").value=url_email_fotos;
  */
    xajax_enviar_foto_por_email(xajax.getFormValues('frm_enviar_foto'));
	//document.getElementById("email_bien").style.visibility="visible";
	alert("La imagen ha sido enviada correctamente al correo indicado"); 
	hs.close();	
 }  else{
   alert(text);
  }
}



function validarEmail_fotos(valor)
	{
		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor))
		{
			return (true)
		} 
		else 
		{
	    	return (false);
	  	}
	 }