/**************************************************************************************************/
// ZetaMMNumero

		function ValidacionDeNumero( Source )					
		{														
			var Tecla = window.event.keyCode;												
			if	((Tecla>=48)&&(Tecla<=57))						
			{													
			}													
			else												
			{													
				if ( (Tecla==45) && (Source.value.length < 1) )						
				{												
				}												
				else											
				{												
					if(Tecla == 13)								
						Source.blur();														
					window.event.returnValue = false;			
				}												
			}													
		}
		
		function ValidacionDeFlotante( Source )							
		{																	
			var Tecla = window.event.keyCode;															
			if	((Tecla>=48)&&(Tecla<=57))									
			{																
			}																
			else															
			{																
				if ((Tecla==46)&&											
				(Source.value.indexOf('.',Source.value.indexOf('.'))==-1))	
				{															
				}															
				else														
				{																						
					if ((Tecla==45)&&										
					(Source.value.length < 1))								
					{														
					}														
					else													
					{														
						if(Tecla == 13)										
							Source.blur();																
						window.event.returnValue = false;		
					}														
				}															
			}																
		}																	
		
		
		function CompletarFlotante( Source )								
		{																	
			if (Source.value.indexOf('.')==0)								
			{																
				Source.value	= '0'+Source.value;							
			}																
																			
			if	((Source.value.indexOf('.') == (Source.value.length-1))&&	
				(Source.value.indexOf('.')!=-1))							
			{																
				Source.value	= Source.value + '00';						
			}																
																			
			if	((Source.value.indexOf('.') == (Source.value.length-2))&&	
				(Source.value.indexOf('.')!=-1))							
			{																
				Source.value	= Source.value + '0';						
			}						
																			
			if	(( Source.value.indexOf('.') ==-1 )&&(Source.value.length>0))									
			{																
				Source.value	= Source.value + '.00';						
			}																
		}	

