/**
 * Objeto Matriz de diarios regionales
 * @version 1.00
 * @author shoto
 */

 
function DRMatriz(){
    
}

/**
 * Inicializa funcionalidades de Matriz de diarios regionales
 */
DRMatriz.prototype.init = function(){

    var links = document.getElementsByTagName('a');
    var consola = new Console('console');
    consola.append('Se econtraron N=' + links.length + ' links');
    for (var i = 0; i < links.length; i++) {
        consola.append('Link encontrado: ' + links[i].href);
        if(links[i].href.match(/#\d+$/)){continue;}
        if(links[i].href.match(/javascript\:/)){continue;}
        if(links[i].href.match(/mailto\:/)){continue;}
        if(links[i].href.match(/\/cgi-bin/)){continue;}
        if(links[i].href.match(/prensatocopilla/)){continue;}
        if(links[i].href.match(/estrellaloa/)){continue;}
        links[i].href += '?s=' + window.location.hostname;
    }
    
}

/**
 * Escribe el head en el div especificado
 * @param String contenido html de head
 */
function writeHead(contenido){
    var containerHead = document.getElementById('cabecera');
    if (containerHead) {
       containerHead.innerHTML = contenido;
    }
}

function writeHeadSup(contenido){
    var containerHead = document.getElementById('cabeceraSup');
    if (containerHead) {
       containerHead.innerHTML = contenido;
    }
}

function writeHeadInf(contenido){
    var containerHead = document.getElementById('cabeceraInf');
    if (containerHead) {
       containerHead.innerHTML = contenido;
    }
}

function chargeElement(elemID, urlSrc){
    try{
        var objElem = document.getElementById(elemID);
        if(objElem){
            var scripto   = document.createElement('script');
//         script.id    = ''
             scripto.type = 'text/javascript';
             scripto.src  = urlSrc;
             objElem.appendChild(scripto);
//        alert('Elemento encontrado'+urlSrc+'-->'+elemID);;
        }
    }catch(e){
        alert('chargeElement: '+e)
    }
}

function fillHtmlElement(elemID,contenido){
    try{
        var objElem = document.getElementById(elemID);
        if(objElem){
            objElem.innerHTML = contenido;
        }
    }catch(e){
        alert('chargeElement: '+e)
    }
};


/**
 * @todo inicializar manejos de error
 * @param e evento asociado al error
 */
DRMatriz.prototype.errorHandler = function(elem, from){
  if (from == 'change') {
      if (elem.readyState == 'complete') {
        //  alert("error detectado[" + from + "]\n" + "status:" + elem.readyState + "\nelemento:"+elem.hasChildNodes());
          var elemento = document.getElementById('nombre');
       //   elemento.
      }
  }else{
     // alert("error detectado[" + from + "]\n" + "\nelemento:" + elem.id);
  }
}

/**
 * Escribe el footer en el div especificado
 * @param String contenido html de footer
 */
function writeFooter(contenido){
    var containerFooter = document.getElementById('menu-foot');
    if (containerFooter) {
       containerFooter.innerHTML = contenido;
    }
}