var precioOok=0.50;
var tiempoProductos= new Object();
var restanteProductos= new Object();
var tipoPujarArray=new Array("Puja a 1 c&eacute;ntimo","Puja a 10 c&eacute;ntimos","Puja a precio fijo","Puja Gratuita");
var tipoPrecioPujarArray=new Array("0.01","0.10","0.01","0.01");
var tipoPujarLogoArray=new Array("centimo.gif","normal.gif","normal.gif","gratis.gif");


function comprobador(producto){
			var usuario="desconectado";
			$.ajax({
				type: "POST",
				url: "/php/infoProductosbis.php",
				data: "producto="+producto,
				dataType: "xml",
				beforeSend: function(){
				},
				complete: function(){
					
					var arrayP=producto.split(";"); 
					for (i=0;i<arrayP.length;i++){
						prodAhora=arrayP[i];
						var segundosRestantes=visibleSegundos($("#"+prodAhora+"_tiempo").html());
						if(segundosRestantes<=1){
							compruebaFinalizada(prodAhora, usuario, 0);
						}	
					}
					
					if(tiempoProductos["productoHome"] == null || tiempoProductos["productoHome"]=='[object]'){
						tiempoProductos["productoHome"]=setInterval(function(){restarTiempoB(producto);}, 1000);
					}else{
						window.clearInterval(tiempoProductos["productoHome"]); 
						tiempoProductos["productoHome"]=setInterval(function(){restarTiempoB(producto);}, 1000);	
					}
					
					restanteProductos["productoHome"]=setTimeout(function(){comprobadorPers(producto);}, 5000);
					
				},
				success: function(xml) {
					
					usuario=$(xml).find('usuarioOnline').text();
					$(xml).find('producto').each(function(){
						var error=$(this).find('error').text();
						var logo=$(this).find('logo').text();
						var nombre=$(this).find('nombre').text();
						var nombrePermalink=$(this).find('nombrePermalink').text();
						var codigoPuja=$(this).find('codigoPuja').text();
						var precioRecomendado=$(this).find('precioRecomendado').text();
						var descripcion=$(this).find('descripcion').text();
						var foto=$(this).find('foto').text();
						var fotoG=$(this).find('fotoG').text();
						var tipoPuja=$(this).find('tipopuja').text();
						var tiempo=$(this).find('tiempo').text();
						var precio=$(this).find('precio').text();
						var precioFijo=$(this).find('precioFijo').text();
						var pujante=$(this).find('pujante').text();
						var horaActual=$(this).find('horaActual').text();
						tiempo = normalizarFecha(tiempo);
						var fecha_Array=tiempo.split(";");
						var ano_fin=fecha_Array[0];
						var mes_fin=fecha_Array[1];
						var dia_fin=fecha_Array[2];
						var hora_fin=fecha_Array[3];
						var minuto_fin=fecha_Array[4];
						var segundo_fin=fecha_Array[5];
						var tiempo_fin = mktime(hora_fin, minuto_fin, segundo_fin, mes_fin, dia_fin, ano_fin);
						var mydate = new Date(horaActual); 
						var tiempo_ahora = mydate.getTime()/1000; 
						tiempo_ahora = Math.ceil(tiempo_ahora); 
						tiempo=tiempo_fin-tiempo_ahora;
						if(tiempo>10){$("#"+codigoPuja+"_tiempo").css("color","black");}else{$("#"+codigoPuja+"_tiempo").css("color","red");}
						if(tiempo<1){tiempo=0;}
						tiempo = segundosVisible(tiempo);
						$("#"+codigoPuja+"_logoPuja").html("<img src='/logos/pujas/"+tipoPujarLogoArray[tipoPuja]+"' alt='Tipo de puja' />");
						$("#"+codigoPuja+"_tipoPuja").html(tipoPujarArray[tipoPuja]);
						$("#"+codigoPuja+"_logo").html("<img src='/logos/productos/"+logo+"' alt='"+nombre+" "+logo+"'/>");
						$("#"+codigoPuja+"_descripcion").html(descripcion);
						$("#"+codigoPuja+"_tiempo").html(tiempo);
						$("#"+codigoPuja+"_precio").html(normalizarPrecio(precio));
						$("#"+codigoPuja+"_pujante").html(pujante);
						
						
						if(tipoPuja==3){
							$("#"+codigoPuja+"_inf").css('background-image','url(/img/casilla_inferior2.gif)');
							$("#"+codigoPuja+"_puja").css('background-image','url(/img/casilla_puja_rojo2.gif)'); 
							$("#"+codigoPuja+"_superiorPujas").css('background-image','url(/img/casilla_superior2.gif)'); 
							$("#"+codigoPuja+"_puja").html("<a title='Pujar' href='javascript:hacerPuja4(&#34;"+nombrePermalink+"&#34;,&#34;"+codigoPuja+"&#34;,&#34;"+usuario+"&#34;,&#34;"+precioRecomendado+"&#34;)'>Pujar</a>");
							$("#"+codigoPuja+"_nombreDiv").html("<a href='/productosGratuitos/"+nombrePermalink+"/"+codigoPuja+"' id="+codigoPuja+"_nombre title ='"+nombre+"'></a>");
							$("#"+codigoPuja+"_nombre").html(nombre);
							$("#"+codigoPuja+"_fotoDiv").html("<a href='/productosGratuitos/"+nombrePermalink+"/"+codigoPuja+"' id="+codigoPuja+"_foto title ='"+nombre+"'></a>");
							$("#"+codigoPuja+"_foto").html("<img border=0 src='/fotos/productos/"+foto+"' alt='"+nombre+"'/>");
							$("#"+codigoPuja+"_fotoDivG").html("<div class='foto2' style='background-image:url(/fotos/productos/"+fotoG+")' ><a href='/productosGratuitos/"+nombrePermalink+"/"+codigoPuja+"' title ='"+nombre+"'><img border=0 src='../img/fondo_taparFoto.png' /></a></div>");
						}else{
							$("#"+codigoPuja+"_puja").html("<a title='Pujar' href='javascript:hacerPuja3(&#34;"+nombrePermalink+"&#34;,&#34;"+codigoPuja+"&#34;,&#34;"+usuario+"&#34;,&#34;"+precioRecomendado+"&#34;)'>Pujar</a>");
							$("#"+codigoPuja+"_nombreDiv").html("<a href='/productos/"+nombrePermalink+"/"+codigoPuja+"' id="+codigoPuja+"_nombre title ='"+nombre+"'></a>");
							$("#"+codigoPuja+"_nombre").html(nombre);
							$("#"+codigoPuja+"_fotoDiv").html("<a href='/productos/"+nombrePermalink+"/"+codigoPuja+"' id="+codigoPuja+"_foto title ='"+nombre+"'></a>");
							$("#"+codigoPuja+"_foto").html("<img border=0 src='/fotos/productos/"+foto+"' alt='"+nombre+"'/>");
							$("#"+codigoPuja+"_fotoDivG").html("<div class='foto2' style='background-image:url(/fotos/productos/"+fotoG+")' ><a href='/productos/"+nombrePermalink+"/"+codigoPuja+"' title ='"+nombre+"'><img border=0 src='../img/fondo_taparFoto.png' /></a></div>");
						}
						
			
						$(document).pngFix();
						
					});
					
					
				}
			});
}

function comprobadorPers(producto){
			
			var usuario="desconectado";
			$.ajax({
				type: "POST",
				url: "/php/infoProductos2bis.php",
				data: "producto="+producto,
				dataType: "xml",
				beforeSend: function(){
				},
				complete: function(){
					 
					var arrayP=producto.split(";"); 
					for (i=0;i<arrayP.length;i++){
						prodAhora=arrayP[i];
						if($("#"+prodAhora+"_tiempo").html()=="FIN"){
							compruebaFinalizada(prodAhora, usuario, 0);
						}else{
						var segundosRestantes=visibleSegundos($("#"+prodAhora+"_tiempo").html());
						if(segundosRestantes<=1){
							compruebaFinalizada(prodAhora, usuario, 0);
						}
						}
					}
					
					if(tiempoProductos["productoHome"] == null || tiempoProductos["productoHome"]=='[object]'){
						tiempoProductos["productoHome"]=setInterval(function(){restarTiempoB(producto);}, 1000);
					}else{
						window.clearInterval(tiempoProductos["productoHome"]); 
						tiempoProductos["productoHome"]=setInterval(function(){restarTiempoB(producto);}, 1000);	
					}
					
					restanteProductos["productoHome"]=setTimeout(function(){comprobadorPers(producto);}, 5000);
				},
				success: function(xml) {
					
					usuario=$(xml).find('usuarioOnline').text();
					$(xml).find('producto').each(function(){
						var error=$(this).find('error').text();
						var nombrePermalink=$(this).find('nombrePermalink').text();
						var codigoPuja=$(this).find('codigoPuja').text();
						var precioRecomendado=$(this).find('precioRecomendado').text();
						var tiempo=$(this).find('tiempo').text();
						var precio=$(this).find('precio').text();
						var precioFijo=$(this).find('precioFijo').text();
						var pujante=$(this).find('pujante').text();
						var tipoPuja=$(this).find('tipopuja').text();
						var horaActual=$(this).find('horaActual').text();
						tiempo = normalizarFecha(tiempo);
						var fecha_Array=tiempo.split(";");
						var ano_fin=fecha_Array[0];
						var mes_fin=fecha_Array[1];
						var dia_fin=fecha_Array[2];
						var hora_fin=fecha_Array[3];
						var minuto_fin=fecha_Array[4];
						var segundo_fin=fecha_Array[5];
						var tiempo_fin = mktime(hora_fin, minuto_fin, segundo_fin, mes_fin, dia_fin, ano_fin);
						var mydate = new Date(horaActual); 
						var tiempo_ahora = mydate.getTime()/1000; 
						tiempo_ahora = Math.ceil(tiempo_ahora); 
						tiempo=tiempo_fin-tiempo_ahora;
						if(tiempo>10){$("#"+codigoPuja+"_tiempo").css("color","black");}else{$("#"+codigoPuja+"_tiempo").css("color","red");}
						if(tiempo<1){tiempo=0;}
						tiempo = segundosVisible(tiempo);
						var tiempoAhora = $("#"+codigoPuja+"_tiempo").html();
						if(tiempoAhora=="FIN"){}else{
							$("#"+codigoPuja+"_tiempo").html(tiempo);
						}
						
						//BRILLO INICIO
						if(desnormalizarPrecio($("#"+codigoPuja+"_precio").html())!=normalizarPrecioSinEuro(precio)){
							//alert("W");	
							$("#"+codigoPuja+"_precio").animate( { backgroundColor: 'red' }, 200).animate( { backgroundColor: 'white' }, 500);
						}
						//FIN BRILLO
						//alert(nombrePermalink);
						if(tiempoAhora=="FIN"){}else{
							
						
						$("#"+codigoPuja+"_precio").html(normalizarPrecio(precio));
						$("#"+codigoPuja+"_pujante").html(pujante);
						
						if(tipoPuja==3){
							$("#"+codigoPuja+"_puja").html("<a title='Pujar' href='javascript:hacerPuja4(&#34;"+nombrePermalink+"&#34;,&#34;"+codigoPuja+"&#34;,&#34;"+usuario+"&#34;,&#34;"+precioRecomendado+"&#34;)'>Pujar</a>");
						}else{
							$("#"+codigoPuja+"_puja").html("<a title='Pujar' href='javascript:hacerPuja3(&#34;"+nombrePermalink+"&#34;,&#34;"+codigoPuja+"&#34;,&#34;"+usuario+"&#34;,&#34;"+precioRecomendado+"&#34;)'>Pujar</a>");
						}
						}
						
					});
					
					
				}
			});
}


