﻿// JavaScript Document [chis]

// Script general de validación de formularios (Version 1.0)
// Impiric

function esNumero(s) {
	num=parseFloat(s)
	if (num!=''+s) return false
    return true
}

function esEntero(s) {   
/*	num=parseInt(s)
	if (num!=''+s) return false
    return true
*/
	return !isNaN(s);
}

function esVacio(s){
   return ((s == null) || (s.length == 0));
}

var numeros="0123456789"
var letras_minusculas="a,b,c,d,e,f,g,h,i,j,k,l,m,n,ñ,o,p,q,r,s,t,u,v,w,x,y,z,ñ,á,é,í,ó,ú"
var letras_mayusculas=letras_minusculas.toUpperCase()
var letras=letras_minusculas+letras_mayusculas

function esNombre (s){
	s = s.replace(String.fromCharCode(225),"a");
	s = s.replace(String.fromCharCode(233),"e");
	s = s.replace(String.fromCharCode(237),"i");
	s = s.replace(String.fromCharCode(243),"o");
	s = s.replace(String.fromCharCode(250),"u");
	
	s = s.replace(String.fromCharCode(193),"A");
	s = s.replace(String.fromCharCode(201),"E");
	s = s.replace(String.fromCharCode(205),"I");
	s = s.replace(String.fromCharCode(211),"O");
	s = s.replace(String.fromCharCode(218),"U");
	
	s = s.replace(String.fromCharCode(241),"ñ");
	s = s.replace(String.fromCharCode(209),"Ñ");
	
	s = s.replace(String.fromCharCode(231),"c");
	s = s.replace(String.fromCharCode(199),"C");
	
    if (esVacio(s)) return false
    validos = letras+" "
    for (i = 0; i < s.length; i++){   
      
	   c = s.charAt(i);
     
	  c2 = s.charCodeAt(i);
	  if (validos.indexOf(c) == -1) return false;
    }
	return true
}

function esDNI(s) {
	if (s.length<=8) return esEntero(s)
}

function esNIF(s) {
	
	s=s.replace("-","");
    lo=s.length
	if (lo<2 || lo>9) return false
    dni=s.substring(0,lo-1)
    if (!esDNI(dni)) return false
	letra=new Array("T","R","W","A","G","M","Y","F",
					"P","D","X","B","N","J","Z","S",
					"Q","V","H","L","C","K","E");
    nif=s.substring(lo-1,lo).toUpperCase()
    if (nif!=letra[dni%23]) return false
	return true
}


function esNIF_NIE(s) {
	s=s.replace("-","");
    lo=s.length
	if (lo<2 || lo>9) return false
	
	if(s.substring(0,1).toUpperCase()=="X"){//NIE
		dni=s.substring(1,lo-1)
	}else{//NIF
    	dni=s.substring(0,lo-1)
	}
	
	if (!esDNI(dni)) return false	
	letra=new Array("T","R","W","A","G","M","Y","F",
					"P","D","X","B","N","J","Z","S",
					"Q","V","H","L","C","K","E");
    nif=s.substring(lo-1,lo).toUpperCase()
    if (nif!=letra[dni%23]) return false
	return true
	
}


function esNIE(s) {
	var regExpNIE = /^[a-zA-Z]{1}[0-9]{7}[a-zA-Z]{1}$/;
	return regExpNIE.test(s);
}

function esEmail(s) {
	if (s=="") return true;
    pb=s.indexOf(' ')
    if (pb!=-1) return false
	p1=s.indexOf('@')
    if (p1<1 || p1==(s.length-1) || p1==-1) return false
	p2=s.indexOf('.');
	if (p2<1 || p2==p1+1 || p2==-1 || p2==(s.length-1)) return false
	return true
}

function esMovil(tel){
	primerdigito="6"
	if (tel.length!=9 || !esEntero(tel) || (primerdigito.indexOf(tel.charAt(0)) == -1)) 
		return false
	return true
}

function esTelefono(tel){
		if (tel=="") return false;
		num = parseInt(tel);
		if (num != '' + tel)
			return false;

		primerdigito = "69";
		if (tel.length!=9 || (primerdigito.indexOf(tel.charAt(0))==-1))
			return false;
		return true;
}
function esCPostal(e)
{
	if (e=="99000") return true; //Codigo Postal establecido para Andorra
	num=(e)*1;
	if ((num < 1001) || (num > 52080) || (!esEntero(num)))
		return false;
	return true;
}


