function objetoAjax_2(){
	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 handleKeyPress(){
	cuenta = trim(document.getElementById('cuenta').value);
	tem_x = document.getElementById('cuenta').getAttribute('rel');
	VerificarCuenta('../../postulacion/usuario/cuenta_disponible.php?cuenta='+cuenta+'&opcx='+tem_x,'rpta_cuenta','contenido'); 
}

/**************************************************************/
function VerificarCuenta(url,div){
		var divResultado = document.getElementById(div);	
		divResultado.innerHTML="Cargando...";
		var ajax_2=objetoAjax_2();
		ajax_2.open("GET", url);
		ajax_2.onreadystatechange=function(){
			if (ajax_2.readyState==4) {
				divResultado.innerHTML = ajax_2.responseText;
				divResultado.style.display = "block"; 
			}
		}
		ajax_2.send(null);
	}
/**************************************************************/



function llenaCuenta(){
	var nombre_trab = document.getElementById('trabajador'); 
	var u_ape = nombre_trab.options[nombre_trab.selectedIndex].getAttribute("alt").toLowerCase();
	var u_nom = nombre_trab.options[nombre_trab.selectedIndex].getAttribute("rel").toLowerCase();
	u_nom = u_nom.substr(0,1); 
	cuenta = u_nom+u_ape; 
	document.getElementById('cuenta').value=cuenta; 
	VerificarCuenta('../../postulacion/usuario/cuenta_disponible.php?cuenta='+cuenta,'rpta_cuenta'); 
 }

// Funcion para el ingreso de solo numeros
	var nav4 = window.Event ? true : false;
	function soloNumeros(evt){ 
		// NOTE: Backspace = 8, Enter = 13, '0' = 48, '9' = 57 
		var key = nav4 ? evt.which : evt.keyCode; 
		return (key <= 13 || (key >= 48 && key <= 57));
	}

// Funcion para habilitar controles
	function cambiar(archivo,valor) {
		var archi = MM_findObj(archivo);
		eval("archi.disabled = valor");
	}
// Funciones para Validar los Formularios
	function MM_findObj(n, d) { //v4.01
	  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	  if(!x && d.getElementById) x=d.getElementById(n); return x;
	}
	function MM_validateForm() { //v4.0
	  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
	  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
		if (val) { nm=val.title; if ((val=val.value)!="") {
		  if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
			if (p<1 || p==(val.length-1)) errors+='- El valor ingresado en el campo '+nm+' no es una direccion de correo valida.\n';
		  } else if (test!='R') { num = parseFloat(val);
			if (isNaN(val)) errors+='- '+nm+' debe de ser numerico.\n';
			if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
			  min=test.substring(8,p); max=test.substring(p+1);
			  if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
		} } } else if (test.charAt(0) == 'R') errors += '- '+nm+', es un campo requerido.\n'; }
	  } if (errors) alert('OCURRIERON LOS SIGUIENTES ERRORES:\n\n'+errors);
	  document.MM_returnValue = (errors == '');
	}

// Funcion para Mostrar Capa
	function mostrar(capa,valor){
		document.getElementById(capa).style.display=valor;
	}
	
// Funcion para Mostrar opciones dependiendo el Estado de la Actividad
	function mostrarEstadoActividad(id){
		switch(id){
			case "0"://Cancelado
			case "1"://En Desarrollo
			case "2"://Completado
				document.getElementById("obs").style.display="block";
				break;			
			case "3"://Observado
				document.getElementById("obs").style.display="none";
				break;
		}
	}

// Funciones para el cambio de color de fondo de las Filas
	function mOvr(src,clrOver) { 
		//if (!src.contains(event.fromElement)) { 
			src.bgColor = clrOver; 
		//} 
	} 
	function mOut(src,clrIn) { 
		//if (!src.contains(event.toElement)) { 
			src.bgColor = clrIn; 
		//}
	}
	
// Funcion para Ejecutar el Filtro
	function filtro(page,url,value,opc){
        if(page=="act"){
			if(opc==1) url = url+"?mes="+value;
			if(opc==2) url = url+"&mes="+value;
			document.getElementById("frameFiltro").innerHTML = "<iframe name='actividades' src='"+url+"' frameborder='0' width='1020' height='670'></iframe>"; 
		}
		if(page=="py"){
			document.getElementById("frameFiltro").innerHTML = "<iframe name='Proyectos' src='"+url+"' frameborder='0' width='1020' height='670'></iframe>"; 
		}
	}

// Funcion para Mostra y Ocultar las SubActividades
	function mostrarOcultarSubactividad(id) {
	 subact = document.all(id).style.display;
	  if(subact == "block")
		document.all(id).style.display = "none";
	  else
		document.all(id).style.display = "block";
	}

