var defaultEmptyOK = false;
var checkNiceness = true;
var digits = "0123456789";
var lowercaseLetters = "abcdefghijklmnopqrstuvwxyzáéíóúñü";
var uppercaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZÁÉÍÓÚÑ";
var whitespace = " \t\n\r";
var phoneChars = "()-+ ";
var mMessage = "Error: no puede dejar este espacio vacio"
var pPrompt = "Error: ";
var pAlphanumeric = "ingrese un texto que contenga solo letras y/o numeros";
var pAlphabetic   = "ingrese un texto que contenga solo letras";
var pInteger = "ingrese un numero entero";
var pNumber = "ingrese un numero";
var pPhoneNumber = "ingrese un número de teléfono";
var pEmail = "ingrese una dirección de correo electrónico válida";
var pName = "ingrese un texto que contenga solo letras, numeros o espacios";
var pNice = "no puede utilizar comillas aqui";
function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}
function isInteger (s)
{   var i;
    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isInteger.arguments[1] == true);
    
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if( i != 0 ) {
            if (!isDigit(c)) return false;
        } else { 
            if (!isDigit(c) && (c != "-") || (c == "+")) return false;
        }
    }
    return true;
}





function clickmapa(prov,cod) {
for (i=0; i<document.buscar.idloc.options.length; i++) 
  if (document.buscar.idloc.options[i].value==cod) break ;
document.buscar.idloc.selectedIndex = i ;
document.buscar.submit() ;
}



function mapad(n) {
   tipoinm = 0 ;
   tipo    = 0 ;

   for(i=0;i<3;i++) {
      if (document.demanda.elements[i].checked) {
         tipo = i + 1 ;
		 break ;
      }
   }

   for(i=3;i<11;i++) {
      if (document.demanda.elements[i].checked) {
         tipoinm = tipoinm | (1 << (i-3)) ;
      }
   }
   for(i=12;i<20;i++) {
      if (document.demanda.elements[i].checked) {
         tipoinm = tipoinm | (1 << (i-4)) ;
      }
   }
  
   if(n<1) {
	   alert("Elije Provincia");
	   return;
   }
   if(!tipo && !tipoinm){	
	   mensaje = "Elija entre Venta, Alquiler o Traspaso. (zona superior)\n\nY seleccione el tipo o tipos de propiedades. (opciones laterales)" ;
	   alert (mensaje) ;
	   return ;
   }
   if (!tipo) {
	   mensaje = "Elije entre Venta, Alquiler o Traspaso." ;
	   alert (mensaje) ;
	   return ;
   }

   if (!tipoinm) {
	   mensaje = "Seleccione el tipo o tipos de propiedades de las opciones laterales." ;
	   alert (mensaje) ;
	   return ;
   }
   if ((tipoinm!="1")&&(tipoinm!="2")&&(tipoinm!="4")&&(tipoinm!="8")&&(tipoinm!="16")&&(tipoinm!="32")&&(tipoinm!="64")&&(tipoinm!="128")&&(tipoinm!="256")&&(tipoinm!="512")&&(tipoinm!="1024")&&(tipoinm!="2048")&&(tipoinm!="4096")&&(tipoinm!="8192")&&(tipoinm!="16384")&&(tipoinm!="32768"))
   {
	   alert (" Sólo puede elegir un tipo de inmueble.");
	   return;
   }

   demanda.idinm.value  = tipoinm ;
   for (i=0; i<demanda.prov.options.length; i++) {
      if (demanda.prov.options[i].value==n) break ;
   }
   demanda.prov.selectedIndex = i ;
    
   demanda.submit() ; 
}

function clickmapa2(prov,cod){ //cambia la localidad del select cuando se pincha en el mapa
for (i=0; i<formu.idloc.options.length; i++) 
  if (formu.idloc.options[i].value==cod) break ;
formu.idloc.selectedIndex = i ;
}

function mapa(n) {
   tipoinm = 0 ;
   tipo    = 0 ;

   for(i=0;i<3;i++) {
      if (document.buscar.elements[i].checked) {
         tipo = i + 1 ;
		 break ;
      }
   }

   for(i=3;i<11;i++) {
      if (document.buscar.elements[i].checked) {
         tipoinm = tipoinm | (1 << (i-3)) ;
      }
   }
   for(i=12;i<20;i++) {
      if (document.buscar.elements[i].checked) {
         tipoinm = tipoinm | (1 << (i-4)) ;
      }
   }

	if(!tipo && !tipoinm){
		mensaje = "Elija entre Venta, Alquiler o Traspaso. (zona superior)\n\nY seleccione el tipo o tipos de propiedades. (opciones laterales)" ;
	   alert (mensaje) ;
	   return ;
	}
   else if (!tipo) {
	   mensaje = "Elije entre Venta, Alquiler o Traspaso.\n(zona superior)" ;
	   alert (mensaje) ;
	   return ;
   }
    if(n<1) {
	   alert("Elije Provincia");
	   return;
   }

   if (!tipoinm) {
	   mensaje = "Seleccione el tipo o tipos de propiedades de las opciones laterales." ;
	   alert (mensaje) ;
	   return ;
   }

   document.buscar.idinm.value  = tipoinm ;
   for (i=0; i<document.buscar.prov.options.length; i++) {
      if (document.buscar.prov.options[i].value==n) break ;
   }
   document.buscar.prov.selectedIndex = i ;
    
   document.buscar.submit() ; 
}


function mapa2(n,dest,check) {
   url     = dest + "mapa="+n ;
   tipoinm = 0 ;
   tipo    = 0 ;

   for(i=0;i<3;i++) {
      if (document.f.elements[i].checked) {
         tipo = i + 1 ;
		 break ;
      }
   }

   for(i=3;i<11;i++) {
      if (document.f.elements[i].checked) {
         tipoinm = tipoinm | (1 << (i-3)) ;
      }
   }
   for(i=12;i<20;i++) {
      if (document.f.elements[i].checked) {
         tipoinm = tipoinm | (1 << (i-4)) ;
      }
   }

   if (document.f)   {
      if (document.f.idloc) {
         tipol = f.idloc.options[f.idloc.selectedIndex].value;
	     url   +=  "&idloc=" + tipol ;
      }
 
/*      if (document.f.idloc2) {
	     url   +=  "&idloc2=" + document.f.idloc2.value ;
      }*/
   }

   if (check && !tipoinm) {
	   mensaje = "No podemos iniciar la búsqueda.\n\n" ;
	   mensaje += "Ha elegido buscar inmuebles en "
	   if (lastn==1) mensaje += "venta, " ;
	   if (lastn==2) mensaje += "alquiler, " ;
	   if (lastn==3) mensaje += "traspaso, " ;
	   mensaje += "pero no ha indicado el tipo.\nPor favor, seleccione en la lista de casillas de la izquierda, las que le interese." ;
	   alert (mensaje) ;
	   return ;
   }

   url += "&idinm=" + tipoinm ;
   url += "&tipo=" + tipo ;
   location = url ; 
}