function validaLibreta(i_entidad,i_oficina,i_digito,i_cuenta){
// VALIDACIÓN DE CUALQUIER LIBRETA DE CUALQUIER ENTIDAD BANCARIA.
// Funcion recibe como parámetro la entidad, la oficina,
// el digito (concatenación del de control entidad-oficina y del de control entidad)
// y la cuenta. Espera los valores con 0's a la izquierda.
// Devuelve true o false.
// NOTAS:
// Formato deseado de los parámetros:
// - i_entidad (4)
// - i_oficina (4)
// - i_digito (2)
// - i_cuenta (10)
var wtotal,wcociente, wresto;
if (i_entidad.length != 4){
return false;
}
if (i_oficina.length != 4){
return false;
}
if (i_digito.length != 2){
return false;
}
if (i_cuenta.length != 10){
return false;
}
wtotal = i_entidad.charAt(0) * 4;
wtotal += i_entidad.charAt(1) * 8;
wtotal += i_entidad.charAt(2) * 5;
wtotal += i_entidad.charAt(3) * 10;
wtotal += i_oficina.charAt(0) * 9;
wtotal += i_oficina.charAt(1) * 7;
wtotal += i_oficina.charAt(2) * 3;
wtotal += i_oficina.charAt(3) * 6;
// busco el resto de dividir wtotal entre 11
wcociente = Math.floor(wtotal / 11);
wresto = wtotal - (wcociente * 11);
//
wtotal = 11 - wresto;
if (wtotal == 11){
wtotal=0;
}
if (wtotal == 10){
wtotal=1;
}
if (wtotal != i_digito.charAt(0)){
return false;
}
//hemos validado la entidad y oficina
//-----------------------------------
wtotal = i_cuenta.charAt(0) * 1;
wtotal += i_cuenta.charAt(1) * 2;
wtotal += i_cuenta.charAt(2) * 4;
wtotal += i_cuenta.charAt(3) * 8;
wtotal += i_cuenta.charAt(4) * 5;
wtotal += i_cuenta.charAt(5) * 10;
wtotal += i_cuenta.charAt(6) * 9;
wtotal += i_cuenta.charAt(7) * 7;
wtotal += i_cuenta.charAt(8) * 3;
wtotal += i_cuenta.charAt(9) * 6;

// busco el resto de dividir wtotal entre 11
wcociente = Math.floor(wtotal / 11);
wresto = wtotal - (wcociente * 11);
//
wtotal = 11 - wresto;
if (wtotal == 11){wtotal=0;}
if (wtotal == 10){wtotal=1;}

if (wtotal != i_digito.charAt(1)){
//alert(wtotal+' y no '+i_digito.charAt(1));
return false;
}
// hemos validado la cuenta corriente

return true;
}


function seleccionaOperador(op,otros){
	if(operadorActual!=""){
		document.getElementById(operadorActual).className="";
	}
	if(otros == false){
		document.getElementById(op).className="activo";
		document.getElementById("otros_operadores").selectedIndex=0;
		document.getElementById("operador").value=op;
		operadorActual=op
	}else{
		document.getElementById("operador").value=document.getElementById("otros_operadores").value;
	}
	
}


function validar(){
		titularreq = Array("nombre","nif","dir_nombrevia","dir_numero","poblacion","cp","provincia","telefono_contacto","email");
		labelstitular = Array("Nombre y apellidos","Identificador Fiscal","Nombre de la via","Número","Población","Código Postal","Provincia","Telefono Contacto","Email");
		formatotitular = Array("esNombre","esNIF","","","esNombre","esCPostal","esNombre","esTelefono","esEmail");
		
		envioreq = Array("nombre_envio","dir_nombrevia_envio","dir_numero_envio","poblacion_envio","cp_envio","provincia_envio","telefono_contacto_envio");
		labelsenvio = Array("Nombre y apellidos","Nombre de la via","Número","Población","Código Postal","Provincia","Telefono Contacto");
		formatoenvio = Array("esNombre","","","esNombre","esCPostal","esNombre","esTelefono");
		
		pagoreq = Array("entidad","oficina","dc","cuentacorriente","titular_cuenta","nif_cuenta");
		labelspago = Array("Entidad de la cuenta corriente","Oficina de la cuenta corriente","Dígito de control de la cuenta corriente","Número de cuenta","Titular de la cuenta","Identificador Fiscal");
		formatopago = Array("esEntidad","esEntero","esEntero","esEntero","esNombre","esNIF");
			
		errortxt = "Por favor, revisa los siguientes campos"+"\n";
		error = false
		
		errortitular=false
		for(var i=0;i<titularreq.length;i++){
			v = document.getElementById(titularreq[i]).value;
			v2= document.getElementById(titularreq[i])
			v2.style.border="1px solid #BAD3DA";
			
			if(v=="" || v==null){
				if(!errortitular){//es el primer error de esta seccion
					errortxt += "\nDATOS DEL TITULAR"+"\n";
				}
				errortxt += "- "+labelstitular[i]+"\n";
				error=true
				errortitular=true
				v2.style.border="1px solid #900";
			}else{
				if(formatotitular[i]!=""){
					
					locumple = validaFormato(v,formatotitular[i]); 
					
					if(!locumple){
						if(!errortitular){//es el primer error de esta seccion
							errortxt += "\nDATOS DEL TITULAR"+"\n";
						}
						errortxt += "- "+labelstitular[i]+"\n";
						error=true
						errortitular=true
						v2.style.border="1px solid #900";
					}
					
				}
				
				
			}
		}
		
		
		errortitular=false
		for(i=0;i<envioreq.length;i++){
		
			v = document.getElementById(envioreq[i]).value;
			v2= document.getElementById(envioreq[i])
			v2.style.border="1px solid #BAD3DA";
			if(v=="" || v==null){
				if(!errortitular){//es el primer error de esta seccion
					errortxt += "\nDATOS DE ENVIO"+"\n";
				}
				errortxt += "- "+labelsenvio[i]+"\n";
				error=true
				errortitular=true
				v2.style.border="1px solid #900";
			}else{
				if(formatoenvio[i]!=""){
					locumple = validaFormato(v,formatoenvio[i]); 
					
					if(!locumple){
						if(!errortitular){//es el primer error de esta seccion
							errortxt += "\nDATOS DE ENVIO"+"\n";
						}
						errortxt += "- "+labelsenvio[i]+"\n";
						error=true
						errortitular=true
						v2.style.border="1px solid #900";
					}
					
				}
			}
		}
		
		errortitular=false
		for(i=0;i<pagoreq.length;i++){
			v = document.getElementById(pagoreq[i]).value;
			v2= document.getElementById(pagoreq[i])
			v2.style.border="1px solid #BAD3DA";
			if(v=="" || v==null){
				if(!errortitular){//es el primer error de esta seccion
					errortxt += "\nDATOS DE PAGO"+"\n";
				}
				errortxt += "- "+labelspago[i]+"\n";
				error=true
				errortitular=true
				v2.style.border="1px solid #900";
			}else{
				if(formatopago[i]!=""){
				locumple = validaFormato(v,formatopago[i]); 
					
					if(!locumple){
						if(!errortitular){//es el primer error de esta seccion
							errortxt += "\nDATOS DE PAGO"+"\n";
						}
						errortxt += "- "+labelspago[i]+"\n";
						error=true
						errortitular=true
						v2.style.border="1px solid #900";
					}
					
				}
			}
		}
		
		/*
		if(!document.getElementById("unoemail").checked && !document.getElementById("unocorreo").checked){
			if(!errortitular){//es el primer error de esta seccion
					errortxt += "\nDATOS DE PAGO"+"\n";
			}
			errortxt +="- ¿Cómo quieres que te enviemos la factura mensual?\n";
			error = true	
		}
		*/
		document.getElementById("t_iberia").style.border="1px solid #BAD3DA";
		if(document.getElementById("t_iberia").value!=""){
			if(!esEntero(document.getElementById("t_iberia").value) || document.getElementById("t_iberia").value.length<8){
				errortxt += "\nIBERIA"+"\n";
				errortxt +="- Número de tarjeta de Iberia Plus.\n";
				document.getElementById("t_iberia").style.border="1px solid #900";
				error=true
			}
		}
		
		
		if(!document.getElementById("compromiso").checked){
				errortxt += "\nCONDICIONES DE USO"+"\n";
				errortxt +="- Debes aceptar las condiciones de uso\n";
				error=true
		}
		if(error){
			alert(errortxt);	
			return false;
		}
		
		
		
		document.form1.submit();
		
}

