// prototype.js needed

var GB_ROOT_DIR = "http://www.elmundodeorizaba.com/js/greybox/";

function montre(id) {
var d = document.getElementById(id);
	for (var i = 1; i<=10; i++) {
		if (document.getElementById('smenu'+i)) {
		document.getElementById('smenu'+i).style.display='none';}
	}
if (d) {d.style.display='block';}
}

function fbs_click() {
            u=location.href;
            t=document.title;
            
            window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&amp;t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
            
    return false;
}

function viewsect(sel){
    if (sel.sections.selectedIndex != 0){
    document.location=sel.sections.options[sel.sections.selectedIndex].value
    }
}

function mobile(){
   if(screen.width <= 800){
      location.replace('http://www.elmundodeorizaba.com/index.php?command=transform&style=error-mobile') 
       }          
    }

function startList(){
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("nav");
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className+=" over";
				}
				node.onmouseout=function() {
					this.className=this.className.replace(" over", "");
				}
			}
		}		
	}
}

function displayComments (newsId){   
    var aleatorio = Math.random() 
    

	new Ajax.Updater({ success: 'comments', failure: 'comments' }, 'http://www.elmundodeorizaba.com/index.php', {
					 method: 'get',
					 evalScripts: true,
					 encoding: 'iso-8859-1',
     				 parameters: {command: 'view_comments', news_id: newsId, aleator: aleatorio}	 
                    }); 
}

function displayPoll ()
{
	new Ajax.Updater({ success: 'poll', failure: 'poll' },'display-poll.php', {
					 method: 'get',
					 evalScripts: false					 
                    }); 
}


function printDate() {
    Fecha = new Date();
    document.write(Fecha.getDate()+' de ');
    document.write(getMes(Fecha.getMonth())+' de ');
    document.write(Fecha.getFullYear());
}

function startTime()
{
    var today=new Date()
    var h=today.getHours()
    var m=today.getMinutes()
    var s=today.getSeconds()
    // add a zero in front of numbers<10
    m=checkTime(m)
    s=checkTime(s)
    document.getElementById('hora').innerHTML=h+":"+m+":"+s
    t=setTimeout('startTime()',500)
}

function checkTime(i)
{
    if (i<10) 
      {i="0" + i}
      return i
}

function banner(zone)
{
    if (!document.phpAds_used) document.phpAds_used = ',';
    phpAds_random = new String (Math.random()); phpAds_random = phpAds_random.substring(2,11);
   
    document.write ("<" + "script language='JavaScript' type='text/javascript' src='");
    document.write ("http://elmundodeoportunidades.com/adorizaba/adjs.php?n=" + phpAds_random);
    document.write ("&amp;what=zone:"+zone);
    document.write ("&amp;exclude=" + document.phpAds_used);
    if (document.referrer)
       document.write ("&amp;referer=" + escape(document.referrer));
    document.write ("'><" + "/script>");

}


function busca_ejemplar() 
{
    var fecha=document.getElementById('sel1').value;
    if (fecha!='')
    {
        var seccion=document.getElementById('seccion').value.split("_");
        var ejemplar = issues[seccion[0]+"_"+fecha];
        if (ejemplar == null) {
            alert ("Lo sentimos. Actualmente no hay dispnible ninguna noticia en la secci\363n y fecha seleccionadas");
        } else {
            document.getElementById('form_hemeroteca').action='index.php?command=show_archive_summary&section_id='+seccion[1]   +'&issue_id='+ejemplar;
            document.getElementById('form_hemeroteca').submit();
        }
    } 
    else 
    {
        document.getElementById('not_date').style.display='inline';
        document.getElementById('cal-button-1').style.border='1px solid #c00';
    }
}

function show_years()
{
    var nodes=document.getElementsByName('exemplar');
    for (var i=0; i<nodes.length; i++)
    {
        nodes[i].style.display='none';
    }
}

function show_months(className, id_publication, year)
{
    var elements=document.getElementsByClassName(className);
    for (i=0; i<elements.length;i++)
    {
        elements[i].style.display='none';
    }
    $('block-mesos-'+id_publication+'-'+year).style.display='block';    
}

