
	var IE = document.all?true:false;
	if (!IE) document.captureEvents (Event.MOUSEMOVE)
	document.onmousemove = getMouseXY;	
	var posicionx = 0;
	var posiciony = 0;

	function getIEversion () {
    	var rv = -1; // Return value assumes failure.
    	if (navigator.appName == 'Microsoft Internet Explorer') {
	        var ua = navigator.userAgent;
    	    var re = new RegExp ("MSIE ([0-9]{1,}[\.0-9]{0,})");
        	if (re.exec (ua) != null)
            	rv = parseFloat (RegExp.$1);

    	}
		return rv;
	}

	if (getIEversion () == 8) {
		var IE8 = 1;
	} else var IE = 0;

	function cambiaImagenesPosturas (tipo) {
		for (i = 1; i < 7; i++) {
			document.getElementById ('postura' + i).src = 'imagenes/virginidad/postura' + tipo + i + '.jpg';
		}
	}
	
	function desactivar (id) {		
		document.getElementById(id).innerHTML = 'Enviando ...';		
	}
	
	function eligeOpcionVirginidad (obj, oculto, parent, resto, etiqueta, texto, lista, indice) {
		document.getElementById (oculto).value = obj.src;
		for (i = 1; i < 7; i++) 
			document.getElementById (resto + i).style.background = '#FFFFFF';					
		document.getElementById (parent).style.background = '#0000FF';
		document.getElementById (etiqueta).value = 0;		
		muestraFraseVirginidad (texto, lista, indice, etiqueta);
		document.getElementById (etiqueta).value = 1;
	}

	function validaFormConfig () {
		if (document.getElementById ('sexo') == (-1))
			alert ('No has seleccionado tu sexo!');
		else document.formPref.submit();
	}

	function muestraFraseVirginidad (obj, lista, indice, etiqueta) {
		if (document.getElementById (etiqueta).value == 0) {			
			if (obj == 'tpostura') {
				var ttendencia = document.getElementById('tendencia');			
				document.getElementById (obj).innerHTML = lista[indice][ttendencia.selectedIndex];
			} else document.getElementById (obj).innerHTML = lista[indice];
		}
	}
	
	function borraFraseVirginidad (obj, etiqueta) {
		if (document.getElementById (etiqueta).value == 0) 
			document.getElementById (obj).innerHTML = '';
	}

	function validaFormularioVirginidad () {	
		document.getElementById ('slugar').value = document.getElementById ('tlugar').innerHTML;
		document.getElementById ('sestilo').value = document.getElementById ('testilo').innerHTML;
		document.getElementById ('spostura').value = document.getElementById ('tpostura').innerHTML;
		document.getElementById ('sjuguete').value = document.getElementById ('tjuguete').innerHTML;		
		if (document.getElementById ('tunombre').value == '') {
			alert ('No has escrito tu nombre o apodo!');
		} else if (document.getElementById ('sunombre').value == '') {
			alert ('No has escrito su nombre o apodo!');			
		} else if (document.getElementById ('tuemail').value.match ('Escribe tu')) {
			alert ('No has escrito tu e-mail!');			
		} else if (document.getElementById ('suemail').value == '') {
			alert ('No has escrito su e-mail!');			
		} else if (document.getElementById ('slugar').value == 0) {
			alert ('No has elegido el sitio!');				
		} else if (document.getElementById ('sestilo').value == 0) {
			alert ('No has elegido el estilo!');				
		} else if (document.getElementById ('spostura').value == 0) {
			alert ('No has elegido la postura!');				
		} else if (document.getElementById ('sjuguete').value == 0) {
			alert ('No has elegido el juguete!');		
		} else if (document.getElementById ('tuemail').value != document.getElementById ('tuemail2').value) {
			alert ('No has escrito tu e-mail correctamente!');
		} else if (document.getElementById ('suemail').value != document.getElementById ('suemail2').value) {
			alert ('No has escrito el e-mail de tu pareja correctamente!');			
		} else {
			document.enviar.submit();
		}
	}

	function cambiaHatenido (valor) {
		document.getElementById ('estado').value = valor;
	}
	
	function cambiaHatenidoEjecuta (valor, id, fecha) {
		var http = new Array ();
		var resultado = new Array ();
		var curDateTime = new Date ();
		http[curDateTime] = createRequestObject ();
		http[curDateTime].open ('post', 'cambiaestado.php');
		http[curDateTime].setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');
    	http[curDateTime].send ('id=' + id + '&estado=' + valor); 
		alert ('Ahora puedes modificar los detalles de esta experiencia');
		document.location = 'nuevaexperiencia.php?editar=' + id + '&fecha=' + fecha;
	}

	function validarCambioPassword () {
		var cactual = document.getElementById ('cactual').value;
		var cnueva = document.getElementById ('cnueva').value;		
		var cnueva2 = document.getElementById ('cnueva2').value;		
		if (cnueva != cnueva2)
			alert ('No coinciden los valores. ');
		else document.getElementById ('formCambio').submit ();
	}

	function vigilaCampoComunidad () {
		var selector = document.getElementById ('tendencia');
		var opcionor = selector.options[selector.selectedIndex].value;
		if (opcionor != 3) {
			(document.getElementById ('compartir')).disabled = '';
			(document.getElementById ('tituloquiero')).setAttribute ("className", 'normal');	
			(document.getElementById ('tituloquiero')).setAttribute ("class", 'normal');				
		} else {  
			(document.getElementById ('compartir')).disabled = 'disabled';
			(document.getElementById ('compartir')).checked = 0;	
			(document.getElementById ('tituloquiero')).setAttribute ("className", 'desactivado');				
			(document.getElementById ('tituloquiero')).setAttribute ("class", 'desactivado');							
		}
	}

	function verificaRegistro ($usuario, $password, $password2) {
		if ($password == $password2) { 
			if ($usuario.length == 0)
				alert ('Tu apodo no puede estar vacio.');			
			else if ($password.length == 0)
				alert ('La contraseña no puede estar vacia.');
			else document.formInvitacion.submit(); 
		} else alert ('Las contraseñas no coinciden. '); 
		
	}

	function getMouseXY (e) {
		if (IE) { 
			posicionx = event.clientX + document.body.scrollLeft;
			posiciony = event.clientY + document.body.scrollTop;
		} else {  
			posicionx = e.pageX;
			posiciony = e.pageY;
		}  
		if (posicionx < 0) posicionx = 0;
		if (posiciony < 0) posiciony = 0;	
		return true;
	}

	function createRequestObject () {
		var request_;
		var browser = navigator.appName;
		if (browser == "Microsoft Internet Explorer") {
			request_ = new ActiveXObject ("Microsoft.XMLHTTP");
		} else { request_ = new XMLHttpRequest (); }
		return request_;
	}
		
	function eliminarComentario (obj, pareja, tipo, formato) {
		var id = obj.id;
		var http = new Array ();
		var curDateTime = new Date ();
		http[curDateTime] = createRequestObject ();
		http[curDateTime].open ('post', 'borrarcomentario.php');
		http[curDateTime].setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');
    	http[curDateTime].send ('tipo=' + tipo + '&id=' + id + '&elemento=' + pareja); 
		http[curDateTime].onreadystatechange = function () {
			if (http[curDateTime].readyState == 4) {
		    	if (http[curDateTime].status == 200 || http[curDateTime].status == 304) {			
		        	var response = http[curDateTime].responseText;	
					mostrarComentarios (response, tipo, formato);
		        }
		    }
		}		
	}
	
	function buscarUsuario (apodo) {
		var http = new Array ();
		var curDateTime = new Date ();
		document.getElementById ('botonbuscar').innerHTML = 'Buscando';
		http[curDateTime] = createRequestObject ();
		http[curDateTime].open ('post', 'buscarusuario.php');
		http[curDateTime].setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');
    	http[curDateTime].send ('buscar=' + apodo); 
		http[curDateTime].onreadystatechange = function () {
			if (http[curDateTime].readyState == 4) {
		    	if (http[curDateTime].status == 200 || http[curDateTime].status == 304) {			
		        	var response = http[curDateTime].responseText;	
					if (response == "0")
						alert ('No hemos encontrado a nadie con ese apodo!');
					else document.location ='usuario.php?id=' + response;
					document.getElementById ('botonbuscar').innerHTML = '<a href="javascript:buscarUsuario (document.getElementById (\'buscar\').value);" class="minipopup">Buscar</a>';					
		        }
		    }
		}		
	}	
	
	function reenviarInvitacion () {
		document.getElementById ('botonenviar').innerHTML = '<a href="javascript:enviarInvitacionUsuario();" class="pequeno2">Enviar invitaci&oacute;n</a>';
		document.getElementById ('emaili').value = 'Escribe el e-mail';
		document.getElementById ('emaili').select ();
	}
		
	function solicitarInvitacion () {
		var email = document.getElementById ('nemail');
		if (email.value != "")
			document.registro.submit();
		else alert ('Tienes que escribir tu e-mail para solicitar la invitacion ');
	}
		
	function enviarInvitacionUsuario () {
		var email = document.getElementById ('emaili').value;
		var departede = document.getElementById ('departede').value;
		var http = new Array ();
		document.getElementById ('botonenviar').innerHTML = 'Enviando ...';
		var curDateTime = new Date ();
		http[curDateTime] = createRequestObject ();
		http[curDateTime].open ('post', 'enviarinvitacion.php');
		http[curDateTime].setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');
    	http[curDateTime].send ('departede=' + departede + '&email=' + email); 
		http[curDateTime].onreadystatechange = function () {
			if (http[curDateTime].readyState == 4) {
		    	if (http[curDateTime].status == 200 || http[curDateTime].status == 304) {			
		        	var response = http[curDateTime].responseText;	
					document.getElementById ('botonenviar').innerHTML = '&iexcl;Enviada!';
					document.getElementById ('emaili').value = '';
					document.getElementById ('labelninvit').innerHTML = response;
					alert ('Tu invitacion se ha enviado correctamente ');	
					if (response > 0) {
						document.getElementById ('mrespuestai').innerHTML = 'Tu invitaci&oacute;n se ha enviado correctamente <a href="javascript:reenviarInvitacion();">&iquest;Quieres enviar otra?</a>';
					} else {
						document.getElementById ('tablainvit').innerHTML = '<span class="resaltado" style="padding-left:20px;">&iexcl;Has agotado tus invitaciones!</span>';
						document.getElementById ('mrespuestai').innerHTML = 'Tu invitaci&oacute;n se ha enviado correctamente';
					}
		        }
		    }
		}		
	}	

	function enviarPropuestaEmail () {
		var email = document.getElementById ('enviaprop').value;
		var departede = document.getElementById ('departede').value;
		var propuesta = document.getElementById ('propuesta').value;
		var http = new Array ();
		document.getElementById ('botonenviar').innerHTML = 'Enviando ...';
		var curDateTime = new Date ();
		http[curDateTime] = createRequestObject ();
		http[curDateTime].open ('post', 'enviarpropuesta.php');
		http[curDateTime].setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');
    	http[curDateTime].send ('departede=' + departede + '&email=' + email + '&propuesta=' + propuesta); 
		http[curDateTime].onreadystatechange = function () {
			if (http[curDateTime].readyState == 4) {
		    	if (http[curDateTime].status == 200 || http[curDateTime].status == 304) {			
		        	var response = http[curDateTime].responseText;	
					document.getElementById ('botonenviar').innerHTML = '&iexcl;Enviada!';
					document.getElementById ('enviaprop').value = '';
					alert ('Hemos enviado tu propuesta! ');	
		        }
		    }
		}		
	}	

	function enviarComentarioEmail () {
		var email = document.getElementById ('enviacom').value;
		var departede = document.getElementById ('departede').value;
		var comentario = document.getElementById ('comentario').value;
		var http = new Array ();
		document.getElementById ('botonenviar').innerHTML = 'Enviando ...';
		var curDateTime = new Date ();
		http[curDateTime] = createRequestObject ();
		http[curDateTime].open ('post', 'enviarcomentario.php');
		http[curDateTime].setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');
    	http[curDateTime].send ('departede=' + departede + '&email=' + email + '&comentario=' + comentario); 
		http[curDateTime].onreadystatechange = function () {
			if (http[curDateTime].readyState == 4) {
		    	if (http[curDateTime].status == 200 || http[curDateTime].status == 304) {			
		        	var response = http[curDateTime].responseText;	
					document.getElementById ('botonenviar').innerHTML = '&iexcl;Enviado!';
					document.getElementById ('enviacom').value = '';
					alert ('Hemos enviado este comentario! ');	
		        }
		    }
		}		
	}	

	function cambioMes (tipo, mes, ano) {
		if (tipo == 0) {
  			var c = new Calendar ();
		} else if (tipo == (-1)) {
			if (mes == 0) 
  				var c = new Calendar (11, ano - 1);
			else var c = new Calendar (mes - 1, ano);
		} else if (tipo == 1) {
			if (mes == 11) 
  				var c = new Calendar (0, ano + 1);
			else var c = new Calendar (mes + 1, ano);	
		}
		c.generateHTML ();
		document.getElementById ('calendario').innerHTML = c.getHTML ();
		return c;
	}
		
	function cargaEstadoPareja (estado) {
		var lista = document.getElementById ('situacion');
		for (var i = 0; i < lista.length; i++) {
			if (estado == lista.options[i].id)
				lista.options[i].selected = "selected";
		}
	}
		
	function cargaAnoPareja (fecha) {
		var ano = fecha.substring(0, 4);
		var lista = document.getElementById ('anocono');
		for (var i = 0; i < lista.length; i++) {
			if (ano == lista.options[i].value)
				lista.options[i].selected = "selected";
		}
	}
		
	function mostrarNuevoComentario () {
		var nc = document.getElementById ('tablacom');
		if (nc.style.visibility == 'hidden') {
			nc.style.visibility = 'visible';
			nc.style.display = '';	
			document.getElementById ('ncomentario').select ();
		} else {
			nc.style.visibility = 'hidden';
			nc.style.display = 'none';			
		}
	}	
	
	function mostrarCuadroCom (id) {
		var nc = document.getElementById (id);
		if (nc.style.visibility == 'hidden') {
			nc.style.visibility = 'visible';
			nc.style.display = '';	
		} else {
			nc.style.visibility = 'hidden';
			nc.style.display = 'none';			
		}
	}
	
	function crearTablon () {
		document.getElementById ('botoncreart').innerHTML = 'Creando tabl&oacute;n ...';
		document.getElementById ('formnuevotablon').submit();
	}
	
	function enviaComentarioTablon () {
		if (document.getElementById ('comentario').value != '') {
			document.getElementById ('botonecom').innerHTML = 'Enviando comentario ...';
			document.getElementById ('formtablon').submit();		
		} else alert ('No has escrito nada!');
	}

	function publicaComPro () {
		document.getElementById ('botonepro').innerHTML = 'Enviando comentario ...';		
		if (document.getElementById ('formtablon').comentario.value.length != 0) 
			document.getElementById ('formtablon').submit(); 
		else alert ('No has escrito nada!');
	}	

	function publicaComSug () {
		document.getElementById ('botonesug').innerHTML = 'Enviando comentario ...';		
		if (document.getElementById ('formtablon').comentario.value.length != 0) 
			document.getElementById ('formtablon').submit(); 
		else alert ('No has escrito nada!');
	}	

	function incluirFavorito (id) {
		document.getElementById ('botonafav').innerHTML = 'Incluyendo en tus favoritos ...';
		document.location = 'usuario.php?id=' + id + '&favorito=si';
	}
	
	function publicarMuro () {
		var texto = document.getElementById ('mensajemuro').value;		
		if (texto == '') {
			alert ('No has escrito nada!');
		} else {
			document.getElementById ('botonpmuro').innerHTML = 'Publicando ...';
			document.getElementById ('fmsjmuro').submit ();
		}
	}
	
	function comentarMuro (id) {
		var texto = document.getElementById ('murocom' + id).value;		
		if (texto == '') {
			alert ('No has escrito nada!');			
		} else {
			document.getElementById ('botonpmurocom').innerHTML = 'Publicando ...';		
			document.getElementById ('fmurocom' + id).submit ();
		}
	}

	function comentarSabiasque (id) {
		var texto = document.getElementById ('comsq' + id).value;		
		if (texto == '') {
			alert ('No has escrito nada!');			
		} else {
			document.getElementById ('botonpsabiasquecom' + id).innerHTML = 'Publicando ...';		
			document.getElementById ('comsabiasque' + id).submit ();
		}
	}
	
	function comentarTablon (id) {
		var texto = document.getElementById ('comtablon' + id).value;		
		if (texto == '') {
			alert ('No has escrito nada!');			
		} else {
			document.getElementById ('botonptabloncom' + id).innerHTML = 'Publicando ...';		
			document.getElementById ('comtablon' + id).submit ();
		}
	}	
	
	function comentarPropuesta (id) {
		var texto = document.getElementById ('comprop' + id).value;		
		if (texto == '') {
			alert ('No has escrito nada!');			
		} else {
			document.getElementById ('botonppropcom' + id).innerHTML = 'Publicando ...';		
			document.getElementById ('comprop' + id).submit ();
		}
	}		

	function nuevaExperienciaCalendario () {
		document.location = 'nuevaexperiencia.php?fecha=' + document.getElementById ('fechasel').value;
	}
	
	function imagenSeleccionada (id, idcontenedor) {
		if (idcontenedor == 'pareja')
			muestraCatalogo (idcontenedor);
		document.getElementById ('imagen').value = document.getElementById (id).src;
		document.getElementById ('imageshow').src = document.getElementById (id).src;
	}
	
	function validarFormExperiencia () {
		if (document.getElementById ('parejasel').value == (-1)) {
			alert ('Tienes que elegir con quien has tenido esta experiencia.');
		} else document.getElementById ('formNueva').submit();		
	}
	
	function parejaSeleccionada (id, nombre, mostrar) {
		if (mostrar == 1)
			muestraCatalogo ('pareja');
		document.getElementById ('imagenpareja').src = document.getElementById (id).src;	
		document.getElementById ('enlacepareja').innerHTML = nombre;	
		document.getElementById ('enlacepareja').href = 'pareja.php?id=';	
		document.getElementById ('parejasel').value = id;
	}
	
	function muestraCatalogo (id) {
		var catalogo = document.getElementById (id);
		if (catalogo != null) {
			if (catalogo.style.visibility == 'hidden') {
				catalogo.style.visibility = 'visible';
				catalogo.style.display = '';			
			} else {
				catalogo.style.visibility = 'hidden';
				catalogo.style.display = 'none';			
			}
		}
	}
		
	function publicarComentario (elemento, mensaje, tipo, formato) {
		var http = new Array ();
		var resultado = new Array ();
		var curDateTime = new Date ();
		http[curDateTime] = createRequestObject ();
		http[curDateTime].open ('post', 'nuevocomentario.php');
		http[curDateTime].setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');
    	http[curDateTime].send ('mensaje=' + mensaje + '&elemento=' + elemento + '&tipo=' + tipo); 
		http[curDateTime].onreadystatechange = function () {
			if (http[curDateTime].readyState == 4) {
		    	if (http[curDateTime].status == 200 || http[curDateTime].status == 304) {			
		        	var response = http[curDateTime].responseText;	
					mostrarNuevoComentario ();
					mostrarComentarios (response, tipo, formato);
		        }
		    }
		}
	}
	
	function dameImagenExperiencia (id) {
		var http = new Array ();
		var resultado = new Array ();
		var curDateTime = new Date ();
		http[curDateTime] = createRequestObject ();
		http[curDateTime].open ('post', 'imagenexperiencia.php');
		http[curDateTime].setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');
    	http[curDateTime].send ('id=' + id); 
		http[curDateTime].onreadystatechange = function () {
			if (http[curDateTime].readyState == 4) {
		    	if (http[curDateTime].status == 200 || http[curDateTime].status == 304) {			
		        	var response = http[curDateTime].responseText;	
					document.getElementById ('exp' + id).src = response;
		        }
		    }
		}
	}	
	
	function mostrarComentarios (response, tipo, formato) {
		var componentes = response.split ('<s>');
		var html = '';
		var p1 = 0;
		var p2 = 0;
		var p3 = 0;		
		var p4 = 0;
		var p5 = 0;
		if (formato == 0) {
			p1 = 296;	
			p2 = 55;
			p3 = 239;
			p4 = 175;
			p5 = 64;
		} else {
			p1 = 359;
			p2 = 60;
			p3 = 362;
			p4 = 236;
			p5 = 65;
		} 
		for (var i = 0; i < (componentes.length-1); i++) {
			var registro = componentes[i].split ('\|');	
			registro[0] = registro[0].replace (/^\s*|\s*$/g,"");			
			html = html + '<table width="' + p1 + '" height="50" border="0" cellpadding="0" cellspacing="0" style="border: 1px solid #999999; background-image: url(\'imagenes/fondoexp.png\'); background-repeat: repeat-x;">';
			html = html + '<tr>';
			html = html + '<td width="' + p2 + '" rowspan="2" valign="top" style="padding-top:8px;"><div align="center"><img src="imagenes/comentario.png" /></div></td>';
			html = html + '<td width="' + p3 + '" height="22" valign="bottom"><table border="0" cellpadding="0" cellspacing="0">';
            html = html + '<tr>';
			html = html + '<td width="' + p4 + '"><span class="pequeno2">' + registro[0] + '</span></td>';
			html = html + '<td width="' + p5 + '"><div align="left" class="pequeno"><a id="' + registro[2] + '"'; 
			html = html + 'href="javascript:eliminarComentario(document.getElementById(' + registro[2] + '),' + registro[3] + ',' + tipo + ',' + formato + ');">Eliminar</a></div></td>';
			html = html + '</tr>';
			html = html + '</table>';
			html = html + '</td>';
			html = html + '</tr>';
			html = html + '<tr>';	
			html = html + '<td height="32" valign="middle" class="lista" style="padding-right: 20px; padding-bottom: 5px; padding-top: 5px;">' + registro[1] + '</td>';
			html = html + '</tr>';
			html = html + '<tr>';
			html = html + '<td height="8" colspan="2"></td>';
			html = html + '</tr></table><br />';
		}
		document.getElementById ('comentarios').innerHTML = html;
	}
	
	function dameExperienciasMes (mes, ano) {
		var http = new Array ();
		var resultado = new Array ();
		var curDateTime = new Date ();
		http[curDateTime] = createRequestObject ();
		http[curDateTime].open ('post', 'experienciasmes.php');
		http[curDateTime].setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');
    	http[curDateTime].send ('mes=' + mes + '&ano=' + ano); 
		http[curDateTime].onreadystatechange = function () {
			if (http[curDateTime].readyState == 4) {
		    	if (http[curDateTime].status == 200 || http[curDateTime].status == 304) {			
		        	var response = http[curDateTime].responseText;
					var componentes = response.split ('<s>');
					for (var i = 0; i < (componentes.length-1); i++) {
						var registro = componentes[i].split ('-');	
						registro[0] = registro[0].replace (/^\s*|\s*$/g,"");
						var contenedor = document.getElementById ('p' + registro[0]);
						if (contenedor.value != 0)
							contenedor.value = contenedor.value + '|' + registro[1];
						else contenedor.value = registro[1];
						var cuadro = document.getElementById ('d' + registro[0]);
						if (registro[2] == 0) {
							cuadro.setAttribute ("className", "dia-con"); 
							cuadro.setAttribute ("class", "dia-con");
						} else if (registro[2] == 2) {
							cuadro.setAttribute ("className", "dia-men"); 
							cuadro.setAttribute ("class", "dia-men");							
						} else {
							cuadro.setAttribute ("className", "dia-pre"); 
							cuadro.setAttribute ("class", "dia-pre");
						}
						resultado[i] = registro; 
					}
		        }
		    }
		}
		return resultado;
	}

	function seleccionaSexoConfig (tipo) {
		var tipo2 = 1;
		if (tipo == 2)
			tipo2 = 3;
		if (tipo == 1)
			tipo2 = 0;
		creaCatalogo (tipo2, 'divavatar');
		if (document.getElementById ('Image1') != null)
			seleccionaSexo (tipo, 1); 
		else if (tipo == 2)
			seleccionaSexo (tipo, -1);
	}

	function creaCatalogo (sexo, div) {
		var http = new Array ();
		var resultado = new Array ();
		var curDateTime = new Date ();
		http[curDateTime] = createRequestObject ();
		http[curDateTime].open ('post', 'avatares.php');
		http[curDateTime].setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');		
    	http[curDateTime].send ('sexo=' + sexo); 
		http[curDateTime].onreadystatechange = function () {
			if (http[curDateTime].readyState == 4) {
		    	if (http[curDateTime].status == 200 || http[curDateTime].status == 304) {			
		        	var response = http[curDateTime].responseText;
					var componentes = response.split ('<s>');
					var html = '<table>';
					for (var i = 0; i < (componentes.length-1); i = i+8) {			
						html = html + '<tr>';
						html = html + '<td height="40">&nbsp;</td>';
						for (var j = i; j < (i + 8); j++) {
							componentes[j] = componentes[j].replace (/^\s*|\s*$/g,"");
							if (j >= (componentes.length - 1))
								break;							
							idimagen = componentes[j].substring (0, componentes[j].indexOf ("."));
							html = html + '<td width="40"><div align="center"><img onmouseover="PopEx(this,-12,-12,60,60,20,null);" onmouseout="Revert(this,20,null);" pbshowrevertbar="false" pbshowreverttext="false" pbshowrevertimage="false" id="' + idimagen + '" src="imagenes/predefinidas' + sexo + '/' + componentes[j] + '" width="30" height="30" onclick="imagenSeleccionada(\'' + idimagen + '\', \'' + div + '\');" /></div></td>'
						}
						html = html + '<td >&nbsp;</td>';
						html = html + '</tr>';
					}
					html = html + '</table>';					
					document.getElementById (div).innerHTML = html;
		        }
		    }
		}
		return resultado;
	}

	function mostrarGrafica (tipo, id, usuario, nparejas) {
		var estadisticas = document.getElementById ('estadisticas');
		var mensajegr = document.getElementById ('mensajegr');
		if (nparejas == 0) {
			estadisticas.style.visibility = 'hidden';
			estadisticas.style.display = 'none';
			mensajegr.innerHTML = '<span style="margin-bottom: 50px; margin-left: 10px; line-height: 60px;">Todav&iacute;a no has anotado ninguna pareja</span>';
			return;
		} else {
			mensajegr.innerHTML = '';
			estadisticas.style.visibility = 'visible';
			estadisticas.style.display = '';
		}
		var imagen = document.getElementById (id);
		var src = 'imagenes/graficas/' + usuario;
		if (tipo == 1)
			imagen.src = src + '-ev.png';
		else if (tipo == 2)
			imagen.src = src + '-ch.png';	
		else if (tipo == 3)
			imagen.src = src + '-ka.png';	
		else imagen.src = src + '-sa.png';	
	}

	function verExperiencia () {
		var dia = document.getElementById ('diasel').value;
		var idexp = document.getElementById ('p' + dia).value;
		document.location = 'experiencia.php?id=' + idexp;
	}

	function pintarExperiencias (dia) {
		var ids = document.getElementById ('p' + dia).value;
		var aids = ids.split ('\|');
		var contenido = '';
		for (var i = 0; i < aids.length; i++) {
			contenido = contenido + '<a href="experiencia.php?id=' + aids[i] + '"><img style="margin-top:10px; margin-bottom:10px;" border="0" width="25" height="25" id="exp' + aids[i] + '" src=""></a>&nbsp;&nbsp;';
			dameImagenExperiencia (aids[i]);
		}
		document.getElementById ('contenidoexps').innerHTML = contenido;
	}

	function mostrarPopup (tipo, cdia, dia) {
		if (tipo == 0) {
			var popup = document.getElementById ('popup-sin');
			var cierre = document.getElementById ('popup-con');
		} else {
			var popup = document.getElementById ('popup-con');	
			pintarExperiencias (dia);
			var cierre = document.getElementById ('popup-sin');
		}
		if (popup.style.visibility == 'hidden') {
			var calobj = document.getElementById('calendario');
			if (!IE)
				var offs = calobj.offsetTop;
			else var offs = calobj.offsetTop - document.documentElement.scrollTop;
			popup.style.marginTop = (posiciony - offs - 415) + 'px';	
			iw = window.innerWidth;
			if (IE)
				iw = (document.documentElement).clientWidth;
			var margenh = (iw - 900)/2;
			popup.style.marginLeft = (posicionx - margenh - 80) + 'px';
			popup.style.visibility = 'visible';
			popup.style.display = '';
		} else {
			popup.style.visibility = 'hidden';
			popup.style.display = 'none';	
		}
		cierre.style.visibility = 'hidden';
		cierre.style.display = 'none';
	}

	function posicionaCatalogo (id, valor) {
		var c = document.getElementById (id);
		iw = window.innerWidth;
		if (IE) {
			iw = (document.documentElement).clientWidth;
			valor = valor + (valor*0.7);
		}
		var margenh = (iw - 900)/2;
		c.style.marginLeft = (posicionx - margenh - valor) + 'px';
	}

	function eliminarEstrellas () {
		for (i = 0; i < 5; i++) {
			document.getElementById ('star' + (i+1)).src = 'imagenes/estrella-off.png';
		}
	}

	function seleccionaSexo (tipo, origen) {
		if (tipo == 0) {
			if (origen == 0)
				document.getElementById ('imageshow').src = 'imagenes/1-default.gif';
			document.getElementById ('Image1' ).src = "imagenes/man-sel.gif";
			document.getElementById ('Image2' ).src = "imagenes/woman-off.gif";
		} else if (tipo == 1) {
			if (origen == 0)
				document.getElementById ('imageshow').src = 'imagenes/0-default.gif';
			document.getElementById ('Image2' ).src = "imagenes/woman-sel.gif";
			document.getElementById ('Image1' ).src = "imagenes/man-off.gif";		
		}
		document.getElementById ('sexo').value = tipo;	
	}

	function buscarRelaciones () {
		var mes = document.getElementById ('mes').value;
		var ano = document.getElementById ('ano').value;
		var pareja = document.getElementById ('parejasel').value;
		var satisfaccion = document.getElementById ('satisfaccion').value;
		var http = new Array ();
		var resultado = new Array ();
		var curDateTime = new Date ();
		http[curDateTime] = createRequestObject ();
		http[curDateTime].open ('post', 'buscar.php');
		http[curDateTime].setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');
    	http[curDateTime].send ('mes=' + mes + '&ano=' + ano + '&pareja=' + pareja + '&satisfaccion=' + satisfaccion); 
		http[curDateTime].onreadystatechange = function () {
			if (http[curDateTime].readyState == 4) {
		    	if (http[curDateTime].status == 200 || http[curDateTime].status == 304) {			
		        	var response = http[curDateTime].responseText;
					var componentes = response.split ('<s>');
					for (var i = 0; i < (componentes.length-1); i++) {
						var registro = componentes[i].split ('|');
						registro[0] = registro[0].replace (/^\s*|\s*$/g,"");
						resultado[i] = registro; 
					}
					mostrarResultados (resultado);
		        }
		    }
		}			
	}

	function mostrarAyuda (id) {
		var cuadro = document.getElementById (id);
		if (cuadro.style.visibility == 'hidden') {
			cuadro.style.visibility = 'visible';
			cuadro.style.display = '';	
		} else {
			cuadro.style.visibility = 'hidden';
			cuadro.style.display = 'none';			
		}
	}

	function mostrarResultados (resultados) {
		var salida = '';
		if (resultados.length == 0)
			salida = salida + '<span class="resaltado">No has anotado ninguna experiencia con esas caracter&iacute;sticas</span><br><br>';			
		else salida = salida + '<span class="resaltadop">Experiencias encontradas:</span><br><br>';		
		for (var i = 0; i < resultados.length; i++) {
			salida = salida + '<table width=330 style="border: 1px solid #999999; background-image: url(\'imagenes/fondoexp.png\'); background-repeat: repeat-x;">';
			salida = salida + '<tr>';
			salida = salida + '<td width="58" rowspan="2"><div align="center"><a href="experiencia.php?id=' + resultados[i][0] + '"><img border="0" width="40" height="40" src="' + resultados[i][1] + '" /></a></div></td>';
			salida = salida + '<td width="242" height="25">';
			for (var j = 0; j < resultados[i][2]; j++)
				salida = salida + '<img src="imagenes/estrella.png" />';	
			salida = salida + '</td>';
			salida = salida + '</tr>';
			salida = salida + '<tr>';
			salida = salida + '<td height="21" class="resaltadop">con ' + resultados[i][5] + ', el ' + resultados[i][3] + '</td>';
			salida = salida + '</tr>';
			salida = salida + '<tr>';
			salida = salida + '<td colspan="2" class="experiencia" style="padding-left: 10px; padding-top: 10px; padding-bottom: 10px">' + recortarTexto (resultados[i][4], 100) + '</td>';
			salida = salida + '</tr>';
			salida = salida + '<tr>';
			salida = salida + '<td colspan="2" height="20"></td>';
			salida = salida + '</tr>';
			salida = salida + '</table><br>';     
		}  
		document.getElementById ('resultados').innerHTML = salida;
	}

	function recortarTexto (texto, numero) {
		if (texto.length < numero)
			return texto;
		else return texto.substr (0, numero) + ' ...';
	}

	function muestraCalificacion (obj) {
		var id = obj.id;
		eliminarEstrellas ();
		if (id == 'star1') {
			document.getElementById ('star1').src = 'imagenes/estrella.png';
			document.getElementById ('calificacion').value = 1;
		} else if (id == 'star2') {
			document.getElementById ('star1').src = 'imagenes/estrella.png';
			document.getElementById ('star2').src = 'imagenes/estrella.png';
			document.getElementById ('calificacion').value = 2;			
		} else if (id == 'star3') {
			document.getElementById ('star1').src = 'imagenes/estrella.png';
			document.getElementById ('star2').src = 'imagenes/estrella.png';
			document.getElementById ('star3').src = 'imagenes/estrella.png';
			document.getElementById ('calificacion').value = 3;			
		} else if (id == 'star4') {
			document.getElementById ('star1').src = 'imagenes/estrella.png';
			document.getElementById ('star2').src = 'imagenes/estrella.png';
			document.getElementById ('star3').src = 'imagenes/estrella.png';
			document.getElementById ('star4').src = 'imagenes/estrella.png';
			document.getElementById ('calificacion').value = 4;			
		} else if (id == 'star5') {
			document.getElementById ('star1').src = 'imagenes/estrella.png';
			document.getElementById ('star2').src = 'imagenes/estrella.png';
			document.getElementById ('star3').src = 'imagenes/estrella.png';
			document.getElementById ('star4').src = 'imagenes/estrella.png';
			document.getElementById ('star5').src = 'imagenes/estrella.png';
			document.getElementById ('calificacion').value = 5;			
		}
	}

	function selecciona (tipo, dia) {
		var dia = document.getElementById ('d' + dia);
		var atr = "class";
		if (IE)
			atr = "className";
		if (IE8)
			atr = "class";
		if (tipo == 1) {
			if (dia.getAttribute (atr) == 'dia-sin') {
				dia.setAttribute (atr, "dia-sin-sel"); 
			} else if (dia.getAttribute (atr) == 'dia-con') {
				dia.setAttribute (atr, "dia-con-sel"); 			
			} else if (dia.getAttribute (atr) == 'dia-pre') {
				dia.setAttribute (atr, "dia-pre-sel"); 			
			} else if (dia.getAttribute (atr) == 'dia-men') {
				dia.setAttribute (atr, "dia-men-sel"); 			
			}
		} else {
			if (dia.getAttribute (atr) == 'dia-sin-sel') {
				dia.setAttribute (atr, "dia-sin"); 
			} else if (dia.getAttribute (atr) == 'dia-con-sel') {
				dia.setAttribute (atr, "dia-con"); 			
			} else if (dia.getAttribute (atr) == 'dia-pre-sel') {
				dia.setAttribute (atr, "dia-pre"); 			
			} else if (dia.getAttribute (atr) == 'dia-men-sel') {
				dia.setAttribute (atr, "dia-men"); 			
			}
		}
	}

	function seleccionaImagen (tipo, imagen) {
		if (tipo == 1) {
			imagen.style.border = '1px solid #999999';
		} else {
			imagen.style.border = '';
		}
	}

	function seleccionaImagenPareja (tipo, imagen, id) {
		seleccionaImagen (tipo, imagen);
	}

	function formateaNumero (numero) {
		if (numero >= 10)
			return numero;
		else return '0' + numero;
	}

	function detalleDia (dia) {
		var fecha = formateaNumero (dia) + '/' + formateaNumero (cal.month+1) + '/' + cal.year;	
		document.getElementById ('diasel').value = dia;
		document.getElementById ('fechasel').value = fecha;
		var cdia = document.getElementById ('d' + dia);
		if (IE && !IE8) {
			if ((cdia.getAttribute ("className") == 'dia-sin-sel') || (cdia.getAttribute ("className") == 'dia-men-sel'))
				mostrarPopup (0, cdia, dia); 
			else mostrarPopup (1, cdia, dia);
		} else {
			if ((cdia.getAttribute ("class") == 'dia-sin-sel') || (cdia.getAttribute ("class") == 'dia-men-sel'))
				mostrarPopup (0, cdia, dia);
			else mostrarPopup (1, cdia, dia);
		}
	}
