var archivoAjax = "./problema_procesar.php";
var tablaComentarios;
var tablaSoluciones;

function fn_LimpiarCamposControl ()
{
	document.frm_Datos.txt_HacerInsertComentario.value = "0";
	document.frm_Datos.txt_HacerCargarComentarios.value = "0";
	document.frm_Datos.txt_HacerBorrarComentario.value = "0";		

	document.frm_Datos.txt_HacerInsertSolucion.value = "0";
	document.frm_Datos.txt_HacerCargarSoluciones.value = "0";
	document.frm_Datos.txt_HacerBorrarSolucion.value = "0";		
	
	document.frm_Datos.txt_HacerVotar.value = "0";
	document.frm_Datos.txt_HacerMeAfecta.value = "0";
}

function fn_BloquearBotones ()
{
	document.getElementById ("tablaExterior").style.cursor = "wait";		

	document.getElementById ("btn_Buscar").style.cursor = "wait";
	document.getElementById ("btn_Buscar").disabled = true;
	
	document.getElementById ("btn_Ingresar").style.cursor = "wait";
	document.getElementById ("btn_Ingresar").disabled = true;

	document.frm_Datos.btn_Ingresar_2.style.cursor = "wait";
	document.frm_Datos.btn_Ingresar_2.disabled = true;

	document.frm_Datos.btn_Ingresar_Soluciones.style.cursor = "wait";
	document.frm_Datos.btn_Ingresar_Soluciones.disabled = true;

	document.frm_Datos.btn_Enviar.style.cursor = "wait";
	document.frm_Datos.btn_Enviar.disabled = true;

	document.frm_Datos.btn_EnviarSolucion.style.cursor = "wait";
	document.frm_Datos.btn_EnviarSolucion.disabled = true;

	document.getElementById ("btn_Votar").style.cursor = "wait";
	document.getElementById ("btn_Votar").disabled = true;

	document.getElementById ("btn_MeAfecta").style.cursor = "wait";
	document.getElementById ("btn_MeAfecta").disabled = true;
}

function fn_HabilitarBotones ()
{
	document.getElementById ("tablaExterior").style.cursor = "default";		

	document.getElementById ("btn_Buscar").style.cursor = "pointer";
	document.getElementById ("btn_Buscar").disabled = false;

	document.getElementById ("btn_Ingresar").style.cursor = "pointer";
	document.getElementById ("btn_Ingresar").disabled = false;

	document.frm_Datos.btn_Ingresar_2.style.cursor = "pointer";
	document.frm_Datos.btn_Ingresar_2.disabled = false;

	document.frm_Datos.btn_Ingresar_Soluciones.style.cursor = "pointer";
	document.frm_Datos.btn_Ingresar_Soluciones.disabled = false;

	document.frm_Datos.btn_Enviar.style.cursor = "pointer";
	document.frm_Datos.btn_Enviar.disabled = false;	

	document.frm_Datos.btn_EnviarSolucion.style.cursor = "pointer";
	document.frm_Datos.btn_EnviarSolucion.disabled = false;	

	document.getElementById ("btn_Votar").style.cursor = "pointer";
	document.getElementById ("btn_Votar").disabled = false;

	document.getElementById ("btn_MeAfecta").style.cursor = "pointer";
	document.getElementById ("btn_MeAfecta").disabled = false;
}

