var xmlHttp
var baseporc
var idelem
var t
var k=0
var vacio = false 
var vcampo="" 
var vevento=""
 

function isIE(){
  var nombre = navigator.appName
  
  if (nombre == "Microsoft Internet Explorer"){
      return true;
  }else{
      return false;
  }

}
function GetXmlHttpObject()
{
  var xmlHttp=null;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    }
  return xmlHttp;
}
//************** AUTOCOMPLETAR ********************************************************************************

function asignaVariables()
{
	// Funcion que asigna variables que se usan a lo largo de las funciones	
	v=1; nuevaBusqueda=1; busqueda=null; ultimaBusquedaNula=null;
	divLista=document.getElementById("lista");
//	inputLista=document.getElementById("input_2");
	inputLista=document.getElementById("empresa");
	elementoSeleccionado=0;
	ultimoIdentificador=0;
	
	var IE  = document.all != null;  //ie4 and above
	var IE5 = document.getElementById && document.all;
	var IE6 = document.getElementById && document.all&&(navigator.appVersion.indexOf("MSIE 6.")>=0);
//	document.captureEvents(Event.KEYDOWN, Event.MOUSEOUT);
    if (!IE && !IE5 &&!IE6 ){
		 
	   document.captureEvents(Event.MOUSEDOWN);
    }
    document.onmousedown = function (evt) {
		   k=0
	   return true;
    }
}
//********************************************************************************
function nuevoAjax()
{ 
	/* Crea el objeto AJAX. Esta funcion es generica para cualquier utilidad de este tipo, por
	lo que se puede copiar tal como esta aqui */
	var xmlhttp=false; 
	try 
	{ 
		// Creacion del objeto AJAX para navegadores no IE
		xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); 
	}
	catch(e)
	{ 
		try
		{ 
			// Creacion del objet AJAX para IE 
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
		} 
		catch(E) { xmlhttp=false; }
	}
	if (!xmlhttp && typeof XMLHttpRequest!="undefined") { xmlhttp=new XMLHttpRequest(); } 

	return xmlhttp; 
}
//********************************************************************************
function eliminaEspacios(cadena)
{
	var x=0, y=cadena.length-1;
	while(cadena.charAt(x)==" ") x++;	
	while(cadena.charAt(y)==" ") y--;	
	return cadena.substr(x, y-x+1);
}
//********************************************************************************
function nuevoDato()
{
	/* Funcion encargada del input de la izquierda. No interfiere para nada en la funcionalidad de
	la lista desplegable */
	var divMensaje=document.getElementById("error");
	var inputIngreso=document.getElementById("input_1");
	var boton=document.getElementById("boton_1");
	var valor=inputIngreso.value;

	// Reinicio las variables del input 2
	inputLista.value=""; nuevaBusqueda=1; busqueda=null; ultimaBusquedaNula=null;

	// Limpio posibles mensajes que haya en el div
	divMensaje.innerHTML="";

	// Saco los espacios en blanco al comienzo y al final de la cadena
	valor=eliminaEspacios(valor);
	
	// Valido con una expresion regular el contenido de lo que el usuario ingresa
	var reg=/(^[a-zA-Z0-9.@ ]{4,40}$)/;
	if(!reg.test(valor)) 
	{
		divMensaje.innerHTML="El texto ingresado contiene caracteres o longitud inválida";
	}
	else
	{
		// Deshabilito el boton y el input para evitar dobles ingresos
		boton.disabled=true; inputIngreso.disabled=true; inputLista.disabled=true;
		inputIngreso.value="Ingresando...";
	
		var ajax=nuevoAjax();
		ajax.open("POST", "index_proceso.php", true);
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send("ingreso="+valor);
			
		ajax.onreadystatechange=function()
		{
			if (ajax.readyState==4)
			{
				// Borro el contenido del input
				inputIngreso.value="";
				// Habilito campos y boton nuevamente
				boton.disabled=false; inputIngreso.disabled=false; inputLista.disabled=false;
				divMensaje.innerHTML=ajax.responseText;
			}
		}
	}
}
//********************************************************************************
function formateaLista(valor)
{
	// Funcion encargada de ir colocando en negrita las palabras y asignarle un ID a los elementos
	var x=0, verificaExpresion=new RegExp("^("+valor+")", "i");
	
	while(divLista.childNodes[x]!=null)
	{
		// Asigo el ID para reconocerlo cuando se navega con el teclado
		divLista.childNodes[x].id=x+1;
		// Coloco en cada elemento de la lista en negrita lo que se haya ingresado en el input
		divLista.childNodes[x].innerHTML=divLista.childNodes[x].innerHTML.replace(verificaExpresion, "<b>$1</b>");
		x++;
	}
}
//********************************************************************************
function limpiaPalabra(palabra)
{
	// Funcion encargada de sacarle el codigo HTML de la negrita a las palabras
	palabra=palabra.replace(/<b>/i, "");
	palabra=palabra.replace(/<\/b>/i, "");
	return palabra;
}
//********************************************************************************
function coincideBusqueda(palabraEntera, primerasLetras)
{
	/* Funcion para verificar que las primeras letras de busquedaActual sean iguales al
	contenido de busquedaAnterior. Se devuelve 1 si la verificacion es afirmativa */
	if(primerasLetras==null) return 0;
	var verificaExpresion=new RegExp("^("+primerasLetras+")", "i");
	if(verificaExpresion.test(palabraEntera)) return 1;
	else return 0;
}
//********************************************************************************
function nuevaCadenaNula(valor)
{
	/* Seteo cual fue la ultima busqueda que no arrojo resultados siempre y cuando la cadena
	nueva no comience con las letras de la ultima cadena que no arrojo resultados */
	if(coincideBusqueda(valor, ultimaBusquedaNula)==0) ultimaBusquedaNula=valor;
}
//********************************************************************************
function busquedaEnBD()
{
	/* Funcion encargada de verificar si hay que buscar el nuevo valor ingresado en la base
	de datos en funcion de los resultados obtenidos en la ultima busqueda y en base a que
	la cadena bsucada anteriormente este dentro de la nueva cadena */
	var valor=inputLista.value;
	
	if((coincideBusqueda(valor, busqueda)==1 && nuevaBusqueda==0) || coincideBusqueda(valor, ultimaBusquedaNula)==1) return 0;
	else return 1;
}
//********************************************************************************
function filtraLista(valor)
{
	// Funcion encargada de modificar la lista de nombres en base a la nueva busqueda
	var x=0;

	while(divLista.childNodes[x]!=null)
	{
		// Saco la negrita a los elementos del listado
		divLista.childNodes[x].innerHTML=limpiaPalabra(divLista.childNodes[x].innerHTML);
		if(coincideBusqueda(limpiaPalabra(divLista.childNodes[x].innerHTML), valor)==0)
		{
			/* Si remuevo el elemento x, el elemento posterior pasa a ocupar la posicion de
			x, entonces quedaria sin revisar. Por eso disminuyo 1 valor a x */
			divLista.removeChild(divLista.childNodes[x]);
			x--;
		}
		x++;
	}
}
//********************************************************************************
function reiniciaSeleccion()
{
	mouseFuera(); 
	elementoSeleccionado=0;
}
//********************************************************************************
function navegaTeclado(evento)
{
	var teclaPresionada=(document.all) ? evento.keyCode : evento.which;
	
	switch(teclaPresionada)
	{
		case 40:
		if(elementoSeleccionado<divLista.childNodes.length)
		{
			mouseDentro(document.getElementById(parseInt(elementoSeleccionado)+1));
		}
		return 0;
		
		case 38:
		if(elementoSeleccionado>1)
		{
			mouseDentro(document.getElementById(parseInt(elementoSeleccionado)-1));
		}
		return 0;
		
		case 13:
		if(divLista.style.display=="block" && elementoSeleccionado!=0)
		{
			clickLista(document.getElementById(elementoSeleccionado))
		}
		return 0;
		
		default: return 1;
	}
}	
//********************************************************************************
function rellenaLista()
{
	var valor=inputLista.value;

	// Valido con una expresion regular el contenido de lo que el usuario ingresa
	var reg=/(^[a-zA-Z0-9.@ ]{2,40}$)/;
	if(!reg.test(valor)) divLista.style.display="none";
	else
	{
		if(busquedaEnBD()==0)
		{	
			// Si no hay que buscar el valor en la BD
			busqueda=valor;
	
			// Hago el filtrado de la nueva cadena ingresada
			filtraLista(valor);
			// Si no quedan elementos para mostrar en la lista
			if(divLista.childNodes[0]==null) { divLista.style.display="none"; nuevaCadenaNula(valor); }
			else { reiniciaSeleccion(); formateaLista(valor); }
		}
		else
		{	
			/* Si se necesita verificar la base de datos, guardo el patron de busqueda con el que se
			busco y luego recibo en una variable si existen mas resultados de los que se van a mostrar */
			busqueda=valor;

			var ajax=nuevoAjax();
			ajax.open("POST", "index_proceso.php?", true);
			ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			ajax.send("busqueda="+valor);
		
			ajax.onreadystatechange=function()
			{	
				if (ajax.readyState==4)
				{
					if(!ajax.responseText) { divLista.style.display="none"; }
					else 
					{
						var respuesta=new Array(2);
						respuesta=ajax.responseText.split("&");
				
						/* Obtengo un valor que representa si tengo que ir a BD en las proximas 
						busquedas con cadena similar */
						nuevaBusqueda=respuesta[0];
				
						// Si se obtuvieron datos los muestro
						if(respuesta[1]!="vacio") 
						{ 
							divLista.style.display="block"; divLista.innerHTML=respuesta[1]; 
							// Coloco en negrita las palabras
							reiniciaSeleccion();
							formateaLista(valor); 
						}
						// En caso contrario seteo la busqueda actual como una busqueda sin resultados
						else nuevaCadenaNula(valor);
					}
				}
			}
		}
	}
}

