function validar(nombre,valor,tipo){
	
	switch(tipo){	
	
		case "vacio":
			if ((valor=="")) {
				document.getElementById(nombre).style.color='red';
				document.getElementById('error_'+ nombre).style.visibility='visible';
				document.getElementById('error_'+ nombre).innerHTML='<span class="mensajeError">Este campo no puede estar vacio</span>'; 
				return false;
			}else{				
				
				document.getElementById(nombre).style.color='#000';
				document.getElementById('error_'+ nombre).style.visibility='hidden';
				document.getElementById('error_'+ nombre).innerHTML=''; 
				return true;
			}
			break;
		
		
		case "email":
		
			if (!esMail(valor)) {
				document.getElementById(nombre).style.color='red';
				document.getElementById('error_'+ nombre).style.visibility='visible';
				document.getElementById('error_'+ nombre).innerHTML='<span class="mensajeError">El email no es correcto</span>'; 
				return false;
			}else{
				document.getElementById(nombre).style.color='#000';
				document.getElementById('error_'+ nombre).style.visibility='hidden';
				document.getElementById('error_'+ nombre).innerHTML=''; 
				return true;
			}
			break;
		
		
		case "telefono":
		
			if (!esTelefono(valor)) {
				document.getElementById(nombre).style.color='red';
				document.getElementById('error_'+ nombre).style.visibility='visible';
				document.getElementById('error_'+ nombre).innerHTML='<span class="mensajeError">No es un teléfono</span>'; 
				return false;
			}else{
				document.getElementById(nombre).style.color='#000';
				document.getElementById('error_'+ nombre).style.visibility='hidden';
				document.getElementById('error_'+ nombre).innerHTML=''; 
				return true;
			}
			break;
			
			
		case "telefono+vacio":
			
			if (!esTelefono(valor) || valor.length<9 || valor=="" ) {
				document.getElementById(nombre).style.color='red';
				document.getElementById('error_'+ nombre).style.visibility='visible';
				document.getElementById('error_'+ nombre).innerHTML='<span class="mensajeError">No es un teléfono o esta vacio</span>'; 
				return false;
			}else{
				document.getElementById(nombre).style.color='#000';
				document.getElementById('error_'+ nombre).style.visibility='hidden';
				document.getElementById('error_'+ nombre).innerHTML=''; 
				return true;
			}
			break;

			
		case "numero":
		
			if (!esNumero(valor)) {
				document.getElementById(nombre).style.color='red';
				document.getElementById('error_'+ nombre).style.visibility='visible';
				document.getElementById('error_'+ nombre).innerHTML='<span class="mensajeError">No es un valor númerico</span>'; 
				return false;
			}else{
				document.getElementById(nombre).style.color='#000';
				document.getElementById('error_'+ nombre).style.visibility='hidden';
				document.getElementById('error_'+ nombre).innerHTML=''; 
				return true;
			}
			break;
			
			
		case "nif":
		
			if (!nif(valor) && !cif(valor)) {
				document.getElementById(nombre).style.color='red';
				document.getElementById('error_'+ nombre).style.visibility='visible';
				document.getElementById('error_'+ nombre).innerHTML='<span class="mensajeError">No es un CIF/NIF valido</span>'; 
				return false;
			}else{
				document.getElementById(nombre).style.color='#000';
				document.getElementById('error_'+ nombre).style.visibility='hidden';
				document.getElementById('error_'+ nombre).innerHTML=''; 
				return true;
			}
			break;
			
			
		case "codigo":
		
			var objXml;
			if(window.XMLHttpRequest && !(window.ActiveXObject)){try{ objXml = new XMLHttpRequest(); } catch(e) { objXml = false; }
			} else if(window.ActiveXObject){try { objXml = new ActiveXObject("Msxml2.XMLHTTP");	} catch(e) { try { objXml = new ActiveXObject("Microsoft.XMLHTTP");	} catch(e) { objXml = false; }}}							
			
			objXml.open("GET", "contratar_codigo.asp", true);  
			objXml.onreadystatechange=function() {
				if (objXml.readyState==4) {	
				  	valorSession = objXml.responseText;
					if (valorSession!=valor) {
						document.getElementById(nombre).style.color='red';
						document.getElementById('error_'+ nombre).style.visibility='visible';
						document.getElementById('error_'+ nombre).innerHTML='<span class="mensajeError">Introduzca en c&oacute;digo de la imagen</span>'; 
						return false;
					}else{
						document.getElementById(nombre).style.color='#000';
						document.getElementById('error_'+ nombre).style.visibility='hidden';
						document.getElementById('error_'+ nombre).innerHTML=''; 
						return true;
					}
				}						
			}
			objXml.send(null);
	}
	
	
}