function fn_ListaParametrosAjax ()
{
	var formulario = document.frm_Datos;
	var lista = "";

	lista = lista + "txt_HacerInsertComentario=" + formulario.txt_HacerInsertComentario.value;
	lista = lista + "&txt_HacerCargarComentarios=" + formulario.txt_HacerCargarComentarios.value;
	lista = lista + "&txt_HacerBorrarComentario=" + formulario.txt_HacerBorrarComentario.value;

	lista = lista + "&txt_HacerInsertSolucion=" + formulario.txt_HacerInsertSolucion.value;
	lista = lista + "&txt_HacerCargarSoluciones=" + formulario.txt_HacerCargarSoluciones.value;
	lista = lista + "&txt_HacerBorrarSolucion=" + formulario.txt_HacerBorrarSolucion.value;
	
	lista = lista + "&txt_HacerVotar=" + formulario.txt_HacerVotar.value;
	lista = lista + "&txt_HacerMeAfecta=" + formulario.txt_HacerMeAfecta.value;

	lista = lista + "&txt_IdComentario=" + formulario.txt_IdComentario.value;
	lista = lista + "&txt_IdSolucion=" + formulario.txt_IdSolucion.value;

	lista = lista + "&txt_Titulo=" + fn_Escape (trim (formulario.txt_Titulo.value));
	lista = lista + "&txt_Mensaje=" + fn_Escape (fn_ColocarSaltosDeLineaHTML (fn_QuitarBasuraExtremos (formulario.txt_Mensaje.value)));
	
	lista = lista + "&txt_TituloSolucion=" + fn_Escape (trim (formulario.txt_TituloSolucion.value));
	lista = lista + "&txt_TextoSolucion=" + fn_Escape (fn_ColocarSaltosDeLineaHTML (fn_QuitarBasuraExtremos (formulario.txt_TextoSolucion.value)));

	lista = lista + "&txt_IdTema=" + formulario.txt_Temp_Id.value;
	lista = lista + "&txt_TituloTema=" + fn_Escape (trim (formulario.txt_Temp_Titulo.value));
	lista = lista + "&txt_TituloUrl=" + fn_Escape (formulario.txt_Temp_TituloUrl.value);
	
	return lista;
}

function fn_EnviarComentario ()
{
	var formulario = document.frm_Datos;
	var textoMensaje = fn_QuitarBasuraExtremos (formulario.txt_Mensaje.value);
	
	if (textoMensaje == "")
	{
		alert ("El mensaje es obligatorio.");
		formulario.txt_Mensaje.focus ();
		return false;
	}	
	
	if (textoMensaje.length > 10000)
	{
		alert ("Superó el límite de 10000 caracteres para el mensaje.");
		formulario.txt_Mensaje.focus ();
		return false;
	}

	fn_LimpiarCamposControl ();
	fn_BloquearBotones ();
	
	formulario.txt_HacerInsertComentario.value = "-1";

	var parametrosAjax = fn_ListaParametrosAjax ();
	fn_InvocarAjax_Post (archivoAjax, parametrosAjax);
}

function fn_CargarComentarios ()
{
	fn_LimpiarCamposControl ();
	fn_BloquearBotones ();
	
	document.frm_Datos.txt_HacerCargarComentarios.value = "-1";

	var parametrosAjax = fn_ListaParametrosAjax ();
	fn_InvocarAjax_Post (archivoAjax, parametrosAjax);
}

function fn_InicioCargaComentarios ()
{
	document.frm_Datos.txt_Titulo.value = "";
	document.frm_Datos.txt_Mensaje.value = "";
	
	tablaComentarios = "";
	tablaComentarios = tablaComentarios + "<table id='tablaComentarios' border='0' width='100%' cellspacing='0' cellpadding='0'>";
	tablaComentarios = tablaComentarios + "	<tr>";
	tablaComentarios = tablaComentarios + "		<td colspan='3' style='padding-bottom:6px'>";
	tablaComentarios = tablaComentarios + "			<b><span id='spanTituloTablaComentarios' style='font-size:14px'></span></b>";
	tablaComentarios = tablaComentarios + "		</td>";
	tablaComentarios = tablaComentarios + "	</tr>";
}

function fn_AgregarComentario (contenido)
{
	tablaComentarios = tablaComentarios + contenido;
}

function fn_FinCargaComentarios (cantComentarios)
{
	tablaComentarios = tablaComentarios + "</table>";
	
	document.getElementById ("div_TablaComentarios").innerHTML = tablaComentarios;

	if (cantComentarios == "1")
		document.getElementById ("spanTituloTablaComentarios").innerHTML = "1 comentario";
	else
		document.getElementById ("spanTituloTablaComentarios").innerHTML = cantComentarios + "&nbsp;comentarios";
}

