var fila_color_reg=0;

//Esta variable es necesaria para resaltar el campo que se tenga seleccionado
var id_campo_resaltar;

function fila_color()
{		
	if(fila_color_reg%2==0)
	{
		document.write("<tr>");
	}else
	{
		document.write("<tr bgcolor='#EDE9DE'>");
	}
	fila_color_reg=fila_color_reg+1;
}

function eliminar_filas(padre)
{
	nodo_padre=document.getElementById(''+padre+'');
	while(nodo_padre.hasChildNodes()&&nodo_padre.childNodes.length>1)
	{		
		nodo_padre.removeChild(nodo_padre.lastChild);
	}
}

function serializar()
{
	var datos="";	
	
	campos=document.getElementsByTagName("select");
	for(i=0;i<campos.length;i++)
	{
		if(campos[i].id!="")
		{
			if(datos!="")
				datos=datos+"&";
			datos=datos+campos[i].id+"="+campos[i].value;
		}			
	}	
	
	campos=document.getElementsByTagName("input");
	for(i=0;i<campos.length;i++)
	{
		if(campos[i].id!="")
		{
			if(datos!="")
				datos=datos+"&";
			datos=datos+campos[i].id+"="+campos[i].value;
		}			
	}
	
	campos=document.getElementsByTagName("textarea");	
	for(i=0;i<campos.length;i++)
	{
		if(campos[i].id!="")
		{			
			if(datos!="")
				datos=datos+"&";
			datos=datos+campos[i].id+"="+campos[i].value;			
		}			
	}
	return datos;
}

function mostrar_mensaje(mensaje)
{
	if(mensaje!="")
		alert (''+mensaje+'');
}

function no_vacios()
{
	campos=document.getElementsByTagName("input");	
	for(u=0;u<campos.length;u++)
	{		
		if(campos[u].value=="")
		{				
			return false;
		}		
	}
	campos=document.getElementsByTagName("textarea");	
	for(u=0;u<campos.length;u++)
	{		
		if(campos[u].value=="")
		{				
			return false;
		}		
	}
	campos=document.getElementsByTagName("select");	
	for(u=0;u<campos.length;u++)
	{		
		if(campos[u].value=="")
		{				
			return false;
		}		
	}
	return true;
}

function campo_vacio(id)
{
	if(document.getElementById(''+id+'').value=="")
	{
		alert ("Por favor ingresa tu nombre");
		document.getElementById("nombre").focus();
		return true;
	}else
		return false;
}

function resaltar_campo()
{	
	this.style.backgroundColor="#F2F2FF";
}

function no_resaltar_campo()
{
	this.style.backgroundColor="";
}

function resaltar_todos_campos()
{
	campos=document.getElementsByTagName("input");	
	for(u=0;u<campos.length;u++)
	{		
		addEvent(campos[u], 'focus', resaltar_campo,false);
		addEvent(campos[u], 'blur', no_resaltar_campo,false);
	}
	campos=document.getElementsByTagName("textarea");	
	for(u=0;u<campos.length;u++)
	{
		addEvent(campos[u], 'focus', resaltar_campo,false);
		addEvent(campos[u], 'blur', no_resaltar_campo,false);
	}
	campos=document.getElementsByTagName("select");	
	for(u=0;u<campos.length;u++)
	{
		addEvent(campos[u], 'focus', resaltar_campo,false);
		addEvent(campos[u], 'blur', no_resaltar_campo,false);
	}
}

function addEvent(elm, evType, fn, useCapture)
{ 
    if(elm.addEventListener)
	{
        elm.addEventListener(evType, fn, useCapture);
    }else if(elm.attachEvent)
	{
        var f=function()
		{
            fn.call(elm,window.event);
        }
        elm.attachEvent('on' + evType, f);        
    }else
	{
        elm['on' + evType] = fn;
    }
}



function es_numero(num,nombre)
{
	if(isNaN(num))
	{	
		alert ("Debes ingresar un numero (Sin separador de miles)");	
		campo="document.form1."+nombre+".focus()";
		eval(campo);
	}
}

function a_mayus(id)
{
		document.getElementById(''+id+'').value=document.getElementById(''+id+'').value.toUpperCase( );
}
function longitud(num,nombre,lmin,lmax)
{
	if(num.length<lmin||num.length>lmax)
	{	
		alert ("la longitud mínima es "+lmin+" y la longitud mázxima es "+lmax);	
		campo="document.form1."+nombre+".focus()";
		eval(campo);
	}			
}
function es_numero_array(num,id)
{	
	if(isNaN(num))
	{		
		alert ("Debes ingresar un numero (Sin separador de miles)");	
		campo="document.form1.elements["+id+"].focus()";
		eval(campo);
		return false;
	}
	if(Number(num)<0)
	{
		alert ("No puedes ingresar numeros negativos");
		campo="document.form1.elements["+id+"].focus()";
		eval(campo);
		return false;
	}	
	return true;
}
function f_open_window_max( aURL, aWinName )
{
   var wOpen;
   var sOptions;

   sOptions = 'status=yes,menubar=yes,scrollbars=yes,resizable=yes,toolbar=yes';
   sOptions = sOptions + ',width=' + (screen.availWidth - 10).toString();
   sOptions = sOptions + ',height=' + (screen.availHeight - 122).toString();
   sOptions = sOptions + ',screenX=0,screenY=0,left=0,top=0';

   wOpen = window.open( '', aWinName, sOptions );
   wOpen.location = aURL;
   wOpen.focus();
   wOpen.moveTo( 0, 0 );
   wOpen.resizeTo( screen.availWidth, screen.availHeight );
   return wOpen;
}
function Minimize() 
{
window.innerWidth = 100;
window.innerHeight = 100;
window.screenX = screen.width;
window.screenY = screen.height;
alwaysLowered = true;
}

