//CSS_ONTHEFLY_BH
var CSS_OTF;
function createCss(){
	try{
		CSS_OTF = document.createStyleSheet();
	}catch(e){
		var css = document.createElement("style");
		document.getElementsByTagName("head")[0].appendChild(css)
		CSS_OTF = document.styleSheets[document.styleSheets.length -1]
	}
}
createCss();


//AP_BH
LOAD_STATUS_TEXT = "<div id=\"cargando\" class=\"preload\"><img src=\"/im/loading.gif\" alt=\"cargando\"><p>Cargando...</p></div>";

function behaviour_apply() {
   Behaviour.apply();
}

function mostrar(modulo,posicionx,posiciony){
    document.getElementById(modulo).style.display='block';
    if (posicionx>0)
        document.getElementById(modulo).style.bottom=posicionx+'px';
    if (posiciony>0)
        document.getElementById(modulo).style.right=posiciony+'px';
}

function ocultar(modulo){
    document.getElementById(modulo).style.display='none';
}


function agregar(){
   if (isExplorer())  window.external.AddFavorite("http://www.elpais.com","EL PAIS");   
   else alert("Presione Ctrl+D para agregar este sitio en sus Favoritos"); 
} 

function isExplorer(){
   if ((navigator.appName=="Microsoft Internet Explorer") && (parseInt(navigator.appVersion)>=4)) return true;
   else if(navigator.appName == "Netscape") return false;   
   else return false;   
}

var rules_paginador= {
	//selector aP: ajaxPetition
	'a.popaudio' : function(el){
		el.onclick = function(){
			//a = new Ajax();
			var url = this.href;
			var argsDec = url.split("?")[1];		
			var aP      = argsDec.split("archi=")[1];
			oiraudiofile(aP);
			return false;
		}
	}

};
Behaviour.register(rules_paginador);


//APS_BH
LOAD_STATUS_TEXT_S = "<div id=\"cargando\" class=\"preload\"><img src=\"/im/loading_mini.gif\" alt=\"cargando\">&nbsp;Cargando ...</div>";

