
/**
 *FUNCION Mostrar(iden, title): Muestra/Oculta el div="iden" con el tooltip="title"
 */
 
function Mostrar(iden, title) {
	var elem = document.getElementById(iden);
	var elem2 = document.getElementById('botonminimizar');
	if (elem.style.display =='') {
		elem.style.display = 'none';
		elem2.src = '/images/comunes/btnPlus.gif';
		elem2.title = 'Abrir ' + title;
	} else {
		elem.style.display='';
		elem2.src = '/images/comunes/btnMinus.gif';
		elem2.title = 'Cerrar ' + title;
	}
};  // END function Mostrar(iden, title)

/**
 * FUNCION:  showhide(what)
 * OBJETIVO: Si el elemento de tipo <span> "what" esta oculto, lo muestra.
 *           Si esta visible, lo oculta.
 */
 
function showhide(what){
	var elem = document.getElementById(what);
	if (elem.style.display=='none') {
		elem.style.display='';
	} else {
		elem.style.display='none';
	}
};

/**
 * FUNCION NoEsNumero(str): VERDAD si algún caracter de str no es número (0..9), FALSO ecc.
 */
 
function NoEsNumero(str) {
	var filter = '0123456789';
	var i = 0;
	while (i < str.length) {
		if (filter.indexOf(str.charAt(i)) == -1) return true;
		i++;
	}
}; // END NoEsNumero(str) =====

function chequearFecha(txtDia, txtMes, txtAno) {
	dia = txtDia.value;
	mes = txtMes.value;
	ano = txtAno.value;
	if(NoEsNumero(dia))
	{
		alert("El día debe ser un número");
		txtDia.focus();
		return false;
	}
	if(NoEsNumero(mes))
	{
		alert("El mes debe ser un número");
		txtMes.focus();
		return false;
	}
	if(NoEsNumero(ano))
	{
		alert("El año debe ser un número");
		txtAno.focus();
		return false;
	}
	if (mes < 1 || mes > 12) {
		alert("Mes inválido."); 
		txtMes.focus();
		return false;
	}
	if (dia == 0) {
		alert("Día inválido."); 
		txtDia.focus();
		return false;
	}
	if ((mes==1 || mes==3 || mes==5 || mes==7 || mes==8 || mes==10 || mes==12) && (dia > 31)) {
		alert(dia + " no es un día válido para el mes " + mes + "."); 
		txtDia.focus();
		return false;
	}
	if ((mes==4 || mes==6 || mes==9 || mes==11) && (dia > 30)) {
		alert(dia + " no es un día válido para el mes " + mes + "."); 
		txtDia.focus();
		return false;
	}
	if (mes == 2) {  //---- chequeo para año bisiesto -----
		if (dia > 28) {
			if (ano%4 != 0) {
				alert(dia + " no es un día válido para el mes " + mes + " del año " + ano + "."); 
				txtDia.focus();
				return false; 
			}
		}
		if (dia > 29) {
			if (ano%4 == 0) {
				alert(dia + " no es un día válido para el mes " + mes + " del año " + ano + "."); 
				txtDia.focus();
				return false;
			}
		}
	}
	return true;
}; // END function chequearFecha() =====

/**
 * FUNCION:  CambiarFondo(fila, color)
 * OBJETIVO: Le asigna el color "color" al fondo de la fila "fila" de una tabla.
 */
function CambiarFondo(fila, color) {
	var elem = document.getElementById(fila);
	elem.style.backgroundColor = color;
	return true;
};

/**
 * FUNCION Trim(str): devuelve la cadena str sin espacios en blanco al principio y al final.
 */
function Trim(str) {
	return (str.replace(/^\s*(\b.*\b|)\s*$/, "$1"));
}; // END function Trim(str)

/**
  * FUNCION callpage(htmlurl): abre una nueva ventana con el htmlurl especificado.
  * Se usa asi: <a href="mipagina.htm" onClick='return callpage(this.href, "miNombre", "yes", 600, 500)'>Mi enlace</A>
  */
function callpage(htmlurl, nombre, sino, ancho, alto) {
  var newWin=window.open(htmlurl, nombre, "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars="+sino+", width="+ancho+", height="+alto+", resizable=no");
  newWin.opener = self;
  newWin.focus();
  return false;
};

/**
  * FUNCION:  Marcar_Todos(f)
	* OBJETIVO: Selecciona todos los elementos de tipo "checkbox" en la forma "f".
  */
function Marcar_Todos(f) {
  var i, cVariable;
  for (i = 0; i < f.elements.length;i++) {
    cVariable = f.elements[i];
    if (cVariable.name != "chkTodos" && cVariable.type == "checkbox")
      cVariable.checked = f.chkTodos.checked;
  }
	if ( f.chkTodos.checked ) {
		f.chkTodos.title = "Des" + f.chkTodos.title.substr(1);
	} else {
		f.chkTodos.title = "S" + f.chkTodos.title.substr(3);
	}
};

