// JavaScript Document
//// AJAX FUNCTIONS 
var estat_ajax = 'OK';

function isExisting(obj){
  return typeof(obj)!='undefined';
}

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

function actualizar(){
	var form_actiu = document.getElementById('form_actualiza');
	form_actiu.submit();
}

function denunciar(id_anuncio){
	var motivo=document.getElementById("motivo").value;
	if(motivo=='Motivo de la denuncia'){
		alert("Debe escribir un motivo para denunciar el anuncio. Gracias.");
		document.getElementById("motivo").focus();
		return false;
	}
	var valor_actiu = id_anuncio;
	ajax=nuevoAjax();
	//contenedor.innerHTML = '<img src="../icons/icon_orange.gif" alt="Guardant" width="10" height="10">';
	ajax.open("POST", "../ajax/denunciar_anuncio.php",true);
	ajax.onreadystatechange=function() {
		if (ajax.readyState==0) {
		} //el 0 vol dir que el retorn es estat INICIALIZAR 
		if (ajax.readyState==1) {
		} //el 1 vol dir que el retorn es estat CARGANDO 
		if (ajax.readyState==2) {
		} //el 2 vol dir que el retorn es estat CARGADO 
		if (ajax.readyState==3) {
		} //el 3 vol dir que el retorn es estat INTERACTUANDO 

		if (ajax.readyState==4) { //el 4 vol dir que el retorn es estat COMPLETADO 
			alert("El anuncio ha sido denunciado. Gracias.");
			document.getElementById('button').disabled=true;
		}
	}
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send("id_anuncio="+valor_actiu+"&motivo="+motivo);
}

function updateProvincies(tipo_anuncio,classe){
	var que_buscas = document.getElementById('que_buscas');
	var valor_actiu = tipo_anuncio;
	var element = "contenedor_provincia";
	contenedor = document.getElementById(element);
	ajax=nuevoAjax();
	//contenedor.innerHTML = '<img src="../icons/icon_orange.gif" alt="Guardant" width="10" height="10">';
	ajax.open("POST", "../ajax/update_provincies.php",true);
	ajax.onreadystatechange=function() {
		if (ajax.readyState==0) {
			contenedor.innerHTML = "Inicializando";
		} //el 0 vol dir que el retorn es estat INICIALIZAR 
		if (ajax.readyState==1) {
			contenedor.innerHTML = "Cargando";
		} //el 1 vol dir que el retorn es estat CARGANDO 
		if (ajax.readyState==2) {
			contenedor.innerHTML = "Cargado";
		} //el 2 vol dir que el retorn es estat CARGADO 
		if (ajax.readyState==3) {
			contenedor.innerHTML = "Interactuando";
		} //el 3 vol dir que el retorn es estat INTERACTUANDO 

		if (ajax.readyState==4) { //el 4 vol dir que el retorn es estat COMPLETADO 
			contenedor.innerHTML = ajax.responseText;
			campo2 = document.getElementById('select_donde_buscas');
			campo2.focus();
			que_buscas.disabled=false;
			campo3=document.getElementById('select_ciudad_buscas');
			if(campo3!=null){
				campo3.selectedIndex=0;
				campo3.disabled=true;
			} else {
				//alert("no existe");
			}
		}
	}
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send("tipo_anuncio_actiu="+valor_actiu+"&classe_activa="+classe);
	
}