function clickLista(elemento)

{
	/* Se ejecuta cuando se hace clic en algun elemento de la lista. Se coloca en el input el
	valor del elemento clickeado */
	v=1;
	valor=limpiaPalabra(elemento.innerHTML); 
	busqueda=valor; inputLista.value=valor;
	empresasdatos(valor);
	divLista.style.display="none"; elemento.className="normal";
}


function mouseFuera()
{
	// Des-selecciono el elemento actualmente seleccionado, si es que hay alguno
	if(elementoSeleccionado!=0 && document.getElementById(elementoSeleccionado)) document.getElementById(elementoSeleccionado).className="normal"; 
}

function mouseDentro(elemento)
{
	mouseFuera();
	elemento.className="resaltado";
	// Establezco el nuevo elemento seleccionado
	elementoSeleccionado=elemento.id;
}


//*************** TABULADOR  ***************************************************************************************

function next(pobjeto){
// alert("HOLA")
// alert(pobjeto.form[(objindex(pobjeto)+1)].id)

 document.getElementById(pobjeto.form[(objindex(pobjeto)+1)].id).select()
// document.getElementById(pobjeto.form[(objindex(pobjeto)+1)].id).select()
 return false;
}


//***********************

function objindex(input) {
   // alert(input)
	
    var index = -1;
	var i = 0;
	var found = false;

	while (i < input.form.length && index == -1){
    if (input.form[i].id == input.id){
	      index = i;	   
       }else{
	      i++;
	   }	  
  
    }
	// alert(index)
return index;

}

//*****************************************

function esTeclaNumerica(tecla,dec){
	
	if(tecla > 7 && tecla < 10 	|| tecla > 44 && tecla < 60 || tecla > 95 && tecla < 106 || tecla == 17 || tecla == 13 || tecla > 34 && tecla < 38 || tecla == 39 || tecla == 116 || tecla == 110 || tecla == 188 || tecla == 0){
	
	    // delete (8) o tabulador (9),números del teclado(47-60),números del teclado numérico(95-106),Ctrl(17),F5 (116)
		 
		return true
	}else{
		 
		 
		return false
	} 
	
}

//*************** APORTES  ***************************************************************************************

