function notdo() {}
//----------------------------------------------------------------
// Funciones de FORMULARIOS
//----------------------------------------------------------------
function Aceptar(form) {
	form.submit();
}
function Actualizar(form) {
	form.submit();
	self.close();
}
function Accion(accion_str) {
	document.DATOS.ACCION.value	= accion_str;
	document.DATOS.submit();
}
function setAnchor(anchor_str) {
	accion = document.DATOS.ACCION.value + "#" + anchor_str;
	document.DATOS.ACCION.value = accion;
}
function AccionFicha(accion_str, ficha) {
	document.DATOS._APP_FICHA.value	= ficha;
	document.DATOS.ACCION.value		= accion_str;
	document.DATOS.submit();
}
function setTarget(target_str) {
	window.document.DATOS.A_DESTINO.value = target_str;
}
function setFormTarget(target_str) {
	window.document.DATOS.target = target_str;
}
function setFormAction(action_str) {
	window.document.DATOS.action = action_str;
}
function imprimir(action_str){
	setFormTarget('_blank');
	setFormAction(action_str);
	Accion('IMPRIMIR');
	setFormTarget('');
	setFormAction('');
}
function EliminarConfirm(accion_str) {
	res=confirm("¿Quiere eliminar DEFINITIVAMENTE los datos seleccionados?");
	if (res==true) {
		document.DATOS.ACCION.value=accion_str;
		document.DATOS.submit();
	}
}
function SelectItem(sele,value) {
	 for (i=0;i<(sele.length);i++)  {
		//sele.options.selectedIndex=value;
		if ( sele.options[i].value == value ) {
			sele.options[i].selected = true;
		}
	}
}
//----------------------------------------------------------------
// Funciones de TEXTAREA
//----------------------------------------------------------------
function TextAreaInsert(textarea,campo,tipo,fuente,fuente_size) {
	var estilo,estilo_font,estilo_size;
	estilo		= "";
	estilo_font	= "";
	estilo_size	= "";
	if (fuente != ""){
		estilo_font = "font-family : " + fuente + ";";
	}
	if (fuente_size != "") {
		estilo_size = "font-size : " + fuente_size + "pt;";
	}
	if ( estilo_font != "" || estilo_size != "") {
		estilo = " style=\"" + estilo_font + estilo_size + "\"";
	}
	switch (tipo) {
		case "negrita" :
			textarea.value=textarea.value + "<b" + estilo + ">" + campo.value + "</b>";
		break;
		case  "italica" :
			textarea.value=textarea.value + "<i" + estilo +">" + campo.value + "</i>";
		break;
		case  "subrayado" :
			textarea.value=textarea.value + "<u" + estilo + ">" + campo.value + "</u>";
		break;
		case  "tachado" :
			textarea.value=textarea.value + "<s" + estilo + ">" + campo.value + "</s>";
		break;
	}
	//Limpiar el campo
	campo.value="";
}
function TextAreaColor(textarea,campo,color) {
	textarea.value=textarea.value + "<font color=" + color + ">" + campo.value + "</font>";
	window.close();
	//Limpiar el campo
	campo.value="";
}
function TextAreaLink(textarea,campo_int,campo_ext,popup) {
	if (popup[0].checked==true) {
		popupStr="target='_blank'";
	}
	else {
		popupStr="";
	}
	if (campo_int.value!="") {
		textarea.value=textarea.value + "<a href='?ID_PAGINA=" + campo_int.value + "' " + popupStr + " > </a>";
	}
	else {
		if (campo_ext.value!="") {
			textarea.value=textarea.value + "<a href='" + campo_ext.value + "' " + popupStr + " > </a>";
			textarea.Value=textarea.Value + "<a href='" + campo_ext.value + "' " + popupStr + " > </a>";
		}
	}
	//Limpiar el campo
	campo_ext.value="";
}
function Formato_Texto(obj){
	var ESTILO,TEXTO_FIN;
	ESTILO="";
	TEXTO_FIN="";
	text=obj.ENT.value;
	if (text != "") {
		color	= obj.COLOR.value;
		fuente	= obj.FUENTE.value;
		size	= obj.SIZE.value;
		if ( color !="") {
			ESTILO=" color : " + color + ";";
		}
		if (fuente!="") {
			ESTILO = ESTILO + " font-family : " + fuente + ";";
		}
		if (size!="") {
			ESTILO = ESTILO + " font-size : " + size + "pt;";
		}
		if (ESTILO!="") {
			TEXTO_FIN = "<font style=\"" + ESTILO + "\">" + text + "</font>";
		}
		else {
			TEXTO_FIN = text;
		}
		//NEGRITA
		if (obj.FORMATO[0].checked==true) {
			TEXTO_FIN="<b>" + TEXTO_FIN + "</b>";
		}
		//CURSIVA
		if (obj.FORMATO[1].checked==true) {
			TEXTO_FIN="<i>" + TEXTO_FIN + "</i>";
		}
		//SUBRAYADO
		if (obj.FORMATO[2].checked==true) {
			TEXTO_FIN="<u>" + TEXTO_FIN + "</u>";
		}
		//TACHADO
		if (obj.FORMATO[3].checked==true) {
			TEXTO_FIN="<s>" + TEXTO_FIN + "</s>";
		}
		obj.TEXTO.value = obj.TEXTO.value + TEXTO_FIN;
		// RESSET datos
		obj.COLOR.value="";
		obj.FUENTE.options[0].selected=true;
		obj.SIZE.options[0].selected=true;
		for (i=0; i < obj.FORMATO.length; i++) {
			obj.FORMATO[i].checked=false;
		}
		obj.ENT.value="";
		// DEBUG
		//alert(TEXTO_FIN);
		//obj.FORMATO.length);
	}
}
//----------------------------------------------------------------
// Funciones de CHECKBOX
//----------------------------------------------------------------
function CB_selectAll(obj, val) {
	num = obj.length;
	if (num == null) {
		obj.checked = val;
	}
	else {
		for (var i = 0;  i < num; i++) { obj[i].checked = val;  }
	}
}
function CB_secciones(thisobj, obj ) {
	valor = thisobj.value;
	switch (valor) {
		case "T" :
			CB_selectAll(obj, true);
			thisobj.value = "N";
		break;
		case "N" :
			CB_selectAll(obj, false);
			thisobj.value = "T";
		break;
	}
}
//----------------------------------------------------------------
// Funciones de PAGINAS
//----------------------------------------------------------------
// VARIABLES GLOBALES
var VentanaPaginas;
VentanaPaginas = "control=0,directories=no,resizable=no,status=0,toolbar=0,scrollbars=0,width=550,height=500";
function InsertarPagina(frm) {
var StrAccion;
	StrAccion = "_vacio.html";
	// Datos iniciales
	frm_action = frm.action;
	// Ventana destino
	editpag = window.open(StrAccion,"editpag",VentanaPaginas);
	editpag.window.focus();
	// Destino del formulario
	frm.target = "editpag";
	frm.action = "paginas.php";
	frm.ACCION.value = "INSERTAR";
	frm.submit();
	// Valores Iniciales
	frm.target = "_self";
	frm.action = frm_action;
}
function ModificarPagina(frm,pag) {
var StrAccion;
	StrAccion = "_vacio.html";
	//alert(pag.value);
	if (pag.selectedIndex >= 0) {
		// Datos iniciales
		frm_action = frm.action;
		// Ventana destino
		editpag = window.open(StrAccion,"editpag",VentanaPaginas);
		editpag.window.focus();
		// Destino del formulario
		frm.target = "editpag";
		frm.action = "paginas.php";
		frm.ACCION.value = "MODIFICAR";
		frm.submit();
		// Valores Iniciales
		frm.target = "_self";
		frm.action = frm_action;
	}
	else  {
		alert('Selecciona una pagina');
	}
}
function EliminarPagina(frm,pag) {
var StrAccion;
	StrAccion="_vacio.html";
	if (pag.selectedIndex >= 0) {
		// Datos iniciales
		frm_action = frm.action;
		// Ventana destino
		editpag = window.open(StrAccion,"editpag",VentanaPaginas);
		editpag.window.focus();
		// Destino del formulario
		frm.target = "editpag";
		frm.action = "paginas.php";
		frm.ACCION.value = "ELIMINAR";
		frm.submit();
		// Valores Iniciales
		frm.target = "_self";
		frm.action = frm_action;
	}
	else  {
		alert('Selecciona una pagina');
	}
}
function VerZonas(datos,lista) {
	if (lista.selectedIndex > -1) {
		datos.submit();
	}
	else   {
		alert("Selecciona una pagina");
	}
}
//----------------------------------------------------------------
// Funciones de ZONAS
//----------------------------------------------------------------
var VentanaZonas0,VZonas0_W,VZonas0_H,VentanaZonas1,VZonas1_W,VZonas1_H;
VentanaZonas0="control=0,directories=no,resizable=no,status=0,toolbar=0,scrollbars=0,width=550,height=200";
VZonas0_W = 550;
VZonas0_H = 200+30;
VentanaZonas1="control=0,directories=no,resizable=no,status=0,toolbar=0,scrollbars=0,width=550,height=275";
VZonas1_W = 550;
VZonas1_H = 275+30;
function InsertarZona(pag) {
	var StrAccion;
	if (pag.selectedIndex > -1) {
		document.DATOS.ACCION.value = "ZONA_INSERTAR";
		document.DATOS.submit();
	}
	else {
		alert('Selecciona una pagina');
	}
}

