function condicionesParticulares() {
	var zoom = window.open("http://www.leonvivienda.com/condicionesPARTICULARES.php","","width=300,height=190,left=0,top=0,status=no,resizable=yes,scrollbars=no"); 
}

function resetearFormulario(ff) { //ok
	if (confirm("¿Está seguro que desea inicializar el formulario?")) {
		ff.reset();
	}
	event.returnValue=false;
}


function validarAcceso(ff) { // ok

	var ok=0;

	if (ff.NombreUsuario.value.length > 0 ){
		if (ff.NombreUsuario.value.length < 4 ){
			ok=1;
			alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Nombre de usuario'.\n\n");
		} else {
			if(ff.NombreUsuario.value.length > 15){
				ok=1;
				alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Nombre de usuario'.\n\n");
			}
		}
	}	

	if (ff.Contrasena.value.length > 0 ){
		if (ff.Contrasena.value.length < 4 ){
			ok=1;
			alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Contraseña'.\n\n");
		} else {
			if(ff.Contrasena.value.length > 15){
				ok=1;
				alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Contraseña'.\n\n");
			}
		}
	}

	if (ok==0){
		if (confirm("Espere mientras se procesa el formulario ...")) {
			ff.submit();
		} else {
			event.returnValue=false;
		}
	} else {
		event.returnValue=false;	
	}
}

function zoomFotos(n) {
	var zoom = window.open("vivienda_foto_zoom.php?idFoto="+n,"","width=50,height=50,left=0,top=0,status=no,resizable=yes,scrollbars=no"); 
}
function zoomFotos2(ruta) {
	var zoom = window.open("vivienda_foto_zoom2.php?idFoto="+ruta,"","width=50,height=50,left=0,top=0,status=no,resizable=yes,scrollbars=no"); 
}

function validarContactoWeb(ff) {
	var ok=0;
	event.returnValue=false;
	if (ff.nombre.value.length < 2 ){
			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 > 40){
				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.apellidos.value.length < 2 ){
			ok=1;
			alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Apellidos'.\n\n");
		} else {
			if(ff.apellidos.value.length > 40){
				ok=1;
				alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Apellidos'.\n\n");
			}
	}
	if (ff.localidad.value.length < 2 ){
			ok=1;
			alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Localidad'.\n\n");
		} else {
			if(ff.localidad.value.length > 30){
				ok=1;
				alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Localidad'.\n\n");
			}
	}
	if (ff.provincia.value.length < 2 ){
			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 > 20){
				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 (ff.telefono.value.length < 9 ){
			ok=1;
			alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Telefono'.\n\n");
		} else {
			if(ff.telefono.value.length > 9){
				ok=1;
				alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Telefono'.\n\n");
			}
	}
	if (ff.email.value.length > 0 ){
		if (!(esEmailValido(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'.\n\n");
		}
	}
	if (ok==0){
			ff.submit();
	} else {
		event.returnValue=false;	
	}
}
function esEmailValido(strMail) {
  var patMail = /^(.+)@(.+)$/;
  var patUser = /^[a-zA-Z\d_-]+(\.[a-zA-Z\d_-]+)*$/;
  var patDomain = /^[a-zA-Z\d_-]+(\.[a-zA-Z\d_-]+)+$/;
  var matchArray = strMail.match(patMail);
  if(matchArray == null)  {
   return false;
  }
  var user = new String(matchArray[1]);
  var domain = new String(matchArray[2]);
  if(user.match(patUser) == null) {
   return false;
  }
  var domainArray = domain.match(patDomain);
  if(domainArray == null) {
   return false;
  }
  if(domainArray[domainArray.length - 1].length < 3 || domainArray[domainArray.length - 1].length > 4) {
   return false;
  }
  return true;
}

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 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 MuestraOcultaMenu(capa,imagen) {
	if(document.getElementById(capa).style.display == 'inline') {
		document.getElementById(capa).style.display = 'none';
		MM_swapImage('imgmas_'+imagen,'','../Images/imgmas.gif',1);
	} else {
		document.getElementById(capa).style.display = 'inline';
		MM_swapImage('imgmas_'+imagen,'','../Images/imgmenos.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