function votar_noticia(num_noticia, voto, origen){
	if(num_noticia==undefined){
		alert("Error: no se ha especificado la noticia");
		return;
	}
	
	if(voto==undefined){
		alert("Error: no se ha especificado el voto");
		return;
	}
	
	if(voto=="1"){
		$.ajax({
			type: "GET",
			url: "acciones.php",
			data: "accion=votar_noticia&num_noticia="+num_noticia+"&voto="+voto+"&origen="+origen,
			success: function(msg){
				document.getElementById("votar_noticia_"+num_noticia).className = msg;
				puntuacion_noticia(num_noticia);
			}, 
			error: function(xho){
				document.getElementById("votar_noticia_"+num_noticia).innerHTML = "Error:"+xho.responseText;
			}
		});	
	}else{
		$.ajax({
			type: "GET",
			url: "acciones.php",
			data: "accion=votar_noticia&num_noticia="+num_noticia+"&voto="+voto+"&origen="+origen,
			success: function(msg){
				document.getElementById("votar_noticia_"+num_noticia+"_").className = msg;
				puntuacion_noticia(num_noticia);
			}, 
			error: function(xho){
				document.getElementById("votar_noticia_"+num_noticia+"_").innerHTML = "Error:"+xho.responseText;
			}
		});		
	}

}

function puntuacion_noticia(num_noticia) {
	$.ajax({
		type: "GET",
		url: "acciones.php",
		data: "accion=puntuacion_noticia&num_noticia="+num_noticia,
		success: function(msg){
			document.getElementById("puntuacion_"+num_noticia).innerHTML = msg;
		}, 
		error: function(xho){
			document.getElementById("puntuacion_"+num_noticia).innerHTML = "Error:"+xho.responseText;
		}
	});
}

function votar_juegoflash(num_juego, voto, origen){
	if(num_juego==undefined){
		alert("Error: no se ha especificado el juego");
		return;
	}
	
	if(voto==undefined){
		alert("Error: no se ha especificado el voto");
		return;
	}

	if(voto=="1"){
		$.ajax({
			type: "GET",
			url: "acciones.php",
			data: "accion=votar_juegoflash&num_juego="+num_juego+"&voto="+voto+"&origen="+origen,
			success: function(msg){
				document.getElementById("votar_juegoflash_"+num_juego).className = msg;
				puntuacion_juegoflash(num_juego);
			}, 
			error: function(xho){
				document.getElementById("votar_juegoflash_"+num_juego).innerHTML = "Error:"+xho.responseText;
			}
		});	
	}else{
		$.ajax({
			type: "GET",
			url: "acciones.php",
			data: "accion=votar_juegoflash&num_juego="+num_juego+"&voto="+voto+"&origen="+origen,
			success: function(msg){
				document.getElementById("votar_juegoflash_"+num_juego+"_").className = msg;
				puntuacion_juegoflash(num_juego);
			}, 
			error: function(xho){
				document.getElementById("votar_juegoflash_"+num_juego+"_").innerHTML = "Error:"+xho.responseText;
			}
		});		
	}

}

function puntuacion_juegoflash(num_juego) {
	$.ajax({
		type: "GET",
		url: "acciones.php",
		data: "accion=puntuacion_juegoflash&num_juego="+num_juego,
		success: function(msg){
			document.getElementById("puntuacion_"+num_juego).innerHTML = msg;
		}, 
		error: function(xho){
			document.getElementById("puntuacion_"+num_juego).innerHTML = "Error:"+xho.responseText;
		}
	});
}

function votar_coche(num_coche, voto, origen){
	if(num_coche==undefined){
		alert("Error: no se ha especificado el coche");
		return;
	}
	
	if(voto==undefined){
		alert("Error: no se ha especificado el voto");
		return;
	}
	
	if(voto=="1"){
		$.ajax({
			type: "GET",
			url: "acciones.php",
			data: "accion=votar_coche&num_coche="+num_coche+"&voto="+voto+"&origen="+origen,
			success: function(msg){
				document.getElementById("votar_coche_"+num_coche).className = msg;
				puntuacion_coche(num_coche);
			}, 
			error: function(xho){
				document.getElementById("votar_coche_"+num_coche).innerHTML = "Error:"+xho.responseText;
			}
		});	
	}else{
		$.ajax({
			type: "GET",
			url: "acciones.php",
			data: "accion=votar_coche&num_coche="+num_coche+"&voto="+voto+"&origen="+origen,
			success: function(msg){
				document.getElementById("votar_coche_"+num_coche+"_").className = msg;
				puntuacion_coche(num_coche);
			}, 
			error: function(xho){
				document.getElementById("votar_coche_"+num_coche+"_").innerHTML = "Error:"+xho.responseText;
			}
		});		
	}
	
}
function puntuacion_coche(num_coche) {
	$.ajax({
		type: "GET",
		url: "acciones.php",
		data: "accion=puntuacion_coche&num_coche="+num_coche,
		success: function(msg){
			document.getElementById("puntuacion_"+num_coche).innerHTML = msg;
		}, 
		error: function(xho){
			document.getElementById("puntuacion_"+num_coche).innerHTML = "Error:"+xho.responseText;
		}
	});
}
					 
