// Pop-up Window

function NewWindow(mypage, myname, w, h, scroll) {
var winl = (screen.width - w) / 2;
var wint = (screen.height - h) / 2;
winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
win = window.open(mypage, myname, winprops)
if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

// Static Comments by Neo Geek
function browser_name() {

   var nav = navigator.userAgent

   if (nav.indexOf('Firefox') != -1) { return 'moz'; }
   else if (nav.indexOf('Flock') != -1) { return 'moz'; }
   else if (nav.indexOf('Opera') != -1) { return 'opera'; }
   else if (nav.indexOf('MSIE') != -1) { return 'ie'; }
   else if (nav.indexOf('Safari') != -1) { return 'safari'; }
   else { return nav; }

}

function comment_follow() {

   var offset = 10;

   var yscroll = window.pageYOffset?window.pageYOffset:document.documentElement.scrollTop;

   if ($('comment-form')) {

      if (!$('comment-form').iniOffsetTop) { $('comment-form').iniOffsetTop = $('comment-form').offsetTop; }
      if (!$('comment-form').inilOffsetLeft) { $('comment-form').iniOffsetLeft = $('comment-form').offsetLeft; }

      if (!retrieveCookie('comment_follow')) { createCookie('comment_follow', 'false', 90); }

      if (retrieveCookie('comment_follow') == 'true') { $('toggle_comments').innerHTML = '<strong>Dock Comment Form</strong>'; }
      else if (retrieveCookie('comment_follow') == 'false') { $('toggle_comments').innerHTML = '<strong>Undock Comment Form</strong>'; }

      if (retrieveCookie('comment_follow') == 'true' && $('commentlist').offsetHeight > $('commentform').offsetHeight) {

         if ((yscroll + offset) > $('comment-form').iniOffsetTop) {

            $('comment-form').style.position = 'fixed';
            $('comment-form').style.top = offset + 'px';
            $('comment-form').style.left = $('comment-form').iniOffsetLeft + 'px';

         } else if ((yscroll + offset) < $('comment-form').iniOffsetTop) {

            $('comment-form').style.position = 'relative';
            $('comment-form').style.top = '0px';
            $('comment-form').style.left = '0px';

         }

      }

   }

}

function toggle_comment_follow(object) {

   if (retrieveCookie('comment_follow') == 'true') {

      object.innerHTML = '<strong>Undock Comment Form</strong>';
      createCookie('comment_follow', 'false', 90);

      $('comment-form').style.position = 'relative';
      $('comment-form').style.top = '0px';
      $('comment-form').style.left = '0px';

   } else if (retrieveCookie('comment_follow') == 'false') {

      object.innerHTML = '<strong>Dock Comment Form</strong>';
      createCookie('comment_follow', 'true', 90);

   }

}

function retrieveCookie(name) {

   var key = '';

   var cookies = document.cookie.split(';');

   for (var i = 0 ; i < cookies.length; i++) {

      key = cookies[i].substring(0, cookies[i].indexOf('=')).replace(/^\s*|\s*$/g,"");
      value = cookies[i].substring(cookies[i].indexOf('=') + 1);

      if (key == name) { return value; }

   }

   return null;

}

function createCookie(name, value, days) {

   if (days) {

      var date = new Date;
      date.setTime(date.getTime() + (days*24*60*60*1000));
      days = 'expires=' + date.toGMTString() + ';';

   } else { days = ''; }

   document.cookie = name + '=' + value + ';' + days + 'path=/';

}

function removeCookie(name) {

   createCookie(name, null, -1);

}

if (browser_name() != 'ie') {

   window.onscroll = function() { comment_follow(); }
   window.onresize = function() { comment_follow(); }

}