function comprobadorIndividual(producto, usuario){
			$.ajax({
				type: "POST",
				url: "/php/infoProductosindv.php",
				data: "producto="+producto,
				dataType: "xml",
				beforeSend: function(){
				},
				complete: function(){
					var segundosRestantes=visibleSegundos($("#"+producto+"_tiempo").html());
					if(segundosRestantes<=0){
						window.clearInterval(tiempoProductos[producto]); 
						compruebaFinalizada(producto, usuario, 1);
						//$("#"+producto+"_tiempo").html("FIN");
						//$("#"+producto+"_puja").html("<a href='#'>FIN</a>");
						}else{
					if(tiempoProductos[producto] == null || tiempoProductos[producto]=='[object]'){
						tiempoProductos[producto]=setInterval(function(){restarTiempo(producto, usuario, 1);}, 1000);
					}else{
						window.clearInterval(tiempoProductos[producto]); 
						tiempoProductos[producto]=setInterval(function(){restarTiempo(producto, usuario, 1);}, 1000);
					}
					}
					if(segundosRestantes>1800){
						restanteProductos[producto]=setTimeout(function(){comprobadorPersIndividual(producto, usuario);}, 60000);
					}else if(segundosRestantes<=1800 && segundosRestantes>60){
						restanteProductos[producto]=setTimeout(function(){comprobadorPersIndividual(producto, usuario);}, 30000);
					}else if(segundosRestantes<=60 && segundosRestantes>10){
						restanteProductos[producto]=setTimeout(function(){comprobadorPersIndividual(producto, usuario);}, 10000);
					}else if(segundosRestantes<=10 && segundosRestantes>1){
						restanteProductos[producto]=setTimeout(function(){comprobadorPersIndividual(producto, usuario);}, 5000);
					}
					
				},
				success: function(xml) {
					var error=$(xml).find('producto').find('error').text();
					if(error=="si"){
						window.location="/resultados.php";
					}else{
					var ookbotId=$(xml).find('producto').find('ookbotId').text();
					var ookbotPrecioMinimo=$(xml).find('producto').find('ookbotPrecioMinimo').text();
					var ookbotPrecioMaximo=$(xml).find('producto').find('ookbotPrecioMaximo').text();
					var ookbotTotalPujas=$(xml).find('producto').find('ookbotTotalPujas').text();
					var ookbotId_Array=ookbotId.split(";");
					var ookbotPrecioMinimo_Array=ookbotPrecioMinimo.split(";");
					var ookbotPrecioMaximo_Array=ookbotPrecioMaximo.split(";");
					var ookbotTotalPujas_Array=ookbotTotalPujas.split(";");
					var ookbotsTexto="";
					if(ookbotTotalPujas_Array.length>1){
						for(a=0;a<ookbotTotalPujas_Array.length-1;a++){
							ookbotsTexto=ookbotsTexto+"<div class='ookbot2'><div class='espacio'></div><div class='separacion'></div><div class='texto'>Quedan "+ookbotTotalPujas_Array[a]+" Ooks</div><div class='separacion'></div><div class='texto2'>"+normalizarPrecio(ookbotPrecioMinimo_Array[a])+"</div><div class='separacion'></div><div class='texto2'>"+normalizarPrecio(ookbotPrecioMaximo_Array[a])+"</div><div class='separacion'></div><div class='texto3'><a href='javascript:eliminarOokbot(&#34;"+ookbotId_Array[a]+"&#34;,&#34;"+producto+"&#34;,&#34;"+usuario+"&#34;)'>[eliminar]</a></div></div>";
						}
					}
					var logo=$(xml).find('producto').find('logo').text();
					var nombre=$(xml).find('producto').find('nombre').text();
					var nombrePermalink=$(xml).find('producto').find('nombrePermalink').text();
					var codigoPuja=$(xml).find('producto').find('codigoPuja').text();
					var descripcion=$(xml).find('producto').find('descripcion').text();
					var tipoPuja=$(xml).find('producto').find('tipopuja').text();
					var tiempo=$(xml).find('producto').find('tiempo').text();
					var fechaFinal=$(xml).find('producto').find('fechaFinal').text();
					var precio=$(xml).find('producto').find('precio').text();
					var precioFijo=$(xml).find('producto').find('precioFijo').text();
					var ooksUsuario=$(xml).find('producto').find('ooksUsuario').text();
					var ooksGastados=$(xml).find('producto').find('ooksGastados').text();
					var precioRecomendado=$(xml).find('producto').find('precioRecomendado').text();
					var pujasUsuario1=$(xml).find('producto').find('puja1_usuario').text();
					var pujasPrecio1=normalizarPrecio($(xml).find('producto').find('puja1_precio').text());
					var pujasTipo1=$(xml).find('producto').find('puja1_tipo').text();
					
					var pujasUsuario2=$(xml).find('producto').find('puja2_usuario').text()+"<br>"+$(xml).find('producto').find('puja3_usuario').text()+"<br>"+$(xml).find('producto').find('puja4_usuario').text()+"<br>"+$(xml).find('producto').find('puja5_usuario').text()+"<br>"+$(xml).find('producto').find('puja6_usuario').text()+"<br>"+$(xml).find('producto').find('puja7_usuario').text()+"<br>"+$(xml).find('producto').find('puja8_usuario').text()+"<br>"+$(xml).find('producto').find('puja9_usuario').text()+"<br>"+$(xml).find('producto').find('puja10_usuario').text();
					var pujasPrecio2=normalizarPrecio($(xml).find('producto').find('puja2_precio').text()) +"<br>"+ normalizarPrecio($(xml).find('producto').find('puja3_precio').text())+"<br>"+ normalizarPrecio($(xml).find('producto').find('puja4_precio').text())+"<br>"+ normalizarPrecio($(xml).find('producto').find('puja5_precio').text())+"<br>"+ normalizarPrecio($(xml).find('producto').find('puja6_precio').text())+"<br>"+ normalizarPrecio($(xml).find('producto').find('puja7_precio').text())+"<br>"+ normalizarPrecio($(xml).find('producto').find('puja8_precio').text())+"<br>"+ normalizarPrecio($(xml).find('producto').find('puja9_precio').text())+"<br>"+ normalizarPrecio($(xml).find('producto').find('puja10_precio').text());
					var pujasTipo2=$(xml).find('producto').find('puja2_tipo').text()+"<br>"+$(xml).find('producto').find('puja3_tipo').text()+"<br>"+$(xml).find('producto').find('puja4_tipo').text()+"<br>"+$(xml).find('producto').find('puja5_tipo').text()+"<br>"+$(xml).find('producto').find('puja6_tipo').text()+"<br>"+$(xml).find('producto').find('puja7_tipo').text()+"<br>"+$(xml).find('producto').find('puja8_tipo').text()+"<br>"+$(xml).find('producto').find('puja9_tipo').text()+"<br>"+$(xml).find('producto').find('puja10_tipo').text();
					var foto1=$(xml).find('producto').find('foto1').text();
					var foto2=$(xml).find('producto').find('foto2').text();
					var foto3=$(xml).find('producto').find('foto3').text();
					var descripcionLarga=unescape($(xml).find('producto').find('descripcionLarga').text());
					var horaActual=$(xml).find('producto').find('horaActual').text();
					tiempo = normalizarFecha(tiempo);
					var fecha_Array=tiempo.split(";");
					var ano_fin=fecha_Array[0];
					var mes_fin=fecha_Array[1];
					var dia_fin=fecha_Array[2];
					var hora_fin=fecha_Array[3];
					var minuto_fin=fecha_Array[4];
					var segundo_fin=fecha_Array[5];
					var tiempo_fin = mktime(hora_fin, minuto_fin, segundo_fin, mes_fin, dia_fin, ano_fin);
					var mydate = new Date(horaActual); 
					var tiempo_ahora = mydate.getTime()/1000; 
					tiempo_ahora = Math.ceil(tiempo_ahora); 
					tiempo=tiempo_fin-tiempo_ahora;
					if(tiempo>10){$("#"+producto+"_tiempo").css("color","black");}else{$("#"+producto+"_tiempo").css("color","red");}
					if(tiempo<0){tiempo=0;}
					tiempo = segundosVisible(tiempo);
					$("#"+producto+"_tipoPuja").html(tipoPujarArray[tipoPuja]);
					fechaFinal = normalizarFecha(fechaFinal);
					var fechaFinal_fecha_Array=fechaFinal.split(";");
					var fechaFinal_ano_fin=fechaFinal_fecha_Array[0];
					var fechaFinal_mes_fin=fechaFinal_fecha_Array[1];
					var fechaFinal_dia_fin=fechaFinal_fecha_Array[2];
					var fechaFinal_hora_fin=fechaFinal_fecha_Array[3];
					var fechaFinal_minuto_fin=fechaFinal_fecha_Array[4];
					var fechaFinal_segundo_fin=fechaFinal_fecha_Array[5];
					$("#"+producto+"_informacionSobrePrecios").html("El precio de cada Ook ejecutado es de 50 c&eacute;ntimos.<br>Con cada PUJA el precio de la subasta aumenta "+normalizarPrecio(tipoPrecioPujarArray[tipoPuja])+"<br>La subasta finalizar&aacute; como m&aacute;ximo el "+fechaFinal_dia_fin+"-"+fechaFinal_mes_fin+"-"+fechaFinal_ano_fin+" a las "+fechaFinal_hora_fin+":"+fechaFinal_minuto_fin+":"+fechaFinal_segundo_fin+"");
					$("#"+producto+"_id").html("ID Subasta: "+codigoPuja);
					$("#"+producto+"_foto").html("<img border=0 src='/fotos/productos/"+foto1+"' alt='"+nombre+"'/>");
					$("#"+producto+"_logo").html("<img src='/logos/productos/"+logo+"' alt='"+nombre+" "+logo+"'/>");
					$("#"+producto+"_nombre").html(nombre);
					$("#"+producto+"_logo2").html("<img src='/logos/productos/"+logo+"' alt='"+nombre+" "+logo+"'/>");
					$("#"+producto+"_nombre2").html(nombre);
					$("#"+producto+"_descripcion").html(descripcion);
					$("#"+producto+"_precioRecomendado").html(normalizarPrecio(precioRecomendado));
					$("#"+producto+"_tiempo").html(tiempo);
					$("#"+producto+"_precio").html(normalizarPrecio(precio));
					if(tipoPuja==2){
						var precioFinal=ooksGastados;
						precioFinal=precioFinal*precioOok;
						precioFinal+=new Number(precioFijo);
						precioFinal=precioFinal.toString();
						$("#"+producto+"_precio2").html(normalizarPrecio(precioFijo));
						$("#final_subasta").html("Precio Fijo:");
					}else{
						var precioFinal=ooksGastados;
						precioFinal=precioFinal*precioOok;
						precioFinal+=new Number(precio);
						precioFinal=precioFinal.toString();
						$("#"+producto+"_precio2").html(normalizarPrecio(precio));	
						$("#final_subasta").html("Precio de la subasta:");
					}
					$("#"+producto+"_pujasUsuario1").html(pujasUsuario1);
					$("#"+producto+"_pujasPrecio1").html(pujasPrecio1);
					$("#"+producto+"_pujasTipo1").html(pujasTipo1);
					$("#"+producto+"_pujasUsuario2").html(pujasUsuario2);
					$("#"+producto+"_pujasPrecio2").html(pujasPrecio2);
					$("#"+producto+"_pujasTipo2").html(pujasTipo2);
					$("#"+producto+"_ookbots").html(ookbotsTexto);
					$("#usuario_ooks").html(ooksUsuario+" Ooks");
					$("#"+producto+"_foto1Div").html("<a href='javascript:fotoGrande(&#34;"+foto1+"&#34;,&#34;"+producto+"&#34;)' id="+producto+"_foto1></a>");
					$("#"+producto+"_foto1").html("<img border=0 src='/redimensionar/fotos/productos/"+foto1+"' alt='"+nombre+"'/>");
					$("#"+producto+"_foto2Div").html("<a href='javascript:fotoGrande(&#34;"+foto2+"&#34;,&#34;"+producto+"&#34;)' id="+producto+"_foto2></a>");
					$("#"+producto+"_foto2").html("<img border=0 src='/redimensionar/fotos/productos/"+foto2+"' alt='"+nombre+"'/>");
					$("#"+producto+"_foto3Div").html("<a href='javascript:fotoGrande(&#34;"+foto3+"&#34;,&#34;"+producto+"&#34;)' id="+producto+"_foto3></a>");
					$("#"+producto+"_foto3").html("<img border=0 src='/redimensionar/fotos/productos/"+foto3+"' alt='"+nombre+"'/>");
					$("#"+producto+"_descripcionLarga").html(descripcionLarga);
					$("#"+producto+"_logoPuja").html("<img src='/logos/pujas/"+tipoPujarLogoArray[tipoPuja]+"' alt='Tipo de puja'/>");
					precio_gastado_actual=ooksGastados*precioOok;
					
					$("#"+producto+"_puja").html("<a title='Pujar' href='javascript:hacerPuja(&#34;"+nombrePermalink+"&#34;,&#34;"+codigoPuja+"&#34;,&#34;"+usuario+"&#34;,&#34;"+precio_gastado_actual+"&#34;,&#34;"+precioRecomendado+"&#34;)'>Pujar</a>");
					$("#"+producto+"_activarOokbot").html("<a title='Activar' href='javascript:activarOokbot(&#34;"+producto+"&#34;,&#34;"+usuario+"&#34;)'>ACTIVAR</a>");
					ooksGastadosEnEuros=ooksGastados*precioOok;
					$("#"+producto+"_ooksGastados").html(ooksGastados+" ("+normalizarPrecio(ooksGastadosEnEuros)+")");
					$("#"+producto+"_precioFinal").html(normalizarPrecio(precioFinal));
					
					// compra
					comprarYaFinal=precioRecomendado;
					comprarYaFinal-=ooksGastados*precioOok;
					$("#"+producto+"_comprarYa_pvp").html(normalizarPrecio(precioRecomendado));
					$("#"+producto+"_comprarYa_gastado").html(normalizarPrecio(ooksGastadosEnEuros));
					$("#"+producto+"_comprarYa_total").html(normalizarPrecio(comprarYaFinal));
					$("#"+producto+"_comprarYa_link").html("<a title='Comprar' href='javascript:comprarProducto(&#34;"+producto+"&#34;,&#34;"+usuario+"&#34;)'>Comprar</a>");
					//
					var pregunta=$(xml).find('producto').find('pregunta').text();
					var pregunta2=$(xml).find('producto').find('pregunta2').text();
					var fechaFinCompra=$(xml).find('producto').find('fechaFinCompra').text();
					if(pregunta2==1){
							$("#subastasG").html("<div class='indvb'><div class='indv1'>&iexcl;FELICIDADES!</div><div class='indv2'>Has ganado la subasta de este producto con c&oacute;digo: "+codigoPuja+" </div><div class='indv3'>&iquest;Deseas adquirirlo ahora?</div><div class='indv4'><div class='siB'><a href='javascript:comprarProducto(&#34;"+producto+"&#34;,&#34;"+usuario+"&#34;)'>COMPRAR</a></div></div><div class='indv5'>Esta opci&oacute;n solo estar&aacute; activa hasta el "+datacastella(fechaFinCompra)+".</div></div>");

					}else if(pregunta==1){
							$("#subastasG").html("<div class='indv'><div class='indv1'>&iexcl;ATENCION!</div><div class='indv2'>Has intentado comprar este producto con c&oacute;digo: "+codigoPuja+" </div><div class='indv3'>&iquest;Deseas adquirirlo ahora? </div><div class='indv4'><div class='si'><a href='javascript:comprarProducto(&#34;"+producto+"&#34;,&#34;"+usuario+"&#34;)'>SI</a></div><div class='no'><a href='javascript:cancelarProducto(&#34;"+producto+"&#34;,&#34;"+usuario+"&#34;)'>NO</a></div></div><div class='indv5'>Esta opci&oacute;n solo estar&aacute; activa hasta el "+datacastella(fechaFinCompra)+". <br /> Si pulsas sobre el bot&oacute;n &#34;NO&#34;, este aviso no se volver&aacute; a mostrar.</div></div>");
					}else{
						$("#subastasG").html("");
					}
					}
				}
			});
}