function updateCiutats(tipo_anuncio,provicia_activa,classe){
	var select_donde_buscas = document.getElementById('select_donde_buscas');
	var valor_actiu1 = tipo_anuncio;
	var valor_actiu2 = provicia_activa;
	var element = "contenedor_ciutat";
	contenedor = document.getElementById(element);
	ajax=nuevoAjax();
	//contenedor.innerHTML = '<img src="../icons/icon_orange.gif" alt="Guardant" width="10" height="10">';
	ajax.open("POST", "../ajax/update_ciutats.php",true);
	ajax.onreadystatechange=function() {
		if (ajax.readyState==0) {
			contenedor.innerHTML = "Inicializando";
		} //el 0 vol dir que el retorn es estat INICIALIZAR 
		if (ajax.readyState==1) {
			contenedor.innerHTML = "Cargando";
		} //el 1 vol dir que el retorn es estat CARGANDO 
		if (ajax.readyState==2) {
			contenedor.innerHTML = "Cargado";
		} //el 2 vol dir que el retorn es estat CARGADO 
		if (ajax.readyState==3) {
			contenedor.innerHTML = "Interactuando";
		} //el 3 vol dir que el retorn es estat INTERACTUANDO 

		if (ajax.readyState==4) { //el 4 vol dir que el retorn es estat COMPLETADO 
			contenedor.innerHTML = ajax.responseText;
			campo2 = document.getElementById('select_ciudad_buscas');
			campo2.focus();
			if(select_donde_buscas!=null){
				select_donde_buscas.disabled=false;
			}
		}
	}
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send("tipo_anuncio_actiu="+valor_actiu1+"&provincia_activa="+valor_actiu2+"&classe_activa="+classe);
}

function updateCiutatsEntrada(provicia_activa){
	var select_donde_buscas = document.getElementById('id_provincia');
	var valor_actiu2 = provicia_activa;
	var element = "contenedor_ciutat";
	contenedor = document.getElementById(element);
	ajax=nuevoAjax();
	//contenedor.innerHTML = '<img src="../icons/icon_orange.gif" alt="Guardant" width="10" height="10">';
	ajax.open("POST", "../ajax/update_ciutats_entrada.php",true);
	ajax.onreadystatechange=function() {
		if (ajax.readyState==0) {
			contenedor.innerHTML = "Inicializando";
		} //el 0 vol dir que el retorn es estat INICIALIZAR 
		if (ajax.readyState==1) {
			contenedor.innerHTML = "Cargando";
		} //el 1 vol dir que el retorn es estat CARGANDO 
		if (ajax.readyState==2) {
			contenedor.innerHTML = "Cargado";
		} //el 2 vol dir que el retorn es estat CARGADO 
		if (ajax.readyState==3) {
			contenedor.innerHTML = "Interactuando";
		} //el 3 vol dir que el retorn es estat INTERACTUANDO 

		if (ajax.readyState==4) { //el 4 vol dir que el retorn es estat COMPLETADO 
			contenedor.innerHTML = ajax.responseText;
			campo2 = document.getElementById('ciudad');
			campo2.focus();
			if(select_donde_buscas!=null){
				select_donde_buscas.disabled=false;
			}
		}
	}
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send("provincia_activa="+valor_actiu2);
}

// ALTRES FUNCIONS
function poner_tipo(){
	var form_busc_mini = document.getElementById('form_buscador_mini');
	var tipo_anuncio_buscas = document.getElementById('tipo_anuncio_buscas');
	var select_donde_buscas = document.getElementById('select_donde_buscas');
	var que_buscas = document.getElementById('que_buscas');
	var selind = que_buscas.selectedIndex;
	tipo_anuncio_buscas.value=que_buscas.options[selind].lang; // utilitzaem la etiqueta lang perque el firefox no és capaç d'accedir a camps personalitzats. I el label dóna errors en IE7.
	campo_p1=document.getElementById('pene_longitud');
	campo_p2=document.getElementById('pene_diametro');
	if(tipo_anuncio_buscas.value==1){
		if((campo_p1!=null)&&(campo_p2!=null)){
			if((que_buscas.value=='chicos')||(que_buscas.value=='travestis')||(que_buscas.value=='parejas')){
				campo_p1.disabled=false;
				campo_p2.disabled=false;
			} else {
				campo_p1.selectedIndex=0;
				campo_p2.selectedIndex=0;
				campo_p1.disabled=true;
				campo_p2.disabled=true;
			}
		}
		form_busc_mini.action='buscador1.php';
	} else {
		if((campo_p1!=null)&&(campo_p2!=null)){
			campo_p1.selectedIndex=0;
			campo_p2.selectedIndex=0;
			campo_p1.disabled=true;
			campo_p2.disabled=true;
		}
		form_busc_mini.action='buscador2.php';
	}
	if(selind>0){
		updateProvincies(que_buscas.value,que_buscas.className);
		que_buscas.disabled=true;
	} else {
		select_donde_buscas.selectedIndex=0;
		select_donde_buscas.disabled=true;
	}
}

