//--------------------------------------------------------------------------------------------------
// MUESTRA O OCULTA UN DIV EN POSICION ABSOLUTA
//--------------------------------------------------------------------------------------------------
function POPUP_MostrarOcultar(POPUPID)
{
	popup = document.getElementById(POPUPID);
	if (popup.style.display == "none") {
		popup.style.display = "";
	}
	else {
		popup.style.display = "none";
	}
}

/* FUNCIONES LISTBOX */

//--------------------------------------------------------------------------------------------------
// RECOPILA ELEMENTOS DE UN LIST BOX Y LOS GUARDA EN UNA LISTA SEPARADA POR COMAS EN UN HIDDEN
//--------------------------------------------------------------------------------------------------
function LISTBOX_RecopilarValores(control, hidden)
{
	LISTBOXCONTROL = document.getElementById(control);
	HIDDENLIST = document.getElementById(hidden);

	HIDDENLIST.value = "";
	count = LISTBOXCONTROL.length;
	for (n = 0; n < count; n++) {
		VALOR = LISTBOXCONTROL.options[n].value;
		
		if (HIDDENLIST.value != "") HIDDENLIST.value += ', ';
		HIDDENLIST.value += VALOR;
	}
}

//--------------------------------------------------------------------------------------------------
// TRASPASA ELEMENTOS SELECCIONADOS DE UN LIST BOX A OTRO
//--------------------------------------------------------------------------------------------------
function LISTBOX_TraspasarValoresSeleccionados(controlorigen, controldestino)
{
	LISTBOXORIG = document.getElementById(controlorigen);
	LISTBOXDEST = document.getElementById(controldestino);
	
	count = LISTBOXORIG.length;
	a = 0;
	b = LISTBOXDEST.length;
	while (a < count) {
		if (LISTBOXORIG.options[a].selected) {
			VALOR = LISTBOXORIG.options[a].value;
			TEXT = LISTBOXORIG.options[a].innerHTML;
			LISTBOXDEST.options[b] = new Option(TEXT, VALOR);
			b++;
			LISTBOXORIG.options[a] = null;
			a--;
			count--;
		}
		a++;
	}
}


//--------------------------------------------------------------------------------------------------
// QUITA ELEMENTOS EN EL LISTBOX DE LA IZQUIERDA QUE YA ESTEN EN LISTBOX DE LA DERECHA
//--------------------------------------------------------------------------------------------------
function LISTBOX_QuitarRepetidosIzquierda(controlizq, controlderecha)
{
	LISTBOXIZQ = document.getElementById(controlizq);
	LISTBOXDER = document.getElementById(controlderecha);
	
	count = LISTBOXDER.length;
	for (n = 0; n < count; n++) {
		VALOR = LISTBOXDER.options[n].value;
		numelem = LISTBOXIZQ.length;
		i = 0;
		while (i < numelem)
		{
			if (LISTBOXIZQ.options[i].value == VALOR) {
				LISTBOXIZQ.options[i] = null;
				break;
			}
			i++;
		}
	}
}
		

/* Sincronizacion de scrolls entre DIVs */

function SincronizarScrollHoriz(DIVORIGEN, DIVDESTINO)
{
	var SCROLLHORIZ = document.getElementById(DIVORIGEN).scrollLeft;
	document.getElementById(DIVDESTINO).scrollLeft = SCROLLHORIZ;
}


function SincronizarScrollVert(DIVORIGEN, DIVDESTINO)
{
	var SCROLLVERT = document.getElementById(DIVORIGEN).scrollTop;
	document.getElementById(DIVDESTINO).scrollTop = SCROLLVERT;
}


/* Validacion de Formularios */

function DesactivarForm(FORMID)
{
	var objForm = document.forms[FORMID];
	
	numElem = objForm.elements.length;
	for (i = 0; i < numElem; i++) {
		objForm.elements[i].disabled = true;
	}
}


function ActivarForm(FORMID)
{
	var objForm = document.forms[FORMID];
	
	numElem = objForm.elements.length;
	for (i = 0; i < numElem; i++) {
		objForm.elements[i].disabled = false;
	}
}