function validar_formulario(nombre){
	error = 'no'
	act = 'no'
	var msg;	
	if (!validar('contacto_facturacion',document.getElementById('contacto_facturacion').value,'vacio')){error='si';msg = 'Los campos con * son obligatorios para poder efectuar el alta.';};
	if (!validar('nombrecomercial_facturacion',document.getElementById('nombrecomercial_facturacion').value,'vacio')){error='si';msg = 'Los campos con * son obligatorios para poder efectuar el alta.';};
	if (!validar('razonsocial_facturacion',document.getElementById('razonsocial_facturacion').value,'vacio')){error='si';msg = 'Los campos con * son obligatorios para poder efectuar el alta.';};
	if (!validar('cif_facturacion',document.getElementById('cif_facturacion').value,'vacio')){error='si';msg = 'Los campos con * son obligatorios para poder efectuar el alta.';};
	if (!validar('provincia_facturacion',document.getElementById('provincia_facturacion').value,'vacio')){error='si';msg = 'Los campos con * son obligatorios para poder efectuar el alta.';};
	//if (!validar('poblacion_facturacion',document.getElementById('poblacion_facturacion').value,'vacio')){error='si';msg = 'Los campos con * son obligatorios para poder efectuar el alta.';};
	if (!validar('direccion_facturacion',document.getElementById('direccion_facturacion').value,'vacio')){error='si';msg = 'Los campos con * son obligatorios para poder efectuar el alta.';};
	if (!validar('codpostal_facturacion',document.getElementById('codpostal_facturacion').value,'vacio')){error='si';msg = 'Los campos con * son obligatorios para poder efectuar el alta.';};
	if (!validar('email',document.getElementById('email').value,'vacio')){error='si';msg = 'Los campos con * son obligatorios para poder efectuar el alta.';};
	
	if (!validar('telefono',document.getElementById('telefono').value,'vacio') && !validar('movil',document.getElementById('movil').value,'vacio')){
		error='si';msg = 'Debe indicar un telefono o un movil.';
	}
	
	if (!validar('nombrecomercial',document.getElementById('nombrecomercial').value,'vacio')){error='si';msg = 'Los campos con * son obligatorios para poder efectuar el alta.';};
	if (!validar('razonsocial',document.getElementById('razonsocial').value,'vacio')){error='si';msg = 'Los campos con * son obligatorios para poder efectuar el alta.';};
	if (!validar('cif',document.getElementById('cif').value,'nif')){error='si';msg = 'Los campos con * son obligatorios para poder efectuar el alta.';};
	if (!validar('pais',document.getElementById('pais').value,'vacio')){error='si';msg = 'Los campos con * son obligatorios para poder efectuar el alta.';};
	if (!validar('provincia',document.getElementById('provincia').value,'vacio')){error='si';msg = 'Los campos con * son obligatorios para poder efectuar el alta.';};
	//if (!validar('poblacion',document.getElementById('poblacion').value,'vacio')){error='si';msg = 'Los campos con * son obligatorios para poder efectuar el alta.';};
	if (!validar('direccion',document.getElementById('direccion').value,'vacio')){error='si';msg = 'Los campos con * son obligatorios para poder efectuar el alta.';};
	if (!validar('codpostal',document.getElementById('codpostal').value,'numero')){error='si';msg = 'Los campos con * son obligatorios para poder efectuar el alta.';};
	if (!validar('actividad',document.getElementById('actividad_final').value,'vacio')){error='si';msg = 'Debe seleccionar una actividad del desplegable que aparece al escribir en dicho campo.'};	
	//if (!validar('captchacode',document.getElementById('captchacode').value,'codigo')){error='si'};
	
	if (document.getElementById('acepto').checked == false){
		error='si';		
		msg = msg + '. Debe aceptar las condiciones de contratación';
	}
	
	if(error == 'no'){
		document.getElementById(nombre).submit();
	}else{
		alert(msg)		
	}
}