function botonesboletas(bot,par1)
{ 
var botvalido
botvalido=false
switch(bot)
 {
    case "continua00": 
      window.location='boleta00.php'
	  break; 
   case "continua01": 
   
	  var vcuit = document.getElementById("cuit").value ;
	  vcuit = vcuit.replace(/^\s*|\s*$/g,"");
    
	  if (vcuit == ""){
		  alert("Debe ingresar un núnmero de CUIT");
		  document.getElementById("cuit").select();
		  return false;
	  }else{ 
	      var vnombre = document.getElementById("empresa").value ;
    	  vnombre = vnombre.replace(/^\s*|\s*$/g,"");
	      if (vnombre == ""){
		     alert("Debe ingresar un Nombre");
		     document.getElementById("empresa").select();
		     return false;
	      }else{
			   var vrazonsocial = document.getElementById("razonsocial").value ;
    	       vrazonsocial = vrazonsocial.replace(/^\s*|\s*$/g,"");
     	       if (vrazonsocial == ""){
		         alert("Debe ingresar una Razón Social");
		         document.getElementById("razonsocial").select();
		         return false;
	           }else{   
					var vcalle = document.getElementById("calle").value ;
    	            vcalle = vcalle.replace(/^\s*|\s*$/g,"");
        	        if (vcalle == ""){
		               alert("Debe ingresar una Calle");
		               document.getElementById("calle").select();
		               return false;
	                }else{
	                   var vnro = document.getElementById("nro").value ;
    	               vnro = vnro.replace(/^\s*|\s*$/g,"");
        	           if (vnro == ""){
		                  alert("Debe ingresar una Número");
		                  document.getElementById("nro").select();
		                  return false;
	                   }else{
	                      var vlocalidad = document.getElementById("localidad").value ;
    	                  vlocalidad = vlocalidad.replace(/^\s*|\s*$/g,"");
        	              if (vlocalidad == ""){
		                    alert("Debe ingresar una Localidad");
		                    document.getElementById("localidad").select();
		                    return false;
	                      }else{
	                         var vprovincia = document.getElementById("provincia").value ;
    	                      vprovincia = vprovincia.replace(/^\s*|\s*$/g,"");
        	                  if (vprovincia == ""){
		                         alert("Debe ingresar una Provincia");
		                         document.getElementById("provincia").select();
		                         return false;
	                          }else{
	                              botvalido=true
		                      }
		                  }
			           }
		            }
	          }
		  }
	      
	  }
      
	  if (botvalido){window.location='boleta01.php'}
	  
   //  window.open("aportesempleados.php","empleados","width=880,height=600,top=10,left=50,menubar=no,scrollbars=NO") 
     break; 
   case "continua02":
      
	  var vconvenio = document.getElementById("convenio").value ;
	  vconvenio = vconvenio.replace(/^\s*|\s*$/g,"");
    
	  if (vconvenio == ""){
	  //1
		  alert("Debe ingresar un CONVENIO");
		  document.getElementById("convenio").select();
		  return false;
	  }else{ 
	  //1
	      var vmes = document.getElementById("permes").value ;
    	  vmes = vmes.replace(/^\s*|\s*$/g,"");
	      if (vmes == ""){
		  //2
		     alert("Debe ingresar un MES");
		     document.getElementById("permes").select();
		     return false;
	      }else{
		  //2
			   var vanio = document.getElementById("peranio").value ;
    	       vanio = vanio.replace(/^\s*|\s*$/g,"");
     	       if (vanio == ""){
			   //3
		         alert("Debe ingresar un AÑO");
		         document.getElementById("peranio").select();
		         return false;
	           }else{   
			   //3
			        tafi = document.getElementById("totafiliados").value *1 ;
					tnafi = document.getElementById("totnoafiliados").value *1 ;
					
					grabavar('totnoafiliados',tnafi) 
					grabavar('totafiliados',tafi) 
					
					var vafi = document.getElementById("totnoafiliados").value + document.getElementById("totafiliados").value ;
					var vnafi = document.getElementById("totnoafiliados").value *1 + document.getElementById("totafiliados").value*1 ;
                    vafi = vafi.replace(/^\s*|\s*$/g,"");
        	        if (vafi == "" || !vnafi > 0){
					//11
		               alert("Debe ingresar cantidad de EMPLEADOS");
		               document.getElementById("totnoafiliados").select();
		               return false;
	                }else{
					//11
					     
					      if ((document.getElementById("remnoafiliados").value *1)>0){
						  //12
					           vnafi = document.getElementById("totnoafiliados").value *1 ;
                               vafi = vafi.replace(/^\s*|\s*$/g,"");
        	                   if (vafi == "" || !vnafi > 0){
							   //13
		                          alert("Debe ingresar cantidad de EMPLEADOS NO AFILIADOS");
		                          document.getElementById("totnoafiliados").select();
		                          return false;
	                           }//13
					       }else{
						   //12
					            if ((document.getElementById("remafiliados").value *1)>0){
								//14
					                vnafi = document.getElementById("totafiliados").value *1 ;
                                    vafi = vafi.replace(/^\s*|\s*$/g,"");
        	                         if (vafi == "" || !vnafi > 0){
									 //15
   		                                alert("Debe ingresar cantidad de EMPLEADOS AFILIADOS");
		                                document.getElementById("totafiliados").select();
		                                return false;
	                                 }//15
						        }//14
					      }//12
					
					
					   	   rafi = document.getElementById("remafiliados").value *1 ;
  					       rnafi = document.getElementById("remnoafiliados").value *1 ;
  					       grabavar('remafiliados',dosdecimales(rafi)) 
					       grabavar('remnoafiliados',dosdecimales(rnafi)) 
					
				           var vremu = document.getElementById("remnoafiliados").value + document.getElementById("remafiliados").value ;
				           var vnremu = document.getElementById("remnoafiliados").value*1+document.getElementById("remafiliados").value*1 ;
    	                   vremu = vremu.replace(/^\s*|\s*$/g,"");
        	               
						    if (vremu == "" || !vnremu >0){
					        //4
		                       alert("Debe ingresar REMUNERACION");
		                       document.getElementById("remnoafiliados").select();
		                       return false;
	                        }else{
					         //4
	            
				                if ((document.getElementById("totnoafiliados").value *1)>0){
						        //21
					               vnremu = document.getElementById("remnoafiliados").value *1 ;
                                   
        	                       if (vnremu == "" || !vnremu > 0){
							      //22
		                              alert("Debe ingresar cantidad de REMUNERACION NO AFILIADOS");
		                              document.getElementById("remnoafiliados").select();
		                              return false;
	                               }//22
					             }
						         //21
					             if ((document.getElementById("totafiliados").value *1)>0){
								    //23
					                   vnremu = document.getElementById("remafiliados").value *1 ;
                                        if (vnremu == "" || !vnremu > 0){
									    //24
   		                                   alert("Debe ingresar cantidad de REMUNERACION AFILIADOS");
		                                   document.getElementById("remafiliados").select();
		                                   return false;
	                                    }//24
								  }//23
                                  
			
				          if(document.getElementById("convenio").value==1){
						  //5
						     var vapor = document.getElementById("cuotabajatemp").value*1+ document.getElementById("aposolnoafi").value*1+document.getElementById("segsepelio").value *1+document.getElementById("fondoconvord").value *1+document.getElementById("otras1").value *1;
    	                  }else{
						  //5
						     var vapor = document.getElementById("apotrabajador").value*1+document.getElementById("fondoturismo").value*1+document.getElementById("contconven").value*1+document.getElementById("capaprof").value*1+document.getElementById("otras1").value*1+document.getElementById("otras2").value*1;
						  }
						  //5
						 
        	              if (vapor == "" || !vapor >0){
						  //6
		                    alert("Debe ingresar APORTES Y CONTRIBUCIONES");
							if(document.getElementById("convenio").value==1){
							//7
		                         document.getElementById("cuotabajatemp").select();
							}else{
							//7
							     document.getElementById("apotrabajador").select();
							}
							//7	 
		                    return false;
	                      }else{
						  //6
	                         var vtotapo = ((document.getElementById("totaportes").value)*1) ;
    	                    //  vtotapo = vtotapo.replace(/^\s*|\s*$/g,"");
        	                  if (vtotapo == "" || !vtotapo >0){
							  //8
		                         alert("Debe ingresar TOTAL DE APORTES");
		                         document.getElementById("totaportes").select();
		                         return false;
	                          }else{
							  //8
	                              botvalido=true
		                      
		                      }//8		     

			              }//6
						 
		               } //4
					}//11   
		      } //3 
		  }//2    
	  }//1   
	  if (botvalido){window.location='boleta02.php'}

     break; 
	 
 
   case "continua03":	
      
    
	  for (ele = 1; ele < par1; ele++) {
         
		var  ncui=  "emplecuil"+ele;
		var  vcui = document.getElementById(ncui).value;
		var  nnom=  "emplenombre"+ele;
		var  vnom = document.getElementById(nnom).value;
		var  nrem=  "empleremu"+ele;
		var  vrem = document.getElementById(nrem).value;
        
		var campo = vcui+vnom+vrem
		campo = campo.replace(/^\s*|\s*$/g,"");
        	               
		if (campo !== "" ){
		// alert(campo)
	       vcui = vcui.replace(/^\s*|\s*$/g,"");
           if (vcui == ""){
		       alert("Debe ingresar un núnmero de CUIL del empleado Nº: "+ele );
		       document.getElementById(ncui).select();
		       return false;
	       }else{ 
		   
		       vnom = vnom.replace(/^\s*|\s*$/g,"");
               if (vnom == ""){
		          alert("Debe ingresar el NOMBRE del empleado Nº: "+ele );
		          document.getElementById(nnom).select();
		          return false;
	           }else{ 
	 	          vrem = vrem.replace(/^\s*|\s*$/g,"");
                  if (vrem == ""){
		             alert("Debe ingresar la REMUNERACION del empleado Nº: "+ele );
		             document.getElementById(nrem).select();
		             return false;
	              }else{ 
	                 botvalido=true
			      }
	
			   }
		   }
		}
		
	  
	  }
	
	
	
	 // if (botvalido){window.location='grabadatos.php'}
//	  window.location='grabadatos.php'
	  
	  
/*	  var opciones = "fullscreen=0" + 
                 ",toolbar= 0" +
                 ",location=0"+ 
                 ",status=0" +
                 ",menubar=0"+
                 ",scrollbars=1"+ 
                 ",resizable=1"+ 
                 ",width=700" +
                 ",height=800"+ 
                 ",left=10"  + 
                 ",top=20" ; */
				 
		  var opciones = "fullscreen=1" + 
                 ",toolbar= 0" +
                 ",location=0"+ 
                 ",status=0" +
                 ",menubar=0"+
                 ",scrollbars=1"+ 
                 ",resizable=0"+ 
                 ",width=0" +
                 ",height=0"+ 
                 ",left=0"  + 
                 ",top=0" ; 		 
				 
				 sustituir="1"
      var ventana = window.open('preview.php',"venta",opciones,sustituir); 
	  break; 

  case "continua04":	
     //  var ventana = window.open('grabadatos.php',"venta",opciones,sustituir); 
	   window.location='previewtut.php'
   	   break; 	
	   
  case "continua05":	
     //  var ventana = window.open('grabadatos.php',"venta",opciones,sustituir); 
	   window.location='grabadatos.php'
   	   break; 
	   
  case "sal": 
      
      window.close()
     break; 
  default:
	 
 }
}
//********************************************************************************
function borraempleado(ele)
{ 
   	    var  ncui=  "emplecuil"+ele;
		var  nnom=  "emplenombre"+ele;
		var  nrem=  "empleremu"+ele;
		var  nalt=  "emplealta"+ele;
		
		document.getElementById(ncui).value = ""
		document.getElementById(nnom).value = ""
		document.getElementById(nrem).value = ""
		document.getElementById(nalt).value = ""
		
		grabavar(ncui,'')
  	    grabavar(nnom,'')
		grabavar(nrem,'')
		grabavar(nalt,'')
	
}
//********************************************************************************
function verificames(val)
{ 
/* 
 //var mesnum= val*1
 if (isNaN(val)) {  
    
	if (val.toUpperCase() =="S1" || val.toUpperCase() =="S2" )
	{
	     val=val.toUpperCase() ;
		 document.getElementById("permes").value = val
     	 grabavar("permes",val)
  	     return true;
	}
	else
	{
     alert("inserta un numero"); 
	 
	 document.getElementById("permes").select()
	 return false;
	}
 }else
 { 
*/
    if (parseInt(val*1) > 0 && parseInt(val*1)< 13)
	{
	     val=strzero(2, val) ;
		 document.getElementById("permes").value = val
     	 grabavar("permes",val)
	      return true;
    }
	else
	{
 	 alert("Número no válido como mes"); 
	 
 	 //document.getElementById("permes").select()
 	 return false;
	}
	
//}
}