// Funcion para Activar las opciones de Agregar Actividad
	function activar(opc){
		if(opc!=1){ //Actividad Concluida
			document.getElementById("estado_act").style.display="block";
		}else{
			document.getElementById("estado_act").style.display="none";
		}
	}
// Funcion para abrir popup
	function editarActividad(url){
		var h = (screen.width);
		var v = (screen.height);
		var top=(v/2)-(400/2);
		var left=(h/2)-(500/2);
		editar = window.open(url,"EDIT","width=630, height=345, top="+top+", left="+left+", scrollbars=yes, menubar=no, location=no, resizable=no") 
	}
// Funcion para abrir cualquier POPUP
	function abrirPopup(url,width,height){
		var h = (screen.width);
		var v = (screen.height);
		var top=(v/2)-(400/2);
		var left=(h/2)-(500/2);
		ventana = window.open(url,"Ventana","width="+width+", height="+height+", top="+top+", left="+left+", scrollbars=no, menubar=no, location=no, resizable=no") 
	}
// Funciones de Mantenimiento
	function validarAgregarTrab(frm){
		var validado = false;
		var msg = "OCURRIERON LOS SIGUIENTES ERRORES\n\n";
		var nombre = trim(frm.nombre.value);
		var apellido = trim(frm.apellido.value);
		var cargo = trim(frm.cargo.value);
		var profesion = trim(frm.profesion.value);
		var dni = trim(frm.dni.value);
		var email = trim(frm.email.value);
		
		if( (nombre!="")&&(apellido!="")&&(cargo!="")&&(profesion!="")&&(dni!="") ){ validado=true; }
		else{
			validado=false;
			if(nombre==""){msg = msg+"- El campo nombre es requerido\n";}
			if(apellido==""){msg = msg+"- El campo apellido es requerido\n";}
			if(cargo==""){msg = msg+"- El campo cargo es requerido\n";}
			if(profesion==""){msg = msg+"- El campo profesion es requerido\n";}
			if(dni==""){msg = msg+"- El campo dni es requerido\n";}
		}
		if(email!=""){
			if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)==false){
				validado=false;
				msg = msg+"- La direccion de correo ingresada es Incorrecta.\n";
			}
		}
		if(validado==false){alert(msg);}
		return validado;
	}
// Funcion para validar el campo de recordar CLAVE DE ACCESO
	function validarRecordar(obj){
		if(trim(obj.value)!="") return true;
		else{
			alert("Debe de ingresar el dni.");
			obj.focus();
			return false;
		}
	}
// Funcion para habilitar los campos a editar	
	function habilitar(campos){
		for(i=0;i<=(campos.length-3);i++){
			campos[i].disabled = false;
		}
		campos[0].focus();
		campos[(campos.length-1)].disabled = false;
		campos[(campos.length-2)].disabled = true;
	}
	function habilitarDni1(div){
		var divDni = document.getElementById(div);
		divDni.innerHTML = "<a href='agregarDni.php' onclick='agregarDni(document.agregar.trabajador.value,document.agregar); return false;' title='Agregar el DNI del trabajador'><img src='../imagenes/dni.gif' border='0'></a>";
	}
	function habilitarDni2(div){
		var divDni = document.getElementById(div);
		//divDni.innerHTML = "<a href='agregarDni.php' onclick=\"agregarDni(<?php echo $row_rsTrab['ps_idtrabajador']; ?>,document.modificar); return false;\" title='Agregar el DNI del trabajador'><img src='../imagenes/dni.gif' border='0'></a>";
	}
// Funciones para ELIMINAR los espacios en blanco
	function ltrim(s) { return s.replace(/^\s+/, ""); }  
	function rtrim(s) { return s.replace(/\s+$/, ""); }  
	function trim(s)  { return rtrim(ltrim(s)); }
	
// Funciones para MOSTRAR y OCULTAR el div con las opciones de la impresion
	function mostrarDiv(ev,div,left,top){
		var px, py, cadena, obj;
		if (!document.all)
		{
			event = ev;
			py = ev.pageY; 
			px = ev.pageX;
		}
		else{
			py = event.clientY + document.body.scrollTop; 
			px = event.clientX + document.body.scrollLeft;
		}
//		alert("X: "+px+", Y: "+py);
//		posX = (screen.width)- px;
		document.getElementById(div).style.left = px + left - (document.getElementById(div).style.width).split("px")[0];
		//document.getElementById(div).style.top = py;
		//document.getElementById(div).style.left = 970;
		document.getElementById(div).style.top = top;
		document.getElementById(div).style.display = "block";
	}
	function ocultarDiv(div){
		document.getElementById(div).style.display = "none";
	}
	function cargarImpresion(url){
		document.location.href = url;
	}