function validarFichaVenta() {

	var ok=0;

	var ff=window.document.FVentaCompra;
	
	event.returnValue=false;

	validacion = /[^a-z-.@0-9A-Z]/g;
	validacionTelefono = /[^+ 0-9]/g;
	validacionNumerica = /[^0-9]/g;

	if (ff.Nombre.value.length < 3 ){
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Nombre'.\n\n");
	} else {
		if(ff.Nombre.value.length > 128){
			ok=1;
			alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Nombre'.\n\n");
		}
	}


	if (ff.Direccion.value.length < 3 ){
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Dirección'.\n\n");
	} else {
		if(ff.Direccion.value.length > 128){
			ok=1;
			alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Dirección'.\n\n");
		}
	}

	if (ff.Codigo_Postal.value.length != 5 ){
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Código Postal'.\n\n");
	} else {
		if (validacionNumerica.test(ff.Codigo_Postal.value)) {
			ok=1;
			alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Código Postal'.\n\n");
		}
	}

	if (ff.Poblacion.value.length < 3 ){
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Población'.\n\n");
	} else {
		if(ff.Poblacion.value.length > 128){
			ok=1;
			alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Población'.\n\n");
		}
	}

	if (ff.Provincia.value.length < 3 ){
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Provincia'.\n\n");
	} else {
		if(ff.Provincia.value.length > 128){
			ok=1;
			alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Provincia'.\n\n");
		}
	}

	if (validacionTelefono.test(ff.Telefono.value) || (ff.Telefono.value.length<6)) {
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Teléfono'.\nLos únicos caracteres válidos para este campo son '+', ' ' y números del 0 al 9\n\n");
	}


	if (ff.Fax.value.length>0){
		if (validacionTelefono.test(ff.Fax.value) || (ff.Fax.value.length<6)) {
			ok=1;
			alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Fax'.\nLos únicos caracteres válidos para este campo son '+', ' ' y números del 0 al 9\n\n");
		}
	}

	if (checkEmail(ff.eMail.value)) {
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'eMail'.\nEl formato válido es usuario@dominio.tld\n\n");
	}

	if (ff.Tipo_de_Inmueble.options[ff.Tipo_de_Inmueble.selectedIndex].text == "") {
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Tipo de Inmueble'.\n\n");
	}

	if (ff.Direccion_Inmueble.value.length < 3 ){
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Dirección'.\n\n");
	} else {
		if(ff.Direccion_Inmueble.value.length > 128){
			ok=1;
			alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Dirección'.\n\n");
		}
	}

	if (ff.Codigo_Postal_Inmueble.value.length != 5 ){
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Código Postal'.\n\n");
	} else {
		if (validacionNumerica.test(ff.Codigo_Postal_Inmueble.value)) {
			ok=1;
			alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Código Postal'.\n\n");
		}
	}


	if (ff.Zona.options[ff.Zona.selectedIndex].text == "") {
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Zona'.\n\n");
	}


	if (ff.Observaciones.value.length < 1 ){
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Observaciones'.\n\n");
	}


	if (ok==0) {
		ff.submit();
	} else {
		event.returnValue=false;	
	}
}




