/**
 * @author Juan Requena
 */
var _recargapag_js_ = true;
function NuevoAjax(){
        var xmlhttp=false;
        try{
                xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        }catch(e){
                try{
                        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                }catch(E){
                        xmlhttp = false;
                }
        }

        if(!xmlhttp && typeof XMLHttpRequest!='undefined'){
                xmlhttp = new XMLHttpRequest();
        }
        return xmlhttp;
	}
	
function NuevoAjax2(pag){
        var xmlhttp=false;
		var msje = "Su navegador no soporta las funciónalidades de este sitio y podria experimentarlo de forma diferente a la que fue pensada.";
		msje += " Por favor habilite javascript en su navegador para verlo normalmente.\n";
	    this.AjaxFailedAlert = msje;
			 
	    this.requestFile = pag;
	    this.encodeURIString = true;
	    this.execute = false;
	    if (window.XMLHttpRequest) { 
	        this.xmlhttp = new XMLHttpRequest();
	        if (this.xmlhttp.overrideMimeType) {
	            this.xmlhttp.overrideMimeType('text/xml');
	        }
	    } 
        try{
                xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        }catch(e){
                try{
                        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                }catch(E){
                        xmlhttp = false;
                }
        }

        if(!xmlhttp && typeof XMLHttpRequest!='undefined'){
                xmlhttp = new XMLHttpRequest();
        }
        return xmlhttp;
	}

function Cargar(url){
	//prompt('mensaje', url);
    var contenido, preloader;
    contenido = document.getElementById('contenidoajax');
    preloader = document.getElementById('preloader');
	document.getElementById('preloader').style.display='block';
	var auzurl = url.split("/");
	var auxurl2 = auzurl[auzurl.length -1].split("?");
	var nompag = auxurl2[0];

	//creamos el objeto XMLHttpRequest
    ajax=NuevoAjax(); 
    //peticionamos los datos, le damos la url enviada desde el link
	
    ajax.open("GET", url,true);
	 
    ajax.onreadystatechange=function(){
            if(ajax.readyState==1){
                    //preloader.innerHTML = "Cargando...";
                    //modificamos el estilo de la div, mostrando una imagen de fondo
                    //preloader.style.background = "url('loading.gif') no-repeat"; 
            }else if(ajax.readyState==4){
					//alert(ajax.status);
                    if(ajax.status==200){
                            //mostramos los datos dentro de la div
                            contenido.innerHTML = ajax.responseText;
							switch(nompag){
								 case "InformacionTerminos":
								 	contenido.style.backgroundColor = "#FFFFCC"; //#edda74
									contenido.style.borderWidth = "1px";
									contenido.style.borderColor = "#ff9933";
									contenido.style.borderStyle = "solid";
									contenido.style.width = "200px";
									contenido.style.left = "200px";
									contenido.style.top=  "550px";
									contenido.style.display = "block";
								break;
								case "loginback":
									preloader.style.backgroundColor = "#FFFFCC";
									preloader.style.borderWidth = "1px";
									//preloader.style.width = "200px";
									preloader.style.borderStyle = "solid";
									preloader.innerHTML="Procesando Solicitud";
									contenido.style.display = "none";
									try{
										document.getElementById("loginsubmit").click();
									}
									catch(ex){
										//alert(ex);
										preloader.style.display = "none";
										var msje = "Usuario No Registrado";
										setCookie('msjes', msje, '', '/', '', '');
										RegistrarRegistroUsuario('46','AUT-02');
										window.location.href = 'recordarclave';
										
									}
								break;
								case "seleccarro":
								case "seleccarroSeleccionadas":
								case "seleccarroTratados":
								case "selecarroavanzada":
									try{
										//prompt(ajax.responseText, contenido.innerHTML);
										var carrito = getCookie('carritoNorma');
										var aux = document.getElementById('inputcookies').value;
										//alert(aux);
										if ((aux != "-1") && (aux != "") && (aux != "0")) {
											aux = aux.split("#");
											for (var k = 0; k < aux.length; k++){
												if(!existeEnCarro(aux[k])){
													if (calcularEspacio() > 0){
														carrito = carrito +"#"+aux[k];		
													}
												}
												deleteCookie('carritoNorma', '/', '');
											    setCookie('carritoNorma', carrito, '', '/', '', '');
											    recalcularCarro('carritoNorma');
											}
											
										}
										else if(aux == "-1") {
											alert("Error Base Datos: " + aux)
										}    
	                                }
									catch(ex){}
									break;
								default:
								break;
							}
							
							preloader.innerHTML = "Cargado.";
                            preloader.style.background = "url('loaded.gif') no-repeat";
							document.getElementById('preloader').style.display='none'; //descomentar
							document.getElementById('mensaje').style.display='none'; //descomentar
							
                    }else if(ajax.status==404){
                            preloader.innerHTML = "La página no existe";
                    }else{
                            //mostramos el posible error
                            preloader.innerHTML = "Error:"+ajax.status; 
                    }
            }
    }
    ajax.send(null);
}

