// JavaScript Document
	
	
	function cambia(id)
	{
		
		var foto1 = document.getElementById("foto1");
		var miurl = foto1.src;
		var foto2 = document.getElementById(id);
		
		foto1.src = foto2.src;
		foto2.src = miurl;		
	}
	
	function validaPuja(form, creditos, creditosPorPuja)
	{	
		mif = document.getElementById(form);
		if( parseFloat(creditos) >= parseFloat(creditosPorPuja))
		{
			if(mif.entero.value != "" && mif.decimal.value != "")
			{
				if(confirm("La puja que vas a realizar es por " + mif.entero.value + "." + mif.decimal.value + " €, ¿Estas seguro?"))
				{
					mif.action = "insertarp.asp"
					return true;
				}
				else
				{
					document.getElementById("entero").select();
					return false;
				}
			}
			else
			{
				alert("Debes rellenar los valores de tu puja");
				document.getElementById("entero").focus();
				return false;
			}
		}
		else
		{
			alert("Esta operación requiere " + parseFloat(creditosPorPuja) + " Cr. y tu saldo (" + parseFloat(creditos) + " Cr.) no permite realizarla")
			return false;
		}
	}

	function validaMultiPuja(form, creditos, creditosPorPuja)
	{	
		mif = document.getElementById(form);
		linf = Math.round(100*(parseFloat("0"+mif.li_entero.value)+ parseFloat("0."+mif.li_decimal.value)));
		lsup = Math.round(100*(parseFloat("0"+mif.ls_entero.value)+ parseFloat("0."+mif.ls_decimal.value)));
				
		//alert(linf < lsup);		
		//alert("linf:" + linf + " lsup:"+lsup);
		
		
		if(linf < lsup) 
		{
			
			total = (lsup - linf) + 1;
			cuantos = total;
			
			//alert(parseFloat(total) + " " + parseFloat(creditosPorPuja));
			total = parseFloat(total) * parseFloat(creditosPorPuja);
			total = total.toFixed(2);
			//alert(cuantos + " " + creditosPorPuja + " " + total + " " + creditos);
			if(parseFloat(total) <= parseFloat(creditos))
			{					
				if(confirm('Está operación requiere ' + total + ' €Créditos\n¿Deseas realizar la multipuja?'))
				{
					mif.action = "insertarpMulti.asp";
					return true;
				}
				else
				{
					return false;
				}
			}
			else
			{
				alert("Esta operación requiere " + parseFloat(total) + " €Créditos. Tu saldo (" + parseFloat(creditos) + " €Créditos) no permite realizarla.")
				return false;
			}
		}
		else
		{
			alert("Límite inferior debe ser menor que límite superior")
			return false;
		}		
	}




	function cambiacreditos(tipo)
	{
		if(tipo == "paypal")
		{
			midiv = document.getElementById("SelSinPay");
			midiv.style.display = "none";
	
			midiv2 = document.getElementById("SelConPay");
			midiv2.style.display = "block";
	
			misel1 = document.getElementById("creditosSP");
			misel1.disabled = "disabled";
			
			misel2 = document.getElementById("creditosCP");
			misel2.disabled = "";
		}
		else
		{
			midiv = document.getElementById("SelSinPay");
			midiv.style.display = "block";
	
			midiv2 = document.getElementById("SelConPay");
			midiv2.style.display = "none";
	
			misel1 = document.getElementById("creditosSP");
			misel1.disabled = "";
			
			misel2 = document.getElementById("creditosCP");
			misel2.disabled = "disabled";	
		}
		
	}
	
	function cambiafinalizacion(fecha, id, sincron)
	{
		//alert(fecha);
	
		

		trozos = fecha.split(" ");
		mifecha = trozos[0];
		trozosfecha = trozos[0].split("/");
		dia = trozosfecha[0];
		mes = trozosfecha[1];
		anyo = trozosfecha[2];
		
		trozoshora = trozos[1].split(":");
		hora = trozoshora[0];
		minuto = trozoshora[1];
		segundo = trozoshora[1];	
		
		fecha1 = new Date(anyo, mes-1, dia, hora, minuto, (segundo-desfase));
		fecha2 = new Date();
		
		
		a1 = fecha1.getTime();
		a2 = fecha2.getTime();
		
		dif = Math.round(( a1-a2 ) / 1000) ;
		
		//alert(fecha1 + " " + fecha2 + " dif " + dif);
		
		rdias = Math.floor(dif/86400);
		restsegs = Math.floor(dif%86400);
		rhoras = Math.floor(restsegs/3600);
		resthoras = Math.floor(restsegs%3600);
		rmins = Math.floor(resthoras/60);
		rsegs = Math.floor(resthoras%60);
		
		//alert(dif + " " + rdias + " " + restsegs + " " + rhoras + " " + resthoras + " " + rmins + " " + rsegs);
		mid = "dias" + id;
		mih = "horas" + id;
		mim = "minutos"+id;
		mis = "segundos"+id;
		
		if(dif < 0) 
			setTimeout("window.location.reload()",1000);
		//document.getElementById("kk").innerHTML = desfase + " " + dif; 
		document.getElementById(mid).innerHTML = rdias; 
		document.getElementById(mih).innerHTML = rhoras;
		document.getElementById(mim).innerHTML = rmins;
		//document.getElementById(mis).innerHTML = rsegs;
	}
	
	function aceptamodificar(form)
	{
		if(confirm("¿Está seguro que desea modificar sus datos?"))
		{
			if(validateOnSubmit(form))
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		else
		{
			return false;
		}
	}
	
	function sincroniza(hoy)
	{
		fecha2 = new Date();
		Strozos = hoy.split(" ");
		Smifecha = Strozos[0];
		Strozosfecha = Strozos[0].split("/");
		Sdia = Strozosfecha[0];
		Smes = Strozosfecha[1];
		Sanyo = Strozosfecha[2];
		
		Strozoshora = Strozos[1].split(":");
		Shora = Strozoshora[0];
		Sminuto = Strozoshora[1];
		Ssegundo = Strozoshora[1];	
		
		fechaS = new Date(Sanyo,Smes-1,Sdia,Shora,Sminuto,Ssegundo);
		desfase = Math.round( (fechaS.getTime() - fecha2.getTime()) / 1000 );			
	}