function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null) 	{document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];} 
}

function cambiar_comentadas_valoradas(id){
 	if(id == "noticias_mas_valoradas"){
	 	document.getElementById(id).style.display="";
		document.getElementById("noticias_mas_comentadas").style.display="none";
		document.images["valorada"].src = "/templates/default/css/images/mas_valorados.jpg";
		document.images["comentada"].src = "/templates/default/css/images/mas_comentados.gif";
	}else{
		document.getElementById(id).style.display="";
		document.getElementById("noticias_mas_valoradas").style.display="none";	
		document.images["comentada"].src = "/templates/default/css/images/mas_comentados_hover.gif";
		document.images["valorada"].src = "/templates/default/css/images/mas_valorados.gif";
	}
}

function new_captcha(){
	if(document.getElementById){
		// extract image name from image source (i.e. cut off ?randomness)
		thesrc = document.getElementById("captcha").src;

		// add ?(random) to prevent browser/isp caching
		document.getElementById("captcha").src = thesrc+"&"+Math.round(Math.random()*100000);
	}//fin if
}//fin function

function mostrar_listado(id){
	document.getElementById(id).style.display="";
}

function ocultar_listado(id){
	document.getElementById(id).style.display="none";
}

function mostrar_noticias(action){
	if(action == "mostrar"){
		document.getElementById("list_news").style.display="";
		document.getElementById("list_news_separador").style.display="none";
	}else{
		document.getElementById("list_news").style.display="none";
		document.getElementById("list_news_separador").style.display="";
	}
    
}

function mostrar_articulos(action){
	if(action == "mostrar"){
		document.getElementById("list_articles").style.display="";
		document.getElementById("list_articles_separador").style.display="none";
	}else{
		document.getElementById("list_articles").style.display="none";
		document.getElementById("list_articles_separador").style.display="";
	}
    
}

function mostrar_codigos(action){
	if(action == "mostrar"){
		document.getElementById("list_codes").style.display="";
		document.getElementById("list_codes_separador").style.display="none";
	}else{
		document.getElementById("list_codes").style.display="none";
		document.getElementById("list_codes_separador").style.display="";
	}
    
}

function ver_redes_sociales(){
 	if (document.getElementById('redes_sociales').style.display == "none"){
		document.getElementById('redes_sociales').style.display = "";
		document.getElementById('email_amigo').style.display = "none";
	}else{
		document.getElementById('redes_sociales').style.display = "none";
	}
}

function ver_recomendar(){
 	if (document.getElementById('email_amigo').style.display == "none"){
		document.getElementById('email_amigo').style.display = ""; 
		document.getElementById('redes_sociales').style.display = "none";
	}else{
		document.getElementById('email_amigo').style.display = "none";
	}
}

function solapas(action,id){
	if(document.getElementById("solapa_1")){
		document.getElementById("solapa_1").style.display="";
		document.getElementById("solapa_over_1").style.display="none";
		document.getElementById("menu_solapa_1").style.display="none";
	}
	if(document.getElementById("solapa_2")){
		document.getElementById("solapa_2").style.display="";
		document.getElementById("solapa_over_2").style.display="none";
		document.getElementById("menu_solapa_2").style.display="none";
	}
	if(document.getElementById("solapa_3")){
		document.getElementById("solapa_3").style.display="";
		document.getElementById("solapa_over_3").style.display="none";
		document.getElementById("menu_solapa_3").style.display="none";
	}
	if(document.getElementById("solapa_4")){
		document.getElementById("solapa_4").style.display="";
		document.getElementById("solapa_over_4").style.display="none";
		document.getElementById("menu_solapa_4").style.display="none";
	}
	if(document.getElementById("solapa_5")){
		document.getElementById("solapa_5").style.display="";
		document.getElementById("solapa_over_5").style.display="none";
		document.getElementById("menu_solapa_5").style.display="none";
	}
	if(action == "mostrar"){
		document.getElementById("solapa_"+id).style.display="none";
		document.getElementById("solapa_over_"+id).style.display="";
		document.getElementById("menu_solapa_"+id).style.display="";
	}	
}

function add_cat(id, name){
 	document.getElementById('cuantos_llevas').innerHTML = "<div id='proglang'><b>- PHP</b></div>";
}

function anadir_categoria(id, nombre){
 	contador = parseInt(document.getElementById("contadorcat").value);
 	if (contador <= 3){
 	 	if (!document.getElementById("categories-"+id)){
		 	var d = document.getElementById("cuantos_llevas"); 
		 	if(id){
				d.style.display = "";
			}
			d.innerHTML += "<div id='categories-"+id+"'><img src='/templates/default/imgs/delete.gif' align='absmiddle' style='cursor:hand;cursor:pointer;' onclick='eliminar_categoria("+id+")' border='0'> "+nombre+"<input type='hidden' name='category[category_"+id+"]' value='"+id+"'></div>";
			contador = parseInt(document.getElementById("contadorcat").value);
			newcontador = contador + 1;
			document.getElementById("contadorcat").value = newcontador;
			cerrar();
		}
	}else{
		alert("Has superado el límite de categorias");
	}
}

