/*function WindowOnload(B){var A=window.onload;window.onload=function(){if(A){A()}B()}}function ec3(){WindowOnload(function(){var S=document.getElementById("ec3_prev");var R=document.getElementById("ec3_next");if(S&&R){var T=new RegExp("&cat=[0-9]+$");var P=T.exec(S.href);if(P){ec3.catClause=P[0]}S.href="javascript:ec3.go_prev()";R.href="javascript:ec3.go_next()";ec3.imgwait=new Image(14,14);ec3.imgwait.src=ajax_loader_img.src;ec3.viewpostsfor=B(ec3.viewpostsfor);for(var Q=0;Q<ec3.month_of_year.length;Q++){ec3.month_of_year[Q]=B(ec3.month_of_year[Q])}for(var O=0;O<ec3.month_abbrev.length;O++){ec3.month_abbrev[O]=B(ec3.month_abbrev[O])}}});function B(O){if(!ec3.unencodeDiv){ec3.unencodeDiv=document.createElement("div")}ec3.unencodeDiv.innerHTML=O;return(ec3.unencodeDiv.innerText||ec3.unencodeDiv.firstChild.nodeValue)}function H(Q,R){var P=Q.getElementsByTagName(R);if(P){for(var O=0;O<P.length;O++){if(P[O].parentNode==Q){return P[O]}}}return 0}ec3.get_child_by_tag_name=H;function K(O,P,Q){if(ec3.today_day_num==O&&ec3.today_month_num==P&&ec3.today_year_num==Q){return"today"}else{return"ec3_"+Q+"_"+P+"_"+O}}function N(d,Q,X){var d=d.cloneNode(1);var V=Q-1;var e=H(d,"caption");if(e&&e.firstChild){var Z=e.firstChild;var S=ec3.month_of_year[V]+" "+X;if(Z.nodeType==ec3.TEXT_NODE){Z.data=S}else{if(Z.nodeType==ec3.ELEMENT_NODE&&(Z.tagName=="A"||Z.tagName=="a")&&Z.firstChild&&Z.firstChild.nodeType==ec3.TEXT_NODE){if(Q<10){Q="0"+Q}Z.href=ec3.home+"/"+X+"/"+Q+"/";if(ec3.catClause){Z.href+=ec3.catClause}Z.title=ec3.viewpostsfor;Z.title=Z.title.replace(/%1\$s/,ec3.month_of_year[V]);Z.title=Z.title.replace(/%2\$s/,X);Z.firstChild.data=S}}}if(e&&e.firstChild&&e.firstChild.nodeType==ec3.TEXT_NODE){e.firstChild.data=ec3.month_of_year[V]+" "+X}var W=H(d,"tbody");while(W.lastChild){W.removeChild(W.lastChild)}var T=new Date(X,V,1,12,0,0);var Y=document.createElement("tr");var U,P;W.appendChild(Y);var O=0;var R=0;while(T.getMonth()==V&&O<40){var b=(T.getDay()+7-ec3.start_of_week)%7;if(R>6){Y=document.createElement("tr");W.appendChild(Y);R=0}if(R<b){U=document.createElement("td");U.colSpan=b-R;U.className="pad";Y.appendChild(U);R=b}U=document.createElement("td");U.appendChild(document.createTextNode(T.getDate()));U.id=K(T.getDate(),Q,X);Y.appendChild(U);R++;O++;T.setDate(T.getDate()+1)}if(R<7){U=document.createElement("td");U.colSpan=7-R;U.className="pad";Y.appendChild(U)}if((7-R)>1&&!ec3.hide_logo){a=document.createElement("a");a.href="http://blog.firetree.net/?ec3_version="+ec3.version;a.title="Event Calendar "+ec3.version;U.style.verticalAlign="bottom";U.appendChild(a);P=document.createElement("div");P.className="ec3_ec";P.align="right";a.appendChild(P)}d.id="ec3_"+X+"_"+Q;return d}function L(O,Q){var P=new XMLHttpRequest();if(P){ec3.reqs.push(P);P.onreadystatechange=I;P.open("GET",ec3.home+"/?ec3_xml="+Q+"_"+O,true);F(1);P.send(null)}}function E(){var R=document.getElementById("wp-calendar");var O=new Array();for(var P=0;P<R.childNodes.length;P++){var Q=R.childNodes[P];if(Q.id&&Q.id.search("ec3_[0-9]")==0&&Q.style.display!="none"){O.push(R.childNodes[P])}}if(O.length>0){return O}else{return 0}}ec3.get_calendars=E;function C(Q,R){var P=document.getElementById("ec3_prev");if(P&&P.firstChild&&P.firstChild.nodeType==ec3.TEXT_NODE){P.firstChild.data="\u00ab\u00a0"+ec3.month_abbrev[Q%12]}var O=document.getElementById("ec3_next");if(O&&O.firstChild&&O.firstChild.nodeType==ec3.TEXT_NODE){O.firstChild.data=ec3.month_abbrev[R%12]+"\u00a0\u00bb"}}function F(O){var P=document.getElementById("ec3_spinner");if(P){if(O){P.style.display="inline"}else{P.style.display="none"}}}function A(){var T=E();if(!T){return }var O=T[0].parentNode;var Q=T[0].id.split("_");if(Q.length<3){return }var S=parseInt(Q[1]);var P=parseInt(Q[2])-1;if(P==0){P=12;S--}var R=document.getElementById("ec3_"+S+"_"+P);if(R){R.style.display=ec3.calendar_display}else{R=N(T[0],P,S);O.insertBefore(R,T[0]);L(P,S)}ec3.calendar_display=T[T.length-1].style.display;T[T.length-1].style.display="none";C(P+10,P+T.length-1)}ec3.go_prev=A;function D(){var U=E();if(!U){return }var P=U[0].parentNode;var O=U[U.length-1];var R=O.id.split("_");if(R.length<3){return }var T=parseInt(R[1]);var Q=1+parseInt(R[2]);if(Q==13){Q=1;T++}var S=document.getElementById("ec3_"+T+"_"+Q);if(S){S.style.display=ec3.calendar_display}else{S=N(U[0],Q,T);if(O.nextSibling){P.insertBefore(S,O.nextSibling)}else{P.appendChild(S)}L(Q,T)}ec3.calendar_display=U[0].style.display;U[0].style.display="none";C(Q-U.length+11,Q)}ec3.go_next=D;function I(){var Q=0;for(var O=0;O<ec3.reqs.length;O++){var P=ec3.reqs[O];if(P){if(P.readyState==4){ec3.reqs[O]=0;if(P.status==200){if(P.responseXML&&P.responseXML.documentElement){J(P.responseXML.documentElement)}}}else{Q=1}}}if(!Q){window.setTimeout(G,1000);while(ec3.reqs.shift&&ec3.reqs.length&&!ec3.reqs[0]){ec3.reqs.shift();if(M>3){break}}F(0)}}var M=0;function G(){M++}function J(R){var V=R.getElementsByTagName("day");if(!V){return }for(var Q=0;Q<V.length;Q++){var U=document.getElementById(V[Q].getAttribute("id"));if(U&&U.firstChild&&U.firstChild.nodeType==ec3.TEXT_NODE){U.className="ec3_postday";var O=U.removeChild(U.firstChild);var P=document.createElement("a");P.href=V[Q].getAttribute("link");P.title=V[Q].getAttribute("titles");if(V[Q].getAttribute("is_event")){U.className+=" ec3_eventday";P.className="eventday"}P.appendChild(O);U.appendChild(P);var S=P.title;U.setAttribute("onmouseover","popupevents_show('"+S+"')");U.setAttribute("onclick","popupevents_toogle('"+S+"')");U.onmouseout=popupevents_hide;P.removeAttribute("title");P.removeAttribute("href");P.setAttribute("href","javascript:void(0)")}}if(typeof ec3_Popup!="undefined"){var T=document.getElementById(R.childNodes[0].getAttribute("id"));if(T){ec3_Popup.add_tbody(H(T,"tbody"))}}}}ec3();ec3.today=new Date();ec3.today_day_num=ec3.today.getDate();ec3.today_month_num=1+ec3.today.getMonth();ec3.today_year_num=ec3.today.getFullYear();ec3.reqs=new Array();ec3.ELEMENT_NODE=1;ec3.TEXT_NODE=3;ec3.version="3.0.4";
*/           