function EliminarZona(pag,zon) {
	var StrAccion;
	if (pag.selectedIndex > -1 && zon.selectedIndex > -1) {
		msg = " Esta acción eliminará la ZONA todas sus SECCIONES. " + "\n"
		    + "                                                    " + "\n"
		    + " ¿ Quieres eliminar la ZONA SELECCIONADA ?          ";
		res = confirm(msg);
		if (res == true) {
			document.DATOS.ACCION.value = "ZONA_ELIMINAR";
			document.DATOS.submit();
		}
	}
	else {
		alert('Selecciona una pagina y una zona');
	}
}
function CopiarDe(pag) {
var StrAccion;
	if (pag.selectedIndex > -1 ) {
		StrAccion	= "zonas.php?ACCION=COPIARDE&ID_PAGINA=" + pag.value;
		editpag	= window.open(StrAccion,"editpag",VentanaZonas1);
		editpag.window.resizeTo(VZonas1_W,VZonas1_H);
		editpag.window.focus();
	}
	else {
		alert('Selecciona una pagina');
	}
}
function MoverZona(accion) {
	document.DATOS.ACCION.value = accion;
	document.DATOS.submit();
}
//----------------------------------------------------------------
// Funciones de SECCIONES
//----------------------------------------------------------------
function VerSecciones(pag,zon) {
	if ( zon.value != 0 ) {
		locationStr = "secciones.php?ID_PAGINA="+ pag.value + "&ID_ZONA=" + zon.value;
		parent.derecha.location	= locationStr;
	}
}
function AccionSeccion(accion) {
	switch (accion) {
		case "ELIMINAR":
			res = confirm(" ¿Quieres eliminar la seccion SELECCIONADA? ");
			if (res == true) {
				document.DATOS.ACCIONSECCION.value = accion;
				document.DATOS.submit();
			}
		break;
		case "ELIMINAR_SELECCIONADOS":
			res = confirm(" ¿Quieres eliminar las secciones SELECCIONADAS? ");
			if (res == true) {
				document.DATOS.ACCIONSECCION.value = accion;
				document.DATOS.submit();
			}
		break;
		case "ELIMINAR_TODOS":
			res = confirm(" ¿Quieres eliminar todas las secciones? ");
			if (res == true) {
				document.DATOS.ACCIONSECCION.value = accion;
				document.DATOS.submit();
			}
		break;
		case "RESET" :
			document.DATOS.ID_SECCION.value	= "";
			document.DATOS.ACCIONSECCION.value	= accion;
			document.DATOS.submit();
		break;
		default :
			document.DATOS.ACCIONSECCION.value	= accion;
			document.DATOS.submit();
		break;
	}
}
//----------------------------------------------------------------
// Funciones de VENTANAS
//----------------------------------------------------------------
function popupwin(href,prop) {
	popup = window.open(href,"popup",prop);
	popup.focus();
}
function popupwin2(href, prop) {
	popup2 = window.open(href,"popup2",prop);
	popup2.focus();
}
//----------------------------------------------------------------
// Funciones de OBJETOS
//----------------------------------------------------------------
function showCalendario(obj, formato) {
	target 	= "OBJ_calendario.php?_APP_CALENDARIO_OBJ="+ obj + "&_APP_CALENDARIO_FORMATO=" + formato;
	param = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=280,height=250";
	popupwin(target,param);
}
function showFicheros(obj, path_web, path_file) {
	target = "OBJ_ficheros.php?OBJ="+ obj + "&WEB="+path_web + "&FILE="+path_file ;
	param = "toolbar=no,location=no,directories=no,status=no,menubar=no,width=650,height=450,scrollbars=no,resizable=yes";
	popupwin(target,param);
}
function showColorPicker(obj) {
	target = "OBJ_colorpicker.php?OBJ="+ obj;
	param = "toolbar=no,location=no,directories=no,status=no,menubar=no,width=350,height=350,scrollbars=no,resizable=yes";
	popupwin2(target,param);
}
//----------------------------------------------------------------
// Funcion de ENVIO DE FORMULARIOS
//----------------------------------------------------------------
function submitForm(){
	// Funcion de actualizacion de RTE's
	updateRTEs();
	// Para enviar el formulario
	// Cambiar a 'false' para no enviarlo
	return true;
}
/* Limitar numero de caracteres */
function checkInputSize(which, maxsize) {
	which.value = which.value.substring(0, maxsize);
}
// OBJETOS
/* Recoger una unstacia de un OBJ DHTML con compatibilidad de navegadores */
function getObj(name) {
	obj = new Object();
    obj.obj = new Object();
    obj.style = new Object();
    obj.style.visibility = "";
    if (name != "") {
		if (document.all)  {
            obj.obj = document.all[name];
			if (obj.obj != "undefined" && obj.obj != null ) {
				obj.style = document.all[name].style;
			}
        }
        else if (document.getElementById) {
			obj.obj = document.getElementById(name);

			if (obj.obj != "undefined" && obj.obj != null ) {
				obj.style = document.getElementById(name).style;
			}
        }
        else if (document.layers) {
            obj.obj = document.layers[name];
			if (obj.obj != "undefined" && obj.obj != null ) {
				obj.style = document.layers[name];
			}
        }
    }
  return obj;
}

