/* APS Javascript Methods
*******************************/


/* ENTER Submits
--------------------------- */
function ENTERSubmits(e, func)
{
    if(!e) var e = window.event;
    if(e.keyCode) key = e.keyCode;
    else if(e.which) key = e.which;

    if(key == 13)
    {
        setTimeout(func + '()', 1);
    }
    else
        return true;
}

/* Toggle Most Viewed / Recent Comments
--------------------------- */
function ToggleMVRC(li)
{
    // if not clicking an already current tab
    if (!$(li).hasClassName('current'))
    {
       // toggle visibility of tab contents
       $$('div.tabbed-holder-content').invoke('toggle');
       
       // toggle current
       $$('li.mvrc').invoke('toggleClassName', 'current');
    }
}

function dateChanged(calendar) {
    
    // Beware that this function is called even if the end-user only
    // changed the month/year.  In order to determine if a date was
    // clicked you can use the dateClicked property of the calendar:
    
    // OK, a date was clicked, redirect to /yyyy/mm/dd/index.php
    var y = calendar.date.getFullYear();
    var m = calendar.date.getMonth() + 1;     // integer, 0..11
    var d = calendar.date.getDate();      // integer, 1..31
    var extra = '';
   
   if (!calendar.dateClicked)
       // redirect to specific day ...
       extra = '&mode=list';
   
   // redirect to specific day ...
   window.location = 'program_' + $('tbxProgram').value + '_archive.aspx?date=' + m  + '/' + d + '/' + y + extra;

    
};

function CalendarSetup() {
  
  // initialize
  Calendar.setup(
    {
      flat         : "calendar-container", // ID of the parent element
      flatCallback : dateChanged,           // our callback function
      weekNumbers  : false,
      showOthers   : true,
      date         : gup('date')
    }
  );
  
}




/* Get URL Parameter
--------------------------- */
function gup( name )
{
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var tmpURL = window.location.href;
  var results = regex.exec( tmpURL );
  if( results == null )
    return "";
  else
    return results[1];
}

popupWins = new Array();

function windowOpener(url, name, args) {
/*******************************
the popupWins array stores an object reference for
each separate window that is called, based upon
the name attribute that is supplied as an argument
*******************************/
if ( typeof( popupWins[name] ) != "object" ){
popupWins[name] = window.open(url,name,args);
} else {
if (!popupWins[name].closed){
popupWins[name].location.href = url;
} else {
popupWins[name] = window.open(url, name,args);
}
}

popupWins[name].focus();
}

/* Show/hide element (added due to show() function conflict w/ prototype library)
--------------------------- */
function toggleCprElement(id) {
    el = document.getElementById(id);
    if (el.style.display == 'none') {
        el.style.display = '';
    } else {
        el.style.display = 'none';
    }
}