
var slideCache = new Array();
var carrusel = "";
var lastnextText = "";
//funcion para mostrar un carrusel de imagenes
function RunSlideShow(pictureName,imageFiles,textId,displaySecs,tipo)
{
	clearTimeout(carrusel);
	var imageSeparator = imageFiles.indexOf(";");
	var nextImage = imageFiles.substring(0,imageSeparator);
	
	var textSeparator = textId.indexOf(";");
	var nextText = textId.substring(0,textSeparator);
	
	if (document.getElementById(pictureName)){
			if(nextImage.substring(nextImage.length-4) == ".swf"){
				document.getElementById(pictureName).innerHTML = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" name="banner" width="600" height="180" id="banner"><param name="movie" value="banners/"' + nextImage + '><param name="swLiveConnect" value="true"><param name="quality" value="high"><embed src="banners/' + nextImage + '" width="600" height="180" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" name="panel"></embed></object>';
			}else {
				document.getElementById(pictureName).innerHTML = '	<img id="img_New" width="600" height="180" src="images/fotos/actividades/' + nextImage + '">';
			}
	
		
		if (tipo == "noticias") {
			//Ocultamos la noticia anterior y mostramos la nueva
			if (lastnextText != "") {
				document.getElementById("div_Noticias_" + lastnextText).style.display = "none";
				document.getElementById("span_Bola_" + lastnextText).style.textDecoration = "none";
				document.getElementById("img_Bola_" + lastnextText).style.backgroundImage = "url(images/estilo/fondobotongris.png)";
			}
			document.getElementById("div_Noticias_" + nextText).style.display = "";
			
			
			//Subrallamos la nueva noticia
			document.getElementById("span_Bola_" + nextText).style.textDecoration = "underline";
			
			//Cambiamos el color la bola
			document.getElementById("img_Bola_" + nextText).style.backgroundImage = "url(images/estilo/fondotitulo.jpg)";
			
		}else{
			if (tipo == "sub"){
				if (lastnextText != "") {
					document.getElementById("noticia_" + lastnextText).style.textDecoration = "none";
				}
				document.getElementById("noticia_" + nextText).style.textDecoration = "underline";
				
			}
		}
		lastnextText = nextText;
		var futureImages= imageFiles.substring(imageSeparator+1,imageFiles.length) + ';' + nextImage;
		var futureId= textId.substring(textSeparator+1,textId.length) + ';' + nextText;
		carrusel = setTimeout("RunSlideShow('"+pictureName+"','"+futureImages+"','"+futureId+"',"+displaySecs+",'"+tipo+"')",displaySecs*1000);
		
	}
}
anterior = 0;
function seleccionaTienda(idTienda,fotoTienda) {
	
	if (anterior != 0) {
		document.getElementById('link_Tienda' + anterior).style.textDecoration = 'none';
		document.getElementById('link_Tienda' + anterior).style.fontWeight = 'normal';
		document.getElementById('tr_Tienda' + anterior).style.display = "none";
	}
	if (idTienda != 0) {
		document.getElementById('tr_Tienda0').style.display= 'none';
		document.getElementById('link_Tienda' + idTienda).style.textDecoration = 'underline';
		document.getElementById('link_Tienda' + idTienda).style.fontWeight = 'bold';	
	}
	document.getElementById('tr_Tienda' + idTienda).style.display = "";
	document.getElementById('img_tiendas').src = "images/sitio/" + fotoTienda;
	anterior = idTienda;
}

function compruebaCampos(pagina){
	var nombre = document.getElementById('nombre_' + pagina);
	var apellidos = document.getElementById('apellidos_' + pagina);
	var direccion = document.getElementById('direccion_' + pagina);
	var fecha = document.getElementById('fecha_' + pagina);
	var cp = document.getElementById('cp_' + pagina);
	var telfijo = document.getElementById('telfijo_' + pagina);
	var telmovil = document.getElementById('telmovil_' + pagina);
	var email = document.getElementById('email_' + pagina);
	var comentarios = document.getElementById('comentarios_' + pagina);
	
	//Requeridos
	if (nombre.value == "") {
		alert('Debe indicar su nombre');
		return false;
	}
	if (apellidos.value == "") {
		alert('Debe indicar sus apellidos');
		return false;
	}
	if (direccion.value == "") {
		alert('Debe indicar su direccion');
		return false;
	}
	if (fecha.value == "") {
		alert('Debe indicar su fecha de nacimiento');
		return false;
	}
	if (cp.value == "") {
		alert('Debe indicar el código postal de su ciudad');
		return false;
	}
	/*if (telfijo.value == "") {
		alert('Debe indicar su teléfono fijo');
		return false;
	}
	if (telmovil.value == "") {
		alert('Debe indicar su teléfono móvil');
		return false;
	}*/
	if (email.value == "") {
		alert('Debe indicar su email');
		return false;
	}
	if (comentarios.value == "") {
		alert('Debe indicar los comentarios');
		return false;
	}
	
	//Fecha
	
	//Numéricos
	
	//Email
	var b=/^[^@\s]+@[^@\.\s]+(\.[^@\.\s]+)+$/;          
           
  //devuelve verdadero si validacion OK, y falso en caso contrario  
  if( !b.test(email.value)) {
  	alert('El Email introducido no es correcto');
  	return false;
  }  
	
	document.form_Datos.submit();
}