function esICC(s){
	if( /^([0-9]{18}) ([0-9]{1})$/.test(s) || /^([0-9]{19})$/.test(s)){
		inicio = s.substr(0,6);
		
		if(iccesp_str.indexOf(";"+inicio+";")> -1){
			return true;		
		}else{
			return false;	
		}
	}else{
		alert("reg");
		return false;
	}
}


function validaFormato(valor,formato){
	switch(formato){
		case "esMovil":
			return esMovil(valor);
			break;
		case "esNombre":
			return esNombre(valor);
			break;
		case "esCPostal":
			return esCPostal(valor);
			break;
		case "esTelefono":
			return esTelefono(valor);
			break;
		case "esEmail":
			return esEmail(valor);
			break;
		case "esEntero":
			return esEntero(valor);
			break;
		case "esNIF":
			return esNIF_NIE(valor);
			break;
		case "esEntidad":
			return esEntidad(valor);
			break;
		case "esICC":
			return esICC(valor);
			break;
	}
}	







function validarPortabilidad(){
		titularreq = Array("telefono_portabilidad","icc","operador", "nombre","nif","dir_nombrevia","dir_numero","poblacion","cp","provincia","telefono_contacto","email");
		labelstitular = Array("Número de linea que deseas conservar","Número ICC","Operador actual","Nombre y apellidos","Identificador Fiscal","Nombre de la via","Número","Población","Código Postal","Provincia","Telefono Contacto","Email");
		formatotitular = Array("esMovil","esICC","","esNombre","esNIF","","","esNombre","esCPostal","esNombre","esTelefono","esEmail");
		
		envioreq = Array("nombre_envio","dir_nombrevia_envio","dir_numero_envio","poblacion_envio","cp_envio","provincia_envio","telefono_contacto_envio");
		labelsenvio = Array("Nombre y apellidos","Nombre de la via","Número","Población","Código Postal","Provincia","Telefono Contacto");
		formatoenvio = Array("esNombre","","","esNombre","esCPostal","esNombre","esTelefono");
		
		pagoreq = Array("entidad","oficina","dc","cuentacorriente","titular_cuenta","nif_cuenta");
		labelspago = Array("Entidad de la cuenta corriente","Oficina de la cuenta corriente","Dígito de control de la cuenta corriente","Número de cuenta","Titular de la cuenta","Identificador Fiscal");
		formatopago = Array("esEntidad","esEntero","esEntero","esEntero","esNombre","esNIF");
		
		
		
		
		
		
		errortxt = "Por favor, revisa los siguientes campos"+"\n";
		error = false
		
		errortitular=false
		for(var i=0;i<titularreq.length;i++){
			
			v = document.getElementById(titularreq[i]).value;
			v2= document.getElementById(titularreq[i])
			v2.style.border="1px solid #BAD3DA";
			
			if(v=="" || v==null){
				if(!errortitular){//es el primer error de esta seccion
					errortxt += "\nDATOS DEL TITULAR"+"\n";
				}
				errortxt += "- "+labelstitular[i]+"\n";
				error=true
				errortitular=true
				v2.style.border="1px solid #900";
			}else{
				if(formatotitular[i]!=""){
					
					
					locumple = validaFormato(v,formatotitular[i]); 
										
					if(!locumple){
						if(!errortitular){//es el primer error de esta seccion
							errortxt += "\nDATOS DEL TITULAR"+"\n";
						}
						errortxt += "- "+labelstitular[i]+"\n";
						error=true
						errortitular=true
						v2.style.border="1px solid #900";
					}
					
				}
				
				
			}
		}
		
		
		errortitular=false
		for(i=0;i<envioreq.length;i++){
		
			v = document.getElementById(envioreq[i]).value;
			v2= document.getElementById(envioreq[i])
			v2.style.border="1px solid #BAD3DA";
			if(v=="" || v==null){
				if(!errortitular){//es el primer error de esta seccion
					errortxt += "\nDATOS DE ENVIO"+"\n";
				}
				errortxt += "- "+labelsenvio[i]+"\n";
				error=true
				errortitular=true
				v2.style.border="1px solid #900";
			}else{
				if(formatoenvio[i]!=""){
					
					locumple = validaFormato(v,formatoenvio[i]); 
					
					if(!locumple){
						if(!errortitular){//es el primer error de esta seccion
							errortxt += "\nDATOS DE ENVIO"+"\n";
						}
						errortxt += "- "+labelsenvio[i]+"\n";
						error=true
						errortitular=true
						v2.style.border="1px solid #900";
					}
					
				}
			}
		}
		
		errortitular=false
		for(i=0;i<pagoreq.length;i++){
			v = document.getElementById(pagoreq[i]).value;
			v2= document.getElementById(pagoreq[i])
			v2.style.border="1px solid #BAD3DA";
			if(v=="" || v==null){
				if(!errortitular){//es el primer error de esta seccion
					errortxt += "\nDATOS DE PAGO"+"\n";
				}
				errortxt += "- "+labelspago[i]+"\n";
				error=true
				errortitular=true
				v2.style.border="1px solid #900";
			}else{
				if(formatopago[i]!=""){
					
					locumple = validaFormato(v,formatopago[i]); 
					
					if(!locumple){
						if(!errortitular){//es el primer error de esta seccion
							errortxt += "\nDATOS DE PAGO"+"\n";
						}
						errortxt += "- "+labelspago[i]+"\n";
						error=true
						errortitular=true
						v2.style.border="1px solid #900";
					}
					
				}
			}
		}
		
		/*
		if(!document.getElementById("unoemail").checked && !document.getElementById("unocorreo").checked){
			if(!errortitular){//es el primer error de esta seccion
					errortxt += "\nDATOS DE PAGO"+"\n";
			}
			errortxt +="- ¿Cómo quieres que te enviemos la factura mensual?\n";
			error = true	
		}
		*/
		
		document.getElementById("t_iberia").style.border="1px solid #BAD3DA";
		if(document.getElementById("t_iberia").value!=""){
			if(!esEntero(document.getElementById("t_iberia").value) || document.getElementById("t_iberia").value.length<8){
				errortxt += "\nIBERIA"+"\n";
				errortxt +="- Número de tarjeta de Iberia Plus.\n";
				document.getElementById("t_iberia").style.border="1px solid #900";
				error=true
			}
		}
		
		
		if(!document.getElementById("compromiso").checked){
				errortxt += "\nCONDICIONES DE USO"+"\n";
				errortxt +="\n- Debes aceptar las condiciones de uso\n";
				error=true
		}
		if(error){
			alert(errortxt);	
			return false;
		}
		
		
		
		document.form1.submit();
}




