//FUNCIONS PER VERIFICAR
function MyTrim(camp,upper) {
  var valor = camp.value;
	while (''+valor.charAt(0)==' ') valor=valor.substring(1,valor.length);
  while (''+valor.charAt(valor.length)==' ') valor=valor.substring(0,valor.length-1);
	if (upper) valor=valor.toUpperCase();
  camp.value = valor;
}

function verificarText(formulari,obj) {
 var valor=eval("document.forms['"+formulari+"']."+obj);
 MyTrim(valor,false);
 if(valor.value == '') return false;
 else return true;
}

function checkemail(id){
 str = document.getElementById(id).value;
 var filter=/^.+@.+\..{2,4}$/
 if (filter.test(str))  return true
 else return false
}

function showError(id) {
	document.getElementById(id).style.border = '1px solid red';
	document.getElementById(id+'Error').style.display = 'block';
}

function hiddenError(id) {
	document.getElementById(id).style.border  = '1px solid #000';
	document.getElementById(id+'Error').style.display = 'none';
}

function send(v) {
	var error = false;
	if (!verificarText('frmForm','name')) {
		showError('name');
		error = true;	
	} else 	hiddenError('name');
	
	if (v == 1) {
		if (!verificarText('frmForm','password')) {
		showError('password');
		error = true;
		} else hiddenError('password');
	}

	if (!verificarText('frmForm','mail') || !checkemail('mail')) {
		showError('mail');
		error = true;
	} else hiddenError('mail');
	
 for(i=0;i<document.frmForm.human.length;i++) {
        if(document.frmForm.human[i].checked) {
					if (document.frmForm.human[i].value == 'no') {
						showError('lblHuman');
						error = true;
					}
					if (document.frmForm.human[i].value == 'si') {
						hiddenError('lblHuman')
					}
					
				}
	}

	return error;
	//if (!error) document.forms.frmForm.submit();
	
}
function limita(elEvento, maximoCaracteres,campo) {
  var elemento = document.getElementById(campo);

  // Obtener la tecla pulsada 
  var evento = elEvento || window.event;
  var codigoCaracter = evento.charCode || evento.keyCode;
  // Permitir utilizar las teclas con flecha horizontal
  if(codigoCaracter == 37 || codigoCaracter == 39) {
    return true;
  }

  // Permitir borrar con la tecla Backspace y con la tecla Supr.
  if(codigoCaracter == 8 || codigoCaracter == 46) {
    return true;
  }
  else if(elemento.value.length >= maximoCaracteres ) {
    return false;
  }
  else {
    return true;
  }
}