function cargaDatosOk(url){
	var contenido, preloader;
	var tabla = "<table class=\"tblRegistro\" >";
	tabla +="<tr><td class=\"tituloRegistro\">Procesando..</td> </tr></table>";
	var error = "<table class=\"tblError\">";
    error +="<tr><td class=\"encabezadoError\">Error</td></tr>";
    error +=" <tr><td class=\"contenidoError\" id=\"contenidoError\">Hubo un error.</td></tr></table>";
	contenido = document.getElementById('contenidoajax');
    ajax=NuevoAjax(); 
    ajax.open("GET", url,true);
	 
    ajax.onreadystatechange=function(){
            if(ajax.readyState==1){
                    contenido.innerHTML = tabla;
                    
            }else if(ajax.readyState==4){
                    if(ajax.status==200){
                            contenido.innerHTML = ajax.responseText;
							
                    }else if(ajax.status==404){
                            preloader.innerHTML = "La página no existe";
                    }else{
                            contenido.innerHTML = error;
                    }
            }
    }
    ajax.send(null);
}
function cargarDivRefundidos(idNorma,cadena){
	var contenido, preloader;
	var url = "divRefundidos";
	url += "?idnorma=" + idNorma+"&cadena="+cadena;
    contenido = document.getElementById('textosRefundidos');
    ajax=NuevoAjax(); 
    //peticionamos los datos, le damos la url enviada desde el link
    ajax.open("GET", url,true);
	 
    ajax.onreadystatechange=function(){
            if(ajax.readyState==1){
                    //preloader.innerHTML = "Cargando...";
                    //modificamos el estilo de la div, mostrando una imagen de fondo
                    //preloader.style.background = "url('loading.gif') no-repeat"; 
            }else if(ajax.readyState==4){
					//alert(ajax.status);
                    if(ajax.status==200){
                            //mostramos los datos dentro de la div
                            contenido.innerHTML = ajax.responseText;
							
                    }else if(ajax.status==404){
                            preloader.innerHTML = "La página no existe";
                    }else{
                            //mostramos el posible error
                            //preloader.innerHTML = "Error:".ajax.status; 
							alert("Error:".ajax.status);
                    }
            }
    }
    ajax.send(null);
}
function cargarDivRefundeA(idLlama,idNorma,norma,cadena){
	var contenido, preloader;
	var url = "divRefundeA";
	url += "?idnorma=" + idNorma+"&norma="+norma+"&cadena="+cadena;
    contenido = document.getElementById('textosRefundeA');
	preloader = document.getElementById('msjeLogin');
    ajax=NuevoAjax(); 
    //peticionamos los datos, le damos la url enviada desde el link
    ajax.open("GET", url,true);
	 
    ajax.onreadystatechange=function(){
            if(ajax.readyState==1){
                    //preloader.innerHTML = "Cargando...";
                    //modificamos el estilo de la div, mostrando una imagen de fondo
                    //preloader.style.background = "url('loading.gif') no-repeat"; 
            }else if(ajax.readyState==4){
					//alert(ajax.status);
                    if(ajax.status==200){
                            //mostramos los datos dentro de la div
                            contenido.innerHTML = ajax.responseText;
							var textos = document.getElementById('textosRefundeA');
							var Llama = document.getElementById(idLlama);
							var posicion = findPos(Llama);
							textos.style.left = posicion[0]-(50)+'px';
						    textos.style.top = posicion[1]+'px';
						    textos.style.display ="block";
							
                    }else if(ajax.status==404){
                            preloader.innerHTML = "La página no existe";
                    }else{
                            //mostramos el posible error
							//alert("Error:"+ajax.status);
                            alert("Vinculacion no existente en XML");
							//preloader.innerHTML = "Error:"+ajax.status; 
                    }
            }
    }
    ajax.send(null);
}
function getUserDB2_eliminar(url){
	var contenido, preloader;
	var user=document.getElementById("usuario").value;
	alert("user:"+user);
	var clave = document.getElementById("password").value;
	alert("clave:"+clave);
	user =  user.replace('@',"%40");

	//url += "/../Consulta/userplonecd?user=" + user+"&clave="+clave;
	url += "/../Consulta/userplonecd"
	datos = "user=" + user+"&clave="+clave;
    contenido = document.getElementById("__ac_name")
	
    ajax=NuevoAjax2('/../Consulta/userplonecd'); 
	url = url.replace('undefined/','');
	alert("url2:"+url)
    ajax.open("POST", url,true);
	//alert(url);
    ajax.onreadystatechange=function(){
			if(ajax.readyState==1){
                    //preloader.innerHTML = "Cargando...";
                    //modificamos el estilo de la div, mostrando una imagen de fondo
                    //preloader.style.background = "url('loading.gif') no-repeat"; 
            }else if(ajax.readyState==4){
					if(ajax.status==200){
							var res = ajax.responseText; 
							if (parseInt(res) == -1) {
								//alert(res);
								alert("Datos Incorrectos");
								document.getElementById("usuario").focus();
								document.getElementById("usuario").select();
								RegistrarRegistroUsuario('46','AUT-04');
							}
							else {
								var user = document.getElementById("__ac_name");
								user.value = ajax.responseText.replace("\n","");
								try{document.getElementById("login_name").value =ajax.responseText.replace("\n","") ;}
								catch(e){}
								//alert(user.value);
								var subdiv = document.getElementById("divxsumbit");
								document.getElementById("lclave").value = document.getElementById("password").value;
								document.getElementById("lUser").value = document.getElementById("usuario").value;
								subdiv.innerHTML = "<input type=\"submit\" id=\"newsubmit\" style=\"display:none\" >"
								
								document.getElementById("newsubmit").click();
								user.style.display = "none";
							}
											
                    }else if(ajax.status==404){
                            alert("Error Obtener Usuario");
                    }else{
                            alert("Error : nº "+ajax.status);
							 
                    }
            }
    }
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    alert("datos:"+datos);
	ajax.send(datos);
    //ajax.send(null);
}

