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()
{

 var text="Han ocurrido los siguientes errores: ";
 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+="\n   * Escribir su nombre."; 
 }
 
 

if (su_email.length==0){
	   bien=false;
	   text+="\n   * Escribir su e-mail.";
	 }else{
		 if (!validarEmail_fotos(su_email)){
				bien=false;
				text+="\n   * Formato de su e-mail es incorrecto.";
			 }
	 } 
 
 
 
  if (email_destino.length==0){
	   bien=false;
	   text+="\n   * Escribir e-mail destino.";
	 }else{
		 if (!validarEmail_fotos(email_destino)){
				bien=false;
				text+="\n   * Formato de e-mail destino es incorrecto.";
			 }
	 }


 if (comentario.length==0){
	     bien=false;
		 text+="\n   * Escribir comentario."; 
 }

 
 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);
	  	}
	 }