google.load("language", "1");
var espera=0;
var usuario_id='0';
var usuario_correcto=1;

function ocultar_correos_rapidos(){
	document.getElementById('borrador_correos').style.display='none';
	borrar_linea('rapidos')
}

function vaciar_correos_rapidos(usuario){

	var contar=0
	var container=document.getElementById('rapidos')
	var cadena=''
	var frm=document.forms.form_recomendar_anuncios
	for (i=0;i<frm.elements.length;i++){
		if( frm.elements[i].name == 'correo_rapido[]' && frm.elements[i].checked==true ){
			if(contar>0)
				cadena = cadena+','+frm.elements[i].value
			else
				cadena = cadena+frm.elements[i].value
			
			frm.elements[i].checked=false
			frm.elements[i].parentNode.style.display='none'
			contar = contar+1
		}
	}

	if(contar > 0)
		enviar_ajax ("background_div","borrar_correo",usuario,cadena,"/acciones/vaciar_correos.php");
	else
		alert(Idioma_errorBorrar_correos)
	
}

function recomendar_anuncios(){
	Send_form('form_recomendar_anuncios','includes/envio_recomendacion.php','cositas_en_el_fondo');
	setTimeout("ocultar_div_ventanitas();",300)
	setTimeout("res_recomendar_anuncios()",800);
}

function res_recomendar_anuncios(error_mail){
	abrir_ventanita_especial('top=-75,left=-150,height=100,width=300');
	datos_2('cositas_en_el_fondo','respuesta',error_mail,'0','/includes/envio_recomendacion.php');
}

function abrir_recomendaciones(valor){
	abrir_ventanita_especial("top=-150,left=-350,height=300,width=700");
	datos_2("cositas_en_el_fondo","posible_borrar_img",valor,"0","/includes/form_enviar_amigos.php");	
}

function cambio_de_municipio(municipio_id,modi){
	datos ("mostrar_municipio","cambio_de_municipios",municipio_id,modi);
}

function abrir_tpv(){
	vent=window.open('','tpv','width=725,height=600,scrollbars=no,resizable=yes,status=yes,menubar=no,location=no');
	document.forms[0].submit();
}

function destaque_anuncio (anuncio_id){
		//abrir_ventanita_especial('paddingLeft=10');
		abrir_ventanita_especial('top=-200,left=-350,height=300,width=500');
		enviar_ajax ("cositas_en_el_fondo","informacion",anuncio_id,"mostrar","/destacar_anuncio.php");
}

function renueve_anuncio (anuncio_id){

	abrir_ventanita_especial('top=-200,left=-350,height=300,width=500');
	enviar_ajax ("cositas_en_el_fondo","informacion_renovar",anuncio_id,"mostrar","/destacar_anuncio.php");

}

function telefono_rellenar (){
	//Si llamo una funcion ajax para esperar que me devuelva los datos.. si se ha borrado historial, archivos temporales mi amigo IE me da un error
	//datos no procesados.. poca paciencia.
	
	var contrasena= document.anuncio.contrasena.value;
	var correo= document.anuncio.correo.value;
	var anuncio_tlf=document.anuncio.anuncio_tlf;

	var tel= usuario_ajax ("usuario_telefono",correo,contrasena)
	
	if (document.anuncio.usuario_tipo[1].checked)
		{  
		if ((tel.responseText != '') && (anuncio_tlf.value==""))
				{
				anuncio_tlf.value =  tel.responseText;
				}
		}
}

function desactivar_precio(formulario) {
	var precio= eval ("document."+formulario+".precio");
	precio.value="";
	//precio.disabled=true;
}
function activar_precio (formulario){
	//var precio= eval ("document."+formulario+".precio");
	var tipoPrecio= eval ("document."+formulario+".tipo_precio");
	tipoPrecio[1].checked=false;
	//precio.disabled=false;
}
function nuevo_telefono (valor){
	document.anuncio.anuncio_tlf.value= valor;
}
function traduse (idiomaOrig,idiomaDest,formulario){
	
	var obj= document.getElementById ('idioma_'+idiomaDest);
	obj.style.display="";
	
	var obj_reloj= document.getElementById ('reloj_'+idiomaDest);
	obj_reloj.style.display="";
	var titulo_traducido = eval ("document."+formulario+".titulo_"+idiomaDest);
	var titulo= eval ("document."+formulario+".titulo_"+Idioma+".value");
	
	document.getElementById ('traducido_'+idiomaDest).value='1';
	
	google.language.translate (titulo,idiomaOrig, idiomaDest,function (result){
			if (!result.error){
				
				titulo_traducido.value= result.translation;
				
				 //obj.style.display="";
			}	
		}
	);

	var obj_texto= document.getElementById ('idioma_texto_'+idiomaDest);
	 obj_texto.style.display="";
	var texto_traducido = document.getElementById ("anuncio_texto_"+idiomaDest);
	var texto= document.getElementById ("anuncio_texto_"+Idioma).value;
	
	google.language.translate (texto,idiomaOrig, idiomaDest,function (resultado){
			if (!resultado.error){
				
				texto_traducido.innerHTML= resultado.translation;
				tamano_texto(idiomaDest);
				obj_reloj.style.display="none";
				}	
		}
	);
	
}
function tamano_texto(idiom){
	var letras= document.getElementById ('letras_'+idiom);
	var id_texto=document.getElementById('anuncio_texto_'+idiom);
	
	var tam=id_texto.value.length ; 
	
	var tam_max = 600;
	
	if (tam==0) letras.innerHTML=" "+tam_max+" ";
	
	var n = tam ;
	
	//letras.innerHTML=" "+n+" ";

	if (n> tam_max) 
	{
		id_texto.value = id_texto.value.substring(0, tam_max);
		
		return false;
	}
	else {
		letras.innerHTML=" "+tam_max - n+" ";
	}
}

