function grabarUsuario()
{
	jQuery('#contacta_nombre').css('background-color', '#fff');
	jQuery('#contacta_mail').css('background-color', '#fff');
	jQuery('#contacta_ciudad').css('background-color', '#fff');
	jQuery('#contacta_pais').css('background-color', '#fff');
	if(jQuery('#acepto_news').is(':checked'))
	{
		var acepto_news ='1';	
	}
	else
	{
		var acepto_news ='0';
	}
	var control = new Array();
	control[0] = 0;
	control[1] = '';
	if(jQuery('#contacta_nombre').get(0).value=='' || jQuery('#contacta_nombre').get(0).value=='Nombre / Apellidos')
	{
		control[0] = 1;
		jQuery('#contacta_nombre').css('background-color', '#FF6464');
	}
	if(jQuery('#contacta_mail').get(0).value=='' || jQuery('#contacta_mail').get(0).value=='Email' || comprobar_mail(jQuery('#contacta_mail').get(0).value)==false)
	{
		control[0] = 1;
		jQuery('#contacta_mail').css('background-color', '#FF6464');
	}
	if(jQuery('#contacta_ciudad').get(0).value=='' || jQuery('#contacta_ciudad').get(0).value=='Ciudad')
	{
		control[0] = 1;
		jQuery('#contacta_ciudad').css('background-color', '#FF6464');
	}
	if(jQuery('#contacta_pais').get(0).value=='' || jQuery('#contacta_pais').get(0).value=='Pais')
	{
		control[0] = 1;
		jQuery('#contacta_pais').css('background-color', '#FF6464');
	}
	if(control[0] == 0)
	{
		var nombre = jQuery('#contacta_nombre').get(0).value;
		var mail = jQuery('#contacta_mail').get(0).value;
		var ciudad = jQuery('#contacta_ciudad').get(0).value;
		var pais = jQuery('#contacta_pais').get(0).value;
		jQuery('#datos_contacto').hide();
		jQuery('#cargando_datos_contacto').show();
		$.ajax({
   			type: "POST",
   			url: "./fun/grabar_datos_contacto.php",
   			data: "nombre=" + nombre + '&mail=' + mail + '&ciudad=' + ciudad + '&pais=' + pais + '&news=' + acepto_news,
			dataType: 'html',
   			success: function(data)
			{
				jQuery('#datos_contacto').html(data);
				jQuery('#cargando_datos_contacto').hide();
				jQuery('#datos_contacto').show();
   			}
 		});
	}
}

function comprobar_mail(texto)
	{
		var mailres = true;            
    	var cadena = "abcdefghijklmnñopqrstuvwxyzABCDEFGHIJKLMNÑOPQRSTUVWXYZ1234567890@._-";
    	var arroba = texto.indexOf("@",0);
    	if ((texto.lastIndexOf("@")) != arroba) arroba = -1;
    	var punto = texto.lastIndexOf(".");
        for (var contador = 0 ; contador < texto.length ; contador++)
		{
        	if (cadena.indexOf(texto.substr(contador, 1),0) == -1)
			{
            	mailres = false;
            	break;
     		}
    	}
		if ((arroba > 1) && (arroba + 1 < punto) && (punto + 1 < (texto.length)) && (mailres == true) && (texto.indexOf("..",0) == -1))
		{
     		mailres = true;
		}
    	else
		{
     		mailres = false;
		}
    	return mailres;
	}
function cargarDatosContacto()
{
	jQuery('#datos_contacto_lateral').hide();
	jQuery('#cargando_datos_lateral').show();
	$.ajax({
   		type: "POST",
   		url: "./fun/cargar_datos_contacto.php",
   		data: "cod=0",
		dataType: 'json',
   		success: function(data)
		{
			jQuery('#datos_contacto_lateral').html(data[0]);
			jQuery('#select_direcciones').html(data[1]);
			jQuery('#cargando_datos_lateral').hide();
			jQuery('#datos_contacto_lateral').show();
   		}
 	});	
}

