















String.prototype.trim = function() {
 // skip leading and trailing whitespace
 // and return everything in between
  var x=this;
    x=x.replace(/^\s*(.*)/, "$1");
    x=x.replace(/(.*?)\s*$/, "$1");
  return x;
}


function rolloverOn(imagen,cual)
{
	if(typeof cual == "undefined")
	{		
		eval("document.getElementById('"+imagen+"').src = '/webSite/img/"+imagen+"_on.gif'");
	}
	else
	{
		eval("document.getElementById('"+imagen+cual+"').src = '/webSite/img/"+imagen+"_on.gif'");
	}
}
function rolloverOff(imagen,cual)
{
	if(typeof cual == "undefined")
	{		
		eval("document.getElementById('"+imagen+"').src = '/webSite/img/"+imagen+".gif'");
	}
	else
	{
		eval("document.getElementById('"+imagen+cual+"').src = '/webSite/img/"+imagen+".gif'");
	}
}

function rolloverBoton(p){
              
                    var sheet = document.styleSheets[0];
                    
                    
                    var estilo;
                    var i = 0;
                    var nombre = '.'+p;
                    while (estilo==null){
                        if (!document.all){
                            if (sheet.cssRules[i].selectorText==nombre){
                                estilo=sheet.cssRules[i].style;
                            
                            }
                            else{
                                i++;
                            }
                        }
                        else{
                            if (sheet.rules[i].selectorText==nombre){
                                estilo=sheet.rules[i].style;
                            
                            }
                            else{
                                i++;
                            }
                        
                        }
                    }
                    if (estilo!=null){
                        
                   
                       var color= estilo.color;
                       var fondo = estilo.backgroundColor;
                       
                       estilo.color = fondo;
                       estilo.backgroundColor = color;
                       
                     
                       
                       document.getElementById(p).style.color = estilo.color;
                       document.getElementById(p).style.backgroundColor = estilo.backgroundColor;
                       
                    }
            }
function rolloverOnClass(cual,tamanyo)
{
	eval("document.getElementById('bullet"+cual+"').className = 'clase_bullet_"+tamanyo+"'")
}

function rolloverOffClass(cual,tamanyo)
{
	eval("document.getElementById('bullet"+cual+"').className = 'enlace_"+tamanyo+"'")
}

var winn;
function abrir(cual,wid,heig){	
	var LeftP = (screen.width) ? (screen.width-wid) / 2 : 0;
	var TopP = (screen.height) ? (screen.height-heig) / 2 : 0;
	if(screen.width == 800 || screen.height == 600) scrol = 'auto';
	if(winn){
		if(!winn.closed) winn.close();
		winn = null;
	}
	window.focus();
	winn=eval("open('/webSite"+cual+"','','dependent=yes,toolbar=no,location=no,Directory=no,Status=no,menubar=no,scrollbars=no,resizable=no,width="+wid+",height="+heig+",top="+TopP+",left="+LeftP+",scrollbars=yes')");
	winn.focus();
}
function abrirResice(cual,wid,heig){	
	var LeftP = (screen.width) ? (screen.width-wid) / 2 : 0;
	var TopP = (screen.height) ? (screen.height-heig) / 2 : 0;
	if(screen.width == 800 || screen.height == 600) scrol = 'auto';
	if(winn){
		if(!winn.closed) winn.close();
		winn = null;
	}
	window.focus();
	winn=eval("open('/webSite"+cual+"','','dependent=yes,toolbar=no,location=no,Directory=no,Status=no,menubar=no,scrollbars=no,resizable=yes,width="+wid+",height="+heig+",top="+TopP+",left="+LeftP+",scrollbars=yes')");
	winn.focus();
}
function verTodas(f) {
       f.action='/webSite/buscadorVerTodas.do';
       f.submit();
    }
    
function mapabarrios(f){
        migas(f);
	f.action='/webSite/buscadorPaso3Distrito.do';
	f.submit();
}