function repara_ciutat(){
	var select_ciudad_buscas = document.getElementById('select_ciudad_buscas');
	var selind = select_ciudad_buscas.selectedIndex;
	var ciudad_buscas = document.getElementById('ciudad_buscas');
	ciudad_buscas.value = select_ciudad_buscas.options[selind].value;
}

function poner_provincia(){
	var form_busc_mini = document.getElementById('form_buscador_mini');
	var selcampo1 = document.getElementById('que_buscas');
	var selcampo2 = document.getElementById('select_donde_buscas');
	var selcampo3 = document.getElementById('select_ciudad_buscas');
	var donde_buscas = document.getElementById('donde_buscas');
	var selind1 = selcampo1.selectedIndex;
	var selind2 = selcampo2.selectedIndex;
	donde_buscas.value = selcampo2.options[selind2].value;
	if(selcampo3!=null){
		var selind3 = selcampo3.selectedIndex;
		valcampo1=selcampo1.options[selind1].value;
		valcampo2=selcampo2.options[selind2].value;
		valcampo3=selcampo3.options[selind3].value;
		if(selind2>0){
			updateCiutats(valcampo1,valcampo2,selcampo1.className);
			selcampo2.disabled=true;
		} else {
			selcampo3.selectedIndex=0;
			selcampo3.disabled=true;
		}
	}
}

function poner_provincia_entrada(){
	var selcampo2 = document.getElementById('id_provincia');
	var selcampo3 = document.getElementById('ciudad');
	var selind2 = selcampo2.selectedIndex;
	var selind3 = selcampo3.selectedIndex;
	valcampo2=selcampo2.options[selind2].value;
	valcampo3=selcampo3.options[selind3].value;
	if(selind2>0){
		updateCiutatsEntrada(valcampo2);
		selcampo2.disabled=true;
	} else {
		selcampo3.selectedIndex=0;
		selcampo3.disabled=true;
	}
}

function envia_buscador_mini(){
	var form_busc_mini = document.getElementById('form_buscador_mini');
	var campo1 = document.getElementById('tipo_anuncio_buscas');
	if(campo1.value==1){
		form_busc_mini.action='buscador1.php';
	} else {
		form_busc_mini.action='buscador2.php';
	}
	var campo2 = document.getElementById('select_donde_buscas');
	if((campo2.disabled==false)&&(campo2.selectedIndex>0)){
		form_busc_mini.submit();
	} else {
		alert('Debe seleccionar Que busca \r\ny Dónde lo busca, \r\npara continuar. \r\n\r\nGracias.');
	}
}

function torna_buscador(){
	var form_tornar = document.getElementById('form_volver');
	form_tornar.submit();
}

function pinta_combo(combo_actiu){
	var selind = combo_actiu.selectedIndex;
	var class_activa = combo_actiu.className;
	if((class_activa=='buscador_mini_combo_mini_small')||(class_activa=='buscador_mini_combo_mini_small_active')){
		if(selind>0){
			combo_actiu.className="buscador_mini_combo_mini_small_active";
		} else {
			combo_actiu.className="buscador_mini_combo_mini_small";
		}
	}
	if((class_activa=='buscador_mini_combo_mini')||(class_activa=='buscador_mini_combo_mini_active')){
		if(selind>0){
			combo_actiu.className="buscador_mini_combo_mini_active";
		} else {
			combo_actiu.className="buscador_mini_combo_mini";
		}
	}
	if((class_activa=='buscador_mini_combo')||(class_activa=='buscador_mini_combo_active')){
		if(selind>0){
			combo_actiu.className="buscador_mini_combo_active";
		} else {
			combo_actiu.className="buscador_mini_combo";
		}
	}
}

function configura_doble(combo_actiu){
	pinta_combo(combo_actiu);
	var selind = combo_actiu.selectedIndex;
	var nom_camp = combo_actiu.name;
	var nom_camp1 = nom_camp+'1';
	var nom_camp2 = nom_camp+'2';
	var camp1 = document.getElementById(nom_camp1);
	var camp2 = document.getElementById(nom_camp2);
	var val1 = combo_actiu.options[selind].value;
	var val2 = combo_actiu.options[selind].lang;
	camp1.value = val1;
	camp2.value = val2;
}

