// JavaScript Document 10/07/2006

/****************************************************************************************
*       Funcion que genera el calendario para seleccion de fechas	 					*
*																						*
*****************************************************************************************/ 

var festivos = [5,6];
    var festivosColor = "#00CCFF";
    var familia_fuente = "Verdana";
    var size_fuente = 2;
    var ahora = new Date();
    var calculo;
    
    
    if (document.layers)
        isNav = true;
    else if (document.all)
        isIE = true;

   
    Calendario.Meses = ["Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Deciembre"];
    Calendario.DiasMes = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
    Calendario.BisiestoDiasMes = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
    function Calendario(p_item, p_WinCal, mes, anyo, formato)
    {
        if ((mes == null) && (anyo == null))	
            return;
	    if (p_WinCal == null)
		    this.gWinCal = calculo;
	    else
		    this.gWinCal = p_WinCal;
	
	    if (mes == null)
        {
	        this.dameMes = null;
            this.dameNumeroMes = null;
            this.dameAnyo = true;
        }
        else
        {
	        this.dameMes = Calendario.get_month(mes);
            this.dameNumeroMes = new Number(mes);
            this.dameAnyo = false;
        }

	    this.gYear = anyo;
	    this.gFormat = formato;
	    this.gBGColor = "#336699";
	    this.gFGColor = "black";
	    this.gTextColor = "black";
	    this.gHeaderColor = "WHITE";
	    this.gReturnp_item = p_item;
    }

    Calendario.get_month = Calendario_get_month;
    Calendario.get_diasdelmes = Calendario_get_diasdelmes;
    Calendario.calcula_mes_anyo = Calendario_calcula_mes_anyo;
    Calendario.print = Calendario_print;

    function Calendario_get_month(monthNo) 
    {
	    return Calendario.Meses[monthNo];
    }

    function Calendario_get_diasdelmes(monthNo, anyo) 
    {	
        if ((anyo % 4) == 0) 
        {
            if ((anyo % 100) == 0 && (anyo % 400) != 0)
                return Calendario.DiasMes[monthNo];	
		     return Calendario.BisiestoDiasMes[monthNo];
	     }
         else
		     return Calendario.DiasMes[monthNo];
    }

        function Calendario_calcula_mes_anyo(mes, anyo, incremento) 
    {
	    var ret_arr = new Array();	
	    if (incremento == -1) 
        {
		  
	        if (mes == 0) 
            {
                ret_arr[0] = 11;
		    	ret_arr[1] = parseInt(anyo) - 1;
	    	}	
            else 
            {
	    		ret_arr[0] = parseInt(mes) - 1;
	    		ret_arr[1] = parseInt(anyo);
		    }
	    }
       
        else if (incremento == 1) 
        {
		    if (mes == 11) 
            {
			    ret_arr[0] = 0;
    			ret_arr[1] = parseInt(anyo) + 1;
    		}
    		else
            {
			    ret_arr[0] = parseInt(mes) + 1;
    			ret_arr[1] = parseInt(anyo);
    		}
    	}	
	    return ret_arr;
    }

       function Calendario_print()
    {
	    calculo.print();
    }

     Calendario.prototype.getMonthlyCalendarioCode = function() 
    {
	    var vCode = "";
	    var vHeader_Code = "";
	    var vData_Code = "";
	
	    vCode = vCode + "<TABLE BORDER=1 BGCOLOR=\"" + this.gBGColor + "\">";	
	    vHeader_Code = this.cal_header();
	    vData_Code = this.cal_data();
	    vCode = vCode + vHeader_Code + vData_Code;	
	    vCode = vCode + "</TABLE>";	
	    return vCode;
    }

    Calendario.prototype.show = function() 
    {
	    var vCode = "";	
    	this.gWinCal.document.open();
	    this.wwrite("<html>");
	    this.wwrite("<head><title>Calendario</title>");
	    this.wwrite("</head>");
	    this.wwrite("<body " + 
		"link=\"" + this.gLinkColor + "\" " + 
		"vlink=\"" + this.gLinkColor + "\" " +
		"alink=\"" + this.gLinkColor + "\" " +
		"text=\"" + this.gTextColor + "\">");
	    this.wwriteA("<FONT FACE='" + familia_fuente + "' SIZE=2><B>");
    	this.wwriteA(this.dameMes + " " + this.gYear);
    	this.wwriteA("</B><BR>");    	
	    var prevMMYYYY = Calendario.calcula_mes_anyo(this.dameNumeroMes, this.gYear, -1);
    	var prevMM = prevMMYYYY[0];
    	var prevYYYY = prevMMYYYY[1];
	    var nextMMYYYY = Calendario.calcula_mes_anyo(this.dameNumeroMes, this.gYear, 1);
	    var nextMM = nextMMYYYY[0];
	    var nextYYYY = nextMMYYYY[1];	
	    this.wwrite("<TABLE WIDTH='100%' BORDER=0 CELLSPACING=0 CELLPADDING=0><TR><TD ALIGN=center>");
	    this.wwrite("[<A STYLE='font-size:10px;text-decoration:none;' HREF=\"" +
		"javascript:window.opener.Build(" + 
		"'" + this.gReturnp_item + "', '" + this.dameNumeroMes + "', '" + (parseInt(this.gYear)-1) + "', '" + this.gFormat + "'" +
		");" +
		"\"><<<\/A>]</TD><TD ALIGN=center>");
	    this.wwrite("[<A STYLE='font-size:10px;text-decoration:none;' HREF=\"" +
		"javascript:window.opener.Build(" + 
		"'" + this.gReturnp_item + "', '" + prevMM + "', '" + prevYYYY + "', '" + this.gFormat + "'" +
		");" +
		"\"><<\/A>]</TD><TD ALIGN=center>");
	    this.wwrite("[<A STYLE='font-size:10px;text-decoration:none;' HREF=\"javascript:window.print();\">Imprimir</A>]</TD><TD ALIGN=center>");
	    this.wwrite("[<A STYLE='font-size:10px;text-decoration:none;' HREF=\"" +
		"javascript:window.opener.Build(" + 
		"'" + this.gReturnp_item + "', '" + nextMM + "', '" + nextYYYY + "', '" + this.gFormat + "'" +
		");" +
		"\">><\/A>]</TD><TD ALIGN=center>");
	    this.wwrite("[<A STYLE='font-size:10px;text-decoration:none;' HREF=\"" +
		"javascript:window.opener.Build(" + 
		"'" + this.gReturnp_item + "', '" + this.dameNumeroMes + "', '" + (parseInt(this.gYear)+1) + "', '" + this.gFormat + "'" +
		");" +
		"\">>><\/A>]</TD></TR></TABLE><BR>");
	    vCode = this.getMonthlyCalendarioCode();
	    this.wwrite(vCode);
	    this.wwrite("</font></body></html>");
	    this.gWinCal.document.close();
    }

    Calendario.prototype.showY = function() 
    {
	    var vCode = "";
    	var i;
    	var vr, vc, vx, vy;
    	var vxf = 285;		
    	var vyf = 200;		
    	var vxm = 10;		
    	var vym;
    	if (isIE)	
            vym = 75;
    	else if (isNav)	
            vym = 25;	
    	this.gWinCal.document.open();
    	this.wwrite("<html>");
    	this.wwrite("<head><title>Calendario</title>");
    	this.wwrite("<style type='text/css'>\n<!--");
     	for (i=0; i<12; i++) 
        {
            vc = i % 3;
    		if (i>=0 && i<= 2)	vr = 0;
    		if (i>=3 && i<= 5)	vr = 1;
    		if (i>=6 && i<= 8)	vr = 2;
    		if (i>=9 && i<= 11)	vr = 3;		
    		vx = parseInt(vxf * vc) + vxm;
    		vy = parseInt(vyf * vr) + vym;
    		this.wwrite(".lclass" + i + " {position:absolute;top:" + vy + ";left:" + vx + ";}");
    	}
	    this.wwrite("-->\n</style>");
    	this.wwrite("</head>");
    	this.wwrite("<body " + 
		"link=\"" + this.gLinkColor + "\" " + 
		"vlink=\"" + this.gLinkColor + "\" " +
		"alink=\"" + this.gLinkColor + "\" " +
		"text=\"" + this.gTextColor + "\">");
    	this.wwrite("<FONT FACE='" + familia_fuente + "' SIZE=1><B>");
    	this.wwrite("Year : " + this.gYear);
    	this.wwrite("</B><BR>");
	    var prevYYYY = parseInt(this.gYear) - 1;
    	var nextYYYY = parseInt(this.gYear) + 1;	
    	this.wwrite("<TABLE WIDTH='100%' BORDER=1 BORDERCOLOR=RED CELLSPACING=0 CELLPADDING=0 BGCOLOR='#ffcc66'><TR><TD ALIGN=center>");
    	this.wwrite("[<A HREF=\"" +
		"javascript:window.opener.Build(" + 
		"'" + this.gReturnp_item + "', null, '" + prevYYYY + "', '" + this.gFormat + "'" +
		");" +
		"\" alt='Prev Year'><<<\/A>]</TD><TD ALIGN=center>");
	    this.wwrite("[<A HREF=\"javascript:window.print();\">Print</A>]</TD><TD ALIGN=center>");
    	this.wwrite("[<A HREF=\"" +
    	"javascript:window.opener.Build(" + 
		"'" + this.gReturnp_item + "', null, '" + nextYYYY + "', '" + this.gFormat + "'" +
		");" +
		"\">>><\/A>]</TD></TR></TABLE><BR>");
    	var j;
    	for (i=11; i>=0; i--) 
        {
    		if (isIE)
    			this.wwrite("<DIV ID=\"layer" + i + "\" CLASS=\"lclass" + i + "\">");
    		else if (isNav)
    			this.wwrite("<LAYER ID=\"layer" + i + "\" CLASS=\"lclass" + i + "\">");
    		this.dameNumeroMes = i;
    		this.dameMes = Calendario.get_month(this.dameNumeroMes);
    		vCode = this.getMonthlyCalendarioCode();
    		this.wwrite(this.dameMes + "/" + this.gYear + "<BR>");
    		this.wwrite(vCode);
    		if (isIE)
     			this.wwrite("</DIV>");
    		else if (isNav)
    			this.wwrite("</LAYER>");
    	}
    	this.wwrite("</font><BR></body></html>");
    	this.gWinCal.document.close();
    }

    Calendario.prototype.wwrite = function(wtext) 
    {
	    this.gWinCal.document.writeln(wtext);
    }

    Calendario.prototype.wwriteA = function(wtext) 
    {
	    this.gWinCal.document.write(wtext);
    }

    Calendario.prototype.cal_header = function() 
    {
	    var vCode = "";	
       	vCode = vCode + "<TR BGCOLOR='#336699'>";
    	vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + familia_fuente + "' COLOR='" + this.gHeaderColor + "'><B>Lunes</B></FONT></TD>";
    	vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + familia_fuente + "' COLOR='" + this.gHeaderColor + "'><B>Martes</B></FONT></TD>";
    	vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + familia_fuente + "' COLOR='" + this.gHeaderColor + "'><B>Miercoles</B></FONT></TD>";
    	vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + familia_fuente + "' COLOR='" + this.gHeaderColor + "'><B>Jueves</B></FONT></TD>";
    	vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + familia_fuente + "' COLOR='" + this.gHeaderColor + "'><B>Viernes</B></FONT></TD>";
    	vCode = vCode + "<TD WIDTH='16%'><FONT SIZE='2' FACE='" + familia_fuente + "' COLOR='" + this.gHeaderColor + "'><B>S&aacute;bado</B></FONT></TD>";
        vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + familia_fuente + "' COLOR='" + this.gHeaderColor + "'><B>Domingo</B></FONT></TD>";
       vCode = vCode + "</TR>";	
    	return vCode;
    }

    Calendario.prototype.cal_data = function()
    {
	    var vDate = new Date();
    	vDate.setDate(1);
    	vDate.setMonth(this.dameNumeroMes);
    	vDate.setFullYear(this.gYear);
    	var vFirstDay=vDate.getDay()-1;
    	var vDay=1;
    	var vLastDay=Calendario.get_diasdelmes(this.dameNumeroMes, this.gYear);
    	var vOnLastDay=0;
    	var vCode = "";
    	vCode = vCode + "<TR ALIGN= center BGCOLOR='#FFFFCC'>";
        if(vFirstDay==-1)
        {
            for (i=0; i<6; i++) 
            {
		        vCode = vCode + "<TD WIDTH='14%'" + this.write_festivos_string(i) + "><FONT SIZE='2' FACE='" + familia_fuente + "'>&nbsp;</FONT></TD>";
	        }
            for (j=6; j<7; j++) 
            {
    		    vCode = vCode + "<TD WIDTH='14%'" + this.write_festivos_string(j) + "><FONT SIZE='2' FACE='" + familia_fuente + "'>" + 
			    "<A HREF='#' " + 
			    "onClick=\"self.opener.document." + this.gReturnp_item + ".value='" + 
			    this.format_data(vDay) + 
			    "';window.close();\">" + 
			    this.format_day(vDay) + 
			    "</A>" + 
			    "</FONT></TD>";
    		    vDay=vDay+1;
    	   }
        }
        else
        {
            for (i=0; i<vFirstDay; i++) 
            {
		        vCode = vCode + "<TD WIDTH='14%'" + this.write_festivos_string(i) + "><FONT SIZE='2' FACE='" + familia_fuente + "'>&nbsp;</FONT></TD>";
	        }
    	for (j=vFirstDay; j<7; j++) 
        {
    		vCode = vCode + "<TD WIDTH='14%'" + this.write_festivos_string(j) + "><FONT SIZE='2' FACE='" + familia_fuente + "'>" + 
			"<A HREF='#' " + 
			"onClick=\"self.opener.document." + this.gReturnp_item + ".value='" + 
			this.format_data(vDay) + 
			"';window.close();\">" + 
			this.format_day(vDay) + 
			"</A>" + 
			"</FONT></TD>";
    		vDay=vDay+1;
    	}
        }
    	vCode = vCode + "</TR>";
    	for (k=2; k<7; k++) 
        {
		    vCode = vCode + "<TR ALIGN= center BGCOLOR='#FFFFCC'>";
            for (j=0; j<7; j++) 
            {
			    vCode = vCode + "<TD WIDTH='14%'" + this.write_festivos_string(j) + "><FONT SIZE='2' FACE='" + familia_fuente + "'>" + 
                "<A HREF='#' " + 
				"onClick=\"self.opener.document." + this.gReturnp_item + ".value='" + 
				this.format_data(vDay) + 
				"';window.close();\">" + 
	    		this.format_day(vDay) + 
		    	"</A>" + 
			    "</FONT></TD>";
			    vDay=vDay + 1;
        		if (vDay > vLastDay) 
                {
				    vOnLastDay = 1;
        			break;
	            }
		    }
		    if (j == 6)
			    vCode = vCode + "</TR>";
            if (vOnLastDay == 1)
	        	break;
         }
	     for (m=1; m<(7-j); m++) 
         {
		     if (this.dameAnyo)
			     vCode = vCode + "<TD WIDTH='14%'" + this.write_festivos_string(j+m) + 
			     "><FONT SIZE='2' FACE='" + familia_fuente + "' COLOR='gray'> </FONT></TD>";
		    else
			    vCode = vCode + "<TD WIDTH='14%'" + this.write_festivos_string(j+m) + 
			    "><FONT SIZE='2' FACE='" + familia_fuente + "' COLOR='gray'>" + m + "</FONT></TD>";
	     }	
	     return vCode;
     }

    Calendario.prototype.format_day = function(vday) 
    {
	    var vNowDay = ahora.getDate();
    	var vNowMonth = ahora.getMonth();
    	var vNowYear = ahora.getFullYear();
    	if (vday == vNowDay && this.dameNumeroMes == vNowMonth && this.gYear == vNowYear)
	    	return ("<FONT COLOR=\"RED\"><B>" + vday + "</B></FONT>");
    	else
    		return (vday);
    }

    Calendario.prototype.write_festivos_string = function(vday) 
    {
	    var i;
	    for (i=0; i<festivos.length; i++) 
        {
		    if (vday == festivos[i])
			    return (" BGCOLOR=\"" + festivosColor + "\"");
	    }	
	    return "";
    }

   Calendario.prototype.format_data = function(p_day) 
    {
    	var vData;
    	var vMonth = 1 + this.dameNumeroMes;
    	vMonth = (vMonth.toString().length < 2) ? "0" + vMonth : vMonth;
    	var vMon = Calendario.get_month(this.dameNumeroMes).substr(0,3).toUpperCase();
    	var vFMon = Calendario.get_month(this.dameNumeroMes).toUpperCase();
    	var vY4 = new String(this.gYear);
    	var vY2 = new String(this.gYear.substr(2,2));
    	var vDD = (p_day.toString().length < 2) ? "0" + p_day : p_day;
    	switch (this.gFormat) 
        {
		    case "MM\/DD\/YYYY" :
		    	vData = vMonth + "\/" + vDD + "\/" + vY4;
			    break;
		    case "MM\/DD\/YY" :
			   vData = vMonth + "\/" + vDD + "\/" + vY2;
			    break;
		    case "MM-DD-YYYY" :
			    vData = vMonth + "-" + vDD + "-" + vY4;
			    break;
		    case "MM-DD-YY" :
			   vData = vMonth + "-" + vDD + "-" + vY2;
               break;
		    case "DD\/MON\/YYYY" :
			    vData = vDD + "\/" + vMon + "\/" + vY4;
    			break;
    		case "DD\/MON\/YY" :
    			vData = vDD + "\/" + vMon + "\/" + vY2;
    			break;
    		case "DD-MON-YYYY" :
    			vData = vDD + "-" + vMon + "-" + vY4;
    			break;
    		case "DD-MON-YY" :
    			vData = vDD + "-" + vMon + "-" + vY2;
    			break;
    		case "DD\/MONTH\/YYYY" :
    			vData = vDD + "\/" + vFMon + "\/" + vY4;
    			break;
    		case "DD\/MONTH\/YY" :
    			vData = vDD + "\/" + vFMon + "\/" + vY2;
    			break;
    		case "DD-MONTH-YYYY" :
    			vData = vDD + "-" + vFMon + "-" + vY4;
    			break;
    		case "DD-MONTH-YY" :
    			vData = vDD + "-" + vFMon + "-" + vY2;
    			break;
    		case "DD\/MM\/YYYY" :
    			vData = vDD + "\/" + vMonth + "\/" + vY4;
    			break;
    		case "DD\/MM\/YY" :
    			vData = vDD + "\/" + vMonth + "\/" + vY2;
    			break;
    		case "DD-MM-YYYY" :
        		vData = vDD + "/" + vMonth + "/" + vY4;
    			break;
    		case "DD-MM-YY" :
    			vData = vDD + "-" + vMonth + "-" + vY2;
    			break;
    		default :
			vData = vMonth + "\/" + vDD + "\/" + vY4;
	    }
	    return vData;
    }

   function Build(p_item, mes, anyo, formato) 
    {
	    var p_WinCal = calculo;
	    gCal = new Calendario(p_item, p_WinCal, mes, anyo, formato);
    	gCal.gBGColor="#336699";
    	gCal.gLinkColor="black";
    	gCal.gTextColor="black";
    	gCal.gHeaderColor="WHITE";
    	if (gCal.dameAnyo)	
            gCal.showY();
    	else
            gCal.show();
    }

   function show_Calendario() 
    {
	    p_item = arguments[0];
      	if (arguments[1] == null)
	    	mes = new String(ahora.getMonth());
    	else
    		mes = arguments[1];
       	if (arguments[2] == "" || arguments[2] == null)
    		anyo = new String(ahora.getFullYear().toString());
    	else
    		anyo = arguments[2];    	
        if (arguments[3] == null)
    		formato = "DD-MM-YYYY";
	    else
		    formato = arguments[3];
	    
        vWinCal = window.open("", "Calendario", "width=450,height=250,status=no,resizable=no,top=200,left=200");
	    vWinCal.opener = self;
	    calculo = vWinCal;
	    Build(p_item, mes, anyo, formato);
    }
  
    function show_yearly_Calendario(p_item, anyo, formato) 
    {
	  
	    if (anyo == null || anyo == "")
		    anyo = new String(ahora.getFullYear().toString());
	    if (formato == null || formato == "")
		    formato = "DD/MM/YYYY";
	    var vWinCal = window.open("", "Calendario", "scrollbars=no");
	    vWinCal.opener = self;
	    calculo = vWinCal;
	    Build(p_item, null, anyo, formato);
    }
	

