// JavaScript Document
function verGaleria(cual){
	document.form1.Sala.value = cual;
	if(document.form1.Sala.value != ""){
		document.form1.submit();
	}else{
		verGaleria(cual);
	}
}
function enviarFormulario(){
	document.formInscripcion.submit();	
}
function cerrarFotos(){
	ocultarDiv('bgEnabled4');
	llamarListado('AlbumEditar');
}
function agregarLineaFoto(posicion){
	var posicionNueva = parseInt(posicion) +1;
	agregarDivContenedor('divFoto', posicionNueva, 'conenedorImagenes');
	peticion('../administracion/inc/inc.lineaFoto.php', 'divFoto'+posicionNueva, 'POST', 'posicionNueva='+posicionNueva);
	document.getElementById('cargaDatosBase').style.height =  parseInt(document.getElementById('cargaDatosBase').style.height) + 25 +"px";
	document.formGestionA.CantidadFotos.value = posicionNueva;
}
function agregarDivContenedor(nombreDiv, posicionNueva, enqueContenedor){
	var div1=document.createElement('div');
	div1.id=nombreDiv+posicionNueva;
	div1.style.fontSize="11px";
	var t = document.getElementById(enqueContenedor);
	t.appendChild(div1);
}
function mostrarInfoFoto(idFoto, numDiv){
	peticion("../administracion/inc/inc.cargarFoto.php", "divFoto"+numDiv, "POST", "IDFoto="+idFoto+"&NumeroFoto="+numDiv);
	document.getElementById('cargaDatosBase').style.height =  parseInt(document.getElementById('cargaDatosBase').style.height) - 10 +"px";
}
function validarAlbum(){
	if(document.formGestionA.Titulo.value==""){
		alert("Ingrese el titulo del album.");
		document.formGestionA.Titulo.focus();
		return;
	}
	if((document.formGestionA.FechaInicio.value=="")||(document.formGestionA.FechaInicio.value=="00/00/0000")){
		alert("Ingrese la fecha de inicio del evento.")
		document.formGestionA.FechaInicio.focus();
		return;
	}
	if((document.formGestionA.FechaFin.value=="")||(document.formGestionA.FechaFin.value=="00/00/0000")){
		alert("Ingrese la fecha de finalizaci\xF3n del evento.");
		document.formGestionA.FechaFin.focus();
		return;
	}
	mostrarDiv('bgEnabled5');
	document.formGestionA.submit();
}
function validarSecretaria(){
	if(document.formGestionS.Nombre.value==""){
		alert("Ingrese el nombre de la secretaria.");
		document.formGestionS.Nombre.focus();
		return;
	}
	document.formGestionS.submit();
}
function gestionSecretaria(){
	mostrarDiv("bgEnabled3");
	peticion("../paginas/secretariaAgregar.php", "bgEnabled3", "post", "IDSecretaria=0");
}
function llamarMenu(){
	peticion("../administracion/inc/inc.menu.php", "contentMenu", "POST", "");		
}
function llamarControles(){
	peticion("../administracion/inc/inc.controles.php", "contenedorFormulario", "POST", "");		
}
function llamarUsuario(){
	peticion("../administracion/inc/inc.usuario.php", "btsRap", "post", "");	
}
function llamarListadoInscriptos(){
	document.listadoInscr.submit();
}	
function eliminarSecretaria(idSecretaria){
	if(confirm('\xBFSeguro que desea eliminar la secretar\xEDa?')){		
		peticion("../accion/iframe.gestionSecretaria.php", "FrameForm", "POST", "IDSecretaria="+idSecretaria+"&Modalidad=eliminar");		
		alert("Se ha eliminado la secretar\xEDa con \xE9xito");
		parent.llamarListadoSecretaria();
	}
}
function eliminarAlbum(idAlbum){
	if(confirm('\xBFSeguro que desea eliminar el album?')){		
		peticion("../accion/iframe.gestionAlbum.php", "FrameForm", "POST", "IDAlbum="+idAlbum+"&Modalidad=eliminar");		
		alert("Se ha eliminado el album con \xE9xito");
		parent.llamarListado('AlbumEditar');
	}
}
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 \xE9xito");
		parent.llamarListadoEnvento();
	}
}
function llamarListado(donde){
	peticion("../paginas/listado"+donde+".php", "contenedorFormulario", "post", "");
}
function llamarListadoSecretaria(){
	peticion("../paginas/listadoSecretaria.php", "contenedorFormulario", "post", "")
}
function llamarListadoEnvento(){
	peticion("../paginas/listadoEvento.php", "contenedorFormulario", "post", "")
}
function llamarListadoEnventoAjax(){
	peticion("../paginas/listadoEventoAjax.php", "listadoEventos", "post", "")
}