function pinta_neteja(quants){
	// recorre la llista i posa el bg al correcte
	var alt = 1;
	for(i=0;i<quants;i++){
		var noui = i+1;
		elemento = "fila_"+noui;
		if(alt==1){ 
			document.getElementById(elemento).className='fila_gris1'; 
		} else { 
			document.getElementById(elemento).className='fila_gris2'; 
		}
		alt = alt*-1;
	}
}

function pinta(numero){
	var elemento = 'num_tot_filas';
	var tot_filas = document.getElementById(elemento).value;
	pinta_neteja(tot_filas);
	var elemento = "fila_"+numero;
	document.getElementById(elemento).className='fila_activa';
}

function reset_buscador(){
	document.form_buscador_mini.reset();
	document.form_buscador_mini.estatura1.value=0;
	document.form_buscador_mini.estatura2.value=99999;
	document.form_buscador_mini.peso1.value=0;
	document.form_buscador_mini.peso2.value=99999;
	document.form_buscador_mini.edad1.value=0;
	document.form_buscador_mini.edad2.value=99999;
	document.form_buscador_mini.medidas_pecho1.value=0;
	document.form_buscador_mini.medidas_pecho2.value=99999;
	document.form_buscador_mini.medidas_cintura1.value=0;
	document.form_buscador_mini.medidas_cintura2.value=99999;
	document.form_buscador_mini.medidas_caderas1.value=0;
	document.form_buscador_mini.medidas_caderas2.value=99999;
	document.form_buscador_mini.palabras_buscas.value='';
	document.form_buscador_mini.submit();
}

function login(lloc){
	elemento = "form_login_"+lloc;
	document.getElementById(elemento).submit();
}

function logout(){
	elemento = "form_logout";
	agree = confirm('¿Desea salir de la sesión activa / cambiar de usuario?');
	if (agree) {
		document.getElementById(elemento).submit();
	}
}

function eliminar_anuncio(id_anuncio_eliminado){
	elemento = "form_eliminar_anuncio_"+id_anuncio_eliminado;
	agree = confirm('¿Seguro que desea eliminar su anuncio de foma definitiva?');
	if (agree) {
		document.getElementById(elemento).submit();
	}
}

function eliminar_anuncio_local(id_anuncio_eliminado){
	elemento = "form_eliminar_anuncio_"+id_anuncio_eliminado;
	agree = confirm('¿Seguro que desea eliminar su anuncio? \nEste anuncio tiene otros anuncios relacionados. \nSi lo borra perderá todos los anuncios relacionados.');
	if (agree) {
		document.getElementById(elemento).submit();
	}
}

function actualizar_anuncio(id_anuncio_actualizar){
	elemento = "form_actualizar_anuncio_"+id_anuncio_actualizar;
	document.getElementById(elemento).submit();
}

function confirmar_anuncio(id_anuncio_confirmar){
	elemento = "form_confirmar_anuncio_"+id_anuncio_confirmar;
	agree = confirm('¿Confirma que quiere publicar este anuncio?');
	if (agree) {
		document.getElementById(elemento).submit();
	}
}

function modificar_anuncio(tipo,id_anunci) { 
    var agree=confirm('¿Esta seguro que quiere modificar su anuncio?\nSi acepta la modificación su anuncio estará temporalmente no publicado hasta ser revisado por un supervisor.'); 
    if (agree){ 
         window.location = "editar_anuncio"+tipo+".php?recordID="+id_anunci; 
    }     
}

function posa_usr_pwd(usuari,contrasenya){
	document.form_registro.usr_registro.value=usuari;
	document.form_registro.pwd_registro.value=contrasenya;
}

function valida_null(campo){
	var elemento = campo;
	elementID = document.getElementById(elemento);
	if ((elementID.value==null)||(elementID.value=="")){
		return false;
	}
	return true;
}

