// JavaScript Document
function pintarCelda(cual, color){	
	document.getElementById(cual).style.backgroundColor=color;
}
function descargarArchivo(archivo, carpeta){
	document.location.href= 'paginas/descargar.php?carpeta='+carpeta+'&archivo='+archivo;
}
function modificarNoticia(idNoticia){
	peticion('form/form.gestionNoticia.php', 'formNoticia', 'POST', 'idNoticia='+idNoticia);	
}
function verNoticia(idNoticia){
	peticion('paginas/detalleNoticia.php', 'contenido', 'POST', 'idNoticia='+idNoticia);	
}
function llamarNoticias(){
	peticion('paginas/noticiasDestacadas.php', 'noticias', 'POST', '');		
}
function validarNoticia(){
	if(document.gestionNoticia.TituloNoticia.value==""){
		alert("Debe ingresar el t\xEDtulo de la noticia.")
		document.gestionNoticia.TituloNoticia.focus();
		return;
	}
	document.gestionNoticia.submit();
}
function llamarEventos(cual){
	//o son futuros y 1 son pasados
	peticion('paginas/listadoEventos.php', 'content', 'POST', 'TipoEvento='+cual);
	pageTracker._trackPageview('/paginas/eventos.php');

}
function llamarInvitadosTemas(idEvento){
	mostrarDiv('divCargaDatos');
	peticion('paginas/detalleInvitadosTemas.php', 'divCargaDatos', 'POST', 'IDEvento='+idEvento);
}
function checkVacio(id, texto){
	if(document.getElementById(id).value==''){
		document.getElementById(id).value=texto;	
	}
}
function vaciarCampo(campo, texto){
	if(document.getElementById(campo).value==texto){
		document.getElementById(campo).value='';	
	}
}
function validarEvento(){
	if(document.formGestion.titulo.value == "" || document.formGestion.titulo.value == "Escriba el título del evento" || document.formGestion.titulo.value == "Escriba el t&iacute;tulo del evento"){
		alert("Debe ingresar el t\xEDtulo del evento.");
		return;
	}
	mostrarDiv('bgEnabled');
	/*
	if(document.formGestion.lugarEvento.value == ""){
		alert("Debe ingresar el lugar del evento.");
		return;
	}*/
	document.formGestion.submit();
}
function validarWeb(){
	if(document.formGestion.webEvento.value == ""){
		alert("Debe ingresar la direcci\xF3n web del sitio.");
		return;
	}
	document.formGestion.submit();
}
function validarImagen(){
	if(document.formGestion.titulo==""){
		alert("Debe ingresar el t\xEDtulo del congreso.");
		return;
	}
	if(document.formGestion.imagenEvento.value == ""){
		alert("Debe elegir un archivo");
		return;
	}
	document.formGestion.submit();
}
function validarProgFinal(){
	if(document.formGestion.titulo==""){
		alert("Debe ingresar el t\xEDtulo del congreso.");
		return;
	}
	if(document.formGestion.progFinalEvento.value == "" && document.formGestion.progFinalOnlineEvento.value == ""){
		alert("Debe elegir un archivo o ingresar una direcci\xF3n web del formulario.");
		return;
	}
	document.formGestion.submit();
}
function validarProgPreliminar(){
	if(document.formGestion.titulo==""){
		alert("Debe ingresar el t\xEDtulo del congreso.");
		return;
	}
	if(document.formGestion.progPreliminarEvento.value == ""){
		alert("Debe elegir un archivo.");
		return;
	}
	document.formGestion.submit();
}
function validarLugar(){
	if(document.formGestion.lugarEvento==""){
		alert("Debe ingresar el lugar del congreso.");
		return;
	}
	document.formGestion.submit();
}
function validarInscripcion(){
	if(document.formGestion.titulo==""){
		alert("Debe ingresar el t\xEDtulo del congreso.");
		return;
	}
	if(document.formGestion.inscripcionEvento.value == "" && document.formGestion.inscripcionOnlineEvento.value == ""){
		alert("Debe elegir un archivo o ingresar una direcci\xF3n web del formulario.");
		return;
	}
	document.formGestion.submit();
}
function validarHotel(){
	if(document.formGestion.titulo==""){
		alert("Debe ingresar el t\xEDtulo del congreso.");
		return;
	}
	if(document.formGestion.hotelEvento.value == "" && document.formGestion.hotelOnlineEvento.value == ""){
		alert("Debe elegir un archivo o ingresar una direcci\xF3n web del formulario.");
		return;
	}
	document.formGestion.submit();
}
function validarEmail(){
	var email = document.formGestion.emailEvento;
	if (!emailCheck(email.value)){		
		email.focus();
		return;
	}
	document.formGestion.submit();
}
function validarFecha(){
	document.formGestion.submit();
}
function llamarForm(quePag){
	mostrarDiv('auxiliarEvento')
	peticion('form/form.'+quePag+'.php', 'auxiliarEvento', 'POST', '');	
}
function llamarForm(quePag){
	peticion('form/form.gestion'+quePag+'.php', 'formNoticia', 'POST', '');	
}
function cerrarVentanaFondo(){
	ocultarDiv('divCargaDatos');
	ocultarDiv('contentCargaDatos');
}
function modificarEvento(idEvento){
	mostrarDiv('divCargaDatos');
	peticion('paginas/eventosAgregar.php', 'divCargaDatos', 'POST', 'IDEvento='+idEvento);
}
function eliminarEvento(idEvento){
	if(confirm('\xBFSeguro que desea eliminar el evento?')){		
		peticion("accion/iframe.gestionEvento.php", "FrameForm", "POST", "idEvento="+idEvento+"&Modalidad=eliminar");		
		alert("Se ha eliminado el evento con exito")
		parent.llamarPag2('listadoEventos')
	}
}
function agregarAltura(myfield,e){
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;
	if (keycode == 13){
		document.getElementById('titulo').style.height = (document.getElementById('titulo').clientHeight + 10) +"px";
		document.getElementById('titulo').innerHTML = document.getElementById('titulo').value + "\r\n";
	return false;
	}else
	return true;
}
function llenarListadoEventos(cualAno, tipoEvento){
	peticion('inc/inc.eventoListado.php', 'listadoEventos', 'POST', 'Ano='+cualAno+'&TipoEvento='+tipoEvento);
}
function desactivarUsuario(){
	peticion('inc/inc.menu.php', 'menuEdicion', 'POST', 'Desactivar=1');
	peticion('paginas/listadoEventos.php', 'content', 'POST', '');
	cerrarVentanaFondo()
}
function activarLoguin(nombre){
	/*document.location.href="../principal.php?cualPagina=listadoEventos&cualMenu=eventos";*/
	document.location.href="../administrar.php";
	modificarEvento(0)
/*	peticion('paginas/listadoEventos.php', 'content', 'POST', '');
	peticion('menu/eventosSubMenu.php', 'subMenuDeco', 'POST', '');*/
}
function submitenter(myfield,e){
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;
	if (keycode == 13){
		validarUsuario();
	return false;
	}else
	return true;
}
function validarUsuario(){
	if(document.formUsuario.Loguin.value==""){
		alert("Ingrese su nombre de usuario.")
		document.formUsuario.Loguin.focus();
		return;
	}
	if(document.formUsuario.Password.value==""){
		alert("Ingrese su password.")
		document.formUsuario.Password.focus();
		return;
	}
	document.formUsuario.submit();	
}
function validarEnvioContacto(){
	var nombre = document.formContactoA.nombreContacto.value;
	var mail = document.formContactoA.mailContacto.value;
	var telefono = document.formContactoA.telefonoContacto.value;
	var consulta = document.formContactoA.consultaContacto.value;
	
	if((mail=="")&&(telefono=="")){
		alert("Debe ingresar su telifono o su e-mail para poder comunicarnos con ud. Gracias");
		document.formContactoA.mailContacto.focus();					
		return;
	}
	if(mail!=""){
		if (!emailCheck(mail)){		
			document.formContactoA.mailContacto.focus();
			return;
		}
	}
	if(consulta==""){
		alert("Debe ingresar su consulta para poder continuar. Gracias");
		document.formContactoA.consultaContacto.focus();
		return;
	}
	peticion('paginas/contactoEnviar.php', 'content', 'POST', 'nombreContacto='+nombre+'&mailContacto='+mail+'&telefonoContacto='+telefono+'&consultaContacto='+consulta);	
	//document.formContactoA.submit();	
}
function mostrarDiv(cual){
	document.getElementById(cual).style.display = "block";
	return
}
function ocultarDiv(cual){
	document.getElementById(cual).style.display = "none";
	return
}