function Tamanyo1(c,f) {
	var Obj;
	//var Obj2;
	//Obj2=document.getElementById(c);

	Obj=eval('document.forms.'+f+'.'+c);
	
	if (Obj==undefined){
		Obj=eval('document.forms.detalle_anuncio.'+c);
	}
	Obj.style.fontSize='16px';
	Obj.style.fontWeight='bold';
	Obj.style.border='1px solid #7F9DB9';
	Obj.style.backgroundColor='#D6EBFF';
	//Obj2.style.fontSize='12px';
	//Obj2.style.fontWeight='bold';
}

function Tamanyo2(c,f) { 
	var Obj;
	//var Obj2;
	//Obj2=document.getElementById(c);
	Obj=eval('document.forms.'+f+'.'+c);
	
	if (Obj==undefined){
		Obj=eval('document.forms.detalle_anuncio.'+c);
	}
	Obj.style.fontSize='12px';
	Obj.style.fontWeight='normal';
	Obj.style.backgroundColor='#FFFFFF';
	//Obj2.style.fontSize='10px';
	//Obj2.style.fontWeight='normal';
}
function verificar_tecla(e)
		{
  		var charCode
  		if (navigator.appName == "Netscape") 
    		charCode = e.which;
  		else
	  		charCode = e.keyCode  
 		status = charCode;
		if (charCode > 31 && (charCode < 48 || charCode > 57))
    			return false;
  		return true;
		}

function mostrar(valor, caso)
	{
	switch (caso){
		case 'categoria': envion(valor);break;
		case 'producto': envio_pro(valor); break;
		}
	}


function envion(valor)
	{
	document.getElementById('extra_div').style.display='none';
	datos ("producto_div","imp_div_producto",valor,"mostrar");
	}

function envio_pro(valor)
	{
	datos ("extra_div","imp_div_producto_extra",valor,0);
	}

function nueva_img()
	{
	//var img=parseInt(document.anuncio.fotos.value);
	var img=parseInt(document.anuncio.fotos.value);
	
	document.getElementById ("mas_imagenes_"+img).style.display="";
	//datos ("mas_imagenes_"+img,"imp_div_mas_img",img,0);

	document.anuncio.fotos.value=img+1;
	if(img=="7")
		document.getElementById('bot_img').style.display='none';
	}

/*
function nueva_img()
	{
	var img=parseInt(document.anuncio.fotos.value);

	datos ("mas_imagenes_"+img,"imp_div_mas_img",img,0);

	document.anuncio.fotos.value=img+1;
	if(img==5)
		document.getElementById('bot_img').style.display='none';
	}
*/
function insertar (nombreFormulario)
	{
	var obj= eval ("document."+nombreFormulario);
	obj.submit()
	}

function hipersalto(donde,hasta)
	{

	
	//datos('msj_error_buscador','cambio_pag',donde,"<?=$_REQUEST['pg']?>",'/includes/montar.php');

	document.anuncio.pagina_inicial.value=donde;
	document.anuncio.action="";
	document.anuncio.submit();
	}

function cambiar_paginacion()
	{
	
	//alert(document.getElementById('tot_reg'))

	if((document.anuncio.pagina_inicial.value !="nada") && (document.getElementById('tot_reg') != null))
		{
	
		var pag=document.anuncio.pagina_inicial.value;
		var tot_pag=parseFloat(document.getElementById('tot_reg').value / document.anuncio.ver_grupo.value);
	
		datos_2("paginacion","imp_paginacion",pag,tot_pag,"/acciones/listar.php" );
		}

	}

function ver_anuncio_url (valor,titulo,url)
	{
	document.location.href='/'+titulo+'/'+url+'/'+valor+'/';
	}

function ver_anuncio(valor)
	{
	document.location.href='/index.php?pg=detalles&valor='+valor;
	}

function cambiar_foto (foto)
	{
	document.getElementById ('imagen_central').src=foto;
	}

function cambiar_derecha(valor)
	{
	recarga_derecha(document.anuncio.categoria.value);
	}

function cambiar_derecha_total()
	{
	recarga_derecha(0);
	}

function recarga_derecha(valor)
	{
	datos_2("el_div_der","nuevas_img",valor,"0","/acciones/listar.php");
	}

function ordenar(campo)
	{
	//if(espera==0)
	//	{
		
		if(document.anuncio.campo.value==campo)
			{
			if(document.anuncio.dir.value=='desc')
				document.anuncio.dir.value='asc';
				else
				document.anuncio.dir.value='desc';
			}
			else
				{
				document.anuncio.dir.value=='desc';
				document.anuncio.campo.value=campo;
				}
		document.anuncio.submit();
		
	//	}
	}
function nuevo_buscador(valor)
	{
	datos_2("cositas_busqueda","busqueda_campos",valor,"0","/acciones/listar.php")
	}