function valida_form_registro_edita(idioma){
	var campos = new Array("nombre","apellidos","direccion","ciudad","telefonos");
	var nom_campos_esp = new Array("Nombre","Apellidos","Dirección","Ciudad","Teléfono");	
	var elemento = "modificar_perfil";
	
	var provincia_activa = document.getElementById('provincia').selectedIndex;
	if(provincia_activa<1){
		alert("Debe seleccionar su provincia.");
		return false;
	}
	var ciudad_activa = document.getElementById('ciudad').selectedIndex;
	if(ciudad_activa<1){
		alert("Debe seleccionar su ciudad.");
		return false;
	} else {
		document.getElementById('ciudad_entrada').value=document.getElementById('ciudad').options[ciudad_activa].value;
	}
	
	var num_tel = document.getElementById(elemento).telefonos.value;
	if(isNaN(num_tel)){
		alert("Introduzca un teléfono válido\r\ncon los 9 números solamente.\r\nGracias");
		return false;
	}
	
	// comprobem nulls als camps
	for (i=0; i<campos.length; i++){
		var validat = valida_null(campos[i])
		if(validat==false){
			if(idioma=="esp"){
				alert('Error en validación de datos. Compruebe: '+nom_campos_esp[i]);
			return false;
			} else if(idioma=="cat"){
				alert('Error en la validació de dades. Comprovi: '+nom_campos_cat[i]);
			return false;
			}
		}
	}
	document.getElementById(elemento).submit();
}

function valida_form_registro(idioma){
	var campos = new Array("nombre","apellidos","direccion","ciudad","telefonos");
	var nom_campos_esp = new Array("Nombre","Apellidos","Dirección","Ciudad","Teléfono");	
	var elemento = "form_registro";
	
	var provincia_activa = document.getElementById('id_provincia').selectedIndex;
	if(provincia_activa<1){
		alert("Debe seleccionar su provincia.");
		return false;
	}
	var ciudad_activa = document.getElementById('ciudad').selectedIndex;
	if(ciudad_activa<1){
		alert("Debe seleccionar su ciudad.");
		return false;
	} else {
		document.getElementById('ciudad_entrada').value=document.getElementById('ciudad').options[ciudad_activa].value;
	}
	
	var num_tel = document.getElementById(elemento).telefonos.value;
	if(isNaN(num_tel)){
		alert("Introduzca un teléfono válido\r\ncon los 9 números solamente.\r\nGracias");
		return false;
	}
	
	// comprobem nulls als camps
	for (i=0; i<campos.length; i++){
		var validat = valida_null(campos[i])
		if(validat==false){
			if(idioma=="esp"){
				alert('Error en validación de datos. Compruebe: '+nom_campos_esp[i]);
			return false;
			} else if(idioma=="cat"){
				alert('Error en la validació de dades. Comprovi: '+nom_campos_cat[i]);
			return false;
			}
		}
	}
	document.getElementById(elemento).submit();
}