function getUserDB(url){
	var contenido, preloader;
	var user=document.getElementById("usuario").value;
	var clave = document.getElementById("password").value;
	
	deleteCookie('rolUser','/');
	
	url += "/../Consulta/userplonecd"
    contenido = document.getElementById("__ac_name")
	url = url.replace('undefined/','');
	url = url.replace('Consulta/../Consulta','Consulta');

	this.success = function (req){
		var res = req.responseText;
		try {
			if (parseInt(res) == -1) {
				alert("Datos Incorrectos");
				document.getElementById("usuario").focus();
				document.getElementById("usuario").select();
				RegistrarRegistroUsuario('46', 'AUT-04');
			}
			else {
				var user = document.getElementById("__ac_name");
				user.value = res.replace("\n", "");
				try {
					document.getElementById("login_name").value = res.replace("\n", "");
				} 
				catch (e) {
				}
				var subdiv = document.getElementById("divxsumbit");
				document.getElementById("lclave").value = document.getElementById("password").value;
				document.getElementById("lUser").value = document.getElementById("usuario").value;
				subdiv.innerHTML = "<input type=\"submit\" id=\"newsubmit\" style=\"display:none\" >"
				
				document.getElementById("newsubmit").click();
				user.style.display = "none";
			}
		} 
		catch (e) {
			alert(e);
		}
	};
    this.failure = function(req){
		alert("Error!!!");
	};

	//ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	var params = {
		method:'get',
		onSuccess: this.success, 
		onFailure: this.failure,
		parameters: {user: user, 
					 clave: clave}
	};
	this.request = new Ajax.Request(url, params);
}