//Validar rango de fechas
function fecha_menor_o_igual_que(fecha1, fecha2)
{ 
    var bRes = false; 
    var sDia0 = fec0.value.substr(0, 2); 
    var sMes0 = fec0.value.substr(3, 2); 
    var sAno0 = fec0.value.substr(6, 4); 
    var sDia1 = fec1.value.substr(0, 2); 
    var sMes1 = fec1.value.substr(3, 2); 
    var sAno1 = fec1.value.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;
} 



/****************************************************************************************
*       Funcion que retira todos los espacio a la derecha e izquierda de una cadena		*
*																						*
*****************************************************************************************/ 
//Variables Globales
cont=0;

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;
}

/****************************************************************************************
*       Funcion que evita el reenvio de formularios										*
*																						*
*****************************************************************************************/ 
function enviado() { 

if (cont == 0)
{
cont++;
return true;
}
else 
{
alert("El siguiente formulario ya ha sido enviado, muchas gracias.");
return false;
}
}

/****************************************************************************************
*       Funcion que valida el ingreso de solo numeros en un campo de texto*
*																						*
*****************************************************************************************/ 
function acceptFloat(evt){	
	// NOTE: Backspace = 8, Enter = 13, '0' = 48, '9' = 57	
	var nav4 = window.Event ? true : false;
	var key = nav4 ? evt.which : evt.keyCode;	
	//return (key <= 13 || (key >= 48 && key <= 57) || key == 46);
	return (key <= 13 || (key >= 48 && key <= 57));
}


