// JavaScript Document

/* FUNCIONES DE AJAX */

function procesandoEnDiv (div)
{
	$("#"+div).append('<div id="ajax_procesando" class="ajax_procesandoEnDiv"></div>');
}

function postAjax(direccion,data, div)
{
	 $.ajax({
			beforeSend: procesando(),
			type: "POST",
			url: direccion,
			cache: false,
			data: data,
			success: function(htmlResult)
			{
				quitarProcesando();
				var obj = "#" + div;
				$(obj).html(htmlResult);
			}
	});
}

function postAjaxSP(direccion,data, div)
{
	 $.ajax({
			type: "POST",
			url: direccion,
			cache: false,
			data: data,
			success: function(htmlResult)
			{
				var obj = "#" + div;
				$(obj).html(htmlResult);
			}
	});
}

function getAjax(direccion,data, div)
{
	 $.ajax({
			beforeSend: procesando(),
			type: "GET",
			url: direccion,
			cache: false,
			data: data,
			success: function(htmlResult)
			{
				quitarProcesando();
				var obj = "#" + div;
				$(obj).html(htmlResult);
			}
	});
}

function getAjaxSP(direccion,data, div)
{
	 $.ajax({
			type: "GET",
			url: direccion,
			data: data,
			cache: false,
			success: function(htmlResult)
			{
				quitarProcesando();
				var obj = "#" + div;
				$(obj).html(htmlResult);
			}
	});
}

function abrirVentana(direccion, alto, ancho, div)
{
	$('#'+div).html('<iframe src="'+direccion+'" scrolling="no" height="'+alto+'" width="'+ancho+'"></iframe>');
}

function cerrarVentana(idparticipante)
{
	$("#ventana"+idparticipante).html('');
}

function textAreaMaxLenght()
{
	$("textarea[maxlength]").keypress(function(event){  
		var key = event.which;  
		//Todas las teclas menos el backspace
		if(key >= 33 || key == 13) 
		{  
			var maxLength = $(this).attr("maxlength");  
			var length = this.value.length;  
			if(length >= maxLength) 
			{  
				event.preventDefault();  
			}
		}  
	});
}

function reproducirAudio (archivo){
	
	var ultimo = $("#ultimo").val();
	window.open('sonido.php?audio='+archivo+'&ultimo='+ultimo,'sonido','');
	
	if (ultimo == archivo)
	{
		$("#ultimo").val('');
	}
	else
	{
		$("#ultimo").val(archivo);
	}
	
}
