if (document.layers){document.captureEvents(Event.MOUSEMOVE);}
posX = 0;
posY = 0;
function guardaPos(e) 
{
	posX = e.layerX ;
	posY = e.layerY ;
	return true;
}
if (navigator.appName == "Netscape") document.onmousemove = guardaPos;
function ver (eldiv)
{
	ed = document.getElementById(eldiv);
	ed.style.display = '';
}
function borrar (eldiv)
{
	ed = document.getElementById(eldiv);
	ed.style.display = 'none';
}
function mover (eldiv)
{
	ed = document.getElementById(eldiv);
	if (navigator.appName != "Netscape")
	{
		ed.style.left = event.clientX + 10;
		ed.style.top = event.clientY + 10;
	}
	else
	{
		ed.style.left = posX + 10;
		ed.style.top = posY + 10;
	}
}

//verifica que un campo no este vacio
function nonulo(campo)
{
	if (campo.value=="")
	{
		alert("El campo " + campo.alt + " es obligatorio.");
		campo.focus();
		return false;
	}
	else
		return true;
}

//chequea que sea una direccion de correo electronico valida
function emailCheck (emailStr) 
{
	if(emailStr.value!="")
	{
		/* Verificar si el email tiene el formato user@dominio. */
		var emailPat=/^(.+)@(.+)$/ 

		/* Verificar la existencia de caracteres. ( ) < > @ , ; : \ " . [ ] */
		var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]" 

		/* Verifica los caracteres que son válidos en una dirección de email */
		var validChars="\[^\\s" + specialChars + "\]" 

		var quotedUser="(\"[^\"]*\")" 

		/* Verifica si la dirección de email está representada con una dirección IP Válida */ 


		var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/


		/* Verificar caracteres inválidos */ 

		var atom=validChars + '+'
		var word="(" + atom + "|" + quotedUser + ")"
		var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
		/*domain, as opposed to ipDomainPat, shown above. */
		var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")


		var matchArray=emailStr.value.match(emailPat)
		if (matchArray==null) {
			alert("La dirección de correo parece incorrecta (por ejemplo revise la @)\n\rEjemplo:informacion@interpropiedades.com");
			emailStr.select();
			emailStr.focus();
			return false;
		}
		var user=matchArray[1]
		var domain=matchArray[2]

		// Si el user "user" es valido 
		if (user.match(userPat)==null) {
			// Si no
			alert("nombre de usuario parece incorrecto.");
			emailStr.select();
			emailStr.focus();
			return false;
		}

		/* Si la dirección IP es válida */
		//var IPArray=domain.match(ipDomainPat)
		//if (IPArray!=null) {
			//for (var i=1;i<=4;i++) {
				//if (IPArray[i]>255) {
					//alert("Destination IP Is Not Valid.")
					//return false
				//}
			//}	
			//return true
		//}

	var domainArray=domain.match(domainPat)
		if (domainArray==null) {
			alert("El dominio no es válido.");
			emailStr.select();
			emailStr.focus();
			return false
		}

	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
		if (domArr[domArr.length-1].length<2 || 
			domArr[domArr.length-1].length>3) { 

			alert("La estensión debe ser de tres caracteres(.'com' .'net' etc.)");
			emailStr.select();
			emailStr.focus();
			return false
		}
	
		if (len<2) {
			var errStr="La dirección no es correcta.\n\rEjemplo:informacion@interpropiedades.com"
			alert(errStr);
			emailStr.select();
			emailStr.focus();
			return false
		}

		// La dirección de email ingresada es Válida
		return true;
	}
	else
	{
		var errStr="La dirección no puede estar vacia.";
		alert(errStr);
		return false;
	}
}

//comprueba que el valor de una type text sea numerico
function numero(arg)
	{
		if(isNaN(arg.value))
		{
			alert("Por favor introduzca valor numérico.");
			arg.value=arg.value.substring(0,arg.value.length-1);
		}else{
			if(arg.value.substring(arg.value.length-1,arg.value.length)==".")
			{
				arg.value=arg.value.substring(0,arg.value.length-1);
			}
			if(navigator.appName!="Microsoft Internet Explorer")
			{
				colorn='#FFFFFF';
				arg.style.background=colorn;
			}
		}
	}			

