﻿function cambioCSS(id, clase) {

    $(id).className = clase
}

window.onload = function()
{
	objIconos = document.getElementById("iconos");
	if (objIconos != null) { objIconos.style.display = "block";}
	
	objPrint = document.getElementById("print");
	if (objPrint != null)
	{
		objPrint.onclick = function() { window.print(); return false;}
		objPrint.onkeypress = objPrint.onclick;
	}
}

function validarEntero(valor){ 
      //intento convertir a entero. 
     //si era un entero no le afecta, si no lo era lo intenta convertir 
     valor = parseInt(valor) 

      //Compruebo si es un valor numérico 
      if (isNaN(valor)) { 
            //entonces (no es numero) devuelvo el valor cadena vacia 
            return "" 
      }else{ 
            //En caso contrario (Si era un número) devuelvo el valor 
            return valor 
      } 
} 

function formatoFecha(fech) 
{ 
    var fecha = document.getElementById(fech).value.length; 
    var key = window.event.keyCode; 
    
    if(fecha < 2 || (fecha > 2 && fecha < 5) || fecha > 5) 
        { 
        if(key >= 48 && key <=57) return true; 
        else return false; 
        } 
    if(fecha == 2 || fecha == 5) 
        {   
        if(key == 47) return true; 
        else return false 
        } 
} 

function ConfirmacionDoble()
{
    
    if(confirm('El elemento se borrará totalmente de la base de datos')==true) {
        
        return confirm('¿Está seguro de que desea continuar con la operación?');
    }
    return false;
}

function ConfirmacionPersonal(valor)
{
    var aux=false;
    var x=confirm('El elemento se borrará totalmente de la base de datos');
    if(x) {
        aux=true;
        Listado_Equipo.borrado(aux);
    }
    else return false;
}

function ConfirmacionEncuesta(valor)
{
    var aux=false;
    var x=confirm('El elemento se borrará totalmente de la base de datos');
    if(x) {
        var doc= Listado_EGOPA.comprobarDoc(valor);
        //alert(doc.value);
        if(doc.value > 0){
            aux=confirm('La encuesta tiene archivos asociados, se borrará todo ¿Está seguro de que desea continuar con la operación?');
            //alert('entra');
        }else aux=true;
        //alert(aux);
        Listado_EGOPA.borrado(aux);
    }
    else return false;
}

function ConfirmacionEncuesta2(valor)
{
    var aux=false;
    var x=confirm('El elemento se borrará totalmente de la base de datos');
    if(x) {
        var doc= Listado_OPA.comprobarDoc(valor);
        //alert(doc.value);
        if(doc.value > 0){
            aux=confirm('La encuesta tiene archivos asociados, se borrará todo ¿Está seguro de que desea continuar con la operación?');
            //alert('entra');
        }else aux=true;
        //alert(aux);
        Listado_OPA.borrado(aux);
    }
    else return false;
}

function cargar_datos(str,lista){
    var id = lista.value;
    
    if (lista.selectedIndex != 0) {
        //toggleFCKeditor(FCKeditorAPI.GetInstance(str));
        document.getElementById('editor').style.display="inline";
        if(habilitar( FCKeditorAPI.GetInstance(str)))
        {
            var contenido = ContenidoEstDin.mostrar_contenido(id); 
            if (contenido.value.substring(0,5) == "Error") {
                FCKeditorAPI.GetInstance(str).SetHTML("");
                alert (contenido.value);
            }
            else {
                FCKeditorAPI.GetInstance(str).SetHTML(contenido.value);
                if(contenido.value == "") alert ('No existen datos en esta zona.');
            }
        }    
    }else{
        //toggleFCKeditor(FCKeditorAPI.GetInstance(str));
        document.getElementById('editor').style.display="none";
        deshabilitar( FCKeditorAPI.GetInstance(str));
    }

}

function enviar_datos(str,lista){

    var id = document.getElementById(lista).value;
    //alert(id);
    var contenido = FCKeditorAPI.GetInstance(str).GetXHTML();
    var correcto = ContenidoEstDin.modificarContenido(id,contenido);
    
    //alert(correcto.value);
    if(correcto.value)alert('Los datos se almacenaron correctamente');
    else alert('Error al modificar los datos');
}


