function buscandoInmuebles(ff) {
	var ok=0;
	if (ff.M.options[ff.M.selectedIndex].value == ""){
		ok+=1;
	}
	if (ff.T.options[ff.T.selectedIndex].value == ""){
		ok+=1;
	}
	if (ff.PA.options[ff.PA.selectedIndex].value == ""){
		ok+=1;
	}
	if (ff.PV.options[ff.PV.selectedIndex].value == ""){
		ok+=1;
	}
	if (ff.Z.options[ff.Z.selectedIndex].value == ""){
		ok+=1;
	}
	if (ok<5){
			ff.submit();
	} else {
		msg="Rellene al menos un campo.\n\n";
		alert(msg);
		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 zoomFotosL(n) {
	var zoom = window.open("local_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 condicionesParticulares() {
	var zoom = window.open("condicionesPARTICULARES.php","","width=300,height=190,left=0,top=0,status=no,resizable=yes,scrollbars=no"); 
}
function condicionesEmpresas(idempresa) {
	var zoom = window.open("condicionesEMPRESAS.php?id="+escape(idempresa),"","width=300,height=190,left=0,top=0,status=no,resizable=yes,scrollbars=no"); 
}

function resetearFormulario(ff) {
	if (confirm("żEstá seguro que desea inicializar el formulario?")) {
		ff.reset();
	}
	event.returnValue=false;
}
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 validarContactoWebRed(ff) {
			ff.submit();
}
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 MM_swapImgRestore() {
  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() {
  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) {
  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() {
  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() {
   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 MM_displayStatusMsg(msgStr) {
  status=msgStr;
  document.MM_returnValue = true;
}
function MuestraOcultaMenu(capa,imagen) {
	if(document.getElementById(capa).style.display == 'inline') {
		document.getElementById(capa).style.display = 'none';
		MM_swapImage('imgmas_'+imagen,'','Images/flechamenu2.gif',1);
	} else {
		document.getElementById(capa).style.display = 'inline';
		MM_swapImage('imgmas_'+imagen,'','Images/flechamenu.gif',1);
	}
}
var marked_row = new Array;
function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor) {
    var theCells = null;
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }
	var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } 
    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);
        }
    }
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor              = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    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;
        }
    }
    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;
        }
    }
    if (newColor) {
        var c = null;
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            }
        }
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    }
    return true;
}

function Puntos_euros(campo, tecla)
{
	if ((tecla == 37) || (tecla == 39))
	{		
		return;
	}
	
	if ((tecla == 188) && (campo.value.indexOf(',') != -1) && (campo.value.substring(campo.value.indexOf(',') + 1, campo.value.length)))
	{		
		campo.value = campo.value.substring(0, campo.value.length - 1);		
		return;
	}
	else if (tecla == 188)
			{
				return;
			}
	if ((campo.value == '') && (tecla == 8))
	{
		return;
	}
	if (campo.value == '')
	{
		return;
	}
	numero = campo.value;
	var punto = numero.indexOf('.');
	while (punto != -1)
	{
		numero = numero.substring(0, punto) + numero.substring(punto + 1, numero.length);
		punto = numero.indexOf('.');
	}
	var coma = numero.indexOf(',');
	if (coma == 0)
	{
		return ('0' + numero);		
	}
	var num = "";
	var decimal = "";
				
		var coma = numero.indexOf(',');
		
		if (coma != -1)
		{		
			decimal = ',' + numero.substring(coma + 1, coma + 3);
			numero = numero.substring(0, coma);
		}
		else decimal = '';
		if (numero != '')
		{
	
			var str = "";
			while (numero > 999){
		
				n1 = Math.floor(numero/1000);
				n2 = numero - 1000 * n1;
				
				if (n2 < 10){
				   n2 = "00" + n2;
		        	}   
				else{
				   if (n2 < 100)
		       		      n2 = "0" + n2;
		                }
				str = "." + n2 + str;
				numero = n1;		
			}
			str = numero + str;		
		}
		campo.value = str + decimal;
}
function Puntos_euros2(numero) {
	numero = numero.replace('.', ',');	
	var coma = numero.indexOf(',');	
	if (coma == 0)
	{
		return ('0' + numero);		
	}
	var num = "";
	var decimal = "";	
		if (coma != -1)
		{		
			decimal = ',' + numero.substring(coma + 1, coma + 3);
			numero = numero.substring(0, coma);
		}
		else decimal = '';		
		if (numero != "")
		{
	
			var str = "";
			while (numero > 999){
		
				n1 = Math.floor(numero/1000);
				n2 = numero - 1000 * n1;
				
				if (n2 < 10){
				   n2 = "00" + n2;
		        	}   
				else{
				   if (n2 < 100)
		       		      n2 = "0" + n2;
		                }
				str = "." + n2 + str;
				numero = n1;		
			}
			str = numero + str;		
		}		
		return str + decimal;
}
function Delete_miles(numero_puntos)
{
	var entera = '';
	var decimal = '';
	coma = numero_puntos.indexOf(',');

	if (numero_puntos == '')
	{
		return '';
	}

	if (coma != -1)
	{
		entera = numero_puntos.substr(0, coma);
		decimal = numero_puntos.substr(coma + 1, numero_puntos.length);
	}
	else
		{
			entera = numero_puntos;
			decimal = '00';
		}
	var num_p;
	num_p = entera;
	longitud = 0;
	longitud = num_p.length;
	n = 0;
	var num_sp = "";
	while (n<longitud)
	{
     	var car = ' ';
      	var car = num_p.charAt(n);
      	if (car != '.')
		num_sp += num_p.charAt(n);
       	n++;
	}
	return (num_sp + '.' + decimal);
}
function Pts2Euros(numero)
{		
		while (numero.indexOf('.') != -1)
		{
			numero = numero.substring(0, numero.indexOf('.')) + numero.substring(numero.indexOf('.') + 1, numero.length);
		}
		n = parseFloat(numero) / 166.386;
		n = n * 1000;
		num = n.toString();
		num = num.substring(0, num.indexOf('.'));
		if (parseFloat(num.substring(num.length - 1, num.length)) >= 5)
		{
			n = parseFloat(n) + (10 - parseFloat(num.substring(num.length - 1, num.length)));
			num = n.toString();
			num = num.substring(0, num.indexOf('.'));
		}
		num = num.substring(0, num.length - 3) + ',' + num.substring(num.length - 3, num.length - 1);
		return Puntos_euros2(String(num));
}
function Euros2Pts(numero)
{	
	pesetas = parseInt(Delete_miles(numero) * 166.386);
	return Puntos_euros2(String(pesetas));
}