/**************************************************************************************************/
//ZetaMMFecha

			var _mes1 	= "ENE";																																										
			var _mes2 	= "FEB";																																										
			var _mes3 	= "MAR";																																										
			var _mes4 	= "ABR";																																										
			var _mes5 	= "MAY";																																										
			var _mes6 	= "JUN";																																										
			var _mes7 	= "JUL";																																										
			var _mes8 	= "AGO";																																										
			var _mes9 	= "SEP";																																										
			var _mes10 	= "OCT";																																										
			var _mes11 	= "NOV";																																										
			var _mes12	= "DIC";																																										
			var NumCaracteres	= 0;																																									
			var separador		= "/";																																								
			var bandera			= false;																																								
			function _FechaValida(source,caso)																																						
			{																																														
				temp 	= false;																																									
				sepIni = source.value.indexOf(separador,0);																																			
				sepFin = source.value.indexOf(separador,sepIni+1);																																	
				if (  (sepIni>0)&&(sepFin>0)&&((sepIni+1)<sepFin)&&(sepFin <(source.value.length-1))  )																								
				{																																													
					sepOk=true;																																										
				}																																													
				else																																												
				{																																													
					sepOk=false;																																									
				};																																													
				if (caso==0)																																										
				{																																													
					day 	= (source.value.substring(0,sepIni));																																	
					month 	= (source.value.substring(sepIni+1,sepFin));																															
				}																																													
				else																																												
				{																																													
					month 	= (source.value.substring(0,sepIni));																																	
					day 	= (source.value.substring(sepIni+1,sepFin));																															
				};																																													
				year 	= parseInt( source.value.substr(sepFin+1,source.value.length-(sepFin+1))  );																								
				if ( !isNaN(day) && !isNaN(month) && !isNaN(year) && (source.value.length<=10)&& sepOk  )																							
				{																																													
					if (year<50)																																									
					{																																												
						year = year + 2000;																																							
					};																																												
					if ((year>=50)&&(year<100))																																						
					{																																												
						year = year + 1900;																																							
					};																																												
					viciesto = (year%4)==0;																																							
					viciesto = viciesto & (((year%100)!=0)||((year%1000)==0));																														
					if ((year>1899)&&(year<3999))																																					
					{																																												
						if	(																																										
							(month==1)||(month==3)||(month==5)||(month==7)||																														
							(month==8)||(month==10)||(month==12)																																	
							)																																										
						{																																											
							if (day<=31)																																							
							{																																										
								temp = true;																																						
							};																																										
						};																																											
						if	(																																										
							(month==4)||(month==6)||(month==9)||																																	
							(month==11)||(month==10)||(month==12)																																	
							)																																										
						{																																											
							if (day<=30)																																							
							{																																										
								temp = true;																																						
							};																																										
						};																																											
						if (month==2)																																								
						{																																											
							if (  (viciesto) && (day==29)  )																																		
							{																																										
								temp = true;																																						
							};																																										
							if (day<=28)																																							
							{																																										
								temp = true;																																						
							};																																										
						};																																											
					};																																												
				};																																													
				if (temp)																																											
				{																																													
					if (day.length==1)																																								
					{																																												
						strDia ="0";																																								
					}																																												
					else																																											
					{																																												
						strDia="";																																								
					};																																												
					if (month.length==1)																																							
					{																																												
						strMes ="0";																																								
					}																																												
					else																																											
					{																																												
						strMes="";																																								
					};																																												
					switch(strMes+month)																																							
					{																																												
						case "01": MesTexual=_mes1;break;																																			
						case "02": MesTexual=_mes2;break;																																			
						case "03": MesTexual=_mes3;break;																																			
						case "04": MesTexual=_mes4;break;																																			
						case "05": MesTexual=_mes5;break;																																			
						case "06": MesTexual=_mes6;break;																																			
						case "07": MesTexual=_mes7;break;																																			
						case "08": MesTexual=_mes8;break;																																			
						case "09": MesTexual=_mes9;break;																																			
						case "10": MesTexual=_mes10;break;																																		
						case "11": MesTexual=_mes11;break;																																		
						case "12": MesTexual=_mes12;break;																																		
						default: 																																									
						MesTexual = strMes+month;																																					
					};																																												
					if (caso==0)																																									
					{																																												
						source.value = strDia+day+separador+MesTexual+separador+year;																												
					}																																												
					else																																											
					{																																												
						source.value = MesTexual+separador+strDia+day+separador+year;																												
					};																																												
				};																																													
				return temp;																																										
			};																																														
			function _TeclaCodeComplete(componente,caso)																																			
			{																																														
				Tecla = window.event.keyCode - 48;																																					
				if (caso==0)																																										
				{																																													
					if ((NumCaracteres==0)&&(Tecla>=4))																																				
					{																																												
						__Agrega(componente,"0");																																					
					};																																												
					if ((NumCaracteres==3)&&(Tecla>=2))																																				
					{																																												
						__Agrega(componente,"0");																																					
					};																																												
				}																																													
				else																																												
				{																																													
					if ((NumCaracteres==0)&&(Tecla>=2))																																				
					{																																												
						__Agrega(componente,"0");																																					
					};																																												
					if ((NumCaracteres==3)&&(Tecla>=4))																																				
					{																																												
						__Agrega(componente,"0");																																					
					};																																												
				};																																													
			};																																														
			function _ValidacionFinal(componente,caso)																																				
			{																																														
				if (_FechaValida(componente,caso))																																					
				{																																													
				}																																													
				else																																												
				{																																													
					if (componente.value!="")																																						
					{																																												
						__Selecciona(componente);																																					
					}																																												
				}																																													
			};																																														
			function __Selecciona(componente)																																						
			{																																														
				componente.focus();																																									
				componente.select();																																								
			};																																														
			function _ComponenteSeleccionado(componente)																																			
			{																																														
				NumCaracteres =  componente.value.length;																																			
			};																																														
			function _TeclasFiltrado(componente,caso)																																				
			{																																														
				temp = false;																																										
				if 	(																																												
					((window.event.keyCode>=48)&&(window.event.keyCode<=57  ))																														
					)																																												
				{																																													
					if ( (componente.value.length <10) || (window.event.keyCode==8)|| (bandera) )																											
					{																																														
					bandera=false;																																										
						if ((componente.value.length==2)||(componente.value.length==5))																														
						{																																														
							__Agrega(componente,separador);																																						
						}																																														
						_TeclaCodeComplete(componente,caso);																																					
						temp =true;																																											
					}																																																
				};																																														
				switch (window.event.keyCode)																																							
				{																																														
					case 45:																																												
					case 47:																																												
					if((componente.value.length==2)||(componente.value.length==5))																															
					{																																														
						__Agrega(componente,separador);																																						
					}																																														
					if(componente.value.length==1)																																							
					{																																														
						componente.value = "0" + componente.value;																																			
						NumCaracteres++;																																										
						__Agrega(componente,separador);																																						
					};																																														
					if(componente.value.length==4)																																							
					{																																														
						componente.value = componente.value.substring(0,3)+ "0" + componente.value.substring(3,4);																							
						NumCaracteres++;																																										
						__Agrega(componente,separador);																																						
					};																																														
					break;																																													
				};																																														
				window.event.returnValue = temp;																																						
			};																																														
		function _TerminoPresionTecla(componente)																																				
			{																																														
				NumCaracteres = componente.value.length;																																				
				if ( 																																													
						((window.event.keyCode>=96)&&(window.event.keyCode<=105))||(window.event.keyCode==8)||																								
						((window.event.keyCode>=48)&&(window.event.keyCode<=57))||(window.event.keyCode==8)																									
				)																																														
				{																																														
				if(((NumCaracteres==2)||(NumCaracteres==5))&&(window.event.keyCode!=8))																												
					{																																														
						__Agrega(componente,separador);																																						
					};																																														
				}																																														
				else																																													
				{																																														
				}																																															
			};																																														
			function __Agrega(componente,caracter)																																					
			{																																														
					NumCaracteres = NumCaracteres +1;																																						
					componente.value = componente.value.substr(0,NumCaracteres-1)+caracter;																												
					if ((NumCaracteres==2)||(NumCaracteres==5))																																			
					{																																														
						_Agrega(componente, separador );																																						
					};																																														
			};																																															
			function _ComponenteFocus(source,caso)																																					
			{																																														
				temp 	= false;																																											
				sepIni = source.value.indexOf(separador,0);																																				
				sepFin = source.value.indexOf(separador,sepIni+1);																																		
				if (  (sepIni>0)&&(sepFin>0)&&((sepIni+1)<sepFin)&&(sepFin <(source.value.length-1))  )																									
				{																																														
					sepOk=true;																																											
				}																																														
				else																																													
				{																																														
					sepOk=false;																																											
				};																																														
				if (caso==0)																																											
				{																																														
					day 	= (source.value.substring(0,sepIni));																																						
					month 	= (source.value.substring(sepIni+1,sepFin));																																		
				}																																														
				else																																													
				{																																														
					month 	= (source.value.substring(0,sepIni));																																					
					day 	= (source.value.substring(sepIni+1,sepFin));																																			
				};																																														
				year 	= parseInt( source.value.substr(sepFin+1,source.value.length-(sepFin+1))  );																										
				if (sepOk)																																												
				{																																														
					switch (month)																																											
					{																																														
						case _mes1: monthNum="01";break;																																					
						case _mes2: monthNum="02";break;																																					
						case _mes3: monthNum="03";break;																																					
						case _mes4: monthNum="04";break;																																					
						case _mes5: monthNum="05";break;																																					
						case _mes6: monthNum="06";break;																																					
						case _mes7: monthNum="07";break;																																					
						case _mes8: monthNum="08";break;																																					
						case _mes9: monthNum="09";break;																																					
						case _mes10: monthNum="10";break;																																					
						case _mes11: monthNum="11";break;																																					
						case _mes12: monthNum="12";break;																																					
						default:																																												
						monthNum=month;																																										
					}; 																																													
					if (caso==0)																																											
					{																																														
						source.value=day+separador+monthNum+separador+year;																																	
					}																																														
					else																																													
					{																																														
						source.value=monthNum+separador+day+separador+year;																																	
					}																																														
				};																																														
				source.select();																																										
				bandera=true;																																											
			};
				