/**
  * FUNCION:  Desmarcar(chkT, chkA)
	* OBJETIVO: Marca el checkbox "chkT" si todos los checkbox "chkA" estan marcados.
	*           Desmarca el checkbox "chkT" en caso contrario.
  */
function Desmarcar(chkT, f) {

	var blnTodos = true;
	var i, cVariable;
	
	for (i = 0; i < f.elements.length;i++) 
	{
		cVariable = f.elements[i];
	    if (cVariable.name != "chkTodos" && cVariable.type == "checkbox")
		{
			if(cVariable.checked == false)
			{
				blnTodos = false;
				break;
			}
		}
	}
	
	if ( blnTodos ) {
		if ( ! chkT.checked ) {
			chkT.title = "Des" + chkT.title.substr(1);
		}
		chkT.checked = true;
	} else {
		if ( chkT.checked ) {
			chkT.title = "S" + chkT.title.substr(3);
		}
		chkT.checked = false;
	}
};

/**
 * FUNCION Reg (codHijo, codPadre, nomHijo): 
 */
function Reg (codHijo, codPadre, nomHijo) {
   this.codPadre = codPadre;
   this.codHijo = codHijo;
   this.nomHijo = nomHijo;
}; //END function Reg (codHijo, codPadre, nomHijo)

/**
 * FUNCION LoadNext (cmbOrigen, cmbDestino, Arreglo, str1, str2)
 * OBJETIVO: Carga en cmbDestino los valores del Arreglo que sean hijos del valor seleccionado en cmbOrigen.
 *           Si no hay hijos en Arreglo, cmbDestino se carga con clave=str1 y valor=str2.
 */
function LoadNext(cmbOrigen, cmbDestino, Arreglo, str1, str2) {
  idToFind = cmbOrigen.options[cmbOrigen.selectedIndex].value;
  cuantos = 0;
  for (i = 0; i < Arreglo.length; i++) {
    if (Arreglo[i].codPadre == idToFind) {
			cuantos++;
		}
  }
  cmbDestino.length = cuantos;

  ind = 0;
	if (str1 != null) {
	  cmbDestino.options[ind++] = new Option (str1, str2);
	}

  for (i = 0; (i < Arreglo.length); i++) {
    if (Arreglo[i].codPadre == idToFind) {
      cmbDestino.options[ind++] = new Option (Arreglo[i].nomHijo, Arreglo[i].codHijo);
    }
  }
  cmbDestino.selectedIndex = 0;

	if (cuantos==0) {
		cmbDestino.disabled = true;
	} else {
		cmbDestino.disabled = false;
	}
}; // END function LoadNext(cmbOrigen, cmbDestino, Arreglo, str1, str2)

/**
 * FUNCION LoadNextOM (cmbOrigen, cmbDestino, Arreglo, str1, str2, seleccion)
 * OBJETIVO: Carga en cmbDestino los valores del Arreglo que sean hijos del valor seleccionado
 *           en cmbOrigen, dejando seleccionado en cmbDestino la opcion que sea igual a "seleccion".
 *           Si no hay hijos en Arreglo, cmbDestino se carga con clave=str1 y valor=str2.
 */
function loadNextOM(cmbOrigen, cmbDestino, Arreglo, str1, str2, seleccion) {
  idToFind = cmbOrigen.options[cmbOrigen.selectedIndex].value;
  cuantos = 0;
  s = 0;
  for (i = 0; (i < Arreglo.length); i++) {
    if (Arreglo[i].codPadre == idToFind) {
			cuantos++;
		}
  }

  cmbDestino.length = cuantos;
	
  ind = 0;
	if (str1 != null) {
	  cmbDestino.options[ind++] = new Option (str1, str2);
	}
	
  for (i = 0; (i < Arreglo.length); i++) {
    if (Arreglo[i].codPadre == idToFind) {
      if (Arreglo[i].codHijo == seleccion) {
				s = ind;
			}
      cmbDestino.options[ind] = new Option (Arreglo[i].nomHijo, Arreglo[i].codHijo);
      ind++;
    }
  }
  cmbDestino.selectedIndex = s;

	if (cuantos==0) {
		cmbDestino.disabled = true;
	} else {
		cmbDestino.disabled = false;
	}
}; // END function loadNextOM(cmbOrigen, cmbDestino, Arreglo, str1, str2, seleccion)

/**
*  Esta funcion selecciona o deselecciona las casillas (checkbox)
*  segun el parametro seleccionar que debe ser boolean (true o false)
*/
function selectCheckBox(seleccionar,casilla) {
	try {
		if ( casilla.length != undefined ) {
			for(var i = 0; i < casilla.length; i++) {
				casilla[i].checked = seleccionar;
			}
		} else {
				casilla.checked = seleccionar;
		}
	} catch(e) {}
}

