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

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

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

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

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//script por Tunait 
	var ventana 
	var cont=0 
	var titulopordefecto = "Perico de los palotes" //texto por defecto a mostrar en la barra de título en caso de omitir el argumento titulo 

	function afoto(cual,titulo) 
	{ 
		if(cont==1){ventana.close();ventana=null} 
		if(titulo==null){titulo=titulopordefecto} 
		ventana=window.open('','ventana','resizable=yes,scrollbars=no') 
		ventana.document.write('<html><head><title>' + titulo + '</title></head><body style="overflow:hidden" marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" scroll="no" onUnload="opener.cont=0"><img src="' + cual + '" onLoad="opener.redimensionar(this.width, this.height)"></body></html>') 
		ventana.document.close() 
	cont++ 
	}
	 
	function redimensionar(ancho,alto) 
	{ 
		ventana.resizeTo(ancho+12,alto+28) 
		ventana.moveTo((screen.width-ancho)/2,(screen.height-alto)/2) //centra la ventana. Eliminar si no se quiere centrar el popup 
	} 
	
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	function validar_anuncio(estado,idanuncio)
	{
		var numvf = document.getElementById('vf').value;
		//alert('numvf = '+numvf)
		//alert('estado = '+estado)
		//alert('idanuncio = '+idanuncio)
		if(document.getElementById('titulo').value == '')
		{
			alert("El campo 'titulo' no puede estar vacio");
		//	document.getElementById('titulo').focus();
			return 0;
		}
		/*
		var cadena_foto1 = document.getElementById('foto1');
		var cadena_foto2 = document.getElementById('foto2');
		var cadena_foto3 = document.getElementById('foto3');
		
		texto_foto1 = new Array();
		texto_foto2 = new Array();
		texto_foto3 = new Array();
		
		texto_foto1 = cadena_foto1.split('\\');
		texto_foto2 = cadena_foto2.split('\\');
		texto_foto3 = cadena_foto3.split('\\');
		
		for(i=0;i<texto_foto1.length;i++)
		{
			document.write(""+texto_foto1[i]+"<br>");
		}
		/*
		if(document.getElementById('foto1').value == '')
		{
			alert("El campo 'titulo' no puede estar vacio");
		//	document.getElementById('titulo').focus();
			return 0;
		}
		if(document.getElementById('foto2').value == '')
		{
			alert("El campo 'titulo' no puede estar vacio");
		//	document.getElementById('titulo').focus();
			return 0;
		}
		if(document.getElementById('foto3').value == '')
		{
			alert("El campo 'titulo' no puede estar vacio");
		//	document.getElementById('titulo').focus();
			return 0;
		}
		*/
		if(document.getElementById('idcategorias').value == 0)
		{
			alert("Tienes que elegir una categoria");
			document.getElementById('idcategorias').focus();
			return 0;
		}
		if(document.getElementById('idsubcategorias').value == 0)
		{
			alert("Tienes que elegir una categoria");
			document.getElementById('idsubcategorias').focus();
			return 0;
		}
		if(document.getElementById('contenido').value == '')
		{
			alert("El campo 'contenido' no puede estar vacio");
			document.getElementById('contenido').focus();
			return 0;
		}
		if(document.getElementById('cambio1').value == '')
		{
			alert("Debe haber un cambio como mínimo.");
			document.getElementById('cambio1').focus();
			return 0;
		}
		if(document.getElementById('vf').value < 5)
		{
			alert('El valor mínimo ha de ser de 5 VF\'s');
			document.getElementById('vf').focus();
			return 0;
		}
			enviar_formulario(estado,idanuncio);		
	}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	function enviar_formulario(estado,idanuncio)
	{ 
		if(estado == 1){
			document.forms[0].action=" modificaranuncio.php?valor=1&idanuncio=" + idanuncio;	
		}
		else if(estado == 2){
			document.forms[0].action="anunciar.php?valor=1";
		}
		document.fanuncio.submit();
	}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	function enviar_formulario_usuario(estado,idpais,idusuario)
	{ 
		if(estado == 1)
		{
			document.forms[0].action="pc.php?valor=1&idusuario=" + idusuario;
		}
		else if(estado == 2)
		{
			document.forms[0].action="formregistro.php?valor=1&idpais=" + idpais;
		}
		
		document.fusuario.submit();
	}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	function validar_anuncio_prueba(estado,idanuncio)
	{
		var numvf = document.getElementById('vf').value
		//alert('numvf = '+numvf)
		if(document.getElementById('titulo').value == '')
		{
			alert("El campo 'titulo' no puede estar vacio");
			document.getElementById('titulo').focus();
		}
		else if(document.getElementById('idcategorias').value == 0)
		{
			alert("Tienes que elegir una categoria");
			document.getElementById('idcategorias').focus();
		}
		else if(document.getElementById('idsubcategorias').value == 0)
		{
			alert("Tienes que elegir una categoria");
			document.getElementById('idsubcategorias').focus();
		}
		else if(document.getElementById('contenido').value == '')
		{
			alert("El campo 'contenido' no puede estar vacio");
			document.getElementById('contenido').focus();
		}
		else if(document.getElementById('vf').value < 5)
		{
			alert('El valor mínimo ha de ser de 5 VF\'s');
			document.getElementById('vf').focus();
		}
		else
		{	
			enviar_formulario_vista(estado,idanuncio);			
		}
	}




	function enviar_formulario_vista(estado,idanuncio)
	{ 
		if(estado == 1)
		{
			document.forms[0].action="vistaprevia.php?idanuncio=" + idanuncio;		
		}
		else if(estado == 2)
		{
			document.forms[0].action="vistaprevia.php?idanuncio=" + idanuncio;	
		}
		document.fanuncio.submit();
	}
	
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	function validar_usuario(estado,idpais,idusuario,politica)
	{
		if(document.getElementById('nick').value == '')
		{
			alert("El campo 'nick' no puede estar vacio");
			document.getElementById('nick').focus();
		}
		else if(document.getElementById('email').value == '')
		{
			alert("El campo 'email' no puede estar vacio");
			document.getElementById('email').focus();
		}
 		/* Se verifica el dato escrito 
		Si no contiene el simbolo @ o . se ejecuta la condición */
		else if (document.getElementById('email').value.indexOf('@', 1) == -1 || document.getElementById('email').value.indexOf('.',document.getElementById('email').value.indexOf('@', 0)) == -1) 
		{
 			alert("Dirección de e-mail inválida"); 
			document.getElementById('email').focus();
		}			
		else if(document.getElementById('password').value == "")
		{
			alert("El campo 'contraseña' no puede estar vacio");
			document.getElementById('password').focus();
		}
		else if(document.getElementById('password1').value == '')
		{
			alert("Tienes que volver a introducir la contraseña");
			document.getElementById('password1').focus();
		}
		else if(document.getElementById('nombre').value == '')
		{
			alert("El campo 'nombre' no puede estar vacio");
			document.getElementById('nombre').focus();
		}
		else if(document.getElementById('dia').value == '' || document.getElementById('mes').value == '' || document.getElementById('anno').value == '')
		{
			alert("Tiene que introducir el día, mes y año [00][00][0000]");
			document.getElementById('dia').focus();
		}	
		else if(document.getElementById('telefono').value == '')
		{
			alert("El campo 'telefono' no puede estar vacio");
			document.getElementById('telefono').focus();
		}	
		else if(document.getElementById('direccion').value == '')
		{
			alert("El campo 'direccion' no puede estar vacio");
			document.getElementById('direccion').focus();
		}	
		else if(document.getElementById('paises').value == 0)
		{
			alert("Tiene que seleccionar un país");
			document.getElementById('paises').focus();
		}	
		else if(document.getElementById('provincias').value == 0)
		{
			alert("Tiene que seleccionar una provincia");
			document.getElementById('provincias').focus();
		}	
		else if(document.getElementById('poblaciones').value == 0)
		{
			alert("Tiene que seleccionar una población");
			document.getElementById('poblaciones').focus();
		}
		else if(document.getElementById('ididioma').value == 0)
		{
			alert("Tiene que seleccionar un idioma");
			document.getElementById('ididioma').focus();
		}	
		else if(politica == 1)
		{
			if(document.getElementById('politica').value == '')
			{
				alert("Tienes que aceptar la política de privacidad");
				document.getElementById('politica').focus();
			}
			else if(document.getElementById('password').value != document.getElementById('password1').value)
			{
				alert("Las contraseñas introducidas no coinciden.");
				document.getElementById('password').focus();
			}
			else
			{	
				enviar_formulario_usuario(estado,idpais,idusuario);			
			}
		}	
		else if(document.getElementById('password').value != document.getElementById('password1').value)
		{
			alert("Las contraseñas introducidas no coinciden.");
			document.getElementById('password').focus();
		}		
		else
		{	
			enviar_formulario_usuario(estado,idpais,idusuario);			
		}
	}