function DesactivarFormularios()
{
	for (n = 0; n < document.forms.length; n++)
	{
		objForm = document.forms[n];
		numElem = objForm.elements.length;
		for (i = 0; i < numElem; i++) {
			objForm.elements[i].disabled = true;
		}
	}
}


function ActivarFormularios()
{
	for (n = 0; n < document.forms.length; n++)
	{
		objForm = document.forms[n];
		numElem = objForm.elements.length;
		for (i = 0; i < numElem; i++) {
			objForm.elements[i].disabled = false;
		}
	}
}


function ValidarCampoTexto(ID, blnObligatorio, jsError)
{
	var elem = document.getElementById(ID);

	if (blnObligatorio) {
		if (elem.value.replace(" ", "") == "") {
			alert(jsError);
			elem.focus();
			return false;
		}
	}
	if (elem.value.indexOf("\"") != -1) {
		alert("No se puede introducir comillas (\") en el campo de texto");
		elem.focus();
		return false;
	}
	if (elem.value.indexOf("\'") != -1) {
		alert("No se puede introducir comillas (\') en el campo de texto");
		elem.focus();
		return false;
	}
	if (elem.value.indexOf("&") != -1) {
		alert("No se puede introducir ampersand (&) en el campo de texto");
		elem.focus();
		return false;
	}
	return true;
}


function ValidarPassword(ID, jsError)
{
	var elem = document.getElementById(ID);

	if (elem.value.replace(" ", "") == "") {
		alert(jsError);
		elem.focus();
		return false;
	}
	if (elem.value.indexOf("\"") != -1) {
		alert("No se puede introducir comillas (\") en la clave");
		elem.focus();
		return false;
	}
	if (elem.value.indexOf("\'") != -1) {
		alert("No se puede introducir comillas (\') en la clave");
		elem.focus();
		return false;
	}
	if (elem.value.indexOf("&") != -1) {
		alert("No se puede introducir el ampersand (&) en la clave");
		elem.focus();
		return false;
	}
	if (elem.value.length < 6) {
		alert(jsError);
		elem.focus();
		return false;
	}
	return true;
}


// Control BesLoading - ESPERE
// ---------------------------------------------------------------------------------------------------------
var scrollingload;

function MostrarCargandoPanel(DIV)
{
	document.getElementById(DIV).style.display = '';
	document.getElementById(DIV).innerHTML = "<div class='cargando' align='center' style='position:absolute; padding:5px; width:100%; height:100%'><br />Cargando datos...</div>";
}

function BESLOADING_Mostrar()
{	
	//DesactivarFormularios();
	// PARA ENVIAR POSTS POR FRAMESUBMIT NO SE ENVIAN LOS ELEMENTOS DESACTIVADOS
	try
	{
		document.getElementById('ESPERA').style.left = '0px';
		//document.getElementById('ESPERA').style.top = '0px';
		document.getElementById('ESPERA').style.top = document.body.scrollTop + 'px';
		document.getElementById('ESPERA').style.display = '';
		document.getElementById('ESPERA').style.zIndex = 50;
		document.body.style.overflow = "hidden";
		document.getElementById('ESPERA').style.width= document.body.clientWidth + 'px';
	}
	catch(err){}
}

function BESLOADING_Ocultar()
{	
	//ActivarFormularios();
	// PARA ENVIAR POSTS POR FRAMESUBMIT NO SE ENVIAN LOS ELEMENTOS DESACTIVADOS
	document.getElementById('ESPERA').style.display = 'none';
	document.getElementById('ESPERA').style.zIndex = -1;
	document.body.style.overflow = "auto"
}

// TODO: Substituir funciones ShowLoading y HideLoading por BESLOADING mostrar y ocultar

function ShowLoading()
{
	BESLOADING_Mostrar();
}
		
function HideLoading()
{
	BESLOADING_Ocultar();
}