function validarEvento(){
	if(document.formGestion.titulo.value==""){
		alert("Ingrese el título del evento.")
		document.formGestion.titulo.focus();
		return;
	}
	if((document.formGestion.fechaInicio.value=="")||(document.formGestion.fechaInicio.value=="00/00/0000")){
		alert("Ingrese la fecha de inicio del evento.")
		document.formGestion.fechaInicio.focus();
		return;
	}
	if((document.formGestion.fechaFin.value=="")||(document.formGestion.fechaFin.value=="00/00/0000")){
		alert("Ingrese la fecha de finalizaci\xF3n del evento.");
		document.formGestion.fechaFin.focus();
		return;
	}
	mostrarDiv('bgEnabled5');
	document.formGestion.submit();
}
function llamarForm(idItem, donde){
	switch(donde){
		case "Secretaria":
			mostrarDiv("bgEnabled3");
			peticion("../paginas/secretariaAgregar.php", "bgEnabled3", "post", "IDSecretaria="+idItem)
		break;
		case "Album":
			mostrarDiv("bgEnabled4");
			peticion("../paginas/albumAgregar.php", "bgEnabled4", "post", "IDAlbum="+idItem)
		break;
		case "Evento":
			mostrarDiv("bgEnabled");
			peticion("../paginas/eventoAgregar.php", "bgEnabled", "post", "IDEvento="+idItem)
		break;
	}
	
	
}
/*function llamarFormEvento(idEvento){
	mostrarDiv("bgEnabled");
	peticion("../paginas/eventoAgregar.php", "bgEnabled", "post", "IDEvento="+idEvento)
}

function llamarFormSecretaria(idSecretaria){
	mostrarDiv("bgEnabled3");
	peticion("../paginas/secretariaAgregar.php", "bgEnabled3", "post", "IDSecretaria="+idSecretaria)
}
function llamarFormEvento(idEvento){
	mostrarDiv("bgEnabled");
	peticion("../paginas/eventoAgregar.php", "bgEnabled", "post", "IDEvento="+idEvento)
}*/
function activarLoguin(nombre){
	llamarControles();
	llamarMenu();
	llamarUsuario();
	llamarListadoEnvento();
	//peticion("inc/inc.menu.php", "contenedorFormulario", "post", "")
}
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 validarInscripcion(){
	if(document.formInscripcion.apellidoInscripcion.value==""){
		alert("Debe ingresar su apellido para completar el formulario.");
		document.formInscripcion.apellidoInscripcion.value="";
		document.formInscripcion.apellidoInscripcion.focus();
		return;
	}
	if(document.formInscripcion.nombreInscripcion.value==""){
		alert("Debe ingresar su nombre para completar el formulario.");
		document.formInscripcion.nombreInscripcion.value="";
		document.formInscripcion.nombreInscripcion.focus();
		return;
	}
	if(!emailCheck(document.formInscripcion.emailInscripcion.value)){
		document.formInscripcion.emailInscripcion.value="";
		document.formInscripcion.emailInscripcion.focus();
		return;
	}
	document.formInscripcion.submit();
}
function enviarMailSala(idSala){
	if((document.getElementById("NombreMail"+idSala).value=="")||(document.getElementById("NombreMail"+idSala).value=="Nombre")){
		alert("Debe ingresar su nombre. Gracias.");
		document.getElementById("NombreMail"+idSala).value="";
		document.getElementById("NombreMail"+idSala).focus();
		return;
	}
	if((document.getElementById("DireccionMail"+idSala).value=="")||(document.getElementById("DireccionMail"+idSala).value=="eMail")){
		alert("Debe ingresar su correo electrónico. Gracias.");
		document.getElementById("DireccionMail"+idSala).value="";
		document.getElementById("DireccionMail"+idSala).focus();
		return;
	}
/*	if(!emailCheck(document.getElementById("DireccionMail"+idSala).value=="")){
		document.getElementById("DireccionMail"+idSala).value="";
		document.getElementById("DireccionMail"+idSala).focus();
		return;
	}*/
	document.getElementById("IDSalaEnvio").value=idSala;
	document.envioMailSalaResultado.submit();
}
function mostrarPaso(paso){
	switch(paso){
		case "personas":
			if(document.formElegirSala.IDSala.value==""){alert("Por favor, elija un tipo de sala para continuar");return;}
		break;
		/*case "salasResultado":
			if(document.formElegirSala.CantidadPersonas.value==""){alert("Por favor, la cantidad de personas para continuar");return;}
		break;*/
	}
	ocultarDiv('formato');
	ocultarDiv('personas');
	ocultarDiv('salasResultado');
	mostrarDiv(paso)
}

