/* COOKIE MANAGEMENT */
function neSetCookie(name,val,expDays) {
	Cookie.set(name,val,expDays);
}
function neGetCookie(which) {
   return Cookie.get(which);
}

/* TIMEDIFF */
function formatFullDate(postTime) {
	postTime=new Date(postTime);
	var month=['January','February','March','April','May','June','July','August','September','October','November','December'];
	var postYear=postTime.getYear();
	if (postYear<1900) postYear+=1900;
	return month[postTime.getMonth()]+' '+postTime.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;
}

// neAddStartEvent depricated in favor of Event.onDOMReady
function neAddStartEvent(which) {
	Event.onDOMReady(which);
}

/* AUDIO LOADER */
function loadAudio(fName,track,options) {
	if (!options) options = {};
	options.width = options.width || 150;
	options.height = options.height || 21;
	
	var tracking;
	
	if (track=="daily") {
		tracking = "http://chkpt.zdnet.com/chkpt/news.pod.daily.flash/";
	} else if (track=="bites")  {
		tracking = "http://chkpt.zdnet.com/chkpt/news.pod.bites.flash/";
	} else {
		tracking = "http://chkpt.zdnet.com/chkpt/ne.audio.flash/";
	}
	
	if (fName.match('/')) {
		fName = fName.substring(fName.lastIndexOf('/')+1);
		var noteit = new Image();
		noteit.src = "http://dw.com.com/redir?destUrl=http%3A%2F%2Fwww%2Ecnet%2Ecom%2Fi%2Fb%2Egif&edId=3&siteId=3&oId=&ontId=&lop=ne.audio.legacy."+fName;
	}

	var url = "http://podcast-files.cnet.com/podcast/"+fName;
	var player = "http://i.n.com.com/av/n/emff.swf?src=";

	var embed = '<object type="application/x-shockwave-flash" ';
	embed += 'data="' + player+tracking+url+'" ';
	embed += 'width="'+options.width+'" ';
	embed += 'height="'+options.height+'" ';
	embed += '/>'+"\n";
	embed += ' <param name="movie" ';
	embed += 'value="' + player+tracking+url+'" ';
	embed += '/>'+"\n";
	embed += ' <param name="quality" value="high" />'+"\n";
	embed += '</object>'+"\n";
	
	document.write(embed);
}

// STRIP TAGS, STOLEN FROM PROTOTYPE
Object.extend(String.prototype, {
	stripTags: function() {
		return this.replace(/<\/?[^>]+>/gi,'');
	}
});

/* INIT THE LOGIN BOX */
Event.onDOMReady(function(){
	new LoginStatus;
});