// ---------------------------------------------------------------------------------------------------------
function BESLOADING_AnimarLogoBBS()
{
	var imgref = new Array(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 10, 9, 8, 7, 6, 5, 4, 3);
	
	var img = document.getElementById('LOGOBBSESPERA');
	if (typeof img.num == 'undefined') img.num = 0;
	img.src = '/images/logotest/LogotipoBBS_' + imgref[img.num] + '.jpg';
	img.num++;
	if (img.num > 17) img.num = 0;
	setTimeout('BESLOADING_AnimarLogoBBS()', 125);
}

// Control BesDebugPanel
// ---------------------------------------------------------------------------------------------------------

function WEBCONTROLS_DEBUGBAR_VerParams()
{
	var panel = document.getElementById('DEBUGPARAMS');
	if (panel.style.display == 'none') {
		panel.style.display = '';
		panel.style.zIndex = 100;
	}
	else {
		panel = document.getElementById('DEBUGPARAMS');
		panel.style.display = 'none'
		panel.style.zIndex = -1;
	}
	panel = document.getElementById('AJAXRESULT');
	panel.style.display = 'none'
	panel.style.zIndex = -1;
	panel = document.getElementById('DEBUGFRASUBMIT');
	panel.style.display = 'none'
	panel.style.zIndex = -1;
}


function WEBCONTROLS_DEBUGBAR_VerAjax()
{
	var panel = document.getElementById('contenedorAjax');

	if (panel.style.display == 'none') 
	{
		panel.style.display = '';
		panel.style.zIndex = 100;
	}
	else 
	{		
		panel.style.display = 'none'
		panel.style.zIndex = -1;
	}

	panel = document.getElementById('DEBUGPARAMS');
	panel.style.display = 'none'
	panel.style.zIndex = -1;
	panel = document.getElementById('DEBUGFRASUBMIT');
	panel.style.display = 'none'
	panel.style.zIndex = -1;
}


function WEBCONTROLS_DEBUGBAR_VerIFrame()
{
	var panel = document.getElementById('DEBUGFRASUBMIT');
	if (panel.style.display == 'none') {
		panel.style.display = '';
		panel.style.zIndex = 100;
	}
	else {		
		panel.style.display = 'none'
		panel.style.zIndex = -1;
	}
	panel = document.getElementById('DEBUGPARAMS');
	panel.style.display = 'none'
	panel.style.zIndex = -1;
	panel = document.getElementById('AJAXRESULT');
	panel.style.display = 'none'
	panel.style.zIndex = -1;
}

function WEBCONTROLS_DEBUGBAR_Mover()
{
	//document.getElementById("DEBUGBAR").style.top = "100px";
	//document.getElementById("DEBUGBAR").style.bottom = "0px";
	if (document.getElementById("DEBUGBAR").style.display == "none")
	{		
		document.getElementById("DEBUGBAR").style.display = "";
		document.getElementById("DEBUGMIN").style.display = "none";
		document.getElementById("DEBUGBAR").style.height = "100px";
	}
	else
	{	
		document.getElementById("DEBUGBAR").style.display = "none";
		document.getElementById("DEBUGMIN").style.display = "";
	}
}

function WEBCONTROLS_DEBUGBAR_Desactivar()
{
	panel = document.getElementById('DEBUGPARAMS');
	panel.style.display = 'none'
	panel.style.zIndex = -1;
	panel = document.getElementById('AJAXRESULT');
	panel.style.display = 'none'
	panel.style.zIndex = -1;
	panel = document.getElementById('DEBUGFRASUBMIT');
	panel.style.display = 'none'
	panel.style.zIndex = -1;			
	document.getElementById('DEBUGBAR').style.display = 'none';
}


// WEBCONTROL BESBOTON
// ---------------------------------------------------------------------------------------------------------

function BESBOTON_onmouseover(obj)
{
	obj.style.color = '#4444ff';
}

function BESBOTON_onmouseout(obj)
{
	obj.style.color = '#000000';
}


function BESBOTONTOGGLE_Inicializar(DIVPARENT)
{
	var activo = document.getElementById(DIVPARENT + '_ACTIVO');
	activo.toggled = true;
	document.getElementById(DIVPARENT).ultimoToggled = activo;
}