function comprobar_usuario(nombre, pass,etiq){

    var n = document.getElementById(nombre).value;
    var c = document.getElementById(pass).value;

    var correcto = Opciones_AccesoRestringido.Enviar(n,c);

    if (correcto.value) {
        
        document.getElementById("ctl00_ucMenu_divAdmin").className = "";
        document.getElementById('ctl00_ContentPlaceHolder1_btnSinSesion').style.display="none";
        document.getElementById('ctl00_ContentPlaceHolder1_btnConSesion').style.display="inline";
        document.getElementById('ctl00_ContentPlaceHolder1_btnConRecordar').style.display="none";
        document.getElementById(etiq).innerHTML = document.getElementById('ctl00_ContentPlaceHolder1_txtNombre').value ;
        }
    else alert('Usuario incorrecto');
    
}

function cerrar_Sesion(){

    Opciones_AccesoRestringido.CerrarSesion();
    document.getElementById("ctl00_ucMenu_divAdmin").className = "oculto";
     
    document.getElementById('ctl00_ContentPlaceHolder1_btnSinSesion').style.display="inline";
    document.getElementById('ctl00_ContentPlaceHolder1_btnConSesion').style.display="none";
    document.getElementById('ctl00_ContentPlaceHolder1_btnConRecordar').style.display="none";
    
    document.getElementById('ctl00_ContentPlaceHolder1_txtNombre').value="";
    document.getElementById('ctl00_ContentPlaceHolder1_txtPassword').value="";
}

function activar_recordar(){
    document.getElementById('ctl00_ContentPlaceHolder1_btnSinSesion').style.display="none";
    document.getElementById('ctl00_ContentPlaceHolder1_btnConSesion').style.display="none";
    document.getElementById('ctl00_ContentPlaceHolder1_btnConRecordar').style.display="inline";
}

function recordar_password(txt){
        var correo=document.getElementById(txt).value; 
        var correcto = Opciones_AccesoRestringido.Recordar(correo);

        if(correcto.value==null) {alert('Error al enviar el correo');}
        else if (correcto.value) {alert('Se le ha enviado un correo con su nombre y contraseña');}
        else {alert('No existe ningun usuario con ese correo electronico');}
        document.getElementById('ctl00_ContentPlaceHolder1_btnSinSesion').style.display="inline";
        document.getElementById('ctl00_ContentPlaceHolder1_btnConSesion').style.display="none";
        document.getElementById('ctl00_ContentPlaceHolder1_btnConRecordar').style.display="none";
        document.getElementById(txt).value="";
}

function cancelar_correo(){
        document.getElementById('ctl00_ContentPlaceHolder1_btnSinSesion').style.display="inline";
        document.getElementById('ctl00_ContentPlaceHolder1_btnConSesion').style.display="none";
        document.getElementById('ctl00_ContentPlaceHolder1_btnConRecordar').style.display="none";
        document.getElementById('ctl00_ContentPlaceHolder1_txtMail').value="";
}

function comprobar_validador(validate){

    if (document.getElementById(validate).style.display=="none"){
        recordar_password('ctl00_ContentPlaceHolder1_txtMail');}
}

function noticia_enlace(enlace){
    
    var en= document.getElementById(enlace);
    
    if(en.innerHTML=="Abrir Noticia")en.innerHTML="Cerrar Noticia";
    else en.innerHTML="Abrir Noticia";
}


function muestraNoticia(elemento, outer, menu) {
    
    if ($(outer).getStyle('height') == $(menu).getStyle('height')) {
        elemento.start({'height':44});
    }
    else {
        elemento.start({'height':$(menu).getStyle('height')});
    }
}

function mas_categorias(txt,lista){

    if( document.getElementById(lista).value=="Otra Categoría"){
        document.getElementById(txt).style.display = "inline";
        document.getElementById(lista).style.width = "194px";}
    else{
        document.getElementById(txt).style.display = "none";
        document.getElementById(lista).style.width = "350px";}
}