function comprobadorPersIndividual(producto, usuario){
	
			$.ajax({
				type: "POST",
				url: "/php/infoProductosindv2.php",
				data: "producto="+producto,
				dataType: "xml",
				beforeSend: function(){
				},
				complete: function(){
					var segundosRestantes=visibleSegundos($("#"+producto+"_tiempo").html());
					if(segundosRestantes<=0){
						window.clearInterval(tiempoProductos[producto]); 
						compruebaFinalizada(producto, usuario, 1);
						//$("#"+producto+"_tiempo").html("FIN");
						//$("#"+producto+"_puja").html("<a href='#'>FIN</a>");
						}else{
					if(tiempoProductos[producto] == null || tiempoProductos[producto]=='[object]'){
						tiempoProductos[producto]=setInterval(function(){restarTiempo(producto, usuario, 1);}, 1000);
					}else{
						window.clearInterval(tiempoProductos[producto]); 
						tiempoProductos[producto]=setInterval(function(){restarTiempo(producto, usuario, 1);}, 1000);
					}
					}
					if(segundosRestantes>1800){
						restanteProductos[producto]=setTimeout(function(){comprobadorPersIndividual(producto, usuario);}, 60000);
					}else if(segundosRestantes<=1800 && segundosRestantes>60){
						restanteProductos[producto]=setTimeout(function(){comprobadorPersIndividual(producto, usuario);}, 30000);
					}else if(segundosRestantes<=60 && segundosRestantes>10){
						restanteProductos[producto]=setTimeout(function(){comprobadorPersIndividual(producto, usuario);}, 10000);
					}else if(segundosRestantes<=10 && segundosRestantes>1){
						restanteProductos[producto]=setTimeout(function(){comprobadorPersIndividual(producto, usuario);}, 5000);
					}
					
				},
				success: function(xml) {
					var error=$(xml).find('producto').find('error').text();
					if(error=="si"){
						window.location="/resultados.php";
					}else{
					var ookbotId=$(xml).find('producto').find('ookbotId').text();
					var ookbotPrecioMinimo=$(xml).find('producto').find('ookbotPrecioMinimo').text();
					var ookbotPrecioMaximo=$(xml).find('producto').find('ookbotPrecioMaximo').text();
					var ookbotTotalPujas=$(xml).find('producto').find('ookbotTotalPujas').text();
					var ookbotId_Array=ookbotId.split(";");
					var ookbotPrecioMinimo_Array=ookbotPrecioMinimo.split(";");
					var ookbotPrecioMaximo_Array=ookbotPrecioMaximo.split(";");
					var ookbotTotalPujas_Array=ookbotTotalPujas.split(";");
					var ookbotsTexto="";
					if(ookbotTotalPujas_Array.length>1){
						for(a=0;a<ookbotTotalPujas_Array.length-1;a++){
							ookbotsTexto=ookbotsTexto+"<div class='ookbot2'><div class='espacio'></div><div class='separacion'></div><div class='texto'>Quedan "+ookbotTotalPujas_Array[a]+" Ooks</div><div class='separacion'></div><div class='texto2'>"+normalizarPrecio(ookbotPrecioMinimo_Array[a])+"</div><div class='separacion'></div><div class='texto2'>"+normalizarPrecio(ookbotPrecioMaximo_Array[a])+"</div><div class='separacion'></div><div class='texto3'><a href='javascript:eliminarOokbot(&#34;"+ookbotId_Array[a]+"&#34;,&#34;"+producto+"&#34;,&#34;"+usuario+"&#34;)'>[eliminar]</a></div></div>";
						}
					}
					var tipoPuja=$(xml).find('producto').find('tipopuja').text();
					var tiempo=$(xml).find('producto').find('tiempo').text();
					var precio=$(xml).find('producto').find('precio').text();
					var nombrePermalink=$(xml).find('producto').find('nombrePermalink').text();
					var codigoPuja=$(xml).find('producto').find('codigoPuja').text();
					var precioRecomendado=$(xml).find('producto').find('precioRecomendado').text();
					var precioFijo=$(xml).find('producto').find('precioFijo').text();
					var ooksUsuario=$(xml).find('producto').find('ooksUsuario').text();
					var ooksGastados=$(xml).find('producto').find('ooksGastados').text();
					var pujasUsuario1=$(xml).find('producto').find('puja1_usuario').text();
					var pujasPrecio1=normalizarPrecio($(xml).find('producto').find('puja1_precio').text());
					var pujasTipo1=$(xml).find('producto').find('puja1_tipo').text();
					
					var pujasUsuario2=$(xml).find('producto').find('puja2_usuario').text()+"<br>"+$(xml).find('producto').find('puja3_usuario').text()+"<br>"+$(xml).find('producto').find('puja4_usuario').text()+"<br>"+$(xml).find('producto').find('puja5_usuario').text()+"<br>"+$(xml).find('producto').find('puja6_usuario').text()+"<br>"+$(xml).find('producto').find('puja7_usuario').text()+"<br>"+$(xml).find('producto').find('puja8_usuario').text()+"<br>"+$(xml).find('producto').find('puja9_usuario').text()+"<br>"+$(xml).find('producto').find('puja10_usuario').text();
					var pujasPrecio2=normalizarPrecio($(xml).find('producto').find('puja2_precio').text()) +"<br>"+ normalizarPrecio($(xml).find('producto').find('puja3_precio').text())+"<br>"+ normalizarPrecio($(xml).find('producto').find('puja4_precio').text())+"<br>"+ normalizarPrecio($(xml).find('producto').find('puja5_precio').text())+"<br>"+ normalizarPrecio($(xml).find('producto').find('puja6_precio').text())+"<br>"+ normalizarPrecio($(xml).find('producto').find('puja7_precio').text())+"<br>"+ normalizarPrecio($(xml).find('producto').find('puja8_precio').text())+"<br>"+ normalizarPrecio($(xml).find('producto').find('puja9_precio').text())+"<br>"+ normalizarPrecio($(xml).find('producto').find('puja10_precio').text());
					var pujasTipo2=$(xml).find('producto').find('puja2_tipo').text()+"<br>"+$(xml).find('producto').find('puja3_tipo').text()+"<br>"+$(xml).find('producto').find('puja4_tipo').text()+"<br>"+$(xml).find('producto').find('puja5_tipo').text()+"<br>"+$(xml).find('producto').find('puja6_tipo').text()+"<br>"+$(xml).find('producto').find('puja7_tipo').text()+"<br>"+$(xml).find('producto').find('puja8_tipo').text()+"<br>"+$(xml).find('producto').find('puja9_tipo').text()+"<br>"+$(xml).find('producto').find('puja10_tipo').text();
					var horaActual=$(xml).find('producto').find('horaActual').text();
					tiempo = normalizarFecha(tiempo);
					var fecha_Array=tiempo.split(";");
					var ano_fin=fecha_Array[0];
					var mes_fin=fecha_Array[1];
					var dia_fin=fecha_Array[2];
					var hora_fin=fecha_Array[3];
					var minuto_fin=fecha_Array[4];
					var segundo_fin=fecha_Array[5];
					var tiempo_fin = mktime(hora_fin, minuto_fin, segundo_fin, mes_fin, dia_fin, ano_fin);
					var mydate = new Date(horaActual); 
					var tiempo_ahora = mydate.getTime()/1000; 
					tiempo_ahora = Math.ceil(tiempo_ahora); 
					tiempo=tiempo_fin-tiempo_ahora;
					if(tiempo>10){$("#"+producto+"_tiempo").css("color","black");}else{$("#"+producto+"_tiempo").css("color","red");}
					if(tiempo<0){tiempo=0;}
					tiempo = segundosVisible(tiempo);
					$("#"+producto+"_ookbots").html(ookbotsTexto);
					$("#"+producto+"_tiempo").html(tiempo);
					//INICIO BRILLO
					if(desnormalizarPrecio($("#"+producto+"_precio").html())!=normalizarPrecioSinEuro(precio)){
						$("#"+producto+"_precio").animate( { backgroundColor: 'red' }, 200).animate( { backgroundColor: 'white' }, 500);
					}
					//FIN BRILLO
					$("#"+producto+"_precio").html(normalizarPrecio(precio));
					if(tipoPuja==2){
						var precioFinal=ooksGastados;
						precioFinal=precioFinal*precioOok;
						precioFinal+=new Number(precioFijo);
						precioFinal=precioFinal.toString();
						$("#"+producto+"_precio2").html(normalizarPrecio(precioFijo));
					}else{
						var precioFinal=ooksGastados;
						precioFinal=precioFinal*precioOok;
						precioFinal+=new Number(precio);
						precioFinal=precioFinal.toString();
						$("#"+producto+"_precio2").html(normalizarPrecio(precio));	
					}
					$("#usuario_ooks").html(ooksUsuario+" Ooks");
					$("#"+producto+"_pujasUsuario1").html(pujasUsuario1);
					$("#"+producto+"_pujasPrecio1").html(pujasPrecio1);
					$("#"+producto+"_pujasTipo1").html(pujasTipo1);
					$("#"+producto+"_pujasUsuario2").html(pujasUsuario2);
					$("#"+producto+"_pujasPrecio2").html(pujasPrecio2);
					$("#"+producto+"_pujasTipo2").html(pujasTipo2);
					ooksGastadosEnEuros=ooksGastados*precioOok;
					$("#"+producto+"_ooksGastados").html(ooksGastados+" ("+normalizarPrecio(ooksGastadosEnEuros)+")");
					$("#"+producto+"_precioFinal").html(normalizarPrecio(precioFinal));
					
					// compra
					comprarYaFinal=precioRecomendado;
					comprarYaFinal-=ooksGastados*precioOok;
					$("#"+producto+"_comprarYa_pvp").html(normalizarPrecio(precioRecomendado));
					$("#"+producto+"_comprarYa_gastado").html(normalizarPrecio(ooksGastadosEnEuros));
					$("#"+producto+"_comprarYa_total").html(normalizarPrecio(comprarYaFinal));
					$("#"+producto+"_comprarYa_link").html("<a title='Comprar' href='javascript:comprarProducto(&#34;"+producto+"&#34;,&#34;"+usuario+"&#34;)'>Comprar</a>");
					//
					
					precio_gastado_actual=ooksGastados*precioOok;
					//$("#"+producto+"_puja").html("<a title='Pujar' href='javascript:hacerPuja(&#34;"+nombrePermalink+"&#34;,&#34;"+codigoPuja+"&#34;,&#34;"+usuario+"&#34;,&#34;"+precio_gastado_actual+"&#34;,&#34;"+precioRecomendado+"&#34;)'>Pujar</a>");
					
					var pregunta=$(xml).find('producto').find('pregunta').text();
					var pregunta2=$(xml).find('producto').find('pregunta2').text();
					var fechaFinCompra=$(xml).find('producto').find('fechaFinCompra').text();
					if(pregunta2==1){
							$("#subastasG").html("<div class='indvb'><div class='indv1'>&iexcl;FELICIDADES!</div><div class='indv2'>Has ganado la subasta de este producto con c&oacute;digo: "+codigoPuja+" </div><div class='indv3'>&iquest;Deseas adquirirlo ahora?</div><div class='indv4'><div class='siB'><a href='javascript:comprarProducto(&#34;"+producto+"&#34;,&#34;"+usuario+"&#34;)'>COMPRAR</a></div></div><div class='indv5'>Esta opci&oacute;n solo estar&aacute; activa hasta el "+datacastella(fechaFinCompra)+".</div></div>");

					}else if(pregunta==1){
						$("#subastasG").html("<div class='indv'><div class='indv1'>&iexcl;ATENCION!</div><div class='indv2'>Has intentado comprar este producto con c&oacute;digo: "+codigoPuja+" </div><div class='indv3'>&iquest;Deseas adquirirlo ahora? </div><div class='indv4'><div class='si'><a href='javascript:comprarProducto(&#34;"+producto+"&#34;,&#34;"+usuario+"&#34;)'>SI</a></div><div class='no'><a href='javascript:cancelarProducto(&#34;"+producto+"&#34;,&#34;"+usuario+"&#34;)'>NO</a></div></div><div class='indv5'>Esta opci&oacute;n solo estar&aacute; activa hasta el "+datacastella(fechaFinCompra)+". <br /> Si pulsas sobre el bot&oacute;n &#34;NO&#34;, este aviso no se volver&aacute; a mostrar.</div></div>");
					}else{
						$("#subastasG").html("");
					}
					}
				}
			});
}
function comprobadorIndividualGratuitas(producto, usuario){
			$.ajax({
				type: "POST",
				url: "/php/infoProductosindvGratuitas.php",
				data: "producto="+producto,
				dataType: "xml",
				beforeSend: function(){
				},
				complete: function(){
					var segundosRestantes=visibleSegundos($("#"+producto+"_tiempo").html());
					if(segundosRestantes<=0){
						window.clearInterval(tiempoProductos[producto]); 
						compruebaFinalizada(producto, usuario, 3);
						//$("#"+producto+"_tiempo").html("FIN");
						//$("#"+producto+"_puja").html("<a href='#'>FIN</a>");
						}else{
					if(tiempoProductos[producto] == null || tiempoProductos[producto]=='[object]'){
						tiempoProductos[producto]=setInterval(function(){restarTiempo(producto, usuario, 3);}, 1000);
					}else{
						window.clearInterval(tiempoProductos[producto]); 
						tiempoProductos[producto]=setInterval(function(){restarTiempo(producto, usuario, 3);}, 1000);
					}
					}
					if(segundosRestantes>1800){
						restanteProductos[producto]=setTimeout(function(){comprobadorPersIndividualGratuitas(producto, usuario);}, 60000);
					}else if(segundosRestantes<=1800 && segundosRestantes>60){
						restanteProductos[producto]=setTimeout(function(){comprobadorPersIndividualGratuitas(producto, usuario);}, 30000);
					}else if(segundosRestantes<=60 && segundosRestantes>10){
						restanteProductos[producto]=setTimeout(function(){comprobadorPersIndividualGratuitas(producto, usuario);}, 10000);
					}else if(segundosRestantes<=10 && segundosRestantes>1){
						restanteProductos[producto]=setTimeout(function(){comprobadorPersIndividualGratuitas(producto, usuario);}, 5000);
					}
					
				},
				success: function(xml) {
					var error=$(xml).find('producto').find('error').text();
					if(error=="si"){
						window.location="/resultados.php";
					}else{
					var logo=$(xml).find('producto').find('logo').text();
					var nombre=$(xml).find('producto').find('nombre').text();
					var nombrePermalink=$(xml).find('producto').find('nombrePermalink').text();
					var codigoPuja=$(xml).find('producto').find('codigoPuja').text();
					var descripcion=$(xml).find('producto').find('descripcion').text();
					var tipoPuja=$(xml).find('producto').find('tipopuja').text();
					var tiempo=$(xml).find('producto').find('tiempo').text();
					var fechaFinal=$(xml).find('producto').find('fechaFinal').text();
					var precio=$(xml).find('producto').find('precio').text();
					var precioFijo=$(xml).find('producto').find('precioFijo').text();
					var ooksUsuario=$(xml).find('producto').find('ooksUsuario').text();
					var ooksGastados=$(xml).find('producto').find('ooksGastados').text();
					var precioRecomendado=$(xml).find('producto').find('precioRecomendado').text();
					var pujasUsuario1=$(xml).find('producto').find('puja1_usuario').text();
					var pujasPrecio1=normalizarPrecio($(xml).find('producto').find('puja1_precio').text());
					var pujasTipo1=$(xml).find('producto').find('puja1_tipo').text();
					
					var pujasUsuario2=$(xml).find('producto').find('puja2_usuario').text()+"<br>"+$(xml).find('producto').find('puja3_usuario').text()+"<br>"+$(xml).find('producto').find('puja4_usuario').text()+"<br>"+$(xml).find('producto').find('puja5_usuario').text()+"<br>"+$(xml).find('producto').find('puja6_usuario').text()+"<br>"+$(xml).find('producto').find('puja7_usuario').text()+"<br>"+$(xml).find('producto').find('puja8_usuario').text()+"<br>"+$(xml).find('producto').find('puja9_usuario').text()+"<br>"+$(xml).find('producto').find('puja10_usuario').text();
					var pujasPrecio2=normalizarPrecio($(xml).find('producto').find('puja2_precio').text()) +"<br>"+ normalizarPrecio($(xml).find('producto').find('puja3_precio').text())+"<br>"+ normalizarPrecio($(xml).find('producto').find('puja4_precio').text())+"<br>"+ normalizarPrecio($(xml).find('producto').find('puja5_precio').text())+"<br>"+ normalizarPrecio($(xml).find('producto').find('puja6_precio').text())+"<br>"+ normalizarPrecio($(xml).find('producto').find('puja7_precio').text())+"<br>"+ normalizarPrecio($(xml).find('producto').find('puja8_precio').text())+"<br>"+ normalizarPrecio($(xml).find('producto').find('puja9_precio').text())+"<br>"+ normalizarPrecio($(xml).find('producto').find('puja10_precio').text());
					var pujasTipo2=$(xml).find('producto').find('puja2_tipo').text()+"<br>"+$(xml).find('producto').find('puja3_tipo').text()+"<br>"+$(xml).find('producto').find('puja4_tipo').text()+"<br>"+$(xml).find('producto').find('puja5_tipo').text()+"<br>"+$(xml).find('producto').find('puja6_tipo').text()+"<br>"+$(xml).find('producto').find('puja7_tipo').text()+"<br>"+$(xml).find('producto').find('puja8_tipo').text()+"<br>"+$(xml).find('producto').find('puja9_tipo').text()+"<br>"+$(xml).find('producto').find('puja10_tipo').text();
					var foto1=$(xml).find('producto').find('foto1').text();
					var foto2=$(xml).find('producto').find('foto2').text();
					var foto3=$(xml).find('producto').find('foto3').text();
					var descripcionLarga=unescape($(xml).find('producto').find('descripcionLarga').text());
					var horaActual=$(xml).find('producto').find('horaActual').text();
					tiempo = normalizarFecha(tiempo);
					var fecha_Array=tiempo.split(";");
					var ano_fin=fecha_Array[0];
					var mes_fin=fecha_Array[1];
					var dia_fin=fecha_Array[2];
					var hora_fin=fecha_Array[3];
					var minuto_fin=fecha_Array[4];
					var segundo_fin=fecha_Array[5];
					var tiempo_fin = mktime(hora_fin, minuto_fin, segundo_fin, mes_fin, dia_fin, ano_fin);
					var mydate = new Date(horaActual); 
					var tiempo_ahora = mydate.getTime()/1000; 
					tiempo_ahora = Math.ceil(tiempo_ahora); 
					tiempo=tiempo_fin-tiempo_ahora;
					if(tiempo>10){$("#"+producto+"_tiempo").css("color","black");}else{$("#"+producto+"_tiempo").css("color","red");}
					if(tiempo<0){tiempo=0;}
					tiempo = segundosVisible(tiempo);
					$("#"+producto+"_tipoPuja").html(tipoPujarArray[tipoPuja]);
					fechaFinal = normalizarFecha(fechaFinal);
					var fechaFinal_fecha_Array=fechaFinal.split(";");
					var fechaFinal_ano_fin=fechaFinal_fecha_Array[0];
					var fechaFinal_mes_fin=fechaFinal_fecha_Array[1];
					var fechaFinal_dia_fin=fechaFinal_fecha_Array[2];
					var fechaFinal_hora_fin=fechaFinal_fecha_Array[3];
					var fechaFinal_minuto_fin=fechaFinal_fecha_Array[4];
					var fechaFinal_segundo_fin=fechaFinal_fecha_Array[5];
					$("#"+producto+"_informacionSobrePrecios").html("Puja gratis, consigue tus Ooks gratuitos para participar.<br><a href='/pagina/como_conseguir_ooks_gratuitos/ '>&iquest;Como conseguir Ooks gratuitos?</a> <br>La subasta finalizar&aacute; como m&aacute;ximo el "+fechaFinal_dia_fin+"-"+fechaFinal_mes_fin+"-"+fechaFinal_ano_fin+" a las "+fechaFinal_hora_fin+":"+fechaFinal_minuto_fin+":"+fechaFinal_segundo_fin+"");
					$("#"+producto+"_id").html("ID Subasta: "+codigoPuja);
					$("#"+producto+"_foto").html("<img border=0 src='/fotos/productos/"+foto1+"' alt='"+nombre+"'/>");
					$("#"+producto+"_logo").html("<img src='/logos/productos/"+logo+"'alt='"+nombre+" "+logo+"' />");
					$("#"+producto+"_nombre").html(nombre);
					$("#"+producto+"_logo2").html("<img src='/logos/productos/"+logo+"' alt='"+nombre+" "+logo+"'/>");
					$("#"+producto+"_nombre2").html(nombre);
					$("#"+producto+"_descripcion").html(descripcion);
					$("#"+producto+"_precioRecomendado").html(normalizarPrecio(precioRecomendado));
					$("#"+producto+"_tiempo").html(tiempo);
					$("#"+producto+"_precio").html(normalizarPrecio(precio));
					var precioFinal=ooksGastados;
					precioFinal=precioFinal*precioOok;
					precioFinal+=new Number(precio);
					precioFinal=precioFinal.toString();
					$("#"+producto+"_precio2").html(normalizarPrecio(precio));	
					$("#final_subasta").html("Precio de la subasta:");
					$("#"+producto+"_pujasUsuario1").html(pujasUsuario1);
					$("#"+producto+"_pujasPrecio1").html(pujasPrecio1);
					$("#"+producto+"_pujasTipo1").html(pujasTipo1);
					$("#"+producto+"_pujasUsuario2").html(pujasUsuario2);
					$("#"+producto+"_pujasPrecio2").html(pujasPrecio2);
					$("#"+producto+"_pujasTipo2").html(pujasTipo2);
					$("#usuario_ooks").html(ooksUsuario+" Ooks");
					$("#"+producto+"_foto1Div").html("<a href='javascript:fotoGrande(&#34;"+foto1+"&#34;,&#34;"+producto+"&#34;)' id="+producto+"_foto1></a>");
					$("#"+producto+"_foto1").html("<img border=0 src='/redimensionar/fotos/productos/"+foto1+"' alt='"+nombre+"'/>");
					$("#"+producto+"_foto2Div").html("<a href='javascript:fotoGrande(&#34;"+foto2+"&#34;,&#34;"+producto+"&#34;)' id="+producto+"_foto2></a>");
					$("#"+producto+"_foto2").html("<img border=0 src='/redimensionar/fotos/productos/"+foto2+"'alt='"+nombre+"' />");
					$("#"+producto+"_foto3Div").html("<a href='javascript:fotoGrande(&#34;"+foto3+"&#34;,&#34;"+producto+"&#34;)' id="+producto+"_foto3></a>");
					$("#"+producto+"_foto3").html("<img border=0 src='/redimensionar/fotos/productos/"+foto3+"'alt='"+nombre+"' />");
					$("#"+producto+"_descripcionLarga").html(descripcionLarga);
					$("#"+producto+"_logoPuja").html("<img src='/logos/pujas/"+tipoPujarLogoArray[tipoPuja]+"' alt='Tipo de puja'/>");
					precio_gastado_actual=ooksGastados*precioOok;
					
					$("#"+producto+"_puja").html("<a title='Pujar' href='javascript:hacerPuja5(&#34;"+nombrePermalink+"&#34;,&#34;"+codigoPuja+"&#34;,&#34;"+usuario+"&#34;,&#34;"+precioRecomendado+"&#34;)'>Pujar</a>");
					ooksGastadosEnEuros=ooksGastados*precioOok;
					$("#"+producto+"_ooksGastados").html(ooksGastados);
					$("#"+producto+"_precioFinal").html(" <span class='GratisPrecio'>"+normalizarPrecio(0)+"</span> <span class='GratisRojo'>GRATIS </span>");
					
					// compra
					comprarYaFinal=precioRecomendado;
					$("#"+producto+"_comprarYa_pvp").html(normalizarPrecio(precioRecomendado));
					$("#"+producto+"_comprarYa_gastado").html(normalizarPrecio(0));
					$("#"+producto+"_comprarYa_total").html(normalizarPrecio(comprarYaFinal));
					$("#"+producto+"_comprarYa_link").html("<a title='Comprar' href='javascript:comprarProducto(&#34;"+codigoPuja+"&#34;,&#34;"+usuario+"&#34;)'>Comprar</a>");
					//
					
					var pregunta=$(xml).find('producto').find('pregunta').text();
					var pregunta2=$(xml).find('producto').find('pregunta2').text();
					var fechaFinCompra=$(xml).find('producto').find('fechaFinCompra').text();
					if(pregunta2==1){
							$("#subastasG").html("<div class='indvb'><div class='indv1'>&iexcl;FELICIDADES!</div><div class='indv2'>Has ganado la subasta de este producto con c&oacute;digo: "+codigoPuja+" </div><div class='indv3'>&iquest;Deseas adquirirlo ahora?</div><div class='indv4'><div class='siB'><a href='javascript:comprarProducto(&#34;"+producto+"&#34;,&#34;"+usuario+"&#34;)'>COMPRAR</a></div></div><div class='indv5'>Esta opci&oacute;n solo estar&aacute; activa hasta el "+datacastella(fechaFinCompra)+".</div></div>");

					}else if(pregunta==1){
							$("#subastasG").html("<div class='indv'><div class='indv1'>&iexcl;ATENCION!</div><div class='indv2'>Has intentado comprar este producto con c&oacute;digo: "+codigoPuja+" </div><div class='indv3'>&iquest;Deseas adquirirlo ahora? </div><div class='indv4'><div class='si'><a href='javascript:comprarProducto(&#34;"+producto+"&#34;,&#34;"+usuario+"&#34;)'>SI</a></div><div class='no'><a href='javascript:cancelarProducto(&#34;"+producto+"&#34;,&#34;"+usuario+"&#34;)'>NO</a></div></div><div class='indv5'>Esta opci&oacute;n solo estar&aacute; activa hasta el "+datacastella(fechaFinCompra)+". <br /> Si pulsas sobre el bot&oacute;n &#34;NO&#34;, este aviso no se volver&aacute; a mostrar.</div></div>");
					}else{
						$("#subastasG").html("");
					}
					}
				}
			});
}

