
function openHelp(tema) {
  window.open( 
    'ayuda.aspx?tema=' + tema, 
    '_blank', 
    'top=100, left=200, heigth=500, width=500, scrollbars=yes, channelmode=no, status=no, toolbar=no, menubar=no, directories=no, location=no, titlebar=no');
 }

function expandCollapse( idDiv, idImg, imgExpanded, imgCollapsed) {
var div, img;

	div = document.getElementById(idDiv);
	if (div==null) return;
	img = document.getElementById(idImg);

  if (imgExpanded==null) imgExpanded='imagenes/Expand_up.PNG';
  if (imgCollapsed==null) imgCollapsed='imagenes/Expand_down.PNG';
	
	if (div.style.display=="none") {
	  div.style.display="";
	  if (img!=null) img.src = imgExpanded;
	} else {
	  div.style.display="none";
	  if (img!=null) img.src = imgCollapsed;
	}
}

function validate() {

var yDesde, mDesde, dDesde
var yHasta, mHasta, dHasta
var desde;
var hasta;
var f = Default;

	if (f.radFechas_6==null) return;

	// Valido las fechas ingresadas
	if (f.radFechas_6.checked) {
	
		yDesde = f.cboYearDesde.value
		mDesde = f.cboMonthDesde.value
		dDesde = f.cboDayDesde.value

		yHasta = f.cboYearHasta.value
		mHasta = f.cboMonthHasta.value
		dHasta = f.cboDayHasta.value
		
		if (!isDate(dDesde, mDesde, yDesde)) return false;
		if (!isDate(dHasta, mHasta, yHasta)) return false;
		
		desde = new Date( yDesde, mDesde, dDesde ) 
		hasta = new Date( yHasta, mHasta, dHasta ) 

		if (desde > hasta) {
			alert( "La fecha desde no puede es mayor a la fecha hasta.");
			return false;
		}
	}

	return true;

}

function getParent( element, parentTag ) {
var parent;
	parent = element.parentElement;
	if (parentTag==null) {
		parentTag = "TABLE";
	}
	while ( parent != null && parent.tagName != parentTag ) 
		parent = parent.parentElement;

	return parent
}

function onclickCheck() {
var firstCheck;
var activeCheck;
var table;

	//debugger;
	table = getParent( event.srcElement, "DIV" );
	
	if (table==null) return;

	firstCheck = table.getElementsByTagName("INPUT")[0];
	activeCheck = document.activeElement;
	
	// Hizo click en un elemento que no es un check
	if (activeCheck.tagName != "INPUT") return;
	
	// Hizo click en el primer elemento
	if (activeCheck == firstCheck) {
		// si hizo lick en el primer elemento, desmarco todos
		if (firstCheck.checked) {
			checkAll( table, false );
			firstCheck.checked = true;
		// Si lo apagó y no hay ninguno marcado, se lo vuelvo a encender
		} else {
			if (!isAnyChecked(table)) firstCheck.checked = true;
		}
	// Hizo click en alguno de los demas elementos
	} else {
	  //Si hay alguno marcado desmarco el check de todas y viceversa
	  //Si no hay ninguno marcado marco el check de todas
	  firstCheck.checked = (!isAnyChecked(table));
	}

}

// retorna true si alguno de los check están marcados
// no verifica el primero de ellos
function isAnyChecked( parent ) { 
var aCheck, c;
	aCheck = parent.getElementsByTagName("INPUT");
	//Salteo el primero, por eso arranca c=1
	for (c=1; c<aCheck.length; c++) {
		if (aCheck[c].checked) return true;
	}
	return false;
}


function checkAll( parent, check ) {
var aCheck, c;
	aCheck = parent.getElementsByTagName("INPUT");
	for (c=0; c<aCheck.length; c++) {
		aCheck[c].checked = check;
	}
}

function especificarFecha() {
	if (Default.radFechaEspecificar!=null) Default.radFechaEspecificar.checked=true;
  return
}

function isDate(day, month, year) {

	if (month < 1 || month > 12) { // check month range
		alert("Mes incorrecto.");
		return false;
	}

	if (day < 1 || day > 31) {
		alert("Día incorrecto.");
		return false;
	}

	if ((month==4 || month==6 || month==9 || month==11) && day==31) {
		alert("El mes especificado no tiene 31 días.")
	return false;
	}

	if (month == 2) { // check for february 29th
		var isBisiesto = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		
		if (day > 29 || (day==29 && !isBisiesto)) {
			alert("Febrero de " + year + " no tiene " + day + " días.");
		return false;
		}
	}
	return true;
}

function showdiv(event)
{
 //determina un margen de pixels del div al raton
 margin=-100;

 //La variable IE determina si estamos utilizando IE
 var IE = document.all?true:false;
 //Si no utilizamos IE capturamos el evento del mouse
 if (!IE) document.captureEvents(Event.MOUSEMOVE)

 var tempX = 0;
 var tempY = 0;

 if(IE)
 { //para IE
 tempX = event.clientX + document.body.scrollLeft;
 tempY = event.clientY + document.body.scrollTop;
 }else{ //para netscape
 tempX = event.pageX;
 tempY = event.pageY;
 }
 if (tempX < 0){tempX = 0;}
 if (tempY < 0){tempY = 0;}

 //modificamos el valor del id "posicion" para indicar la posicion del mouse
 //document.getElementById('posicion').innerHTML="PosX = "+tempX+" | PosY = "+tempY;

 document.getElementById('help').style.top = (tempY+margin);
 document.getElementById('help').style.left = (tempX+margin);
 document.getElementById('help').style.display='block';
 return;
}
function hidediv()
{
 document.getElementById('1').style.display='none';
}
