/* COOKIE MANAGEMENT */
var neCookies;
function neAllCookies() {
   neCookies = new Array();
   if (document.cookie) {
      var temp = document.cookie.split("; ");
      for (var i=0; i<temp.length; i++) {
         var cook = temp[i].split("=");
         neCookies[cook[0]] = cook[1];
      }
   }
}
neAllCookies();

function neSetCookie(name,val,expDays) {
 var cs = name+"="+escape(val);
 if (expDays) {
    var exp = new Date();
    exp.setTime(exp.getTime() + 1000*60*60*24*expDays);
    cs += "; expires="+exp.toGMTString();
 }
 cs += "; path=/";
 document.cookie=cs;
 // neAllCookies();
}

function neGetCookie(which) {
   if (neCookies[which]) return unescape(neCookies[which]);
   else return false;
}

/* BROWSER DETECTION */
var nn4 = false;	// Netscape Navigator or Communicator
var ie4 = false;
var ie5 = false;
var ie6 = false;
var moz = false;	// Mozilla, NS 6+, Konqueror, etc
var dom1 = false;	// fully supports DOM1
var dom2 = false;	// fully supports (important bits of) DOM2
var old = false;	// very old browser

function neBrowseDetect() {
// do it the official W3C way
   if (window.document.implementation != null) {
      dom1 = window.document.implementation.hasFeature("HTML","1.0");
      dom2 = window.document.implementation.hasFeature("HTML","2.0") &&
      window.document.implementation.hasFeature("Events","2.0") &&
      window.document.implementation.hasFeature("Core","2.0") &&
      window.document.implementation.hasFeature("CSS2","2.0");
   }
   
   // Mozilla based browsers contain the Gecko rendering engine
   moz = (window.navigator != null) ? (window.navigator.userAgent.indexOf("ecko") != -1) : false;
   nn4 = (window.document.layers != null && !moz);
   // IE has incremental support for the Document Object Model
   ie6 = (window.document.all && dom1);
   ie5 = (window.document.all && window.document.getElementsByTagName && !ie6);
   ie4 = (window.document.all && !ie6 && !ie5);
   // something horrible and old - sorry Opera.
   old = (!ie4 && !ie5 && !ie6 && !dom1 && !nn4 && !moz);
}
neBrowseDetect();


/* TIMEDIFF */
function formatFullDate(postTime) {
   var postStamp=new Date(postTime);
   var month=new Array('January','February','March','April','May','June','July','August','September','October','November','December');
   var postMonth=month[postStamp.getMonth()];
   var postYear=postStamp.getYear();
   if (postYear < 1900 ) {
      postYear= postYear+1900;
}
  return postMonth+" "+postStamp.getDate()+", "+postYear;
}

function timeDifference(postTime) {
   if (!serverTime || serverTime<postTime) return formatFullDate(postTime);
   
   var ago=Math.floor((serverTime-postTime)/(1000*60)); // Posted ago in whole minutes rounded down
   if (ago>(60*24)) return formatFullDate(postTime); // Skip if more than 24 hours
   
   var hoursAgo=Math.floor(ago/60); //Whole hours = total minutes/(60min/hour) rounded down
   var minutesAgo=ago%60;           //Minutes = the remainder

   var message='';
   if (hoursAgo) {
      message+=hoursAgo+" hour";
      if (hoursAgo>1) message+="s";
      if (minutesAgo) message+=", ";
   }
   if (minutesAgo) {
      message+=minutesAgo+" minute";
      if (minutesAgo>1) message+="s";
   }
   message+=" ago";
   return message;
}

/* PASSWORD BOX */
function initPassword() {
   if (document.getElementById("newsLoginForm")) {
      document.getElementById("PASSWORD").style.display="none";

      var newinput = document.createElement("input");
      newinput.type="text";
      newinput.id="PASSWORDTEMP";
      newinput.value="Password";
      newinput.className="input pass";

      var formElem = document.getElementById("newsLoginForm");
      var submitElem = formElem.submit;
      formElem.insertBefore(newinput,submitElem);

      document.getElementById("EMAILADDR").onfocus=function(){if (this.value=="E-mail address") this.value="";}
      document.getElementById("PASSWORDTEMP").onfocus=function(){document.getElementById("newsLoginForm").removeChild(document.getElementById("PASSWORDTEMP"));document.getElementById("PASSWORD").style.display="inline";document.getElementById("PASSWORD").focus();document.getElementById("PASSWORD").select();}
   }
}


/* WINDOW.ONLOAD */
var neStartEvents = new Array();

function neAddStartEvent(which) {
   neStartEvents[neStartEvents.length] = which;
}

function neFireStartEvents() {
   if (neStartEvents.length)
      for (var i=0; i<neStartEvents.length; i++)
         neStartEvents[i]();
}

if (window.onload) neAddStartEvent(window.onload);
window.onload=neFireStartEvents;


/* AUDIO LOADER */
function loadAudio(url,track,pwidth,pheight) {
   pwidth = (pwidth) ? pwidth : 150;
   pheight = (pheight) ? pheight : 21;
   var tracking = (track=="pod") ? "http://chkpt.zdnet.com/chkpt/news.pod.daily.flash/" : "http://chkpt.zdnet.com/chkpt/ne.audio.flash/";
   var player = "/av/n/emff.swf?src=";
   var cdspre = "http://i.i.com.com/cnwk.1d";
   
   var embed = '<object type="application/x-shockwave-flash" ';
   embed += 'data="' + cdspre+player+tracking+cdspre+url+'" ';
   embed += 'width="'+pwidth+'" ';
   embed += 'height="'+pheight+'" ';
   embed += '/>'+"\n";
   embed += ' <param name="movie" ';
   embed += 'value="' + cdspre+player+tracking+cdspre+url+'" ';
   embed += '/>'+"\n";
   embed += ' <param name="quality" value="high" />'+"\n";
   embed += '</object>'+"\n";
   
   document.write(embed);
}