function validarFichaBusca() {

	var ok=0;

	var ff=window.document.FVentaCompra;
	
	event.returnValue=false;

	validacion = /[^a-z-.@0-9A-Z]/g;
	validacionTelefono = /[^+ 0-9]/g;
	validacionNumerica = /[^0-9]/g;

	if (ff.Nombre.value.length < 3 ){
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Nombre'.\n\n");
	} else {
		if(ff.Nombre.value.length > 128){
			ok=1;
			alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Nombre'.\n\n");
		}
	}


	if (ff.Direccion.value.length < 3 ){
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Dirección'.\n\n");
	} else {
		if(ff.Direccion.value.length > 128){
			ok=1;
			alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Dirección'.\n\n");
		}
	}

	if (ff.Codigo_Postal.value.length != 5 ){
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Código Postal'.\n\n");
	} else {
		if (validacionNumerica.test(ff.Codigo_Postal.value)) {
			ok=1;
			alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Código Postal'.\n\n");
		}
	}

	if (ff.Poblacion.value.length < 3 ){
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Población'.\n\n");
	} else {
		if(ff.Poblacion.value.length > 128){
			ok=1;
			alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Población'.\n\n");
		}
	}

	if (ff.Provincia.value.length < 3 ){
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Provincia'.\n\n");
	} else {
		if(ff.Provincia.value.length > 128){
			ok=1;
			alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Provincia'.\n\n");
		}
	}

	if (validacionTelefono.test(ff.Telefono.value) || (ff.Telefono.value.length<6)) {
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Teléfono'.\nLos únicos caracteres válidos para este campo son '+', ' ' y números del 0 al 9\n\n");
	}


	if (ff.Fax.value.length>0){
		if (validacionTelefono.test(ff.Fax.value) || (ff.Fax.value.length<6)) {
			ok=1;
			alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Fax'.\nLos únicos caracteres válidos para este campo son '+', ' ' y números del 0 al 9\n\n");
		}
	}

	if (checkEmail(ff.eMail.value)) {
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'eMail'.\nEl formato válido es usuario@dominio.tld\n\n");
	}

	if (ff.Tipo_de_Inmueble.options[ff.Tipo_de_Inmueble.selectedIndex].text == "") {
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Tipo de Inmueble'.\n\n");
	}

	if ((ff.Tipo_de_Inmueble.options[ff.Tipo_de_Inmueble.selectedIndex].text != "Garaje") && (ff.Tipo_de_Inmueble.options[ff.Tipo_de_Inmueble.selectedIndex].text != "Trastero")) {


		if ((ff.Tipo_de_Inmueble.options[ff.Tipo_de_Inmueble.selectedIndex].text != "Bajo") && (ff.Tipo_de_Inmueble.options[ff.Tipo_de_Inmueble.selectedIndex].text != "Local Comercial") && (ff.Tipo_de_Inmueble.options[ff.Tipo_de_Inmueble.selectedIndex].text != "Oficina")) {
			if (ff.nHabitaciones.options[ff.nHabitaciones.selectedIndex].text == ""){
				ok=1;
				alert("Se ha detectado un error en la validación del formulario de datos :\nRellene correctamente el campo 'Nº de Habitaciones'.\n");
			}
		}

		if (ff.Superficie_Minima.options[ff.Superficie_Minima.selectedIndex].text == ""){
			ok=1;
			alert("Se ha detectado un error en la validación del formulario de datos :\nRellene correctamente el campo 'Superficie Mínima'.\n");
		}

	}

	if (ff.Precio_Maximo.options[ff.Precio_Maximo.selectedIndex].text == "") {
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Precio Máximo'.\n\n");
	}

	if (ff.Zona_Preferida.options[ff.Zona_Preferida.selectedIndex].text == "") {
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Zona Preferida'.\n\n");
	}

	if (ff.Observaciones.value.length < 1 ){
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Observaciones'.\n\n");
	}


	if (ok==0) {
		ff.submit();
	} else {
		event.returnValue=false;	
	}
}

function paginadoListado(mipagina) {
	var ff=window.document.bava;
	ff.pagina.value=mipagina;
	ff.submit();
}


function calidades(n) {
	var zoom = window.open("calidades.html?obra="+n,"","width=600,height=600,left=0,top=0,status=no,resizable=yes,scrollbars=yes"); 
}

function zoomFotos(n) {
	var zoom = window.open("zoom.html?Id="+n,"","width=50,height=50,left=0,top=0,status=no,resizable=yes,scrollbars=no"); 
}

function on_zoom(n) {
	var zoom = window.open("zoom_2.html?Thumb="+n,"","width=50,height=50,left=0,top=0,status=no,resizable=yes,scrollbars=no"); 
}


function mostrarOferta(Id,Tabla) {
	window.location.href="oferta.html?tipo="+Tabla+"&id="+Id;
}

function paginadoListadoFiltro(mipagina) {
	var ff=window.document.bava;
	ff.pagina.value=mipagina;
	validarBusquedaAvanzada();
}