function show_exemplar(className, id_publication, year, month)
{
    show_years();

    var visibles=document.getElementsByClassName('exemplar-'+year+'-'+month);    

    for (k=0; k<visibles.length;k++)
    {
        visibles[k].style.display='block';
    }
}

function show_publication(id){
    document.getElementById('economia').style.display='none';   
    document.getElementById('estilo_de_vida').style.display='none';   
    document.getElementById('tecnologia').style.display='none';   
    document.getElementById('salud').style.display='none';   
    switch (id) {
        case 1: document.getElementById('economia').style.display='block'; break;  
        case 2: document.getElementById('estilo_de_vida').style.display='block'; break;  
        case 3: document.getElementById('tecnologia').style.display='block'; break;  
        case 4: document.getElementById('salud').style.display='block'; break;  
    }
}

function DOMToString(doc) 
{
	var e = doc.firstChild;
	return ElementToString(e);
}

function ElementToString(e) 
{
	 var attr = "";
	 var cont = "";
	 if (e.hasChildNodes == false) return "<"+e.nodeName+"\/>";
	 
	 for (var i=0;i<e.childNodes.length;i++) {
	     var c = e.childNodes.item(i);
	     if (c.nodeType=="2") {
	     	if(c.nodeValue != null && c.nodeValue != "" && c.nodeValue != "inherit") 
	     		attr += " "+c.nodeName+"=\""+c.nodeValue+"\" ";
	     }
	     else if (c.nodeType=="1") cont+=ElementToString(c);
	     else if (c.nodeType=="3") cont+=c.nodeValue;                              
	 }
	 
	 var a = e.attributes;
	 for (var i=0;i<a.length;i++) {
	     if(a[i].nodeValue != null && a[i].nodeValue != "" && c.nodeValue != "inherit") 
	     	attr += " "+a[i].nodeName+"=\""+a[i].nodeValue+"\" ";
	 }
	 
	 return "<"+e.nodeName+attr+">"+cont+"<\/"+e.nodeName+">";
}





function create_param(node,src,value)
{
    var param=node.createElement('param');
        param.setAttribute("value", value);
        param.setAttribute("name",src);
        return param;
}

function create_object(node, url)
{
        var object=node.createElement('object');

        object.type="video/quicktime";
        object.data=url;
        object.height="300";
        object.width="320";
        object.className="iesucks";
        alert("object atribute");
        object.appendChild(create_param(node, "autoplay","false"));
        alert("object atribute2");
        object.appendChild(create_param(node, "controller","true"));
         alert("object end");
    return object;
}

function add_video(url, root_video, link, link_close)
{
if(navigator.appName=="Microsoft Internet Explorer")
{
    var text="<embed src=\""+url+"\"width=\"300\" height=\"320\" autoplay=\"false\">"
    +"<param name=\"cache\" value=\"true\">"
    +"<param name=\"type\" value=\"video/quicktime\">"
    +"<param name=\"bgcolor\" value=\"#FFFFFF\">"
    +"<param name=\"controller\" value=\"true\">"
    +"<param name=\"showcontrols\" value=\"1\"/>"
    +"<param name=\"enablejavascript\" value=\"TRUE\">"
    +"<param name=\"showdisplay\" value=\"1\">"
    +"<param name=\"qtnext1\" value=\"javascript:GAMIndexAds.endMovie(GAMIndexAds.oCurrentMovie);\">"
    +"</embed>";

} else {
    var text="<object classid=\"clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B\" codebase=\"http://www.apple.com/qtactivex/qtplugin.cab#version=6,0,2,0\" id=\"movie\" height=\"300\" width=\"320\">"
    +"<param name=\"src\" value=\""+url+"\">"
    +"<param name=\"autoplay\" value=\"false\">"
    +"<param name=\"cache\" value=\"true\">"
    +"<param name=\"type\" value=\"video/quicktime\">"
    +"<param name=\"bgcolor\" value=\"#FFFFFF\">"
    +"<param name=\"controller\" value=\"true\">"
    +"<param name=\"showcontrols\" value=\"1\"/>"
    +"<param name=\"enablejavascript\" value=\"TRUE\">"
    +"<param name=\"showdisplay\" value=\"1\">"
    +"<param name=\"qtnext1\" value=\"javascript:GAMIndexAds.endMovie(GAMIndexAds.oCurrentMovie);\">"
    +"<object type=\"video/quicktime\" data=\""+url+"\" height=\"300\" width=\"320\" class=\"iesucks\">"
    +"<param name=\"autoplay\" value=\"false\"/>"
    +"<param name=\"controller\" value=\"true\"/>"
    +"<param name=\"showcontrols\" value=\"1\"/>"
    +"<param name=\"cache\" value=\"true\">"
    +"</object>"
    +"</object>";
}

     document.getElementById(root_video).innerHTML=text;
     document.getElementById(link).style.display='none';
     document.getElementById(link_close).style.display='block';

}

