﻿// JavaScript Document

//Muestra u oculta una capa
function MostrarOcultar(id) {
	if(document.getElementById(id).className != "oculta"){
		document.getElementById(id).className = "oculta";
	} else {
		document.getElementById(id).className = "muestra";
	}
}

function mostrarCapa(nombreCapa){
	document.getElementById(nombreCapa).style.display = "block";
}
function ocultarCapa(nombreCapa){
	document.getElementById(nombreCapa).style.display = "none";
} 

//función genérica que crea un nuevo objeto ajax | elajax=nuevoAjax();
function nuevoAjax(){
	var xmlhttp=false;
 	try {
 		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 	} catch (e) {
 		try {
 			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
 		} catch (E) {
 			xmlhttp = false;
 		}
  	}

	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
 		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}

//manejo de texto
function limpiaEspacios(eltexto){
	// Quito los espacion antes y después
	while(eltexto.charAt(eltexto.length-1)==" ") eltexto = eltexto.substr(0, eltexto.length-1);
	while(eltexto.charAt(0)==" ") eltexto = eltexto.substr(1, eltexto.length-1);
	return eltexto;
}

//para los formularios
////validación
function validaCorreo(valor){
	var caract=/(^[a-zA-Z0-9._-]{1,30})@([a-zA-Z0-9.-]{1,30}$)/;
	if(caract.test(valor)) return true;
	else return false;
}
function validaLargoText(eltexto, txmin, txmax){
	var valido = false;
	if(txmax != null){
		if(eltexto.length > txmin & eltexto.length < txmax){
			valido = true;
		}
	}else{
		if(eltexto.length > txmin){
			valido = true;
		}
	}
	return valido;
}
////mensajes
var veces=0;
function sacaMensajeForm(elmensaje){
	document.getElementById("mensajeForm").innerHTML = elmensaje;
	document.getElementById("mensajeForm").style.display = "block";
}
function quitaMensajeForm(){
	document.getElementById("mensajeForm").style.display = "none";
}