function BESBOTONTOGGLE_click(obj, DIVPARENT)
{
	if (typeof obj.toggled == 'undefined') obj.toggled = false;
	if (obj.toggled) {
		obj.toggled = false;
		obj.className = 'besBoton';
	} else {
		obj.toggled = true;
		obj.className = 'besBotonToggle';
	}

	var ultimo = document.getElementById(DIVPARENT).ultimoToggled;
	if (typeof(ultimo) != 'undefined') {
		ultimo.toggled = false;
		ultimo.className = 'besBoton';
	}
	obj.toggled = true;
	obj.className = 'besBotonToggle';
	document.getElementById(DIVPARENT).ultimoToggled = obj;
}


// WEBCONTROL BESTAB - REQUIERE AJAX.JS
// ---------------------------------------------------------------------------------------------------------

function BESTAB_onmouseover(obj)
{
	/*if (obj.activo) {
		obj.className = 'besTabActivoHover';
	}
	else {
		obj.className = 'besTabHover';
	}*/
}


function BESTAB_onmouseout(obj)
{
	/*if (obj.activo) {
		obj.className = 'besTabActivo';
	}
	else {
		obj.className = 'besTab';
	}*/
}


function BESTAB_onclick(obj, DIVDESTINO, ajaxURL, guardarCallback, onloadCallback)
{
	// el div que engloba las pestañas recuerda el ultimo tab activo
	if (eval(guardarCallback)) {
		// Recordar ultima pestaña activa en el DIV padre
		var antiguo = document.getElementById(DIVDESTINO).ultimoTabActivo;
		if (typeof(antiguo) != 'undefined') {
			antiguo.activo = false;
			antiguo.className = 'besTab';
		}
		obj.activo = true;
		obj.className = 'besTabActivo';
		document.getElementById(DIVDESTINO).ultimoTabActivo = obj;
		
		BESTABPANEL_Cargar(DIVDESTINO, ajaxURL, onloadCallback);
	}
}


// WEBCONTROL BESTAB2 - REQUIERE AJAX.JS
// ---------------------------------------------------------------------------------------------------------

function BESTAB2_onmouseover(obj)
{
	/*if (obj.activo) {
		obj.className = 'besTabActivoHover2';
	}
	else {
		obj.className = 'besTabHover2';
	}*/
}


function BESTAB2_onmouseout(obj)
{
	/*if (obj.activo) {
		obj.className = 'besTabActivo2';
	}
	else {
		obj.className = 'besTab2';
	}*/
}


function BESTAB2_onclick(obj, DIVDESTINO, ajaxURL, guardarCallback, onloadCallback)
{
	// el div que engloba las pestañas recuerda el ultimo tab activo
	if (eval(guardarCallback)) {
		// Recordar ultima pestaña activa en el DIV padre
		var antiguo = document.getElementById(DIVDESTINO).ultimoTabActivo;
		if (typeof(antiguo) != 'undefined') {
			antiguo.activo = false;
			antiguo.className = 'besTab2';
		}
		obj.activo = true;
		obj.className = 'besTabActivo2';
		document.getElementById(DIVDESTINO).ultimoTabActivo = obj;
		
		BESTABPANEL_Cargar(DIVDESTINO, ajaxURL, onloadCallback);
	}
}


// WEBCONTROL BESTABPANEL
// ---------------------------------------------------------------------------------------------------------

function BESTABPANEL_Inicializar(IDTABPANEL)
{
	var tabobj = document.getElementById(IDTABPANEL + '_TABACTIVO');

	if (tabobj) 
	{
		tabobj.activo = true;
		document.getElementById(IDTABPANEL).ultimoTabActivo = tabobj;
		tabobj.onclick();
		if (tabobj.onmouseout) tabobj.onmouseout();
	}
}

function BESTABPANEL_SeleccionarTab(IDTABPANEL, IDTAB)
{
	if (document.getElementById(IDTAB)) {
		var tabobj = document.getElementById(IDTAB);
		tabobj.activo = true;
		tabobj.onclick();
		if(document.getElementById(IDTABPANEL)){
			var antiguo = document.getElementById(IDTABPANEL).ultimoTabActivo;
			if (typeof(antiguo) != 'undefined') {
				if (antiguo.onmouseout) antiguo.onmouseout();
			}
		}
	}
}

