/* Funciones Genéricas para los tratamientos de formularios.
/* Todas las funciones tienen en cuenta que para las validaciones existe un elemento que admite código
/* HTML dentro y cuyo id es el nombre del campo a validar más '_msg'
*/

function limpiarCampo(campo){
	var c = document.getElementById(campo);
	c.value='';
}	

function validarCampo(IdCampo){
	var campo = document.getElementById(IdCampo);
	var msg = document.getElementById(IdCampo+'_msg');
	msg.innerHTML="";
	if (campo.value == '' || campo.value.length <= 0){
		msg.innerHTML=" Campo obligatorio";
		return false;
	}
	return true;
}

function validarPassword(pass,confirmacion){
	var campoPass = document.getElementById(pass);
	var campoConf = document.getElementById(confirmacion);
	var msg = document.getElementById(confirmacion+'_msg');
	msg.innerHTML="";
	if (campoPass.value != campoConf.value){
		msg.innerHTML="La contraseña y la validación no coinciden";
		return false;
	}
	return true;
}

function numbersonly(myfield, e, allowPoint)
{
var key;
var keychar;
var numbStr = "0123456789";
if (allowPoint)
	numbStr+='.';

if (window.event)
   key = window.event.keyCode;
else if (e)
   key = e.which;
else
   return true;
keychar = String.fromCharCode(key);

// control keys
if ((key==null) || (key==0) || (key==8) || 
    (key==9) || (key==13) || (key==27) )
   return true;

// numbers
else if (((numbStr).indexOf(keychar) > -1))
   return true;
return false;
}

function cambiarImagenAjaxCargando(idImagen){
	document.getElementById(idImagen).setAttribute("src","./images/ajax_cargando.gif");
}

function validarContacto(form){
		nombre=form.nombre;
		email=form.email;
		consulta=form.consulta;
		if (nombre.value=='') nombre.value='Campo Obligatorio';
		if (email.value=='') email.value='Campo Obligatorio';
		if (consulta.value=='') consulta.value='Campo Obligatorio';
		if (nombre.value=='Campo Obligatorio' ||
		    email.value=='Campo Obligatorio' ||
		    consulta.value=='Campo Obligatorio'){
		    return false;
		}else{
			form.submit();
		}
	
}