/**************************************************************************************************/
// ZetaMMCalendario

var txtFecha;
var posCalendarX;
var posCalendarY;
var dialogFecha = null;


// valid range for yy is 1901 to 2100 inclusive or zero for current year
// valid range for mm is 1 to 12 or zero for current month
 


function calendario(yy,mm,dd,source)
{
	posCalendarX = event.x;
	posCalendarY = event.y;
	
	txtFecha = getElement(source);
	var Fecha = getFecha(txtFecha);
	calendar(Fecha.getFullYear(),Fecha.getMonth() + 1, Fecha.getDate() );
}

function calendar(yy,mm,dd) 
{
	var daysInMonth;
	if (mm < 1)
	{
		mm = 1;
	}
	if (mm > 12) 
	{
		mm = 12;
	} 
	if (yy != 0 && (yy < 1901 || yy > 2100)) 
	{
		yy = new Date().getFullYear();
	} 
	switch(mm)
	{
		case 1: 
		case 3: 
		case 5: 
		case 7: 
		case 8: 
		case 10: 
		case 12:
			daysInMonth = 31; 						
			break; 
		case 4: 
		case 6: 
		case 9: 
		case 11:
			daysInMonth = 30;						
			break; 
		case 2:			
			if (yy%4!=0 || (yy%100==0 && yy%400!=0))
			{				
				daysInMonth = 28;				
			}
			else
			{
				daysInMonth = 29;								
			}
			break; 
	}	
	if (dd < 1 )
	{
		dd = 1;
	}
	if (dd > daysInMonth)
	{
		dd=daysInMonth;		
	}
	var scriptValidacion =	'				var Tecla = window.event.keyCode;					\n'+														
							'				if	((((Tecla>=48)&&(Tecla<=57))||Tecla==8 || Tecla==13 || Tecla==46 || Tecla==45)&& event.srcElement.type== "text")\n'+
							'				{													\n'+							
							'					if(Tecla == 13)									\n'+
							'					{												\n'+															
							'						cambioYear();								\n'+
							'					}												\n'+
							'				}													\n'+
							'				else												\n'+
							'				{													\n'+
							'																	\n'+			
							'					event.keyCode = 0;								\n'+               																								
							'					event.returnValue = false;						\n'+               
							'				}													\n';
							
	var scriptCambioDia =   'if (event.srcElement.innerText.replace(" ","").length > 0)					\n\t\t\t\t'+		
							'	self.opener.calendar(' + yy + ',' + mm + ',event.srcElement.innerText);\n';		
							
	var scriptCambioYear =  'if (txtYear.value != "' + yy + '")													\n\t\t\t\t'+
							'{													\n\t\t\t\t\t'+													
							'self.opener.calendar(txtYear.value,' + mm + ',' + dd + ');\n\t\t\t	'+							
							'}													';																		
	var scriptBtnAceptar =  'self.opener.setDate("' + dd + '/' + mm + '/' + yy + '"); \n\t\t\t\tself.close();';								
	
	var dow = new Array('Dom','Lun','Mar','Mie','Jue','Vie','Sab');
	var moy = new Array('Enero','Febrero','Marzo','Abril','Mayo','Junio','Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre'); 
	var calendar = new Date(); 	
	calendar.setFullYear(yy,mm-1,dd);
	var year = calendar.getFullYear();
	var month = calendar.getMonth(); 	
	var today = dd; 	
	var weekday = calendar.getDay();
			 	
	var hilite_start = '\n\t\t\t\t\t\t\t<td class="CAL_DIA_ACTUAL">';
	var td_daysofweek = '\n\t\t\t\t\t\t\t<td class="CAL_DIA_SEMANA">'; 
	var td_days = '\n\t\t\t\t\t\t\t<td onclick="cambioDia()" class="CAL_DIA_MES">'; 
	var selectMes = '<select name="cboMeses" language="javascript" id="cboMeses" class="LETREROS_NOMBRES" onchange="cambioMes();">\n';//
	for (iMes=0; iMes<12; iMes++)
	selectMes +='\n\t\t\t\t\t\t\t<option value="' + (iMes + 1) + '">' + moy[iMes] + '</option>';
	selectMes +='\n\t\t\t\t\t\t</select>';
	var selectYear = '<input name="txtYear" type="text" value="' + yy + '" id="txtYear" class="LETREROS_NOMBRES" style="WIDTH:50px;" onchange="javascript:cambioYear();"/>';	
	var cal = '\n\t\t<table  border="0" cellspacing="2" cellpadding="1">\n\t\t\t<tr>\n\t\t\t\t<td width="50%" align="Left" class="LETREROS">\n\t\t\t\t\t\tMes: ' + selectMes + '\n\t\t\t\t</td>\n\t\t\t\t<td width="50%" align="right" class="LETREROS">\n\t\t\t\t\t\tA&#241;o: ' + selectYear + '\n\t\t\t\t</td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td colspan="2" align="center">';		
	cal += '\n\t\t\t\t\t<table cellspacing="0" cellpadding="2",  class="CALENDARIO" width="100%">\n\t\t\t\t\t\t<tr>';//\n\t\t\t\t\t\t\t<td colspan="7" class="CAL_TITULO">'; 		
	for(dex=0; dex < 7; dex++) 
	{
		if(weekday == dex) 
			cal += td_daysofweek + '<b>' + dow[dex] + '</b></td>';
		else 
			cal += td_daysofweek + dow[dex] + '</td>';		
	} 	
	cal += '</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr>'; 	
	var day2 = today; 
	for (dex = today; dex > 6; dex -=7)
	{ 	
		day2 = dex; 
	}
	
	weekday -= day2 - 1; 
	if (weekday < 0) 
		weekday += 7; 
	if (weekday < 0)
		weekday += 7; 
	
	for(dex=0; dex < weekday; dex++) 
		cal += td_days + '&nbsp;</td>';
	for(dex=0; dex < daysInMonth; dex++) 
	{
		if(weekday == 7) 
		{
			cal += '\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr>'; 
			weekday = 0;
		} 
		if( today==dex + 1 ) 
			cal += hilite_start + (dex + 1) + '</td>'; 
		else 
			cal += td_days + (dex + 1) + '</td>'; weekday += 1;
	} 	
	for(dex=weekday; dex < 7; dex++) 
		cal += td_days + '&nbsp</td>';		
	dialogFecha = window.open('','calendar','height=215,width=285,toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,left='+ posCalendarX + ',top=' + posCalendarY); 			
	dialogFecha.document.open();
	dialogFecha.document.clear();			
	dialogFecha.document.write('<html>\n\t<head>\n\t\t<title>Calendario</title>\n\t\t<script language="javascript"> \n\t\t\tfunction cambioMes()\n\t\t\t{\n\t\t\t\tself.opener.calendar(' + yy + ', self.cboMeses.selectedIndex + 1,' + dd + ');\n\t\t\t}\n\n\t\t\tfunction Tecla()\n\t\t\t{\n' + scriptValidacion + '\t\t\t}\n\n\t\t\tfunction cambioDia()\n\t\t\t{\n\t\t\t\t' + scriptCambioDia + '\t\t\t}\n\n\t\t\tfunction cambioYear()\n\t\t\t{\n\t\t\t\t' + scriptCambioYear + '\n\t\t\t}\n\n\t\t\tfunction btnAceptar()\n\t\t\t{\n\t\t\t\t' + scriptBtnAceptar + '\n\t\t\t}\n\n\t\t</script>\n\t\t<LINK type="text/css" rel="stylesheet" href="./CSS/Calendario.css"/>\n\t</head>\n\t<body style="overflow:hidden;" onkeydown="Tecla();">'); 		
	dialogFecha.document.write(cal += '\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t</table>\n\t\t\t\t</td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td colspan="2" align="center">\n\t\t\t\t\t<Input type="button" value="Aceptar" class="LETREROS" onclick="btnAceptar()"/>&nbsp;\n\t\t\t\t\t<Input type="button" value="Cancelar" class="LETREROS" onclick="self.close();return false;"/>\n\t\t\t\t</td>\n\t\t\t</tr>\n\t\t</table>\n\t</body>\n</html>'); 	
	dialogFecha.document.close();
	dialogFecha.cboMeses.selectedIndex = mm-1;
	return true;
}


