/****************************************************************************************************
  ABRE UNA VENTANA DEL EXPLORADOR
*****************************************************************************************************/
var miVentana;
function abrir_ventana(url, nombre, propiedades) 
{ 
	
  	miVentana = window.open(url,nombre,propiedades);
	miVentana.focus();
}

function cerrar_ventana() 
{ 
	miVentana.close();  
}

/****************************************************************************************************
  ABRE UNA VENTANA DEL EXPLORADOR
*****************************************************************************************************/

// FUNCION PARA LANZAR LOS LINKS EXTERNOS CENTRADOS EN LA PAGINA.    
var myWindow;
function abrir_ventana_centro(url,nombre,propiedades,width,height) {
	
    if (!width) width = 800;
	if (!height) height = 600;
	
    var left = parseInt((screen.availWidth/2) - (width/2));
    var top = parseInt(((screen.availHeight/2) - (height/2))-15);
    propiedades = "width=" + width + ",height=" + height + 
        ",status,resizable,left=" + left + ",top=" + top + 
        ",screenX=" + left + ",screenY=" + top+", "+propiedades;
    myWindow = window.open(url,nombre,propiedades);
	myWindow.focus();
}

/*****************************************************************************************************
 CAMBIA LA PAGINA DE RESULTADOS
*****************************************************************************************************/
function cambiarPagina(form, numero)
{
	eval("document."+form+".pagina.value = numero");
	eval("document."+form+".submit()");
}
/*****************************************************************************************************
 CAMBIA LA PAGINA DE RESULTADOS
*****************************************************************************************************/

/*****************************************************************************************************
 RESALTA FILA/CELDA DE UNA TABLA
*****************************************************************************************************/
function resaltarFila(fila, color) 
{
	fila.bgColor=color;
	fila.style.cursor="hand"; 
}
/*****************************************************************************************************
 RESALTA FILA/CELDA DE UNA TABLA
*****************************************************************************************************/

/*****************************************************************************************************
 DES-RESALTA FILA/CELDA DE UNA TABLA
*****************************************************************************************************/
function reestablecerFila(fila, color) 
{
	fila.bgColor=color;
	fila.style.cursor="default"; 
}
/*****************************************************************************************************
 DES-RESALTA FILA/CELDA DE UNA TABLA
*****************************************************************************************************/

/*****************************************************************************************************
 PREPARA LOS CAMPOS PARA EL LOGIN
*****************************************************************************************************/
function ingresar() 
{
	clave_hash = hex_md5(document.frm_login.txt_clave_ne.value);
	document.frm_login.txt_clave.value = clave_hash;
	document.frm_login.txt_clave_ne.value = "";
	document.frm_login.submit();
}
/*****************************************************************************************************
 PREPARA LOS CAMPOS PARA EL LOGIN
*****************************************************************************************************/

/*****************************************************************************************************
 RESTRINGE EL CLIC DERECHO
*****************************************************************************************************/
function inhabilitar(){ 
    alert ("No se puede utilizar el clic derecho en esta aplicaci�n") 
    return false 
} 

//document.oncontextmenu=inhabilitar
/*****************************************************************************************************
 RESTRINGE EL CLIC DERECHO
*****************************************************************************************************/

/*****************************************************************************************************
 MUESTRA Y ESCONDE OBJETOS EN LA PANTALLA
*****************************************************************************************************/
function visibilidad(nombre, valor)
{
	var objeto = document.getElementById(nombre);
	objeto.style.display = valor;
}
/*****************************************************************************************************
 MUESTRA Y ESCONDE OBJETOS EN LA PANTALLA
*****************************************************************************************************/

/*****************************************************************************************************
 RESTRINGE LA ENTRADA DE DATOS A SOLO NUMEROS
*****************************************************************************************************/
function soloNumeros(e) { // 1
    tecla = (document.all) ? e.keyCode : e.which; // 2
    if (tecla==8) return true; // 3
    patron =/\d/; // 4
    te = String.fromCharCode(tecla); // 5
    return patron.test(te); // 6
	/*
	patron = /\d/; // Solo acepta números
	patron = /\w/; // Acepta números y letras
	patron = /\D/; // No acepta números
	patron =/[A-Za-zñÑ\s]/; // igual que el ejemplo, pero acepta también las letras ñ y Ñ
	*/
} 
//Uso: onkeypress="validar(event,)"
/*****************************************************************************************************
 RESTRINGE LA ENTRADA DE DATOS A SOLO NUMEROS
*****************************************************************************************************/