function comprobadorPersIndividualGratuitas(producto, usuario){
	
			$.ajax({
				type: "POST",
				url: "/php/infoProductosindv2Gratuitas.php",
				data: "producto="+producto,
				dataType: "xml",
				beforeSend: function(){
				},
				complete: function(){
					var segundosRestantes=visibleSegundos($("#"+producto+"_tiempo").html());
					if(segundosRestantes<=0){
						window.clearInterval(tiempoProductos[producto]); 
						compruebaFinalizada(producto, usuario, 3);
						//$("#"+producto+"_tiempo").html("FIN");
						//$("#"+producto+"_puja").html("<a href='#'>FIN</a>");
						}else{
					if(tiempoProductos[producto] == null || tiempoProductos[producto]=='[object]'){
						tiempoProductos[producto]=setInterval(function(){restarTiempo(producto, usuario, 3);}, 1000);
					}else{
						window.clearInterval(tiempoProductos[producto]); 
						tiempoProductos[producto]=setInterval(function(){restarTiempo(producto, usuario, 3);}, 1000);
					}
					}
					if(segundosRestantes>1800){
						restanteProductos[producto]=setTimeout(function(){comprobadorPersIndividualGratuitas(producto, usuario);}, 60000);
					}else if(segundosRestantes<=1800 && segundosRestantes>60){
						restanteProductos[producto]=setTimeout(function(){comprobadorPersIndividualGratuitas(producto, usuario);}, 30000);
					}else if(segundosRestantes<=60 && segundosRestantes>10){
						restanteProductos[producto]=setTimeout(function(){comprobadorPersIndividualGratuitas(producto, usuario);}, 10000);
					}else if(segundosRestantes<=10 && segundosRestantes>1){
						restanteProductos[producto]=setTimeout(function(){comprobadorPersIndividualGratuitas(producto, usuario);}, 5000);
					}
					
				},
				success: function(xml) {
					var error=$(xml).find('producto').find('error').text();
					if(error=="si"){
						window.location="/resultados.php";
					}else{
					var tipoPuja=$(xml).find('producto').find('tipopuja').text();
					var tiempo=$(xml).find('producto').find('tiempo').text();
					var precio=$(xml).find('producto').find('precio').text();
					var nombrePermalink=$(xml).find('producto').find('nombrePermalink').text();
					var codigoPuja=$(xml).find('producto').find('codigoPuja').text();
					var precioRecomendado=$(xml).find('producto').find('precioRecomendado').text();
					var precioFijo=$(xml).find('producto').find('precioFijo').text();
					var ooksUsuario=$(xml).find('producto').find('ooksUsuario').text();
					var ooksGastados=$(xml).find('producto').find('ooksGastados').text();
					var pujasUsuario1=$(xml).find('producto').find('puja1_usuario').text();
					var pujasPrecio1=normalizarPrecio($(xml).find('producto').find('puja1_precio').text());
					var pujasTipo1=$(xml).find('producto').find('puja1_tipo').text();
					
					var pujasUsuario2=$(xml).find('producto').find('puja2_usuario').text()+"<br>"+$(xml).find('producto').find('puja3_usuario').text()+"<br>"+$(xml).find('producto').find('puja4_usuario').text()+"<br>"+$(xml).find('producto').find('puja5_usuario').text()+"<br>"+$(xml).find('producto').find('puja6_usuario').text()+"<br>"+$(xml).find('producto').find('puja7_usuario').text()+"<br>"+$(xml).find('producto').find('puja8_usuario').text()+"<br>"+$(xml).find('producto').find('puja9_usuario').text()+"<br>"+$(xml).find('producto').find('puja10_usuario').text();
					var pujasPrecio2=normalizarPrecio($(xml).find('producto').find('puja2_precio').text()) +"<br>"+ normalizarPrecio($(xml).find('producto').find('puja3_precio').text())+"<br>"+ normalizarPrecio($(xml).find('producto').find('puja4_precio').text())+"<br>"+ normalizarPrecio($(xml).find('producto').find('puja5_precio').text())+"<br>"+ normalizarPrecio($(xml).find('producto').find('puja6_precio').text())+"<br>"+ normalizarPrecio($(xml).find('producto').find('puja7_precio').text())+"<br>"+ normalizarPrecio($(xml).find('producto').find('puja8_precio').text())+"<br>"+ normalizarPrecio($(xml).find('producto').find('puja9_precio').text())+"<br>"+ normalizarPrecio($(xml).find('producto').find('puja10_precio').text());
					var pujasTipo2=$(xml).find('producto').find('puja2_tipo').text()+"<br>"+$(xml).find('producto').find('puja3_tipo').text()+"<br>"+$(xml).find('producto').find('puja4_tipo').text()+"<br>"+$(xml).find('producto').find('puja5_tipo').text()+"<br>"+$(xml).find('producto').find('puja6_tipo').text()+"<br>"+$(xml).find('producto').find('puja7_tipo').text()+"<br>"+$(xml).find('producto').find('puja8_tipo').text()+"<br>"+$(xml).find('producto').find('puja9_tipo').text()+"<br>"+$(xml).find('producto').find('puja10_tipo').text();
					var horaActual=$(xml).find('producto').find('horaActual').text();
					tiempo = normalizarFecha(tiempo);
					var fecha_Array=tiempo.split(";");
					var ano_fin=fecha_Array[0];
					var mes_fin=fecha_Array[1];
					var dia_fin=fecha_Array[2];
					var hora_fin=fecha_Array[3];
					var minuto_fin=fecha_Array[4];
					var segundo_fin=fecha_Array[5];
					var tiempo_fin = mktime(hora_fin, minuto_fin, segundo_fin, mes_fin, dia_fin, ano_fin);
					var mydate = new Date(horaActual); 
					var tiempo_ahora = mydate.getTime()/1000; 
					tiempo_ahora = Math.ceil(tiempo_ahora); 
					tiempo=tiempo_fin-tiempo_ahora;
					if(tiempo>10){$("#"+producto+"_tiempo").css("color","black");}else{$("#"+producto+"_tiempo").css("color","red");}
					if(tiempo<0){tiempo=0;}
					tiempo = segundosVisible(tiempo);
					$("#"+producto+"_tiempo").html(tiempo);
					//INICIO BRILLO
					if(desnormalizarPrecio($("#"+producto+"_precio").html())!=normalizarPrecioSinEuro(precio)){
						$("#"+producto+"_precio").animate( { backgroundColor: 'red' }, 200).animate( { backgroundColor: 'white' }, 500);
					}
					// FIN BRILLO
					$("#"+producto+"_precio").html(normalizarPrecio(precio));
					
					var precioFinal=ooksGastados;
					precioFinal=precioFinal*precioOok;
					precioFinal+=new Number(precio);
					precioFinal=precioFinal.toString();
					$("#"+producto+"_precio2").html(normalizarPrecio(precio));	
				
					$("#usuario_ooks").html(ooksUsuario+" Ooks");
					$("#"+producto+"_pujasUsuario1").html(pujasUsuario1);
					$("#"+producto+"_pujasPrecio1").html(pujasPrecio1);
					$("#"+producto+"_pujasTipo1").html(pujasTipo1);
					$("#"+producto+"_pujasUsuario2").html(pujasUsuario2);
					$("#"+producto+"_pujasPrecio2").html(pujasPrecio2);
					$("#"+producto+"_pujasTipo2").html(pujasTipo2);
					ooksGastadosEnEuros=ooksGastados*precioOok;
					$("#"+producto+"_ooksGastados").html(ooksGastados);
					$("#"+producto+"_precioFinal").html(" <span class='GratisPrecio'>"+normalizarPrecio(0)+"</span> <span class='GratisRojo'>GRATIS </span>");
					
					// compra
					comprarYaFinal=precioRecomendado;
					$("#"+producto+"_comprarYa_pvp").html(normalizarPrecio(precioRecomendado));
					$("#"+producto+"_comprarYa_gastado").html(normalizarPrecio(0));
					$("#"+producto+"_comprarYa_total").html(normalizarPrecio(comprarYaFinal));
					$("#"+producto+"_comprarYa_link").html("<a title='Comprar' href='javascript:comprarProducto(&#34;"+codigoPuja+"&#34;,&#34;"+usuario+"&#34;)'>Comprar</a>");
					//

					
					var pregunta=$(xml).find('producto').find('pregunta').text();
					var pregunta2=$(xml).find('producto').find('pregunta2').text();
					var fechaFinCompra=$(xml).find('producto').find('fechaFinCompra').text();
					if(pregunta2==1){
							$("#subastasG").html("<div class='indvb'><div class='indv1'>&iexcl;FELICIDADES!</div><div class='indv2'>Has ganado la subasta de este producto con c&oacute;digo: "+codigoPuja+" </div><div class='indv3'>&iquest;Deseas adquirirlo ahora?</div><div class='indv4'><div class='siB'><a href='javascript:comprarProducto(&#34;"+producto+"&#34;,&#34;"+usuario+"&#34;)'>COMPRAR</a></div></div><div class='indv5'>Esta opci&oacute;n solo estar&aacute; activa hasta el "+datacastella(fechaFinCompra)+".</div></div>");

					}else if(pregunta==1){
						$("#subastasG").html("<div class='indv'><div class='indv1'>&iexcl;ATENCION!</div><div class='indv2'>Has intentado comprar este producto con c&oacute;digo: "+codigoPuja+" </div><div class='indv3'>&iquest;Deseas adquirirlo ahora? </div><div class='indv4'><div class='si'><a href='javascript:comprarProducto(&#34;"+producto+"&#34;,&#34;"+usuario+"&#34;)'>SI</a></div><div class='no'><a href='javascript:cancelarProducto(&#34;"+producto+"&#34;,&#34;"+usuario+"&#34;)'>NO</a></div></div><div class='indv5'>Esta opci&oacute;n solo estar&aacute; activa hasta el "+datacastella(fechaFinCompra)+". <br /> Si pulsas sobre el bot&oacute;n &#34;NO&#34;, este aviso no se volver&aacute; a mostrar.</div></div>");
					}else{
						$("#subastasG").html("");
					}
					}
				}
			});
}
function comprobador_pcontrol_ookbots(producto, usuario){
			$.ajax({
				type: "POST",
				url: "/php/infoProductosPControlOokbotbis.php",
				data: "producto="+producto,
				dataType: "xml",
				beforeSend: function(){
				},
				complete: function(){
					
				},
				success: function(xml) {
					$(xml).find('producto').each(function(){
						var logo=$(this).find('logo').text();
						var nombre=$(this).find('nombre').text();
						var error=$(this).find('error').text();
						var nombrePermalink=$(this).find('nombrePermalink').text();
						var codigoPuja=$(this).find('codigoPuja').text();
						var ookbotId=$(this).find('ookbotId').text();
						var ookbotPrecioMinimo=$(this).find('ookbotPrecioMinimo').text();
						var ookbotPrecioMaximo=$(this).find('ookbotPrecioMaximo').text();
						var ookbotTotalPujas=$(this).find('ookbotTotalPujas').text();
						var ooksUsuario=$(this).find('ooksUsuario').text();
						var ookbotId_Array=ookbotId.split(";");
						var ookbotPrecioMinimo_Array=ookbotPrecioMinimo.split(";");
						var ookbotPrecioMaximo_Array=ookbotPrecioMaximo.split(";");
						var ookbotTotalPujas_Array=ookbotTotalPujas.split(";");
						var ookbotsTexto="";
						if(ookbotTotalPujas_Array.length>1){
							for(a=0;a<ookbotTotalPujas_Array.length-1;a++){
								ookbotsTexto=ookbotsTexto+"<div class='ookbot2'><div class='texto'>Quedan "+ookbotTotalPujas_Array[a]+" Ooks</div><div class='separacion'></div><div class='texto2'>"+normalizarPrecio(ookbotPrecioMinimo_Array[a])+"</div><div class='separacion'></div><div class='texto2'>"+normalizarPrecio(ookbotPrecioMaximo_Array[a])+"</div><div class='separacion'></div><div class='texto3'><a href='javascript:eliminarOokbot2(&#34;"+ookbotId_Array[a]+"&#34;,&#34;"+codigoPuja+"&#34;,&#34;"+usuario+"&#34;)'>[eliminar]</a></div></div>";
							}
						}
						
						$("#usuario_ooks").html(ooksUsuario+" Ooks");
						$("#"+codigoPuja+"_logo").html("<a title ='"+nombre+"' href='/productos/"+nombrePermalink+"/"+codigoPuja+"'><img src='/logos/productos/"+logo+"' alt='"+nombre+" "+logo+"'/></a>");
						$("#"+codigoPuja+"_info1").html("<a title ='"+nombre+"' href='/productos/"+nombrePermalink+"/"+codigoPuja+"'>"+nombre+" | cod."+codigoPuja+"</a>");
						$("#"+codigoPuja+"_info2").html(ookbotsTexto);
					
					});
				}
			});
}
function comprobador_pcontrol_finalizadas(producto, usuario){
			$.ajax({
				type: "POST",
				url: "/php/infoProductosPControlFinalizadasbis.php",
				data: "producto="+producto,
				dataType: "xml",
				beforeSend: function(){
				},
				complete: function(){	
				},
				success: function(xml) {
					$(xml).find('producto').each(function(){
														  
						var logo=$(this).find('logo').text();
						var nombre=$(this).find('nombre').text();
						var nombrePermalink=$(this).find('nombrePermalink').text();
						var codigoPuja=$(this).find('codigoPuja').text();
						var precio=$(this).find('precio').text();
						var pujante=$(this).find('pujante').text();
						var ooksGastados=$(this).find('ooksGastados').text();
						var ooksUsuario=$(this).find('ooksUsuario').text();
						$("#"+codigoPuja+"_logo").html("<a title ='"+nombre+"' href='/productos/"+nombrePermalink+"/"+codigoPuja+"'><img src='/logos/productos/"+logo+"' alt='"+nombre+" "+logo+"'/></a>");
						$("#"+codigoPuja+"_info1").html("<a title ='"+nombre+"' href='/productos/"+nombrePermalink+"/"+codigoPuja+"'>"+nombre+" | cod."+codigoPuja+"</a>");
						$("#"+codigoPuja+"_tiempo").html("Finalizada");
						$("#"+codigoPuja+"_precio").html(normalizarPrecio(precio));
						$("#"+codigoPuja+"_pujante").html(pujante);
						$("#"+codigoPuja+"_ooksGastados").html("Ooks Gastados "+ooksGastados);
						$("#"+codigoPuja+"_puja").html("<a title ='"+nombre+"' href='/productos/"+nombrePermalink+"/"+codigoPuja+"'>Finalizada</a>");
						$("#usuario_ooks").html(ooksUsuario+" Ooks");
					
					});
				}
			});
}
function comprobador_pcontrol_ganadas(producto, usuario){
			$.ajax({
				type: "POST",
				url: "/php/infoProductosPControlFinalizadasbis.php",
				data: "producto="+producto,
				dataType: "xml",
				beforeSend: function(){
				},
				complete: function(){	
				},
				success: function(xml) {
					$(xml).find('producto').each(function(){
						var logo=$(this).find('logo').text();
						var nombre=$(this).find('nombre').text();
						var nombrePermalink=$(this).find('nombrePermalink').text();
						var codigoPuja=$(this).find('codigoPuja').text();
						var precio=$(this).find('precio').text();
						var pujante=$(this).find('pujante').text();
						var ooksGastados=$(this).find('ooksGastados').text();
						var ooksUsuario=$(this).find('ooksUsuario').text();
						$("#"+codigoPuja+"_logo").html("<a title ='"+nombre+"' href='/productos/"+nombrePermalink+"/"+codigoPuja+"'><img src='/logos/productos/"+logo+"' alt='"+nombre+" "+logo+"' /></a>");
						$("#"+codigoPuja+"_info1").html("<a title ='"+nombre+"' href='/productos/"+nombrePermalink+"/"+codigoPuja+"'>"+nombre+" | cod."+codigoPuja+"</a>");
						$("#"+codigoPuja+"_tiempo").html("Finalizada");
						$("#"+codigoPuja+"_precio").html(normalizarPrecio(precio));
						$("#"+codigoPuja+"_pujante").html(pujante);
						$("#"+codigoPuja+"_ooksGastados").html("Ooks Gastados "+ooksGastados);
						$("#"+codigoPuja+"_puja").html("<a title ='"+nombre+"' href='/productos/"+nombrePermalink+"/"+codigoPuja+"'>Ganada</a>");
						$("#usuario_ooks").html(ooksUsuario+" Ooks");
					});
				}
			});
}
function comprobador_pcontrol(producto, usuario){
			var usuario="desconectado";
			$.ajax({
				type: "POST",
				url: "/php/infoProductosPControlbis.php",
				data: "producto="+producto,
				dataType: "xml",
				beforeSend: function(){
				},
				complete: function(){
					
					var arrayP=producto.split(";"); 
					for (i=0;i<arrayP.length;i++){
						prodAhora=arrayP[i];
						var segundosRestantes=visibleSegundos($("#"+prodAhora+"_tiempo").html());
						if(segundosRestantes<=0){
							compruebaFinalizada(prodAhora, usuario, 2);
						}	
					}
					
					if(tiempoProductos["productoHome"] == null || tiempoProductos["productoHome"]=='[object]'){
						tiempoProductos["productoHome"]=setInterval(function(){restarTiempoB(producto);}, 1000);
					}else{
						window.clearInterval(tiempoProductos["productoHome"]); 
						tiempoProductos["productoHome"]=setInterval(function(){restarTiempoB(producto);}, 1000);	
					}
					
					restanteProductos["productoHome"]=setTimeout(function(){comprobador_pcontrolPers(producto,usuario);}, 5000);
					
					
				},
				success: function(xml) {
					usuario=$(xml).find('usuarioOnline').text();
					$(xml).find('producto').each(function(){
						var error=$(this).find('error').text();
						var logo=$(this).find('logo').text();
						var nombre=$(this).find('nombre').text();
						var nombrePermalink=$(this).find('nombrePermalink').text();
						var codigoPuja=$(this).find('codigoPuja').text();
						var precioRecomendado=$(this).find('precioRecomendado').text();
						var descripcion=$(this).find('descripcion').text();
						var foto=$(this).find('foto').text();
						var fotoG=$(this).find('fotoG').text();
						var tipoPuja=$(this).find('tipopuja').text();
						var tiempo=$(this).find('tiempo').text();
						var precio=$(this).find('precio').text();
						var precioFijo=$(this).find('precioFijo').text();
						var pujante=$(this).find('pujante').text();
						var ooksGastados=$(this).find('ooksGastados').text();
						var ooksUsuario=$(this).find('ooksUsuario').text();
						var horaActual=$(this).find('horaActual').text();
						tiempo = normalizarFecha(tiempo);
						var fecha_Array=tiempo.split(";");
						var ano_fin=fecha_Array[0];
						var mes_fin=fecha_Array[1];
						var dia_fin=fecha_Array[2];
						var hora_fin=fecha_Array[3];
						var minuto_fin=fecha_Array[4];
						var segundo_fin=fecha_Array[5];
						var tiempo_fin = mktime(hora_fin, minuto_fin, segundo_fin, mes_fin, dia_fin, ano_fin);
						var mydate = new Date(horaActual); 
						var tiempo_ahora = mydate.getTime()/1000; 
						tiempo_ahora = Math.ceil(tiempo_ahora); 
						tiempo=tiempo_fin-tiempo_ahora;
						if(tiempo>10){$("#"+codigoPuja+"_tiempo").css("color","black");}else{$("#"+codigoPuja+"_tiempo").css("color","red");}
						if(tiempo<0){tiempo=0;}
						tiempo = segundosVisible(tiempo);
						
						$("#"+codigoPuja+"_tiempo").html(tiempo);
						$("#"+codigoPuja+"_precio").html(normalizarPrecio(precio));
						$("#"+codigoPuja+"_pujante").html(pujante);
						$("#usuario_ooks").html(ooksUsuario+" Ooks");
					if(tipoPuja==3){
						$("#"+codigoPuja+"_puja").html("<a title='Pujar' href='javascript:hacerPuja4(&#34;"+nombrePermalink+"&#34;,&#34;"+codigoPuja+"&#34;,&#34;"+usuario+"&#34;,&#34;"+precioRecomendado+"&#34;)'>Pujar</a>");
						$("#"+codigoPuja+"_logo").html("<a title ='"+nombre+"' href='/productosGratuitos/"+nombrePermalink+"/"+codigoPuja+"'><img src='/logos/productos/"+logo+"' alt='"+nombre+" "+logo+"'/></a>");
						$("#"+codigoPuja+"_info1").html("<a title ='"+nombre+"' href='/productosGratuitos/"+nombrePermalink+"/"+codigoPuja+"'>"+nombre+" | cod."+codigoPuja+" | "+tipoPujarArray[tipoPuja]+"</a>");
						$("#"+codigoPuja+"_ooksGastados").html("Ooks Gastados "+ooksGastados);
					}else{
						$("#"+codigoPuja+"_puja").html("<a title='Pujar' href='javascript:hacerPuja2(&#34;"+nombrePermalink+"&#34;,&#34;"+codigoPuja+"&#34;,&#34;"+usuario+"&#34;,&#34;"+precioRecomendado+"&#34;)'>Pujar</a>");
						$("#"+codigoPuja+"_logo").html("<a title ='"+nombre+"' href='/productos/"+nombrePermalink+"/"+codigoPuja+"'><img src='/logos/productos/"+logo+"' alt='"+nombre+" "+logo+"' /></a>");
						$("#"+codigoPuja+"_info1").html("<a title ='"+nombre+"' href='/productos/"+nombrePermalink+"/"+codigoPuja+"'>"+nombre+" | cod."+codigoPuja+" | "+tipoPujarArray[tipoPuja]+"</a>");
						$("#"+codigoPuja+"_ooksGastados").html("Ooks Gastados "+ooksGastados);
					}
						
					});
					
				
					
				}
			});
}