function setDate(Fecha)
{  
  txtFecha.focus();
  txtFecha.value = Fecha;    
  if (txtFecha.onchange != null)
    txtFecha.onchange();  
  else
	txtFecha.blur();
}

function addDay(source)
{	
	
	txtFecha = getElement(source);	
	var Fecha = getFecha(txtFecha);
	Fecha.setDate(Fecha.getDate() + 1);
	setDate(Fecha.getDate() + "/" + (Fecha.getMonth() + 1) + "/" + Fecha.getFullYear());
}

function subDay(source)
{	
	txtFecha = getElement(source);	
	var Fecha = getFecha(txtFecha);
	Fecha.setDate(Fecha.getDate() - 1);	
	setDate(Fecha.getDate() + "/" + (Fecha.getMonth() + 1) + "/" + Fecha.getFullYear());
}

function isThisMes(mes, nombre)
{	
	switch (mes)
	{
		case 0:
			return nombre.toLowerCase() == "ene";			
		case 1:
			return nombre.toLowerCase() == "feb";			
		case 2:
			return nombre.toLowerCase() == "mar";			
		case 3:
			return nombre.toLowerCase() == "abr";			
		case 4:
			return nombre.toLowerCase() == "may";			
		case 5:
			return nombre.toLowerCase() == "jun";			
		case 6:
			return nombre.toLowerCase() == "jul";			
		case 7:
			return nombre.toLowerCase() == "ago";			
		case 8:
			return nombre.toLowerCase() == "sep";			
		case 9:
			return nombre.toLowerCase() == "oct";			
		case 10:
			return nombre.toLowerCase() == "nov";
		case 11:
			return nombre.toLowerCase() == "dic";			
	}
}
function getFecha(source)
{
	var day;
	var month;
	var year;
	var iMes;
	day = source.value.substring(0,source.value.indexOf("/"));	
	month = source.value.substring(source.value.indexOf("/") + 1, source.value.lastIndexOf("/"));			
	for (iMes = 0; iMes<12; iMes++)
	{
		if (isThisMes(iMes, month))
		{
			month = iMes;
			break;
		}
	}	
	year = txtFecha.value.substring(source.value.lastIndexOf("/") + 1);	
		
	var Fecha = new Date();
	Fecha.setFullYear(year,month,day);	
	return Fecha;	
}
function getElement(source)
{
	return self.document.getElementById(source.id.substring(0,source.id.lastIndexOf("_"))+"_txt");	
}