function informacionEnviar(){
	if((document.formInformacion.nombreInformacion.value=="")||(document.formInformacion.nombreInformacion.value=="nombre y apellido")){
		alert("Debe ingresar su nombre. Gracias");
		document.formInformacion.nombreInformacion.value="";
		document.formInformacion.nombreInformacion.focus();
		return;
	}
	if (!emailCheck(document.formInformacion.mailInformacion.value)){		
		document.formInformacion.mailInformacion.focus();
		return;
	}
	document.formInformacion.submit();
}
function calcularSalasResultado(){
	cantPers = document.formElegirSala.CantidadPersonas.value;
	sala = document.formElegirSala.IDSala.value;
	if(sala==""){
		alert("Por favor, seleccione un tipo de sala para su reunión.");
		return;
	}
	if(cantPers==""){
		alert("Por favor, seleccione la cantidad de personas que integrarán su reunión.");
		return;
	}
	mostrarDiv('salasResultado');
	peticion("paginas/salasResultado.php", "salasResultado", "post", "CantidadPersonas="+cantPers+"&IDSala="+sala)
}
function elegirPersonas(cantPersonas){
	for(i=1;i<=6;i++){
		document.getElementById(i).style.border= "0px";		
		document.getElementById(i).style.height = "18px";
		document.getElementById(i).style.width = "220px";
	}
	
	document.getElementById(cantPersonas).style.height = "16px";
	document.getElementById(cantPersonas).style.width = "218px";
	document.getElementById(cantPersonas).style.border = "1px solid #090";
	document.formElegirSala.CantidadPersonas.value = cantPersonas;	
}
function elegirSala(idSala){
	for(i=1;i<=7;i++){
		document.getElementById("sala"+i).style.width = "220px";
		document.getElementById("sala"+i).style.border= "0px";
		document.getElementById("sala"+i).style.height = "20px";
	}
	document.getElementById(idSala).style.width = "218px";
	document.getElementById(idSala).style.height = "18px";
	document.getElementById(idSala).style.border = "1px solid #090";
	document.formElegirSala.IDSala.value = idSala;
	
	switch(idSala){
		case "sala1":
			arrayDisponibles = new Array(1,2,3);
		break;
		case "sala2":
			arrayDisponibles = new Array(1,2,3,5);
		break;
		case "sala3":
			arrayDisponibles = new Array(1,2,3);
		break;
		case "sala4":
			arrayDisponibles = new Array(1,3,6);
		break;
		case "sala5":
			arrayDisponibles = new Array(0,1);
		break;
		case "sala6":		
			arrayDisponibles = new Array(1,2,3);
		break;
		case "sala7":
			arrayDisponibles = new Array(1,2);
		break;		
	}// onClick="javascript:elegirPersonas(this.id)"
	peticion('paginas/personasResultado.php', 'personas', 'POST', 'arrayPersonas='+arrayDisponibles);
/*	for(e=1;e<=arrayDisponibles.length;e++){	
		document.getElementById(arrayDisponibles[e]).style.border= "1px solid #090";
	}*/
}
function llamarFormPasos(){
	mostrarDiv('bgEnabled');
	mostrarPaso('formato');
}
function validarContacto(){
	if(document.formContacto.nombreContacto.value=="nombre y apellido"){
		alert("Debe ingresar su nombre. Gracias");
		document.formContacto.nombreContacto.value="";
		document.formContacto.nombreContacto.focus();
		return;
	}
	if(document.formContacto.mailContacto.value=="mail"){
		alert("Debe ingresar su e-mail. Gracias");
		document.formContacto.mailContacto.value="";
		document.formContacto.mailContacto.focus();
		return;
	}
	if(document.formContacto.consultaContacto.value=="Escriba su consulta"){
		alert("Debe ingresar la consulta. Gracias");
		document.formContacto.consultaContacto.value="";
		document.formContacto.consultaContacto.focus();
		return;
	}
	document.formContacto.submit();	
}
function validarContacto2(){
	if(document.formContacto2.nombreContacto.value=="nombre y apellido"){
		alert("Debe ingresar su nombre. Gracias");
		document.formContacto2.nombreContacto.value="";
		document.formContacto2.nombreContacto.focus();
		return;
	}
	if(document.formContacto2.mailContacto.value=="mail"){
		alert("Debe ingresar su e-mail. Gracias");
		document.formContacto2.mailContacto.value="";
		document.formContacto2.mailContacto.focus();
		return;
	}
	if(document.formContacto2.consultaContacto.value=="Escriba su consulta"){
		alert("Debe ingresar la consulta. Gracias");
		document.formContacto2.consultaContacto.value="";
		document.formContacto2.consultaContacto.focus();
		return;
	}
	document.formContacto2.submit();	
}
function validarContacto3(){
	if(document.formContacto2.nombreContacto.value=="nombre y apellido"){
		alert("Debe ingresar su nombre. Gracias");
		document.formContacto2.nombreContacto.value="";
		document.formContacto2.nombreContacto.focus();
		return;
	}
	if(document.formContacto2.mailContacto.value=="mail"){
		alert("Debe ingresar su e-mail. Gracias");
		document.formContacto2.mailContacto.value="";
		document.formContacto2.mailContacto.focus();
		return;
	}
	if(document.formContacto2.consultaContacto.value=="Escriba su consulta"){
		alert("Debe ingresar la consulta. Gracias");
		document.formContacto2.consultaContacto.value="";
		document.formContacto2.consultaContacto.focus();
		return;
	}
	document.formContacto2.submit();	
}
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 mostrarOcultar(cual){
	if((document.getElementById(cual).style.display == "none")||(document.getElementById(cual).style.display == "")){
		mostrarDiv(cual)
	}else{
		ocultarDiv(cual)
	}
}
function mostrarDiv(cual){
	document.getElementById(cual).style.display = "block";
	return
}
function ocultarDiv(cual){
	document.getElementById(cual).style.display = "none";
	return
}
function resetEstiloMenu(quePag){
	document.getElementById('instalaciones').className = 'instalaciones';
	document.getElementById('conozca').className = 'conozca';
	document.getElementById('servicios').className = 'servicios';
	document.getElementById('tipoEvent').className = 'tipoEvent';
	document.getElementById('listadoEvento').className = 'listadoEvento';
	document.getElementById('listadoAlbum').className = 'listadoAlbum';
	document.getElementById('contacto').className = 'contacto';
	document.getElementById('montevideo').className = 'montevideo';
	if(quePag!='principal')	document.getElementById(quePag).className = quePag+'A';
}
function llamarPag(quePag){
	resetEstiloMenu(quePag);
	peticion('paginas/'+quePag+'.php', 'txt', 'POST', '');
}
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();	
}
function validarEnvioContacto(){
	var nombre = document.form1.nombreContacto1.value;
	var mail = document.form1.mailContacto1.value;
	var telefono = document.form1.telefonoContacto1.value;
	var consulta = document.form1.consultaContacto1.value;
	var largoTipoMsj = document.form1.tipoMsj.length;
		for(i=0; i<largoTipoMsj;i++){
			if( document.form1.tipoMsj[i].checked == true){
				tipoMsj = document.form1.tipoMsj[i].value;				
			}
		}
	if((mail=="")&&(telefono=="")){
		alert("Debe ingresar su telefono o su e-mail para poder comunicarnos con ud. Gracias");
		document.form1.mailContacto1.focus();
		return;
	}
	if(mail!=""){
		if (!emailCheck(mail)){		
			document.form1.mailContacto1.focus();
			return;
		}
	}
	if(consulta==""){
		alert("Debe ingresar su consulta para poder continuar. Gracias");
		document.form1.consultaContacto1.focus();
		return;
	}
	peticion('paginas/contactoEnviar.php', 'contenido', 'POST', 'nombreCnt='+nombre+'&mailCnt='+mail+'&telefonoCnt='+telefono+'&consultaCnt='+consulta+'&tipoMsj='+tipoMsj);	
}

///***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\u00f3n 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\u00f3n 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***///