function comprobador_pcontrolPers(producto, usuario){
			var usuario="desconectado";
			$.ajax({
				type: "POST",
				url: "/php/infoProductosPControl2bis.php",
				data: "producto="+producto,
				dataType: "xml",
				beforeSend: function(){
				},
				complete: function(){
					
					var arrayP=producto.split(";"); 
					for (i=0;i<arrayP.length;i++){
						prodAhora=arrayP[i];
						var segundosRestantes=visibleSegundos($("#"+prodAhora+"_tiempo").html());
						if(segundosRestantes<=0){
							compruebaFinalizada(prodAhora, usuario, 2);
						}	
					}
					
					if(tiempoProductos["productoHome"] == null || tiempoProductos["productoHome"]=='[object]'){
						tiempoProductos["productoHome"]=setInterval(function(){restarTiempoB(producto);}, 1000);
					}else{
						window.clearInterval(tiempoProductos["productoHome"]); 
						tiempoProductos["productoHome"]=setInterval(function(){restarTiempoB(producto);}, 1000);	
					}
					
					restanteProductos["productoHome"]=setTimeout(function(){comprobador_pcontrolPers(producto,usuario);}, 5000);
					
				},
				success: function(xml) {
					usuario=$(xml).find('usuarioOnline').text();
					$(xml).find('producto').each(function(){
						var error=$(this).find('error').text();
						var nombrePermalink=$(this).find('nombrePermalink').text();
						var codigoPuja=$(this).find('codigoPuja').text();
						var precioRecomendado=$(this).find('precioRecomendado').text();
						var tiempo=$(this).find('tiempo').text();
						var precio=$(this).find('precio').text();
						var tipoPuja=$(this).find('tipopuja').text();
						var pujante=$(this).find('pujante').text();
						var ooksGastados=$(this).find('ooksGastados').text();
						var ooksUsuario=$(this).find('ooksUsuario').text();
						var horaActual=$(this).find('horaActual').text();
						tiempo = normalizarFecha(tiempo);
						var fecha_Array=tiempo.split(";");
						var ano_fin=fecha_Array[0];
						var mes_fin=fecha_Array[1];
						var dia_fin=fecha_Array[2];
						var hora_fin=fecha_Array[3];
						var minuto_fin=fecha_Array[4];
						var segundo_fin=fecha_Array[5];
						var tiempo_fin = mktime(hora_fin, minuto_fin, segundo_fin, mes_fin, dia_fin, ano_fin);
						var mydate = new Date(horaActual); 
						var tiempo_ahora = mydate.getTime()/1000; 
						tiempo_ahora = Math.ceil(tiempo_ahora); 
						tiempo=tiempo_fin-tiempo_ahora;
						if(tiempo>10){$("#"+codigoPuja+"_tiempo").css("color","black");}else{$("#"+codigoPuja+"_tiempo").css("color","red");}
						if(tiempo<0){tiempo=0;}
						tiempo = segundosVisible(tiempo);
						$("#"+codigoPuja+"_tiempo").html(tiempo);
						/*if(desnormalizarPrecio($("#"+codigoPuja+"_precio").html())!=normalizarPrecioSinEuro(precio)){
							$("#"+codigoPuja+"_precio").animate( { backgroundColor: 'red' }, 200).animate( { backgroundColor: 'white' }, 500);
						}*/
						$("#"+codigoPuja+"_precio").html(normalizarPrecio(precio));
						$("#"+codigoPuja+"_pujante").html(pujante);
						$("#usuario_ooks").html(ooksUsuario+" Ooks");
						
						if(tipoPuja==3){
						$("#"+codigoPuja+"_puja").html("<a title='Pujar' href='javascript:hacerPuja4(&#34;"+nombrePermalink+"&#34;,&#34;"+codigoPuja+"&#34;,&#34;"+usuario+"&#34;,&#34;"+precioRecomendado+"&#34;)'>Pujar</a>");
						
						$("#"+codigoPuja+"_ooksGastados").html("Ooks Gastados "+ooksGastados);
					}else{
						$("#"+codigoPuja+"_puja").html("<a title='Pujar' href='javascript:hacerPuja2(&#34;"+nombrePermalink+"&#34;,&#34;"+codigoPuja+"&#34;,&#34;"+usuario+"&#34;,&#34;"+precioRecomendado+"&#34;)'>Pujar</a>");
						
						$("#"+codigoPuja+"_ooksGastados").html("Ooks Gastados "+ooksGastados);
					}
					
					});
				}
			});
}
function restarTiempoB(producto){
	var arrayP=producto.split(";"); 
	for (i=0;i<arrayP.length;i++){
		var tiempo = $("#"+arrayP[i]+"_tiempo").html();
		if(tiempo=="FIN"){}else{
			var tiempoSegundosTotales=visibleSegundos(tiempo);
			tiempoSegundosTotales=tiempoSegundosTotales-1;
			if(tiempoSegundosTotales<1){tiempoSegundosTotales=0;}
			if(tiempoSegundosTotales>10){$("#"+arrayP[i]+"_tiempo").css("color","black");}else{$("#"+arrayP[i]+"_tiempo").css("color","red");}
			tiempoSegundosTotales=segundosVisible(tiempoSegundosTotales);
			$("#"+arrayP[i]+"_tiempo").html(tiempoSegundosTotales);
		}
	}
	
}