/*****************************************************************************************************
 FORMATEO DE NUMEROS A MONEDA
*****************************************************************************************************/
function numero_moneda(numero)
{	
	negativo = false;
	
	if (numero < 0)
	{
		negativo = true;
		numero *= -1;
	}
	
	numero = numero.toString();
	
	punto_pos = numero.length;
	if (numero.indexOf('.') != -1)
	{	
		punto_pos = numero.indexOf('.');
	}
	
	int_numero = numero.substring(0, punto_pos);
	dec_numero = numero.substring(punto_pos+1, numero.length);
	strnumero = int_numero;
	moneda = "";
	
	while (strnumero.length > 2)
	{
		moneda = "." + strnumero.substring(strnumero.length-3, strnumero.length) + moneda;
		strnumero = strnumero.substr(0, strnumero.length-3);
	}
	
	if (strnumero.length > 0)
	{
		moneda = strnumero + moneda;
	}
	else
	{
		moneda = moneda.substr(1, moneda.length);
	}
	
	if (dec_numero != '')
	{
		moneda += ","+dec_numero;
	}
	
	if (negativo)
	{
		return "-"+moneda;
	}
	else
	{
		return moneda;
	}
}

function formatNumber(num,prefix){
    prefix = prefix || "";
    num += "";
    var splitStr = num.split(".");
    var splitLeft = splitStr[0];
    var splitRight = splitStr.length > 1 ? "." + splitStr[1] : "";
    var regx = /(\d+)(\d{3})/;
    while (regx.test(splitLeft)) {
	    splitLeft = splitLeft.replace(regx, "$1" + "," + "$2");
    }
    return prefix + splitLeft + splitRight;
}

function unformatNumber(num) {
    return num.replace(/([^0-9\.\-])/g,"")*1;
} 
/*****************************************************************************************************
 FORMATEO DE NUMEROS A MONEDA
*****************************************************************************************************/

/*****************************************************************************************************
 DIFERENCIA EN DIAS DE DOS FECHAS
*****************************************************************************************************/
function diferencia_en_dias(inicio, fin)
{
	if (inicio != '')
	{
		// esta es la expresion regular 
		var regex = /(\d+)-(\d+)-(\d+)/; 
		
		// la "fecha inicial" 
		var aFini = inicio.replace(regex,"$1"); 
		var mFini = inicio.replace(regex,"$2"); 
		var dFini = inicio.replace(regex,"$3"); 
		
		// la "fecha final" 
		var aFfin = fin.replace(regex,"$1"); 
		var mFfin = fin.replace(regex,"$2"); 
		var dFfin = fin.replace(regex,"$3"); 
		
		var oFini = new Date(aFini,mFini - 1,dFini); 
		var oFfin = new Date(aFfin,mFfin - 1,dFfin); 
		
		return (oFfin - oFini)/86400000;
	}
	else
	{
		return 0;
	}
}
/*****************************************************************************************************
 DIFERENCIA EN DIAS DE DOS FECHAS
*****************************************************************************************************/

/*****************************************************************************************************
 VALIDA UN EMAIL
*****************************************************************************************************/
function validar_email(valor) 
{
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor))
	{
		//alert("La direcci�n de email " + valor    + " es correcta.") 
		return (true)
	} 
	else 
	{
		//alert("La direcci�n de email es incorrecta.");
		return (false);
	}
}
/*****************************************************************************************************
 VALIDA UN EMAIL
*****************************************************************************************************/

/*****************************************************************************************************
 REDONDEA UN NUMERO
*****************************************************************************************************/
function redondear(numero, decimales)
{
	factor = Math.pow(10, decimales);
	return (Math.round(numero*factor)/factor);
}
/*****************************************************************************************************
 REDONDEA UN NUMERO
*****************************************************************************************************/