function verificarUser(url){
	var correo=document.getElementById("contacto1").value;
	if (validaCorreoConsulta("contacto1") == false){
		return false;
	}
	
	correo =  correo.replace('@',"%40");
	url += "/../Consulta/datosUserConsulta?correo=" + correo;
    correo_usuario = correo;
    ajax=NuevoAjax(); 
	url = url.replace('undefined/','');
    ajax.open("GET", url,true);
	 
    ajax.onreadystatechange=function(){
			if(ajax.readyState==1){
                     
            }else if(ajax.readyState==4){
					if(ajax.status==200){
							var res = ajax.responseText;
							//alert(res); 
							if (res.length >0){
								datos = res.split("||");
								//alert(datos);
								if (datos.length >= 4){
									var nombre = document.getElementById('nombre');
									var act = document.getElementById('actividad');
									var profesion = document.getElementById('profesion');
									var correo = document.getElementById('correo');
									var institucion = document.getElementById('institucion'); 
									var region = document.getElementById('region'); 
									var pais = document.getElementById('pais');									
									var contLetras = document.getElementById('contLetras');
									var contCodigo = document.getElementById('contCodigo');
									
									nombre.value = datos[0];
									correo.value = datos[5];
									act.value = datos[1];
									profesion.value = datos[2];
									institucion.value = datos[3];
									var id_tipo_atencion = datos[6];
									var id_region = datos[8];
									var es_parla = datos[9];
									var id_usuario = datos[10];
									var nom_pais = datos[11];
									
									var fono	 = datos[12];
									var fax 	 = datos[13];
									try{
										$('id_usuario').value 		= id_usuario;
										$('contacto2_fono').value 	= fono;
										$('contacto2_fax').value 	= fax;
									}catch(e){
										
									}
									
									try {
										contCodigo.removeChild(document.getElementById('contCodigo1'));
										contCodigo.removeChild(document.getElementById('contCodigo2'));
										contLetras.removeChild(document.getElementById('contLetras1'));
										contLetras.removeChild(document.getElementById('contLetras2'));
									} 
									catch (e) {
										//pass
									}

									act.disabled = true;
									nombre.disabled = true;
									profesion.disabled= true;
									institucion.disabled= true;
									
									var ids_parla_asociados = document.getElementById('ids_parla_asociados');
									ids_parla_asociados.value = datos[7];																			

									eligeParlaAsociado(1);
									revisaParlamentarioAsociado();
									modificaOptionsSelectDestServ();
									if (id_region == "" || id_region ==''|| id_region =='none') {
										id_region ='0';	}	
									eligeRegion(id_region);
									//eligePais(nom_pais);
									
									if ((id_region != '-1' && id_region != "")||id_region =='0') {
										region.disabled = true;	}	
									else{
										region.selectedIndex = 0;
										region.disabled = false;}	
									
									//if (nom_pais != '-1' && nom_pais != "") {
									//	pais.disabled = true;}	
									//else{
									//	pais.selectedIndex = 0;
									//	pais.disabled = false;}								
									
									
									// solo si el usuario es Congreso (Senado, Camara, BCN)
									if (id_tipo_atencion == '1' || id_tipo_atencion == '2') {
										$('div_destinatario_servicio').style.display = "block";
										//$('tr_region').style.display = 'none';
										//$('tr_pais').style.display = 'none';										
										$('esUsuarioCongreso').value = 'True';
										$('ind_oferta_demanda').style.display = 'none';										
									}
      //alert("habilita pais1");
									// solo si es Ciudadano
									if (id_tipo_atencion == '0' || id_tipo_atencion == '') {
										$('esUsuarioCongreso').value = 'False';
										$('div_destinatario_servicio').style.display = "none";										
										//$('tr_region').style.display = '';
										//$('tr_pais').style.display = '';
										
										//if (nom_pais != '-1' && nom_pais != 'Chile'){
											//$('tr_region').style.display = 'none';}															
									}
     //alert("habilita pais2");
									// solo si es Senado o Camara
									if (id_tipo_atencion == '1') {
										$('tabla_parlamentario_asociado').style.display = '';
										if ($('parlamentarioAsociado').length == 1){
											$('id_destinatario_servicio').selectedIndex = 6;
											activaDestinatario($('id_destinatario_servicio'));
											$('tabla_parlamentario_asociado').style.display = 'none';
										}
										if (es_parla == 'checked'){
											$('tabla_parlamentario_asociado').style.display = 'none';
											if (institucion == "CAMARA") { $('id_destinatario_servicio').value = "1";}
											else {$('id_destinatario_servicio').value = "2";}
											activaDestinatario($('id_destinatario_servicio'));
											eligeOpcion('parlamentario', id_usuario);
										}
									}
					//	alert("habilita pais3");			
									// solo si es BCN
									if (id_tipo_atencion == '2') {
										$('tabla_parlamentario_asociado').style.display = 'none';
										$('parlamentarioAsociado').selectedIndex = 0;
										$('id_destinatario_servicio').selectedIndex = 6;
										activaDestinatario($('id_destinatario_servicio'));
									}
																		
									var hijos2 = document.getElementById('div_destinatario_servicio').childNodes;
									enableHijos(hijos2);																	
										
								}
								else{
									var nombre = document.getElementById('nombre');
									var identificador = document.getElementById('contacto1');
									var correo = document.getElementById('correo');
									var act = document.getElementById('actividad');
									var profesion = document.getElementById('profesion');
									var institucion = document.getElementById('institucion'); 
									var region = document.getElementById('region'); 									
									var contLetras = document.getElementById('contLetras');
									var contCodigo = document.getElementById('contCodigo');
									
									try{
										$('id_usuario').value 		= id_usuario;
										$('contacto2_fono').value 	= '';
										$('contacto2_fax').value 	= '';
									}catch(e){
										
									}
									nombre.value = '';
									correo.value = identificador.value;
									act.selectedIndex = 0;
									profesion.value = '';
									institucion.value = '';									
									act.disabled = false;
									nombre.disabled = false;
									profesion.disabled= false;
									institucion.disabled= false;
									region.disabled= false;
									region.selectedIndex = 0;
									
									$('div_destinatario_servicio').style.display = "none";
									$('parlamentarioAsociado').selectedIndex = 0;									
									var hijos2 = document.getElementById('div_destinatario_servicio').childNodes;
									disableHijos(hijos2);
									eligeRegion(id_region);
									//$('tr_region').style.display = '';

									// solo si es Senado o Camara
									correo_usuario= correo_usuario.replace("%40","@");
									if (correo_usuario.match(/^.*@camara.cl$|^.*@senado.cl$/)) {
										$('tabla_parlamentario_asociado').style.display = '';
										if ($('parlamentarioAsociado').length == 1){
											$('id_destinatario_servicio').selectedIndex = 6;
											activaDestinatario($('id_destinatario_servicio'));
											$('tabla_parlamentario_asociado').style.display = 'none';
										}
										if (es_parla == 'checked'){
											$('tabla_parlamentario_asociado').style.display = 'none';
											if (institucion == "CAMARA") { $('id_destinatario_servicio').value = "1";}
											else {$('id_destinatario_servicio').value = "2";}
											activaDestinatario($('id_destinatario_servicio'));
											eligeOpcion('parlamentario', id_usuario);
										}
										$('div_destinatario_servicio').style.display = "block";
										//$('tr_region').style.display = 'none';
										$('tr_pais').style.display = 'none';										
										$('esUsuarioCongreso').value = 'True';
										$('ind_oferta_demanda').style.display = 'none';										
									}

								}
								
							}
							//alert(res);
											
                    }else if(ajax.status==404){
                            alert("Error PT");
                    }else{
                            alert("Error : nº "+ajax.status);
							 
                    }
            }
    }
    ajax.send(null);
}