function Maximize() 
{
window.innerWidth = screen.width;
window.innerHeight = screen.height;
window.screenX = 0;
window.screenY = 0;
alwaysLowered = false;
}


function oNumero(numero)
{
//Propiedades 
this.valor = numero || 0
this.dec = -1;
//Métodos 
this.formato = numFormat;
this.ponValor = ponValor;
//Definición de los métodos 
function ponValor(cad)
{
if (cad =='-' || cad=='+') return
if (cad.length ==0) return
if (cad.indexOf('.') >=0)
    this.valor = parseFloat(cad);
else 
    this.valor = parseInt(cad);
} 
function numFormat(dec, miles)
{
var num = this.valor, signo=3, expr;
var cad = ""+this.valor;
var ceros = "", pos, pdec, i;
for (i=0; i < dec; i++)
ceros += '0';
pos = cad.indexOf('.')
if (pos < 0)
    cad = cad+"."+ceros;
else
    {
    pdec = cad.length - pos -1;
    if (pdec <= dec)
        {
        for (i=0; i< (dec-pdec); i++)
            cad += '0';
        }
    else
        {
        num = num*Math.pow(10, dec);
        num = Math.round(num);
        num = num/Math.pow(10, dec);
        cad = new String(num);
        }
    }
pos = cad.indexOf('.')
if (pos < 0) pos = cad.lentgh
if (cad.substr(0,1)=='-' || cad.substr(0,1) == '+') 
       signo = 4;
if (miles && pos > signo)
    do{
        expr = /([+-]?\d)(\d{3}[\.\,]\d*)/
        cad.match(expr)
        cad=cad.replace(expr, RegExp.$1+','+RegExp.$2)
        }
while (cad.indexOf(',') > signo)
    if (dec<0) cad = cad.replace(/\./,'')
        return cad;
}
}//Fin del objeto oNumero:

function pintar_fondo(id)
{
	document.getElementById(''+id+'').style.backgroundColor='#99CCFF';
}

function despintar_fondo(id)
{
	document.getElementById(''+id+'').style.backgroundColor='#FFFFFF';
}

function Comparar_Fecha(Obj1,Obj2) 
{

if(Obj1.indexOf("-",0)!=-1)
{		
	String1= new String;
	for(i=0;i<Obj1.length;i++)
	{
		letra=Obj1.charAt(i);
		if(letra=="-")
			String1=String1+"/";			
		else if (letra==" ")
			i=Obj1.Length;
		else
			String1=String1+letra;
	}
}else
	String1=Obj1;

if(Obj2.indexOf("-",0)!=-1)
{	
	String2= new String;
	for(i=0;i<Obj2.length;i++)
	{
		letra=Obj2.charAt(i);
		if(letra=="-")
			String2=String2+"/";			
		else if (letra==" ")
			i=Obj2.Length;
		else
			String2=String2+letra;
	}
}else
	String2=Obj2;

dia1=String1.substring(8,10);
mes1=String1.substring(5,7);
anyo1=String1.substring(0,4);
dia2=String2.substring(8,10);
mes2=String2.substring(5,7);
anyo2=String2.substring(0,4);

if (dia1 == "08") // parseInt("08") == 10 base octogonal
dia1 = "8";
if (dia1 == '09') // parseInt("09") == 11 base octogonal
dia1 = "9";
if (mes1 == "08") // parseInt("08") == 10 base octogonal
mes1 = "8";
if (mes1 == "09") // parseInt("09") == 11 base octogonal
mes1 = "9";
if (dia2 == "08") // parseInt("08") == 10 base octogonal
dia2 = "8";
if (dia2 == '09') // parseInt("09") == 11 base octogonal
dia2 = "9";
if (mes2 == "08") // parseInt("08") == 10 base octogonal
mes2 = "8";
if (mes2 == "09") // parseInt("09") == 11 base octogonal
mes2 = "9";

dia1=parseInt(dia1);
dia2=parseInt(dia2);
mes1=parseInt(mes1);
mes2=parseInt(mes2);
anyo1=parseInt(anyo1);
anyo2=parseInt(anyo2);

if (anyo1>anyo2)
{
return false;
}

if ((anyo1==anyo2) && (mes1>mes2))
{
return false;
}
if ((anyo1==anyo2) && (mes1==mes2) && (dia1>dia2))
{
return false;
} 

return true;
}