function enviarNewsletter()
{
	jQuery('#mail_newsletter').css('background-color', '#fff');
	var control = 0;
	mail = jQuery('#mail_newsletter').get(0).value;
	if(jQuery('#checkbox_leido').is(':checked'))
	{
		control = 0;
	}
	else
	{
		control = 1;
		alert("Tienes que leer y aceptar las condiciones de privacidad");
	}
	if(mail=='' || comprobar_mail(mail)==false)
	{
		control = 1;
		jQuery('#mail_newsletter').css('background-color', '#FF6464');
	}
	if(control==0)
	{
		jQuery('#datos_newsletter').hide();
		jQuery('#cargando_datos_envio_newsletter').show();
		$.ajax({
   			type: "POST",
   			url: "./fun/grabar_mails.php",
   			data: 'mail=' + mail,
			dataType: 'json',
   			success: function(data)
			{
				jQuery('#datos_newsletter').html(data[0]);
				jQuery('#cargando_datos_envio_newsletter').hide();
				jQuery('#datos_newsletter').show();
   			}
 		});
	}
}

function enviarContacto()
{
	jQuery('#nombre').css('background-color', '#fff');
	jQuery('#email').css('background-color', '#fff');
	jQuery('#telefono').css('background-color', '#fff');
	jQuery('#comentario').css('background-color', '#fff');
	var control = 0;
	destino = jQuery('#mail_destino').val();
	nombre = jQuery('#nombre').get(0).value;
	mail = jQuery('#email').get(0).value;
	telefono = jQuery('#telefono').get(0).value;
	comentario = jQuery('#comentario').get(0).value;
	if(nombre=='')
	{
		control = 1;
		jQuery('#nombre').css('background-color', '#FF6464');
	}
	if(mail=='' || comprobar_mail(mail)==false)
	{
		control = 1;
		jQuery('#email').css('background-color', '#FF6464');
	}
	if(telefono=='')
	{
		control = 1;
		jQuery('#telefono').css('background-color', '#FF6464');
	}
	if(comentario=='')
	{
		control = 1;
		jQuery('#comentario').css('background-color', '#FF6464');
	}
	if(control==0)
	{
		jQuery('#formulario_contacta').hide();
		jQuery('#enviando_datos').show();
		$.ajax({
   			type: "POST",
   			url: "./fun/enviar_contacto.php",
   			data: "nombre=" + nombre + '&mail=' + mail + '&telefono=' + telefono + '&comentario=' + comentario + '&destinatario=' + destino,
			dataType: 'json',
   			success: function(data)
			{
				jQuery('#formulario_contacta').html(data[0]);
				jQuery('#enviando_datos').hide();
				jQuery('#formulario_contacta').show();
   			}
 		});
	}
}

function listadoEmpresasTodas()
	{
		//document.getElementById('datos').style.display='none';
		jQuery('#datos').hide();
		jQuery('#cargando').show();
		$.ajax({
   			type: "POST",
   			url: "./fun/listado_empresas_todas.php",
   			data: "cod=0",
			dataType: 'json',
   			success: function(data)
			{
				jQuery('#cargando').hide();
     			document.getElementById('datos').innerHTML = data;
				jQuery('#datos').show();
   			}
 		});	
	}

function listadoEmpresasTipo(cod)
	{
		//document.getElementById('datos').style.display='none';
		jQuery('#datos').hide();
		jQuery('#cargando').show();
		$.ajax({
   			type: "POST",
   			url: "./fun/listado_empresas_tipo.php",
   			data: "cod=" + cod,
			dataType: 'json',
   			success: function(data)
			{
				jQuery('#cargando').hide();
     			document.getElementById('datos').innerHTML = data;
				jQuery('#datos').show();
   			}
 		});	
	}
	
function listadoEmpresasTexto(texto)
	{
		//document.getElementById('datos').style.display='none';
		jQuery('#datos').hide();
		jQuery('#cargando').show();
		$.ajax({
   			type: "POST",
   			url: "./fun/listado_empresas_texto.php",
   			data: "texto=" + texto,
			dataType: 'json',
   			success: function(data)
			{
				jQuery('#cargando').hide();
     			document.getElementById('datos').innerHTML = data;
				jQuery('#datos').show();
   			}
 		});	
	}
	
