
function trim(cadena)
{
	for(i=0; i<cadena.length; )
	{
		if(cadena.charAt(i)==" ")
			cadena=cadena.substring(i+1, cadena.length);
		else
			break;
	}

	for(i=cadena.length-1; i>=0; i=cadena.length-1)
	{
		if(cadena.charAt(i)==" ")
			cadena=cadena.substring(0,i);
		else
			break;
	}
	
	return cadena;
}

function converFechaInglesaEspanol (valfecha)
{
	var Fecha= new String(valfecha);	// Crea un string
	var RealFecha= new Date();	// Para sacar la fecha de hoy
	// Cadena Año

	var anio= new String(Fecha.substring(Fecha.lastIndexOf("/")+1,Fecha.length));

	// Cadena Mes
	var dia= new String(Fecha.substring(Fecha.indexOf("/")+1,Fecha.lastIndexOf("/")));
	// Cadena Día
	var mes= new String(Fecha.substring(0,Fecha.indexOf("/")));	
	
	var nuevafecha=dia+"/"+mes+"/"+anio;
	
	return nuevafecha;
}
//trabajarlo independientemente
function ValidarFecha(Cadena)
{
	var Fecha= new String(Cadena);	// Crea un string
	var RealFecha= new Date();	// Para sacar la fecha de hoy
	var valorRetorno=true;
	// Cadena Año

	if(Fecha.indexOf("/")!=-1)
	{
	
		var Ano= new String(Fecha.substring(Fecha.lastIndexOf("/")+1,Fecha.length));
	
		// Cadena Mes
		var Mes= new String(Fecha.substring(Fecha.indexOf("/")+1,Fecha.lastIndexOf("/")));
		// Cadena Día
		var Dia= new String(Fecha.substring(0,Fecha.indexOf("/")));
	
		// Valido el año
	
		if(isNaN(Ano) || Ano.length<4 || parseFloat(Ano)<1900)
		{		//alert("Anio invalido");
				return false;
		}
		// Valido el Mes
		if (isNaN(Mes) || parseFloat(Mes)<1 || parseFloat(Mes)>12)
		{
			//alert('Mes invalido');
			return false;
		}
			// Valido el Dia
		if (isNaN(Dia) || parseInt(Dia, 10)<1 || parseInt(Dia, 10)>31)
		{
			//alert('Dia invalido');
			return false;
		}
		
		var nanio= parseFloat(Ano);
		
		if(nanio%4==0)
		{//es divisible entre cuatro -  es bisiesto
				if (Mes==4 || Mes==6 || Mes==9 || Mes==11 || Mes==2) 
				{
					if (Mes==2 && Dia > 29 || Dia>30) 
					{
						//alert('Dia invalido')
						return false;
					}
				}
		}
		else
		{//no es bisiesto
			if (Mes==4 || Mes==6 || Mes==9 || Mes==11 || Mes==2) 
			{
				if (Mes==2 && Dia > 28 || Dia>30) 
				{
					//alert('Dia invalido')
					return false;
				}
			}
		}
	
		
	  //para que envie los datos, quitar las  2 lineas siguientes
	
	  valorRetorno=true;
	  
		
	}
	else
	{
		valorRetorno=false;
	}
		return valorRetorno;

}

var meses=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec") ;

function contador2( yr , m , d )
{ 
		var hoy=new Date() ;
		var ano=hoy.getYear(); 
		if (ano < 1000) 
			ano+=1900 
		
		var mes=hoy.getMonth() 
		var dia=hoy.getDate() 
		var fecha=meses[mes]+" "+dia+", "+ano 
		var paststring=meses[m-1]+" "+d+", "+yr 
		
		var diferencia=(Math.round((Date.parse(fecha)-Date.parse(paststring))/(24*60*60*1000))*1) ;
		
		return diferencia;
}

function makedate()
{

document.getElementById("txt_fnac").value= document.getElementById("month").value + "/" + document.getElementById("day").value + "/" + document.getElementById("year").value;
}

function makedate_general(day_aplic,month_aplic,year_aplic,txt_fec_aplic)
{
	document.getElementById(txt_fec_aplic).value= document.getElementById(month_aplic).value + "/" + document.getElementById(day_aplic).value + "/" + document.getElementById(year_aplic).value;
}

function convertir_fechaEspanol(fec)
{
	 var trozos = fec.split ("/");
	 
	 var dia, mes, ano, fecha;
	 
	 if(trozos[0].length==1)
	 	dia='0'+trozos[0];
	else
		dia=trozos[0];
		
		
	if(trozos[1].length==1)
	 	mes='0'+trozos[1];
	else
		mes=trozos[1];
	
	
	ano=trozos[2];
	
	fecha=dia+'/'+mes+'/'+ano;
		
	
	return  fecha;	
	
}

  function fechaMayorOIgualQue(fec0, fec1)
  {  
		var bRes = false;  
		var sDia0 = fec0.substr(0, 2);  
		var sMes0 = fec0.substr(3, 2);  
		var sAno0 = fec0.substr(6, 4); 
		
		var sDia1 = fec1.substr(0, 2);  
		var sMes1 = fec1.substr(3, 2);  
		var sAno1 = fec1.substr(6, 4);  
		if (sAno0 > sAno1) bRes = true;  
		else 
		{  
			 if (sAno0 == sAno1)
			 {  
				  if (sMes0 > sMes1) bRes = true;  
				  else 
				  {  
				   	if (sMes0 == sMes1)  
					if (sDia0 >= sDia1) bRes = true;  
				  }  
			 }  
		}  
		return bRes;  
   } 
    