function ucFirst(string){
 return string.substr(0,1).toUpperCase()+string.substr(1,string.length).toLowerCase();
}

function llamarEventos(cual){
	//o son futuros y 1 son pasados
	peticion('paginas/listadoEventos.php', 'content', 'POST', 'TipoEvento='+cual);
}
function checkVacio(id, texto){
	if(document.getElementById(id).value==''){
		document.getElementById(id).value=texto;	
	}
}
function vaciarCampo(campo, texto){
	if(document.getElementById(campo).value==texto){
		document.getElementById(campo).value='';	
	}
}
function validarEvento(){
	if(document.formGestion.titulo.value == "" || document.formGestion.titulo.value == "Escriba el título del evento" || document.formGestion.titulo.value == "Escriba el t&iacute;tulo del evento"){
		alert("Debe ingresar el t\xEDtulo del evento.");
		return;
	}/*
	if(document.formGestion.lugarEvento.value == ""){
		alert("Debe ingresar el lugar del evento.");
		return;
	}*/
	document.formGestion.submit();
}
function validarWeb(){
	if(document.formGestion.webEvento.value == ""){
		alert("Debe ingresar la direcci\xF3n web del sitio.");
		return;
	}
	document.formGestion.submit();
}
function validarImagen(){
	if(document.formGestion.titulo==""){
		alert("Debe ingresar el t\xEDtulo del congreso.");
		return;
	}
	if(document.formGestion.imagenEvento.value == ""){
		alert("Debe elegir un archivo");
		return;
	}
	document.formGestion.submit();
}
function validarProgFinal(){
	if(document.formGestion.titulo==""){
		alert("Debe ingresar el t\xEDtulo del congreso.");
		return;
	}
	if(document.formGestion.progFinalEvento.value == "" && document.formGestion.progFinalOnlineEvento.value == ""){
		alert("Debe elegir un archivo o ingresar una direcci\xF3n web del formulario.");
		return;
	}
	document.formGestion.submit();
}
function validarProgPreliminar(){
	if(document.formGestion.titulo==""){
		alert("Debe ingresar el t\xEDtulo del congreso.");
		return;
	}
	if(document.formGestion.progPreliminarEvento.value == ""){
		alert("Debe elegir un archivo.");
		return;
	}
	document.formGestion.submit();
}
function validarLugar(){
	if(document.formGestion.lugarEvento==""){
		alert("Debe ingresar el lugar del congreso.");
		return;
	}
	document.formGestion.submit();
}
function validarInscripcion(){
	if(document.formGestion.titulo==""){
		alert("Debe ingresar el t\xEDtulo del congreso.");
		return;
	}
	if(document.formGestion.inscripcionEvento.value == "" && document.formGestion.inscripcionOnlineEvento.value == ""){
		alert("Debe elegir un archivo o ingresar una direcci\xF3n web del formulario.");
		return;
	}
	document.formGestion.submit();
}
function validarHotel(){
	if(document.formGestion.titulo==""){
		alert("Debe ingresar el t\xEDtulo del congreso.");
		return;
	}
	if(document.formGestion.hotelEvento.value == "" && document.formGestion.hotelOnlineEvento.value == ""){
		alert("Debe elegir un archivo o ingresar una direcci\xF3n web del formulario.");
		return;
	}
	document.formGestion.submit();
}
function validarEmail(){
	var email = document.formGestion.emailEvento;
	if (!emailCheck(email.value)){		
		email.focus();
		return;
	}
	document.formGestion.submit();
}
function validarFecha(){
	document.formGestion.submit();
}
function llamarForm(quePag){
	mostrarDiv('auxiliarEvento')
	peticion('form/form.'+quePag+'.php', 'auxiliarEvento', 'POST', '');	
}
function llamarPag2(quePag) {
	//$('#content').load('paginas/'+quePag+'.php');
	peticion('paginas/'+quePag+'.php', 'content', 'POST', '');	
		pageTracker._trackPageview('/paginas/'+quePag+'.php');

}


