function enviarAmigoCerrar()
{	
	document.getElementById("divWrapEnviarAmigo").style.visibility = "hidden";
	document.getElementById("divWrapEnviarAmigo").style.display = "none";
	document.getElementById("divWrapEnviarAmigo").style.zIndex = "0";
	
	document.getElementById("div_enviar_amigo").style.visibility = "hidden";
	document.getElementById("div_enviar_amigo").style.display = "none";
	document.getElementById("div_enviar_amigo").style.zIndex = "0";
	
}


function enviarAmigoMostrar(KeyPropiedad)
{	
	document.getElementById("divWrapEnviarAmigo").style.visibility = "visible";
	document.getElementById("divWrapEnviarAmigo").style.display = "block";
	document.getElementById("divWrapEnviarAmigo").style.zIndex = "10";
	
	document.getElementById("div_enviar_amigo").style.visibility = "visible";
	document.getElementById("div_enviar_amigo").style.display = "block";
	document.getElementById("div_enviar_amigo").style.zIndex = "10";
	
	var forma = document.forms["enviaramigo"];
	forma.IDPROPIEDAD.value = KeyPropiedad;
	
}

function enviarAmigo()
{		
		var forma = document.forms["enviaramigo"];
		
		// ********************************
		// **** Remitente
		// ********************************
		
		if (forma.REMITENTE.value == "") {
			alert("Escriba su nombre");
			forma.REMITENTE.focus();
			return;
		}
		
		if (forma.EMAILREMITENTE.value == "") {
			alert("Escriba su direccion de correo electronico");
			forma.EMAILREMITENTE.focus();
			return;
		}
		else
		{
			if (!validarEmail(forma.EMAILREMITENTE.value,"Su direccion de email no es valida"))
			{
				forma.EMAILREMITENTE.focus();
				return;
			}
		}
		
		// ********************************
		// **** Destinatario
		// ********************************
		
		if (forma.DESTINATARIO.value == "") {
			alert("Escriba el nombre del destinatario");
			forma.DESTINATARIO.focus();
			return;
		}
		
		if (forma.EMAILDESTINATARIO.value == "") {
			alert("Escriba la direccion de correo electronico del destinatario");
			forma.EMAILDESTINATARIO.focus();
			return;
		}
		else
		{
			if (!validarEmail(forma.EMAILDESTINATARIO.value,
			       "La direccion de email del destinatario no es valida"))
			{
				forma.EMAILDESTINATARIO.focus();
				return;
			}
		}
		
		var url = "enviaramigo.php?DESTINATARIO=" + forma.DESTINATARIO.value + "&EMAILDESTINATARIO=" + forma.EMAILDESTINATARIO.value +
			      "&REMITENTE=" + forma.REMITENTE.value + "&EMAILREMITENTE=" + forma.EMAILREMITENTE.value + 
			      "&IDPROPIEDAD=" + forma.IDPROPIEDAD.value;
				      
		CExecuteUrlSync("GET",url);
		
		alert("Se ha enviado un correo con información de la propiedad para " + forma.DESTINATARIO.value);
		enviarAmigoCerrar();

}