function RellenaDDL (res, elemento, conBlanco, colTexto, colValor) {   
	var dt = res.value; 
	var html = new Array(); 
	var oSelect = document.getElementById(elemento);
	
	oSelect.options.length = 0;
						
	if(dt!= null && typeof(dt) == "object")
	{
	    if (conBlanco) {
	        agregaBlanco(oSelect);
	    }
		for(var i = 0; i < dt.Rows.length; i++)
		{
			var oOption = document.createElement("OPTION");
			oOption.value = dt.Rows[i][colValor];
			oOption.text = dt.Rows[i][colTexto];
			
			try {
				oSelect.add(oOption, null); // Para cumplir con el estándar
			}
			catch(ex) {
				oSelect.add(oOption); // Para IE
			}
        }
    }
}
function agregaBlanco(oSelect) {
    var oOption = document.createElement("OPTION");
    oOption.value = "";
    oOption.text = "";

    try {
        oSelect.add(oOption, oSelect.options[0]); // Para cumplir con el estándar
    }
    catch(ex) {
        oSelect.add(oOption, 0); // Para IE
    }
}
function agregaOtra(oSelect) {
    var oOption = document.createElement("OPTION");
    oOption.value = 99;
    oOption.text = "Otra";

    try {
        oSelect.add(oOption, null); // Para cumplir con el estándar
    }
    catch(ex) {
        oSelect.add(oOption); // Para IE
    }
}

function muestraImagen(txt){

    var texto = document.getElementById(txt).innerHTML;

    //var enlace = '· <a href="'+ link +'" rel="boxed" title="cadpea.org">'+ aux +'</a>'; 
    texto = texto.replace('· [image [enlace]','· <a href="');
    texto = texto.replace('[/enlace]]','" rel="boxed" title="cadpea.org">');
    texto = texto.replace('[/image]','</a>'); 
    document.getElementById(txt).innerHTML = texto;
}

function muestraVideo(txt){

    var texto = document.getElementById(txt).innerHTML;

    //var enlace = '· <a href="http://www.youtube.com/watch?v='+ link +'" class="boxed" rel="{url:\'http://www.youtube.com/v/'+ link + '\',handler:\'swf\',size:{x:425,y:350}}" title="cadpea.org">'+ aux +'</a>'; 
    texto = texto.replace('· [video [enlace]','· <a href="http://www.youtube.com/watch?v=');
    texto = texto.replace('[/enlace] [rel]','" class="boxed" rel="{url:\'http://www.youtube.com/v/');
    texto = texto.replace('[/rel]]','\',handler:\'swf\',size:{x:425,y:350}}" title="cadpea.org">');
    texto = texto.replace('[/video]','</a>'); 
    document.getElementById(txt).innerHTML = texto;
}

function insertaImagen()
{
        document.getElementById('divIframe').style.display = 'inline';
}

function insertaVideo(){

    var link = prompt("Inserta la direccion del enlace:", "http://");
    var aux = prompt("Inserta el texto del enlace:", "Abrir Enlace");
    if( link != null && aux != null ){

        //link = link.substring(link.lastIndexOf('v=',link.length)+2,link.length);
        Inserta_noticia.insertaEnlace(aux,link,1);
        
        var oOption = document.createElement("OPTION"); 
        oOption.value = aux;
        oOption.text = aux;
        var lista = document.getElementById('ctl00_ContentPlaceHolder1_lbEnlaces');
        
        try {
            lista.add(oOption, null); // Para cumplir con el estándar
        }
        catch(ex) {
            lista.add(oOption); // Para IE
        }
    }
}

function quitarEnlace(lista){

    var list = document.getElementById(lista);
    
    if(list.selectedIndex != -1){
    
        Inserta_noticia.borrarEnlace(list.selectedIndex);
        try {
            var hijo = list.options[list.selectedIndex];
			list.removeChild(hijo); // Para cumplir con el estándar  
		}
		catch(ex) {
		    list.options.remove(i); // Para IE
        }
    }
    else{
        alert("Seleccione el enlace a borrar");
    }
}

function esInteger(evt)
{
    evt = (evt) ? evt : window.event
    var charCode = (evt.which) ? evt.which : evt.keyCode

         if (charCode > 31 && (charCode < 48 || charCode > 57)) {  
            return false;
         }
         else{      
            return true;
         }
}


function actualiza(tipo)
{
    var res = Inserta_DOC.RellenaDDL(tipo);

    if(res.value != null)
        document.getElementById('encuestas').innerHTML = res.value;
    else 
        alert('Error al rellenar la lista.');    
}