function restarTiempo(producto, usuario, lugar){
	var tiempo = $("#"+producto+"_tiempo").html();
	var tiempoSegundosTotales=visibleSegundos(tiempo);
	tiempoSegundosTotales=tiempoSegundosTotales-1;
	if(tiempoSegundosTotales<1){
		tiempoSegundosTotales=0;
		window.clearInterval(tiempoProductos[producto]);
		compruebaFinalizada(producto,usuario,lugar);
	}
	if(tiempoSegundosTotales>10){
		$("#"+producto+"_tiempo").css("color","black");}else{$("#"+producto+"_tiempo").css("color","red");
	}
	tiempoSegundosTotales=segundosVisible(tiempoSegundosTotales);
	$("#"+producto+"_tiempo").html(tiempoSegundosTotales);
}

	
function normalizarFecha(fecha){
	var normalizar_fecha = fecha.replace(/-/g, ";");
	normalizar_fecha = normalizar_fecha.replace(/ /g, ";");
	normalizar_fecha = normalizar_fecha.replace(/:/g, ";");	
	return normalizar_fecha;	
}


  function mktime() {
	  
    var no, ma = 0, mb = 0, i = 0, d = new Date(), argv = arguments, argc = argv.length;
    d.setHours(0,0,0); d.setDate(1); d.setMonth(1); d.setYear(1972);
 
    var dateManip = {
        0: function(tt){ return d.setHours(tt); },
        1: function(tt){ return d.setMinutes(tt); },
        2: function(tt){ set = d.setSeconds(tt); mb = d.getDate() - 1; return set; },
        3: function(tt){ set = d.setMonth(parseInt(tt)-1); ma = d.getFullYear() - 1972; return set; },
        4: function(tt){ return d.setDate(tt+mb); },
        5: function(tt){ return d.setYear(tt+ma); }
    };
    
    for( i = 0; i < argc; i++ ){
        no = parseInt(argv[i]*1);
        if (isNaN(no)) {
            return false;
        } else {
            if(!dateManip[i](no)){
                return false;
            }
        }
    }
  return Math.floor(d.getTime()/1000);
}

function visibleSegundos(tiempo){
	var tiempoSeparado = tiempo.split(':');
	var tiempoSegundosTotales=new Number(tiempoSeparado[0]*3600);
	tiempoSegundosTotales=tiempoSegundosTotales+(new Number(tiempoSeparado[1]*60));
	tiempoSegundosTotales=tiempoSegundosTotales+new Number(tiempoSeparado[2]);
	return tiempoSegundosTotales;
}

function segundosVisible(tiempoSegundosTotales){
	var horasTotales= Math.floor(tiempoSegundosTotales/3600);
	tiempoSegundosTotales=tiempoSegundosTotales-(horasTotales*3600);
	var minutosTotales= Math.floor(tiempoSegundosTotales/60);
	tiempoSegundosTotales=tiempoSegundosTotales-(minutosTotales*60);
	var segundosTotales= tiempoSegundosTotales;
	if (horasTotales < 10) {
    	if (horasTotales < 0) {
			horasTotales = 0;
    	}
    	horasTotales = '0' + horasTotales;
  	}
  	if (minutosTotales < 10) {
    	if (minutosTotales < 0) {
    		minutosTotales = 0;
    	}
    	minutosTotales = '0' + minutosTotales;
  	}
  	if (segundosTotales < 10) {
    	if (segundosTotales < 0) {
		  segundosTotales = 0;
    	}
    	segundosTotales = '0' + segundosTotales;
  	}

	tiempoSegundosTotales=horasTotales+":"+minutosTotales+":"+segundosTotales;
	return tiempoSegundosTotales;
}

function datacastella(fecha){
mes = new Array('', 'enero', 'febrero', 'marzo', 'abril', 'mayo', 'junio', 'julio', 'agosto', 'setiembre', 'octubre', 'noviembre', 'diciembre');
fechaVieja = fecha.split("-");
fechaNueva = parseInt(fechaVieja[2])+" de "+mes[parseInt(fechaVieja[1])]+" de "+fechaVieja[0];
return fechaNueva;
}

function actualizar(producto, usuario){
	comprobador(producto, usuario);
	
}

function login(){
	document.selec.submit();
	
}
function login2(){
	document.selec2.submit();
	
}
function desconectar(){
	document.selec.submit();
	
}

function fotoGrande(qfoto, producto){
	$("#"+producto+"_foto").html("<img border=0 src='/fotos/productos/"+qfoto+"' />");
	
}

function normalizarPrecio(precio){
precio=precio.toString();
var e = precio.length;
if(e>0){
precio=round(precio, 2);
precio=precio.toString();
var a=precio.indexOf('.');
if(a>-1){
	var b = precio.substring(a+1, precio.length); 
	var c = b.length;
	if(c==1){
		precio=round(precio, 2);
		precio=precio.toString();
		precio = precio.split(".").join(",");
		precio = precio + "0 &euro;";
	}else if(c==0){
		precio=round(precio, 2);
		precio=precio.toString();
		precio = precio.split(".").join(",");
		precio = precio + "00 &euro;";
	}else {
		precio=round(precio, 2);
		precio=precio.toString();
		precio = precio.split(".").join(",");
		precio = precio + " &euro;";
	}
}else{
	var d = precio.length;
	if(d>0){
		precio=round(precio, 2);
		precio=precio.toString();
		precio = precio + ",00 &euro;";
	}
}
}
return precio;
}
function desnormalizarPrecio(precio){
precio=precio.toString();
var a = precio.length;
var b = precio.substring(0, a-2); 
var precio = b;
return precio;
	}
	