//********************************************************************************
function verificaanio(val)
{ 
 
 
 if (isNaN(val)) {  
    
     alert("inserta un numero"); 
	 
	 document.getElementById("peranio").select()
	 return false;
 }else
 { 
    //num.toString().length < 
	
    if(val.length > 4)
	{
	  alert("Número demasiado largo"); 
	  document.getElementById("peranio").select()
	  return false;
	}
	else
	{
	   if(val.length < 4)
	   {
	    val= "2"+strzero(3, val*1) ;
		document.getElementById("peranio").value=val;
       }
	} 
	//var fecha = new Date();
	//var anio= fecha.getYear() 
  
//    if (parseInt(anio*1) > anio-10 && parseInt(val*1)< anio +10)
	  if (parseInt(val*1) > 2000 && parseInt(val*1)< 3000)
	{
	
     	 grabavar("peranio",val)
		 return true;
	}
	else
	{
 	 alert("Número no válido como año"); 
	 
 	 document.getElementById("peranio").select()
 	 return false;
	}
	
}
}


//********************************************************************************
function valida(que,tipo,largo,dec,pevento,pobjeto,pvalor,enblanco){
//function valida(que,tipo,largo,dec,pevento,pobjeto,pvalor){


     t=pobjeto
   // alert(t.id)
	//var k;
	k=0
	var esvalida = false 
	vcampo = que
	
	if (typeof enblanco == "undefined"){
       enblanco=false;
	}
	
	if(que.substring(0,9)=="granoporc"){
	   que2=que
   	   que="granoporc"
	}
	 
	if ("which" in pevento){k=pevento.which} 
	else if("keyCode" in pevento){k=pevento.keyCode}
    else if("keyCode" in window.event){k=window.event.keyCode }
    else if ("which" in window.event){k=pevento.which}
    else{
	  	return true
	}
	 
	
  //  alert(k)
  
    
  
  
    switch(tipo.toUpperCase()){
       case "N":
	     if (!esTeclaNumerica(k)){  
   	         alert("Solo se pueden ingresar numeros.");
		     var valorant=t.value
		     if(valorant.length <=largo){
				if (!isIE()){t.value=valorant.substring(0,valorant.length-1)};
			 }
			 esvalida = false 
	      }else{   
	         switch(k){
				case 9:
				case 8:
				case 13:
				case 35:
				case 36:
				case 37:
				case 39:
				case 45:
				case 46:
				 	esvalida = true 
				    break;
			    case 110:
				    if(dec.toUpperCase()=="S") {    
					    
						comapunto = t.value
						for(i=0;i<comapunto.length;i++)
                        {
                           if(comapunto.charAt(i)==".")
						   {
						       haypunto=true
					       }
                        }
						
				    	if (haypunto) {
  						    esvalida = false 	
						}else{
 					        esvalida = true
					    }
					}else{
					
					alert("No se pueden ingresar decimales.");
    		            var valorant=t.value
  		            	if(t.value.length+1 <= largo){
				   	   	       if (!isIE()){t.value=valorant.substring(0,valorant.length-1)};
						    }
						    esvalida = false 
					}
	  			    break;
					
				case 188:
				     comapunto = t.value
					 //alert(comapunto)
				    // t.value=comapunto.replace(",","."); 
					
					haypunto=false
					
					for(i=0;i<comapunto.length;i++)
                    {
                       if(comapunto.charAt(i)=="."){
						    haypunto=true
					   }
                    }
					if (!haypunto) {
						t.value=comapunto + "."; 
					}
					 
				 	esvalida = false 
				    break;
	            default: 
				    if( t.value.length+1 <= largo){
			            esvalida = true 
					}else{
				 	    esvalida = false
				    }
					break;	
             }
          }
 	      break; 
      
	   case "F":
	     
		 
       if (k==111 || k==109 ){
           esvalida = false 
		   t.value=t.value + "/";
	   }else{
		      if( t.value.length+1 <= largo){
			    switch(t.value.length)
			    {
			     case 2:
			      t.value=t.value + "/";
				
//				  document.getElementById("convdescr").value=t.value;
				  
				  
			      break; 
			     case 5:
 			      t.value=t.value + "/";
			      break; 	
			    }
			    esvalida = true 
		   
		      }else{
			    esvalida = false 
	          }
		   
		}
	    break;
	   
	   default: 
	     
		
		 
		 
          if( t.value.length+1 <= largo){
			  
		 /*   if (k==219){
              t.value=t.value + "´";
			  esvalida = false 
	        }else{*/
			  esvalida = true	
			//}
		  }else{
			 esvalida = false 
	      }
	      break;
    } 

/*	if (k == 9 || k == 13 || k == 0 ) {
	   esvalida = true 
	  //  esvalida= postvalida(que)
	
     }
*/
	
  
  if (k == 9 || k == 13 || k == 0 ) {
	    
		vacio=enblanco
		 
	     if(trim(t.value)=="" && !vacio){
			  esvalida = false 
         }else{
		      esvalida = true 
		}
		 	
  }
  return esvalida
}