function remove_video(root_video, link, link_close)
{
     document.getElementById(root_video).innerHTML="";
     document.getElementById(link).style.display='block';
     document.getElementById(link_close).style.display='none';
}

function add_audio(url, root_audio, link, link_close)
{
if(navigator.appName=="Microsoft Internet Explorer")
{
  var text="<embed src=\""+url+"\"width=\"200\" height=\"30\" autoplay=\"false\" cache=\"true\" type=\"video/quicktime\">"
    +"<param name=\"enablejavascript\" value=\"TRUE\">"
    +"</embed>";
}
else
{
    var text="<object classid=\"clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B\" codebase=\"http://www.apple.com/qtactivex/qtplugin.cab#version=6,0,2,0\" id=\"movie\" height=\"30\" width=\"200\">"
    +"<param name=\"src\" value=\""+url+"\">"
    +"<param name=\"autoplay\" value=\"false\">"
    +"<param name=\"cache\" value=\"TRUE\">"
    +"<param name=\"type\" value=\"video/quicktime\">"
    +"<param name=\"bgcolor\" value=\"#FFFFFF\">"
    +"<param name=\"controller\" value=\"TRUE\">"
    +"<param name=\"enablejavascript\" value=\"TRUE\">"
    +"<param name=\"qtnext1\" value=\"javascript:GAMIndexAds.endMovie(GAMIndexAds.oCurrentMovie);\">"
    +"<object type=\"video/quicktime\" data=\""+url+"\" height=\"30\" width=\"200\" class=\"iesucks\">"
    +"<param name=\"autoplay\" value=\"false\"/>"
    +"<param name=\"controller\" value=\"true\"/>"
    +"</object>"
    +"</object>";
}
     document.getElementById(root_audio).innerHTML=text;
     document.getElementById(link).style.display='none';
     document.getElementById(link_close).style.display='block';
}
function remove_audio(root_audio, link, link_close)
{
     document.getElementById(root_audio).innerHTML="";
     document.getElementById(link).style.display='block';
     document.getElementById(link_close).style.display='none';
}


function changeElementText (id,text) 
{
    var node = document.getElementById(id);

    if (node!=null)
    {
        var textNode = document.createTextNode(text);
        node.replaceChild(textNode,node.lastChild);
    }
}

function new_human_date()
{
    var string=$('sel1').value;
    var ano=string.substring(0,4);
    var mes=string.substring(5,7);
    var dia=string.substring(8,10);
    if (dia.substring(0,1)=='0')
    {
        dia=dia.substring(1,2);
    }
    var mesTexto="";
    
    switch (mes) {
        case '01' : mesTexto="enero"; break;
        case '02' : mesTexto="febrero"; break;        
        case '03' : mesTexto="marzo"; break;
        case '04' : mesTexto="abril"; break;
        case '05' : mesTexto="mayo"; break;
        case '06' : mesTexto="junio"; break;
        case '07' : mesTexto="julio"; break;
        case '08' : mesTexto="agosto"; break;
        case '09' : mesTexto="septiembre"; break;
        case '10' : mesTexto="octubre"; break;
        case '11' : mesTexto="noviembre"; break;
        case '12' : mesTexto="diciembre"; 
    }
    
    changeElementText('human_date',dia+" de "+mesTexto+" de "+ano);
}