/******************************************************************************************/

//No pop-up blocker

function NoPopUpBlocker() 
{
	var objChild;                           // Window
	var reWork = new RegExp('object','gi');	// Regular expression
	try 
	{
		objChild = window.open('','child','top='+ window.screen.availHeight +',left='+ window.screen.availWidth +',width=50,height=50, menubar=0, location=0, status=no, resizable=yes' ); 
		objChild.close();
	}
	catch(e) 
	{ 
	}
	if ( reWork.test(String( objChild ) ) )
	{
		return true;
	}
	else
	{
		alert( "Aviso: Usted tiene habilitado un Popupblocker, desactivelo y vuelva a intentarlo");
		return false;
	}
}
/******************************************************************************************/
/******************************************************************************************/

/*Funcion que abre un hijo no modal con el tamano pedido*/
function dialog(url,w,h)
{
	var iPixY		= window.screen.availHeight;   	//Pix x Disponibles en monitor usuario
	var iPixX		= window.screen.availWidth;		//Pyx y Disponibles en monitor usuario			
	
	var iCentradoX	= (iPixX-w)/2;
	var iCentradoY	= (iPixY-h)/2;
	window.open(url,"SeleccionEmpleado", "left="+ iCentradoX +",top="+ iCentradoY +",width="+w+",height="+h+",status=no,toolbar=no,menubar=no,location=no,titlebar=no");
}

/* Inicializa la posicion, tamaņo y propiedades de la ventana, la relanza en dado caso que el nombre sea diferente del que se manda en el parametro name y sea relanzable*/
function inicio(name,width,height,statusbar,scrollbars, resizable, relanzable )
{	
	var iPixY		= window.screen.availHeight;   	//Pix x Disponibles en monitor usuario
	var iPixX		= window.screen.availWidth;		//Pyx y Disponibles en monitor usuario
	
	var iLoginW		= width//(iPixX * .8);	//Tamanno de la ventana 
	var iLoginH		= height//(iPixY * .9);	//Tamanno de la ventana 
	
	var iCentradoX	= (iPixX-iLoginW)/2;
	var iCentradoY	= (iPixY-iLoginH)/2;				
	
	if (window.name != name && relanzable)
	{
		window.opener = self;
		var nwd = window.open(self.location.href,name,'height=' + iLoginH + ',width=' + iLoginW + ',left=' + iCentradoX+ ',top=' + iCentradoY + ',status=' + statusbar +',resizable=' + resizable + ',menubar=no,toolbar=no,scrollbars=' + scrollbars);
		nwd.name = name;
		window.close();
	}
	else
	{
		self.resizeTo (iLoginW,iLoginH);
		self.moveTo(iCentradoX,iCentradoY);		
	}	
}