function comprobar_formulario_anuncio_prof(idioma){
	var campos = new Array("nombre","telefono","titulo");
	var nom_campos_esp = new Array("Nombre","Teléfono","Título");	
	var nom_campos_cat = new Array("Nom","Telèfon","Títol");
	var elemento = "form_nuevo_anuncio_profesional";
	// comprobem nulls als camps
	for (i=0; i<campos.length; i++){
		var validat = valida_null(campos[i]);
		if(validat==false){
			if(idioma=="esp"){
				alert('Error en validación de datos. Compruebe: '+nom_campos_esp[i]);
			return false;
			} else if(idioma=="cat"){
				alert('Error en la validació de dades. Comprovi: '+nom_campos_cat[i]);
			return false;
			}
		}
	}
	
	// comprobar telèfon
	var num_tel = document.getElementById(elemento).telefono.value;
	if(isNaN(num_tel)){
		alert("Introduzca un teléfono válido\r\ncon los 9 números solamente.\r\nGracias");
		return false;
	}
		
	// Comprobem desplegables
	var provincia_activa = document.getElementById('id_provincia');
	var index_provincia_activa = provincia_activa.selectedIndex;
	if(index_provincia_activa<1){
		alert("Debe seleccionar su provincia.");
		return false;
	}
	var ciudad_activa = document.getElementById('ciudad');
	var index_ciudad_activa = ciudad_activa.selectedIndex;
	if(index_ciudad_activa<1){
		alert("Debe seleccionar su ciudad.");
		return false;
	} else {
		document.getElementById('ciudad_entrada').value = ciudad_activa.options[index_ciudad_activa].value;
	}
	
	
	var arr_camps_select = new Array();
	arr_camps_select.push(document.getElementById('categorias_anuncio'));
	arr_camps_select.push(document.getElementById('orientacion'));
	arr_camps_select.push(document.getElementById('edad'));
	arr_camps_select.push(document.getElementById('medidas_pecho'));
	arr_camps_select.push(document.getElementById('medidas_cintura'));
	arr_camps_select.push(document.getElementById('medidas_caderas'));
	arr_camps_select.push(document.getElementById('estatura'));
	arr_camps_select.push(document.getElementById('peso'));
	arr_camps_select.push(document.getElementById('color_pelo'));
	arr_camps_select.push(document.getElementById('longitud_pelo'));
	arr_camps_select.push(document.getElementById('color_ojos'));
	arr_camps_select.push(document.getElementById('tarifa_minima'));
	
	var arr_noms_camps_select = new Array();
	arr_noms_camps_select.push('Categoría del anuncio');
	arr_noms_camps_select.push('Orientacion');
	arr_noms_camps_select.push('Edad');
	arr_noms_camps_select.push('Medidas pecho');
	arr_noms_camps_select.push('Medidas cintura');
	arr_noms_camps_select.push('Medidas caderas');
	arr_noms_camps_select.push('Estatura');
	arr_noms_camps_select.push('Peso');
	arr_noms_camps_select.push('Color de cabello');
	arr_noms_camps_select.push('Longitud de cabello');
	arr_noms_camps_select.push('Color de ojos');
	arr_noms_camps_select.push('Tarifa mínima');
	
	for (i=0; i<arr_camps_select.length; i++){
		var campo_activo = arr_camps_select[i];
		var index_activo = campo_activo.selectedIndex;
		if(index_activo<1){
			alert("Compruebe: "+arr_noms_camps_select[i]);
			return false;
		}
	}
	
	var arr_camps_select_chico = new Array();
	arr_camps_select_chico.push(document.getElementById('pene_longitud'));
	arr_camps_select_chico.push(document.getElementById('pene_diametro'));
	var arr_noms_camps_select_chico = new Array();
	arr_noms_camps_select_chico.push('Longitud del pene');
	arr_noms_camps_select_chico.push('Diámetro del pene');
	
	// comprobació camps chico
	var categoria_activa = document.getElementById('categorias_anuncio');
	var index_categoria_activa = categoria_activa.selectedIndex;
	var nom_categoria_activa = categoria_activa.options[index_categoria_activa].value;
	if((nom_categoria_activa=='chicos')||(nom_categoria_activa=='travestis')||(nom_categoria_activa=='parejas')){
		// és noi
		for (i=0; i<arr_camps_select_chico.length; i++){
			var campo_activo = arr_camps_select_chico[i];
			var index_activo = campo_activo.selectedIndex;
			if(index_activo<1){
				alert("Compruebe: "+arr_noms_camps_select_chico[i]);
				return false;
			}
		}
	}
	
	// comprobem checkboxs
	var camp_num_forma_pago = document.getElementById('num_forma_pago');
	if(camp_num_forma_pago!=null){
		var num_lugares = parseInt(document.getElementById('num_lugares').value)+1;
		var num_forma_pago = parseInt(document.getElementById('num_forma_pago').value)+1;
	
		var error_check1 = true;
		for (i=1; i<num_lugares; i++){
			var nom_campo_activo = "lugares_"+i;
			var campo_activo = document.getElementById(nom_campo_activo);
			if(campo_activo.checked == true){
				error_check1 = false;
			}
		}
		
		if(error_check1==true){
			alert("Debe seleccionar almenos un lugar.\r\nGracias.");
			return false;
		}
		
		var error_check2 = true;
		for (i=1; i<num_forma_pago; i++){
			var nom_campo_activo = "forma_pago_"+i;
			var campo_activo = document.getElementById(nom_campo_activo);
			if(campo_activo.checked == true){
				error_check2 = false;
			}
		}
		
		if(error_check2==true){
			alert("Debe seleccionar almenos una forma de pago.\r\nGracias.");
			return false;
		}
	}
	
	// si esta tot correcte afegim l'anunci
	document.getElementById(elemento).submit();
	//alert("OK");
}