function listadoEmpresasTextoTipo(texto, cod)
	{
		//document.getElementById('datos').style.display='none';
		jQuery('#datos').hide();
		jQuery('#cargando').show();
		$.ajax({
   			type: "POST",
   			url: "./fun/listado_empresas_texto_tipo.php",
   			data: "texto=" + texto + "&cod=" + cod,
			dataType: 'json',
   			success: function(data)
			{
				jQuery('#cargando').hide();
     			document.getElementById('datos').innerHTML = data;
				jQuery('#datos').show();
   			}
 		});	
	}

function paginarNoticiasPubliIndex()
	{
		//document.getElementById('datos').style.display='none';
		jQuery('#datos_noticias_index').hide();
		jQuery('#cargando_datos_noticias_index').show();
		$.ajax({
   			type: "POST",
   			url: "./fun/listado_noticias_publi_index.php",
   			data: "cod=0",
			dataType: 'html',
   			success: function(data)
			{
				jQuery('#cargando_datos_noticias_index').hide();
     			document.getElementById('datos_noticias_index').innerHTML = data;
				jQuery('#datos_noticias_index').show();
   			}
 		});	
	}
	
function cargarVideosPubliIndex()
	{
		//document.getElementById('datos').style.display='none';
		jQuery('#wrap').hide();
		jQuery('#cargando_datos_videos_index').show();
		$.ajax({
   			type: "POST",
   			url: "./fun/cargar_videos.php",
   			data: "cod=0",
			dataType: 'json',
   			success: function(data)
			{
				jQuery('#mycarousel').html(data[0]);
				jQuery('#cargando_datos_videos_index').hide();
				jQuery('#wrap').show();
				jQuery('#mycarousel').jcarousel({
     				wrap: 'circular'
   				});
   			}
 		});	
	}
	
function cargarFotoVideoPubliIndex(cod)
	{
		jQuery('#video').hide();
		jQuery('#foto_video').hide();
		jQuery('#titu-video').hide();
		jQuery('#titu-video2').hide();
		jQuery('#descripcion').hide();
		jQuery('#cargando_datos_foto_video_index').show();
		$.ajax({
   			type: "POST",
   			url: "./fun/cargar_foto_video.php",
   			data: "cod=" + cod,
			dataType: 'json',
   			success: function(data)
			{
				jQuery('#foto_video').html(data[0]);
				jQuery('#titu-video').html(data[1]);
				jQuery('#titu-video2').html(data[2]);
				jQuery('#descripcion').html(data[3]);
				jQuery('#cargando_datos_foto_video_index').hide();
				jQuery('#foto_video').show();
				jQuery('#titu-video').show();
				jQuery('#titu-video2').show('slow');
				jQuery('#descripcion').show('slow');
   			}
 		});	
	}
	
function cargarVideo(cod)
	{
		//document.getElementById('datos').style.display='none';
		jQuery('#foto_video').hide();
		jQuery('#titu-video').hide();
		jQuery('#titu-video2').hide();
		jQuery('#descripcion').hide();
		jQuery('#cargando_datos_foto_video_index').show();
		$.ajax({
   			type: "POST",
   			url: "./fun/cargar_video.php",
   			data: "cod=" + cod,
			dataType: 'json',
   			success: function(data)
			{
				jQuery('#video').html(data[0]);
				jQuery('#cargando_datos_foto_video_index').hide();
				jQuery('#video').show();
				jQuery('#titu-video2').show('slow');
				jQuery('#descripcion').show('slow');
   			}
 		});	
	}

function paginarDiscosPubliIndex(pagina)
	{
		jQuery('#datos_discos_index').hide();
		jQuery('#datos_paginador_discos_index').hide();
		jQuery('#cargando_datos_discos_index').show();
		$.ajax({
   			type: "POST",
   			url: "./fun/listado_discos_publi_index.php",
   			data: "pagina=" + pagina,
			dataType: 'json',
   			success: function(data)
			{
				jQuery('#cargando_datos_discos_index').hide();
				jQuery('#datos_discos_index').html(data[0]);
				jQuery('#datos_paginador_discos_index').html(data[1]);
				jQuery('#datos_discos_index').show();
				jQuery('#datos_paginador_discos_index').show();
   			}
 		});	
	}