function votar_video(num_video, voto, origen){
	if(num_video==undefined){
		alert("Error: no se ha especificado el vídeo");
		return;
	}
	
	if(voto==undefined){
		alert("Error: no se ha especificado el voto");
		return;
	}
	
	if(voto=="1"){
		$.ajax({
			type: "GET",
			url: "acciones.php",
			data: "accion=votar_video&num_video="+num_video+"&voto="+voto+"&origen="+origen,
			success: function(msg){
				document.getElementById("votar_video_"+num_video).className = msg;
				puntuacion_video(num_video, origen);
				
			}, 
			error: function(xho){
				document.getElementById("votar_video_"+num_video).innerHTML = "Error:"+xho.responseText;
			}
		});	
	}else{
		$.ajax({
			type: "GET",
			url: "acciones.php",
			data: "accion=votar_video&num_video="+num_video+"&voto="+voto+"&origen="+origen,
			success: function(msg){
				document.getElementById("votar_video_"+num_video+"_").className = msg;
				puntuacion_video(num_video, origen);
			}, 
			error: function(xho){
				document.getElementById("votar_video_"+num_video+"_").innerHTML = "Error:"+xho.responseText;
			}
		});		
	}
}
function puntuacion_video(num_video, origen){
	
	if(origen=="3"){
		var identif_orig="puntuacion_2_";
	} else {
		var identif_orig="puntuacion_";
	}
	$.ajax({
		type: "GET",
		url: "acciones.php",
		data: "accion=puntuacion_video&num_video="+num_video,
		success: function(msg){
			document.getElementById(identif_orig+num_video).innerHTML = msg;
		}, 
		error: function(xho){
			document.getElementById(identif_orig+num_video).innerHTML = "Error:"+xho.responseText;
		}
	});
}
	
function votar_video_t(num_video, voto, origen){
	if(num_video==undefined){
		alert("Error: no se ha especificado el vídeo");
		return;
	}
	
	if(voto==undefined){
		alert("Error: no se ha especificado el voto");
		return;
	}
	
	if(voto=="1"){
		$.ajax({
			type: "GET",
			url: "acciones.php",
			data: "accion=votar_video_t&num_video="+num_video+"&voto="+voto+"&origen="+origen,
			success: function(msg){
				alert("--"+msg);
				document.getElementById("votar_video_t_"+num_video).className = msg;
				puntuacion_video_t(num_video);
			}, 
			error: function(xho){
				document.getElementById("votar_video_t_"+num_video).innerHTML = "Error:"+xho.responseText;
			}
		});	
	}else{
		$.ajax({
			type: "GET",
			url: "acciones.php",
			data: "accion=votar_video_t&num_video="+num_video+"&voto="+voto+"&origen="+origen,
			success: function(msg){
				document.getElementById("votar_video_t_"+num_video+"_").className = msg;
				puntuacion_video_t(num_video);
			}, 
			error: function(xho){
				document.getElementById("votar_video_t_"+num_video+"_").innerHTML = "Error:"+xho.responseText;
			}
		});		
	}
}

function puntuacion_video_t(num_video){
	$.ajax({
		type: "GET",
		url: "acciones.php",
		data: "accion=puntuacion_video_t&num_video="+num_video,
		success: function(msg){
			document.getElementById("puntuacion_"+num_video).innerHTML = msg;
		}, 
		error: function(xho){
			document.getElementById("puntuacion_"+num_video).innerHTML = "Error:"+xho.responseText;
		}
	});
}