function comprobar_formulario_anuncio_loc(idioma){
	var campos = new Array("nombre","telefono","direccion","titulo");
	var nom_campos_esp = new Array("Nombre","Teléfono","Dirección","Título");	
	var nom_campos_cat = new Array("Nom","Telèfon","Títol");
	var elemento = "form_nuevo_anuncio_local";
	// comprobem nulls als camps
	for (i=0; i<campos.length; i++){
		var validat = valida_null(campos[i]);
		if(validat==false){
			if(idioma=="esp"){
				alert('Error en validación de datos. Compruebe: '+nom_campos_esp[i]);
			return false;
			} else if(idioma=="cat"){
				alert('Error en la validació de dades. Comprovi: '+nom_campos_cat[i]);
			return false;
			}
		}
	}
	
	if(document.getElementById('telefono').lang=='ko'){
		alert('Error en validación de datos. Compruebe: Teléfono');
		return false;
	}
	
	// comprobar telèfon
	var num_tel = document.getElementById(elemento).telefono.value;
	if(isNaN(num_tel)){
		alert("Introduzca un teléfono válido\r\ncon los 9 números solamente.\r\nGracias");
		return false;
	}
		
	// Comprobem desplegables
	var provincia_activa = document.getElementById('id_provincia');
	var index_provincia_activa = provincia_activa.selectedIndex;
	if(index_provincia_activa<1){
		alert("Debe seleccionar su provincia.");
		return false;
	}
	var ciudad_activa = document.getElementById('ciudad');
	var index_ciudad_activa = ciudad_activa.selectedIndex;
	if(index_ciudad_activa<1){
		alert("Debe seleccionar su ciudad.");
		return false;
	} else {
		document.getElementById('ciudad_entrada').value = ciudad_activa.options[index_ciudad_activa].value;
	}
	
	
	var arr_camps_select = new Array();
	arr_camps_select.push(document.getElementById('categorias_anuncio'));
	arr_camps_select.push(document.getElementById('tarifa_minima'));
	
	var arr_noms_camps_select = new Array();
	arr_noms_camps_select.push('Categoría del anuncio');
	arr_noms_camps_select.push('Tarifa mínima');
	
	for (i=0; i<arr_camps_select.length; i++){
		var campo_activo = arr_camps_select[i];
		var index_activo = campo_activo.selectedIndex;
		if(index_activo<1){
			alert("Compruebe: "+arr_noms_camps_select[i]);
			return false;
		}
	}
	

	// comprobem checkboxs
	var camp_num_forma_pago = document.getElementById('num_forma_pago');
	if(camp_num_forma_pago!=null){
		var num_forma_pago = parseInt(document.getElementById('num_forma_pago').value)+1;

		var error_check2 = true;
		for (i=1; i<num_forma_pago; i++){
			var nom_campo_activo = "forma_pago_"+i;
			var campo_activo = document.getElementById(nom_campo_activo);
			if(campo_activo.checked == true){
				error_check2 = false;
			}
		}
		
		if(error_check2==true){
			alert("Debe seleccionar almenos una forma de pago.\r\nGracias.");
			return false;
		}
	}
	
	// si esta tot correcte afegim l'anunci
	document.getElementById(elemento).submit();
	//alert("OK");
}

function activa_desactiva_pene_entrada(){
	
	var arr_camps_select_chico = new Array();
	arr_camps_select_chico.push(document.getElementById('pene_longitud'));
	arr_camps_select_chico.push(document.getElementById('pene_diametro'));
	var arr_noms_camps_select_chico = new Array();
	arr_noms_camps_select_chico.push('Longitud del pene');
	arr_noms_camps_select_chico.push('Diámetro del pene');
	
	var categoria_activa = document.getElementById('categorias_anuncio');
	var index_categoria_activa = categoria_activa.selectedIndex;
	var nom_categoria_activa = categoria_activa.options[index_categoria_activa].value;
	if((nom_categoria_activa=='chicos')||(nom_categoria_activa=='travestis')||(nom_categoria_activa=='parejas')){
		// és noi
		for (i=0; i<arr_camps_select_chico.length; i++){
			var campo_activo = arr_camps_select_chico[i];
			campo_activo.selectedIndex = 0;
			campo_activo.disabled=false;
		}
	} else {
		// no és noi. Descativem els camps
		for (i=0; i<arr_camps_select_chico.length; i++){
			var campo_activo = arr_camps_select_chico[i];
			campo_activo.selectedIndex = 0;
			campo_activo.disabled=true;
		}
	}
}