function paginarDiscosPubli(pagina)
	{
		jQuery('#datos_discos').hide();
		jQuery('#datos_paginador_discos').hide();
		jQuery('#cargando_datos_discos').show();
		$.ajax({
   			type: "POST",
   			url: "./fun/listado_discos_publi.php",
   			data: "pagina=" + pagina,
			dataType: 'json',
   			success: function(data)
			{
				jQuery('#cargando_datos_discos').hide();
				jQuery('#datos_discos').html(data[0]);
				jQuery('#datos_paginador_discos').html(data[1]);
				jQuery('#datos_discos').show();
				jQuery('#datos_paginador_discos').show();
   			}
 		});	
	}
	
function cargarDisco(cod)
	{
		jQuery('#datos_disco_titulo').hide();
		jQuery('#datos_letra').hide();
		jQuery('#datos_disco').hide();
		jQuery('#cargando_datos_disco').show();
		$.ajax({
   			type: "POST",
   			url: "./fun/cargar_disco.php",
   			data: "cod=" + cod,
			dataType: 'json',
   			success: function(data)
			{
				jQuery('#datos_disco_titulo').html(data[1]);
				jQuery('#datos_disco').html(data[0]);
				jQuery('#cargando_datos_disco').hide();
				jQuery('#datos_disco_titulo').show();
				jQuery('#datos_disco').show();
				cargarCanciones(cod, 1);
   			}
 		});	
	}

function cargarLetra(cod)
	{
		jQuery('#datos_letra').hide();
		jQuery('#cargando_datos_letra').show();
		$.ajax({
   			type: "POST",
   			url: "./fun/cargar_letra.php",
   			data: "cod=" + cod,
			dataType: 'json',
   			success: function(data)
			{
				jQuery('#datos_letra').html(data[0]);
				jQuery('#cargando_datos_letra').hide();
				jQuery('#datos_letra').show('slow');
   			}
 		});	
	}
	
function cargarCanciones(cod, pagina)
	{
		jQuery('#datos_paginador_canciones').hide();
		jQuery('#datos_canciones').hide();
		jQuery('#cargando_datos_canciones').show();
		$.ajax({
   			type: "POST",
   			url: "./fun/listado_canciones_publi.php",
   			data: "cod=" + cod + '&pagina=' + pagina,
			dataType: 'json',
   			success: function(data)
			{
				jQuery('#datos_paginador_canciones').html(data[1]);
				jQuery('#datos_canciones').html(data[0]);
				jQuery('#cargando_datos_canciones').hide();
				jQuery('#datos_paginador_canciones').show();
				jQuery('#datos_canciones').show('slow');
   			}
 		});	
	}

function paginarConciertosPubliIndex()
	{
		//document.getElementById('datos').style.display='none';
		jQuery('#datos_conciertos_index').hide();
		jQuery('#cargando_datos_conciertos_index').show();
		$.ajax({
   			type: "POST",
   			url: "./fun/listado_conciertos_publi_index.php",
   			data: "cod=0",
			dataType: 'html',
   			success: function(data)
			{
				jQuery('#cargando_datos_conciertos_index').hide();
     			document.getElementById('datos_conciertos_index').innerHTML = data;
				jQuery('#datos_conciertos_index').show();
   			}
 		});	
	}

function paginarNoticiasPubli(pagina)
	{
		jQuery('#datos_noticias_publi').hide();
		jQuery('#cargando_datos_noticias_publi').show();
		$.ajax({
   			type: "POST",
   			url: "./fun/listado_noticias_publi.php",
   			data: "pagina=" + pagina,
			dataType: 'json',
   			success: function(data)
			{
				jQuery('#cargando_datos_noticias_publi').hide();
     			document.getElementById('datos_noticias_publi').innerHTML = data[0];
				document.getElementById('paginador').innerHTML = data[1];
				jQuery('#datos_noticias_publi').show();
   			}
 		});	
	}
	
