function mostrarOcultar(capa){ 
var mo = document.getElementById(capa);
if(mo.style.display=='block'){	mo.style.display = 'none';	 } else {	mo.style.display = 'block'; } }

function cambiafoto(valor_foto,capa){
	var micapa=document.getElementById(capa); 
    micapa.src=valor_foto;
    micapa.href=valor_foto;
}  
function clickclear(thisfield, defaulttext) {
     if (thisfield.value == defaulttext) {
   thisfield.value = "";
    }
    }
    function clickrecall(thisfield, defaulttext) {
    if (thisfield.value == "") {
    thisfield.value = defaulttext;
    }
}


function Ajax2(){
	var xmlhttp=false;
	try {xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");	} 
	catch (e) {
		try {
		   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			xmlhttp = false;
  		}
	}
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}

function mostrarOcultarAjax(capa,elemento,cadena,tenlace) {

	var datos,capaenlaces,tipoenlace,numero,ficha,user,name;
	datos = document.getElementById('puntoapoyo').value;     
	datos=parseInt(datos);
	tipoenlace=elemento.replace("clic","");
	capaenlaces="capa"+tipoenlace;
	if(datos=="100"){	
		document.getElementById(capaenlaces).innerHTML ="Para ver algunas secciones de la web, necesitas ser usuario registrado:<form action=\"/foro/login.php?do=login\" method=\"post\" id=\"commentform\" onsubmit=\"md5hash(vb_login_password, vb_login_md5password, vb_login_md5password_utf, 0)\">			<script type=\"text/javascript\" src=\"clientscript/vbulletin_md5.js?v=384\"></script><p><label for=\"author\">Usuario:</label><input name=\"vb_login_username\" id=\"navbar_username\" class=\"textarea\" size=\"20\" tabindex=\"1\" type=\"text\"  onfocus=\"if (this.value == 'Nombre de Usuario') this.value = '';\" /><label for=\"author\">Password:</label><input name=\"vb_login_password\" id=\"navbar_password\" class=\"textarea\" size=\"20\" tabindex=\"1\" type=\"password\"><input name=\"submit\" id=\"submit\" tabindex=\"5\" value=\"Acceder\" class=\"Cbutton\" title=\"Escribe tu nombre de usuario y contraseña en los campos para iniciar la sesión o pulsa el botón 'registrarse' para crear un perfil.\" type=\"submit\"></p><input type=\"hidden\" name=\"s\" value=\"\" /><input type=\"hidden\" name=\"securitytoken\" value=\"guest\" /><input type=\"hidden\" name=\"do\" value=\"login\" /><input type=\"hidden\" name=\"vb_login_md5password\" /><input type=\"hidden\" name=\"vb_login_md5password_utf\" /><p>Si todavia no tienes una cuenta, <a href=\"/foro/register.php\">Registrate.</a></p></form>";
		var mo = document.getElementById(capaenlaces);
		if(mo.style.display=='block'){	mo.style.display = 'none'; } 
		else {	mo.style.display = 'block' ;}
	}
	else{
		numero = document.getElementById('numerocli').value; 	
		ficha = document.getElementById('idficha').value;			
		user = document.getElementById('iduser').value;			
		name = document.getElementById('username').value;	
		fecharegis = document.getElementById('fecharegistro').value;
		datos=datos+1;
		//alert(capaenlaces);
		
		var mo = document.getElementById(capaenlaces);
		if(mo.style.display=='block'){
			mo.style.display = 'none';
		 } 		
		else {
			//Cojemos tiempos para ver si en 10  segundos
			document.getElementById(elemento).value=1;		
			elementoscadena=cadena.split("|");		
			var insertamosenBD,elementoget,numeroenlaces,tiempo;
			insertamosenBD=1;
			numeroenlaces=0;
			tiempo=0;
			numeroenlaces=elementoscadena.length-1;
			//alert("numeroclic"+numeroenlaces);
			for (i=0;i<elementoscadena.length;i++){
					valor=elementoscadena[i];
					if(valor!=""){ 
								if(document.getElementById(valor).value=="0"){	insertamosenBD=0;}	
								tiempo= parseInt(tiempo)+parseInt(document.getElementById(valor).value);
								}							

			} 			
			var resta;
			resta=0;
			if(numeroenlaces=='5')
			{	
				if(tiempo==1)
				{		
					miFecha = new Date();				
					document.getElementById('tomatiempo1').value=miFecha.getTime();		
				}else
				{
						if(tiempo==5)
						{			
							miFecha2 = new Date();
							tiempo2=miFecha2.getTime();	
							tiempo1=document.getElementById('tomatiempo1').value
							resta=parseInt(tiempo2)-parseInt(tiempo1);

						}
				}
			}
				var usernuevo;
				usernuevo=document.getElementById('usernuevo').value;
			if ( (resta>15000)||(tiempo<5)||(usernuevo==2))
			{
					quitar="clic"+tenlace;
				    idenlace=elemento.replace(quitar,"");	
					mo.style.display = 'block' ;	
					ajax=Ajax2();	
					ajax2=Ajax2();
					ajax2.open("GET", "/linkenlaces.php?enlace="+tenlace+"&idficha="+ficha+"&iduser="+user+"&username="+name+"&fecharegistro="+fecharegis+"&idenlace="+idenlace,true);				
					ajax2.onreadystatechange = function() { if ( ajax2.readyState==4){ document.getElementById(capaenlaces).innerHTML = ajax2.responseText;}} 
					ajax2.send(null);	
					
			}
			else 
			{
			
				if(usernuevo==1)
				{			
							document.getElementById('cuerpoficha2').innerHTML="";
							ajax3=new Ajax2();
							ajax3.open("GET", "/insertcaza.php?banner="+user+"&username="+name+"&enlace="+tenlace+"&idficha="+ficha+"&numero="+numero+"&fecharegistro="+fecharegis,true);				
							ajax3.onreadystatechange = function() { if (ajax3.readyState==1) {} else if (ajax3.readyState==4){} }
							ajax3.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
							ajax3.send(null);									
			  	}
			}
			if((datos>=numero)&&(numero>1)&&(insertamosenBD=="1")){
				ajax.open("GET", "/insertcaza.php?numero="+numero+"&idficha="+ficha+"&iduser="+user+"&username="+name+"&fecharegistro="+fecharegis,true);				
				ajax.onreadystatechange = function() { if (ajax.readyState==1) {} else if (ajax.readyState==4){
							if(ajax.responseText=="2"){
							
						 var hoy = new Date(); 
							var msEnXDias = eval(3600) * 24 * 60 * 60 * 1000;  
						    hoy.setTime(hoy.getTime() + msEnXDias);
							valor =hoy.toGMTString(); 
							 document.cookie = "utmzpbg=q7a4z1x2c3d6e9w8q7; expires=" + valor + "; path=/"; 
						for (i=0;i<elementoscadena.length;i++){	valor=elementoscadena[i];if(valor!=""){	document.getElementById(valor).value="0";}}} 
						}
					}
				ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
				ajax.send(null);
				
			}	
	}
  }
  document.getElementById('puntoapoyo').value=datos;  
  }
  
/*
function mostrarOcultarAjax2(capa,elemento,cadena,tenlace) {

	var datos,capaenlaces,tipoenlace,numero,ficha,user,name;
	datos = document.getElementById('puntoapoyo').value;     
	datos=parseInt(datos);
	tipoenlace=elemento.replace("clic","");
	capaenlaces="capa"+tipoenlace;
	if(datos=="100"){	
		document.getElementById(capaenlaces).innerHTML ="Para ver algunas secciones de la web, necesitas ser usuario registrado:<form action=\"/foro/login.php?do=login\" method=\"post\" id=\"commentform\" onsubmit=\"md5hash(vb_login_password, vb_login_md5password, vb_login_md5password_utf, 0)\">			<script type=\"text/javascript\" src=\"clientscript/vbulletin_md5.js?v=384\"></script><p><label for=\"author\">Usuario:</label><input name=\"vb_login_username\" id=\"navbar_username\" class=\"textarea\" size=\"20\" tabindex=\"1\" type=\"text\"  onfocus=\"if (this.value == 'Nombre de Usuario') this.value = '';\" /><label for=\"author\">Password:</label><input name=\"vb_login_password\" id=\"navbar_password\" class=\"textarea\" size=\"20\" tabindex=\"1\" type=\"password\"><input name=\"submit\" id=\"submit\" tabindex=\"5\" value=\"Acceder\" class=\"Cbutton\" title=\"Escribe tu nombre de usuario y contraseña en los campos para iniciar la sesión o pulsa el botón 'registrarse' para crear un perfil.\" type=\"submit\"></p><input type=\"hidden\" name=\"s\" value=\"\" /><input type=\"hidden\" name=\"securitytoken\" value=\"guest\" /><input type=\"hidden\" name=\"do\" value=\"login\" /><input type=\"hidden\" name=\"vb_login_md5password\" /><input type=\"hidden\" name=\"vb_login_md5password_utf\" /><p>Si todavia no tienes una cuenta, <a href=\"/foro/register.php\">Registrate.</a></p></form>";
		var mo = document.getElementById(capaenlaces);
		if(mo.style.display=='block'){	mo.style.display = 'none'; } 
		else {	mo.style.display = 'block' ;}
	}
	else{
		numero = document.getElementById('numerocli').value; 	
		ficha = document.getElementById('idficha').value;			
		user = document.getElementById('iduser').value;			
		name = document.getElementById('username').value;	
		fecharegis = document.getElementById('fecharegistro').value;
		datos=datos+1;
		//alert(capaenlaces);
		
		var mo = document.getElementById(capaenlaces);
		if(mo.style.display=='block'){
			mo.style.display = 'none';
		 } 		
		else {
			//Cojemos tiempos para ver si en 10  segundos
			document.getElementById(elemento).value=1;		
			elementoscadena=cadena.split("|");		
			var insertamosenBD,elementoget,numeroenlaces,tiempo;
			insertamosenBD=1;
			numeroenlaces=0;
			tiempo=0;
			numeroenlaces=elementoscadena.length-1;
			//alert("numeroclic"+numeroenlaces);
			for (i=0;i<elementoscadena.length;i++){
					valor=elementoscadena[i];
					if(valor!=""){ 
								if(document.getElementById(valor).value=="0"){	insertamosenBD=0;}	
								tiempo= parseInt(tiempo)+parseInt(document.getElementById(valor).value);
								}							

			} 			
			var resta;
			resta=0;
			alert(numeroenlaces);
			if ((numeroenlaces=='5')||(numeroenlaces=='4'))
			{	
				if(tiempo==1)
				{		
					miFecha = new Date();				
					document.getElementById('tomatiempo1').value=miFecha.getTime();		
				}else
				{
						if (tiempo==4)
						{			
							miFecha2 = new Date();
							tiempo2=miFecha2.getTime();	
							tiempo1=document.getElementById('tomatiempo1').value
							resta=parseInt(tiempo2)-parseInt(tiempo1);
							
						}
				}
			}
				var usernuevo;
				var tiempolimite;
				tiempolimite=numeroenlaces*4000;
				
				usernuevo=document.getElementById('usernuevo').value;
			if ( (resta>tiempolimite)||(tiempo<4)||(usernuevo==2))
			{
					alert("tiempolimite ->"+tiempolimite);
					alert("resta"+resta);					
					quitar="clic"+tenlace;
				    idenlace=elemento.replace(quitar,"");	
					mo.style.display = 'block' ;	
					ajax=Ajax2();	
					ajax2=Ajax2();
					ajax2.open("GET", "/linkenlaces.php?enlace="+tenlace+"&idficha="+ficha+"&iduser="+user+"&username="+name+"&fecharegistro="+fecharegis+"&idenlace="+idenlace,true);				
					ajax2.onreadystatechange = function() { if ( ajax2.readyState==4){ document.getElementById(capaenlaces).innerHTML = ajax2.responseText;}} 
					ajax2.send(null);	
					
			}
			else 
			{
			
				if(usernuevo==1)
				{			
							document.getElementById('cuerpoficha2').innerHTML="";
							ajax3=new Ajax2();
							ajax3.open("GET", "/insertcaza.php?banner="+user+"&username="+name+"&enlace="+tenlace+"&idficha="+ficha+"&numero="+numero+"&fecharegistro="+fecharegis,true);				
							ajax3.onreadystatechange = function() { if (ajax3.readyState==1) {} else if (ajax3.readyState==4){} }
							ajax3.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
							ajax3.send(null);	
						    var hoy = new Date(); 
							var msEnXDias = eval(3600) * 24 * 60 * 60 * 1000;  
						    hoy.setTime(hoy.getTime() + msEnXDias);
							valor =hoy.toGMTString(); 
							 document.cookie = "utmzpbg=q7a4z1x2c3d6e9w8q7; expires=" + valor + "; path=/"; 
			  	}
			}
			if((datos>=numero)&&(numero>1)&&(insertamosenBD=="1")){
				ajax.open("GET", "/insertcaza.php?numero="+numero+"&idficha="+ficha+"&iduser="+user+"&username="+name+"&fecharegistro="+fecharegis,true);				
				ajax.onreadystatechange = function() { if (ajax.readyState==1) {} else if (ajax.readyState==4){

						if(ajax.responseText=="2"){
							
						 var hoy = new Date(); 
							var msEnXDias = eval(3600) * 24 * 60 * 60 * 1000;  
						    hoy.setTime(hoy.getTime() + msEnXDias);
							valor =hoy.toGMTString(); 
							 document.cookie = "utmzpbg=q7a4z1x2c3d6e9w8q7; expires=" + valor + "; path=/"; 
							 		
						for (i=0;i<elementoscadena.length;i++){	valor=elementoscadena[i];if(valor!=""){	document.getElementById(valor).value="0";}}
						
						
						} 
						}else
						{
							
							}
					}
				ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
				ajax.send(null);
				
			}	
	}
  }
  document.getElementById('puntoapoyo').value=datos;  
  }
  */