function borrar(valor)
	{
	var obj=eval("document.anuncio."+valor);
	obj.value='';
	}
function usuario_campos_mostrar ()
	{
	document.getElementById ('usuario_campos').style.display="";
	}
function usuario_nuevo()
	{
	quitar_comprobaciones ();
	document.anuncio.usuario_tipo[0].checked=true;
	usuario_campos_mostrar();
	//document.anuncio.usuario_existente.value=0;
	//datos ("usuario_div","nuevo_usuario_div",0,0);
	document.getElementById ('usuario_nuevo_1').style.display="";
	document.getElementById ('usuario_nuevo_2').style.display="";
	document.getElementById ('usuario_registrado_1').style.display="none";
	}

function usuario_registrado()
	{
	quitar_comprobaciones ();
	document.anuncio.usuario_tipo[1].checked=true;
	usuario_campos_mostrar();
	//document.anuncio.usuario_existente.value=1;
	//document.getElementById('usuario_div').innerHTML='';
	document.getElementById ('usuario_nuevo_1').style.display="none";
	document.getElementById ('usuario_nuevo_2').style.display="none";
	document.getElementById ('usuario_registrado_1').style.display="";
	}
function montar_buscador(valor, caso)
	{
	//alert(valor+' '+caso);
	switch (caso){
		case 'categoria': nuevo_buscador (valor); break;
	//	case 'producto': envio_pro(valor); break;
		}

	/*
	if((valor == "P_12_2") || (valor == "P_14_1") || (valor == "P_16_1") || (valor == "P_17_1") || (valor == "P_15_1") || (valor == "P_13_1") || (valor == "P_18_1"))
		document.getElementById('buscador').style.height="100px";
		else
		document.getElementById('buscador').style.height="68px";
	*/
	}
function div_error (campo,mensaje)
	{
		var div = document.getElementById (campo+'_div_in');
		var div_error= document.getElementById (campo+'_error');
		var caja= document.getElementsByName (campo);	
		
		//if (caja[0]!=undefined) caja[0].focus();

		div_error.style.display="";
		div.style.border="1px dashed red"; 
		div_error.style.color="red";
		div_error.innerHTML= mensaje;
		
		//caja[0].selected();
	
	}

function div_no_error (campo){
	
	var div= document.getElementById (campo+'_div_in');
	var div_error= document.getElementById (campo+'_error');
	var validado="";
	if (document.anuncio != undefined)
	if (document.anuncio.validado_id != undefined)
		validado= document.anuncio.validado_id.value;
	
	if (div_error != undefined)
		{
		if (document.anuncio !=undefined){
			if(document.anuncio.accion.value!='mis_anuncios' && validado =="")
				if (document.anuncio.usuario_tipo[1].checked && !usuario_correcto && (campo == "correo" || campo == "contrasena")  )
				{
					if (campo == "correo") {
						usuario_correcto=1;
						div_no_error ("contrasena");
					}
					else if (campo == "contrasena") {
						usuario_correcto=1;
						div_no_error ("correo");
					}
				}
		}
			div_error.style.display="none";
			div.style.border="0px";	
			div.style.borderTop="5px solid #FFFFFF";
		}
}
function div_error_log (mensaje){

		var correo_div_in= document.getElementById ("correo_div_in");
		var correo_error= document.getElementById ("contrasena_error");

		correo_div_in.style.borderTop="1px dashed red";
		correo_div_in.style.borderRight="1px dashed red";
		correo_div_in.style.borderLeft="1px dashed red";
		correo_div_in.style.borderBottom="1px dashed white";

		correo_error.innerHTML= mensaje;

		var contrasena_div_in= document.getElementById ("contrasena_div_in");
		contrasena_div_in.style.borderTop="0px dashed red";
		contrasena_div_in.style.borderRight="1px dashed red";
		contrasena_div_in.style.borderLeft="1px dashed red";
		contrasena_div_in.style.borderBottom="1px dashed red";

		
 		correo_error.style.display="";

		//contrasena
// 		
// 		div.style.border="1px dashed red"; 
 		correo_error.style.color="red";
 		correo_error.innerHTML= mensaje;



}
function quitar_comprobaciones ()
	{	
		//document.anuncio.reset ();

		var cnj_formulario= document.anuncio.elements;

	
		for (var i=0; i<cnj_formulario.length; i++)
			{
				div_no_error (cnj_formulario[i].name);
			}
	}

function comprobar_extras (nombreFormulario)
	{
	var p='';

	if (nombreFormulario=="") nombreFormulario="anuncio";

	var aux= document.getElementsByName("error_extra");	
	if (aux.length >0)
		{
		for (var i=0; i<aux.length; i++)
			{
			p=aux[i].value.split(".");
			//alert (p[0]+"  "+p[1]);
			return comprobar_campo (p[0],p[1],nombreFormulario);
			}
		}
	}
function revisar (nombreFormulario,pagina)
	{
	datos('msj_error_buscador','cargar_lista_anuncio','','','/includes/montar.php');
		if (!pagina){
		
			if (nombreFormulario !="") publicar (nombreFormulario,"revisar"); 
			else publicar ("anuncio","revisar");
		
		}
		else {
			publicar (nombreFormulario,"revisar",pagina); 
		}
	}