//  ----------------------------------------------------------------------------------
//  function cif(texto)
//  ----------------------------------------------------------------------------------
function cif(texto)
{
	var pares = 0;
	var impares = 0;
	var suma;
	var ultima;
	var unumero;
	var uletra = new Array("J", "A", "B", "C", "D", "E", "F", "G", "H", "I");
	var xxx;
	texto = texto.toUpperCase();
	var regular = new RegExp(/^[ABCDEFGHKLMNPQS]\d\d\d\d\d\d\d[0-9,A-J]$/g);
	if (!regular.exec(texto)) return false;
	
	ultima = texto.substr(8,1);
	
	for (var cont = 1 ; cont < 7 ; cont ++)
	{
	xxx = (2 * parseInt(texto.substr(cont++,1))).toString() + "0";
	impares += parseInt(xxx.substr(0,1)) + parseInt(xxx.substr(1,1));
	pares += parseInt(texto.substr(cont,1));
	}
	
	xxx = (2 * parseInt(texto.substr(cont,1))).toString() + "0";
	impares += parseInt(xxx.substr(0,1)) + parseInt(xxx.substr(1,1));
	
	suma = (pares + impares).toString();
	unumero = parseInt(suma.substr(suma.length - 1, 1));
	unumero = (10 - unumero).toString();
	
	if(unumero == 10) unumero = 0;
	
	if ((ultima == unumero) || (ultima == uletra[unumero]))
	return true;
	else
	return false;

}



//  ----------------------------------------------------------------------------------
//  function nif(abc)
//  ----------------------------------------------------------------------------------


function nif(abc){
	dni=abc.substring(0,abc.length-1)
	let=abc.charAt(abc.length-1)
	if (!isNaN(let)){
	  return false
	 }else{
	  cadena="TRWAGMYFPDXBNJZSQVHLCKET"
	  posicion = dni % 23
	  letra = cadena.substring(posicion,posicion+1)
	  if (letra!=let.toUpperCase()){
	    return false
	   }
	 }
	return true
}









//  ----------------------------------------------------------------------------------
//  function esMail(str)
//  	devuelve TRUE si la la cadena que se le pasa como parámetro es una dirección de mail
//  ----------------------------------------------------------------------------------
function esMail(str) {

  	return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}



//  ----------------------------------------------------------------------------------
//   function esNumero(cad)
//  	devuelve TRUE si la cadena que se le pasa como parámetro es un número
//  ----------------------------------------------------------------------------------	
function esNumero(cad) {
	var ok=true;
	if (cad.length>0) {
		for (i=1;i<=cad.length;i++)
			if (((cad.substring(i-1,i)>"9") || (cad.substring(i-1,i)<"0")) && (cad.substring(i-1,i)!=".")) {
				ok=false;
				break;
		}
	} else ok=false;
	if (ok) return true;
		else return false;
}	
	
//  ----------------------------------------------------------------------------------
//   function esTelefono(cad)
//  	devuelve TRUE si la cadena que se le pasa como parámetro es un número de teléfono
//  ----------------------------------------------------------------------------------		
function esTelefono(cad){
   var ValidChars = " 0123456789.-";
   var esTelefono=true;
   var Char;

   for (i = 0; i < cad.length && esTelefono == true; i++) { 
	  Char = cad.charAt(i); 
	  if (ValidChars.indexOf(Char) == -1)
		  esTelefono = false;
   }
   return esTelefono;
}

//  ----------------------------------------------------------------------------------
//  function DifFecha (fechIni,fechfin)
//  	devuelve TRUE si la diferencia entre dos fechas es mayor de 1 dia
//  ----------------------------------------------------------------------------------
function difFecha (fechIni,fechFin) {
   //Obtiene los datos del formulario
   CadenaFecha1 = fechIni;
   CadenaFecha2 = fechFin;
   
   //Obtiene dia, mes y año
   var fecha1 = new fecha( CadenaFecha1 );
   var fecha2 = new fecha( CadenaFecha2 );
      
   //Obtiene objetos Date
   var miFecha1 = new Date( fecha1.anio, fecha1.mes, fecha1.dia );
   var miFecha2 = new Date( fecha2.anio, fecha2.mes, fecha2.dia );
   
   //Resta fechas y redondea
   var diferencia = miFecha1.getTime() - miFecha2.getTime();
   if (diferencia>0) //Fecha Ini > Fecha Fin
	return true;
   else 	
	return false;
}