/****************************************************************************************
*       Funcion para combos dependientes												*
*																						*
*****************************************************************************************/ 
 var peticion = false;
 var  testPasado = false;
 try {
   peticion = new XMLHttpRequest();
   } catch (trymicrosoft) {
   try {
   peticion = new ActiveXObject("Msxml2.XMLHTTP");
   } catch (othermicrosoft) {
  try {
  peticion = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (failed) {
  peticion = false;
  }
  }
}
if (!peticion)
alert("ERROR AL INICIALIZAR!");
 
function cargarCombo (url, comboAnterior, element_id) {

//Obtenemos el contenido del div
//donde se cargaran los resultados
var element =  document.getElementById(element_id);
//Obtenemos el valor seleccionado del combo anterior
var valordepende = document.getElementById(comboAnterior)
var x = valordepende.value
//construimos la url definitiva
//pasando como parametro el valor seleccionado
var fragment_url = url+x;
element.innerHTML = '<img src="Imagenes/loading.gif" />';
//abrimos la url
peticion.open("GET", fragment_url);
peticion.onreadystatechange = function() {
if (peticion.readyState == 4) {
//escribimos la respuesta
element.innerHTML = peticion.responseText;
}
}
peticion.send(null);
}
/***********************************************************************************
       07/08/2006
	   Marvin Zabala
       Permite la entrada de numeros, letras y espacio en una cadena; sin caracteres especiales
***********************************************************************************/
/*function esalfanum(cadena)
{ 
  if(cadena.value.match(/[^a-z,ñ,0-9, \ ]/)) 
  	{ 
    cadena.value=cadena.value.replace(/[^a-z,ñ,0-9, \ ]/gi,"") 
  	}
}*/
 
/***********************************************************************************
       07/08/2006
	   Marvin Zabala
       Valida entrada de formato de correo		
***********************************************************************************/
function esemail_old(valor,obj) 
{
	var mail=0;
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor))
     {
   	 mail=1;
  	 } 
  else 
	 {
   	 alert("La dirección de correo es incorrecta.");
     obj.value="";
	 //obj.focus();
   	 mail=2;
     }
	 return mail;
 }