/* EventCalendar. Copyright (C) 2005, 2006 Alex Tingle.  $Revision: 1.24.4.4 $
 * This file is licensed under the GNU GPL. See LICENSE file for details.
 */

// Set in HTML file:
//   var ec3.start_of_week
//   var ec3.month_of_year
//   var ec3.month_abbrev
//   var ec3.siteurl
//   var ec3.home
//   var ec3.hide_logo
//   var ec3.viewpostsfor

/** Register an onload function. */
function WindowOnload(f)
{
  var prev=window.onload;
  window.onload=function(){ if(prev)prev(); f(); }
}

// namespace
function ec3()
{
  WindowOnload( function()
  {
    // Overwrite the href links in ec3_prev & ec3_next to activate EC3.
    var prev=document.getElementById('ec3_prev');
    var next=document.getElementById('ec3_next');
    if(prev && next)
    {
      // Check for cat limit in month link
      var xCat=new RegExp('&cat=[0-9]+$');
      var match=xCat.exec(prev.href);
      if(match)
        ec3.catClause=match[0];
      // Replace links
      prev.href='javascript:ec3.go_prev()';
      next.href='javascript:ec3.go_next()';
      // Pre-load image.
      ec3.imgwait=new Image(16,16);
      ec3.imgwait.src = ajax_loader_img.src;
      // Convert strings from PHP into Unicode
      ec3.viewpostsfor=unencode(ec3.viewpostsfor);
      for(var i=0; i<ec3.month_of_year.length; i++)
        ec3.month_of_year[i]=unencode(ec3.month_of_year[i]);
      for(var j=0; j<ec3.month_abbrev.length; j++)
        ec3.month_abbrev[j]=unencode(ec3.month_abbrev[j]);
    }
  } );

  /** Converts HTML encoded text (e.g. "&copy Copyright") into Unicode. */
  function unencode(text)
  {
    if(!ec3.unencodeDiv)
      ec3.unencodeDiv=document.createElement('div');
    ec3.unencodeDiv.innerHTML=text;
    return (ec3.unencodeDiv.innerText || ec3.unencodeDiv.firstChild.nodeValue);
  }

  function get_child_by_tag_name(element,tag_name)
  {
    var results=element.getElementsByTagName(tag_name);
    if(results)
      for(var i=0; i<results.length; i++)
        if(results[i].parentNode==element)
          return results[i];
    return 0;
  }
  ec3.get_child_by_tag_name=get_child_by_tag_name;


  function calc_day_id(day_num,month_num,year_num)
  {
    if(ec3.today_day_num==day_num &&
       ec3.today_month_num==month_num &&
       ec3.today_year_num==year_num)
    {
      return 'today';
    }
    else
    {
      return 'ec3_'+year_num+'_'+month_num+'_'+day_num;
    }
  }


  /** Replaces the caption and tbody in table to be the specified year/month. */
  function create_calendar(table,month_num,year_num)
  {
    // Take a deep copy of the current calendar.
    var table=table.cloneNode(1);

    // Calculate the zero-based month_num
    var month_num0=month_num-1;

    // Set the new caption
    var caption=get_child_by_tag_name(table,'caption');
    if(caption && caption.firstChild)
    {
      var c=caption.firstChild;
      var caption_text=ec3.month_of_year[month_num0] + ' ' + year_num;
      if(c.nodeType==ec3.TEXT_NODE)
      {
        c.data=caption_text;
      }
      else if(c.nodeType==ec3.ELEMENT_NODE && (c.tagName=='A' || c.tagName=='a')
           && c.firstChild && c.firstChild.nodeType==ec3.TEXT_NODE )
      {
        //c.href=ec3.home+'/?year='+year_num+'&monthnum='+month_num;
        if(month_num < 10 ) month_num = '0'+month_num;
        c.href=ec3.home+'/'+year_num+'/'+month_num+'/';
        if(ec3.catClause)
           c.href+=ec3.catClause; // Copy cat' limit from original month link.
        c.title=ec3.viewpostsfor;
        c.title=c.title.replace(/%1\$s/,ec3.month_of_year[month_num0]);
        c.title=c.title.replace(/%2\$s/,year_num);
        c.firstChild.data=caption_text;
      }
    }

    if(caption && caption.firstChild && caption.firstChild.nodeType==ec3.TEXT_NODE)
      caption.firstChild.data=ec3.month_of_year[month_num0] + ' ' + year_num;

    var tbody=get_child_by_tag_name(table,'tbody');

    // Remove all children from the table body
    while(tbody.lastChild)
      tbody.removeChild(tbody.lastChild);

    // Make a new calendar.
    var date=new Date(year_num,month_num0,1, 12,00,00);

    var tr=document.createElement('tr');
    var td,div;
    tbody.appendChild(tr);
    var day_count=0
    var col=0;
    while(date.getMonth()==month_num0 && day_count<40)
    {
      var day=(date.getDay()+7-ec3.start_of_week)%7;
      if(col>6)
      {
        tr=document.createElement('tr');
        tbody.appendChild(tr);
        col=0;
      }
      if(col<day)
      {
        // insert padding
        td=document.createElement('td');
        td.colSpan=day-col;
        td.className='pad';
        tr.appendChild(td);
        col=day;
      }
      // insert day
      td=document.createElement('td');
      td.appendChild(document.createTextNode(date.getDate()));
      td.id=calc_day_id(date.getDate(),month_num,year_num);
      //alert(td.id);
      tr.appendChild(td);
      col++;
      day_count++;
      date.setDate(date.getDate()+1);
    }
    // insert padding
    if(col<7)
    {
      td=document.createElement('td');
      td.colSpan=7-col;
      td.className='pad';
      tr.appendChild(td);
    }

    // add the 'dog'                      
    if((7-col)>1 && !ec3.hide_logo)
    {
      //a=document.createElement('a');
      //a.href='http://blog.firetree.net/?ec3_version='+ec3.version;
      //a.title='Event Calendar '+ec3.version;
      //td.style.verticalAlign='bottom';
      //td.appendChild(a);
      //div=document.createElement('div');
      //div.className='ec3_ec';
      //div.align='right'; // keeps IE happy
      //a.appendChild(div);
    }

    // set table's element id
    table.id='ec3_'+year_num+'_'+month_num;

    return table;
  } // end create_calendar()

                                 
  /** Despatch an XMLHttpRequest for a month of calendar entries. */
  function loadDates(month_num,year_num)
  {
    var req=new XMLHttpRequest();
    if(req)
    {
      ec3.reqs.push(req);
      req.onreadystatechange=process_xml;      
      req.open("GET",
        ec3.home+'/?ec3_xml='+year_num+'_'+month_num,true);      
      set_spinner(1);
      req.send(null);
    }
  }
  

  /** Obtain an array of all the calendar tables. */
  function get_calendars()
  {
    var div=document.getElementById('wp-calendar');
    var result=new Array();
    for(var i=0; i<div.childNodes.length; i++)
    {
      var c=div.childNodes[i];
      if(c.id && c.id.search('ec3_[0-9]')==0 && c.style.display!='none')
        result.push(div.childNodes[i]);
    }
    if(result.length>0)
      return result;
    else
      return 0;
  }
  ec3.get_calendars=get_calendars;


  /** Changes the link text in the forward and backwards buttons.
   *  Parameters are the 0-based month numbers. */
  function rewrite_controls(prev_month0,next_month0)
  {
    var prev=document.getElementById('ec3_prev');
    if(prev && prev.childNodes[1] && prev.childNodes[1].nodeType==ec3.TEXT_NODE)
      prev.childNodes[1].data=' '+ec3.month_abbrev[prev_month0%12];
    var next=document.getElementById('ec3_next');
    if(next && next.firstChild && next.firstChild.nodeType==ec3.TEXT_NODE)
      next.firstChild.data=ec3.month_abbrev[next_month0%12]+' ';
  }


  /** Turn the busy spinner on or off. */
  function set_spinner(on)
  {
    var spinner=document.getElementById('ec3_spinner');
    if(spinner)
    {
      if(on)
        spinner.style.display='inline';
      else
        spinner.style.display='none';
    }
  }


  /** Called when the user clicks the 'previous month' button. */
  function go_prev()
  {               
    var calendars=get_calendars();
    if(!calendars)
      return;
    var pn=calendars[0].parentNode;

    // calculate date of new calendar
    var id_array=calendars[0].id.split('_');
    
    if(id_array.length<3)
      return;
    var year_num=parseInt(id_array[1]);
    id_array[2]=id_array[2].replace(/^0/,'');
    var month_num=parseInt(id_array[2])-1;        
    if(month_num==0)
    {
      month_num=12;
      year_num--;
    }    
    // Get new calendar
    var newcal=document.getElementById('ec3_'+year_num+'_'+month_num);
    if(newcal)
    {
      // Add in the new first calendar
      newcal.style.display=ec3.calendar_display;
    }
    else
    {
      newcal=create_calendar(calendars[0],month_num,year_num);
      pn.insertBefore( newcal, calendars[0] );
      loadDates(month_num,year_num);
    }
    // Hide the last calendar
    ec3.calendar_display=calendars[calendars.length-1].style.display;
    calendars[calendars.length-1].style.display='none';

    // Re-write the forward & back buttons.
    rewrite_controls(month_num+10,month_num+calendars.length-1);
  }
  ec3.go_prev=go_prev;


  /** Called when the user clicks the 'next month' button. */
  function go_next()
  {
    var calendars=get_calendars();
    if(!calendars)
      return;
    var pn=calendars[0].parentNode;
    var last_cal=calendars[calendars.length-1];

    // calculate date of new calendar
    var id_array=last_cal.id.split('_');
    if(id_array.length<3)
      return;
    var year_num=parseInt(id_array[1]);
    id_array[2]=id_array[2].replace(/^0/,'');
    var month_num=1+parseInt(id_array[2]);
    
    if(month_num==13)
    {
      month_num=1;
      year_num++;
    }    
    // Get new calendar
    var newcal=document.getElementById('ec3_'+year_num+'_'+month_num);    
    if(newcal)
    {
      // Add in the new last calendar
      newcal.style.display=ec3.calendar_display;
    }
    else
    {
      newcal=create_calendar(calendars[0],month_num,year_num);
      if(last_cal.nextSibling)
        pn.insertBefore(newcal,last_cal.nextSibling);
      else
        pn.appendChild(newcal);
      loadDates(month_num,year_num);
    }
    // Hide the first calendar
    ec3.calendar_display=calendars[0].style.display;
    calendars[0].style.display='none';

    // Re-write the forward & back buttons.
    rewrite_controls(month_num-calendars.length+11,month_num);
  }
  ec3.go_next=go_next;


  /** Triggered when the XML load is complete. Checks that load is OK, and then
   *  updates calendar days. */
  function process_xml()
  {
    var busy=0;    
    for(var i=0; i<ec3.reqs.length; i++)
    {              
      var req=ec3.reqs[i];      
      if(req)
      {
        if(req.readyState==4)
        {
          ec3.reqs[i]=0;
          if(req.status==200){
            if(req.responseXML && req.responseXML.documentElement)
            update_days(req.responseXML.documentElement);
          }
        }
        else
          busy=1;
      }
    }
    if(!busy)
    {
      window.setTimeout(dont_hang,1000);  
      // Remove old requests.
      while(ec3.reqs.shift && ec3.reqs.length && !ec3.reqs[0]){
        ec3.reqs.shift();      
        if(hang_time > 3){
         //document.getElementById('ec3_spinner').style.display='none';    
         break;
        }
      }
      set_spinner(0);
    }
  }
  
  var hang_time = 0;  
  function dont_hang(){
        hang_time++;       
  }

  /** Adds links to the calendar for each day listed in the XML. */
  function update_days(month_xml)
  {
    popupeventslocked = false;
     popupeventsopened = false;
    var days=month_xml.getElementsByTagName('day');        
    if(!days)
      return;
    for(var i=0; i<days.length; i++)
    {      
      var td=document.getElementById(days[i].getAttribute('id'));          
      if(td && td.firstChild && td.firstChild.nodeType==ec3.TEXT_NODE)
      {        
        td.className='ec3_postday';
        var txt=td.removeChild(td.firstChild);
        var a=document.createElement('a');
        a.href=days[i].getAttribute('link');
        a.title=days[i].getAttribute('titles');                        
                                     
        if(days[i].getAttribute('is_event'))
        {
          td.className+=' ec3_eventday';
          a.className='eventday';
        }        
        a.appendChild(txt);        
        td.appendChild(a);                
        var titke = a.title;                
        a.setAttribute('onmouseover','popupevents_show(\''+titke+'\',this.parentNode)');
        a.setAttribute('onclick','popupevents_toogle(\''+titke+'\',this.parentNode)');
        //td.onmouseover=function(){
        //    popupevents_show(titke);
        //}        
        //td.onclick=function(){
        //    popupevents_toogle(titke);
        //}
        a.onmouseout=popupevents_hide;       
        
            
        a.removeAttribute('title');
        a.removeAttribute('href');
        a.setAttribute('href','javascript:void(0)');        
            
               
      }      
    }
       
    if(typeof ec3_Popup != 'undefined')
    {
      var month=
        document.getElementById(month_xml.childNodes[0].getAttribute('id'));      
      if(month)
        ec3_Popup.add_tbody( get_child_by_tag_name(month,'tbody') );
    }
  }


} // end namespace ec3