function BESTABPANEL_Recargar(IDTABPANEL)
{
	var tabobj = document.getElementById(IDTABPANEL).ultimoTabActivo;
	tabobj.onclick();
	if (tabobj.onmouseout) tabobj.onmouseout();
}


function BESTABPANEL_Cargar(IDTABPANEL, ajaxURL, onloadCallback)
{
	if (typeof(AjaxCreate) == 'undefined') {
		alert("Este modulo requiere la libreria AJAX. Contacte con el soporte tecnico");
		throw new Error('Este modulo requiere la libreria AJAX. Contacte con el soporte tecnico');
	}

	if (ajaxURL != "") {
		//AjaxGetPanel(ajaxURL, IDTABPANEL);
		AjaxGetPanel(ajaxURL, IDTABPANEL, function() {
			eval(onloadCallback);
		});
	}
}


// WEBCONTROL BESTABIFRAME - Control de pestañas con IFrames
// ---------------------------------------------------------------------------------------------------------

function BESTABIFRAME_onmouseover(obj)
{
	/*if (obj.activo) {
		obj.className = 'besTabActivoHover';
	}
	else {
		obj.className = 'besTabHover';
	}*/
}


function BESTABIFRAME_onmouseout(obj)
{
	/*if (obj.activo) {
		obj.className = 'besTabActivo';
	}
	else {
		obj.className = 'besTab';
	}*/
}


function BESTABIFRAME_onclick(obj, IDIFRAME, strURL, guardarCallback)
{
	if (eval(guardarCallback)) {
		// el div que engloba las pestañas recuerda el ultimo tab activo
		// Recordar ultima pestaña activa en el DIV padre
		var antiguo = document.getElementById(IDIFRAME + '_PANEL').ultimoTabActivo;
		if (typeof(antiguo) != 'undefined') {
			antiguo.activo = false;
			antiguo.className = 'besTab';
		}
		obj.activo = true;
		obj.className = 'besTabActivo';
		document.getElementById(IDIFRAME + '_PANEL').ultimoTabActivo = obj;
		
		BESTABPANELIFRAME_Cargar(IDIFRAME, strURL);
	}
}

function BESTABIFRAME2_onclick(obj, IDIFRAME, strURL, guardarCallback)
{
	if (eval(guardarCallback)) {
		// el div que engloba las pestañas recuerda el ultimo tab activo
		// Recordar ultima pestaña activa en el DIV padre
		var antiguo = document.getElementById(IDIFRAME + '_PANEL').ultimoTabActivo;
		if (typeof(antiguo) != 'undefined') {
			antiguo.activo = false;
			antiguo.className = 'besTab3';
		}
		obj.activo = true;
		obj.className = 'besTabActivo3';
		document.getElementById(IDIFRAME + '_PANEL').ultimoTabActivo = obj;
		
		BESTABPANELIFRAME_Cargar(IDIFRAME, strURL);
	}
}

function BESTABIFRAME3_onclick(obj, IDIFRAME, strURL, guardarCallback)
{
	if (eval(guardarCallback)) 
	{
		// el div que engloba las pestañas recuerda el ultimo tab activo
		// Recordar ultima pestaña activa en el DIV padre
		var antiguo = document.getElementById(IDIFRAME + '_PANEL').ultimoTabActivo;

		if (typeof(antiguo) != 'undefined') 
		{
			antiguo.activo = false;
			antiguo.className = 'besTabIframe3_Tab';
		}
		obj.activo = true;
		obj.className = 'besTabIframe3_TabActivo';
		document.getElementById(IDIFRAME + '_PANEL').ultimoTabActivo = obj;
		
		BESTABPANELIFRAME_Cargar(IDIFRAME, strURL);
	}
}

// WEBCONTROL BESTABPANELIFRAME
// ---------------------------------------------------------------------------------------------------------