/*Cierra la ventana pedida*/
function closeWin(winHandle) {	
	if (winHandle && !winHandle.closed )
		winHandle.close();	
}

/* Funcion para eliminar los botones f11,f5, alt con flechas, ctrl + n, ctrl + r, o el backspace fuera de un campo de texto*/
function eliminaBotones()
{		
	if ( (event.altKey )&&(event.keyCode == 37 || event.keyCode == 39) || ((event.keyCode == 8) && 
    	 			(event.srcElement.type != "text" &&
    	 			 event.srcElement.type != "textarea" &&
    	 			 event.srcElement.type != "password")) || 
    	 			((event.ctrlKey) && ((event.keyCode == 78) || (event.keyCode == 82)) ) ||
    	 			(event.keyCode == 116)  || (event.keyCode == 122)) {
        	 		//alert ('no puedes retroceder');
        	 		event.keyCode = 0;
        	 		event.returnValue = false;
     }
}

/*Regresa a la ventana que la abrio, agregandole en el url el parametro y su valor que se mandan en params,
  la ventana padre obtiene el foco y la hija se cierra, la ventana padre se carga con el nuevo URL.
*/

function regresar(params)
			{				
				//alert(params);				
				var targetUrl = self.opener.location.href;
				var posAmper=0;
				var posIgual=0;
				var posAntAmper=-1;			
				
				while (posAmper != -1)
				{					
					posIgual = params.indexOf('=',posAntAmper+1);
					posAmper = params.indexOf('&',posAntAmper+1);
					var param = params.substring(posAntAmper+1,posIgual);
					//alert(param);
					//if (posAmper != -1)
						//alert(params.substring(posIgual, posAmper));
					//else
					//	alert(params.substring(posIgual));
					if (targetUrl.indexOf (param) == -1)
					{
						if (targetUrl.indexOf("?") == -1)
						{							
							targetUrl += "?";							
						}
						else
						{
							targetUrl += "&";
						}					
						if (posAmper != -1)
							targetUrl += param + params.substring(posIgual, posAmper);
						else
							targetUrl += param + params.substring(posIgual);
					}
					else
					{
						var aux = targetUrl.substring(targetUrl.indexOf(param + "=") + param.length + 1);						
						if (aux.indexOf("&") == -1)
						{
							aux = "";
						}
						else
						{
							aux = aux.substring(aux.indexOf("&"));
						}	
						targetUrl = targetUrl.substring(0,targetUrl.indexOf(param));					
						if (posAmper != -1)
							targetUrl += param + params.substring(posIgual, posAmper)+ aux;					
						else
							targetUrl += param + params.substring(posIgual)+ aux;					
					}
					//alert(targetUrl);
					posAntAmper = posAmper;
				}													
				self.opener.navigate(targetUrl);									
				self.opener.focus();
				self.close();
			}	

/*Funciones para refrescar ventana padre*/

function refreshParent()
{	
	try 
	{
		var location = self.opener.location.href;
		alert(location); 
        if (location.indexOf('#')==-1)
        {
			self.opener.navigate(location);
		}
		else
		{
			self.opener.navigate(location.substring(0,location.indexOf('#')));
		}
	}
	catch(e)
	{
	}	
}

function refreshParent(Url)
{	
	alert(Url);
	try 
	{
		window.opener.navigate(Url);		
	}
	catch(e)
	{
	}
}	
																							
/*Funciones para eliminar caracteres al final y/o al inicio de un string.*/

function rtrim(str,chr)
{
	var iPtr;
	for (iPtr=str.length-1;iPtr> -1;iPtr--)
	{		
		if (str.charAt(iPtr)!= chr)
			break;					
	}	
	return str.substring(0,iPtr+1);
}

function ltrim(str,chr)
{	
	var iPtr;
	for (iPtr=0;iPtr<str.length;iPtr++)
	{		
		if (str.charAt(iPtr)!= chr)
			break;					
	}	
	return str.substring(iPtr);
}

function trim(str,chr)
{
	return rtrim(ltrim(str,chr),chr);
}

function replace (str, oldchr, newchr)
{
	var pos = str.indexOf(oldchr);
	var aux = "";
	var posant = 0;
	while (pos > 0 )
	{
		aux += str.substring(posant,pos) + newchr;		        
		posant = pos + 1;
		pos = str.indexOf(oldchr, pos + 1) 		        
	}
	aux += str.substring(posant);
	return aux;
}


/*Funcion que pide confirmacion al usuario para cerrar la ventana.*/
function tress_ConfirmaCerrar(InformacionPendiente, Mensaje) 
{	
	if(event.clientY < 0 ) 
	{ 
		if( InformacionPendiente )
		{
			event.returnValue = Mensaje; 
		}
	}
}


		
/*Funciones para manejar el grid de infragistics*/
var updating = false;