function eliminar_categoria(id){
	if (document.getElementById("categories-"+id)){
	 	var d = document.getElementById("cuantos_llevas"); 
		var d_nested = document.getElementById("categories-"+id); 
		var throwawayNode = d.removeChild(d_nested);
		contador = parseInt(document.getElementById("contadorcat").value);
		newcontador = contador - 1;
		document.getElementById("contadorcat").value = newcontador;
		if (newcontador == 1){
			d.style.display = "none";
		}
	}
}


function handleHttpResponse_votarnoticia() {
	if (http.readyState == 4) {
		if (http.responseText.indexOf('invalid') == -1) {
			var response = http.responseXML;
			document.getElementById('numvotos').innerHTML = response.getElementsByTagName('votes').item(0).firstChild.data;
			document.getElementById('botonvotar').innerHTML = '<div style="-moz-border-radius:5px 5px 5px 5px;background:none repeat scroll 0 0 #A84A40;color:#FFFFFF;padding:4px;margin-top:4px;font-size:10px;width:40px;">gracias</div>';
			isWorking = false;
		}
	}
}

var isWorking = false;
function votar_noticia(id, ip){
 	var ieVer = /*
				 * @cc_on function(){ switch(@_jscript_version){ case 1.0:return
				 * 3; case 3.0:return 4; case 5.0:return 5; case 5.1:return 5;
				 * case 5.5:return 5.5; case 5.6:return 6; case 5.7:return 7;
				 * case 5.8:return 8; }}()||@
				 */0;
	if (ieVer > 0 && ieVer <= 6) {
		http = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		http = new XMLHttpRequest();
	}
	if (!id){
		alert("Ha habido un problema al votar, disculpe las molestias");
	}else{
		var url = "/ajax/votar_noticia.php?id="+id+"&ip="+ip;
		http.open("GET", url, true);
		http.onreadystatechange = handleHttpResponse_votarnoticia;
		isWorking = true;
		http.send(null);
	}
}


function handleHttpResponse_votararticulo() {
	if (http.readyState == 4) {
		if (http.responseText.indexOf('invalid') == -1) {
			var response = http.responseXML;
			document.getElementById('numvotos').innerHTML = response.getElementsByTagName('votes').item(0).firstChild.data;
			document.getElementById('botonvotar').innerHTML = '<div style="-moz-border-radius:5px 5px 5px 5px;background:none repeat scroll 0 0 #A84A40;color:#FFFFFF;padding:4px;margin-top:4px;font-size:10px;width:40px;">gracias</div>';
			isWorking = false;
		}
	}
}

var isWorking = false;
function votar_articulo(id, ip){
 	var ieVer = /*
				 * @cc_on function(){ switch(@_jscript_version){ case 1.0:return
				 * 3; case 3.0:return 4; case 5.0:return 5; case 5.1:return 5;
				 * case 5.5:return 5.5; case 5.6:return 6; case 5.7:return 7;
				 * case 5.8:return 8; }}()||@
				 */0;
	if (ieVer > 0 && ieVer <= 6) {
		http = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		http = new XMLHttpRequest();
	}
	if (!id){
		alert("Ha habido un problema al votar, disculpe las molestias");
	}else{
		var url = "/ajax/votar_articulo.php?id="+id+"&ip="+ip;
		http.open("GET", url, true);
		http.onreadystatechange = handleHttpResponse_votararticulo;
		isWorking = true;
		http.send(null);
	}
}


function handleHttpResponse_votarcodigo() {
	if (http.readyState == 4) {
		if (http.responseText.indexOf('invalid') == -1) {
			var response = http.responseXML;
			document.getElementById('numvotos').innerHTML = response.getElementsByTagName('votes').item(0).firstChild.data;
			document.getElementById('botonvotar').innerHTML = '<div style="-moz-border-radius:5px 5px 5px 5px;background:none repeat scroll 0 0 #A84A40;color:#FFFFFF;padding:4px;margin-top:4px;font-size:10px;width:40px;">gracias</div>';
			isWorking = false;
		}
	}
}

var isWorking = false;
function votar_codigo(id, ip){
 	var ieVer = /*
				 * @cc_on function(){ switch(@_jscript_version){ case 1.0:return
				 * 3; case 3.0:return 4; case 5.0:return 5; case 5.1:return 5;
				 * case 5.5:return 5.5; case 5.6:return 6; case 5.7:return 7;
				 * case 5.8:return 8; }}()||@
				 */0;
	if (ieVer > 0 && ieVer <= 6) {
		http = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		http = new XMLHttpRequest();
	}
	if (!id){
		alert("Ha habido un problema al votar, disculpe las molestias");
	}else{
		var url = "/ajax/votar_codigo.php?id="+id+"&ip="+ip;
		http.open("GET", url, true);
		http.onreadystatechange = handleHttpResponse_votarcodigo;
		isWorking = true;
		http.send(null);
	}
}