//********************************************************************************

function definet(pobjeto){
// t=pobjeto
//alert(t.value)
}
//********************************************************************************

function postvalida(quenulo){

	var esvalida = false 
	var tabula = false 
	
	que = vcampo
 
    vvalor= t.value
   
	
	
	if(que.substring(0,9)=="emplecuil"){
	   que2=que
   	   que="emplecuil"
	}
	 
	switch(que.toUpperCase()){
		    case "CUIT":
			 
		      vcuit= t.value
              if(!validacuit(vcuit)){
                setTimeout("t.select()",3)
			    tabula=false
              }else{
                tabula=true
              }
			  break;
			 
			 case "FECHA":
		      vfecha= t.value
			  if(!fechavalid(t)){
				
				alert("Esa fecha no es válida. Por favor, pruebe de nuevo. (FORMATO: 'dd/mm/aaaa')");
                setTimeout("t.select()",3)
                 tabula= false
              }else{
                  tabula=true
              }
			 break;
			 
			 
			  case "CONVENIO":
		          vconv= t.value
				 
	  		      switch(vconv){
                     case '1': 
					   conveniodatos(vconv)
 					   tabula=true
                       document.getElementById("convdescr").value="Otros convenios";
					    
					  
					   break;
					 case '4':
 					   conveniodatos(vconv)
 					    tabula=true
  				       document.getElementById("convdescr").value="Pinamar";
                        
					   
					   break;
			         default:  
 					    alert("1- Otros Convenios o 4- Convenio Pinamar")
						document.getElementById("convdescr").value="No Valido";
				        t.value="";
						setTimeout("t.select()",3)
			             tabula=false
                       break;
				  }
			      break;
			  
			 case "PERMES":
		          vmes= t.value;
				 //alert(vmes)
	  		      if(verificames(vmes)){
 				        tabula=true
					  // document.getElementById(pobjeto.form[(objindex(pobjeto)+1)].id).select()
					   
				  }else{
			         //   t.value="";
						setTimeout("t.select()",3)
			             tabula= false
			      }
  				
	  		      break;  
			 
			 case "PERANIO":
		          vanio= t.value;
				 
	  		      if(verificaanio(vanio)){
 				        tabula=true
					 //  alert(pobjeto.id)
                	    
				  }else{
			        //   t.value="";
					   setTimeout("t.select()",3)
			            tabula=false
			      }
 				
			      break;  
			 
			 case "NOAFIL":
		          vnoafil= t.value;
			      grabavar('totnoafiliados',vnoafil)
    	          tabula=true
                   
					 		
			      break 
			 
			 case "REMNOAFILIADOS":
		       
			      calculaaporteauto()
				   tabula=true
				  t.value=dosdecimales(t.value)
                 
								
			       break;  
			 case "TOTAFILIADOS":
		          vnoafil= t.value;
			      grabavar('totafiliados',vnoafil)
    	           tabula=true
                  
								
			      break 
			
			 case "REMAFILIADOS":
		       
			      calculaaporteauto()
				  tabula=true
				  t.value=dosdecimales(t.value)
                   
								
			       break;   
				    
			  case "APOTRABAJADOR":
			  case "FONDOTURISMO":
			  case "CONTCONVEN":
			  case "CAPAPROF":
  			  case "OTRAS1":
  			  case "OTRAS2":
			 
				  apoval = document.getElementById(que).value=dosdecimales(t.value);
 
				  if(que=="otras1"){
				      calculatotalaporte(que,apoval,document.getElementById("convenio").value)
				  }else{
 				      calculatotalaporte(que,apoval,4)
				  }	  
				  
				   tabula=true
                   
								
			       break;  
			  
			  case "CUOTABAJATEMP":
			  case "APOSOLNOAFI":
			  case "SEGSEPELIO":
			  case "FONDOCONVORD":
  			      
				 // alert(t.value)
				  apoval = document.getElementById(que).value=dosdecimales(t.value);
				 
				  calculatotalaporte(que,apoval,1)
				   tabula=true
                  
								
			       break;    	  
  		  
		      case "EMPLECUIL":
		          vcuit= t.value
                  if(!validacuit(vcuit)){
				    setTimeout("t.select()",3)
			         tabula= false 
                  }else{
 				    grabavar(que2,vcuit)
                   
			         tabula=true
                  } 			
			      break 	  			  
		      default: 	
			      break;
		  
     }

  if (k == 0 ) {tabula=false}
 
	      if(tabula){
		   
              if (!isIE()){
				 
				 setTimeout("document.getElementById(t.form[(objindex(t)+1)].id).select()",3)
              }else{
				 document.getElementById(t.form[(objindex(t)+1)].id).select()
			  }
			 
		 	//}	 
		  }
    
  
  return esvalida
}
 


