// Fecha: 2/Dic/2005
// Diseño: Beto Ayon
// Programacion: Miriam Calderon

function fverifica() {
    remove_XS_whitespace(document.form.name);
    remove_XS_whitespace(document.form.mail);
    //remove_XS_whitespace(document.form.asunto);
    remove_XS_whitespace(document.form.come);
   
    var cad='';
    if (document.form.name.value=='') 
      cad=cad+ "Escribe tu nombre\n";
    if (document.form.mail.value=='') 
      cad=cad+ "Escribe tu correo electronico\n";
	else  
      if(checa_mail(document.form.mail.value)==1)
	   cad=cad + "El e-mail es incorrecto\n";
    //if (document.form.asunto.value=='')
     //cad=cad + "Escribe un asunto para el mensaje \n";
    if (document.form.come.value=='') 
     cad=cad+ "Escribe tu comentario\n";
    if(cad!=''){
       alert('Por favor verifica los siguientes datos:\n\n'+cad);
       return false;
     }
     else
       return true;
}

function checa_mail(email)
{
 if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)==false)
  return 1;
}

function remove_XS_whitespace(item)
{
  var tmp = "";
  var item_length = item.value.length;
  var item_length_minus_1 = item.value.length - 1;
  for (index = 0; index < item_length; index++)
  {
    if (item.value.charAt(index) != ' ')
    {
      tmp += item.value.charAt(index);
    }
    else
    {
      if (tmp.length > 0)
      {
        if (item.value.charAt(index+1) != ' ' && index != item_length_minus_1)
        {
          tmp += item.value.charAt(index);
        }
      }
    }
  }
  item.value = tmp;
}
