function load_functions()
{
// dummy line	
}


function abrir_url(url){
	window.location = url;
}
function abrirlink(accion,url,random_name){
	switch(accion){
		case "insertar":
			window_insertar = window.open(url,random_name,  "toolbar=no,location=no,directories=no,status=no,menuBar=no,scrollBars=yes,resizable=yes,left=1,top=1,width=796,height=480");
			window_insertar.focus();
		break;
		case "editar":
			window_editar = window.open(url,random_name, "toolbar=no,location=no,directories=no,status=no,menuBar=no,scrollBars=yes,resizable=yes,left=1,top=1,width=796,height=480");
			window_editar.focus();
		break;
		case "borrar":
			var alerta = confirm("¿Desea eliminar este registro?");
				if(alerta){
					window.open(url,random_name, "toolbar=no,location=no,directories=no,status=no,menuBar=no,scrollBars=yes,resizable=yes,left=1,top=1,width=700,height=10");
				}
		break;
		case "recuperar":
			var alerta = confirm("¿Desea recuperar este registro?");
				if(alerta){
					window.open(url,random_name,"toolbar=no,location=no,directories=no,status=no,menuBar=no,scrollBars=yes,resizable=yes,left=1,top=1,width=700,height=10");
				}
		break;
		case "ver":		
			window_ver = window.open(url,random_name,"toolbar=no,location=no,directories=no,status=no,menuBar=yes,scrollBars=yes,resizable=yes,left=1,top=1,width=700,height=480");
			window_ver.focus();
		break;
	}
}
function detalle_grid(campo,codigo,random_name)
{
	window_detalle_grid = window.open("browser_editar.php?tabla="+campo+"&nombre_campo=codigo&codigo="+codigo+"&nombre_seccion=Detalle&no_menu=1", random_name, "toolbar=no,location=no,directories=no,status=no,menuBar=no,scrollBars=yes,resizable=yes,left=1,top=1,width=796,height=480");
	window_detalle_grid.focus();
}


function detalle_grid_view(campo,codigo,rotulo,random_name)
{
	window_detalle_grid_view = window.open("browser_ficha.php?tabla="+campo+"&nombre_campo=codigo&codigo="+codigo+"&nombre_seccion="+rotulo+"&no_menu=1",random_name,"toolbar=no,location=no,directories=no,status=no,menuBar=yes,scrollBars=yes,resizable=yes,left=1,top=1,width=796,height=480");
	window_detalle_grid_view.focus();
}

function open_window(url)
{
    window.location = url;
}


function refresh()
{
	var sURL = unescape(window.location.href);
    window.location.href = sURL;
}

function confirmar_bitacora(){
	var alerta = confirm("¿Guardó ya la Información de toda la Bitácora?");
	if(alerta){
		document.form1.submit();
	}
}
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;
	if (document.form1.repetir_contrasena){
		if(document.form1.repetir_contrasena.value != document.form1.contrasena.value) {
			errors += '- contrasena y repetir contrasena deben ser iguales.\n';
			}
	}
	for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' debe contener un correo electronico valido.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' debe contener un numero.\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+' debe contener un numero entre '+min+' y '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' es requerido.\n'; }
  } if (errors) alert('Los siguientes errores ocurrieron:\n'+errors);
document.MM_returnValue = (errors == '');
return (errors == '');
}
function getIFrameDocument(aID){
		var rv = null;
		// Mozilla
				if (document.getElementById(aID).contentDocument){
					rv = document.getElementById(aID).contentDocument;
				} else {
				// IE
					rv = document.frames[aID].document;
				}
			return rv;
		}
function cargar_marco(nombre_marco,link_marco){
			var marco1 = getIFrameDocument(nombre_marco);
			if(marco1!=null){
				var marco1 = getIFrameDocument(nombre_marco);
				marco1.location=link_marco;
			}
}


 function OnSubmitForm()
{

	if(document.pressed == -1){
		refresh_opener();
	}

if(document.pressed > 0)
  {
abrirlink('editar', 'browser_editar.php?tabla=empleado&nombre_campo=codigo&codigo='+document.pressed+'&nombre_seccion=Empleados&no_menu=1');	
  }
  return true;
}

function calcular_afp(){
	if (document.form1.salario.value == ""){
		document.form1.salario.value = "0.00";
	}	

	if (document.form1.cotizacion_isss.value == ""){
		document.form1.cotizacion_isss.value = "0.00";
	}	
	
	if (document.form1.cotizacion_previsional.value == ""){
		document.form1.cotizacion_previsional.value = "0.00";
	}	
		
	if (document.form1.procuraduria.value == ""){
		document.form1.procuraduria.value = "0.00";
	}	

	if (document.form1.descuentos_judiciales.value == ""){
		document.form1.descuentos_judiciales.value = "0.00";
	}	

	if (document.form1.credito_personal.value == ""){
		document.form1.credito_personal.value = "0.00";
	}	
	if (document.form1.credito_hipotecario.value == ""){
		document.form1.credito_hipotecario.value = "0.00";
	}	
	if (document.form1.otros.value == ""){
		document.form1.otros.value = "0.00";
	}
	var total_deducciones = Math.round((parseFloat(document.form1.cotizacion_isss.value)+parseFloat(document.form1.cotizacion_previsional.value)+parseFloat(document.form1.procuraduria.value)+parseFloat(document.form1.descuentos_judiciales.value)+parseFloat(document.form1.credito_personal.value)+parseFloat(document.form1.credito_hipotecario.value)+parseFloat(document.form1.otros.value))*100)/100;
	document.form1.total_deducciones.value = total_deducciones;
	document.form1.total_liquido.value = Math.round((parseFloat(document.form1.salario.value)-parseFloat(total_deducciones))*100)/100;	
}

function cerrar_bulk(codigo_campo_id,campo_id,codigo,campo_valor){
	 window.opener.document.getElementById(codigo_campo_id).value = codigo; 
	 window.opener.document.getElementById(campo_id).value = campo_valor;
	 window.close();
}

function validar_username(usuario,nombre_campo){
	var marco = document.getElementById('iframeOculto');
		if(marco!=null){
			var marco = getIFrameDocument("iframeOculto");
			marco.location='validar_usuario.php?username='+usuario+'&nombre_campo='+nombre_campo;
		}
	}

var theObj="";
 
function toolTip(text,me) {
       theObj=me;
       theObj.onmousemove=updatePos;
       document.getElementById('toolTipBox').innerHTML=text;
       document.getElementById('toolTipBox').style.display="block";
       window.onscroll=updatePos;
}
function updatePos() {
       var ev=arguments[0]?arguments[0]:event;
       var x=ev.clientX;
       var y=ev.clientY;
       diffX=24;
       diffY=0;
       document.getElementById('toolTipBox').style.top  = y-2+diffY+document.body.scrollTop+ "px";
       document.getElementById('toolTipBox').style.left = x-2+diffX+document.body.scrollLeft+"px";
       theObj.onmouseout=hideMe;
}
 
function hideMe() {
       document.getElementById('toolTipBox').style.display="none";
}