function ExpanderContraerObj(obj){
	elemento = getObj(obj);
	estilo = elemento.style.display;
	if ( estilo == '' ) {
		elemento.style.display = 'none';
	}
	else {
		elemento.style.display = '';
	}
}

// Cambiar CONTENIDO
function alterContent(objeto, contenido){
	if (document.all)
		document.all[objeto].innerHTML = contenido;
	else if (document.getElementById){
		rng = document.createRange();
		el = document.getElementById(objeto);
		rng.setStartBefore(el);
		htmlFrag = rng.createContextualFragment(contenido);
		while (el.hasChildNodes()) el.removeChild(el.lastChild);
		el.appendChild(htmlFrag);
	}
}

function alterContentMainFrame(objeto, contenido){
	if (window.parent.document.all)
		window.parent.document.all[objeto].innerHTML = contenido;
	else if (window.parent.document.getElementById){
		rng = window.parent.document.createRange();
		el = window.parent.document.getElementById(objeto);
		rng.setStartBefore(el);
		htmlFrag = rng.createContextualFragment(contenido);
		while (el.hasChildNodes()) el.removeChild(el.lastChild);
		el.appendChild(htmlFrag);
	}
}

//Prototipos
String.prototype.trim = function() {
    a = this.replace(/^\s+/, '');
    return a.replace(/\s+$/, '');
}

