function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + value +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

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));
}

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";
  }
}

function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}

function rememberPost(pid) {
	var pids = getCookie("pids");
	  var now = new Date();
	  fixDate(now);
	  now.setTime(now.getTime() + 2 * 60 * 60 * 1000);
	
	if(pids == null)
		setCookie("pids", pid, null, "/");
	else 
		setCookie("pids", pids + "p" + pid, null, "/");
}

function dopopup(popUrl, popTitle, popW, popH, scroll)
{
	var w = 640, h = 480;
	if (document.all || document.layers) {
	   w = screen.availWidth;
	   h = screen.availHeight;
	}

	var leftPos = (w-popW)/2, topPos = (h-popH)/2;
	var scrolling = 'no';
	if(scroll && scroll == true)
		scrolling = 'yes';
	
	window.open(popUrl,popTitle,"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=" + scrolling + ",resizable=" + scrolling + ",copyhistory=yes,width=" + popW + ",height=" + popH + ",top=" + topPos + ",left=" + leftPos);
}