function normalizarPrecioSinEuro(precio){
precio=precio.toString();
var e = precio.length;
if(e>0){
precio=round(precio, 2);
precio=precio.toString();
var a=precio.indexOf('.');
if(a>-1){
	var b = precio.substring(a+1, precio.length); 
	var c = b.length;
	if(c==1){
		precio=round(precio, 2);
precio=precio.toString();
precio = precio.split(".").join(",");
		precio = precio + "0";
	}else if(c==0){
		precio=round(precio, 2);
precio=precio.toString();
precio = precio.split(".").join(",");
		precio = precio + "00";
	}else {
		precio=round(precio, 2);
precio=precio.toString();
precio = precio.split(".").join(",");
		precio = precio + "";
	}
	}else{
		var d = precio.length;
		if(d>0){
			precio=round(precio, 2);
precio=precio.toString();
			precio = precio + ",00";
		}
	}
}
	
	return precio;
	}
	
function normalizarPrecioSinEuroCONPUNTO(precio){
precio=precio.toString();
var e = precio.length;
if(e>0){
precio=round(precio, 2);
precio=precio.toString();
var a=precio.indexOf('.');
if(a>-1){
	var b = precio.substring(a+1, precio.length); 
	var c = b.length;
	if(c==1){
		precio=round(precio, 2);
precio=precio.toString();
precio = precio.split(",").join(".");
		precio = precio + "0";
	}else if(c==0){
		precio=round(precio, 2);
precio=precio.toString();
precio = precio.split(",").join(".");
		precio = precio + "00";
	}else {
		precio=round(precio, 2);
precio=precio.toString();
precio = precio.split(",").join(".");
		precio = precio + "";
	}
	}else{
		var d = precio.length;
		if(d>0){
			precio=round(precio, 2);
precio=precio.toString();
			precio = precio + ".00";
		}
	}
}
	
	return precio;
	}
function round ( val, precision ) {
    return parseFloat(parseFloat(val).toFixed(precision));
}
function compruebaFinalizada(codigo,usuario,lugar){
	$.ajax({
				type: "POST",
				url: "/compruebaFinalizada/",
				data: "codigo="+codigo,
				dataType: "html",
				beforeSend: function(){
				},
				complete: function(){
					
				},
				success: function(msg) {
					if(msg==0){
						$("#"+codigo+"_tiempo").html("FIN");
						$("#"+codigo+"_puja").html("<a href='#'>FIN</a>");
					}else if(msg==1){
						if(lugar==0){
						//comprobadorPers(codigo, usuario);
						}else if(lugar==1){
						comprobadorPersIndividual(codigo, usuario);
						}else if(lugar==2){
						//comprobador_pcontrolPers(codigo, usuario);	
						}else if(lugar==3){
						comprobadorPersIndividualGratuitas(codigo, usuario);	
						}
					}
				}
			});
	}
	function cancelarProducto(producto,usuario){
	$.ajax({
				type: "POST",
				url: "/cancelarProductos.php",
				data: "producto="+producto,
				dataType: "html",
				beforeSend: function(){
				},
				complete: function(){
					
				},
				success: function(msg) {
					if(msg==0){
						window.location="/resultados.php";
					}else if(msg==1){
						window.location="/resultados.php";
					}
				
				}
			});
	}
	function comprarProducto(producto,usuario){
	$.ajax({
				type: "POST",
				url: "/comprarProductos.php",
				data: "producto="+producto,
				dataType: "html",
				beforeSend: function(){
				},
				complete: function(){
					
				},
				success: function(msg) {
					if(msg==1){
						alert("Para poder comprar, tienes que iniciar sesion.");
						window.location="/entrar.php";
					}else if(msg==0){
						window.location="/comprar/"+producto+"";
					}else if(msg==2){
						window.location="/comprarProducto/"+producto+"";
					}else if(msg==6){
						alert("No puedes comprar un producto con la subasta finalizada hace mas de 30 minutos.");
						window.location="/resultados.php";
					}else if(msg==7){
						alert("No puedes comprar el producto de una misma subasta 2 veces.");
						window.location="/resultados.php";
					}
				
				}
			});
	}
function hacerPuja(producto,codigo,usuario,precio_gastado_actual,precioRecomendado){
	$.ajax({
				type: "POST",
				url: "/pujar/"+producto+"/"+codigo+"/",
				data: "producto="+producto+"&codigo="+codigo+"&precio_gastado_actual="+precio_gastado_actual+"&precioRecomendado="+precioRecomendado,
				dataType: "html",
				beforeSend: function(){
				},
				complete: function(){
					
				},
				success: function(msg) {
					if(msg==0){
						alert("Para poder pujar, tienes que iniciar sesion.");
						window.location="/entrar.php";
					}else if(msg==1){
						alert("Para poder pujar, tienes que iniciar sesion.");
						window.location="/entrar.php";
					}else if(msg==2){
						alert("No te quedan suficientes Ooks.");
						window.location="/private_ookbid/compra_ooks/";
					}else if(msg==3){
						comprobadorPersIndividual(codigo, usuario);
					}else if(msg==4){
						alert("No puedes pujar 2 veces seguidas.");
					}else if(msg==5){
						alert("La subasta ya ha finalizado.");
					}
				
				}
			});
	}
	function hacerPuja2(producto,codigo,usuario,precioRecomendado){
	$.ajax({
				type: "POST",
				url: "/pujar/"+producto+"/"+codigo+"/",
				data: "producto="+producto+"&codigo="+codigo+"&precioRecomendado="+precioRecomendado,
				dataType: "html",
				beforeSend: function(){
				},
				complete: function(){
					
				},
				success: function(msg) {
					if(msg==0){
						alert("Para poder pujar, tienes que iniciar sesion.");
						window.location="/entrar.php";
					}else if(msg==1){
						alert("Para poder pujar, tienes que iniciar sesion.");
						window.location="/entrar.php";
					}else if(msg==2){
						alert("No te quedan suficientes Ooks.");
						window.location="/private_ookbid/compra_ooks/";
					}else if(msg==3){
						//comprobador_pcontrolPers(codigo, usuario);
					}else if(msg==4){
						alert("No puedes pujar 2 veces seguidas.");
					}else if(msg==5){
						alert("La subasta ya ha finalizado.");
					}
				
				}
			});
	}
	function hacerPuja3(producto,codigo,usuario,precioRecomendado){
	$.ajax({
				type: "POST",
				url: "/pujar/"+producto+"/"+codigo+"/",
				data: "producto="+producto+"&codigo="+codigo+"&precioRecomendado="+precioRecomendado,
				dataType: "html",
				beforeSend: function(){
				},
				complete: function(){
					
				},
				success: function(msg) {
					if(msg==0){
						alert("Para poder pujar, tienes que iniciar sesion.");
						window.location="/entrar.php";
					}else if(msg==1){
						alert("Para poder pujar, tienes que iniciar sesion.");
						window.location="/entrar.php";
					}else if(msg==2){
						alert("No te quedan suficientes Ooks.");
						window.location="/private_ookbid/compra_ooks/";
					}else if(msg==3){
						//comprobadorPers(codigo, usuario);
					}else if(msg==4){
						alert("No puedes pujar 2 veces seguidas.");
					}else if(msg==5){
						alert("La subasta ya ha finalizado.");
					}
				
				}
			});
	}
	function hacerPuja4(producto,codigo,usuario,precioRecomendado){
	$.ajax({
				type: "POST",
				url: "/pujarGratis/"+producto+"/"+codigo+"/",
				data: "producto="+producto+"&codigo="+codigo+"&precioRecomendado="+precioRecomendado,
				dataType: "html",
				beforeSend: function(){
				},
				complete: function(){
					
				},
				success: function(msg) {
					if(msg==0){
						alert("Para poder pujar, tienes que iniciar sesion.");
						window.location="/entrar.php";
					}else if(msg==1){
						alert("Para poder pujar, tienes que iniciar sesion.");
						window.location="/entrar.php";
					}else if(msg==2){
						alert("Consigue Ooks gratuitos.");
						window.location="/pagina/como_conseguir_ooks_gratuitos/";
					}else if(msg==3){
						//comprobadorPers(codigo, usuario);
					}else if(msg==4){
						alert("No puedes pujar 2 veces seguidas.");
					}else if(msg==5){
						alert("La subasta ya ha finalizado.");
					}
				
				}
			});
	}
	function hacerPuja5(producto,codigo,usuario,precioRecomendado){
	$.ajax({
				type: "POST",
				url: "/pujarGratis/"+producto+"/"+codigo+"/",
				data: "producto="+producto+"&codigo="+codigo+"&precioRecomendado="+precioRecomendado,
				dataType: "html",
				beforeSend: function(){
				},
				complete: function(){
					
				},
				success: function(msg) {
					if(msg==0){
						alert("Para poder pujar, tienes que iniciar sesion.");
						window.location="/entrar.php";
					}else if(msg==1){
						alert("Para poder pujar, tienes que iniciar sesion.");
						window.location="/entrar.php";
					}else if(msg==2){
						alert("Consigue Ooks gratuitos.");
						window.location="/pagina/como_conseguir_ooks_gratuitos/";
					}else if(msg==3){
						comprobadorPersIndividualGratuitas(codigo, usuario);
					}else if(msg==4){
						alert("No puedes pujar 2 veces seguidas.");
					}else if(msg==5){
						alert("La subasta ya ha finalizado.");
					}
				
				}
			});
	}
	function eliminarOokbot(id,codigo,usuario){
	$.ajax({
				type: "POST",
				url: "/php/eliminarOokbot.php",
				data: "id="+id,
				dataType: "html",
				beforeSend: function(){
				},
				complete: function(){
					
				},
				success: function(msg) {
					if(msg==1){
						comprobadorIndividual(codigo, usuario);
					}
				}
			});
	}
	function eliminarOokbot2(id,codigo,usuario){
	$.ajax({
				type: "POST",
				url: "/php/eliminarOokbot.php",
				data: "id="+id,
				dataType: "html",
				beforeSend: function(){
				},
				complete: function(){
					
				},
				success: function(msg) {
					if(msg==1){
						comprobador_pcontrol_ookbots(codigo, usuario);
					}
				}
			});
	}
	
	function activarOokbot(codigo,usuario){
		ooks_form=document.formOokbot.ooks_form.value;
		ooks_form = ooks_form.split(",").join(".");
		desde_form=document.formOokbot.desde_form.value;
		desde_form = desde_form.split(",").join(".");
		hasta_form=document.formOokbot.hasta_form.value;
		hasta_form = hasta_form.split(",").join(".");
		ooks_form =new Number(ooks_form);
		desde_form=new Number(desde_form);
		hasta_form=new Number(hasta_form);
		if (isNaN(ooks_form)==true || ooks_form==""){
			alert("En el campo Cuantos ooks quieres pujar? escribe un numero mayor de 0 ej: 5");
			return;
			}
		if (isNaN(desde_form)==true || desde_form==""){
			alert("En el campo Puja desde escribe un numero mayor de 0 ej: 0,10");
			return;
			}
		if (isNaN(hasta_form)==true || hasta_form==""){
			alert("En el campo Puja hasta escribe un numero mayor de 0 ej: 0,10");
			return;
			}
		ooks_form=round(ooks_form);
		desde_form=round(desde_form,2);
		hasta_form=round(hasta_form,2);
		
		if (desde_form>=hasta_form){
			alert("Compruebe que ha introducido los campos correctamente");
			return;
			}
			
	$.ajax({
				type: "POST",
				url: "/php/activarOokbot.php",
				data: "ooks_form="+ooks_form+"&desde_form="+desde_form+"&hasta_form="+hasta_form+"&codigo="+codigo,
				dataType: "html",
				beforeSend: function(){
				},
				complete: function(){
					
				},
				success: function(msg) {
					
					if(msg==1){
						comprobadorIndividual(codigo, usuario);
					}else if(msg==0){
					alert("Para poder pujar, tienes que iniciar sesion.");	
					window.location="/entrar.php";
					}else{
					alert(msg);	
					}
				}
			});
	}
	function diseloAmigo(){	
	
	
		if(mail($("#Amail").val())!=true){
			alert("El e-mail introducido no es valido");
			return;
		}
		if($("#Anombre").val().length<1){
			alert("Asegurate de introducir un nombre");
			return;
		}
		document.fomulito.action="/regAmigo.php";
		document.fomulito.submit();
	}
	function compruebaRegistro(){	
		
		if(document.getElementById("Racepto").checked==false){
			alert("Tienes que aceptar los TERMINOS Y CONDICIONES y LA POLITICA DE PRIVACIDAD");
			return;
		}
		if($("#Rusuario").val().length<3 || $("#Rusuario").val().length>20){
			alert("El nombre de usuario tiene que tener entre 3 y 20 caracteres");
			return;
		}
		if($("#Rcontrasena").val().length<6){
			alert("La contrase\u00f1a tiene que tener un m\u00ednimo de 6 caracteres");
			return;
		}
		if($("#Rcontrasena").val()!=$("#Rcontrasena2").val()){
			alert("Asegurate de repetir correctamente la contrase\u00f1a");
			return;
		}
		if(mail($("#Rmail").val())!=true){
			alert("El e-mail introducido no es valido");
			return;
		}
		if($("#Rmail").val()!=$("#Rmail2").val()){
			alert("Asegurate de repetir correctamente el e-mail");
			return;
		}
		if($("#Rnombre").val().length<1){
			alert("Asegurate de introducir un nombre");
			return;
		}
		if($("#Rapellidos").val().length<1){
			alert("Asegurate de introducir los apellidos");
			return;
		}
		if(valida_nif_cif_nie($("#Rdni").val())!=1){
			alert("El DNI introducido no es valido, recuerda: Si es un NIF tienes que introducir la letra al final y si es un NIE la tienes que introducir al principio.");
			return;
		}
		if($("#Rdireccion").val().length<1){
			alert("Debes introducir una direcci\u00f3n para poder enviarte tus art\u00edculos ganados");
			return;
		}
		if($("#Rcp").val().length<1){
			alert("No has rellenado el C\u00f3digo Postal");
			return;
		}
		if($("#Rciudad").val().length<1){
			alert("Debes introducir una ciudad donde poder enviarte tus art\u00edculos ganados");
			return;
		}
		if($("#Rprovincia").val()==0){
			alert("Asegurate de introducir una provincia");
			return;
		}
		if(isValidTelef($("#Rmovil").val())!=true & isValidTelef($("#Rfijo").val())!=true){
			alert("Debes introducir un tel\u00e9fono valido, m\u00f3vil o fijo");
			return;
		}
		if(document.getElementById("Rboletin").checked==false){
		$("#Rboletin2").val(0);
		}else{
		$("#Rboletin2").val(1);	
		}
		document.fomulito.action="/regFrom.php";
		document.fomulito.submit();
	}
	
	function compruebaRegistro2(){	
		if(mail($("#Rmail").val())!=true){
			alert("El e-mail introducido no es valido");
			return;
		}
		if($("#Rmail").val()!=$("#Rmail2").val()){
			alert("Asegurate de repetir correctamente el e-mail");
			return;
		}
		if($("#Rdireccion").val().length<1){
			alert("Debes introducir una direcci\u00f3n.");
			return;
		}
		if($("#Rcp").val().length<1){
			alert("No has rellenado el C\u00f3digo Postal");
			return;
		}
		if($("#Rciudad").val().length<1){
			alert("Debes introducir una ciudad.");
			return;
		}
		if($("#RdireccionEnvio").val().length<1){
			alert("Debes introducir una direcci\u00f3n para poder enviarte tus art\u00edculos ganados");
			return;
		}
		if($("#RcpEnvio").val().length<1){
			alert("No has rellenado el C\u00f3digo Postal para poder enviarte tus art\u00edculos ganados");
			return;
		}
		if($("#RciudadEnvio").val().length<1){
			alert("Debes introducir una ciudad donde poder enviarte tus art\u00edculos ganados");
			return;
		}
		if($("#RnombreEnvio").val().length<1){
			alert("Asegurate de introducir el nombre de la direcci\u00f3n de envio");
			return;
		}
		if($("#RapellidosEnvio").val().length<1){
			alert("Asegurate de introducir los apellidos de la direcci\u00f3n de envio");
			return;
		}
		
		document.fomulito.action="/regFromupdate.php";
		document.fomulito.submit();
	}
	function valida_nif_cif_nie(a) 
{
	
	var temp=a.toUpperCase();
	var cadenadni="TRWAGMYFPDXBNJZSQVHLCKE";
 
	if (temp!==''){
		//si no tiene un formato valido devuelve error
		if ((!/^[A-Z]{1}[0-9]{7}[A-Z0-9]{1}$/.test(temp) && !/^[T]{1}[A-Z0-9]{8}$/.test(temp)) && !/^[0-9]{8}[A-Z]{1}$/.test(temp))
		{
			return 0;
		}
 
		//comprobacion de NIFs estandar
		if (/^[0-9]{8}[A-Z]{1}$/.test(temp))
		{
			posicion = a.substring(8,0) % 23;
			letra = cadenadni.charAt(posicion);
			var letradni=temp.charAt(8);
			if (letra == letradni)
			{
			   	return 1;
			}
			else
			{
				return -1;
			}
		}
 
		//algoritmo para comprobacion de codigos tipo CIF
		suma = parseInt(a.charAt(2))+parseInt(a.charAt(4))+parseInt(a.charAt(6));
		for (i = 1; i < 8; i += 2)
		{
			temp1 = 2 * parseInt(a.charAt(i));
			temp1 += '';
			temp1 = temp1.substring(0,1);
			temp2 = 2 * parseInt(a.charAt(i));
			temp2 += '';
			temp2 = temp2.substring(1,2);
			if (temp2 == '')
			{
				temp2 = '0';
			}
 
			suma += (parseInt(temp1) + parseInt(temp2));
		}
		suma += '';
		n = 10 - parseInt(suma.substring(suma.length-1, suma.length));
 
		//comprobacion de NIFs especiales (se calculan como CIFs)
		if (/^[KLM]{1}/.test(temp))
		{
			if (a.charAt(8) == String.fromCharCode(64 + n))
			{
				return 1;
			}
			else
			{
				return -1;
			}
		}
 
		//comprobacion de CIFs
		if (/^[ABCDEFGHJNPQRSUVW]{1}/.test(temp))
		{
			temp = n + '';
			if (a.charAt(8) == String.fromCharCode(64 + n) || a.charAt(8) == parseInt(temp.substring(temp.length-1, temp.length)))
			{
				return 1;
			}
			else
			{
				return -1;
			}
		}
 
		//comprobacion de NIEs
		//T
		if (/^[T]{1}[A-Z0-9]{8}$/.test(temp))
		{
			if (a[8] == /^[T]{1}[A-Z0-9]{8}$/.test(temp))
			{
				return 1;
			}
			else
			{
				return -1;
			}
		}
 
		//XYZ
		if (/^[XYZ]{1}/.test(temp))
		{
			pos = str_replace(['X', 'Y', 'Z'], 0, ['0','1','2'], temp).substring(0, 8) % 23;
			if (a.charAt(8) == cadenadni.substring(pos, pos + 1))
			{
				return 1;
			}
			else
			{
				return -1;
			}
		}
	}
 
	return 0;
}