function esemail(valor,obj)
{ 
    var pos1, pos2, bOk = true; 
    var sDir = valor; 
    pos1 = sDir.indexOf('@', 0); 
    pos2 = sDir.indexOf('.', 0);
    pos3 = sDir.indexOf(' ', 0);
    bOk = bOk && (pos1 > 0); 
    bOk = bOk && (pos2 != -1); 
    bOk = bOk && (pos3 < 0); 
    bOk = bOk && (pos2 < sDir.length - 1); 
    if (!bOk){ 
     alert("Dirección de correo inválida"); 
	 obj.value="";
	 mail = 2;
	}
	else{
		mail = 1;
    } 
    return mail; 
} 


/***********************************************************************************
       15/08/2006
	   Rafael Salinas
       Rutina para impresion de vistas preliminares
***********************************************************************************/

function printIt(nombre) {
  ficha = window.document.getElementById(nombre);
  win = window.open('','Vent','height=400,width=600,scrollbars=yes');
  self.focus();
  win.document.open();
  win.document.write("<link href='css/estilo1.css' rel='stylesheet' type='text/css'></br>"+ficha.innerHTML);
  win.document.close();
  win.print();
  win.close();
}

function printIt2(nombre) {
  ficha = window.document.getElementById(nombre);
  win = window.open('','Vent','height=400,width=600,scrollbars=yes');
  self.focus();
  win.document.open();
  win.document.write("<link href='../css/estilo1.css' rel='stylesheet' type='text/css'></br>"+ficha.innerHTML);
  win.document.close();
  win.print();
  win.close();
}

