/* 
 * Funciones para crear entradas
 * se establece editor como variable global. e instancia de ckeditor
 */
var editor;

function guardarEntrada(sig){
    validacion = true;
    validacion = textfieldValidate("titulo", "errTitulo", "", true, validacion) && validacion;
    //validacion = textfieldValidate("entrada", "errEntrada", "", true, validacion) && validacion;
	
    if(editor!=null)
        var htmleditor = editor.getData()
	
    if(validacion){
        xajax_guardarEntrada(xajax.getFormValues('entradaFrm'),htmleditor)
        validacion =true;
    }
	
	
    if(validacion && editor!=null){
        if(sig==1)
            xajax_pintardocumentos();
			
        if(sig==2)
            xajax_pintarVinculos();
    }
		
	
}

function editarnombreentrada(idobjeto){
    document.getElementById('nombre'+idobjeto).removeAttribute('disabled');
    xajax_pintarguardarnombreentrada(idobjeto);
	
}

//cambiar
function guardareditarentrada(identrada){
    //alert("cambiar tetete mini");
	
    var validacion = true;
    validacion = textfieldValidate("nombre"+identrada, "errTitulo"+identrada, "", true, validacion) && validacion;
	
    if(validacion){
        var nombre;
        nombre=document.getElementById("nombre"+identrada).value
        xajax_guardarNombreEntrada(identrada,nombre);
        xajax_pintarEdiNEntrada(identrada);
        document.getElementById("nombre"+identrada).disabled = "disabled"
    }
}


function cambiarCateEntrada(identrada){
    //alert("cambiar categoria mini");
    document.getElementById('select'+identrada).removeAttribute('disabled');
    xajax_pintarGuardarCateEntrada(identrada);
}
	
	
function parametrosentrada(identrada,nombrec){
    //alert(identrada+"op"+nombrec);
    document.getElementById(""+identrada+"op"+nombrec+"").selected = "selected"
    document.getElementById("select"+identrada).disabled = "disabled"
}
	
function guardarCateEntrada(identrada){
    var nombre;
    idcategoria=document.getElementById("select"+identrada).value
    xajax_guardarCateEntrada(identrada,idcategoria);
    xajax_pintarEdiCateEntrada(identrada);
    document.getElementById("select"+identrada).disabled = "disabled"
    
}
	
function guardarTablaEditar(){
    var validacion = true;
    //validacion = textfieldValidate(idobjeto, "err"+idobjeto, "", true, validacion) && validacion;
    if(validacion){
        xajax_guardarTablaEditarEntradas(xajax.getFormValues('editarentradaFrm'));
    }
}

//PINTA LA VISTA DE CREAR EDITAR ENTRADA
function editarCrearEntradaVis(identrada){
    xajax_ponerSessionEntrada(identrada);
    xajax_pintarCrearEntradas();
}

function pintarEditarEntradas(){
    xajax_pintarEditarEntradas('');
		
}
	
	
function nuevaEntrada(){
    //alert('nueva entrada');
    //xajax_liberarSessionEntrada();
    xajax_pintarCrearEntradas();
}
	
function crearEntradaNueva() {
    xajax_liberarSessionEntrada();
    xajax_pintarEntradaNueva();
}


function createEditor()
{
	
	
    if ( editor )
        return;
	
    document.getElementById( 'contents' ).style.display = 'none';
    var html = document.getElementById( 'editorcontents' ).innerHTML;

    // Create a new editor inside the <div id="editor">, setting its value to html
    var config = {};
    editor = CKEDITOR.appendTo( 'editor', config, html );
}

function removeEditor()
{
    if ( !editor )
        return;

    // Retrieve the editor contents. In an Ajax application, this data would be
    // sent to the server or used in any other way.
    //document.getElementById( 'editorcontents' ).innerHTML = editor.getData();
    //document.getElementById( 'contents' ).style.display = 'block';

    // Destroy the editor.
    editor.destroy();
    editor = null;
}


