﻿/* INFORME DE VALORACION DE VIVIENDAS 
   (C) AXESOR, 2009.
   VERSION: 1.0.0
   
   REQUIERE: 
            - JQuery.js
            - /fincas/testDireccion.asp
            - Fincas.dll
*/

function TestDireccion()
{
    this.provincia = "";
    this.municipio = "";
    this.tipoVia = "";
    this.nombreVia = "";
    this.numeroVia = "";
    this.cp = "";
    this.bloque = "";
    this.escalera = "";
    this.puerta = "";
    this.planta = "";
    
    this.tipoFinca = "";
    this.refCatastral = "";
    
    this.comunicacionAsincrona = false;
    this.urlScript = "/fincas/testDireccion.asp";
    
    this.functionSuccess = function functionSuccess(resultado){return;}
    
    /*
       Comprueba si una direccion existe y se puede geolocalizar.
       
       RETORNO:
       -2 : Tipo de finca invalido.
       -1 : Error 500.
        0 : Operacion realizada con exito.
        1 : Imposible localizar la vivienda.
	    2 : La referencia catastral no existe o el usuo no es residencial.
	    3 : No se ha podido extraer la superficie de la información catastral.
	    4 : Error general al consultar el servicio catastral.
	    5 : La vivienda no se puede geolicalizar con la precisión mínima.
	    6 : Uso de la vivienda no permitido.
	    7 : NO HAY TESTIGOS EN LA VALORACION.
	    8 : VALORACION NO FIABLE.
    */
    this.runTest = function runTest()
    {
        //if(this.tipoFinca != 'C' && this.tipoFinca !='P')
        //   return -2;
        
        var resultado = 0;
        var int_functionSuccess = this.functionSuccess;
           
        jQuery.ajax({
						type: "post",
						url: this.urlScript,
						async : this.comunicacionAsincrona,
						dataType:"html",
						data:"provincia="+encodeURIComponent(encodeURI( this.provincia ))+"&municipio="+encodeURIComponent(encodeURI( this.municipio ))+"&direccion="+encodeURIComponent(encodeURI( this.tipoVia + " " + this.nombreVia ))+"&numero="+encodeURIComponent(encodeURI( this.numeroVia ))+"&cp="+encodeURIComponent(encodeURI( this.cp ))+"&tipofinca="+encodeURIComponent(encodeURI( this.tipoFinca ))+"&bloque="+encodeURIComponent(encodeURI( this.bloque ))+"&escalera="+encodeURIComponent(encodeURI( this.escalera ))+"&puerta="+encodeURIComponent(encodeURI( this.puerta ))+"&numeroplanta="+encodeURIComponent(encodeURI( this.planta ))+"&refCatastro="+encodeURIComponent(encodeURI(trim( this.refCatastral )))+"&cati=1",
						success:function(data)
						{							    						    								        							
							if( data.search("1")>=0 ) { resultado = 1; }
							if( data.search("2")>=0 ) { resultado = 2; }
							if( data.search("3")>=0 ) { resultado = 3; }
							if( data.search("4")>=0 ) { resultado = 4; }
							if( data.search("5")>=0 ) { resultado = 5; }
							if( data.search("6")>=0 ) { resultado = 6; }	
							if( data.search("7")>=0 ) { resultado = 7; }	
							if( data.search("8")>=0 ) { resultado = 8; }	
							int_functionSuccess(resultado);			
						},
						error:function (xhr, ajaxOptions, thrownError){ int_functionSuccess(-1); resultado = -1; }       
					});
	    return resultado;    
    }
}