function validarTarifa(){
		req = Array("telefono_portabilidad","telefono_contacto","nombre","nif");
		labels = Array("Número de linea","Telefono de contacto","Nombre y apellidos","Número de identificación fiscal");
		formato = Array("esMovil","esTelefono","esNombre","esNIF");
		
	
		errortxt = "Por favor, revisa los siguientes campos"+"\n";
		error = false
		
		errortitular=false
		for(var i=0;i<req.length;i++){
			
			v = document.getElementById(req[i]).value;
			v2= document.getElementById(req[i])
			v2.style.border="1px solid #BAD3DA";
			
			if(v=="" || v==null){
				
				errortxt += "- "+labels[i]+"\n";
				error=true
				errortitular=true
				v2.style.border="1px solid #900";
			}else{
				if(formato[i]!=""){
					
					locumple = validaFormato(v,formato[i]); 
					
					if(!locumple){
						if(!errortitular){//es el primer error de esta seccion
							errortxt += "\nDATOS DEL TITULAR"+"\n";
						}
						errortxt += "- "+labels[i]+"\n";
						error=true
						errortitular=true
						v2.style.border="1px solid #900";
					}
					
				}
				
				
			}
		}
		
		
		if(!document.getElementById("compromiso").checked){
				errortxt += "\nCONDICIONES DE USO"+"\n";
				errortxt +="\n- Debes aceptar las condiciones de uso\n";
				error=true
		}
		if(error){
			alert(errortxt);	
			return false;
		}
		
		
		
		document.form1.submit();
		
		
		
		
		
}

function esEntidad(s){
	if(s.length<4){
		return false;	
	}
	
	n = Number(s);
	
	if(entidades_str.indexOf(";"+n+";")> -1){
		return true;	
	}else{
		return false;	
	}
}