//  ----------------------------------------------------------------------------------
//  function DifDias (fechIni,fechfin)
//  	devuelve el numero de dias de la diferencia entre dos fechas 
//  ----------------------------------------------------------------------------------
function difDias (fechIni,fechFin) {
   //Obtiene los datos del formulario
   CadenaFecha1 = fechIni;
   CadenaFecha2 = fechFin;
   
   //Obtiene dia, mes y año
   var fecha1 = new fecha( CadenaFecha1 );
   var fecha2 = new fecha( CadenaFecha2 );
      
   //Obtiene objetos Date
   var miFecha1 = new Date( fecha1.anio, fecha1.mes, fecha1.dia );
   var miFecha2 = new Date( fecha2.anio, fecha2.mes, fecha2.dia );
   
   //Resta fechas y redondea
	var diferencia=(Math.round((Date.parse(miFecha2)-Date.parse(miFecha1))/(24*60*60*1000))*1) 

	return diferencia;
   
}






//  ----------------------------------------------------------------------------------
//  function fecha( cadena )
//  	devuelve dia, mes y año por separado de la cadena que se le pasa como parametro
//  ----------------------------------------------------------------------------------
function fecha( cadena ) {
   //Separador para la introduccion de las fechas
   var separador = "/";

   //Separa por dia, mes y año
   if ( cadena.indexOf( separador ) != -1 ) {
        var posi1 = 0;
        var posi2 = cadena.indexOf( separador, posi1 + 1 );
        var posi3 = cadena.indexOf( separador, posi2 + 1 );
        this.dia  = cadena.substring( posi1, posi2 );
        this.mes  = cadena.substring( posi2 + 1, posi3 );
        this.anio = cadena.substring( posi3 + 1, cadena.length );
   } else {
        this.dia  = 0;
        this.mes  = 0;
        this.anio = 0;   
   }
}

//  ----------------------------------------------------------------------------------
//   function esFecha(fech)
//  	devuelve TRUE si la fecha que se le pasa es válida o FALSE en caso contrario
//  ----------------------------------------------------------------------------------
function esFecha(fech) {
	i=0;
	z=0;
	dia="";

	separador1=fech.indexOf('/');
	resto=fech.substring(separador1+1,fech.length);		
	separador2=resto.indexOf('/');		
		
	if ((separador1<=0) || (separador2<=0))
		return false;
		
	while (fech.charAt(i) != '/') {
		dia=dia+fech.charAt(i);
		i=i+1;
	}
	
	mes="";
	i=i+1;
	
	while (fech.charAt(i) != '/') { 
		mes=mes+fech.charAt(i);
		i=i+1;
	}					
	
	anio="";
	i=i+1;
	
	while (fech.charAt(i) != ''){
		anio=anio+fech.charAt(i);
		i=i+1;
	} 
	
	var ok=true;
	var bisiesto=false;
	if (esNumero(dia) && esNumero(mes) && esNumero(anio)) {
		if(anio%4==0) bisiesto=true;
		if (mes>0 && mes<13) {
			if (dia>0 && dia<32) {
				if ((mes==4 || mes==6 || mes==9 || mes==11) && dia==31) ok=false
				if (mes==2) {
					if (bisiesto && dia>29) ok=false;
					if (!bisiesto && dia>28) ok=false;
				}
			} else ok=false;
		} else ok=false;
	} else ok=false;
	if (ok) {
		return true;
	}else return false;
}	


function existe(valor)
{
	if(window.XMLHttpRequest) {
			objXml2 = new XMLHttpRequest(); // Gecko (Firefox, Moz), KHTML (Konqueror, Safari), Opera
		} else if(window.ActiveXObject) {
			objXml2 = new ActiveXObject("Microsoft.XMLHTTP"); // Internet Explorer		
		}		
		objXml2.open("GET", "/usuarios/_empresas.asp?valor=" + valor  , true);  
		
		objXml2.onreadystatechange=function() {
			if (objXml2.readyState==4) {
				document.getElementById('posibles').innerHTML = objXml2.responseText;				
				document.getElementById('posibles').style.visibility='visible';
			}
		}
}	