function verificarUserRegistro(url){
	var correo=document.getElementById("rUser").value;
	if (validaCorreoConsulta("rUser") == false){
		return false;
	}
	
	correo =  correo.replace('@',"%40");
	url += "/../Consulta/datosUserConsulta?correo=" + correo;
    
    ajax=NuevoAjax(); 
	url = url.replace('undefined/','');
    ajax.open("GET", url,true);
	 
    ajax.onreadystatechange=function(){
		if(ajax.readyState==1){}
		else if(ajax.readyState==4){
			if(ajax.status==200){
				var res = ajax.responseText;
				if (res.length >0){
					datos = res.split("||");
					var nombre = document.getElementById('rNombre');
					var pais = document.getElementById('rPais');
					var region = document.getElementById('rRegion'); 
					var profesion = document.getElementById('rProfesion');
					var institucion = document.getElementById('rInstitucion'); 
					var actividad = document.getElementById('rActividad'); 
					var telefono = document.getElementById('rTelefono'); 
					var fax = document.getElementById('rFax'); 
					var pass = document.getElementById('rPass');
					var rpass = document.getElementById('rRpass');	
					
					estado_usuario = datos[15]				
					if (estado_usuario == 1) {
						alert("Ya existe un usuario activo con ese correo electrónico. Debe ingresar otro correo.");
						$('rUser').focus();
						$('rUser').select();
					}
					else {
						if (datos.length >= 4) {
							nombre.value = datos[0];
							pais.value = datos[11];
							region.value = datos[8];
							profesion.value = datos[2];
							institucion.value = datos[3];
							telefono.value = datos[12];
							fax.value = datos[13];
							pass.value = datos[14];
							rpass.value = datos[14];
							
							act = datos[1];
							eligeActividad(act);
							
							nombre.disabled = true;
							pais.disabled = true;
							region.disabled = true;
							profesion.disabled = true;
							institucion.disabled = true;
							actividad.disabled = true;
							telefono.disabled = true;
							fax.disabled = true;
							
							nombre.style.background = '#f4f4f4';
							pais.style.background = '#f4f4f4';
							region.style.background = '#f4f4f4';
							profesion.style.background = '#f4f4f4';
							institucion.style.background = '#f4f4f4';
							actividad.style.background = '#f4f4f4';
							telefono.style.background = '#f4f4f4';
							fax.style.background = '#f4f4f4';

							if (pass.value == 'act1663') {
								pass.value  = '';
								rpass.value = '';
								pass.style.background = '#fff';
								rpass.style.background = '#fff';
								pass.disabled = false;
								rpass.disabled = false;								
								if ($('rRegion').selectedIndex == 0){
									region.disabled = false;
									region.style.background = '#fff';
								}
								alert("Atencion!!\n\nYa existe una cuenta creada para este correo en espera de su activación.\nComplete los datos que faltan y le enviaremos un mail para que pueda confirmar su registro. Terminado el proceso de registro podrá actualizar sus datos.");
								$('botonEnvioCorreoRegistro').style.display = "none";
								$('botonAceptarRegistro').style.display = "";																
							}
							else {
								pass.disabled = true;
								rpass.disabled = true;
								pass.style.background = '#f4f4f4';
								rpass.style.background = '#f4f4f4';
								alert("Atencion!!\n\nYa existe una cuenta para este correo en espera de su activación.\nNo puede editar los campos, sólo solicitar que se le envíe un correo con los datos necesarios para confirmar su registro. Terminado el proceso de registro podrá actualizar sus datos.");
								$('botonEnvioCorreoRegistro').style.display = "";
								$('botonAceptarRegistro').style.display = "none";								
							}
							

						}
						else {
							$('botonEnvioCorreoRegistro').style.display = "none";
							$('botonAceptarRegistro').style.display = "";
							
							nombre.value = '';
							pais.value = '';
							region.value = '';
							profesion.value = '';
							institucion.value = '';
							telefono.value = '';
							fax.value = '';
							pass.value = '';
							rpass.value = '';
							actividad.selectedIndex = 0;
							region.selectedIndex = 0;
							
							nombre.disabled = false;
							pais.disabled = false;
							region.disabled = false;
							profesion.disabled = false;
							institucion.disabled = false;
							actividad.disabled = false;
							telefono.disabled = false;
							fax.disabled = false;
							pass.disabled = false;
							rpass.disabled = false;
							
							nombre.style.background = '#fff';
							pais.style.background = '#fff';
							region.style.background = '#fff';
							profesion.style.background = '#fff';
							institucion.style.background = '#fff';
							actividad.style.background = '#fff';
							telefono.style.background = '#fff';
							fax.style.background = '#fff';
							pass.style.background = '#fff';
							rpass.style.background = '#fff';
						}
					}					
				}
            }else if(ajax.status==404){
                    alert("Error PT");
            }else{
                    alert("Error : nº "+ajax.status);
            }
        }
    }
    ajax.send(null);
}