/***********************************************************************************
       15/08/2006
	   Angi Arias
       Rutina para ocultar vinculos en bara de estado
***********************************************************************************/

<!--
/**var current = 0;	
var x = 0;
var speed = 100;
var speed2 = 2000;

function initArray(n) {
  this.length = n;
  for (var i =1; i <= n; i++) {
    this[i] = ' ';
  }
}

typ = new initArray(4);
typ[0]="SIDCAI...";
typ[1]="Sistema de Declaración de Aportes-Inversiones en Ciencia, Tecnología e Innovación";
typ[2]="Dirección General de Financiamiento";
typ[3]="Ministerio de Ciencia y Tecnología";

function typewrite() {
var m = typ[current];

window.status = m.substring(0, x++) + "_";

if (x == m.length + 1) {
x = 0;
current++;

if (current > typ.length - 1) {
current = 0;
}

setTimeout("typewrite()", speed2);
}

else {
setTimeout("typewrite()", speed);
}
}

typewrite();**/

/****************************************************************************************
       17/08/2006
	   Gregoria Quintero
       Funcion para colocar formato de moneda  000,000,000.00
****************************************************************************************/
function FormatCurrency(objNum)
  {
      /*if(objNum=='txt_subtotal_bs')
      {
        //alert(document.getElementById(objNum).value);
        num = document.getElementById(objNum).value
      }
      else*/
      var num = objNum.value;
      var ent, dec;
      if (num != '' && num != objNum.oldvalue)
      {
           num = MoneyToNumber(num);
           if (isNaN(num) )
           {
                if(isNaN(objNum.oldvalue))
                objNum.value="";
                else
                objNum.value = objNum.oldvalue;
           }
           else
           {//alert(num.split('.')[0])
                var ev = (navigator.appName.indexOf('Netscape') !=
-1)?Event:event;
                if (ev.keyCode == 190 || !isNaN(num.split('.')[1]))
                {//alert(num.split('.')[0])
                     objNum.value =
AddCommas(num.split('.')[0])+'.'+num.split('.')[1].substring(0,2);
                     //objNum.value = AddCommas(num.split('.')[0]);
                }
                else
                {//alert(num.split('.')[0])
                     objNum.value = AddCommas(num.split('.')[0]);
                }
                objNum.oldvalue = objNum.value;
           }
      }
    return
  }
