

//-------------------------------------------------------
// solo numeros, si no es numero devuelve false ----------

	function numero(cadena)
	{
	 var str = "1234567890";
	 for(cont = 0;cont < cadena.length;cont++)
		{
		tmp = cadena.substring(cont,cont+1);
		if (str.indexOf (tmp,0)== -1)
		return(false);
		}
	 return(true); 
	}
//---------------------------------------------------------






// abre ventana nueva segun parametros recibidos--------

	function NewWin(URL,WinName,Opciones)

	{	window.open(URL,WinName,Opciones); }

//--------------------------------------------






// maximiza ventana --------------------------------

	function maxi() 
	{
	window.innerWidth = screen.width;
	window.innerHeight = screen.height;
	window.screenX = 0;
	window.screenY = 0;
	alwaysLowered = false;
	}

//--------------------------------------------






// Submite un form ante un cambio en un campo ----------------

function EnviaFormCambio(FormName,Campo)
{
	var form = document.forms[FormName];
	var campo = form.elements[Campo].value;
	
	if (campo != '')
	{
		form.submit();
		return (false);
	}

}
// --------------------------------------------




// Submite un form ----------------------------
	
	function EnviaForm(formu)
	{
		if (formu == '') 		
			{ 	document.forms[0].submit(); 		}
		else		
			{ 
				document.formu.submit(); 
			}
			
	}

//--------------------------------------------





// imprimir -------------------------------------

	function WinImprime()

	{	
		window.print();
		window.close();

	}

//--------------------------------------------

  

//---------------------------------------------------------------


function redir(url)
{  
	if (url != '' )
	 { 	this.location.replace(url);  } 
	 
}  



//---------------------------------------------------------------



//---------------------------------------------------------------


function RedirParam(url,param)
{  
	if (param != '' )
	 { 
	 	//alert(url+param);
	 	this.location.replace(url+param);
	 } 
	 
}  




//--------------------------------------------

function CheckMail(emailStr)
{

var filter=/^[A-Za-z0-9_.-]*@[A-Za-z0-9_-]+\.[-A-Za-z0-9_.]+[A-za-z]$/;
if (emailStr.length == 0 ) return false;
if (! filter.test(emailStr)) return false;

return true;

}


//--------------------------------------------







// *********** FUNCIONES DE FECHA **********************************





function FormateaFecha(dia, mes, anio)
{ 
	var fecha = new Date( parseInt(anio), parseInt(mes), parseInt(dia) );
	return (fecha);
} 



// año bisiesto, si es bisiesto devuelve true ----------

	function bisiesto(Vanio) 

	{
		if (Vanio % 4 == 0) 
			return true; 
		else 
			return false; 
	}

//--------------------------------------------




//cantidad de dias para cada mes---------------

	function dias_mes(vMES, vANIO) 
	
	{
	
	var vm = parseInt(vMES);
	
		switch (vm) 
		{
			case 1: 
				return 31;
				break;
			case 2: 
				return 29;
				break;
			case 3: 
				return 31;
				break;
			case 4: 
				return 30;
				break;
			case 5: 
				return 31;
				break;
			case 6: 
				return 30;
				break;
			case 7: 
				return 31;
				break;
			case 8: 
				return 31;
				break;
			case 9: 
				return 30;
				break;
			case 10: 
				return 31;
				break;
			case 11: 
				return 30;
				break;
			case 12: 
				return 31;
				break;
			default:
				return 31;
			
		}
		
	}




// valida fechas----------------------------------------

	function validafecha(REQ,dia,mes,anio) 

	{
	
		if ( (REQ==1) && ( (dia=="") || (mes=="") || (anio=="") ) )
		{ return (false);	}


		if ( dia > dias_mes(mes) )
		{	  return (false);		}


		if ((mes == 2) && ( (bisiesto(anio) == false) && (dia > 28) ) )
		{  return (false);		}

			
	}


// ******************************************************


// CAMBIA EL ESTILO A UN OBJETO ----------------------
function CambiaEstilo(NomObj, estilo)
{ 
 var objeto = document.getElementById(NomObj);
 objeto.className = estilo;
} 



// EXPANDE O CONTRAE OBJETOS ----------------------

function Expandir(NomObj,estilo) 
{ 

 var objeto = document.getElementById(NomObj);
 var contra = objeto.className;
 
 if ( contra.toLowerCase() == 'contraido' ) 
 	  objeto.className = estilo ;
 else
 		objeto.className = 'contraido';
 
 
 //objeto.className = objeto.className == "contraido" ? estilo : "contraido";
 //tblDepo.className = tblDepo.className == "contraido" ? "expandido" : "contraido";


}