function editar_anuncio(valor)
	{

	
	datos('msj_error_buscador','cargar_editar_anuncio',valor,'','/includes/montar.php');
	
	document.location.href=document.location;
	
	//document.getElementById('lista_anuncios').style.display="none";
	//datos ("detalle_de_anuncio","editar_anuncio",valor,"mostrar");
	//document.getElementById('detalle_de_anuncio_botones').style.display="";
	}

function volver_mis_nun()
	{
	datos('msj_error_buscador','cargar_lista_anuncio','','','/includes/montar.php');
	document.location.href=document.location;

	/*document.getElementById('detalle_de_anuncio').style.display="none";
	var botones = document.getElementById('detalle_de_anuncio_botones');
	if (botones != undefined )
		botones.style.display="none";
	document.getElementById('lista_anuncios').style.display="";*/
	}



function seguir_anuncio(valor)
	{

	abrir_ventanita_especial("top=-60,left=-150,height=80,width=300");
	
	datos_2("cositas_en_el_fondo","poner_cookie",valor,"0","/acciones/listar.php");
	
 	}

function responder_anuncio(valor)
	{

	abrir_ventanita_especial("top=-60,left=-150,height=300,width=410");
	
	datos_2("cositas_en_el_fondo","responder_anuncio",valor,"0","/acciones/responder.php");
	
	}

function fraude_anuncio(valor)
	{

	abrir_ventanita_especial("top=-60,left=-150,height=300,width=410");
	
	datos_2("cositas_en_el_fondo","fraude_anuncio",valor,"0","/acciones/responder.php");
	
	}
function comprobar_logo ()
	{
		var archivo= document.anuncio.imagen_logo;
		var error = comprueba_extension(archivo.value);

		if (error != "")  {
			archivo.value="";
			abrir_ventanita_especial("border=2px solid red,left=-150,top=-60,height=80,width=300");
			datos_2("cositas_en_el_fondo","error_foto",error,"0","/acciones/funciones_extras.php");	
		}
	}

function enviar_foto (valor)
	{
	setTimeout('enviar_foto_de_veras('+valor+');',300);
	}
function enviar_foto_de_veras (valor){

	var obj= eval ("document.form_imagen_"+valor);
	var div_foto= document.getElementById ('div_imagen_'+valor);
	var ppal_foto= document.getElementById ('ppal_imagen_'+valor);
	
	var archivo= eval ("document.form_imagen_"+valor+".imagen_"+valor)

	
	var error= comprueba_extension(archivo.value);

	if (error != "")  {
		archivo.value="";
		abrir_ventanita_especial("border=2px solid red,left=-150,top=-60,height=80,width=300");
		datos_2("cositas_en_el_fondo","error_foto",error,"0","/acciones/funciones_extras.php");	
	
	}
	else {
		ppal_foto.style.display="none";
		div_foto.style.display="";
		obj.submit ();
	}

}
function enviar_foto_editar (valor)
	{
	setTimeout('enviar_foto_editar_de_veras('+valor+');',300);
	}

function enviar_foto_editar_de_veras (valor)
	{
	var obj= eval ("document.form_imagen_"+valor);
	var archivo= eval ("document.form_imagen_"+valor+".imagen_"+valor);
	var error= comprueba_extension(archivo.value);

	if (error != "")  {
		archivo.value="";
		abrir_ventanita_especial("border=2px solid red,left=-150,top=-60,height=80,width=300");
		datos_2("cositas_en_el_fondo","error_foto",error,"0","/acciones/funciones_extras.php");
	
	}
	
	else {
		
		
		obj.submit ();
	}
	}


function enviar_a_un_amigo()
	{
	abrir_ventanita_especial("top=-60,left=-150,height=80,width=300");
	setTimeout("Send_form('recomendar_amigo','/includes/envio_mail.php','cositas_en_el_fondo');",800);
	}

function cerrar_imagen (valor){
	
	var div_foto= document.getElementById ('div_imagen_'+valor);
	var ppal_foto= document.getElementById ('ppal_imagen_'+valor);
	var fotito= eval ("document.form_imagen_"+valor+".imagen_"+valor);
	fotito.value="";
	ppal_foto.style.display="";
	div_foto.style.display="none";
	enviar_ajax_img("borrar_imagen_temporal","imagen_"+valor,"/includes/imagenes.php" );

	}

function borrar_img_editar(id, pos)
	{
	abrir_ventanita_especial("top=-60,left=-150,height=100,width=300");
	datos_2("cositas_en_el_fondo","posible_borrar_img",id,pos,"/acciones/funciones_extras.php");	
	}


function borrar_posible_borrar_img(id,pos)
	{
	
	ocultar_div_ventanitas();
	datos_2("hueco_para_foto_"+pos,"cambio_de_opt",id,pos,"/acciones/funciones_extras.php");
	
	}
function deseleccionar (campo,inicio,actual)
	{

	var ind=inicio;
	
	
	
	while (document.getElementById (campo+ind)){
		
		if (ind != actual ) document.getElementById (campo+ind).checked=false;
		ind++;
	}

	}
function cambio_prp_a(id, valor,num_foto)
	{
	//alert (id+",,,,,"+valor+",,,,,,,,"+num_foto);
	deseleccionar ("fot_prp_",0,num_foto); 
	datos_2("mensajes_modificar","modifica_prp",id,valor,"/acciones/funciones_extras.php");
	} 

