// HeaderDate Function //

function HeaderDate()
{
   var months = new Array(12);
   months[0]  = "January";
   months[1]  = "February";
   months[2]  = "March";
   months[3]  = "April";
   months[4]  = "May";
   months[5]  = "June";
   months[6]  = "July";
   months[7]  = "August";
   months[8]  = "September";
   months[9]  = "October";
   months[10] = "November";
   months[11] = "December";
   var days = new Array(7);
   days[0] = "Sunday";
   days[1] = "Monday";
   days[2] = "Tuesday";
   days[3] = "Wednesday";
   days[4] = "Thursday";
   days[5] = "Friday";
   days[6] = "Saturday";               
   var now = new Date();
   var daynumber = now.getDay();
   var dayname = days[daynumber];
   var monthnumber = now.getMonth();
   var monthname = months[monthnumber];
   var monthday = now.getDate();
   var year = now.getYear();
   if(year < 2000) { year = year + 1900; }
   var HeaderDate = dayname + ', ' + monthname + ' ' + monthday + ', ' + year;
   return HeaderDate;
}

// Menu Functions //

function TopMenu(){
  Menu = ""
  Separator = " &nbsp;|&nbsp; "
  Menu = Menu + AddMenuEntry("Home","../home/default.htm","topmenu")
  Menu = Menu + Separator
  Menu = Menu + AddMenuEntry("Submissions","../submissions/default.htm","topmenu")
  Menu = Menu + Separator
  Menu = Menu + AddMenuEntry("About AUGI | AEC EDGE","../about/default.htm","topmenu")
  return Menu
}

function Menubar(){
  Menu = ""
  Separator = " &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "
  Menu = Menu + AddMenuEntry("AEC EDGE Magazine","../magazine/default.htm","menubar")
  Menu = Menu + Separator
  Menu = Menu + AddMenuEntry("Current Issue","../Current/default.htm","menubar")
  //Menu = Menu + Separator
  //Menu = Menu + AddMenuEntry("Website","../website/default.htm","menubar")
  //Menu = Menu + Separator
  //Menu = Menu + AddMenuEntry("eNewsletter","../enewsletter/default.htm","menubar")
  //Menu = Menu + Separator
  //Menu = Menu + AddMenuEntry("eBulletins","../ebulletins/default.htm","menubar")
  //Menu = Menu + Separator
  // Menu = Menu + AddMenuEntry("Events","../events/default.htm","menubar")
  //Menu = Menu + Separator
  //Menu = Menu + AddMenuEntry("Contacts","../contacts/default.htm","menubar")
  // Menu = Menu + Separator
  // Menu = Menu + AddMenuEntry("Sponsorships","../sponsorships/default.htm","menubar")
  // Menu = Menu + Separator
  // Menu = Menu + AddMenuEntry("Editorial","../editorial/default.htm","menubar")
  // Menu = Menu + Separator
  // Menu = Menu + AddMenuEntry("Special Offers","../specialoffers/default.htm","menubar")
  return Menu
}

function AddMenuEntry(Channel,Link,Style){
  MenuEntry = "<a href='" + Link + "' class='" + Style + "'>" + Channel + "</a>"
  if (CurrentChannel == Channel) MenuEntry = Channel
  return MenuEntry
}

function ParseNavsash(){
  CurrentPage = getPageName(window.location)
  if (CurrentPage == "") CurrentPage = "default.htm"
  var a = document.getElementById("navsash").getElementsByTagName("A");
  for(var i=0;i<a.length;i++){
    if (getPageName(a[i]) == CurrentPage){
      FormatActiveLink(a[i],"ActiveNavsashLink");
      var p = document.getElementById("navsash").getElementsByTagName("P");
      //p[i].style.display = "block";
    }
  }
}

function getPageName(URL){
  pathname = URL.pathname
  lastSlash = pathname.lastIndexOf("/")
  return pathname.substring(lastSlash+1,pathname.length)
}

function FormatActiveLink(n,className){
  if(n.hasChildNodes()){
    for(var i=0;i<n.childNodes.length;i++){
      var NewElement = document.createElement('span');
      var NewNode = n.childNodes[i].cloneNode(true);
      NewElement.className = className;
      NewElement.appendChild(NewNode);
      n.parentNode.appendChild(NewElement);
    }
    n.parentNode.removeChild(n);
  }
}

// Cookie Functions //

/*
   name - name of the cookie
   value - value of the cookie
   [expires] - expiration date of the cookie
     (defaults to end of current session)
   [path] - path for which the cookie is valid
     (defaults to path of calling document)
   [domain] - domain for which the cookie is valid
     (defaults to domain of calling document)
   [secure] - Boolean value indicating if the cookie transmission requires
     a secure transmission
   * an argument defaults when it is assigned null as a placeholder
   * a null placeholder is not required for trailing omitted arguments
*/

function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

/*
  name - name of the desired cookie
  return string containing value of specified cookie or null
  if cookie does not exist
*/

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

/*
   name - name of the cookie
   [path] - path of the cookie (must be same as path used to create cookie)
   [domain] - domain of the cookie (must be same as domain used to
     create cookie)
   path and domain default if assigned null or omitted if no explicit
     argument proceeds
*/

function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

// date - any instance of the Date object
// * hand all instances of the Date object to this function for "repairs"

function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}