// fin de FormatCurrency
/****************************************************************************************
       17/08/2006
	   Gregoria Quintero
       Funcion para pasar de formato de moneda a numerico
****************************************************************************************/
  function MoneyToNumber(num)
  {
      return (num.replace(/,/g, ''));
 
  }
// fin de MoneyToNumber

/****************************************************************************************
       17/08/2006
	   Gregoria Quintero
       Funcion para agregar comas al formato moneda
****************************************************************************************/
  function AddCommas(num)
  {
      numArr=new String(num).split('').reverse();
      for (i=3;i<numArr.length;i+=3)
      {
           numArr[i]+=',';
      }
      return numArr.reverse().join('');
  }
  // fin de AddCommas
// Esta funcion da formato al monto completo
/*/////////////////////////////////////////////////////////////*/
function formatoMoneda(num)
{       
    var sVal='';
    var minus='';
    var Decimal='.';
    var num = new String(num);

    if (num.lastIndexOf(Decimal) < 0)
    	num = num + '00';
    	
    num = verificarFormato(num);
    sVal = formatoEntero(num,'.') + ',' + formatoCentimos(num); 
    
    return sVal;
}

/****************************************************************************************
       29/08/2006
	   Rafael Salinas
       Funcion que sólo permite numeros y la coma, solo permitiendo 2 decimales.
*****************************************************************************************/ 
function acceptaNumeros(evt,objeto){	
	// NOTE: Backspace = 8, Enter = 13, '0' = 48, '9' = 57	 
	//alert(evt.keyCode);
	var valorCampo; 
	var numPosPunto = 0; 
	var strParteEntera = ""; 
	var strParteDecimal = ""; 
	var NUM_DECIMALES = 2; 

	var nav4 = window.Event ? true : false;
	var key = nav4 ? evt.which : evt.keyCode;
	
	
	valorCampo = objeto.value; 
		if (key == 44) 
    	if (valorCampo.indexOf(",") != -1) 
		{ 
			//evt.keyCode = 0; 
			
			return false; 
		} 
		
		/* Sólo puede teclear el número de decimales indicado en NUM_DECIMALES */ 
		if ((numPosPunto = valorCampo.indexOf(",")) != -1) 
		{ 
			strParteEntera = valorCampo.substr(0,(numPosPunto - 1)); 
			strParteDecimal = valorCampo.substr((numPosPunto + 1), valorCampo.length) 
			if (strParteDecimal.length > (NUM_DECIMALES - 1)) 
			{ 
				//evt.keyCode = 0; 
				if (key!=8) {
					return false;
				}
			} 
		} 
		
		return (key <= 13 || (key >= 48 && key <= 57) || key==44);
	
}