function fn_BorrarComentario (id)
{
	fn_LimpiarCamposControl ();
	fn_BloquearBotones ();
	
	document.frm_Datos.txt_HacerBorrarComentario.value = "-1";
	document.frm_Datos.txt_IdComentario.value = id;

	var parametrosAjax = fn_ListaParametrosAjax ();
	fn_InvocarAjax_Post (archivoAjax, parametrosAjax);
}

// Soluciones.
function fn_EnviarSolucion ()
{
	var formulario = document.frm_Datos;
	var textoSolucion = fn_QuitarBasuraExtremos (formulario.txt_TextoSolucion.value);
	
	if (trim (formulario.txt_TituloSolucion.value) == "")
	{
		alert ("El t" + String.fromCharCode (237) + "tulo es obligatorio.");
		formulario.txt_TituloSolucion.focus ();
		return false;
	}	

	if (textoSolucion == "")
	{
		alert ("La descripci" + String.fromCharCode (243) + "n es obligatoria.");
		formulario.txt_TextoSolucion.focus ();
		return false;
	}	
	
	if (textoSolucion.length > 10000)
	{
		alert ("Super" + String.fromCharCode (243) + " el l" + String.fromCharCode (237) + "mite de 10000 caracteres para la descripci" + String.fromCharCode (243) + "n.");
		formulario.txt_TextoSolucion.focus ();
		return false;
	}

	fn_LimpiarCamposControl ();
	fn_BloquearBotones ();
	
	formulario.txt_HacerInsertSolucion.value = "-1";

	var parametrosAjax = fn_ListaParametrosAjax ();
	fn_InvocarAjax_Post (archivoAjax, parametrosAjax);
}

function fn_CargarSoluciones ()
{
	fn_LimpiarCamposControl ();
	fn_BloquearBotones ();
	
	document.frm_Datos.txt_HacerCargarSoluciones.value = "-1";

	var parametrosAjax = fn_ListaParametrosAjax ();
	fn_InvocarAjax_Post (archivoAjax, parametrosAjax);
}

function fn_InicioCargaSoluciones ()
{
	document.frm_Datos.txt_TituloSolucion.value = "";
	document.frm_Datos.txt_TextoSolucion.value = "";
	
	tablaSoluciones = "";
	tablaSoluciones = tablaSoluciones + "<table id='tablaSoluciones' border='0' width='100%' cellspacing='0' cellpadding='0'>";
	tablaSoluciones = tablaSoluciones + "	<tr>";
	tablaSoluciones = tablaSoluciones + "		<td colspan='3' style='padding-bottom:6px'>";
	tablaSoluciones = tablaSoluciones + "			<b><span id='spanTituloTablaSoluciones' style='font-size:14px'></span></b>";
	tablaSoluciones = tablaSoluciones + "		</td>";
	tablaSoluciones = tablaSoluciones + "	</tr>";
}

function fn_AgregarSolucion (contenido)
{
	tablaSoluciones = tablaSoluciones + contenido;
}

function fn_FinCargaSoluciones (cantSoluciones)
{
	tablaSoluciones = tablaSoluciones + "</table>";
	
	document.getElementById ("div_TablaSoluciones").innerHTML = tablaSoluciones;

	if (cantSoluciones == "1")
		document.getElementById ("spanTituloTablaSoluciones").innerHTML = "1 soluci&oacute;n propuesta";
	else
		document.getElementById ("spanTituloTablaSoluciones").innerHTML = cantSoluciones + "&nbsp;soluciones propuestas";
		
	if (lvBol_CargarComentariosAlInicio)
	{
		lvBol_CargarComentariosAlInicio = false;
		fn_CargarComentarios ();
	}
}