function compruebaCamposLogin(){
	var login = document.getElementById('sl_user');
	var pass = document.getElementById('sl_pass');
	
	
	//Requeridos
	if (login.value == "") {
		alert('Debe indicar el login');
		return false;
	}
	if (pass.value == "") {
		alert('Debe indicar el password');
		return false;
	}
	return true;
}

function compruebaCamposCreacion(){
	var titulo = document.getElementById('titulo');
	var contenido = document.getElementById('contenido');
	var dia = document.getElementById('dia');
	var enlace = document.getElementById('enlace');
	
	
	//Requeridos
	if (titulo.value == "") {
		alert('Debe indicar el título de la actividad');
		return false;
	}
	if (contenido.value == "") {
		alert('Debe indicar el contenido de la actividad');
		return false;
	}
	if (dia.value == "") {
		alert('Debe indicar el día de la actividad');
		return false;
	}
	return true;
}

function compruebaCamposNegocios(){
	var nombre = document.getElementById('nombre_negocios');
	var apellidos = document.getElementById('apellidos_negocios');
	var direccion = document.getElementById('direccion_negocios');
	var actividad = document.getElementById('actividad_negocios');
	var cargo = document.getElementById('cargo_negocios');
	var supnecesaria = document.getElementById('supnecesaria_negocios');
	var rotulo = document.getElementById('rotulo_negocios');
	var telfijo = document.getElementById('telfijo_negocios');
	var fax = document.getElementById('fax_negocios');
	var email = document.getElementById('email_negocios');
	var comentarios = document.getElementById('comentarios_negocios');
	
	//Requeridos
	if (nombre.value == "") {
		alert('Debe indicar su nombre');
		return false;
	}
	if (apellidos.value == "") {
		alert('Debe indicar sus apellidos');
		return false;
	}
	if (direccion.value == "") {
		alert('Debe indicar su direccion');
		return false;
	}
	if (actividad.value == "") {
		alert('Debe indicar su actividad');
		return false;
	}
	if (cargo.value == "") {
		alert('Debe indicar su cargo');
		return false;
	}
	/*if (supnecesaria.value == "") {
		alert('Debe indicar su superfície necesaria');
		return false;
	}
	if (rotulo.value == "") {
		alert('Debe indicar un rótulo');
		return false;
	}
	if (telfijo.value == "") {
		alert('Debe indicar un telfijo');
		return false;
	}
	if (fax.value == "") {
		alert('Debe indicar un fax');
		return false;
	}*/
	if (email.value == "") {
		alert('Debe indicar su email');
		return false;
	}
	if (comentarios.value == "") {
		alert('Debe indicar los comentarios');
		return false;
	}
	
	//Fecha
	
	//Numéricos
	
	//Email
	var b=/^[^@\s]+@[^@\.\s]+(\.[^@\.\s]+)+$/;          
           
  //devuelve verdadero si validacion OK, y falso en caso contrario  
  if( !b.test(email.value)) {
  	alert('El Email introducido no es correcto');
  	return false;
  }  
	
	document.form_Datos.submit();
}
//Funcion que muestra
function mostrar(idDiv,listaOcultar) {
	if (listaOcultar) {
		var partes = listaOcultar.split(',');
		for(i=0;i<partes.length;i++) {
			ocultar(partes[i]);
		}
	}
	$("#" + idDiv + " div").slideDown("slow");
}
//Funcion que oculta
function ocultar(idDiv) {
		$("#" + idDiv + " div").slideUp("slow");

}