function marcarEncuesta() {

/*	var lon=document.getElementById('ddlEncuesta').length;

	for(var i=0;i<lon;i++)
		if(document.getElementById('ddlEncuesta').options[i].selected){
			var selec=document.getElementById('ddlEncuesta').options[i].value;
			break;
	}
*/

    var selec = document.getElementById('ctl00_ContentPlaceHolder1_ddlEncuesta').value;

	if(selec != '') Inserta_DOC.EncuestaMarcada(selec);
}


function compruebaAnio(){

    var elem = document.getElementById('ctl00_ContentPlaceHolder1_listaAnios');
    var txt = document.getElementById('ctl00_ContentPlaceHolder1_txtNombre');
    
    if(txt.value == ''){
        alert('Debe de indicar un nombre de encuesta.');
        return false;
    }
    
    if(elem.selectedIndex != 0) return true;
    else {
        alert('Debe de seleccionar un año.');
        return false;
    }
}

//--------------------

// Color final que se quiere mostrar
var Rfinal = 255;
var Gfinal = 0;
var Bfinal = 0;
var concurrencia = "";
var unicidad = "";
var elementoSeleccionado="";

function marcarFila(id) {

    var obj = document.getElementById(id);
    var estilo = obj.tagName + (obj.className == ""? "":"."+obj.className);

    if (obj.style.backgroundColor == "") {
        if (unicidad != "") {
            document.getElementById(elementoSeleccionado).style.backgroundColor="";;
        }
        elementoSeleccionado = id;
        obj.style.backgroundColor="#EAC27F";
        unicidad = "0";
    }
    else {
        obj.style.backgroundColor="";
        unicidad = "";
    }
}


function ListaContiene(elem,lista){

    var lon=document.getElementById(lista).length;
    
	for(var i=0;i<lon;i++)
	    if(document.getElementById(lista).options[i].value == elem){ 
	        alert('El elemento ya esta en la lista');
	        return true;
	}

    return false;	
}

// txt
function ponerEnLista(enlace, lista) {

    if(document.getElementById(enlace).value != '' && !ListaContiene(document.getElementById(enlace).value,lista)) {
    
	    var elem= document.getElementById(enlace).value; 

	    document.getElementById(enlace).value='';
	    var oOption = document.createElement("OPTION");
			    oOption.value = elem;
			    oOption.text = elem;
    			
		    try {
			    document.getElementById(lista).add(oOption, null); // Para cumplir con el estándar
		    }
		    catch(ex) {
			    document.getElementById(lista).add(oOption); // Para IE
		    }
	}
}

// ddl

function incluirEnLista(ddl, lista) {

    if(document.getElementById(ddl).value != '' && !ListaContiene(document.getElementById(ddl).value,lista)) {

	    var selection=document.getElementById(ddl)
		var v = selection.options[selection.selectedIndex].value;
		var t = selection.options[selection.selectedIndex].text;

	    document.getElementById(ddl).selectedIndex=-1;
	    var oOption = document.createElement("OPTION");
		oOption.value = v;
		oOption.text = t;
	    
	    try             {document.getElementById(lista).add(oOption, null);  }// Para cumplir con el estándar
		catch(ex) 	    {document.getElementById(lista).add(oOption);        }// Para IE
	}
}


function incluirEnLista2(valor, lista) {

    if(valor != '') 
    {
	    var oOption = document.createElement("OPTION");
		oOption.value = valor;
		oOption.text = valor;
	    
	    try             {document.getElementById(lista).add(oOption, null);  }// Para cumplir con el estándar
		catch(ex) 	    {document.getElementById(lista).add(oOption);        }// Para IE
	}
}


function quitarDeLista(lista) {

	var lon=document.getElementById(lista).length;
	for(i=0;i<lon;i++)
		if(document.getElementById(lista).options[i].selected){
			try {
			    var hijo = document.getElementById(lista).options[i];
			    document.getElementById(lista).removeChild(hijo); // Para cumplir con el estándar  
		    }
		    catch(ex) {
			    document.getElementById(lista).options.remove(i); // Para IE
		    }
			break;
		}	
}