//******** VALIDA trim *****************************************************************************************

function ltrim(texto) {  return texto.replace(/^(\s|\&nbsp;)+/, "");}
function rtrim(texto) {  return texto.replace(/(\s|\&nbsp;)+$/, "");}
function trim(texto) {  return rtrim(ltrim(texto));}

//******** VALIDA NUMEROS *****************************************************************************************


function verifnum(nomvar,nro)
{
	// alert(nomvar);
 if (isNaN(nro)) {   
     return false;
 }else{ 
   grabavar(nomvar,nro)
	return true;
  
 } 
}

//********************************************************************************

function verifremuneracion(apo,val)
{ 
 elemento = apo
 
  if (isNaN(val)) {  
    
     alert("inserta un numero"); 
	 
	 document.getElementById(elemento).select()
	 return false;
 }else{ 
    
	 
    calculaaporteauto()
 }
}

//********************************************************************************
function calculaaporteauto()
{ 
 var con= document.getElementById("convenio").value*1
 var remnoafi = document.getElementById("remnoafiliados").value *1
 var remafi = document.getElementById("remafiliados").value *1
 var totremu = remnoafi + remafi
 


 grabavar("totremunera",totremu)

 if (con==4){  
	 var apo1 = document.getElementById("apotrabajador").value = dosdecimales(remafi * 0.03) 
     var apo2 = document.getElementById("fondoturismo").value  = dosdecimales(totremu * 0.02) 	
	 var apo3 = document.getElementById("contconven").value  = dosdecimales(totremu * 0.03) 	
	 var apo4 = document.getElementById("capaprof").value = dosdecimales(totremu * 0.02) 	
	 var apo5 = dosdecimales(document.getElementById("otras1").value *1) 		
	 var apo6 = dosdecimales(document.getElementById("otras2").value *1) 

     
	 grabavar("cuotabajatemp",0.00)
	 grabavar("aposolnoafi",0.00)
	 grabavar("segsepelio",0.00)
	 grabavar("fondoconvord",0.00)
	 grabavar("otras1",0.00)
	 grabavar("apotrabajador",apo1)
	 grabavar("fondoturismo",apo2)
	 grabavar("contconven",apo3)
	 grabavar("capaprof",apo4)
	 grabavar("otras1",apo5)
	 grabavar("otras2",apo6)
	 
 }else{
     var apo1 = 0
	 var apo2 = document.getElementById("cuotabajatemp").value = dosdecimales(remafi * 0.03) 
	 var apo3 = document.getElementById("aposolnoafi").value = dosdecimales(remnoafi * 0.02) 
	 var apo4 = document.getElementById("segsepelio").value = dosdecimales(totremu * 0.015) 
	 var apo5 = document.getElementById("fondoconvord").value  = dosdecimales(totremu * 0.02) 		
	 var apo6 = dosdecimales(document.getElementById("otras1").value *1)  
	 
	 
	 grabavar("apotrabajador",0.00)
	 grabavar("fondoturismo",0.00)
	 grabavar("contconven",0.00)
	 grabavar("capaprof",0.00)
	 grabavar("otras1",0.00)
	 grabavar("otras2",0.00)
	 grabavar("cuotabajatemp",apo2)
	 grabavar("aposolnoafi",apo3)
	 grabavar("segsepelio",apo4)
	 grabavar("fondoconvord",apo5)
	 grabavar("otras1",apo6)
	 
	 	 
 }	  
	 var aportot=parseFloat(apo1) + parseFloat(apo2) + parseFloat(apo3) + parseFloat(apo4) + parseFloat(apo5) + parseFloat(apo6)
	 
     document.getElementById("totaportes").value = dosdecimales(aportot)
	 
	 grabavar("remnoafiliados",dosdecimales(remnoafi))
	 grabavar("remafiliados",dosdecimales(remafi))
	 grabavar("totaportes",dosdecimales(aportot))
    
 
}

//**********************************
function calculatotalaporte(apo,val,con)
{ 
   //alert(val)
 elemento = apo;
 
 
 if (isNaN(val)) {  
    
     alert("inserta un numero"); 
	 
	 document.getElementById(elemento).select()
	 return false;
 }else{ 

 var varapo 
 var apotot = document.getElementById("totaportes").value
   
 if (con==4){  
	 var apo1 = dosdecimales(document.getElementById("apotrabajador").value *1)
     var apo2 = dosdecimales(document.getElementById("fondoturismo").value *1)
	 var apo3 = dosdecimales(document.getElementById("contconven").value *1)
	 var apo4 = dosdecimales(document.getElementById("capaprof").value *1)
	 var apo5 = dosdecimales(document.getElementById("otras1").value *1)		
	 var apo6 = dosdecimales(document.getElementById("otras2").value *1)
	 
	 grabavar("cuotabajatemp",0.00)
	 grabavar("aposolnoafi",0.00)
	 grabavar("segsepelio",0.00)
	 grabavar("fondoconvord",0.00)
	 grabavar("otras1",0.00)
	 grabavar("apotrabajador",apo1)
	 grabavar("fondoturismo",apo2)
	 grabavar("contconven",apo3)
	 grabavar("capaprof",apo4)
	 grabavar("otras1",apo5)
	 grabavar("otras2",apo6)
	 
	 
 }else{
	// var apo1 = document.getElementById("cuotaaltatemp").value *1
	 var apo1 = 0
     var apo2 = dosdecimales(document.getElementById("cuotabajatemp").value *1)
	 var apo3 = dosdecimales(document.getElementById("aposolnoafi").value *1)
	 var apo4 = dosdecimales(document.getElementById("segsepelio").value *1)
	 var apo5 = dosdecimales(document.getElementById("fondoconvord").value *1)		
	 var apo6 = dosdecimales(document.getElementById("otras1").value *1) 
	 
	 grabavar("apotrabajador",0.00)
	 grabavar("fondoturismo",0.00)
	 grabavar("contconven",0.00)
	 grabavar("capaprof",0.00)
	 grabavar("otras1",0.00)
	 grabavar("otras2",0.00)
	 grabavar("cuotabajatemp",apo2)
	 grabavar("aposolnoafi",apo3)
	 grabavar("segsepelio",apo4)
	 grabavar("fondoconvord",apo5)
	 grabavar("otras1",apo6)
	 
	 
	 
 }	  
	// var aportot= apo1 + apo2 + apo3 + apo4 + apo5 + apo6
	 var aportot=parseFloat(apo1) + parseFloat(apo2) + parseFloat(apo3) + parseFloat(apo4) + parseFloat(apo5) + parseFloat(apo6)
	
	 aportot= dosdecimales(aportot)
     document.getElementById("totaportes").value =aportot
	 
	// grabavar(apo,val)
	 grabavar("totaportes",aportot)
}
}
//*********************************************
function dosdecimales(nro) { 
var val = parseFloat(nro); 
if (isNaN(val)) { return "0.00"; } 
if (val <= 0) { return "0.00"; } 

val=val.toFixed(2) 
return val; 
} 