function borrar_anuncio_mis()
	{
	datos('msj_error_buscador','cargar_lista_anuncio','','','/includes/montar.php');
	abrir_ventanita_especial("border=2px solid red,top=-60,left=-140,height=80,width=280");
	datos_2("cositas_en_el_fondo","posible_borrar_anuncuio","0","0","/acciones/funciones_extras.php");	
	}
function borrar_anuncio_mis_listado(valor)
	{
	
	abrir_ventanita_especial("border=2px solid red,top=-60,left=-140,height=80,width=280");
	datos_2("cositas_en_el_fondo","posible_borrar_anuncuio",valor,"0","/acciones/funciones_extras.php");	
	}

function borra_anuncio_mis_veras(valor)
	{

	ocultar_div_ventanitas();
	if(valor=='0')
		var id=document.detalle_anuncio.anuncio_id[0].value;
	else
		var id=valor;
	datos_2("mensajes_modificar","borrar_anuncio",id,"0","/acciones/funciones_extras.php");
	//setTimeout("espera=0;volver_mis_nun();Send_form('anuncio','/acciones/listar.php','listado_productos');",200);
	setTimeout("espera=0;document.location.replace('/index.php?pg=mis_anuncios')",200);
	}
function detalles_anun_rel(volver,ver)
	{
	document.location.href='/index.php?pg=detalles&valor='+ver+'&volver='+volver;
	}

function anuncios_del_rel(valor,anuncio)
	{
	document.location.href='/index.php?pg=listado_rel&valor='+valor+'&volver='+anuncio;
	}
function comprueba_extension(archivo) {
	
	
	var extensiones_permitidas = new Array(".gif", ".jpeg", ".jpg", ".png");
	error = "";
	
	extension = (archivo.substring(archivo.lastIndexOf("."))).toLowerCase();
	permitida = false;

	for (var i = 0; i < extensiones_permitidas.length; i++) {
		if (extensiones_permitidas[i] == extension) {
			permitida = true;
			break;
		}
	}
	
	if (!permitida) {
		error = "soloExt";
	}
	
	return error;

}
function poner_nombre_provincia(valor_1,valor_2)
	{
	datos_2("nombre_provincia","nombre_de_la_povincia",valor_1,"0","/acciones/listar.php");	
	}
function enviar_responder(){
	var mensaje= responder_comprobar ();
	if (mensaje==""){
		modificar_ventanita_especial("top=-60,left=-150,height=100,width=300");
		Send_form('anuncio_responder','/acciones/responder.php','cositas_en_el_fondo');
	}
}

function enviar_fraude(){
	var mensaje= responder_comprobar ();
	if (mensaje==""){
		modificar_ventanita_especial("top=-60,left=-150,height=100,width=300");
		Send_form('anuncio_responder','/acciones/responder.php','cositas_en_el_fondo');
	}
}
function contrasena_volver (){
	
	ocultar_div_ventanitas();
	document.location.href ="/index.php?pg=mis_anuncios";
}
function renovar_anuncio_mis_veras(valor)
	{
	ocultar_div_ventanitas();
	var id=document.detalle_anuncio.anuncio_id[0].value;
	
	
	datos_2("mensajes_modificar","renovar_anuncio",id,"0","/acciones/funciones_extras.php");
	
	setTimeout("espera=0;volver_mis_nun();Send_form('anuncio','/acciones/listar.php','listado_productos');",200);	
	
	}

function anuncio_renovar()
	{
	abrir_ventanita_especial("border=2px,top=-60,left=-140,height=80,width=280");
	datos_2("cositas_en_el_fondo","posible_anuncio_renovar","0","0","/acciones/funciones_extras.php");	
	}
function resetear_imagen (valor){
		
		var div_foto= document.getElementById ('div_'+valor);
		var ppal_foto= document.getElementById ('ppal_'+valor);
		var imagen_contenido= document.getElementsByName (valor);
		var nombre = imagen_contenido[0].value;
		imagen_contenido[0].value='';
		
		ppal_foto.style.display='';
		div_foto.style.display='none';
		
		abrir_ventanita_especial('top=-60,left=-150,height=100,width=300');
		datos_2("cositas_en_el_fondo","resetear_imagen",nombre,"0","/includes/montar.php"); 
}
////////////////////////////////////////////////////////////////////// TOLTIP //////////////////////////////////////////////////////////////////

/**
*@Autores   George y Manolo
*/  
function globito_pos_y (inputObj){	  
	  var returnValue = inputObj.offsetLeft;
	var anchito=parseInt(inputObj.style.width);
	  while((inputObj = inputObj.offsetParent) != null){
	  	if(inputObj.tagName!='HTML'){
	  		returnValue += inputObj.offsetLeft;
	  		if(document.all)returnValue+=inputObj.clientLeft;
	  	}
	  }
	  return parseInt(returnValue)+anchito;}
function globito_pos_x (inputObj){		
	  var returnValue = inputObj.offsetTop;
	 
	  while((inputObj = inputObj.offsetParent) != null){
	  	if(inputObj.tagName!='HTML'){
	  		returnValue += inputObj.offsetTop;
	  		if(document.all)returnValue+=inputObj.clientTop;
	  	}
	  } 
	
	  return returnValue;}
