var peticion = false;
	
	try {
	   peticion = new XMLHttpRequest();
	} catch (trymicrosoft) {
	   try {
			 peticion = new ActiveXObject("Msxml2.XMLHTTP");
	   } catch (othermicrosoft) {
			try {
				peticion = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (failed) {
				peticion = false;
			}
	   }
	}
	
	if (!peticion)
	   alert("ERROR AL INICIALIZAR!");
	
	function cargarSelect(fragment_url, element_id)
	{
	   var element = document.getElementById(element_id);

           if (element_id != 'caja_elementos_busqueda')
 	      element.innerHTML = '';	       

	   peticion.open("GET", fragment_url);
	   peticion.onreadystatechange = function() {                           

					if ( peticion.readyState==4 ) {

  					    document.getElementById('cargando').innerHTML = "";	

                                            if (fragment_url.indexOf("listadoCallesPorCentro") != -1 || fragment_url.indexOf("listadoCentrosPorCalle") != -1)
                                               {  
                                                 document.getElementById('cargando_buscar_localidad').innerHTML = "<a><div id='buscar_localidad' class='buscar_localidad' onclick='javascript:cargarBotonBuscarLocalidad();'/></div></a></div>";	  					    
                                                 document.location.href='#zona_resultado';
                                               } 
	
     				        element.innerHTML = peticion.responseText;
					}                   

	   }
	   peticion.send(null);

	}	
	
	function limpiaSelect(id)
	{

		document.getElementById(id).selectedIndex=0;
	
	}
	
	function muestraEnProceso(mensaje, x, y)
	{
		document.getElementById('cargando').innerHTML = "<div class='img_cargando_sup'></div>";
		document.getElementById('caja_elementos_busqueda').innerHTML = "";
	}

	function compruebaSelect ()
	{
        	var resul = true;        
        
	    	var primer_select_no_seleccionado = (document.getElementById('select_tipo_centro').selectedIndex) == 0;
	    	var segundo_select_no_seleccionado = (document.getElementById('select_tipo_via_publica').selectedIndex) == 0;
	    
	    	var ningun_select_seleccionado = primer_select_no_seleccionado && segundo_select_no_seleccionado;
	    
        	if (ningun_select_seleccionado)	    
			resul = false;
			
		return resul;
	}
    
	function eliminaBuscar()
	{
                document.getElementById('cargando_buscar_localidad').innerHTML = "<div id='buscar_localidad' class='img_cargando_inf'></div>";       
	}

	function valoresNulos(usuario, codigo)
	{
	   if (usuario == '' || codigo == '')
		  return true;
	   else
		  return false;
	}
  	
function valorNoNumerico(codigo)
{

	if(isNaN(codigo))
	{
            alert("El valor del código debe ser numérico");
	    return true;
	}
	else
	{
	    return false;
	}
} 

	function validar(dato) {
   
   
   

		document.forms.autobaremo.campo4_total.value=document.forms.autobaremo.P.options[document.forms.autobaremo.P.selectedIndex].value;

		document.forms.autobaremo.campo1_total.value=document.forms.autobaremo.campo1.value * 13 ;


		document.forms.autobaremo.campo5_total.value=document.forms.autobaremo.campo5.value ;

		if (document.forms.autobaremo.campo6.value.indexOf(',', 0) > -1 )
		{
			alert("Atención si tiene valores decimales en la renta anual de la unidad familiar, el signo decimal es el punto y no la coma");
			document.forms.autobaremo.campo6.focus(); 
		}
		else
		{

			smi=parseFloat(7236.60);
			smi1=parseFloat(smi / 4);
			smi2=parseFloat(smi / 3);
			smi3=parseFloat(smi / 2);
			smi4=parseFloat(smi /1.5);

			RPC = parseFloat(document.forms.autobaremo.campo6.value / document.forms.autobaremo.campo5_total.value);

			document.forms.autobaremo.RPC.value = RPC;


			if (RPC < smi1 )
			{
				document.forms.autobaremo.campo6_total.value= 2;
			}
			else if ( RPC  < smi2 )
			{
				document.forms.autobaremo.campo6_total.value= 1.5;
			}
			else if ( RPC < smi3 )
			{
				document.forms.autobaremo.campo6_total.value= 1;
			}
			else if ( RPC  < smi4 )
			{
				document.forms.autobaremo.campo6_total.value= 0.5 ;			
			}
			else
			{
				document.forms.autobaremo.campo6_total.value= 0 ;
			
			}
		}


		for (var i=0;i<document.forms.autobaremo.group2.length;i++)
		{ 
		if (document.forms.autobaremo.group2[i].checked)
			  document.forms.autobaremo.campo7_total.value=document.forms.autobaremo.group2[i].value;		
		}


		for (var i=0;i<document.forms.autobaremo.group3.length;i++)
		{
		 if (document.forms.autobaremo.group3[i].checked)
			  document.forms.autobaremo.campo8_total.value=document.forms.autobaremo.group3[i].value;		
		}


		for (var i=0;i<document.forms.autobaremo.group4.length;i++)
		{ 
		if (document.forms.autobaremo.group4[i].checked)
			  document.forms.autobaremo.campo9_total.value=document.forms.autobaremo.group4[i].value;		
		}
		
		
		
		
		
		for (var i=0;i<document.forms.autobaremo.group5.length;i++)
		{
		if (document.forms.autobaremo.group5[i].checked)
			  document.forms.autobaremo.campo10_total.value=document.forms.autobaremo.group5[i].value;
		}
		
		for (var i=0;i<document.forms.autobaremo.group5.length;i++)
		{ if (document.forms.autobaremo.group1[i].checked)
			  document.forms.autobaremo.campo3_total.value=document.forms.autobaremo.group1[i].value;
		
		}


		total = parseFloat(0,00)
		total = parseFloat(total) + parseFloat(document.forms.autobaremo.campo4_total.value);
		total = parseFloat(total) + parseFloat(document.forms.autobaremo.campo1_total.value);
 
		total = parseFloat(total) + parseFloat(document.forms.autobaremo.campo6_total.value);
		total = parseFloat(total) + parseFloat(document.forms.autobaremo.campo7_total.value);
		total = parseFloat(total) + parseFloat(document.forms.autobaremo.campo8_total.value);
		total = parseFloat(total) + parseFloat(document.forms.autobaremo.campo9_total.value);
		total = parseFloat(total) + parseFloat(document.forms.autobaremo.campo10_total.value)
		total = parseFloat(total) + parseFloat(document.forms.autobaremo.campo3_total.value)

		document.forms.autobaremo.campo11_total.value = total
}

	function valprint(dato) {
	
		validar();
		window.print();
	
}