// Export public functions from ec3 namespace.
ec3();

// Set up static variables in namespace 'ec3'.

// Get today's date.
// Note - DO THIS ONCE, so that the value of today never changes!
ec3.today=new Date();
ec3.today_day_num=ec3.today.getDate();
ec3.today_month_num=1+ec3.today.getMonth();
ec3.today_year_num=ec3.today.getFullYear();

// Holds ongoing XmlHttp requests.
ec3.reqs=new Array();

ec3.ELEMENT_NODE=1;
ec3.TEXT_NODE=3;

ec3.version='3.0.4';


/* EventCalendar. Copyright (C) 2005, Alex Tingle.  $Revision: 1.12.4.1 $
 * This file is licensed under the GNU GPL. See LICENSE file for details.
 */
/** class ec3_Popup */
function ec3_Popup()
{

  WindowOnload( function()
  {
    var calendars=ec3.get_calendars();
    if(!calendars)
      return;
    // Pre-load images.
    ec3.imgShadow0=new Image(8,32);
    ec3.imgShadow1=new Image(500,16);
    ec3.imgShadow2=new Image(8,32);
    var imgbase=ec3.siteurl+'/wp-content/plugins/eventcalendar3/';
    ec3.imgShadow0.src=imgbase+'shadow0.png';
    ec3.imgShadow1.src=imgbase+'shadow1.png';
    ec3.imgShadow2.src=imgbase+'shadow2.png';

    // Generate the popup (but keep it hidden).
    var table,tbody,tr,td;
    ec3_Popup.popup=document.createElement('table');
    ec3_Popup.popup.style.display='none';
    ec3_Popup.popup.id='ec3_popup';
    ec3_Popup.popup.className='ec3_popup';
    tbody=ec3_Popup.popup.appendChild( document.createElement('tbody') );
    tr=tbody.appendChild( document.createElement('tr') );
    td=tr.appendChild( document.createElement('td') );
    td.id='ec3_shadow0';
    td.rowSpan=2;
    td.appendChild( document.createElement('div') );
    td=tr.appendChild( document.createElement('td') );
    ec3_Popup.contents=td.appendChild( document.createElement('table') );
    ec3_Popup.contents.style.width=500;
    td=tr.appendChild( document.createElement('td') );
    td.id='ec3_shadow2';
    td.rowSpan=2;
    td.appendChild( document.createElement('div') );
    tr=tbody.appendChild( document.createElement('tr') );
    td=tr.appendChild( document.createElement('td') );
    td.id='ec3_shadow1';

    document.body.appendChild(ec3_Popup.popup);

    // Add event handlers to the calendars.
    for(var i=0; i<calendars.length; i++)
      add_tbody( ec3.get_child_by_tag_name(calendars[i],'tbody') );
  } );
  
  function add_tbody(tbody)
  {
    if(!tbody)
      return;
    var anchor_list=tbody.getElementsByTagName('a');
    if(!anchor_list)
      return;
    for(var i=0; i<anchor_list.length; i++)
    { 
      continue;
      var a=anchor_list[i];
      var td=a.parentNode;
      // 'title' might have become 'nicetitle' if that plugin is being run.
      var titleattr=a.getAttribute('nicetitle');
      if(!titleattr)
          titleattr=a.getAttribute('title');
                    
      if(titleattr && td.nodeName=='TD' && td.className!='pad')
      {     
        
        //a.setAttribute('onMouseOver','popupevents_show("'+titleattr+'")');        
        //a.setAttribute('onMouseOut','popupevents_hide()');
        //a.setAttribute('onClick','popupevents_toogle(\''+titleattr+'\')');

        td.onmouseover=function(){
            popupevents_show(titleattr);
        }        
        td.onclick=function(){
            popupevents_toogle(titleattr);
        }
        td.onmouseout=popupevents_hide;
        
        a.removeAttribute('nicetitle');
        a.removeAttribute('title');
        a.removeAttribute('href');
        a.setAttribute('href','javascript:void(0)');        
                    
        //td.setAttribute('id','tdev_'+i);                    
        //global_poptext['tdev_'+i]=titleattr;
        //addEvent(td,'mouseover',popupevents_show_g);
        //addEvent(td,'click',popupevents_toogle_g);
        //addEvent(td,'mouseout',popupevents_hide);
        
        //addEvent(td,'focus',show);
        //addEvent(td,'blur',hide);
      }
    }
  }
  ec3_Popup.add_tbody=add_tbody;
  
  show_hide_toogle = false;
  
    
  function toogle_show_hide(e){    
    if(!show_hide_toogle){
        show(e);
        show_hide_toogle = true;
    }else{
        hide(e);
        show_hide_toogle = false;
    }
  }
  
  function show(e)
  {
    var n;
    if(e.currentTarget)
        n=e.currentTarget; // Mozilla/Safari/w3c
    else if(window.event)
        n=window.event.srcElement; // IE
    else
        return;

    // Find the TD element and the calendar node.
    // (IE will sometimes randomly give us a child instead).
    var td,cal;
    while(1)
    {
      if(!n || n==document.body)
      {
        return;
      }
      else if(n.tagName=='TABLE')
      {
        cal=n;
        break;
      }
      else if(n.tagName=='TD')
      {
        td=n;
      }
      n=n.parentNode;
    }
    
    var ec3_title=td.getAttribute('ec3_title');
    if(typeof ec3_title == 'undefined')
      return;
    if(ec3_Popup.just_hidden)
       ec3_Popup.popup.style.display = "block";
    else
       ec3_Popup.show_timer=setTimeout(
         function(){ec3_Popup.popup.style.display = "block";},
         600
       );

    ec3_Popup.contents.style.width=''+(cal.offsetWidth-2)+'px';
    ec3_Popup.popup.style.top=''+(findPosY(cal)+cal.offsetHeight)+'px';
    ec3_Popup.popup.style.left=''+(findPosX(cal)-8)+'px';

    var tbody=ec3.get_child_by_tag_name(ec3_Popup.contents,'tbody');
    if(tbody)
      ec3_Popup.contents.removeChild(tbody);
    tbody=ec3_Popup.contents.appendChild(document.createElement('tbody'));
    
    var titles=ec3_title.split(', ');
    for(var i=0; i<titles.length; i++)
    {
      tr=tbody.appendChild(document.createElement('tr'));
      td=tr.appendChild(document.createElement('td'));
      td.appendChild(document.createTextNode(titles[i]));
      if(titles[i].indexOf('@')!=-1)
        td.className='eventday';
    }

    // Let's put this event to a halt before it starts messing things up
    window.event? window.event.cancelBubble=true: e.stopPropagation();
  }

  function hide()
  {
    if(ec3_Popup.show_timer)
      clearTimeout(ec3_Popup.show_timer);
    if(ec3_Popup.popup.style.display!='none')
    {
     ec3_Popup.just_hidden=1;
     ec3_Popup.hide_timer=setTimeout(function(){ec3_Popup.just_hidden=0;},900);
    }
    ec3_Popup.popup.style.display='none';

  }

  //=====================================================================
  // Event Listener
  // by Scott Andrew - http://scottandrew.com
  // edited by Mark Wubben, <useCapture> is now set to false
  //=====================================================================
  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;
    }
  }

  //=====================================================================
  // From http://www.quirksmode.org/
  //=====================================================================
  function findPosX(obj)
  {
    var curleft = 0;
    if (obj.offsetParent)
    {
      while(1)
      {
        curleft += obj.offsetLeft;
    if(!obj.offsetParent) break;
        obj = obj.offsetParent;
      }
    }
    else if (obj.x)
      curleft += obj.x;
    return curleft;
  }

  function findPosY(obj)
  {
    var curtop = 0;
    if (obj.offsetParent)
    {
      while(1)
      {
        curtop += obj.offsetTop;
    if(!obj.offsetParent) break;
        obj = obj.offsetParent;
      }
    }
    else if (obj.y)
      curtop += obj.y;
    return curtop;
  }

} // end namespace ec3_Popup