/**** Pestañas ****/
var req;
function callPage(pageUrl, divElementId, loadinglMessage, pageErrorMessage) {
     document.getElementById(divElementId).innerHTML = loadinglMessage;
     try {
     req = new XMLHttpRequest(); /* e.g. Firefox */
     } catch(e) {
       try {
       req = new ActiveXObject("Msxml2.XMLHTTP");  /* some versions IE */
       } catch (e) {
         try {
         req = new ActiveXObject("Microsoft.XMLHTTP");  /* some versions IE */
         } catch (E) {
          req = false;
         } 
       } 
     }
     req.onreadystatechange = function() {responsefromServer(divElementId, pageErrorMessage);};
     req.open("GET",pageUrl,true);
     req.send(null);
  }

function responsefromServer(divElementId, pageErrorMessage) {
   var output = '';
   if(req.readyState == 4) {
      if(req.status == 200) {
         output = req.responseText;
         document.getElementById(divElementId).innerHTML = output;
         } else {
         document.getElementById(divElementId).innerHTML = pageErrorMessage+"\n"+output;
         }
      }
  }
  
function activeTab(sec, tab, cat) { 
	
	var cargando = '<img src=\"img/cargando.gif\" /> Cargando contenido...';
	var error_cargar = 'Error al cargar el contenido';
	
	if(sec == 'noticias') {
		document.getElementById("tab1").className = "";
		document.getElementById("tab2").className = "";
		document.getElementById("tab3").className = "";
		document.getElementById("tab4").className = "";
		document.getElementById("tab5").className = "";
		document.getElementById("tab"+tab).className = "actualOrden";
		if(tab == 1) {
			callPage('inc/contenido_noticias.php?sec=noticias&zona=1&cat='+cat, 'content', cargando, error_cargar);
		}else if(tab == 2){
			callPage('inc/contenido_noticias.php?sec=noticias&zona=2&cat='+cat, 'content', cargando, error_cargar);
		}else if(tab == 3){
			callPage('inc/contenido_noticias.php?sec=noticias&zona=3&cat='+cat, 'content', cargando, error_cargar);
		}else if(tab == 4){
			callPage('inc/contenido_noticias.php?sec=noticias&zona=4&cat='+cat, 'content', cargando, error_cargar);
		}else
			callPage('inc/contenido_noticias.php?sec=noticias&zona=5&cat='+cat, 'content', cargando, error_cargar);
			
	}else if(sec == 'juegosflash') {
		document.getElementById("tab1").className = "";
		document.getElementById("tab2").className = "";
		document.getElementById("tab3").className = "";
		document.getElementById("tab4").className = "";
		document.getElementById("tab5").className = "";
		document.getElementById("tab"+tab).className = "actualOrden";
		if(tab == 1) {
			callPage('inc/contenido_juegosflash.php?sec=juegosflash&zona=1&cat='+cat, 'content', cargando, error_cargar);
		}else if(tab == 2){
			callPage('inc/contenido_juegosflash.php?sec=juegosflash&zona=2&cat='+cat, 'content', cargando, error_cargar);
		}else if(tab == 3){
			callPage('inc/contenido_juegosflash.php?sec=juegosflash&zona=3&cat='+cat, 'content', cargando, error_cargar);
		}else if(tab == 4){
			callPage('inc/contenido_juegosflash.php?sec=juegosflash&zona=4&cat='+cat, 'content', cargando, error_cargar);
		}else
			callPage('inc/contenido_juegosflash.php?sec=juegosflash&zona=5&cat='+cat, 'content', cargando, error_cargar);
			
	}else if(sec == 'coches') {
		document.getElementById("tab1").className = "";
		document.getElementById("tab2").className = "";
		document.getElementById("tab3").className = "";
		document.getElementById("tab4").className = "";
		document.getElementById("tab5").className = "";
		document.getElementById("tab"+tab).className = "actualOrden";
		if(tab == 1) {
			callPage('inc/contenido_coches.php?sec=coches&zona=1&cat='+cat, 'content', cargando, error_cargar);
		}else if(tab == 2){
			callPage('inc/contenido_coches.php?sec=coches&zona=2&cat='+cat, 'content', cargando, error_cargar);
		}else if(tab == 3){
			callPage('inc/contenido_coches.php?sec=coches&zona=3&cat='+cat, 'content', cargando, error_cargar);
		}else if(tab == 4){
			callPage('inc/contenido_coches.php?sec=coches&zona=4&cat='+cat, 'content', cargando, error_cargar);
		}else
			callPage('inc/contenido_coches.php?sec=coches&zona=5&cat='+cat, 'content', cargando, error_cargar);
	}else if(sec == 'videos') {
		document.getElementById("tab1").className = "";
		document.getElementById("tab2").className = "";
		document.getElementById("tab3").className = "";
		document.getElementById("tab4").className = "";
		document.getElementById("tab5").className = "";
		document.getElementById("tab"+tab).className = "actualOrden";
		if(tab == 1) {
			callPage('inc/contenido_videos.php?sec=videos&zona=1&cat='+cat, 'content', cargando, error_cargar);
		}else if(tab == 2){
			callPage('inc/contenido_videos.php?sec=videos&zona=2&cat='+cat, 'content', cargando, error_cargar);
		}else if(tab == 3){
			callPage('inc/contenido_videos.php?sec=videos&zona=3&cat='+cat, 'content', cargando, error_cargar);
		}else if(tab == 4){
			callPage('inc/contenido_videos.php?sec=videos&zona=4&cat='+cat, 'content', cargando, error_cargar);
		}else
			callPage('inc/contenido_videos.php?sec=videos&zona=5&cat='+cat, 'content', cargando, error_cargar);
	}else if(sec == 'videos_t') {
		document.getElementById("tab1").className = "";
		document.getElementById("tab2").className = "";
		document.getElementById("tab3").className = "";
		document.getElementById("tab4").className = "";
		document.getElementById("tab5").className = "";
		document.getElementById("tab"+tab).className = "actualOrden";
		if(tab == 1) {
			callPage('inc/contenido_videos_t.php?sec=videos_t&zona=1&cat='+cat, 'content', cargando, error_cargar);
		}else if(tab == 2){
			callPage('inc/contenido_videos_t.php?sec=videos_t&zona=2&cat='+cat, 'content', cargando, error_cargar);
		}else if(tab == 3){
			callPage('inc/contenido_videos_t.php?sec=videos_t&zona=3&cat='+cat, 'content', cargando, error_cargar);
		}else if(tab == 4){
			callPage('inc/contenido_videos_t.php?sec=videos_t&zona=4&cat='+cat, 'content', cargando, error_cargar);
		}else
			callPage('inc/contenido_videos_t.php?sec=videos_t&zona=5&cat='+cat, 'content', cargando, error_cargar);
	}
}
/**** FIN Pestañas ****/