function cargarActividades(valor)
{	
	if (valor == ''){
		document.getElementById('actividades').style.visibility = 'hidden';
		document.getElementById('actividades').style.height = '0px';
	}else{
		if(window.XMLHttpRequest) {
			objXml = new XMLHttpRequest(); // Gecko (Firefox, Moz), KHTML (Konqueror, Safari), Opera
		} else if(window.ActiveXObject) {
			objXml = new ActiveXObject("Microsoft.XMLHTTP"); // Internet Explorer		
		}		
		objXml.open("GET", "/ajax/veractividades.asp?valor=" + valor  , true);  
		
		objXml.onreadystatechange = function() {
			if (objXml.readyState == 4) {
				if (((objXml.responseText).indexOf('solouno')) > 0) {
					var ini;
					var fin;					
					fin = (objXml.responseText).indexOf('/script') - 1;
					ini = (objXml.responseText).indexOf('solouno') + 10;
					//alert((objXml.responseText).substring(ini,fin))
					document.getElementById('actividad').value = (objXml.responseText).substring(ini,fin);
					fin = (objXml.responseText).indexOf(';');
					ini = (objXml.responseText).indexOf('solodos') + 10;
					//alert((objXml2.responseText).substring(ini,fin))
					document.getElementById('actividad_final').value = (objXml.responseText).substring(ini,fin);
				}
				document.getElementById('actividades').innerHTML = objXml.responseText; 		
				document.getElementById('actividades').style.height = '250px';
				document.getElementById('actividades').style.visibility = 'visible';
			}else{
				document.getElementById('actividades').innerHTML = "<img src='/css/general/cargando.gif' /> Cargando ...";
				document.getElementById('actividades').style.height = '50px';
				document.getElementById('actividades').style.visibility = 'visible';
			}
		} 
		objXml.send(null);					
	}	
}

function cargarActividades2(valor)
{	
	if (valor == ''){
		document.getElementById('actividades').style.visibility = 'hidden';
		document.getElementById('actividades').style.height = '0px';
	}else{
		if(window.XMLHttpRequest) {
			objXml2 = new XMLHttpRequest(); // Gecko (Firefox, Moz), KHTML (Konqueror, Safari), Opera
		} else if(window.ActiveXObject) {
			objXml2 = new ActiveXObject("Microsoft.XMLHTTP"); // Internet Explorer		
		}		
		objXml2.open("GET", "/ajax/veractividades2.asp?valor=" + valor  , true);  
		
		objXml2.onreadystatechange = function() {
			if (objXml2.readyState == 4) {
				if (((objXml2.responseText).indexOf('solouno')) > 0) {
					var ini;
					var fin;					
					fin = (objXml2.responseText).indexOf('/script') - 1;
					ini = (objXml2.responseText).indexOf('solouno') + 10;
					document.getElementById('actividad2').value = (objXml2.responseText).substring(ini,fin);
					fin = (objXml2.responseText).indexOf(';');
					ini = (objXml2.responseText).indexOf('solodos') + 10;
					document.getElementById('actividad_final').value = (objXml2.responseText).substring(ini,fin);
				}
				document.getElementById('actividades').innerHTML = objXml2.responseText; 		
				document.getElementById('actividades').style.height = '250px';
				document.getElementById('actividades').style.visibility = 'visible';
			}else{
				document.getElementById('actividades').innerHTML = "<img src='/css/general/cargando.gif' /> Cargando ...";
				document.getElementById('actividades').style.height = '50px';
				document.getElementById('actividades').style.visibility = 'visible';
			}
		} 
		objXml2.send(null);					
	}	
}

function cargarActividadesAdmin(valor)
{	
	if (valor == ''){
		document.getElementById('actividad').style.visibility = 'hidden';
		document.getElementById('actividad').style.height = '0px';
	}else{
		if(window.XMLHttpRequest) {
			objXml3 = new XMLHttpRequest(); // Gecko (Firefox, Moz), KHTML (Konqueror, Safari), Opera
		} else if(window.ActiveXObject) {
			objXml3 = new ActiveXObject("Microsoft.XMLHTTP"); // Internet Explorer		
		}		
		objXml3.open("GET", "/ajax/verActividadesAdmin.asp?valor=" + valor  , true);  
		
		objXml3.onreadystatechange = function() {
			if (objXml3.readyState == 4) {
				if (((objXml3.responseText).indexOf('solouno')) > 0) {
					var ini;
					var fin;					
					fin = (objXml3.responseText).indexOf('/script') - 1;
					ini = (objXml3.responseText).indexOf('solouno') + 10;
					document.getElementById('incluir_actividad').value = (objXml3.responseText).substring(ini,fin);
				}
				document.getElementById('actividad').innerHTML = objXml3.responseText; 		
				document.getElementById('actividad').style.height = '250px';
				document.getElementById('actividad').style.visibility = 'visible';
			}else{
				document.getElementById('actividad').innerHTML = "<img src='/css/general/cargando.gif' /> Cargando ...";
				document.getElementById('actividad').style.height = '50px';
				document.getElementById('actividad').style.visibility = 'visible';
			}
		} 
		objXml3.send(null);					
	}	
}