function anar_home(){
	top.location="http://www.relaxfinder.com";
}

function elimina_foto(arxiu){
	elemento = 'form_elimina_foto_'+arxiu;
	agree = confirm(' Eliminar imagen? ');
	if (agree) {
		document.getElementById(elemento).submit();
	}
}


function backButtonOverrideBody(){
  // Works if we backed up to get here
  try {
    history.forward();
  } catch (e) {
    // OK to ignore
  }
  setTimeout("backButtonOverrideBody()", 500);
}

function backButtonOverride(){
	//alert('No utilice el botón atrás de su navegador \no dañará la integridad de los datos actuales del pedido en curso.\n\nUtilice las opciones que le ofrece la aplicación.\n\nGracias.');
	setTimeout("backButtonOverrideBody()", 1);
}

function baja_usuario(){
	elemento = 'form_elimina_perfil';
	agree = confirm(' Seguro que desea Eliminar su Perfil de usuario en Relax Finder?\r\n\r\nAtención: TODOS los datos asociados a su cuenta serán eliminados,\r\n\incluyendo TODOS los anuncios que tenga publciados.');
	if (agree) {
		document.getElementById(elemento).submit();
	}
}

function comprobar_existeix(valor,camp,taula,bt_enviar,extra_cond){
	var val_taulaactiva = taula;
	var val_campactiu = camp;
	var val_valoractiu = valor; 
	var elem_bt_enviar = bt_enviar;
	var obj_camp_actiu = document.getElementById(val_campactiu);
	var val_extra_cond = extra_cond;
	var contenedor = document.getElementById('ct_'+val_campactiu);
	var bt_insertar_registro = document.getElementById(elem_bt_enviar);

	if(val_valoractiu!=''){
		if(estat_ajax == 'OK'){
			estat_ajax = 'KO';
			
			bt_insertar_registro.disabled=true;
			
			ajax=nuevoAjax();
		
			ajax.open("POST", "../ajax/comprova_existeix_camp.php", true);
			ajax.onreadystatechange=function() {
				if (ajax.readyState==0) {	contenedor.innerHTML = '<img src="../icons/icon_loading3.gif" alt="-" width="16" height="16">';} //INTERACTUANDO
				if (ajax.readyState==1) {	contenedor.innerHTML = '<img src="../icons/icon_loading3.gif" alt="-" width="16" height="16">';} //INTERACTUANDO
				if (ajax.readyState==2) {	contenedor.innerHTML = '<img src="../icons/icon_loading3.gif" alt="-" width="16" height="16">';} //INTERACTUANDO
				if (ajax.readyState==3) {	contenedor.innerHTML = '<img src="../icons/icon_loading3.gif" alt="-" width="16" height="16">';} //INTERACTUANDO
				if (ajax.readyState==4) { //COMPLETADO
					bt_insertar_registro.disabled=false;
					estat_ajax = 'OK';
					var resultat_esperat = ajax.responseText;
					if(resultat_esperat=='ok'){
						obj_camp_actiu.lang = "ok";
						contenedor.innerHTML = '<img src="../icons/1_w.gif" width="15" height="15" border="0" align="absmiddle" >';
					} else {
						obj_camp_actiu.lang = "ko";
						contenedor.innerHTML = '<img src="../icons/0_w.gif" width="15" height="15" border="0" align="absmiddle" >';
					}
				}
			}
			ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			var variables_ajax = "taula_activa="+val_taulaactiva+"&camp_actiu="+val_campactiu+"&valor_actiu="+val_valoractiu+"&extra_cond="+val_extra_cond;
			ajax.send(variables_ajax);
		} else {
			obj_txt_pwd.focus();
		}
	}
}