// Export public functions from ec3_Popup namespace.
ec3_Popup();

var IE = document.all?true:false;
if (!IE) document.captureEvents(Event.MOUSEMOVE);
if(IE){
    window.onload = function(){   
        popupevents_show('');
        popupeventslocked = false            
        popupevents_hide();
    }
}

jQuery(document).mousemove(getMouseXY);
// Temporary variables to hold mouse x-y pos.s
var tempX = 0
var tempY = 0

// Main function to retrieve mouse x-y pos.s

var scrOfX = 0, scrOfY = 0;
function getScrollXY() {
  
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
}

function getMouseXY(e) {
  getScrollXY();  
  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + scrOfX
    tempY = event.clientY + scrOfY
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
  // show the position values in the form named Show
  // in the text fields named MouseX and MouseY  
  return true
}

var popupeventslocked = false;
var popupeventsopened = false;
var close_but = false;
function popupevents_show(evtext, td){ 
    if(popupeventslocked || jQuery('#popupeventslist').length) return;
    popupeventslistel = document.createElement('div');
    popupeventslistel.setAttribute('id','popupeventslist');
    try{
        td.appendChild(popupeventslistel);
        if(document.getElementById('popupeventslist')){
            document.getElementById('popupeventslist').innerHTML=evtext;            
            document.getElementById('popupeventslist').style.display="block";;
            document.getElementById('popupeventslist').style.zIndex = 10;    
        }
    }catch(err){
        //
    }
    popupeventsopened = true;
}
function popupevents_show_g(){ 
    popupevents_toogle(global_poptext[tdev_0]);
}
function popupevents_hide(){    
    if(popupeventslocked) return;    
    if(jQuery('#popupeventslist').length){
        jQuery('#popupeventslist').hide();
        jQuery('#popupeventslist').remove();
    }
    close_but = false;
    popupeventsopened = false;
}
function popupevents_toogle(evtext, td){
    if(popupeventslocked){
        document.getElementById('popupeventslist').style.display="none";
        close_but = false;
        popupeventslocked = false;
        if(jQuery('#popupeventslist').length) jQuery('#popupeventslist').remove();    
    }else{
        popupevents_show(evtext, td);
        if(!close_but){
            document.getElementById('popupeventslist').innerHTML += '<br /><br /><div style="float:right;" onclick="popupeventslocked = false;popupevents_hide();"><a href="javascript:void(0)">[close]</a></div>';            
            close_but = true;
        }
        popupeventslocked = true;
    } 
}
function popupevents_toogle_g(){
    popupevents_toogle(global_poptext[this.getAttribute('id')]);
}