function validarBusquedaAvanzada() {

	var ok=0;
	var ff=window.document.bava;



	if ((ff.Modalidad.options[0].selected) && (ff.TipoVivienda.options[0].selected) && (ff.Estado.options[0].selected) && (ff.Zona.options[0].selected) && (ff.Precio.options[0].selected) && (ff.Superficie.options[0].selected) && (ff.nHabitaciones.options[0].selected) && (ff.nBanos.options[0].selected)) {
		ok=1;
		alert("Debe seleccionar alguna de las opciones de búsqueda para filtrar los resultados.\n\n");
	}

	if (ok==0){
		ff.submit();
	} else {
		event.returnValue=false;	
	}

}


function validarBusca() {

	var ok=0;
	var ff=window.document.FBusca;

	if ((ff.Zona.options[0].selected) && (ff.Precio.options[0].selected) && (ff.Superficie.options[0].selected)) {
		ok=1;
		alert("Debe seleccionar alguna de las opciones de búsqueda para filtrar los resultados.\n\n");
	}

	if (ok==0){
		ff.submit();
	} else {
		event.returnValue=false;	
	}

}

function validarContacto() {

	var ok=0;

	var ff=window.document.FContacto;

	validacion = /[^a-z-.@0-9A-Z]/g;
	validacionTelefono = /[^+ 0-9]/g;

	if (ff.Persona_de_Contacto.value.length < 3 ){
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Persona de Contacto'.\n\n");
	} else {
		if(ff.Persona_de_Contacto.value.length > 128){
			ok=1;
			alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Persona de Contacto'.\n\n");
		}
	}

	if (checkEmail(ff.eMail.value)) {
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'eMail'.\nEl formato válido es usuario@dominio.tld\n\n");
	}

	if (validacionTelefono.test(ff.Telefono.value) || (ff.Telefono.value.length<6)) {
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Teléfono'.\nLos únicos caracteres válidos para este campo son '+', ' ' y números del 0 al 9\n\n");
	}

	if (ff.Tipo_de_Soporte.options[0].selected) {
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Tipo de Soporte'.\n\n");
	}

	if (ff.mensaje.value.length < 1 ){
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Comentarios'.\n\n");
	}

	if (ok==0){
		if (confirm("Sea paciente mientras se procesa su solicitud.\n\n\El envío puede tardar unos segundos.\n\n")) {
			ff.submit();
		} else {
			event.returnValue=false;
		}
	} else {
		event.returnValue=false;	
	}
}


function checkEmail(emailStr) {
   if (emailStr.length == 0)
     return true;
   var emailPat=/^(.+)@(.+)$/;
   var specialChars="()<>@,;:\".[]";
   var validChars="[^s" + specialChars + "]";
   var quotedUser="(\"[^\"]*\")";
   var ipDomainPat=/^(d{1,3})[.](d{1,3})[.](d{1,3})[.](d{1,3})$/;
   var atom=validChars + '+';
   var word="(" + atom + "|" + quotedUser + ")";
   var userPat=new RegExp("^" + word + "(." + word + ")*$");
   var domainPat=new RegExp("^" + atom + "(." + atom + ")*$");
   var matchArray=emailStr.match(emailPat);

   if (matchArray == null)
      return false;

   var user=matchArray[1];
   var domain=matchArray[2];

   if (user.match(userPat) == null)
      return false;

   var IPArray = domain.match(ipDomainPat);
   if (IPArray != null) {
      for (var i = 1; i <= 4; i++) {
         if (IPArray[i] > 255)
         	return false;
   		}

   return true;
	 }

   var domainArray=domain.match(domainPat);
   if (domainArray == null)
      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)
      return false;

   if (len < 2)
      return false;

   return true;
}

function manda_mail() {
	window.location.href=String.fromCharCode(109,97,105,108,116,111,58,105,110,102,111,12521536/195649,105,110,116,101,114,112,105,115,111,118,101,110,46,99,111,109);
}