function view_section()
{
    var publicacions=$('publicaciones').value;
    $('secciones-8').style.display='none';
    $('secciones-9').style.display='none';
    $('secciones-10').style.display='none';
    $('secciones-11').style.display='none';
    if (publicacions!=0)
    {
        $('secciones-'+publicacions).style.display='block';
    }
    
    var options0=document.getElementsByClassName('section-0');

    options0.each(function(i){
        i.selected='selected';
    });    
}

function view_issues()
{
    var id_issue=$('anios').value+"-"+$('meses').value+"-"+$('actual_section').value;
    var fechas=document.getElementsByClassName('date_issue');
    var counter=0;
    
    for (var index = 0; index < fechas.length; ++index) {
      var item = fechas[index];
      
       if (id_issue==item.value)
        {
        
          item.parentNode.style.display='block';
          counter++;
        }
        else 
        {
         item.parentNode.style.display='none';
        }
    }   
    
    /*fechas.each(function(i)
    {
        if (id_issue==i.value)
        {
          i.parentNode.style.display='block';
          counter++;
        }
        else 
        {
         i.parentNode.style.display='none';
        }
    }); */  

    if (counter==0) {
        $('no_issues').style.display='block';
        $('issues_found').style.display='none';
    } else
    {
        $('no_issues').style.display='none';
        $('issues_found').style.display='block';
    } 
}

function hide_issues()
{
    var fechas=document.getElementsByClassName('date_issue');
    var counter=0;
    
    for (var index = 0; index < fechas.length; ++index) {
      var item = fechas[index];        
      item.parentNode.style.display='none';
    }   

    /*fechas.each(function(i)
    {
        i.parentNode.style.display='none';
    }); */   
}

function hide_months()
{
    $('fila-mes').style.display='none';
}
function hide_years()
{
    $('fila-anios').style.display='none';
}
function view_months()
{
    $('fila-mes').style.display='block';
    $('meses-0').selected='selected';
    
}

function view_years()
{
    $('fila-anios').style.display='block';
    $('anios-0').selected='selected';
}

function change_section(id_select)
{
    var nou = $('select_sections-'+id_select).value;
    $('actual_section').value=nou;
}

//incrustar videos

function add_video2(url, root_video,width,height)
{
    var text="<object width=\""+width+"\" height=\""+height+"\">"
            +"<param name=\"movie\" value=\""+url+"\"/>"
            +"<param name=\"wmode\" value=\"transparent\"/>"
            +"<embed src=\""+url+"\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\""+width+"\" height=\""+height+"\"/>"
            +"</object>";

    $(root_video).update(text);
   
}

function add_video(url,root_video,width,height)
{

 if(navigator.appName=="Microsoft Internet Explorer")
    {
        var text="<embed src=\""+url+"\" width=\""+width+"\" height=\""+height+"\" autoplay=\"false\" wmode=\"transparent\">"
        +"<param name=\"cache\" value=\"true\">"
        +"<param name=\"type\" value=\"video/quicktime\">"
        +"<param name=\"bgcolor\" value=\"#FFFFFF\">"
        +"<param name=\"controller\" value=\"true\">"
        +"<param name=\"showcontrols\" value=\"1\"/>"
        +"<param name=\"enablejavascript\" value=\"TRUE\">"
        +"<param name=\"showdisplay\" value=\"1\">"
        +"<param name=\"wmode\" value=\"transparent\"/>"
        +"<param name=\"qtnext1\" value=\"javascript:GAMIndexAds.endMovie(GAMIndexAds.oCurrentMovie);\">"
        +"</embed>";
    
    } else {
        var text="<object width=\""+width+"\" height=\""+height+"\">"
            +"<param name=\"movie\" value=\""+url+"\"/>"
            +"<param name=\"wmode\" value=\"transparent\"/>"
            +"<embed src=\""+url+"\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\""+width+"\" height=\""+height+"\"/>"
            +"</object>";
    }
    $(root_video).update(text);
}