function muestraTip(msg,campo)  {
   	var cadena=msg+'<br />';
	var globo= document.getElementById("tip");
	var globo_texto= document.getElementById("texto_toltip");

	globo_texto.innerHTML=cadena;
   	globo.style.top=(parseInt(globito_pos_x(campo))-40)+"px";
	//globo.style.left= parseInt (tam)+"px";
	globo.style.left=(parseInt(globito_pos_y(campo)))+"px";
	
	globo.style.display='';
	globo.style.visibility="visible";}

function ocultaTip(){
          masY=-1000;
          masX=-1000;
          if(document.all)
              parent.document.all("tip").style.visibility="hidden";
          else if(document.layers)
              parent.document.layers["tip"].visibility="hide";
          else if(document.getElementById)
              parent.document.getElementById("tip").style.visibility="hidden";}

function comprobar_campo (campo,mensaje,nombreFormulario)
	{

	var mensaje_aux ="";
	

	if (nombreFormulario=="") nombreFormulario="anuncio";
	if (campo!=("anuncio_texto"+Idioma)){
		 var valor= eval("document."+nombreFormulario+"."+campo+".value");
	}
	else {
		var valor= eval("document."+nombreFormulario+"."+campo+".value.length");
	}
	
	if (campo=="precio"){
		var seleccion= eval ("document."+nombreFormulario+".tipo_precio");
		if ( (valor=="" || valor==0) && (!seleccion[1].checked))
			{
				div_error (campo,mensaje);
				mensaje_aux=mensaje;
			}
	}
	
	else if ((campo!="precio" && valor==0) || valor =='' )
		{
			if (campo =="provincias" && valor ==''  ){
				div_error (campo,mensaje);
				mensaje_aux=mensaje;
				}
			else if (campo !="provincias" ){
				div_error (campo,mensaje);
				mensaje_aux=mensaje;
			}
	
		}
	else if (campo =="categoria"){
		
		div_no_error (campo);
		
		mensaje_aux= comprobar_campo ("producto",Idioma_nec_subcategoria,nombreFormulario);

	}
	else if (campo !="correo" && campo !="contrasena"){
		div_no_error (campo);
	}
	
	
	return mensaje_aux;
	}

function comprobar_usuario_tipo ()
	
{
	var mensaje ="";
	var validado="";
	
	if (document.anuncio.validado_id != undefined)
		validado= document.anuncio.validado_id.value;
	
	if (validado !="") return mensaje;
	
	if (document.anuncio.usuario_tipo != undefined ){
		var tipo = document.anuncio.usuario_tipo;
	
		if (!(tipo[0].checked || tipo [1].checked)){
			mensaje=Idioma_nec_tipo_usuario;
			div_error ("usuario_tipo",mensaje);
		}
	}
	return mensaje;

}

function comprobar_condiciones ()
{
	var mensaje ="";
	var tipo = document.getElementById ("condiciones");
	
	if (!(tipo.checked)){
		mensaje=Idioma_nec_condiciones;
		div_error ("condiciones",mensaje);
	}

	return mensaje;



}
function publicar (nombreFormulario,opcion,pagina) //tercer param para diferenciar la pantalla de mis anuncios.
	{
	
	var validado="";
	if (document.anuncio.validado_id != undefined)
		validado= document.anuncio.validado_id.value;

	var mensaje="";
	
	mensaje+= comprobar_campo ("provincias",Idioma_nec_provincia,nombreFormulario);
	mensaje+= comprobar_campo ("titulo_"+Idioma,Idioma_nec_titulo,nombreFormulario);
	mensaje+= comprobar_campo ("categoria",Idioma_nec_cat_prod,nombreFormulario); 
	mensaje+= comprobar_campo ("precio",Idioma_nec_precio,nombreFormulario); 
	mensaje+= comprobar_campo ("anuncio_texto_"+Idioma,Idioma_nec_texto,nombreFormulario);
	

	if (nombreFormulario=="anuncio")
		{			mensaje+= comprobar_condiciones ();
					mensaje+= comprobar_usuario_tipo ();
			if (validado =="")
				{
				mensaje+= comprobar_campo ("correo",Idioma_nec_correo,nombreFormulario);
			
				mensaje+= comprobar_campo ("contrasena",Idioma_nec_contrasena,nombreFormulario); 
				mensaje+=usuario_cmp_reg ();
				
			
				if (document.anuncio.usuario_tipo[0].checked) //Si el usuario es nuevo
					{
					
					if (document.anuncio.rol_abr[0].checked)
						mensaje+= comprobar_campo ("nombre",Idioma_nec_nick,nombreFormulario);
					else 
						mensaje+= comprobar_campo ("nombre",Idioma_nec_nomb_empresa,nombreFormulario);

					mensaje+= comprobar_campo ("nombre_real",Idioma_nec_nombre,nombreFormulario);
					mensaje+= contrasena_repetida ();
					mensaje+= usuario_cmp_nuevo ();
					}
			}
		}

	

	mensaje+=comprobar_extras (nombreFormulario);
	

	
	if( (mensaje=='' || mensaje== 'undefined') && ( opcion=="publicar"|| opcion=="revisar" ) && comprobar_mail(nombreFormulario) )	
		{
			if (opcion =="revisar")
				{	
				if (nombreFormulario=="anuncio")
					{						
						abrir_ventanita_especial('top=-350,paddingLeft=10,height=750');		
						document.anuncio.publicacion.value="revisar";
						setTimeout("Send_form('anuncio','sub_detalles.php','cositas_en_el_fondo');",800);
						setTimeout("document.anuncio.publicacion.value='';",1000);
					
					}
				
				else if (pagina=="mis_anuncios")
					{
						abrir_ventanita_especial('top=-350,paddingLeft=10,height=750');		
						document.detalle_anuncio.publicacion.value="revisar";
						setTimeout("Send_form('detalle_anuncio','sub_detalles.php','cositas_en_el_fondo');",800);
						setTimeout("document.detalle_anuncio.publicacion.value='';",1000);
					
					}
				else {
					
					Send_form('detalle_anuncio','/acciones/modificar.php','mensajes_modificar');
					var id_anuncio= document.detalle_anuncio.anuncio_mod_id.value;
					//document.location.href= "/index.php?pg=detalles&valor="+id_anuncio;
				}
			}
			else {
				document.anuncio.action= "acciones/insertar.php";
				document.anuncio.target="";
				var obj= eval ("document."+nombreFormulario);
				obj.submit();
			}
		}
	}