function BESTABPANELIFRAME_Inicializar(IDIFRAME)
{
	var tabobj = document.getElementById(IDIFRAME + '_TABACTIVO');
	if (tabobj) 
	{
		tabobj.activo = true;
		document.getElementById(IDIFRAME + '_PANEL').ultimoTabActivo = tabobj;
		tabobj.onclick();
		if (tabobj.onmouseout) tabobj.onmouseout();
	}
}

function BESTABPANELIFRAME_SeleccionarTab(IDIFRAME, IDTAB)
{
	var tabobj = document.getElementById(IDTAB);

	tabobj.activo = true;
	tabobj.onclick();
	var antiguo = document.getElementById(IDIFRAME + '_PANEL').ultimoTabActivo;
	if (typeof(antiguo) != 'undefined') {
		if (antiguo.onmouseout) antiguo.onmouseout();
	}
}

function BESTABPANELIFRAME_Cargar(IDIFRAME, strURL)
{
	if (strURL != "") {
		document.getElementById(IDIFRAME).src = strURL;
	}
}


// WEBCONTROL BESSEPARADOR
// ---------------------------------------------------------------------------------------------------------

var WEBCONTROLS_divseparador = null;
var CAPA_Browser = new CAPA_browser();


function WEBCONTROLS_BESSEPARADOR_onmouseover(IDPANELMOVIBLE)
{
	if (!WEBCONTROLS_divseparador) {
		var obj = document.getElementById(IDPANELMOVIBLE + "_SEPARADOR");
		obj.style.backgroundColor = '#b6cde4';
	}
}


function WEBCONTROLS_BESSEPARADOR_onmouseout(IDPANELMOVIBLE)
{
	if (!WEBCONTROLS_divseparador) {
		var obj = document.getElementById(IDPANELMOVIBLE + "_SEPARADOR");
		obj.style.backgroundColor = '#e4f1f8';
	}
}


function WEBCONTROLS_BESSEPARADOR_onmousedown(IDPANELMOVIBLE)
{
	if (!WEBCONTROLS_divseparador) {
				
		var capa = document.getElementById(IDPANELMOVIBLE + "_CAPA");
		capa.style.zIndex = 49;
		capa.style.display = '';

		var obj = document.getElementById(IDPANELMOVIBLE + "_SEPARADOR");
		obj.style.backgroundColor = '#b6cde4';

		WEBCONTROLS_divseparador = obj;
		document.onmousemove = WEBCONTROLS_BESSEPARADOR_onmousemove;
		
		if (CAPA_Browser.isIE)
		{			
			window.event.cancelBubble = true;
			window.event.returnValue = false;
		}
		if (CAPA_Browser.isNS)
		{
			event.preventDefault();
		}
		
	}
}


function WEBCONTROLS_BESSEPARADOR_onmouseup(IDPANELMOVIBLE)
{
	if (WEBCONTROLS_divseparador) {
		var capa = document.getElementById(IDPANELMOVIBLE + "_CAPA");
		capa.style.zIndex = -1;
		capa.style.display = 'none';

		var obj = document.getElementById(IDPANELMOVIBLE + "_SEPARADOR");
		obj.style.backgroundColor = '#e4f1f8';
		document.getElementById(IDPANELMOVIBLE).style.width = (obj.separadorLeft) + 'px';

		WEBCONTROLS_divseparador = null;
	}
}


function WEBCONTROLS_BESSEPARADOR_CAPA_onmouseup(IDPANELMOVIBLE)		//CAPA del BESSEPARADOR
{
	if (WEBCONTROLS_divseparador) {
		var capa = document.getElementById(IDPANELMOVIBLE + "_CAPA");
		capa.style.zIndex = -1;
		capa.style.display = 'none';

		var obj = document.getElementById(IDPANELMOVIBLE + "_SEPARADOR");
		obj.style.backgroundColor = '#e4f1f8';
		document.getElementById(IDPANELMOVIBLE).style.width = (obj.separadorLeft) + 'px';

		WEBCONTROLS_divseparador = null;
	}
}