//********************************************************************************

/*function NOletra(e){
	
   key=(document.all) ? e.keyCode : e.which;
   
   alert(key);
   if (key < 48 || key > 57){
      alert("Solo se pueden ingresar numeros.");
      return false;
   }
   return true;
   }//fin funcion

*/

function empresasdatos(str)
{ 
  //alert("hola");
 	 xmlHttp=GetXmlHttpObject()
 	 if (xmlHttp==null)
 	 {
 	 	 alert ("Browser does not support HTTP Request")
 	  	 return
 	 }        
 	 url="datosempresa.php"
 	 url=url+"?q="+str
 	 url=url+"&sid="+Math.random()
 	 xmlHttp.onreadystatechange=muestradatempresas
 	 xmlHttp.open("GET",url,true)
 	 xmlHttp.send(null)  
}

//********************************************************************************
function muestradatempresas() 
{ 
 
  if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete" )
   { 
   document.getElementById("empresadatos").innerHTML=xmlHttp.responseText 
   } 
 
}

//********************************************************************************
function conveniodatos(str)
{ 
 
  if(str==4)
  {
    // document.getElementById("convdescr").value="Pinamar";
	  grabavar("convdescr","Pinamar")
  }
  else 
  {
   //  document.getElementById("convdescr").value="Otros convenios";
	 grabavar("convdescr","Otros convenios") 
  }
  setTimeout ("document.getElementById('permes').select()", 200); 
  
   xmlHttp=GetXmlHttpObject()
   if (xmlHttp==null)
  {
   alert ("Browser does not support HTTP Request")
   return
  }        
  url="datosconvenio.php"
  url=url+"?q="+str
  url=url+"&sid="+Math.random()
  xmlHttp.onreadystatechange=muestradatconvenio
  xmlHttp.open("GET",url,true)
  xmlHttp.send(null)
}

function muestradatconvenio() 
{ 
 
  if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete" )
   { 
   document.getElementById("aportes").innerHTML=xmlHttp.responseText 
//  grabavar("convenio",str)
    
   } 
 
}


//***************EMPRESAS ***************************************************************************************



function botonesempresas(bot,vid)
{ 

switch(bot)
 {
  case "grax":

     xmlHttp=GetXmlHttpObject()
     if (xmlHttp==null)
     {
     alert ("Browser does not support HTTP Request")
     return
     }        
     url="empresasgraba.php"
     url=url+"?id="+vid
     url=url+"&sid="+Math.random()
	  
     //xmlHttp.onreadystatechange=stateChanged
     xmlHttp.open("GET",url,true)
     xmlHttp.send(null)
	 lblgrabar.style.visibility = "visible";// o visible
	  setTimeout ("lblgrabar.style.visibility = 'hidden'", 600); 
     break; 
   case "gra": 
      window.location='empresasgraba.php?id='+vid
     break;
   case "coc": 
     // window.location='coccion.php?id='+vid
     break;
  
   case "sal": 
      window.close()
     break; 	 
	  
  default:
	 
 }
}




function validauser(acc)
{ 
if (acc =="E")
{
   window.location='index.php'
}else{
   window.location='resetvar.php'
}

}

function menu(bot)
{ 
 switch(bot)
     {
       case "afi":
	       
            window.location='verafiliados.php'
            break;	 
       case "emp":
  	        
            window.location='verempresas.php'
            break;	 		
       case "apo":
   	       
            window.location='aportesver.php'
            break;	 
  	   
	   case "bol":
   	       
            window.location='../aportes/empresa.php'
            break;	 
			
       default:
	  
     }
}



function grabavar(varnom,val)
{ 

     if (varnom.substr(0,9)=="granoporc")
     { 
	  baseporc= 100-document.getElementById("granoporc1").value-document.getElementById("granoporc2").value-document.getElementById("granoporc3").value-document.getElementById("granoporc4").value-document.getElementById("granoporc5").value
      document.getElementById("granoporc0").value = baseporc   
	 } 
   
		
	 xmlHttp=GetXmlHttpObject()
    
	 if (xmlHttp==null)
     {
      alert ("Browser does not support HTTP Request")
      return
     }        
     
	 var url="sessionvar.php"
     url=url+"?n="+varnom+"&v="+val
	
	 if (varnom.substr(0,9)=="granoporc")
	 {
	     url=url+"&b="+baseporc
	 }
    
	 url=url+"&sid="+Math.random()
     xmlHttp.open("GET",url,true)
     xmlHttp.send(null)
}


function nomuestranada() 
{ 

} 




//******** VALIDA FECHAS *****************************************************************************************


var valorfecha

function validfecha(objName,varnom,val) {
valorfecha= val
var datefield = objName;

if (fechavalid(objName) == false) {
  datefield.select();
  alert("Esa fecha no es válida. Por favor, pruebe de nuevo. (FORMATO: 'dd/mm/aaaa')");
  datefield.focus();
  return false;
}
else {

grabavar(varnom,valorfecha)
return true;
   }
}