function cargarTerminosAdmin(valor)
{	
	if (valor == ''){
		document.getElementById('actividad').style.visibility = 'hidden';
		document.getElementById('actividad').style.height = '0px';
	}else{
		if(window.XMLHttpRequest) {
			objXml4 = new XMLHttpRequest(); // Gecko (Firefox, Moz), KHTML (Konqueror, Safari), Opera
		} else if(window.ActiveXObject) {
			objXml4 = new ActiveXObject("Microsoft.XMLHTTP"); // Internet Explorer		
		}		
		objXml4.open("GET", "/ajax/verTerminosAdmin.asp?valor=" + valor  , true);  
		
		objXml4.onreadystatechange = function() {
			if (objXml4.readyState == 4) {
				document.getElementById('termino').innerHTML = objXml4.responseText; 		
				document.getElementById('termino').style.height = '200px';
				document.getElementById('termino').style.visibility = 'visible';
			}else{
				document.getElementById('termino').innerHTML = "<img src='/css/general/cargando.gif' /> Cargando ...";
				document.getElementById('termino').style.height = '0px';
				document.getElementById('termino').style.visibility = 'visible';
			}
		} 
		objXml4.send(null);					
	}	
}

function cargarEpigrafesAdmin(valor)
{	
	if (valor == ''){
		document.getElementById('epigrafe').style.visibility = 'hidden';
		document.getElementById('epigrafe').style.height = '0px';
	}else{
		if(window.XMLHttpRequest) {
			objXml5 = new XMLHttpRequest(); // Gecko (Firefox, Moz), KHTML (Konqueror, Safari), Opera
		} else if(window.ActiveXObject) {
			objXml5 = new ActiveXObject("Microsoft.XMLHTTP"); // Internet Explorer		
		}		
		objXml5.open("GET", "/ajax/verEpigrafesAdmin.asp?valor=" + valor  , true);  
		
		objXml5.onreadystatechange = function() {
			if (objXml5.readyState == 4) {
				document.getElementById('epigrafe').innerHTML = objXml5.responseText; 		
				document.getElementById('epigrafe').style.height = '200px';
				document.getElementById('epigrafe').style.visibility = 'visible';
			}else{
				document.getElementById('epigrafe').innerHTML = "<img src='/css/general/cargando.gif' /> Cargando ...";
				document.getElementById('epigrafe').style.height = '0px';
				document.getElementById('epigrafe').style.visibility = 'visible';
			}
		} 
		objXml5.send(null);					
	}	
}

function pasardatos(valor)
{
	
	if (valor){
		document.getElementById('persona_contacto').value = document.getElementById('contacto_facturacion').value
		document.getElementById('nombrecomercial').value = document.getElementById('nombrecomercial_facturacion').value
		document.getElementById('razonsocial').value = document.getElementById('razonsocial_facturacion').value
		document.getElementById('cif').value = document.getElementById('cif_facturacion').value
		document.getElementById('provincia').value = document.getElementById('provincia_facturacion').value
		document.getElementById('poblacion').value = document.getElementById('poblacion_facturacion').value
		document.getElementById('direccion').value = document.getElementById('direccion_facturacion').value
		document.getElementById('codpostal').value = document.getElementById('codpostal_facturacion').value		
		document.getElementById('numero').value = document.getElementById('numero_facturacion').value		
		document.getElementById('piso').value = document.getElementById('piso_facturacion').value		
		document.getElementById('tipovia').value = document.getElementById('tipovia_facturacion').value		
		cargarPob('provincia',document.getElementById('provincia_facturacion').value,document.getElementById('poblacion_facturacion').value,'poblacion');
		
	}
}

function cargarPob(nombre,valor,pob,sitio){
	
	if(window.XMLHttpRequest) {
		objXml1 = new XMLHttpRequest(); // Gecko (Firefox, Moz), KHTML (Konqueror, Safari), Opera
	} else if(window.ActiveXObject) {
		objXml1 = new ActiveXObject("Microsoft.XMLHTTP"); // Internet Explorer		
	}					
	
	objXml1.open("GET", "/usuarios/poblaciones_de.asp?valor=" + valor + "&pob=" + pob + "&nombre=" + sitio  , true);  
	objXml1.onreadystatechange=function() {
	if (objXml1.readyState==4) {
			document.getElementById('caja_' + nombre).innerHTML = objXml1.responseText;													
		}
	} 
	objXml1.send(null);		
	
}