/*************************************************************************************************************************
        05/09/2006
	   Rafael Salinas
       Funcion que recibe un numero con separador de decinmal y devuelve el mismo numero agregandole los puntos
	   de separadores de miles.
*****************************************************************************************/
 function formatNmb(numero, tipo){ 
 // tipo 0, el numero viene con , para decimales
 // tipo 1, el numero viene con . para deciamles
    var sRes = ""; 
	var entero="";
	var decimal="";
	var posicion=0;
	if (tipo==0) {
		posicion=numero.indexOf(',');  //  123,32
	} else {
		posicion=numero.indexOf('.');  // 123.32
	}
	if (posicion!= -1) {
		entero=numero.substr(0,posicion);
		decimal=numero.substr(posicion+1, (numero.length-posicion-1));
		if (decimal=='') {
			decimal='00';
		}
	} else {
		if (numero!='') {
			entero=numero;
		} else { 
			entero='0';
		}
		decimal='00';
	}
	
    for (var j, i = entero.length - 1, j = 0; i >= 0; i--, j++) 
     sRes = entero.charAt(i) + ((j > 0) && (j % 3 == 0)? ".": "") + sRes; 
	 
	 sRes=sRes+','+decimal;
    return sRes; 
   } 
   
/***************************************************************************************************************************
        05/09/2006
	   Rafael Salinas
       Funcion que recibe un numero con separador de deciamles con coma y lo sustituye por puntos
************************************************************************************************************************/

