/*
 *	SCRIPT DESAROLLADO EN ARGENTINA POR MAT
 *	mat.hack@gmail.com
 *	LOPEZ, MATIAS
 */



var enviandoListarProducto = 0;

function enviarListarProducto()
{
	// DETERMINAMOS LA URL
	var arreglo = document.location.href.split( "/" );
	var path = arreglo[ arreglo.length-2 ];
	url = "listarProducto.php";
	if( path != "administrar")
		url = "administrar/"+ url;

	// EJECUTAMOS LA PAGINA CON AJAX
	enviarListarProductoAURL(url);
}

function enviarListarProductoAURL(url)
{
	if( enviandoListarProducto == 0 )
	{
		// BLOQUEAMOS EL USO DEL DIV
		enviandoListarProducto = 1;
		// MOSTRAMOS EL DIV
		mostrarDialogoListarProducto();
		// EJECUTAMOS LA PAGINA CON AJAX
		cadenaPost = getCadenaPost();
		xmlhttpPost(url, cadenaPost, verificarEstadoListarProducto);
	}
}

function acomodarDialogoListarProducto()
{
	var objeto = document.getElementById('divDialogoListarProducto');
	// CENTRAMOS EL DIV
	var mitadPantallaDisponible = document.body.clientHeight / 2;
	if( objeto.offsetHeight < 100 )
		objeto.height = 100;
	var mitadObjeto = objeto.offsetHeight / 2;
	nuevoTop = document.body.scrollTop + mitadPantallaDisponible - mitadObjeto;
	if( nuevoTop < 0 )
		nuevoTop = 0;
	objeto.style.top = nuevoTop;

	// ACOMODAMOS EL FONDOOSCURO
	fondoOscuro = document.getElementById('divFondoOscuro');
	if( document.body.clientHeight > document.body.scrollHeight )
		fondoOscuro.style.height = document.body.clientHeight;
	else
		fondoOscuro.style.height = document.body.scrollHeight;
	if( document.body.clientWidth > document.body.scrollWidth )
		fondoOscuro.style.width = document.body.clientWidth;
	else
		fondoOscuro.style.width = document.body.scrollWidth;
}

function mostrarDialogoListarProducto()
{
	var objeto = document.getElementById('divDialogoListarProducto');
	// CENTRAMOS EL DIV
	acomodarDialogoListarProducto();
	// ENVIAMOS EL DIV AL FRENTE
	objeto.style.zIndex = 10;

	// OSCURECEMOS EL FONDO
	fondoOscuro = document.getElementById('divFondoOscuro');
	fondoOscuro.style.visibility = "visible";
	if( document.body.clientHeight > document.body.scrollHeight )
		fondoOscuro.style.height = document.body.clientHeight;
	else
		fondoOscuro.style.height = document.body.scrollHeight;
	if( document.body.clientWidth > document.body.scrollWidth )
		fondoOscuro.style.width = document.body.clientWidth;
	else
		fondoOscuro.style.width = document.body.scrollWidth;

	// MOSTRAMOS EL DIV
	fade('divDialogoListarProducto', 0, 100, 500);
}

function cerrarDialogoListarProducto()
{
	var objeto = document.getElementById('divDialogoListarProducto');
	// ENVIAMOS EL DIV AL FONDO
	objeto.style.zIndex = -1;

	// VOLVEMOS A ILUMINAR EL FONDO
	fondoOscuro = document.getElementById('divFondoOscuro');
	fondoOscuro.style.height = 0;
	fondoOscuro.style.width = 0;
	fondoOscuro.style.visibility = "hidden";

	// OCULTAMOS EL DIV
//	fade('divDialogoListarProducto', 100, 0, 500);
	objeto.height = "";
	// BORRAMOS EL RESULTADO DEL DIV
	document.getElementById( "tdTextoDialogoListarProducto" ).innerHTML = "";
	// LIBERAMOS EL USO DEL DIV
	enviandoListarProducto = 0;
}

// EFECTUA LA ACCION CORRESPONDIENTE AL ESTADO DEL OBJETO XMLLHTTP
function verificarEstadoListarProducto(xmlHttpReqListarProducto)
{
	if( xmlHttpReqListarProducto.readyState == 1 )	// 1: CARGANDO
	{
		mostrarCargandoListarProducto();
	}
	else
	{
		if( xmlHttpReqListarProducto.readyState == 4 )	// 4: FIN
		{
			respuesta = xmlHttpReqListarProducto.responseText;
			actualizarDialogoListarProducto( respuesta );
		}
	}
}

// MUESTRA / OCULTA EL DIV CON LA IMAGEN DE CARGA
function mostrarCargandoListarProducto()
{
	document.getElementById( "divCargandoListarProducto" ).style.visibility = "visible";
}

function ocultarCargandoListarProducto()
{
	document.getElementById( "divCargandoListarProducto" ).style.visibility = "hidden";
}

// MUESTRA EL RESULTADO
function actualizarDialogoListarProducto(strResultado)
{
	// OCULTAMOS LA IMAGEN DE CARGA
	ocultarCargandoListarProducto();

	// PONEMOS EL RESULTADO EN EL DIV
	document.getElementById( "tdTextoDialogoListarProducto" ).innerHTML = strResultado;

	// CENTRAMOS EL DIV
	acomodarDialogoListarProducto();
}



/*
 *	SCRIPT DESAROLLADO EN ARGENTINA POR MAT
 *	mat.hack@gmail.com
 *	LOPEZ, MATIAS
 */