function fn_BorrarSolucion (id)
{
	fn_LimpiarCamposControl ();
	fn_BloquearBotones ();
	
	document.frm_Datos.txt_HacerBorrarSolucion.value = "-1";
	document.frm_Datos.txt_IdSolucion.value = id;
	
	var parametrosAjax = fn_ListaParametrosAjax ();
	fn_InvocarAjax_Post (archivoAjax, parametrosAjax);
}

function fn_MostrarImagenAmpliada (width, height)
{
	var numWidth, numHeight, numLeft, numTop;
	var scrollbars = "no";
	var excedeWidth = false;
	var excedeHeight = false;
	
	numWidth = width + 44;
	numHeight = height + 238;
	numLeft = ((screen.availWidth / 2) - (numWidth / 2));
	numTop = ((screen.availHeight / 2) - (numHeight / 2));
	
	if (numWidth < 400)
		numWidth = 400;

	if (numWidth >= (screen.availWidth - 30))
	{
		numWidth = screen.availWidth - 30;
		numLeft = 10;
		scrollbars = "yes";
		excedeWidth = true;
	}

	if (numHeight >= (screen.availHeight - 80))
	{
		numHeight = screen.availHeight - 80;
		numTop = 0;
		scrollbars = "yes";
		excedeHeight = true;
	}
	
	if (excedeWidth && !excedeHeight)
		numHeight = numHeight + 18;
	else if (!excedeWidth && excedeHeight)
		numWidth = numWidth + 18;
		
	var ventanaPopUp = window.open ("", "popUpColaboras", "scrollbars=" + scrollbars + ",fullscreen=no,channelmode=no,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,width=" + numWidth + ",height=" + numHeight + ",left=" + numLeft + ",top=" + numTop);
	
	if (!ventanaPopUp.opener)
		ventanaPopUp.opener = self;

	if (window.focus)
		ventanaPopUp.focus();
		
	return true;
}

function fn_Votar ()
{
	var formulario = document.frm_Datos;
	
	if (document.getElementById ("txt_UsuarioLogueado").value != "-1")
		alert ("¡Necesita ingresar como usuario registrado para poder realizar esta acción!");
	else
	{
		fn_LimpiarCamposControl ();
		fn_BloquearBotones ();
		
		formulario.txt_HacerVotar.value = "-1";
	
		var parametrosAjax = fn_ListaParametrosAjax ();
		fn_InvocarAjax_Post (archivoAjax, parametrosAjax);
	}
}

function fn_MeAfecta ()
{
	var formulario = document.frm_Datos;
	
	if (document.getElementById ("txt_UsuarioLogueado").value != "-1")
		alert ("¡Necesita ingresar como usuario registrado para poder realizar esta acción!");
	else
	{
		fn_LimpiarCamposControl ();
		fn_BloquearBotones ();
		
		formulario.txt_HacerMeAfecta.value = "-1";
	
		var parametrosAjax = fn_ListaParametrosAjax ();
		fn_InvocarAjax_Post (archivoAjax, parametrosAjax);
	}
}

function fn_ActualizarCantidadVotos (cantVotos)
{
	var plural = "";
	
	if (parseInt (cantVotos) != 1)
		plural = "s";

	document.getElementById ("span_CantidadVotos").innerHTML = "A&nbsp;" + cantVotos + "&nbsp;persona" + plural + "&nbsp;le" + plural + "&nbsp;parece&nbsp;importante.";
	
	alert ("¡Muchas gracias!");
}

function fn_ActualizarCantidadMeAfecta (cantMeAfecta)
{
	var plural = "";
	
	if (parseInt (cantMeAfecta) != 1)
		plural = "s";

	document.getElementById ("span_CantidadMeAfecta").innerHTML = "A&nbsp;" + cantMeAfecta + "&nbsp;persona" + plural + "&nbsp;le" + plural + "&nbsp;afecta&nbsp;este&nbsp;problema.";
	
	alert ("¡Muchas gracias!");
}