function sustituye_coma(numero){ 
    var sRes = ""; 
	var entero="";
	var decimal="";
	var posicion=0;
	
	posicion=numero.indexOf(',');  //  123,32
	if (posicion!= -1) {
		entero=numero.substr(0,posicion);
		decimal=numero.substr(posicion+1, (numero.length-posicion-1));
	} else {
		entero=numero;
		decimal='00';
	}
	sRes=entero+'.'+decimal;
	return sRes;

}

/***************************************************************************************************************************
        13/10/2006
	   Angi Arias
       Funcion que abre ventanas hijas o pop ups dado el url
************************************************************************************************************************/

function ventana(pagina) {
var opciones="toolbar=no, location=no, directories=no, status=yes, menubar=no, scrollbars=no, resizable=yes, width=550, height=400, top=85, left=140";
window.open(pagina,"",opciones);
}

/***************************************************************************************************************************
        01/11/2006
	   Rafael Salinas
       Rutina para volver atras (history.back)
************************************************************************************************************************/
function rutina_volver_atras() {
	//var pagina="scwblank.html"; 
	//var url=document.referrer;
	//partes = url.split('/'); alert(history.previous);
	// Obtención del nombre de la página y sus parámetros. 
	//if ((partes[partes.length-1])==pagina) { 
	if (document.getElementById('scwIFrame')) { 
		history.back();
		history.back();
	} else {
		history.back();
	}
}