function WEBCONTROLS_BESSEPARADOR_onmousemove(ev)
{
	var mouseevent = ev;
	if (!ev) mouseevent = window.event;

	if (WEBCONTROLS_divseparador) {
		if (mouseevent.pageX || mouseevent.pageY) {
			mousex = mouseevent.pageX;
			mousey = mouseevent.pageY;
		}
		else {
			mousex = mouseevent.clientX + document.body.scrollLeft - document.body.clientLeft;
			mousey = mouseevent.clientY + document.body.scrollTop - document.body.clientTop;
		}
		
		w = mousex - 3;
		if (w < 30) w = 30;
		if (w > document.body.clientWidth - 30) w = document.body.clientWidth - 30;
		WEBCONTROLS_divseparador.separadorLeft = w;
		WEBCONTROLS_divseparador.style.left = w + 'px';
		//WEBCONTROLS_divseparador.innerHTML = "x: " + mousex + " - y:" + mousey + " - width: " + document.body.clientWidth + " - height: " + document.body.clientHeight;
		if (CAPA_Browser.isIE)
		{			
			window.event.cancelBubble = true;
			window.event.returnValue = false;
		}
		if (CAPA_Browser.isNS)
		{
			event.preventDefault();
		}
	}
}

// ----------------------------------------------------------------------------
// Mover una capa con el Raton, en pruebas en BesDebugPanel
// ----------------------------------------------------------------------------
function CAPA_browser()
{
	// Determine browser and version.
	var ua, s, i;
	this.isIE = false;
	this.isNS = false;
	this.version = null;
	ua = navigator.userAgent;
	s = "MSIE";
	if ((i = ua.indexOf(s)) >= 0)
	{
		this.isIE = true;
		this.version = parseFloat(ua.substr(i + s.length));
		return;
	}
	s = "Netscape6/";
	if ((i = ua.indexOf(s)) >= 0)
	{
		this.isNS = true;
		this.version = parseFloat(ua.substr(i + s.length));
		return;
	}
	// Treat any other "Gecko" browser as NS 6.1.  
	s = "Gecko";
	if ((i = ua.indexOf(s)) >= 0)
	{
		this.isNS = true;
		this.version = 6.1;
		return;
	}
}

var CAPA_Drag = new Object();
CAPA_Drag.zIndex = 0;

function CAPA_IniciarDrag(event, CAPA)
{
	var el;
	var x, y;
	
	if (CAPA)
	{
		//Si le pasamos un ID de capa, usar esa capa.
		CAPA_Drag.elNode = document.getElementById(CAPA);			
	}
	else
	{
		//Si no se pasa ninguna capa se movera la capa que ha activado el evento.
		if (CAPA_Browser.isIE)
		{
			CAPA_Drag.elNode = window.event.srcElement;				
		}
		
		if (CAPA_Browser.isNS)
		{
			CAPA_Drag.elNode = event.target;				
		}
		
		if (CAPA_Drag.elNode.type == 3)
		{
			CAPA_Drag.elNode = dragObj.elNode.parentNode;
		}
	}
	//Despues hay que obtener las coordenadas actuales del mouse relativas a la página.
	if (CAPA_Browser.isIE)
	{
		x = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
		y = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop;
	}
	
	if (CAPA_Browser.isNS)
	{
		x = event.clientX + window.scrollX;
		y = event.clientY + window.scrollY;
	}
	//Se guarda la posicion inicial de cursor y elemento, con su ancho
	
	CAPA_Drag.cursorStartX = x;
	CAPA_Drag.cursorStartY = y;
	
	CAPA_Drag.elStartLeft  = parseInt(CAPA_Drag.elNode.style.left, 10);
	CAPA_Drag.elStartTop   = parseInt(CAPA_Drag.elNode.style.top,  10);
	CAPA_Drag.elStartWidth = parseInt(CAPA_Drag.elNode.style.width, 10);	
	
	if (isNaN(CAPA_Drag.elStartLeft))
	{
		CAPA_Drag.elStartLeft = 0;
	}
	if (isNaN(CAPA_Drag.elStartTop))
	{
		CAPA_Drag.elStartTop  = 0;
	}
	//Se lleva el nodo encima del todo de la página.
	CAPA_Drag.elNode.style.zIndex = ++CAPA_Drag.zIndex
	//Capturar los eventos mousemove y mouseup del documento, y
	//sustituirlos por los nuestros.
	if (CAPA_Browser.isIE)
	{
		document.attachEvent("onmousemove", CAPA_MoverCapa);
		document.attachEvent("onmouseup",   CAPA_FinDrag);
		window.event.cancelBubble = true;
		window.event.returnValue = false;
	}
	if (CAPA_Browser.isNS)
	{
		document.addEventListener("mousemove", CAPA_MoverCapa,   true);
		document.addEventListener("mouseup",   CAPA_FinDrag, true);
		event.preventDefault();
	}
}