function mapadistritos(f){
        migas(f);    
	f.action='/webSite/buscadorPaso2Poblacion.do';
	f.submit();
}

function opciones(f){
        migas(f);    
	f.action='/webSite/buscadorVerTodas.do';
	f.submit();
}

function poblacionescomarca(f){
        migas(f);
	f.action='/webSite/buscadorPaso2Comarca.do';
	f.submit();
}

function provincia(f){
        migas(f);               
	f.action='/webSite/buscadorPaso1.do';
	f.submit();
}

function opciones(f){
        migas(f);
	vaciarCampos(f);
	f.action='/webSite/buscadorVerTodas.do';
	f.submit();
}

function migas(f){
if (f.pestanas){
    if (f.pestanas.value=='sm'){
        f.solosegundamano.value='';
        f.regimen.value='true';
        f.regimennombre.value='comprar.label';
        //f.tipobusqueda.value='1';
     } else  if (f.pestanas.value=='on'){
            f.solosegundamano.value='';
            f.regimen.value='true';
            f.regimennombre.value='comprar.label';
            f.tipobusqueda.value='2';
     }
     else  if (f.pestanas.value=='al'){
            f.solosegundamano.value='';
            f.regimen.value='false';
            f.regimennombre.value='alquilar.label';
            f.tipobusqueda.value='1';
     }
}

}

function vaciarCampos(f){
	f.tipoinmuebleid.value='';
	f.tipoinmueble.value='';
	f.preciomaximo.value='';
	f.mindormitorios.value='';
	f.tamaniominimo.value='';
	f.preciomaximonombre.value='';
	f.mindormitoriosnombre.value='';
	f.tamaniominimonombre.value='';

}

function irALogin(){
    window.location.replace('/webSite/inilogin.do');
}

function irAWebPrev(url) {
	if(url.indexOf("http://") < 0) {
		url = "http://" + url;
	}

	var webEncoded = encodeURIComponent(url);   
    window.open('/webSite/inmo/buscador/publicidad.jsp?urlpubli='+webEncoded);
}

function irAWeb(web){
    var webEncoded = encodeURIComponent(web);   
    window.open('/webSite/inmo/buscador/publicidad.jsp?urlpubli='+webEncoded);
}
function irAWebOrg(web, org){
    var webEncoded = encodeURIComponent(web);   
    window.open('/webSite/inmo/buscador/publicidad.jsp?origen='+org+'&urlpubli='+webEncoded);
}
function home(doc){
    doc.location=/webSite/;jsessionid=3BA7A576678265A06DBEB2B846CEEA3B.t1portae404;
}

function resultadosBuscador(f,numpag){
        migas(f);  
        if (f.numpagebackup && (f.numpagebackup.value*1)>=0)
            //f.numpage.value=f.numpagebackup.value;
            f.numpage.value=numpag;
	f.action='/webSite/busquedaResultados.do';
	f.submit();
}

function resultadosBuscadorTelefCero(f){
        migas(f);  
        if (f.numpagebackup && (f.numpagebackup.value*1)>=0)
            f.numpage.value=f.numpagebackup.value;
	f.action='/webSite/busquedaResultados.do';
	f.submit();
}

function volverAPromo(f){                      
        f.action='buscadorIrAFicha.do';	
	f.submit();
}




function bisiesto(anio) {
    return ((anio%4==0 && anio%100!=0) || (anio%400==0));
}


function numDiasMes(mes, anio) {
     
     dias = 31;
     switch (mes) {
         case 2: if (bisiesto(anio)) dias=29; else dias=28;break;
         case 4:
         case 6:
         case 9:
         case 11: dias = 30; break;
     }
     return dias;
 }

function validarFecha(dia,mes,anio){

	diasmes=numDiasMes(mes,anio);
	
	if(dia<=diasmes){
		return true;
	}
	else{
		return false;
	}


}

function validarEmail(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;
 }

