function limpia_campos(td){
	if(td=="documento"){
		document.frm_solicitud.carne.value="";
	} else if(td=="carne"){
		document.frm_solicitud.doc.value="";
	} else {
		document.frm_solicitud.doc.value="";
		document.frm_solicitud.carne.value="";
	}
	document.frm_solicitud.nombre.value="";
	document.frm_solicitud.departamento.value="";
	document.frm_solicitud.municipio.value="";
	document.frm_solicitud.depto_af.value="";
	document.frm_solicitud.mun_af.value="";
	document.frm_solicitud.zona.value="";
}
function asigna_valores(carne,doc,nombre,depto,mun,depto_mun,zona,cod_depto,cod_mun,ts,sw,txt_error){
	if(txt_error==""){
		document.frm_solicitud.carne.value=carne;
		document.frm_solicitud.doc.value=doc;
		document.frm_solicitud.nombre.value=nombre;
		document.frm_solicitud.departamento.value=depto;
		document.frm_solicitud.municipio.value=mun;
		document.frm_solicitud.depto_af.value=cod_depto;
		document.frm_solicitud.mun_af.value=cod_mun;
		document.frm_solicitud.zona.value=zona;
		ifr="";
		if(ts=="q" || ts=="r"){
			ifr="iframe_ips";
			ifr1="iframe_otro_origen";
		} else if(ts=="s"){
			ifr="iframe_ips_s";
		} else if(ts=="a"){
			ifr="";
		}
		if(ifr!=""){
			recarga_ips(ifr,cod_depto,cod_mun,sw);
		}
	} else {
		alert(txt_error);
	}
}
function recarga_ips(ifr,depto,mun,sw){
	//setTimeout(alert(),10000);
	//aviso_buscando("Cargando información adicional...","250","60");
	if(sw==""){
		if(ifr=="iframe_ips_s"){
			document.getElementById(ifr).src="depto_mun_prest.php?add=_sug&depto="+depto+"&mun="+mun+"&id_deptomun_prest="+depto+mun;
		} else {
			document.getElementById(ifr).src="depto_mun_prest.php?depto="+depto+"&mun="+mun+"&id_deptomun_prest="+depto+mun;
			document.getElementById(ifr1).src="depto_mun.php?depto="+depto+"&mun="+mun+"&id_deptomun_prest="+depto+mun;
		}
	}
}
function aviso_buscando(msg,w,h){
	Dialog.info(msg, {width:w, height:h, showProgress: true});
}
function aviso(msg,w,h){
	Dialog.alert(msg, 
             {width:w, height:h, okLabel: "Cerrar", 
              ok:function(win) { return 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 cargar_datos(td,valor,ts,sw){ 
	limpia_campos(td);
	if(td=="carne"){
		if(valor!=""){
			vars="td=carne&carne=" + valor + "&sw=" + sw;
		} else {
			document.frm_solicitud.carne.focus();
			aviso('Ingrese el número de carné del afiliado.','350','80');
			return false;
		}
	} else if(td=="documento"){
		if(valor!=""){
			vars="td=documento&documento=" + valor + "&sw=" + sw;
		} else {
			document.frm_solicitud.doc.focus();
			aviso('Ingrese el número de documento del afiliado.','350','80');
			return false;
		}
	}
	vars=vars+"&ts="+ts;
	aviso_buscando("Buscando información del afiliado...","250","60");
    ajax=NuevoAjax(); 
    ajax.open("POST",'busca_datos_afiliado.php',true);
	ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    ajax.send(vars);
    ajax.onreadystatechange=function(){
        if(ajax.readyState==1){
            //Sucede cuando se esta cargando la pagina
			//aviso_buscando("Buscando información del afiliado...","250","60");
        } else if(ajax.readyState==4){
            //Sucede cuando la consulta se realizó
			Dialog.closeInfo();
		    if(ajax.status==200){
                //Todo OK
				//alert(ajax.responseText);
				eval(ajax.responseText);
            } else if(ajax.status==404){
                //La pagina no existe
                //document.getEelementbyId("mensajes").innerHTML = "La página no existe";
				aviso("pagina no encontrada","250","80");
            }else{
                //Mostramos el posible error
                //document.getEelementbyId("mensajes").innerHTML = "Error:".ajax.status; 
				aviso("Error:"+ajax.status,"250","80");
            }
        }
    }
	//var t = new Ajax.Request('busca_datos_afiliado.php', {method: 'post', parameters:vars, onSuccess:handlerFunc}) 

	return false; 
} 

var handlerFunc = function(t) { 
	if(t.responseText){
		$('login_error_msg').hide();
		Dialog.closeInfo();
		administracion();
	} else {
		error();
	}
}