﻿// JScript File
/*
Este Archivo contendra funciones javascript de uso general 
*/



//funciones que piden la confirmación de un borrado de registro 
//=============================================================
function Confirma()
{
    var message = "¿Esta seguro que desea borrar este registro?";
    var return_value = confirm(message);
 return return_value;
}

function Confirma1(mensaje)
{  
  var return_value = confirm(mensaje);
 return return_value;
}


function sacaNodo(valor)
{ 
  document.getElementById("ctl00_HiSelected").value=valor;
}  

   
function SacaImagen(tiempo, img_anterior)
{ 
       
        // Generamos un nº aleatorio para sacar la imagen del array
        var matrand=Math.floor(Math.random()*randimages.length);           
           
        // Control del tiempo
        if (tiempo<1000) tiempo=tiempo*2000;

        //ponemos una imagen aleatoria de las incluidas en el array de parametro
        if(NombreControl.indexOf('_ImageBanner')==-1)   
           NombreControl=NombreControl+"_ImageBanner";
           
           
         // Sacamos la imagen del array
         document.getElementById(NombreControl).src=randimages[matrand];
         
         if(matrand != img_anterior)
         {              
               // Efecto fundido
               document.images[NombreControl].style.filter= "blendTrans(duration=2);"	   
               document.images[NombreControl].filters.blendTrans.Apply(); 	   
               document.images[NombreControl].filters.blendTrans.Play()  
               
               document.images[NombreControl].style.visibility="visible";   
         }	   
                 	               

        //ejecutamos la funcion con la cadencia dada por el parametro tiempo
        setTimeout( "SacaImagen("+tiempo+","+matrand+")",tiempo);   
    
  }
  
function cambia(cual,clase){
identidad=document.getElementById(cual);
identidad.className=clase;
}
//Esta function nos dirigira a la página seleccionada en el combo
function PaginaCombo()
{
// debugger;
//Recogemos el objeto imagen en una variable
 var oImagen= event.srcElement; 
 var NombreCombo=oImagen.id;
 NombreCombo=NombreCombo.replace("img","");
//Recogemos el objeto select en una variable
 var oCombo=document.getElementById( NombreCombo);
// Recogemos el indice del elemento activo en una variable
 var oIndice=oCombo.selectedIndex;
// por ultimo mostramos el valor del indice seleccionado 
 window.location.href=oCombo.options[oIndice].value+"?IND="+oIndice;

}


function GetPageByPeriod()
{
   
//Recogemos el objeto select en una variable
 var oComboYear=document.getElementById('cmbList');
 var oComboMonth=document.getElementById('cmbMonth');
 
// Recogemos el indice del elemento activo en una variable
 var oIndiceYear=oComboYear.selectedIndex;
 var oIndiceMonth=oComboMonth.selectedIndex;
// por ultimo mostramos el valor del indice seleccionado 

 window.location.href= oComboYear.options[oIndiceYear].value + oComboMonth.options[oIndiceMonth].value + '.aspx' + '?DATE=' + oComboYear.options[oIndiceYear].value + oComboMonth.options[oIndiceMonth].value;

}

function DetectaScroll()
{
    var  btnSubir=document.all("btnSubir");
    if (btnSubir!=null){
        if (document.documentElement.clientHeight < document.documentElement.scrollHeight){
            btnSubir.style.visibility = "visible";
        }
        else{
           btnSubir.style.visibility = "hidden";
        }
    }
}

function ViewDetail()
{
 var  divDetalle=document.getElementById("divDetalle");
    if (divDetalle!=null){
        if ((ExisRichBox==null) || (ExisRichBox==true)) {
        
        divDetalle.style.visibility = "visible";
        }
    }
    

}



 function CreaEditor(NombreControl)
      { 
        var NombreElemento =NombreControl+'_innerText'; 
        var oFCKeditor;
        var oTexto= document.getElementById(NombreElemento).value;
        var altura=((document.getElementById(NombreElemento).value.length)/2)+70;
  

/*
        if (altura<200) 
            altura=200;
        else if (altura>400)*/
            altura=300;
            
       // oFCKeditor = new FCKeditor('FCKeditor1_'+NombreControl,'100%',altura,'Default',oTexto);        
        oFCKeditor = new FCKeditor();        
        oFCKeditor.InstanceName='FCKeditor1_'+NombreControl;
        oFCKeditor.BasePath = 'Fields/RichBox/FCKeditor/';
        oFCKeditor.Width = "100%";
        oFCKeditor.Height  = 300;
        oFCKeditor.Value  = oTexto;
        oFCKeditor.Create();
           
      }

      //funcion que consigue el texto de todos los controles richbox en la pantalla
      //y los escribe a sus correspondientes campos ocultos 
     function GetText()
     {  var hiddenFields = document.getElementsByTagName("input");
        var NombreControl='';     
        var NombreElemento =''; 
        var oEditor  
    
      
        for (var i = 0; i < hiddenFields.length ; i++)
        {
         oEditor  = null; 
        NombreControl1=  hiddenFields[i].id;
         if(NombreControl1.indexOf('_innerText')!=-1)
          {
           NombreElemento= NombreControl1;
           NombreControl=NombreControl1.replace('_innerText','');
          while (oEditor==null)
           {    
            oEditor=FCKeditorAPI.GetInstance('FCKeditor1_'+NombreControl); 
            document.getElementById(NombreElemento).value=oEditor.GetXHTML();        
          
            }        
          
          }
        } 
     
     }



function CreaAll()
      { 
        var hiddenFields = document.getElementsByTagName("input");
        var NombreControl='';     
        var NombreElemento =''; 
        var oEditor  = null   
    
      
        for (var i = 0; i < hiddenFields.length ; i++)
        {
         
        NombreControl1=  hiddenFields[i].id;
         if(NombreControl1.indexOf('_innerText')!=-1)
          {
           NombreElemento= NombreControl1;
           NombreControl=NombreControl1.replace('_innerText','');
           CreaEditor(NombreControl)
                
          }
        } 
           
      }