function paginarNoticiasPubli2(pagina)
	{
		jQuery('#datos_noticias_publi').hide();
		jQuery('#cargando_datos_noticias_publi').show();
		$.ajax({
   			type: "POST",
   			url: "./fun/listado_noticias_publi2.php",
   			data: "pagina=" + pagina,
			dataType: 'json',
   			success: function(data)
			{
				jQuery('#cargando_datos_noticias_publi').hide();
     			document.getElementById('datos_noticias_publi').innerHTML = data[0];
				document.getElementById('minipaginador').innerHTML = data[1];
				jQuery('#datos_noticias_publi').show();
   			}
 		});	
	}
	
function paginarConciertosPubli(pagina)
	{
		jQuery('#datos').hide();
		jQuery('#paginador_mostrar').hide();
		jQuery('#cargando_datos').show();
		$.ajax({
   			type: "POST",
   			url: "./fun/listado_conciertos_publi.php",
   			data: "pagina=" + pagina,
			dataType: 'json',
   			success: function(data)
			{
				jQuery('#cargando_datos').hide();
				jQuery('#datos').html(data[0]);
				jQuery('#paginador').html(data[1]);
				jQuery('#datos').show();
				jQuery('#paginador').show();
   			}
 		});	
	}
	
function cargarNoticia(cod)
	{
		jQuery('#datos_noticia_publi').hide();
		jQuery('#cargando_dato_noticias_publi').show();
		$.ajax({
   			type: "POST",
   			url: "./fun/cargar_noticia.php",
   			data: "cod=" + cod,
			dataType: 'html',
   			success: function(data)
			{
				jQuery('#cargando_datos_noticia_publi').hide();
     			document.getElementById('datos_noticia_publi').innerHTML = data;
				jQuery('#datos_noticia_publi').show();
   			}
 		});	
	}
	
function cargarEmpresa(cod)
	{
		jQuery('#empresa').hide();
		jQuery('#cargando_empresa').show();
		$.ajax({
   			type: "POST",
   			url: "./fun/cargar_empresa.php",
   			data: "cod=" + cod,
			dataType: 'html',
   			success: function(data)
			{
				jQuery('#cargando_empresa').hide();
     			document.getElementById('empresa').innerHTML = data;
				jQuery('#empresa').show();
   			}
 		});	
	}
	
function cargarEmpresasLateral(cod, tipo)
	{
		jQuery('#empresas_lateral').hide();
		jQuery('#cargando_empresas_lateral').show();
		$.ajax({
   			type: "POST",
   			url: "./fun/cargar_empresas_lateral.php",
   			data: "cod=" + cod + "&tipo=" + tipo,
			dataType: 'json',
   			success: function(data)
			{
				jQuery('#cargando_empresas_lateral').hide();
     			document.getElementById('empresas_lateral').innerHTML = data[0];
				jQuery('#empresas_lateral').show();
   			}
 		});	
	}
	
function redireccionar_param(pagina, parametro, codigo)
{
	 window.locationf= pagina + '?' + parametro + '=' + codigo; 	
}

function mycarousel_itemLoadCallback(carousel, state)
{
    // Check if the requested items already exist
    if (carousel.has(carousel.first, carousel.last)) {
        return;
    }

    jQuery.get(
        './fun/cargar_videos.php',
        {
            first: carousel.first,
			last: carousel.last
        },
        function(xml) {
            mycarousel_itemAddCallback(carousel, carousel.first, carousel.last, xml);
        },
        'xml'
    );
};

function mycarousel_itemAddCallback(carousel, first, last, xml)
{
    // Set the size of the carousel
    carousel.size(parseInt(jQuery('total', xml).text()));
	//alert(jQuery('total', xml).text());
    jQuery('image', xml).each(function(i) {
		var nos_da = jQuery(this).text();
        var datos = nos_da.split('|');
		carousel.add(first + i, mycarousel_getItemHTML(datos[0], datos[1]));
    });
};

/**
 * Item html creation helper.
 */
function mycarousel_getItemHTML(url, cod)
{
    return '<div class="minivideo"><img src="' + url + '" style="cursor:pointer;" onclick="cargarFotoVideoPubliIndex(' + cod + ')"/></div>';
};