function loadVideos()
{

    var videos=$$('.urlvideo');
    if ($('video-width')!=null && $('video-height')!=null)
    {
        var width=$F('video-width');
        var height=$F('video-height');
    }

    for (i=0; i<videos.length;i++)
    {
        add_video(videos[i].value,'root_video_'+videos[i].id.substring(10),width,height);
    }
}

function addEvent(obj, evType, fn){ 
    if (obj.addEventListener){ 
            obj.addEventListener(evType, fn, false); 
            return true; 
            } else if (obj.attachEvent){ 
            var r = obj.attachEvent("on"+evType, fn); 
            return r; 
            } else { 
            return false; 
        } 
}

function openTargetBlank(e){
   
   var className = 'external';
   
   if (!e) var e = window.event;
   var clickedObj = e.target ? e.target : e.srcElement;
   
   if(clickedObj.nodeName == 'A' )
    {
      r=new RegExp("(^| )"+className+"($| )");
      if(r.test(clickedObj.className)){
         window.open(clickedObj.href);
         return false;
   
      }
    }
}

document.onclick = openTargetBlank;

window.onload=function() {
    fontsize(cookieGrab('fontSize'));   
 }
 
 function fontsize(v) { 
    if(v) {
    $('block-1').style.fontSize=v+'px';
    cookieStab('fontSize',v);
    }
   
}

function cookieGrab(f) {
    var c=document.cookie.split(';'); 
    f=f+"=";
    
for (var i = 0;i<c.length;i++) {
  var v=trim2(c[i]);  
  
  if(v.indexOf(f)==0) {       
        return(v.substr(f.length,v.length)); 
   } 
}

}

function trim2(v) { 
    return(v.replace(/(?:(?:^|\n)\s+|\s+(?:$|\n))/g,""));
     }

function cookieStab(f,v) {
    miliseconds=parseInt(365*24*60*60*1000);
    var date = new Date();  
    
    time=date.getTime();
    total=date.setTime(parseInt(time+miliseconds));
      
    document.cookie=f+'='+v+'; path=/'+'; expires=' + date.toGMTString();
 }


function load()
{
    addEvent(window, 'load', loadVideos);
}
    
load()

//metrics

function em2951()
{
	var version = 1;
	var sitio = "162e4773ce6aceb6"
	var pagina = "";
	var server = "ads.us.e-planning.net";
	var seccion_id = "";
	var grupo_id = "";
	
	var isHttps=document.URL.indexOf('https:')==0;

	var url = "http" + (isHttps ? "s" : "") + "://" + server + "/em/" + version + "/" + sitio; 
	if (pagina != "") {
		url += "/" + pagina;
	}
	var n = new Date();
	var hd = n.getHours() * 3600 + n.getMinutes() * 60 + n.getSeconds();	
	var l = navigator.appName=="Netscape" ? navigator.language : navigator.userLanguage;
	var at = 8;
	if (navigator.javaEnabled()) {
		at |=4;
	}
	var r = Math.floor(Math.random() *65555).toString(16);
	url += "?u=" + escape(document.URL) + "&f=" + escape(window.document.referrer) + "&z=" + n.getTimezoneOffset().toString(16) + "&h=" + hd.toString(16) + "&t=" + history.length.toString(16) + "&l=" + escape(l) + "&a=" + at.toString(16) + "&r=" + r;
	if(typeof(screen)=="object") {
		url += "&n=" + screen.width.toString(16) + "x" + screen.height.toString(16) + "x" + (screen.colorDepth != null ? screen.colorDepth.toString(16) : 0);
	}
	if (document.e_planning_load_start != null) {
		lt = n.getTime() - document.e_planning_load_start;
		url += "&m=" + lt.toString(16);
	}
	document.write('<img width="1" height="1" id="em2951" border="0" src="'+url+'">');
}