function fechaMayorQue(fec0, fec1)
  {  
		var bRes = false;  
		var sDia0 = fec0.substr(0, 2);  
		var sMes0 = fec0.substr(3, 2);  
		var sAno0 = fec0.substr(6, 4); 
		
		var sDia1 = fec1.substr(0, 2);  
		var sMes1 = fec1.substr(3, 2);  
		var sAno1 = fec1.substr(6, 4);  
		if (sAno0 > sAno1) bRes = true;  
		else 
		{  
			 if (sAno0 == sAno1)
			 {  
				  if (sMes0 > sMes1) bRes = true;  
				  else 
				  {  
				   	if (sMes0 == sMes1)  
					if (sDia0 > sDia1) bRes = true;  
				  }  
			 }  
		}  
		return bRes;  
   }
   

function setearFoco(id_campo)
{
	//alert(id_campo);
	var text_sel=document.getElementById(id_campo);
	text_sel.select();
	text_sel.focus();
}


	var nav4 = window.Event ? true : false;
	function acceptNumAlfabeticEspecial(evt)
		{ 
		// NOTE: Backspace = 8, Enter = 13, '0' = 48, '9' = 57 
		var key = nav4 ? evt.which : evt.keyCode; 
		return (key <= 13 || (key >= 45 && key <= 57) || (key >= 65 && key <= 90) || (key >= 97 && key <= 122) || key ==32);
		}
		
		
		function acceptNumAlfabetico(evt)
		{ 
		// NOTE: Backspace = 8, Enter = 13, '0' = 48, '9' = 57 
		var key = nav4 ? evt.which : evt.keyCode; 
		return (key <= 13 || (key >= 48 && key <= 57) || (key >= 65 && key <= 90) || (key >= 97 && key <= 122));
		}
		
		
	function acceptFecha(evt)
		{ 
		// NOTE: Backspace = 8, Enter = 13, '0' = 48, '9' = 57 
		var key = nav4 ? evt.which : evt.keyCode; 
		return (key <= 13 || (key >= 47 && key <= 57) );
		}



//----------FUNCION PARA PINTAR LAS FILAS DE UNA TABLA

function sobre_fila(id_fila)
{
	var color_fila_sel=document.getElementById("color_fila_sobre");
		var fila=document.getElementById(id_fila);
	//capturo color
	color_fila_sel.value	=	fila.style.backgroundColor;
	fila.style.backgroundColor='#588ECB';

	
	//alert("id fila "+id_fila+" ; "+color_fila_sel.value);
	
}

function fuera_fila(id_fila)
{
	var color_fila_sel=document.getElementById("color_fila_sobre");
	
	var fila=document.getElementById(id_fila);
	fila.style.backgroundColor	=	color_fila_sel.value;	
}

function click_fila(id_fila)
{
	//capturo la fila 
	var fila=document.getElementById(id_fila);
	//tengo color de la fila que se selecciono
	var fila_color=document.getElementById("color_fila_sobre");

	//veo si ya selecciono una fila
	var fila_sel=document.getElementById("fila_seleccionada");
	//color original de la fila seleccionada
	var fila_sel_color=document.getElementById("color_fila_seleccionada");
	
	
	if(fila_sel.value=="")
	{//no se selecciono una fila
		//almaceno una la variable de la fila seleccionada
		fila_sel.value=id_fila;
		//almacenamos color de la fila seleccionada la original
		fila_sel_color.value=fila_color.value;
		
		//pintamos de color permanente la fila
		fila.style.backgroundColor	=	'#89AFDA';
		fila_color.value	=	'#89AFDA';
	
	}
	else
	{//ya se selecciono una fila
		
		//capturamos los parametros de la fila actual
		//almaceno una la variable de la fila seleccionada
		var id_fila_actual=id_fila;
		//almacenamos color de la fila seleccionada
		var color_fila_actual=fila_color.value;
		
		//guardamos los valores de la fial anterior guardada
		var id_fila_anterior=fila_sel.value;
		var color_fila_anterior=fila_sel_color.value;
		
		if(id_fila_actual==id_fila_anterior)
		{//es el mismo id no hacer nada
		}
		else
		{
					//la fila anaterior la volvemos a su color original
			document.getElementById(id_fila_anterior).style.backgroundColor = color_fila_anterior;
			
			//almacenamos datos de la nueva fila sleccionada
			fila_sel.value=id_fila_actual;
			fila_sel_color.value=color_fila_actual;
			
			
			//pintamos de color permanente la fila
			fila.style.backgroundColor	=	'#89AFDA';
			fila_color.value	=	'#89AFDA';
		
		}
	
	}
		
}

//-----------end funciones-------------------------------