//Funciones from VB
function IsNumeric(sText){
    var ValidChars = "0123456789.";
    var IsNumber=true;
    var Char;
    for (i = 0; i < sText.length && IsNumber == true; i++){
        Char = sText.charAt(i);
        if (ValidChars.indexOf(Char) == -1){
            IsNumber = false;
        }
    }
    return IsNumber;
}
//-------------------------------------------
// MENUS - LISTA DE CAPAS -
//-------------------------------------------
var MenusJS = new Object();
var MenusTimerID = 0;
var MenusHideTime = 2; // en segundos
function addMenu(nombre) {
	MenusJS[nombre] = new Object();
	MenusJS[nombre]['timer'] = MenusHideTime;
}
function setMenuNumItems(nombre, num) {
	MenusJS[nombre]['num'] = num;
}
function getMenuNumItems(nombre) {
	return MenusJS[nombre]['num'];
}
function showMenuItem(nombre, item) {
	var objeto = new Object();
	MenusJS[nombre]['activo'] = true;
	MenusJS[nombre]['timer'] = MenusHideTime;
    objeto = getObj(item);
    objeto.style.visibility = 'visible';
}
function hideMenuItem(nombre, item){
	var objeto = new Object();
	//MenusJS[nombre]['activo'] = false;
    objeto = getObj(item);
    objeto.style.visibility = 'hidden';
}
function hideAllMenu(nombre, item) {
	MenusJS[nombre]['activo'] = false;
	num = MenusJS[nombre]['num'];
	for (i=0; i < num; i++) {
		item_tmp = nombre + "_" + i;
		if (item == item_tmp ) {
        }
		else {
			hideMenuItem(nombre, item_tmp);
		}
	}
}
function activarMenu(nombre){
	MenusJS[nombre]['activo'] = true;
}
function desactivarMenu(nombre){
	MenusJS[nombre]['activo'] = false;
}
function compruebaMenus(){
	for (menu in MenusJS) {
		time	= MenusJS[menu]['timer'];
		activo	= MenusJS[menu]['activo'];
		if (activo == false) {
			time -= 1;
			MenusJS[menu]['timer'] = time;
			if ( time <= 0 ) {
				hideAllMenu(menu, "");
				MenusJS[menu]['timer'] = MenusHideTime;
				MenusJS[menu]['activo'] = true;
			}
		}
	}
	MenusTimerID = setTimeout("compruebaMenus()", 1000);
}