function CAPA_MoverCapa(event)
{
	var x, y;
	
	if (CAPA_Browser.isIE)
	{
		x = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
		y = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop;
	}
	
	if (CAPA_Browser.isNS)
	{
		x = event.clientX + window.scrollX;
		y = event.clientY + window.scrollY;
	}
	if ((CAPA_Drag.elStartLeft + x - CAPA_Drag.cursorStartX) > 0 && ((CAPA_Drag.elStartLeft + x - CAPA_Drag.cursorStartX) + CAPA_Drag.elStartWidth) < document.body.clientWidth)
	{
		CAPA_Drag.elNode.style.left = (CAPA_Drag.elStartLeft + x - CAPA_Drag.cursorStartX) + "px";
	}
	else if ((CAPA_Drag.elStartLeft + x - CAPA_Drag.cursorStartX) == 0)
	{
		CAPA_Drag.elNode.style.left = 0;
	}
	else if (((CAPA_Drag.elStartLeft + x - CAPA_Drag.cursorStartX) + CAPA_Drag.elStartWidth) == document.body.clientWidth)
	{
		CAPA_Drag.elNode.style.left = document.body.clientWidth - CAPA_Drag.elStartWidth;
	}
	
	if ((CAPA_Drag.elStartTop  + y - CAPA_Drag.cursorStartY) > 0 && ((CAPA_Drag.elStartTop  + y - CAPA_Drag.cursorStartY) + 60) < document.body.clientHeight)
	{
		CAPA_Drag.elNode.style.top = (CAPA_Drag.elStartTop  + y - CAPA_Drag.cursorStartY) + "px";
	}
	else if ((CAPA_Drag.elStartTop  + y - CAPA_Drag.cursorStartY) == 0)
	{
		CAPA_Drag.elNode.style.top = 0;
	}
	else if (((CAPA_Drag.elStartTop  + y - CAPA_Drag.cursorStartY) + 60) == document.body.clientHeight)
	{
		CAPA_Drag.elNode.style.Top = document.body.clientHeight - 60;
	}
	if (CAPA_Browser.isIE)
	{
		window.event.cancelBubble = true;
		window.event.returnValue = false;
	}
	if (CAPA_Browser.isNS)
	{
		event.preventDefault();
	}
	
}

function CAPA_FinDrag(event)
{
	if (CAPA_Browser.isIE)
	{
		document.detachEvent("onmousemove", CAPA_MoverCapa);
		document.detachEvent("onmouseup",   CAPA_FinDrag);
	}
	if (CAPA_Browser.isNS)
	{
		document.removeEventListener("mousemove", CAPA_MoverCapa,   true);
		document.removeEventListener("mouseup",   CAPA_FinDrag, true);
	}
}

function WEBCONTROLS_DEBUGBAR_ToggleNoCopy()
{
	try
	{
		if (EnableRightClick == 0)
		{
			EnableRightClick = 1;
			document.getElementById("ACTIVARNOCOPY").innerHTML = "Des. NoCopy";
		}
		else
		{
			EnableRightClick = 0;
			document.getElementById("ACTIVARNOCOPY").innerHTML = "Act. NoCopy";
		}
	}
	catch(err)
	{
		window.alert("No se pudo descativar NoCopy.\n" + err);
	}
}