/********************/
// EVENTOS BLUR PARA DUPLICAR DATOS
/********************/
/*
$(document).ready(function(){
	$("#nombre").bind("blur",function(e){
		if($("#nombre_envio").val()==""){
			$("#nombre_envio").val($("#nombre").val());	  
			$("#titular_cuenta").val($("#nombre").val());	  
		}
	});
	$("#nif").bind("blur",function(e){
		if($("#nif_cuenta").val()==""){
			$("#nif_cuenta").val($("#nif").val());	  
		}
	});
	$("#direccion").bind("blur",function(e){
		if($("#direccion_envio").val()==""){
			$("#direccion_envio").val($("#direccion").val());	  
		}
	});
	$("#provincia").bind("blur",function(e){
		if($("#provincia_envio").val()==""){
			$("#provincia_envio").val($("#provincia").val());	  
		}
	});
	$("#cp").bind("blur",function(e){
		if($("#cp_envio").val()==""){
			$("#cp_envio").val($("#cp").val());	  
		}
	});
	$("#telefono_contacto").bind("blur",function(e){
		if($("#telefono_contacto_envio").val()==""){
			$("#telefono_contacto_envio").val($("#telefono_contacto").val());	  
		}
	});
	
	
	
});
*/
$(document).ready(function(){
	$("#mismos").bind("click",function(){
									   
		if($("#mismos").attr("checked")){ //duplico
				
			$("#datos-envio > label, #datos-envio > input").fadeTo("slow",0.5);
			
			$("#nombre_envio").val($("#nombre").val());	
			
			$("#dir_nombrevia_envio").val($("#dir_nombrevia").val());
			$("#dir_numero_envio").val($("#dir_numero").val());
			$("#dir_escalera_envio").val($("#dir_escalera").val());
			$("#dir_piso_envio").val($("#dir_piso").val());
			$("#dir_letra_envio").val($("#dir_letra").val());
			$("#poblacion_envio").val($("#poblacion").val());
			
			$("#provincia_envio").val($("#provincia").val());
			$("#cp_envio").val($("#cp").val());	
			$("#telefono_contacto_envio").val($("#telefono_contacto").val());
			
			$("#datos-envio > input").attr("readonly","readonly");
		}else{
			$("#datos-envio > label, #datos-envio > input").fadeTo("slow",1);
			$("#datos-envio > input").removeAttr("readonly");
		}
									   
	});			
	
	
	
	
	$("#nombre").bind("blur",function(e){
		if($("#mismos").attr("checked")){ 
			$("#nombre_envio").val($("#nombre").val());	  
		}
	});
	$("#dir_nombrevia").bind("blur",function(e){
		if($("#mismos").attr("checked")){ 
			$("#dir_nombrevia_envio").val($("#dir_nombrevia").val());	  
		}
	});
	$("#dir_numero").bind("blur",function(e){
		if($("#mismos").attr("checked")){ 
			$("#dir_numero_envio").val($("#dir_numero").val());	  
		}
	});
	$("#dir_escalera").bind("blur",function(e){
		if($("#mismos").attr("checked")){ 
			$("#dir_escalera_envio").val($("#dir_escalera").val());	  
		}
	});
	$("#dir_piso").bind("blur",function(e){
		if($("#mismos").attr("checked")){ 
			$("#dir_piso_envio").val($("#dir_piso").val());	  
		}
	});
	$("#dir_letra").bind("blur",function(e){
		if($("#mismos").attr("checked")){ 
			$("#dir_letra_envio").val($("#dir_letra").val());	  
		}
	});
	$("#poblacion").bind("blur",function(e){
		if($("#mismos").attr("checked")){ 
			$("#poblacion_envio").val($("#poblacion").val());	  
		}
	});
	
	
	
	$("#provincia").bind("blur",function(e){
		if($("#mismos").attr("checked")){ 
			$("#provincia_envio").val($("#provincia").val());	  
		}
	});
	$("#cp").bind("blur",function(e){
		if($("#mismos").attr("checked")){ 
			$("#cp_envio").val($("#cp").val());	  
		}
	});
	$("#telefono_contacto").bind("blur",function(e){
		if($("#mismos").attr("checked")){ 
			$("#telefono_contacto_envio").val($("#telefono_contacto").val());	  
		}
	});
						   
});