lastNew = "";
function showNews(dia,contador) {
	clearTimeout(carrusel);
		if (lastNew != "" && contador == 0) {
			document.getElementById('div_Noticias_' + lastNew).style.display = "none";
			document.getElementById('div_Bolas_' + lastNew).style.display = "none";
		}
		if (document.getElementById('div_Noticias_' + dia)) {
			document.getElementById('div_Noticias_' + dia).style.display = "";
			
		
			listaImagenes = "";
			listaTexto = "";
			listaBolas = "";
			mostrarSlide = 0;
			listaImagenesAux = "";
			listaTextoAux = "";
			for (i =0;i<vector.length;i++) {
				if (vector[i].dia == dia){
					if (listaImagenes == "") {
						listaImagenes = vector[i].foto;
						listaTexto = vector[i].dia + "_" + vector[i].contador;
					} else {
						mostrarSlide = 1;
						if(contador == vector[i].contador) {
							listaImagenesAux = listaImagenes;
							listaTextoAux = listaTexto;
							listaImagenes =  vector[i].foto;
							listaTexto = vector[i].dia + "_" + vector[i].contador;
						} else {
							listaImagenes =  listaImagenes + ';' + vector[i].foto;
							listaTexto = listaTexto + ";" + vector[i].dia + "_" + vector[i].contador;
						}
					}
					/*if (document.getElementById('img_New')){
						document.getElementById('img_New').src = 'images/fotos/actividades/' + vector[i].foto;
						break;
					}*/
				} else {
					if (listaImagenes != "") {
						break;
					}
				}
			}
			
			if (mostrarSlide) {
				if (listaImagenesAux != "") {
					listaImagenes = listaImagenes + ";" + listaImagenesAux;
					listaTexto = listaTexto + ";" + listaTextoAux;
				}

				RunSlideShow("cargador",listaImagenes,listaTexto,10,"noticias");
				document.getElementById('div_Bolas_' + dia).style.display = "";
			}else {

				if (document.getElementById('cargador')){
						if(listaImagenes.substring(listaImagenes.length-4) == ".swf"){
							document.getElementById('cargador').innerHTML = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" name="banner" width="600" height="180" id="banner"><param name="movie" value="banners/' + listaImagenes + '"><param name="swLiveConnect" value="true"><param name="quality" value="high"><embed src="banners/' + listaImagenes + '" width="600" height="180" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" name="panel"></embed></object>';
						}else {
							document.getElementById('cargador').innerHTML = '	<img id="img_New" width="600" height="180" src="images/fotos/actividades/' + listaImagenes + '">';
						}
				}
			}
			
			lastNew = dia;
		}
}

function makeStruct(names) {
  var names = names.split(' ');
  var count = names.length;
  function constructor() {
    for (var i = 0; i < count; i++) {
      this[names[i]] = arguments[i];
    }
  }
  return constructor;
}
var hoy;
var cont;
hoy = new Date();
cont = hoy.getSeconds();
var hora;
var dia, dia_mes, mes, anio;
var dias_semana = new Array ('Domingo','Lunes','Martes','Mi&eacute;rcoles','Jueves','Viernes','S&aacute;bado');
var nombres_mes = new Array ('Enero','Febrero','Marzo','Abril','Mayo','Junio','Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre');
var cambiado = 0;
function reloj() {
		cont = cont+1;
		hoy.setSeconds(cont);
		if (cont > 59) { cont=0 };
		dia = hoy.getDay();
		dia_mes = hoy.getDate();
		mes = hoy.getMonth ();
		anio = hoy.getFullYear();
		h = hoy.getHours();
		if (h < 10) { h =' 0' + hoy.getHours() };
		m = hoy.getMinutes();
		if (m < 10) { m = '0' + hoy.getMinutes() };
		s = hoy.getSeconds();
		if (s < 10) {s = '0' + hoy.getSeconds() };
		horaReloj = h + ':' +  m + ':' + s;
		dia = dias_semana[dia];
		mes = nombres_mes[mes];
		textoReloj = dia + ',' + ' ' + dia_mes + ' de ' + mes + ' de ' + anio;
		
		if (cambiado == 300 ||cambiado == 0) {
			document.getElementById('cuerpo').style.backgroundImage = "url('images/estilo/fondo_" + h + ".jpg')";
			cambiado = 1;
		}
	
		
		cambiado = cambiado + 1;
		if (document.getElementById("reloj")){
			document.getElementById("reloj").innerHTML = horaReloj;
			document.getElementById("calen").innerHTML = textoReloj;
			window.setTimeout("reloj();", 999);
		}
	}

var listaBanners = "";
var listaAux = "";
var contBanners = 0;
var separacionBanners = 30;
function loadBanners() {
	
	
	var vector = listaBanners.split(',');
	var randomnumber=Math.floor(Math.random()*vector.length);
	document.getElementById('divBanner').innerHTML = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" name="banner" width="100%" height="100%" id="banner"><param name="movie" value="banners/' + vector[randomnumber] + '.swf"><param name="swLiveConnect" value="true"><param name="quality" value="high"><embed src="banners/' + vector[randomnumber] + '.swf" width="100%" height="100%" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" name="panel"></embed></object>';
	
	if (listaAux == "") {
		listaAux = vector[randomnumber];
	} else {
		listaAux = listaAux + "," + vector[randomnumber];
	}
	listaBanners = "";
	for (i=0;i<vector.length;i++) {
		if (randomnumber != i) {
			if (listaBanners == "") {
				listaBanners = vector[i];
			}else {
				listaBanners = listaBanners + ',' + vector[i];
			}
		}
	}
	if (listaBanners == "") {
		listaBanners = listaAux;
	}

	setTimeout("loadBanners()",separacionBanners * 1000);
}