function usuario_cmp_nuevo ()
	{
		var correo= document.anuncio.correo.value;

		var respuesta= usuario_ajax ("usuario_existe",correo);
		var mensaje="";

		if (document.anuncio.usuario_tipo[0].checked)
			{
				if (correo=='')
					{
					div_error ("correo",Idioma_intro_correo);
					mensaje= Idioma_intro_correo;
					}
				else if (respuesta.responseText != '0') 
					{	
					div_error ("correo",Idioma_usuario_existe);
					mensaje= Idioma_usuario_existe;
					}
				else 
					{
					div_no_error ("correo");
					mensaje=""
					}
			}
		
		if(comprobar_mail('anuncio')==false)
			mensaje="error";
		return mensaje;
} 

function usuario_cmp_reg ()
	{
	var contrasena= document.anuncio.contrasena.value;
	var correo= document.anuncio.correo.value;
	
	//var respuesta= setTimeout('usuario_ajax ("usuario_validar",document.anuncio.correo.value,document.anuncio.contrasena.value);',1);
	var respuesta= usuario_ajax ("usuario_validar",correo,contrasena);
	var mensaje="";
	usuario_correcto=1;
	
		if (document.anuncio.usuario_tipo[1].checked)
			{  //Usuario Registrado
				
				if (correo=='' || contrasena==''){
					if (correo==''){
						div_error ("correo",Idioma_intro_correo);
						mensaje=Idioma_intro_usuario;
					}
					if (contrasena==''){
						div_error ("contrasena",Idioma_intro_contrasena);
						mensaje=Idioma_intro_contrasena;
					}
				}
				else if (respuesta.responseText == '0'){
						div_error_log (Idioma_us_incorrecto);
						mensaje=Idioma_us_incorrecto;
						usuario_correcto=0;
				}		
				else {
					usuario_id=respuesta.responseText;
				
				}
			}
	
	
	return mensaje;
	}

function contrasena_repetida (formulario)
	{
		var mensaje= "";
		
		if (formulario != undefined){
			
			var contrasena= document.datos_personales.contrasena.value;
		
			var contrasena_rep= document.datos_personales.contrasena_rep.value;
			
		} 
		else {
			var contrasena= document.anuncio.contrasena.value;
		
			var contrasena_rep= document.anuncio.contrasena_rep.value;
		}
		
		if (contrasena_rep == "")
			{
			div_error ("contrasena_rep",Idioma_rep_contrasena);
			mensaje =Idioma_rep_contrasena;
			}
		 if (contrasena != contrasena_rep)
			{
			div_error ("contrasena_rep",Idioma_contra_coinciden);
			mensaje=Idioma_contra_coinciden;
			}

		if (mensaje=="")  {
			div_no_error ("contrasena_rep");
			
		}
	return mensaje;

	}

function comprobar_mail(formulario )
	{
	var validado="";
	if (document.anuncio.validado_id != undefined)
		var validado= document.anuncio.validado_id.value;
	
	if(formulario=='anuncio' && validado =="")
		{
		var s = eval("document."+formulario+".correo.value");
		var filter=/^[A-Za-z0-9][A-Za-z0-9_\.\-]*@[A-Za-z0-9_\.\-]+\.[A-za-z]{2,4}$/;
	 	if (filter.test(s) == false)
			{
			div_error ('correo',Idioma_inc_correo);
			return false;
			}
			else
			return true;
		}
		else
			return true;

}

function correo_comprobar (formulario)
	{
	var s = eval("document."+formulario+".correo.value");
	if (s!=""){
		var filter=/^[A-Za-z0-9][A-Za-z0-9_\.\-]*@[A-Za-z0-9_\.\-]+\.[A-za-z]{2,4}$/;
	 	if (filter.test(s) == false)
			{
			div_error ('correo',Idioma_inc_correo);
			return Idioma_inc_correo;
			}
	}
	return '';
	}


function responder_comprobar ()
	{
		var mensaje= "";
	
		mensaje+= comprobar_campo ("nombre",Idioma_obl_nick,"anuncio_responder");
		mensaje+= comprobar_campo ("correo",Idioma_obl_correo,"anuncio_responder");
		mensaje+= correo_comprobar ("anuncio_responder");
	
		return mensaje;
	}