var entidades = new Array(8904,
8907,
8917,
8764,
8765,
8766,
8767,
8770,
8771,
8772,
8774,
8775,
8777,
8779,
8782,
8783,
8784,
8785,
8786,
8787,
8790,
8792,
8794,
8799,
8800,
8803,
8737,
8738,
8740,
8741,
8742,
8743,
8744,
8745,
8746,
8747,
8748,
8750,
8751,
8752,
8754,
8755,
8756,
8757,
8758,
8759,
8760,
8761,
8762,
8763,
8710,
8711,
8712,
8713,
8715,
8716,
8717,
8718,
8719,
8720,
8721,
8723,
8724,
8725,
8726,
8727,
8728,
8729,
8730,
8731,
8732,
8733,
8736,
8686,
8687,
8688,
8689,
8690,
8691,
8692,
8693,
8694,
8695,
8696,
8697,
8698,
8699,
8700,
8701,
8702,
8703,
8704,
8706,
8707,
8708,
8709,
8661,
8662,
8663,
8664,
8665,
8666,
8668,
8669,
8670,
8671,
8672,
8673,
8674,
8675,
8676,
8677,
8678,
8679,
8680,
8681,
8682,
8683,
8684,
8685,
8637,
8638,
8639,
8641,
8642,
8643,
8644,
8645,
8646,
8647,
8648,
8649,
8650,
8651,
8652,
8653,
8654,
8655,
8656,
8657,
8658,
8659,
8660,
8611,
8613,
8614,
8615,
8616,
8617,
8619,
8621,
8622,
8623,
8624,
8625,
8626,
8627,
8628,
8629,
8630,
8631,
8632,
8633,
8634,
8635,
8636,
8585,
8586,
8587,
8588,
8589,
8590,
8591,
8592,
8593,
8594,
8595,
8597,
8598,
8600,
8601,
8602,
8603,
8604,
8605,
8606,
8607,
8608,
8609,
8610,
8561,
8562,
8563,
8564,
8565,
8566,
8568,
8569,
8570,
8571,
8572,
8573,
8574,
8575,
8576,
8577,
8578,
8579,
8580,
8581,
8582,
8584,
8536,
8537,
8538,
8539,
8540,
8541,
8542,
8543,
8544,
8545,
8546,
8547,
8548,
8550,
8551,
8552,
8553,
8554,
8555,
8556,
8557,
8558,
8559,
8560,
8510,
8511,
8513,
8514,
8515,
8516,
8517,
8518,
8519,
8520,
8521,
8522,
8523,
8525,
8526,
8527,
8528,
8529,
8530,
8531,
8532,
8533,
8534,
8535,
8484,
8485,
8486,
8487,
8488,
8489,
8492,
8493,
8494,
8495,
8496,
8497,
8498,
8499,
8500,
8501,
8502,
8503,
8504,
8505,
8506,
8507,
8508,
8509,
8461,
8462,
8463,
8464,
8465,
8466,
8467,
8468,
8469,
8470,
8471,
8472,
8473,
8474,
8475,
8476,
8477,
8478,
8479,
8480,
8481,
8482,
8483,
8436,
8437,
8438,
8439,
8440,
8441,
8442,
8443,
8444,
8445,
8446,
8447,
8448,
8450,
8451,
8452,
8453,
8454,
8455,
8456,
8457,
8458,
8459,
8460,
8413,
8414,
8415,
8416,
8417,
8418,
8419,
8420,
8421,
8422,
8423,
8424,
8425,
8426,
8427,
8428,
8429,
8430,
8431,
8432,
8433,
8434,
8435,
8386,
8387,
8388,
8389,
8390,
8391,
8392,
8393,
8394,
8395,
8396,
8397,
8398,
8399,
8400,
8401,
8402,
8403,
8404,
8405,
8406,
8407,
8408,
8409,
8411,
8412,
8359,
8360,
8361,
8362,
8363,
8364,
8365,
8366,
8367,
8368,
8369,
8371,
8372,
8373,
8374,
8375,
8377,
8378,
8379,
8380,
8381,
8382,
8383,
8384,
8385,
8333,
8334,
8335,
8336,
8337,
8338,
8339,
8340,
8341,
8343,
8344,
8346,
8347,
8348,
8349,
8350,
8351,
8352,
8353,
8354,
8355,
8356,
8357,
8358,
8300,
8302,
8303,
8304,
8305,
8306,
8311,
8312,
8313,
8315,
8316,
8317,
8318,
8319,
8320,
8322,
8324,
8325,
8326,
8327,
8328,
8329,
8330,
8331,
8332,
8204,
8205,
8208,
8210,
8212,
8214,
8215,
8216,
8217,
8218,
8220,
8222,
8223,
8224,
8226,
8227,
8228,
8229,
8230,
8231,
8232,
8237,
8238,
4816,
4817,
4818,
4820,
4821,
4822,
4823,
4824,
4825,
4826,
4827,
4828,
4829,
4830,
4831,
4833,
4834,
4835,
4836,
4839,
8201,
8202,
8203,
4781,
4783,
4785,
4786,
4787,
4790,
4791,
4792,
4793,
4795,
4796,
4798,
4800,
4801,
4802,
4803,
4804,
4806,
4807,
4808,
4810,
4811,
4812,
4813,
4814,
4815,
4745,
4746,
4747,
4748,
4750,
4751,
4752,
4754,
4755,
4756,
4758,
4759,
4760,
4762,
4763,
4764,
4766,
4768,
4769,
4771,
4773,
4774,
4775,
4777,
4778,
4780,
4715,
4716,
4717,
4718,
4720,
4721,
4722,
4723,
4724,
4725,
4727,
4728,
4729,
4730,
4731,
4732,
4734,
4735,
4736,
4737,
4738,
4739,
4741,
4743,
4744,
3151,
3176,
3178,
4001,
4002,
4003,
4004,
4005,
4006,
4007,
4008,
4009,
4010,
4011,
4012,
4013,
4701,
4702,
4703,
4705,
4707,
4710,
4711,
4712,
4714,
3033,
3034,
3036,
3037,
3038,
3039,
3040,
3041,
3042,
3043,
3044,
3046,
3047,
3048,
3049,
3050,
3051,
3052,
3053,
3055,
3145,
3149,
3122,
3125,
3126,
3132,
3133,
3136,
3143,
3148,
3153,
3156,
3158,
3164,
3170,
3180,
3182,
3026,
3027,
3028,
3030,
3031,
3032,
3011,
3013,
3014,
3071,
3073,
3074,
3075,
3077,
3088,
3002,
3004,
3006,
3012,
3086,
3087,
3091,
3099,
3101,
3103,
3106,
3107,
3109,
64,
70,
71,
90,
117,
120,
126,
134,
140,
7,
14,
23,
27,
39,
52,
84,
98,
5,
18,
51,
66,
80,
92,
110,
139,
3000,
3010,
4487,
4488,
4489,
4490,
4491,
4492,
4493,
4494,
4495,
4496,
4497,
2,
6,
12,
17,
22,
25,
26,
28,
32,
33,
34,
37,
47,
54,
55,
60,
4462,
4463,
4464,
4465,
4466,
4467,
4468,
4469,
4470,
4471,
4472,
4473,
4474,
4475,
4476,
4477,
4478,
4479,
4480,
4481,
4482,
4483,
4484,
4485,
4486,
4435,
4436,
4437,
4438,
4439,
4440,
4441,
4442,
4443,
4444,
4445,
4446,
4447,
4448,
4449,
4450,
4451,
4452,
4453,
4454,
4455,
4456,
4457,
4458,
4459,
4460,
4461,
4410,
4411,
4412,
4413,
4414,
4415,
4416,
4417,
4418,
4419,
4420,
4421,
4422,
4423,
4424,
4425,
4426,
4427,
4428,
4429,
4430,
4431,
4432,
4433,
4434,
4384,
4385,
4386,
4387,
4388,
4389,
4390,
4391,
4392,
4393,
4394,
4395,
4396,
4397,
4398,
4399,
4400,
4401,
4402,
4403,
4404,
4405,
4406,
4407,
4408,
4409,
4357,
4358,
4359,
4360,
4361,
4362,
4363,
4364,
4365,
4366,
4367,
4368,
4369,
4370,
4371,
4372,
4373,
4374,
4375,
4376,
4377,
4378,
4379,
4380,
4381,
4382,
4383,
4331,
4332,
4333,
4334,
4335,
4336,
4337,
4338,
4339,
4340,
4341,
4342,
4343,
4344,
4345,
4347,
4348,
4349,
4350,
4351,
4352,
4353,
4354,
4355,
4356,
4303,
4304,
4305,
4307,
4308,
4309,
4310,
4311,
4312,
4313,
4314,
4315,
4316,
4317,
4318,
4319,
4320,
4321,
4322,
4323,
4324,
4325,
4326,
4327,
4328,
4329,
4330,
1751,
1752,
1753,
1754,
1755,
1756,
1757,
1758,
1759,
1760,
1761,
1762,
1763,
1764,
1765,
1766,
1767,
1768,
1769,
1770,
1771,
1772,
1773,
1774,
1775,
1776,
1777,
4301,
4302,
1725,
1726,
1727,
1728,
1729,
1730,
1731,
1732,
1733,
1734,
1735,
1736,
1737,
1738,
1739,
1740,
1741,
1742,
1743,
1744,
1745,
1746,
1747,
1748,
1749,
1750,
9847,
9848,
9890,
9891,
1701,
1702,
1703,
1704,
1705,
1706,
1707,
1708,
1709,
1710,
1711,
1712,
1713,
1714,
1715,
1716,
1717,
1718,
1719,
1720,
1721,
1722,
1723,
1724,
9823,
9824,
9825,
9826,
9827,
9828,
9829,
9830,
9831,
9832,
9833,
9834,
9836,
9837,
9838,
9839,
9840,
9841,
9842,
9843,
9844,
9845,
9846,
1295,
9801,
9802,
9803,
9804,
9805,
9806,
9807,
9808,
9809,
9810,
9811,
9812,
9813,
9814,
9815,
9816,
9817,
9818,
9819,
9820,
9821,
9822,
1274,
1275,
1276,
1277,
1278,
1279,
1280,
1281,
1282,
1283,
1284,
1285,
1286,
1287,
1288,
1289,
1290,
1292,
1293,
1294,
1252,
1253,
1254,
1255,
1256,
1257,
1258,
1259,
1260,
1261,
1262,
1263,
1264,
1265,
1266,
1267,
1268,
1269,
1270,
1271,
1272,
1273,
1230,
1231,
1232,
1233,
1234,
1235,
1236,
1237,
1238,
1239,
1240,
1241,
1242,
1243,
1244,
1245,
1246,
1247,
1248,
1249,
1250,
1251,
1206,
1207,
1208,
1209,
1210,
1211,
1212,
1213,
1214,
1215,
1216,
1217,
1218,
1219,
1220,
1221,
1222,
1223,
1224,
1225,
1226,
1227,
1228,
1229,
1183,
1184,
1185,
1186,
1187,
1188,
1189,
1190,
1191,
1192,
1193,
1194,
1195,
1196,
1197,
1198,
1199,
1200,
1201,
1202,
1203,
1204,
1205,
1156,
1157,
1158,
1159,
1160,
1161,
1162,
1163,
1164,
1165,
1166,
1167,
1168,
1169,
1170,
1171,
1172,
1173,
1174,
1176,
1177,
1178,
1179,
1180,
1181,
1182,
1128,
1129,
1130,
1131,
1132,
1133,
1134,
1135,
1136,
1137,
1138,
1139,
1140,
1141,
1142,
1143,
1144,
1145,
1146,
1147,
1148,
1149,
1150,
1151,
1152,
1153,
1154,
1155,
1515,
1101,
1102,
1103,
1104,
1105,
1106,
1107,
1108,
1109,
1110,
1111,
1112,
1113,
1114,
1115,
1116,
1117,
1118,
1119,
1120,
1121,
1122,
1123,
1124,
1125,
1126,
1127,
151,
155,
160,
161,
164,
166,
169,
170,
171,
176,
177,
178,
189,
195,
199,
203,
206,
207,
214,
1452,
1460,
1485,
1512,
1513,
1514,
1516,
1517,
1518,
1519,
1520,
1521,
1522,
1523,
1524,
1525,
1526,
1527,
1528,
1529,
1530,
146,
147,
148,
1492,
1493,
1494,
1495,
1496,
1497,
1498,
1499,
1500,
1501,
1502,
1503,
1504,
1505,
1506,
1507,
1508,
1509,
1510,
1511,
1470,
1471,
1472,
1473,
1474,
1475,
1476,
1477,
1478,
1479,
1480,
1481,
1482,
1483,
1484,
1486,
1487,
1488,
1489,
1491,
212,
213,
218,
1451,
1453,
1454,
1455,
1456,
1457,
1458,
1459,
1461,
1462,
1463,
1464,
1465,
1466,
1467,
1468,
1469,
143,
144,
145,
149,
150,
152,
154,
156,
159,
162,
163,
167,
168,
172,
174,
179,
180,
181,
190,
194,
196,
197,
201,
8832,
8901,
8902,
8903,
8905,
8906,
8908,
8909,
8910,
8911,
8912,
8913,
8914,
8915,
8916,
8918,
7861,
7862,
105,
106,
107,
108,
131,
8807,
8808,
8809,
8810,
8811,
8812,
8813,
8814,
8815,
8816,
8817,
8818,
8819,
8820,
8821,
8822,
8823,
8824,
8825,
8826,
8827,
8828,
8829,
8830,
8831,
8739,
8749,
8753,
8768,
8769,
8773,
8776,
8778,
8780,
8781,
8788,
8789,
8791,
8793,
8795,
8796,
8797,
8798,
8801,
8802,
8804,
8805,
8806,
8342,
8345,
8370,
8376,
8410,
8449,
8490,
8512,
8524,
8567,
8583,
8596,
8599,
8612,
8618,
8620,
8640,
8667,
8705,
8714,
8722,
8734,
8735,
4832,
4837,
4838,
8206,
8207,
8209,
8211,
8219,
8221,
8225,
8233,
8234,
8235,
8236,
8239,
8240,
8307,
8308,
8309,
8310,
8314,
8321,
8323,
4733,
4740,
4742,
4749,
4753,
4757,
4761,
4765,
4767,
4770,
4772,
4776,
4779,
4782,
4784,
4788,
4789,
4794,
4797,
4799,
4805,
4809,
4819,
3171,
3172,
3173,
3174,
3175,
3177,
3179,
3181,
3183,
3184,
3185,
3186,
3187,
3188,
3189,
6701,
4704,
4706,
4708,
4709,
4713,
4719,
4726,
3139,
3140,
3141,
3142,
3144,
3146,
3147,
3150,
3152,
3154,
3155,
3157,
3159,
3160,
3161,
3162,
3163,
3165,
3166,
3167,
3168,
3169,
3110,
3111,
3112,
3113,
3114,
3115,
3116,
3117,
3118,
3119,
3121,
3123,
3124,
3127,
3128,
3129,
3130,
3131,
3134,
3135,
3137,
3138,
3078,
3079,
3080,
3081,
3082,
3083,
3084,
3085,
3089,
3090,
3092,
3093,
3094,
3095,
3096,
3097,
3098,
3100,
3102,
3104,
3105,
3108,
3023,
3024,
3025,
3029,
3035,
3045,
3054,
3056,
3057,
3058,
3059,
3060,
3061,
3062,
3063,
3064,
3065,
3066,
3067,
3068,
3069,
3070,
3072,
3076,
2098,
2099,
2100,
2101,
2102,
2103,
2104,
2105,
2106,
3001,
3003,
3005,
3007,
3008,
3009,
3015,
3016,
3017,
3018,
3019,
3020,
3021,
3022,
2075,
2076,
2077,
2078,
2079,
2080,
2081,
2082,
2083,
2084,
2085,
2086,
2087,
2088,
2089,
2090,
2091,
2092,
2093,
2094,
2095,
2096,
2097,
2052,
2053,
2054,
2055,
2056,
2057,
2058,
2059,
2060,
2061,
2062,
2063,
2064,
2065,
2066,
2067,
2068,
2069,
2070,
2071,
2072,
2073,
2074,
2028,
2029,
2030,
2031,
2032,
2033,
2034,
2035,
2036,
2037,
2038,
2039,
2040,
2041,
2042,
2043,
2044,
2045,
2046,
2047,
2048,
2049,
2050,
2051,
2005,
2006,
2007,
2008,
2009,
2010,
2011,
2012,
2013,
2014,
2015,
2016,
2017,
2018,
2019,
2020,
2021,
2022,
2023,
2024,
2025,
2026,
2027,
220,
221,
222,
223,
224,
225,
226,
227,
228,
229,
230,
231,
232,
233,
234,
1001,
1004,
1005,
1301,
1302,
1490,
2000,
2001,
2002,
2003,
2004,
165,
173,
175,
182,
183,
184,
185,
186,
187,
188,
191,
192,
193,
198,
200,
202,
205,
208,
209,
210,
211,
215,
216,
217,
219,
113,
114,
115,
116,
118,
119,
121,
122,
123,
124,
125,
127,
128,
129,
130,
132,
133,
135,
136,
137,
138,
141,
142,
153,
157,
158,
78,
79,
81,
82,
83,
85,
86,
87,
88,
89,
91,
93,
94,
95,
96,
97,
99,
100,
101,
102,
103,
104,
109,
111,
112,
42,
43,
44,
45,
46,
48,
49,
50,
53,
56,
57,
58,
59,
61,
62,
63,
65,
67,
68,
69,
72,
73,
74,
75,
76,
77,
1000,
1002,
1003,
1006,
1,
3,
4,
8,
9,
10,
11,
13,
15,
16,
19,
20,
21,
24,
29,
30,
31,
35,
36,
38,
40,
41);
var entidades_str = ";"+entidades.join(";")+";";



var iccesp = new Array('893418',
'893415',
'893416',
'893419',
'893406',
'893421',
'893422',
'893423',
'893425',
'893407',
'893405',
'893456',
'893401',
'893404',
'893402',
'893401',
'893401',
'893456',
'893401',
'893405',
'893456',
'893456',
'893401',
'893456',
'893402',
'893401');
var iccesp_str = ";"+iccesp.join(";")+";";