function fechavalid(objName) {
	
//var strDatestyle = "US"; //United States date style
var strDatestyle = "EU";  //European date style
var strDate;
var strDateArray;
var strDay;
var strMonth;
var strYear;
var intday;
var intMonth;
var intYear;
var booFound = false;
var datefield = objName;
var strSeparatorArray = new Array("-"," ","/",".");
var intElementNr;
var err = 0;
var strMonthArray = new Array(12);
strMonthArray[0] = "Ene";
strMonthArray[1] = "Feb";
strMonthArray[2] = "Mar";
strMonthArray[3] = "Abr";
strMonthArray[4] = "May";
strMonthArray[5] = "Jun";
strMonthArray[6] = "Jul";
strMonthArray[7] = "Ago";
strMonthArray[8] = "Sep";
strMonthArray[9] = "Oct";
strMonthArray[10] = "Nov";
strMonthArray[11] = "Dic";
strDate = datefield.value;

if (strDate.length < 1) {
   return true;
}

for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
   if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
      strDateArray = strDate.split(strSeparatorArray[intElementNr]);
      if (strDateArray.length != 3) {
      err = 1;
      return false;
    }
    else {
      strDay = strDateArray[0];
      strMonth = strDateArray[1];
      strYear = strDateArray[2];
    }
booFound = true;
   }
}
if (booFound == false) {
if (strDate.length>5) {
strDay = strDate.substr(0, 2);
strMonth = strDate.substr(2, 2);
strYear = strDate.substr(4);
   }
}
if (strYear.length == 2) {
strYear = '20' + strYear;
}
// US style
if (strDatestyle == "US") {
strTemp = strDay;
strDay = strMonth;
strMonth = strTemp;
}
intday = parseInt(strDay, 10);
if (isNaN(intday)) {
err = 2;
return false;
}
intMonth = parseInt(strMonth, 10);
if (isNaN(intMonth)) {
for (i = 0;i<12;i++) {
if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) {
intMonth = i+1;
strMonth = strMonthArray[i];
i = 12;
   }
}
if (isNaN(intMonth)) {
err = 3;
return false;
   }
}
intYear = parseInt(strYear, 10);
if (isNaN(intYear)) {
err = 4;
return false;
}
if (intMonth>12 || intMonth<1) {
err = 5;
return false;
}
if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) {
err = 6;
return false;
}
if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) {
err = 7;
return false;
}
if (intMonth == 2) {
if (intday < 1) {
err = 8;
return false;
}
if (LeapYear(intYear) == true) {
if (intday > 29) {
err = 9;
return false;
}
}
else {
if (intday > 28) {
err = 10;
return false;
}
}
}

dia=strzero(2,intday)
mes=strzero(2,intMonth)

if (strDatestyle == "US") {
//datefield.value = strMonthArray[intMonth-1] + " " + intday+" " + strYear;
datefield.value = mes + "/" + dia+"/" + strYear;
}
else {
//datefield.value = intday + " " + strMonthArray[intMonth-1] + " " + strYear;



datefield.value = dia+ "/" + mes + "/" + strYear;
}
valorfecha=datefield.value
return true;
}



function LeapYear(intYear) {
if (intYear % 100 == 0) {
if (intYear % 400 == 0) { return true; }
}
else {
if ((intYear % 4) == 0) { return true; }
}
return false;
}

//********************************************************************************

function strzero(tam, num) {
if (num.toString().length < tam) return strzero(tam, "0" + num)
else return num;
}

function botonera(url, bot, vid, vord)

{

    switch (bot)
    {
    case "ini":
    case "pro":
    case "ant":
    case "ult":
    case "agr":
    case "edi":
    case "can":
    case "bor":
        vregid = vid
        vorden = vord
        if (bot == "bor")
        {
            borrasino = confirm("Esta a punto de borra este registro ¿ESTA USTED SEGURO?")
        }
        else
        {
            borrasino = true
        }
        xmlHttp = GetXmlHttpObject()
     if (xmlHttp == null)
        {
            alert("Browser does not support HTTP Request")
            return
        }
        url = url + "datos.php"
        url = url + "?id=" + vregid + "&ord=" + vorden + "&ac=" + bot
        url = url + "&sid=" + Math.random()
        xmlHttp.onreadystatechange = cambiagranos
        xmlHttp.open("GET", url, true)
        if (borrasino) {
            xmlHttp.send(null)
        }
        break;
    case "gra":
        vregid = vid
        vorden = vord
        xmlHttp = GetXmlHttpObject()
        if (xmlHttp == null)
        {
            alert("Browser does not support HTTP Request")
            return
        }
        url = url + "graba.php"
        url = url + "?id=" + vregid + "&ord=" + vorden + "&ac=" + bot
        url = url + "&sid=" + Math.random()
        xmlHttp.onreadystatechange = cambiabotones
        xmlHttp.open("GET", url, true)
        xmlHttp.send(null)
        lblgrabar.style.visibility = "visible"; // o visible
        setTimeout("lblgrabar.style.visibility = 'hidden'", 600)
        break;
    case "gra2":
        break;
    case "sal":
        window.close()
        break;
    default:
    }
}

//********************************************************************************
function validacuit(cuit) 
{
	
//	if (!(cuit.match(/^\d{2}\-\d{8}\-\d{1}$/)))
/*	if (!(cuit.match(/^\d{11}$/)))
    {
       alert("El Cuil/Cuit es incorrecto. Revisar");
      return (false); 
    }*/
    
	var vec= new Array(10);
    esCuit=false;
    cuit_rearmado="";
    errors = ''
    for (i=0; i < cuit.length; i++) {   
        caracter=cuit.charAt( i);
        if ( caracter.charCodeAt(0) >= 48 && caracter.charCodeAt(0) <= 57 )     {
            cuit_rearmado +=caracter;
        }
    }

    cuit=cuit_rearmado;
    if ( cuit.length != 11) {  // si to estan todos los digitos
        esCuit=false;
        errors = 'Cuit <11 ';
        //alert( "CUIT Menor a 11 Caracteres" );
    } else {
        x=i=dv=0;
        // Multiplico los dígitos.
        vec[0] = cuit.charAt(  0) * 5;
        vec[1] = cuit.charAt(  1) * 4;
        vec[2] = cuit.charAt(  2) * 3;
        vec[3] = cuit.charAt(  3) * 2;
        vec[4] = cuit.charAt(  4) * 7;
        vec[5] = cuit.charAt(  5) * 6;
        vec[6] = cuit.charAt(  6) * 5;
        vec[7] = cuit.charAt(  7) * 4;
        vec[8] = cuit.charAt(  8) * 3;
        vec[9] = cuit.charAt(  9) * 2;
                    
        // Suma cada uno de los resultado.
        for( i = 0;i<=9; i++) {
            x += vec[i];
        }
        dv = (11 - (x % 11)) % 11;
        if ( dv == cuit.charAt( 10) ) { 
            esCuit=true;
        } 
    }
    if ( !esCuit ) {
        alert( "CUIT Invalido" );
    //    document.frmClientes.cuit.focus();
    //    errors = 'Cuit Invalido ';
    }
	 return esCuit;
     //document.MM_returnValue1 = (errors == '');
}

//****************************************************************
function ayuda(direccion, pantallacompleta, herramientas, direcciones, estado, barramenu, barrascroll, cambiatamano, ancho, alto, izquierda, arriba, sustituir){ 
     var opciones = "fullscreen=" + pantallacompleta + 
                 ",toolbar=" + herramientas + 
                 ",location=" + direcciones + 
                 ",status=" + estado + 
                 ",menubar=" + barramenu + 
                 ",scrollbars=" + barrascroll + 
                 ",resizable=" + cambiatamano + 
                 ",width=" + ancho + 
                 ",height=" + alto + 
                 ",left=" + izquierda + 
                 ",top=" + arriba; 
var ventana = window.open(direccion,"venta",opciones,sustituir); 
}