function validarEnvioContactoArchivo(){
	var nombre = document.form2.nombreContacto2.value;
	var mail = document.form2.mailContacto2.value;
	var telefono = document.form2.telefonoContacto2.value;
	var archivo = document.form2.archivoContacto2.value;	
	if(nombre==""){
		alert("Debe ingresar su nombre. Gracias");
		document.form2.nombreContacto2.focus();
		return;
	}
	if((mail=="")&&(telefono=="")){
		alert("Debe ingresar su telefono o su e-mail para poder comunicarnos con ud. Gracias");
		document.form2.mailContacto2.focus();
		return;
	}
	if(mail!=""){
		if (!emailCheck(mail)){		
			document.form2.mailContacto2.focus();
			return;
		}
	}
	if(archivo==""){
		alert("Debe ingresar su curriculum. Gracias");
		document.form2.archivoContacto2.focus();
		return;
	}
	mostrarDiv('bgEnabled');
	document.form2.submit();	
}

///***FUNCION PARA VALIDAR MAIL***///
function emailCheck (emailStr) {
/* The following pattern is used to check if the entered e-mail address
fits the user@domain format.  It also is used to separate the username
from the domain. */
var emailPat=/^(.+)@(.+)$/
/* The following string represents the pattern for matching all special
characters.  We don't want to allow special characters in the address. 
These characters include ( ) < > @ , ; : \ " . [ ]    */
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
/* The following string represents the range of characters allowed in a 
username or domainname.  It really states which chars aren't allowed. */
var validChars="\[^\\s" + specialChars + "\]"
/* The following pattern applies if the "user" is a quoted string (in
which case, there are no rules about which characters are allowed
and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
is a legal e-mail address. */
var quotedUser="(\"[^\"]*\")"
/* The following pattern applies for domains that are IP addresses,
rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
e-mail address. NOTE: The square brackets are required. */
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
/* The following string represents an atom (basically a series of
non-special characters.) */
var atom=validChars + '+'
/* The following string represents one word in the typical username.
For example, in john.doe@somewhere.com, john and doe are words.
Basically, a word is either an atom or quoted string. */
var word="(" + atom + "|" + quotedUser + ")"
// The following pattern describes the structure of the user
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
/* The following pattern describes the structure of a normal symbolic
domain, as opposed to ipDomainPat, shown above. */
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
/* Finally, let's start trying to figure out if the supplied address is valid. */
/* Begin with the coarse pattern to simply break up user@domain into
 different pieces that are easy to analyze. */
var matchArray=emailStr.match(emailPat)
if (matchArray==null) {
 /* Too many/few @'s or something; basically, this address doesn't
  even fit the general mould of a valid e-mail address. */
    alert("Dirección de mail incorrecta (revise @ y puntos)")
	return false
	}
	var user=matchArray[1]
	var domain=matchArray[2]
// See if "user" is valid 
	if (user.match(userPat)==null) {
// user is not valid
           alert("El dominio no parece ser valido")
        return false
        }
/* if the e-mail address is at an IP address (as opposed to a symbolic
       host name) make sure the IP address is valid. */
       var IPArray=domain.match(ipDomainPat)
       if (IPArray!=null) {
// this is an IP address
       for (var i=1;i<=4;i++) {
          if (IPArray[i]>255) {
            alert("Destination IP address is invalid!")
        return false
    }
}
return true
}
// Domain is symbolic name
    var domainArray=domain.match(domainPat)
if (domainArray==null) {
    	alert("El dominio no parece ser valido")
return false
}
/* domain name seems valid, but now make sure that it ends in a
three-letter word (like com, edu, gov) or a two-letter word,
representing country (uk, nl), and that there's a hostname preceding 
the domain or country. */
/* Now we need to break up the domain to get a count of how many atoms
it consists of. */
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 || 
domArr[domArr.length-1].length>3) {
// the address must end in a two letter or three letter word.
alert("La dirección tiene que terminar en 3 letras del dominio, o 2 letras de pais.")
  return false
}
// Make sure there's a host name preceding the domain.
  if (len<2) {
  var errStr="Falta el nombre del dominio!"
  alert(errStr)
  return false
}
// If we've gotten this far, everything's valid!
return true;
}
//  End -->
///***FIN FUNCION PARA VALIDAR MAIL***///