//tinyMCE FileBorwser
var mcWindow;
var mcFileManager = new Object();
mcFileManager.filebrowserCallBack = function (field_name, url, type, win) {
    // This is where you insert your custom filebrowser logic
    //alert("Example of filebrowser callback: field_name: " + field_name + ", url: " + url + ", type: " + type);
    mcWindow = win;
    this.ventanaPrincipal = mcWindow;

    path_web = "DATOS";
    path_file = "DATOS_FILE";

    //obj = win.document.forms[0].elements[field_name].value;
    //obj = "mcWindow.document.forms[0].elements." + field_name;

    obj = win.document.forms[0].elements[field_name];
    this.openerObj = obj;

    path = new String();
    pathname = new String();
    pathnameArr = new Array();
    pathname = win.opener.location.pathname;
    pathnameArr = pathname.split("/");
    pathnameArr_n = pathnameArr.length;
    for (i=0; i < pathnameArr_n -1; i++){
        path = path + (pathnameArr[i] + "/");
    }

    target = path + "OBJ_ficheros.php?OBJ="+ obj + "&WEB="+path_web + "&FILE="+path_file+"&FUNCTION_SCRIPT=opener.mcFileManager.SeleccionarFichero(nombre);";
	param = "toolbar=no,location=no,directories=no,status=no,menubar=no,width=650,height=450,scrollbars=no,resizable=yes";
	this.filesWin = popupwin(target,param);

    // Insert new URL, this would normaly be done in a popup
    //win.document.forms[0].elements[field_name].value = ficheroSelected;
    //alert( obj.value );
}
mcFileManager.SeleccionarFichero = function(nombre){
    //
    pathnombre = popup.document.DATOS.PATH_WEB_RELATIVO.value + "/" + nombre;
    this.openerObj.value = pathnombre;
    this.ventanaPrincipal.showPreviewImage(this.openerObj.value);
    popup.close();
}