function grd_AfterCellUpdateHandler(gridName, cellId)
{
   if (!updating)
   {
       var cell = igtbl_getCellById(cellId);              
       updating = true;
       if (cell.getValue())
       {
            cellClass = "SELECTED_ROW";	       
       }
       else
       {
            cellClass = "GRID_ROW";
       }
       select_deselectAll(gridName,false);
	   //cell.setValue(true); 
	   updating = false;
   }
}
		
function grd_CellClickHandler(gridName, cellId, button)
{			    		
	var cell = igtbl_getCellById(cellId);	
	if (cell.Column.Key == "Select")
	{				
		var cnt = 0;					
		if (!cell.getValue())
		{			
			cell.setValue(true);			
		}
		else
		{			
			cell.setValue(false);
			try
			{
				for (i=0; i<document.forms[0].length; i++) 
				{
					if (document.forms[0].elements[i].id.indexOf('chkSelAll')!=-1)
					{
						allChk = false;
						document.forms[0].elements[i].checked = allChk;
						i = document.forms[0].length;
					}
				}
			}
			catch(exc){} 
			
		}													
	}
	else
	{	
		var id = cell.getRow().getCellFromKey("URL_LLAVE").getValue();			    			    			    				
		var id2 = cell.getRow().getCellFromKey("WNDNAME_LLAVE").getValue();			    			    			    								
		window.open(id, id2, "height=500, width=750, scrollbars=no, status=yes, menubar=no, toolbar=no, resizable=yes");					
	}							
}


// Select/UnSelect Checboxes in grid
var allChk;
function init_select_deselectAll()
{ 
	try
	{
		for (i=0; i<document.forms[0].length; i++) 
		{
			if (document.forms[0].elements[i].id.indexOf('chkSelAll')!=-1)
			{
				allChk = document.forms[0].elements[i];
				i = document.forms[0].length;
			}
		}
	}
	catch(exc){}
}

function select_deselectAll(grdName, chkVal)
{		
	allChk = chkVal;
	var grd = igtbl_getGridById(grdName);
	var curRow = grd.Rows.getRow(0);						
	while (curRow != null )
	{
		var cell = curRow.getCellFromKey("Select");						
		if (cell !=null && curRow.getIndex()!= row)
		{		    
		    if (chkVal)
		    {
			    if (!cell.getValue())
			    {
				    pintaTodos(cell.Id, "SELECTED_ROW");
			    }
		    }
		    else
		    {
			    if (cell.getValue())
			    {
				    pintaTodos(cell.Id, "GRID_ROW");
			    }
		    }
		    cell.setValue(chkVal);				
		}
		curRow = curRow.getNextRow(); 
	}				
}

function grd_BeforeSortColumnHandler(gridName, columnId){
	var myCol = igtbl_getColumnById(columnId);
	if (myCol.Key == "Select")
	{
		return true; 
	}
}		

var row = null;
var cellClass;
var Url = "";
var Name = "";		    

function grd_MouseOverHandler(gridName, id, button)
{		
	if (button == 0)
	{
		/*var column = id.substring(id.lastIndexOf('_') + 1 );*/
		var rowid;
		if (id.indexOf('_') == id.lastIndexOf('_'))
		{
			rowid = id.substring(id.indexOf('_') + 1);					
		}
		else
		{
			rowid = id.substring(id.indexOf('_') + 1, id.lastIndexOf('_'));																
		}					
		
		if (row != rowid )
		{	    					
		    checaDespinta(gridName);
			pintaRenglon(gridName + "rc_" + rowid + "_0");			
			row = rowid;			
		}		
	}	
	else
	{				
		checaDespinta(gridName);
		row = null;	
	}	
}

/*Funciones para grid jerarquicos*/

function select_deselectAll_hier(grdName, cellId, chkVal)
{		
	allChk = chkVal;
    var clickRow = igtbl_getCellById(cellId).Row; 
	var grd = igtbl_getGridById(grdName);
	var curRow = grd.Rows.getRow(0);								
	while (curRow != null )
	{
		var childRow =  curRow.FirstChildRow;												
		while (childRow != null)
		{
		    var cell = childRow.getCellFromKey("Select");				    						    		    
		    if (cell !=null && clickRow != childRow)
		    {		    
		        if (chkVal)
		        {
			        if (!cell.getValue())
			        {
				        pintaTodos(cell.Id, "SELECTED_ROW");
			        }
		        }
		        else
		        {
			        if (cell.getValue())
			        {
				        pintaTodos(cell.Id, "GRID_ROW_JERARQUICO");
			        }
		        }
		        cell.setValue(chkVal);				
		    }
		    childRow = childRow.getNextRow();
		}
		curRow = curRow.getNextRow(); 
	}				
}