//con esta funcion actualiza los datos del usuario en ficha usuario
function actualizapropietario(id,tb)
	{
		var opciones = "toolbar=no,location=no,directories=no,scrollbars=no,resizable=no,width=300,height=100"; 
		var nombrev = document.getElementById('nombretxt').value;

		var apellidosv= document.getElementById('apellidostxt').value;
		var tfnov= document.getElementById('tfnotxt').value;
		var movilv= document.getElementById('moviltxt').value;
		var faxv= document.getElementById('faxtxt').value;
		
		if(tb=="promotora")
		{
		var callev= document.getElementById('calletxt').value;
		var portalv= document.getElementById('portaltxt').value;
		var cpv= document.getElementById('cptxt').value;
		}
		if((nombrev=="")||(apellidosv==""))
		{
			alert("Tiene campos obligatorios vacios, por favor rellene esos campos para continuar");
		}else{
			if(tb=="propietario"){	window.open("http://www.interpropiedades.com/popups/actualizapropietario.php?id=" + id + "&nombre=" + nombrev + "&apellidos=" + apellidosv + "&tfno=" + tfnov + "&movil=" + movilv + "&fax=" + faxv + "&tb=" + tb,"_blank",opciones); }
			if(tb=="promotora"){	window.open("http://www.interpropiedades.com/popups/actualizapropietario.php?id=" + id + "&nombre=" + nombrev + "&apellidos=" + apellidosv + "&tfno=" + tfnov + "&movil=" + movilv + "&fax=" + faxv +  "&calle=" + callev + "&portal=" + portalv + "&cp=" + cpv + "&tb=" + tb,"_blank",opciones); }
		}
	}

//abre ventana donde se actualiza un campo de la tabla propiedades
function actualizacampo(campo,elid,aux,tab)
	{
		var opciones = "toolbar=no,location=no,directories=no,scrollbars=no,resizable=no,width=300,height=100"; 
		var valor= document.getElementById(aux).value;
		eldir = "actualizacampo.php?id=" + elid + "&campo=" + campo + "&valor=" + valor + "&tb=" + tab;
		window.open("http://www.interpropiedades.com/popups/" + eldir,"_blank",opciones); 
	}

//abre una ventana para subir una foto a la tabla fotos.
function subefoto(elid,usuario)
	{
		var opciones = "toolbar=no,location=no,directories=no,scrollbars=no,resizable=no,width=300,height=150"; 

		window.open("http://www.interpropiedades.com/popups/subefoto.php?id=" + elid + "&usuario=" + usuario,"_blank",opciones); 
	}

//abre una ventana para subir las memorias de calidades.
function subememo(elid,usuario)
	{
		var opciones = "toolbar=no,location=no,directories=no,scrollbars=no,resizable=no,width=300,height=150"; 

		window.open("http://www.interpropiedades.com/popups/subememo.php?id=" + elid + "&usuario=" + usuario,"_blank",opciones); 
	}


//abre una ventana que borra una foto de la tabla fotos
function borrafoto(elid,usuario,idfoto)
	{
		var opciones = "toolbar=no,location=no,directories=no,scrollbars=no,resizable=no,width=300,height=150"; 

		window.open("http://www.interpropiedades.com/popups/borrafoto.php?id=" + elid + "&idfoto=" + idfoto +"&usuario=" + usuario,"_blank",opciones); 
	}

function desactiva(aux)
	{
		if(aux.value!="vivienda") 
		{	
			document.getElementById("viviendaid").disabled=true;
		}
		else
		{
			document.getElementById("viviendaid").disabled=false;
			document.getElementById("plantaid").disabled=false;
		}
		if (aux.value == "solar" || aux.value == "sepultura" )
		{
			document.getElementById("plantaid").value = 0;
			document.getElementById("plantaid").disabled=true;
		}
		else
		{
			document.getElementById("plantaid").disabled=false;
		}

	}