//-----------------------------------------------





// Confirma la eliminación de items en CheckBox ----------
function CheckBorrar(form)
{
var cant = form.contador.value;
var n=0;

	for (i=1;i<=cant;i=i+1)
	{
		var chbox = form.elements["Borrar_"+i];
		if (chbox.checked)
		{ n = (n+1); }
	}

	if (n>0)
	{ return confirm("¿ Confirma que va a ELIMINAR los Items seleccionados ?"); }

}

//-----------------------------------------------





// Controla campos numericos para ORDEN ----------
function CheckOrden(form)
{
var cant = form.contador.value;
var err=false;

	for (i=1;i<=cant;i=i+1)
	{
		if (err==false)
		{
			var campo = form.elements["Orden_"+i];
			if (numero(campo.value) == false)
			{ 
				err=true;
				alert("El ORDEN debe ser numérico");
				campo.focus();
				return(false);
			}
		}
	}

}

//-----------------------------------------------





// TRIM ----------

function trim(txt)
{
	var txt = txt.replace(/^\s+|\s+$/g,'');
	return(txt);
}

//-----------------------------------------------




// Si esta Vacio devuelve TRUE----------

function vacio(dato)
{
	var trimdato = trim(dato);

	if (trimdato=='')
	{	return (true);	}
	else
	{	return (false);	}
}

//-----------------------------------------------





// Valida Campos Requeridos ----------

function esVacio(FormName,campo,txtalerta)
{
	var campo = document.forms[FormName].elements[campo];
	valor = trim(campo.value);

	if (valor=='')
	{
	alert("Debe completar " + txtalerta);
	campo.focus();
	return (false);
	}

}

//-----------------------------------------------



// solo numeros, NUEVO!! ----------

	function NoEsNumero(FormName,campo,txtalerta)
	{
	 var campo = document.forms[FormName].elements[campo];
	 var cadena = campo.value;
	 var ERROR = false;
	 var str = "1234567890";
	 
	 for(cont = 0;cont < cadena.length;cont++)
		{
		tmp = cadena.substring(cont,cont+1);
		if (str.indexOf (tmp,0)== -1)
		ERROR=true;
		}	
		
		if (ERROR==true)
		{
		alert('Debe completar ' +txtalerta+ ' con Números' );
		campo.focus();
		return(true);
		}

	}
	
//---------------------------------------------------------






// valida fechas NUEVO!! -----------------------------------

	function evalFecha(REQ,FormName,DIA,MES,ANIO) 

	{

	  var ERROR = false;
	  var campo = document.forms[FormName].elements[DIA];
	  
	 	var dia = document.forms[FormName].elements[DIA].value;
	 	var mes = document.forms[FormName].elements[MES].value;
	 	var anio = document.forms[FormName].elements[ANIO].value;
	
		if ( (REQ==1) && ( (dia=='') || (mes=='') || (anio=='') ) )
		{ ERROR=true; }
		
		if ( dia > dias_mes(mes) )
		{	ERROR=true; }

		if ((mes == 2) && ( (bisiesto(anio) == false) && (dia > 28) ) )
		{ ERROR=true; }

		if (ERROR==true)
		{
		alert('La Fecha es incorrecta');
		campo.focus();
		return(true);
		}

			
	}








//----------------------------------------------------------
// revisa que no haya valores repetidos en un array   
//----------------------------------------------------------

function CheckRepetidos(FormName,cont,campo,label)

{
	var form = document.forms[FormName];
	for (i=1; i<=cont; i++)
	{
	 valor = form.elements[campo+i].value;
	 if (valor != '')
	 {
		for (n=i; n<=cont; n++)
		{
			compara = form.elements[campo+n].value;
			if ((n != i) && (valor == compara))
			{
				alert("No se puede repetir " + label);
				form.elements[campo+'1'].focus();
				return(true);
			}
		}
	 }	 
	}	
}

//-----------------------------------------------------------------


 function derecha(e) 
   {
      if (navigator.appName == 'Netscape' && (e.which == 3 || e.which == 2))
        {
           alert('Botón derecho inhabilitado');
           return false;
        }
      else 
	{
          if (navigator.appName == 'Microsoft Internet Explorer' && (event.button == 2))
            {
               alert('Botón derecho inhabilitado');
               return false;
             }
        }
   }

//-----------------------------------------------------------------