function revisaParlamentarioAsociado(){
	var pAsociado = $('parlamentarioAsociado');
	if (pAsociado.selectedIndex != 0) {
		var opt = pAsociado.options[pAsociado.selectedIndex];
		var camara = opt.getAttribute("camara");
		var idParalamentario = opt.value;
		if (camara == "CAMARA") {
			$('id_destinatario_servicio').value = "1";
		}
		else {
			$('id_destinatario_servicio').value = "2";
		}
		activaDestinatario($('id_destinatario_servicio'));
		eligeOpcion('parlamentario', idParalamentario);
		$('id_destinatario_servicio').options[0].setAttribute("disabled", "disabled");			
		$('id_destinatario_servicio').options[1].setAttribute("disabled", "disabled");
		$('id_destinatario_servicio').options[2].setAttribute("disabled", "disabled");						
		$('parlamentario').disabled = true;	
		
		if ($('contacto1').value != $('correo').value) {
			$('correo_envio').value = pAsociado[pAsociado.selectedIndex].getAttribute("correo");
		}
	}
	else {
		$('id_destinatario_servicio').selectedIndex = 0;
		activaDestinatario($('id_destinatario_servicio'));
		$('parlamentario').selectedIndex = 0;
		$('id_destinatario_servicio').options[0].removeAttribute("disabled");			
		$('id_destinatario_servicio').options[1].removeAttribute("disabled");
		$('id_destinatario_servicio').options[2].removeAttribute("disabled");
		$('parlamentario').disabled = false;
		$('correo_envio').value = $('correo').value;
	}
	

}

function actualizaEsteDato (obj, dato){
	this.success = function (req){
		//ok.
	}
    this.failure = function(req){
		alert("Error!!! en actualizaEsteDato");
	};
	var id_usuario = $('id_usuario').value;
	if (!id_usuario){
		return false;
	}
	var params = {
		method:'get',
		onSuccess: this.success, 
		onFailure: this.failure,
		parameters: {campo: dato, 
					 id_usuario: id_usuario, 
					 valor: obj.value}
	};
	var url = "script/updateUserInfo";
	this.request = new Ajax.Request(url, params);
}