function grd_AfterCellUpdateHandler_hier(gridName, cellId)
{    
   if (!updating)
   {
       var cell = igtbl_getCellById(cellId);              
       updating = true;
       if (cell.getValue())
       {
            cellClass = "SELECTED_ROW";	       
       }
       else
       {
            cellClass = "GRID_ROW_JERARQUICO";
       }       
       select_deselectAll_hier(gridName, cellId, false);
	   //cell.setValue(true); 
	   updating = false;
   }
}

function grd_CellClickHandler_hier(gridName, cellId, button)
{			    		
	var cell = igtbl_getCellById(cellId);	
	if (cell.Column.Key == "Select")
	{				
		var cnt = 0;					
		if (!cell.getValue())
		{			
			cell.setValue(true);			
		}
		else
		{			
			cell.setValue(false);
			try
			{
				for (i=0; i<document.forms[0].length; i++) 
				{
					if (document.forms[0].elements[i].id.indexOf('chkSelAll')!=-1)
					{
						allChk = false;
						document.forms[0].elements[i].checked = allChk;
						i = document.forms[0].length;
					}
				}
			}
			catch(exc){} 
			
		}													
	}
	else
	{	
		var id = cell.getRow().getCellFromKey("URL_LLAVE").getValue();			    			    			    				
		var id2 = cell.getRow().getCellFromKey("WNDNAME_LLAVE").getValue();			    			    			    								
		window.open(id, id2, "height=500, width=750, scrollbars=no, status=yes, menubar=no, toolbar=no, resizable=yes");					
	}							
}

function grd_MouseOverHandler_hier(gridName, id, button)
{	
	if (button==0)
    {
        var cell = igtbl_getCellById(id);
        var rowId = cell.Row;
        cell = rowId.getCell(0);
        pintaRenglon(cell.Id);        
    }	
}

function grd_MouseOutHandler_hier(gridName, id, button)
{
    if (button==0)
    {
        var cell = igtbl_getCellById(id);
        var rowId = cell.Row;
        cell = rowId.getCell(0);
        despintaRenglon(cell.Id);        
    }
}

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

function checaDespinta(id)
{
	if (row!=null)
	{										
		despintaRenglon(id + "rc_" + row + "_0");																						
	}					
}
function pintaRenglon(cell0Name)
{			
	var cnt = 0;
	var cell = igtbl_getElementById(cell0Name);			
	cellClass = cell.className;	
	while(cell!=null) 
	{
		cell.className="OVER_ROW";				
		cnt++;
		cell = igtbl_getElementById(cell0Name.substring(0,cell0Name.length - 1) + cnt);															
	}
}

function pintaTodos(cell0Name, style)
{			
	var cnt = 0;
	var cell = igtbl_getElementById(cell0Name);							
	while(cell!=null) 
	{
		cell.className = style;				
		cnt++;
		cell = igtbl_getElementById(cell0Name.substring(0,cell0Name.length - 1) + cnt);															
	}
}

function despintaRenglon(cell0Name)
{			
	var cnt = 0;
	var cell = igtbl_getElementById(cell0Name);				
	//cell.className = cellClass;				
	//alert("despinta " + cellClass)		;
	while(cell!=null) 
	{
		cell.className=cellClass;				
		cnt++;
		cell = igtbl_getElementById(cell0Name.substring(0,cell0Name.length - 1) + cnt);															
	}	
}		


/*Funciones para manejar el menu lateral*/

var oldItem = null;
var oldClass = null;              
var item =  null;
var lastItemClicked;		
var itemClass;                
function menuLateral_InitializeMenu(menuId){
	var i=0;						
	var menu = igmenu_getMenuById(menuId);			
	var ItemSibling = igmenu_getItemById(menuId + "_1");//menu.UniqueId + '_1');						
	ItemSibling.setEnabled(false);
	lastItemClicked = ItemSibling.Id;			
	igmenu_getElementById(ItemSibling.Id).className = 'MENU_CLICKED';
	ItemSibling = ItemSibling.getNextSibling();
	while (ItemSibling != null)
	{				
		if (ItemSibling.getText()!= null)
		{
			igmenu_getElementById(ItemSibling.Id).className = 'MENU_UNCLICKED';				    
		}
		ItemSibling = ItemSibling.getNextSibling();
		i++;
	}			
}		
function menuLateral_ItemHover(menuId, itemId, bHover){
	if (bHover)
	{				
		if (itemId != lastItemClicked)
		{
			item = itemId;					
			itemClass = igmenu_getElementById(itemId).className;
			igmenu_getElementById(itemId).className = "MENU_HOVER";								
		}
	}
	else
	{
		if (item != null)
		{					
			igmenu_getElementById(item).className = itemClass;
		}
	}
}
function menuLateral_ItemClick(menuId, itemId){
	if (lastItemClicked != null)
	{
		igmenu_getElementById(lastItemClicked).className = "MENU_UNCLICKED";
		igmenu_getItemById(lastItemClicked).setEnabled(true);				
	}						
	igmenu_getElementById(itemId).className = "MENU_CLICKED";
	igmenu_getItemById(itemId).setEnabled(false);	
	itemClass = "MENU_CLICKED";
	lastItemClicked = itemId;
	window.document.body.style.cursor = "wait";	
}