function str_replace(search, position, replace, subject) {

var f = search, r = replace, s = subject, p = position;
var ra = r instanceof Array, sa = s instanceof Array, f = [].concat(f), r = [].concat(r), i = (s = [].concat(s)).length;

while (j = 0, i--) {
if (s[i]) {
while (s[p] = s[p].split(f[j]).join(ra ? r[j] || "" : r[0]), ++j in f){};
}
};

return sa ? s : s[0];

}

	function nombreUsuario(nombre){
	text=escape(nombre);
  text=text.replace(/(%E1|%E0|%E4|%E2|%E5)/g,'a');
  text = text.replace(/(%E9|%E8|%EB|%EA)/g, 'e');
  text = text.replace(/(%ED|%EC|%EF|%EE)/g, 'i');
  text = text.replace(/(%F3|%F2|%F6|%F4)/g, 'o');
  text = text.replace(/(%FA|%F9|%FC|%FB)/g, 'u');
  text = text.replace(/(%FD|%FF)/g, 'y');
  text = text.replace(/(%F1)/g, 'n');
  text = text.replace(/(%E7)/g, 'c');
  text=text.replace(/(%C1|%C0|%C4|%C2|%C5)/g,'A');
  text = text.replace(/(%C9|%C8|%CB|%CA)/g, 'E');
  text = text.replace(/(%CD|%CC|%CF|%CE)/g, 'I');
  text = text.replace(/(%D3|%D2|%D6|%D4)/g, 'O');
  text = text.replace(/(%DA|%D9|%DC|%DB)/g, 'U');
  text = text.replace(/(%DD|%u0178)/g, 'Y');
  text = text.replace(/(%D1)/g, 'N');
  text = text.replace(/(%C7)/g, 'C');
  text = text.replace(/(26)/g, ' ');
  text = text.replace(/(%27|%22)/g, '');
  text = text.replace(/%20/g, '_');
  text = text.replace(/\s+/g, '_');
  text = text.replace(/(_)$/g, '');
  text = text.replace(/^(_)/g, '');	
  text = unescape(text);
  text = text.replace(/[^a-z|A-Z|0-9-|(_)]/g, '');
  
  alert("Se han eliminado acentos y espacios de tu nombre de usuario.");
 $("#Rusuario").val(text);
	}
	function 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 cambiarcontrasena(){	
		if($("#Rcontrasena").val().length<6){
			alert("La contrase\u00f1a tiene que tener un m\u00ednimo de 6 caracteres.");
			return;
		}
		if($("#Rcontrasena").val()!=$("#Rcontrasena2").val()){
			alert("Asegurate de repetir correctamente la contrase\u00f1a");
			return;
		}
		document.fomulito.action="/regFromupdatecontrasena.php";
		document.fomulito.submit();
	}
	
	
	function cancelarcuenta(){	
		$("#seguro").html("Estas seguro que quieres borrar esta cuenta?<br><div class='dos'><a href='javascript:cancelarcuenta2(&#34;si&#34;);'>SI</a></div><div class='tres'><a href='javascript:cancelarcuenta2(&#34;no&#34;);'>NO</a></div>");
	}
function cancelarcuenta2(estado){	
		if(estado=="si"){
		$.ajax({
				type: "POST",
				url: "/php/cancelar_cuenta.php",
				data: "id="+estado,
				dataType: "html",
				beforeSend: function(){
				},
				complete: function(){
					
				},
				success: function(msg) {
					if(msg==1){
						alert("Esta cuenta ha sido borrada correctamente");
					}else{
						alert("Error: vuelve a intentarlo luego, gracias.");
				}window.location="/";}
			});
		}else{
	window.location="/";		
	}
	}

function isValidNif(abc){
dni=abc.substring(0,abc.length-1);
let=abc.charAt(abc.length-1);
if (!isNaN(let)) {
//alert('Falta la letra');
return false;
}else{
cadena = "TRWAGMYFPDXBNJZSQVHLCKET";
posicion = dni % 23;
letra = cadena.substring(posicion,posicion+1);
if (letra!=let.toUpperCase()){
//alert("Nif no válido");
return false;
}
}
//alert("Nif válido")
return true;
}

function isValidTelef(num){
if(num.length < 9){
return false;
}else if(isNaN( num )){
return false;
}else{
return true;
}
}


function insertarCompra(id, usuario){
	var producto=new Array("Ookbid 40","Ookbid 60","Ookbid 100","Ookbid 200","Ookbid 500");
	var precio=new Array("20.00","30.00","50.00","100.00","250.00");
	
	$("#estadoCompra").html("<form name='pagar' id='pagar' action='https://www.paypal.com/cgi-bin/webscr' method='post'><input type='hidden' name='business' value='danyogroup@gmail.com'><input type='hidden' name='cmd' value='_xclick'><input type='hidden' name='notify_url' value='http://www.ookbid.com/compraA.php'><input type='hidden' name='item_name' value='"+producto[id]+"'><input type='hidden' name='item_number' value='"+id+"'><input type='hidden' name='amount' value='"+precio[id]+"'><input type='hidden' name='currency_code' value='EUR'><input type='hidden' name='custom' value='"+usuario+"'><input type='hidden' name='return' value='http://ookbid.com'></form> ");
	
	document.pagar.submit();
}

function insertarCompra2(id, usuario){
	if(document.seleccionar.seleccionar_pago[0].checked){
		var producto=new Array("Ookbid 40","Ookbid 60","Ookbid 100","Ookbid 200","Ookbid 500");
	var precio=new Array("20.00","30.00","50.00","100.00","250.00");
	
	$("#estadoCompra").html("<form name='pagar' id='pagar' action='https://www.paypal.com/cgi-bin/webscr' method='post'><input type='hidden' name='business' value='danyogroup@gmail.com'><input type='hidden' name='cmd' value='_xclick'><input type='hidden' name='notify_url' value='http://www.ookbid.com/compraA.php'><input type='hidden' name='item_name' value='"+producto[id]+"'><input type='hidden' name='item_number' value='"+id+"'><input type='hidden' name='amount' value='"+precio[id]+"'><input type='hidden' name='currency_code' value='EUR'><input type='hidden' name='custom' value='"+usuario+"'><input type='hidden' name='return' value='http://ookbid.com'></form> ");
	
	document.pagar.submit();
			return;
		}else if(document.seleccionar.seleccionar_pago[1].checked){
			
			var producto=new Array("Ookbid 40","Ookbid 60","Ookbid 100","Ookbid 200","Ookbid 500");
	var precio=new Array("20.00","30.00","50.00","100.00","250.00");
	
	$("#estadoCompra").html("<form name='pagar' id='pagar' action='/e.php' method='post'><input type='hidden' name='item_name' value='"+producto[id]+"'><input type='hidden' name='item_number' value='"+id+"'><input type='hidden' name='amount' value='"+precio[id]+"'><input type='hidden' name='user' value='"+usuario+"'></form> ");
	
	document.pagar.submit();
			return;
		}
	
}
function realizarCompra(id, usuario, producto, precio){
	if(document.seleccionar.seleccionar_pago[0].checked){
	$("#compraPagar").html("<form name='pagar' id='pagar' action='https://www.paypal.com/cgi-bin/webscr' method='post'><input type='hidden' name='business' value='danyogroup@gmail.com'><input type='hidden' name='cmd' value='_xclick'><input type='hidden' name='notify_url' value='http://www.ookbid.com/compraP.php'><input type='hidden' name='item_name' value='"+producto+"'><input type='hidden' name='item_number' value='"+id+"'><input type='hidden' name='amount' value='"+precio+"'><input type='hidden' name='currency_code' value='EUR'><input type='hidden' name='custom' value='"+usuario+"'><input type='hidden' name='return' value='http://ookbid.com'></form> ");
	
	document.pagar.submit();
	return;
	}else if(document.seleccionar.seleccionar_pago[1].checked){
		$("#compraPagar").html("<form name='pagar' id='pagar' action='/f.php' method='post'><input type='hidden' name='item_name' value='"+producto+"'><input type='hidden' name='item_number' value='"+id+"'><input type='hidden' name='amount' value='"+precio+"'><input type='hidden' name='user' value='"+usuario+"'></form> ");
		document.pagar.submit();
	return;
	}
}
function realizarCompraB(id, usuario, producto, precio){
	$.ajax({
				type: "POST",
				url: "/comprarProductos2.php",
				data: "producto="+id,
				dataType: "html",
				beforeSend: function(){
				},
				complete: function(){
					
				},
				success: function(msg) {
					//alert(msg);
					if(document.seleccionar.seleccionar_pago[0].checked){
	$("#compraPagar").html("<form name='pagar' id='pagar' action='https://www.paypal.com/cgi-bin/webscr' method='post'><input type='hidden' name='business' value='danyogroup@gmail.com'><input type='hidden' name='cmd' value='_xclick'><input type='hidden' name='notify_url' value='http://www.ookbid.com/compraPVP.php'><input type='hidden' name='item_name' value='"+producto+"'><input type='hidden' name='item_number' value='"+id+"'><input type='hidden' name='amount' value='"+precio+"'><input type='hidden' name='currency_code' value='EUR'><input type='hidden' name='custom' value='"+usuario+"'><input type='hidden' name='return' value='http://ookbid.com'></form> ");
	
	document.pagar.submit();
	return;
	}else if(document.seleccionar.seleccionar_pago[1].checked){
		$("#compraPagar").html("<form name='pagar' id='pagar' action='/g.php' method='post'><input type='hidden' name='item_name' value='"+producto+"'><input type='hidden' name='item_number' value='"+id+"'><input type='hidden' name='amount' value='"+precio+"'><input type='hidden' name='user' value='"+usuario+"'></form> ");
		document.pagar.submit();
	return;
	}
				}
			});
	
	
}
function realizarCompraC(id, usuario, producto, precio){

		$("#compraPagar").html("<form name='pagar' id='pagar' action='/h.php' method='post'><input type='hidden' name='item_name' value='"+producto+"'><input type='hidden' name='item_number' value='"+id+"'><input type='hidden' name='amount' value='"+precio+"'><input type='hidden' name='user' value='"+usuario+"'></form> ");
		document.pagar.submit();
	
}