function datos_p_comprobar(){
	
	var mensaje="";
	var contrasena= document.datos_personales.contrasena.value;
	var recibo= document.getElementById ("crecido_contrasena_mostrar").value;

	if (document.datos_personales.rol_abr[0].checked)
		mensaje+= comprobar_campo ("nombre",Idioma_nec_nick,"datos_personales");
	else 
		mensaje+= comprobar_campo ("nombre",Idioma_nec_nomb_empresa,"datos_personales");

	mensaje+= comprobar_campo ("correo",Idioma_obl_correo,"datos_personales");
	mensaje+= correo_comprobar ("datos_personales");
	if (recibo!='0') mensaje+=contrasena_repetida ("datos_personales");

	if (mensaje==""){
		document.datos_personales.submit ();
		//abrir_ventanita_especial("top=-60,left=-150,height=100,width=300");
		//Send_form('datos_personales','/acciones/usuario_datos.php','cositas_en_el_fondo');
	}
	
}
function formulario_empresa (){
	
	var div_error= document.getElementById ("nombre_error");
	div_error.innerHTML= Idioma_nec_nomb_empresa;
	
	var registro_empresas= document.getElementById ("registro_empresas");
	registro_empresas.style.display='';

	var div= document.getElementById ("nick_text");
	div.innerHTML=Idioma_nomb_empresa+':';

}
function formulario_particular(){

	var div_error= document.getElementById ("nombre_error");
	div_error.innerHTML= Idioma_nec_nick;

	var registro_empresas= document.getElementById ("registro_empresas");
	registro_empresas.style.display='none';


	var div= document.getElementById ("nick_text");
	div.innerHTML=Idioma_tu_nick+':';

}

function buscar_tipo (tipo){

	switch (tipo){
		case 'particulares':
			document.anuncio.solo_particular.checked=true;
			document.anuncio.solo_empresa.value=0;
			document.anuncio.pagina_inicial.value=0;
			break;
		
		case 'empresas':
			
			document.anuncio.solo_particular.checked=false;
			document.anuncio.solo_empresa.value=1;
			document.anuncio.pagina_inicial.value=0;
			break;

		default:
			document.anuncio.solo_particular.checked=false;
			document.anuncio.solo_empresa.value=0;
			document.anuncio.pagina_inicial.value=0;
			break;
	}
	//document.anuncio.pagina_inicial.value=0;
	Send_form_ajax ("anuncio","/acciones/recoger_busqueda.php","msj_error_buscador");
	document.anuncio.submit();
	
}

function ver_miniaturas(){
	
	if (document.anuncio.ver_fotos.value==1)
		document.anuncio.ver_fotos.value=0;
	else document.anuncio.ver_fotos.value=1;
		
	document.anuncio.submit();
	
}

function inc_llamadas (id_anuncio){
	datos_2('montar_cookie','incrementar_llamadas',id_anuncio,'','/acciones/funciones_extras.php');
}

// Para la recomendaci�n de e-mails.
var num_email = 1;

function nueva_linea(){
	num_email += 1;
	var content = document.getElementById('emails');
	var divIdName = 'correo_' + num_email + 'div';
	var newDiv = document.createElement('div');
	newDiv.setAttribute('id', divIdName);
	
	var newDelete = document.createElement('img');
	//newDelete.setAttribute('onclick', 'javascript:borrar_linea("' + divIdName + '")');
	newDelete.onclick = function() { borrar_linea(divIdName) };
	newDelete.src = ' imagenes/eliminar.png';
	
	var newSpan = document.createElement('span');
	newSpan.innerHTML = '&nbsp;';
	
	var newInput = document.createElement('input');
	newInput.type = 'text';
	newInput.size = '20';
	newInput.name = 'recomendar_mail[]';
	newInput.setAttribute('style','margin-top:5px;');
	
	newDiv.appendChild(newDelete);
	newDiv.appendChild(newSpan);
	newDiv.appendChild(newInput);
	content.appendChild(newDiv);
}

function borrar_linea(div){
	var content = document.getElementById('emails');
	var remove = document.getElementById(div);
	content.removeChild(remove);
}

function comprueba_lineas(){

	var error = 0;
	var contar = 0;
	var contar_mail = 0;
	var frm=document.forms.form_recomendar_anuncios;
	for (i=0;i<frm.elements.length;i++){		
		if( (frm.elements[i].name == 'recomendar_mail[]') || (frm.elements[i].name == 'correo_rapido[]' && frm.elements[i].checked==true) ){
			if( es_correo(frm.elements[i].value) && frm.elements[i].value != '')
				contar_mail = contar_mail+1
			else
				error = error+1
		}
		
		if(frm.elements[i].name.substr(0,6) == 'check_'){
			if(frm.elements[i].checked==true)
				contar = contar+1
		}
	}
	
	if(contar == 0)
		error = error+1;
	if(contar_mail == 0)
		error = error+1

	if(error == 0){
		return true
	}else{
		alert(Idioma_compruebaForm_recomendar)
		return false
	}

}

function es_correo (elemento){
	var s = elemento;
	var filter=/^[A-Za-z][A-Za-z0-9_.]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/;
	if (s.length == 0 ) return true;
	if (filter.test(s))
		return true;
	else
		return false;
}

function toogle_muestra(div){

	if(document.getElementById(div).style.display=='')
		document.getElementById(div).style.display='none'
	else
		document.getElementById(div).style.display=''

}