function anadir_video_fav(num_video){
	if(num_video==undefined){
		alert("Error: no se ha encontrado el vídeo");
		return;
	}

	$.ajax({
		type: "GET",
		url: "acciones.php",
		data: "accion=anadir_video_fav&num_video="+num_video,
		success: function(msg){
			document.getElementById("fav_video_"+num_video).innerHTML = msg;
		}, 
		error: function(xho){
			document.getElementById("fav_video_"+num_video).innerHTML = "Error:"+xho.responseText;
		}
	});	
}	
function borrar_video_fav(num_video){
	if(num_video==undefined){
		alert("Error: no se ha especificado el vídeo");
		return;
	}

	$.ajax({
		type: "GET",
		url: "acciones.php",
		data: "accion=borrar_video_fav&num_video="+num_video,
		success: function(msg){
			document.getElementById("fav_video_borr_"+num_video).innerHTML = msg;
		}, 
		error: function(xho){
			document.getElementById("fav_video_borr_"+num_video).innerHTML = "Error:"+xho.responseText;
		}
	});	
}
function anadir_video_t_fav(num_video){
	if(num_video==undefined){
		alert("Error: no se ha encontrado el vídeo");
		return;
	}

	$.ajax({
		type: "GET",
		url: "acciones.php",
		data: "accion=anadir_video_t_fav&num_video="+num_video,
		success: function(msg){
			document.getElementById("fav_video_t_"+num_video).innerHTML = msg;
		}, 
		error: function(xho){
			document.getElementById("fav_video_t_"+num_video).innerHTML = "Error:"+xho.responseText;
		}
	});	
}	
function borrar_video_t_fav(num_video){
	if(num_video==undefined){
		alert("Error: no se ha especificado el vídeo");
		return;
	}

	$.ajax({
		type: "GET",
		url: "acciones.php",
		data: "accion=borrar_video_t_fav&num_video="+num_video,
		success: function(msg){
			document.getElementById("fav_video_t_borr_"+num_video).innerHTML = msg;
		}, 
		error: function(xho){
			document.getElementById("fav_video_t_borr_"+num_video).innerHTML = "Error:"+xho.responseText;
		}
	});	
}
/*
function info_anunciante(este, mostrar) {
	var elem = document.getElementById(mostrar);
	if(elem.style.display == 'block') {
		elem.style.display = 'none'
		este.innerHTML = 'Mostrar información de contacto ';
	} else {
		elem.style.display = 'block';
		este.innerHTML = 'Ocultar información de contacto ';
	}
	
	return false;
}*/