function Precarga() {
	MM_preloadImages('images/opc_men_garajes.gif','images/opc_men_garajesi.gif','images/opc_men_garajes-.gif','images/opc_men_garajes-i.gif','images/opc_men_locales.gif','images/opc_men_localesi.gif','images/opc_men_locales-.gif','images/opc_men_locales-i.gif','images/opc_men_inmuebles.gif','images/opc_men_inmueblesi.gif','images/opc_men_inmuebles-.gif','images/opc_men_inmuebles-i.gif','images/opc_men_trasteros.gif','images/opc_men_trasterosi.gif','images/opc_men_trasteros-.gif','images/opc_men_trasteros-i.gif');
}


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

 function MM_showHideLayers() { //v2.0
   var i, visStr, args, theObj;
   args = MM_showHideLayers.arguments;
   for (i=0; i<(args.length-2); i+=3) { //with arg triples (objNS,objIE,visStr)
     visStr   = args[i+2];
     if (navigator.appName == 'Netscape' && document.layers != null) {
       theObj = eval(args[i]);
       if (theObj) theObj.visibility = visStr;
     } else if (document.all != null) { //IE
       if (visStr == 'show') visStr = 'visible'; //convert vals
       if (visStr == 'hide') visStr = 'hidden';
       theObj = eval(args[i+1]);
       if (theObj){
		pageWidth=(ie)?document.body.offsetWidth:innerWidth;
		theObj.style.left=(pageWidth - 780)/2;
		theObj.style.visibility = visStr;
		}
  } }
}


function rMostrar_Ocultar(capa,imagen) {
	if(document.getElementById(capa).style.display == 'inline') {
		MM_swapImage('img_'+imagen,'','images/opc_men_'+imagen+'-.gif',1);
	} else {
		MM_swapImage('img_'+imagen,'','images/opc_men_'+imagen+'.gif',1);
	}
}


function iMostrar_Ocultar(capa,imagen) {
	if(document.getElementById(capa).style.display == 'inline') {
		MM_swapImage('img_'+imagen,'','images/opc_men_'+imagen+'-i.gif',1);
	} else {
		MM_swapImage('img_'+imagen,'','images/opc_men_'+imagen+'i.gif',1);
	}
}


function Mostrar_Ocultar(capa,imagen) {
	if(document.getElementById(capa).style.display == 'inline') {
		document.getElementById(capa).style.display = 'none';
		MM_swapImage('img_'+imagen,'','images/opc_men_'+imagen+'.gif',1);
	} else {
		document.getElementById(capa).style.display = 'inline';
		MM_swapImage('img_'+imagen,'','images/opc_men_'+imagen+'-.gif',1);
	}
}

/**
 * This array is used to remember mark status of rows in browse mode
 */
var marked_row = new Array;


/**
 * Sets/unsets the pointer and marker in browse mode
 *
 * @param   object    the table row
 * @param   interger  the row number
 * @param   string    the action calling this script (over, out or click)
 * @param   string    the default background color
 * @param   string    the color to use for mouseover
 * @param   string    the color to use for marking a row
 *
 * @return  boolean  whether pointer is set or not
 */

function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
    var theCells = null;

    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3

    // 3.3 ... Opera changes colors set via HTML to rgb(r,g,b) format so fix it
    if (currentColor.indexOf("rgb") >= 0) 
    {
        var rgbStr = currentColor.slice(currentColor.indexOf('(') + 1,
                                     currentColor.indexOf(')'));
        var rgbValues = rgbStr.split(",");
        currentColor = "#";
        var hexChars = "0123456789ABCDEF";
        for (var i = 0; i < 3; i++)
        {
            var v = rgbValues[i].valueOf();
            currentColor += hexChars.charAt(v/16) + hexChars.charAt(v%16);
        }
    }

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor              = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
             && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
        if (theAction == 'out') {
            newColor              = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor              = (thePointerColor != '')
                                  ? thePointerColor
                                  : theDefaultColor;
            marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
                                  ? true
                                  : null;
        }
    } // end 4

    // 5. Sets the new color...
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5

    return true;
} // end of the 'setPointer()' function