// Intenta cerrar la venta de progreso si esta abierta 
function cierraProgreso() {
	var ventanaProgreso = window.open("", "progreso");
	if (ventanaProgreso) {
		ventanaProgreso.close();
	}
}

function esNumero( valor, flotante ) {           // Regresa verdadero si el parametro enviado es numero
	if (flotante == true) {
		var nums = "0123456789.";
	} else {
		var nums = "0123456789";
	}
	for (var x = 0; x < valor.length; x++) {
		char = valor.charAt(x);
		if (nums.indexOf(char) == -1 ) return false;
	}  
  	return true;
}

// Valida y controla el contenido de un textbox para que se introduzcan
// solo numeros
function numerosTextbox( campo, flotante ) {
	if (!esNumero(campo.value, flotante)) { // Cortale el ultimo caracter
		campo.value = campo.value.substring(0, (campo.value.length - 1));
	} 
}

// Valida y controla el contenido de un textarea
function cuentaTexto(campo, contador, limite) {
	if (campo.value.length > limite) { // Cortalo si esta muy largo
		campo.value = campo.value.substring(0, limite);
	} else {                           // Si no, actualiza el contador
		contador.value = campo.value.length;
	}
}

// This the function to make the screenshots open / *JPA* /
function openScreenshot( imagePath, height, width, name, extraAtribs ) {
	// Default windows size values if not provided
	var height = (height == null) ? 380 : height; 
    var width = (width == null) ? 500 : width;
	var name = (name == null) ? 'screenshot' : name;
	var extraAtribs = (extraAtribs == null) ? ',scrollbars=no' : extraAtribs;
	
	// Calculate center of the window
	var top =  (screen.height / 2) - (height / 2);
    var left = (screen.width / 2)  - (width / 2);
		
	// Build string with arguments and open the window
	var strArgs = "height="+ height +",width="+ width +",top="+ top +",left="+ left+ extraAtribs;
	window.open( imagePath, name, strArgs );
}

// Busca un valor dentro de las opciones de un combobox y regresa el indice
function buscaComboIndex( combobox, valor ) {
	for (x = 0; x < combobox.length; x++) {
		if (combobox.options[x].value == valor) {
			return x;
		}
	}
}

function extraeNumeros( valor ) {
 	var nums = "0123456789";
	var final = "";
	for (var x = 0; x < valor.length; x++) {
		char = valor.charAt(x);
		if (nums.indexOf(char) == -1 ) return final;
		final = final + char;
	}  
  	return true;
} 