function starsOnClick()
{
	a = new Ajax();
	var url = this.href;
	
	var esDeCod = url.match(/\#/g);
	if (esDeCod!=null){
		url = unescape(url);
	}
	var argsDec = url.split("#")[1];		
	var aP      = argsDec.split("aP=")[1];
	aP          = unescape(aP.split("&")[0]);
	var ctn     = argsDec.split("ctn=")[1];
	ctn         = ctn.split("&")[0];
	function estrellas(){
	   behaviour_apply();
		try {
		  if (ctn == "votosC" && typeof(document.getElementById("votosD")!="undefined"))
				  document.getElementById("votosD").innerHTML = document.getElementById("votosC").innerHTML;
		  else if (ctn == "votosD" && typeof(document.getElementById("votosC")!="undefined"))
					 document.getElementById("votosC").innerHTML = document.getElementById("votosD").innerHTML;
		  
		} catch (e) {
			if (debugging) alert(e);
		}

	}
	a.replace("/modulo/index.html",aP,LOAD_STATUS_TEXT_S,ctn,"POST", estrellas);
	return false;
}



/**
* Recorremos las hojas de estilo importadas para encontr
* laa etiqueta body y asi poder capturar su tamaño y
* poder modificarlo
*/
function changeSize(tipo){
   var increment    = 1;
   var maxSize      = 13;
   var minSize      = 6;
   var rule         = false;
   var currentSize = 10;
   var sh           = false;
   var flag         = false;
   var sheets       = document.styleSheets;

   // # Firefox
   try{
      for (var i = 0; i < sheets.length && i < 3; i++) {
         if(flag) break;

         for (var j = 0; j < sheets[i].cssRules.length && j< 3; j++) {
            if(flag) break;

            if(sheets[i].cssRules[j].styleSheet){
               sh =sheets[i].cssRules[j].styleSheet

               for (var l = 0; l < sh.cssRules.length && l < 3; l++) {
                  if(flag) break;

                  rule =  sh.cssRules[l];
                  if(rule.selectorText == "body"){
                     currentSize = parseInt(rule.style.fontSize);
                     flag=true;
                     break;
                  }
               }
            }
         }
      }
   }catch(e){
     // # IE
      for (var i = 0; i < sheets.length && i < 3; i++) {
         if(flag) break;

         for (var j = 0; j < sheets[i].imports.length && j< 3; j++) {
            if(flag) break;

            if(sheets[i].imports[j].rules){
               sh =sheets[i].imports[j].rules
               for (var l = 0; l < sh.length && l < 3; l++) {
                  if(flag) break;

                  rule =  sh[l];
                  if(rule.selectorText == "body" ||rule.selectorText == "BODY" ){
                     currentSize = parseInt(rule.style.fontSize);
                     flag=true;
                     break;
                  }
               }
            }
         }
      }
   }
   if(!rule) return;

   if(tipo > 0 && currentSize < maxSize)
     rule.style.fontSize = parseInt(currentSize+(tipo*increment))+ "px";
   if(tipo < 0 && currentSize > minSize)
     rule.style.fontSize = parseInt(currentSize+(tipo*increment))+ "px";

} // end function

document.onkeydown = function(e) {
        // Si el foco esta en un elemento de formulario NO ejecutamos las acciones de onkeydown
        var focus = null;
        // IE
        try{
                focus = event.srcElement.type;
        }
        // Mozilla
        catch(err){
                focus = e.target.type;
        }

        var form_elements = new Array("text","password","select-one","textarea","button","submit");
        var activar_keydown = true;
        for(var i in form_elements){
                if(form_elements[i] == focus){
                        activar_keydown = false;
                        break;
                }
        }

        if(activar_keydown){
                e = (typeof e == "undefined") ? event : e;
                keyPressed = (typeof e.which == "number") ? e.which : e.keyCode;
                switch(keyPressed){
                        case 37: // <--
                                if(url_prev != undefined){
                                        document.location.href = url_prev;
                                }
                          break;
                        case 39:  // -->
                                if(url_next != undefined){
                                        document.location.href = url_next;
                                }
                          break;
                        case 107: // +
                        case 109: // -
        			var tipo         = 1;
        			if(keyPressed == 109) tipo = -1;
        			changeSize(tipo);
                          break;
                }
        }
}


var imgsIds = new Array();
var imgsSrc = new Array();

function setDisplay(name,display){
	try{
		CSS_OTF.addRule("#"+name,"display:"+display+";")
	}catch(e){
		CSS_OTF.insertRule("#"+name+" { display: "+display+" }", 0)
	}
}

function setBgImage(name, url) {
        try{
	 	CSS_OTF.addRule("#"+name,"background-image:url('"+url+"');");
	}catch(e){
		CSS_OTF.insertRule("#"+name+" { background-image:url('"+url+"') }", 1);
	}
}

function getImgSrcbyId(id)
{
	for (var i=0; i<imgsSrc.length; i++)
		if (imgsSrc[i][0] == id) return imgsSrc[i][1];
	return null;
}

function ponImagenes() {
	var tam = imgsIds.length
	for(i=0; i<tam; i++) {
		im=document.getElementById(imgsIds[i])
		if (im) {
			im.src = getImgSrcbyId(imgsIds[i]);
			im.style.display="block";
		}
	}
}


function randomDiv(id, tam, orden) {
        var aleatorio = ((orden == 'A') ? Math.floor(Math.random() * tam) : 0)
        for(var i=0; i<tam; i++) {
                var cid = id+"ale_"+i
                var imid = cid+"_img"
                if (aleatorio==i) {
                        if (i!=0)
			{
				imgsIds[imgsIds.length]=imid
				setBgImage(imid, getImgSrcbyId(imid));
			}
                }
                else {
                        setDisplay(cid,"none")
                        setDisplay(imid,"none")
                }
        }
}

function prevModuleOnClick()
{
	var node = this.parentNode
	while(node.id.indexOf("ale_")==-1){
		node = node.parentNode
	}
	node.style.display="none";
	var im = document.getElementById(node.id+"_img");
	if (im) im.style.display="none";

	var sibling=node;
	do {
		sibling = sibling.previousSibling;
		if (!sibling) sibling=node.parentNode.lastChild;
	} while (sibling.nodeType!=1)
	
	sibling.style.display="block";
	var im2 = document.getElementById(sibling.id+"_img")
	if (im2) {
		im2.src = getImgSrcbyId(sibling.id+"_img");
		im2.style.display="block";
	}
	return false;
}



//VENTANA_BH
var modal_class       = "modal"; // nombre de la clase css que lanzara los eventos
var modal_close_class = "modal_close"; // nombre de la clase css que lanzara los eventos
var modal_container   = "ventana"; // nombre de la capa que sera la ventana modal
var modal_imagen_id   = "modal_img"; // id para las ventanas modales que son imagen
//var LOAD_STATUS_TEXT_V  = "<img src=\"/im/loading.gif\" width=\"16\" height=\"16\" alt=\"Cargando...\" title=\"Cargando...\"/> Cargando...";
var LOAD_STATUS_TEXT_V  = "<div id=\"cargando\" class=\"preload preload_2\"><img src=\"/im/loading.gif\" alt=\"cargando\"><p>Cargando ...</p></div>";

var rules_modal_window = {
	"a.modal" : function(el){
		el.onclick = function(){
      var href = this.href;
			if(isImg(href)){
				var imgPreloader = new Image();
				var img_w = 0;
				var img_h = 0;
				imgPreloader.onload = function(){
					img_w = imgPreloader.width;
					img_h = imgPreloader.height;
				}
				imgPreloader.src = href;
				var content = "<img src=\""+href+"\" class=\""+modal_close_class+"\" id=\""+modal_imagen_id+"\" alt=\""+href+"\" title=\"\">";
				Ventana.instance.setStringContent(content);
			}else{
				Ventana.instance.setHttpContent(href, LOAD_STATUS_TEXT_V, "GET");
			}
      
			Ventana.instance.show();
			return false;
		}
	},
	"#modal_img" : function (el){
		el.onload = function () {
			Ventana.instance.center(Ventana.instance.getVentHeight(),Ventana.instance.getVentWidth());
		}
	},
	"img.modal_close" : function(el){
		el.onclick = function(){
			Ventana.instance.hide();
			return false;
		}
	},
	"a.modal_close" : function(el){
		el.onclick = function(){
			Ventana.instance.hide();
			return false;
		}
	}
};
function isImg(url){
	var urlImgs = /\.jpg|\.jpeg|\.png|\.gif|\.bmp/g;
	var urlType = url.match(urlImgs);	
	if(urlType===null)
		return false;
	return true;
}
Behaviour.register(rules_modal_window);


//Para la lista de los vídeos
function createVideoList()
{
	 if(typeof(var_video_list_ids) != 'undefined'){

		for(i=0; i<var_video_list_ids.length; i++){
			var idAux = var_video_list_ids[i];
			var srcAux = var_video_list_src[idAux];
			var FlashVarsAux = var_video_list_FlashVars[idAux];
			var strAux = '';
			strAux += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="100%" height="100%" id="objLista_'+idAux+'">';
			strAux += '<param name="allowScriptAccess" value="sameDomain" /> ';
			strAux += '<param name="movie" value="'+srcAux+'" />';
			strAux += '<param name="FlashVars" value="'+FlashVarsAux+'&get_memory_fv=0" />';
	        strAux += '<param name="quality" value="high" />';
	        strAux += '<param name="bgcolor" value="#ffffff" />';
	        strAux += '<embed src="'+srcAux+'" FlashVars="'+FlashVarsAux+'&get_memory_fv=1" quality="high" bgcolor="#ffffff" width="100%" height="100%" swliveconnect="true" name="objLista_'+idAux+'" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
	        strAux += '</object>';
	        var divVideoLista = document.getElementById("divVideoLista_"+idAux);
	        loadEmbedObjectInDiv(divVideoLista, strAux);
		}
	}
}
Behaviour.addLoadEvent(createVideoList);

// MENUS
try{
	CSS_OTF.addRule(".tabContenido","display:none;")
	CSS_OTF.addRule(".tSel","display:block;")
	CSS_OTF.addRule(".sh","display:none;")
}catch(e){
	CSS_OTF.insertRule(".tabContenido { display: none; }", 0)
	CSS_OTF.insertRule(".tSel { display: block; }", 1)
	CSS_OTF.insertRule(".sh { display: none; }", 2)
}

