// Standard get/set cookie functions
function GetCookie(name) {
  name += '=';
  var c = document.cookie.split('; ');
  for (var i in c)
    if (c[i].lastIndexOf(name, 0) == 0)
      return unescape(c[i].substr(name.length));
  return null;
}
function SetCookie(name, value, expires, path, domain, secure) {
  document.cookie= name + "=" + escape(value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}


// Adds the channel to the list maintained in the cookie - if it's not
// there already. If already there, move to front of list.
// Limits number of entries, with the oldest dropping off the end.
function AddVC(cookie, channel) {
  var cookieval = GetCookie(cookie);
  var maxchannels = 15;
  var expdate = new Date ();
  expdate.setTime(expdate.getTime() + (15*24*60*60*1000)); // 15 days
  channel = 'vc=' + channel + ';';
  if (!cookieval) {newcookieval = channel;}
  else if (cookieval.indexOf(channel) == -1) {newcookieval = channel + cookieval;}
  else {newcookieval = channel + cookieval.replace(channel, '');}
  while (newcookieval.split(';').length>maxchannels+1) { newcookieval = newcookieval.substr(0, newcookieval.lastIndexOf('vc=')); }
  SetCookie(cookie, newcookieval, expdate, '/', '', false);
}


// Get values from query string
function getQueryVar(variable) {
 var query = window.location.search.substring(1);
 var v = query.split("&");
 for (var i=0;i<v.length;i++) {
  var pair = v[i].split("=");
   if (pair[0] == variable) {
    return pair[1];
   }
 } 
 return false;
}



// Random number
var rand=Math.random()*10000000000000000;



// Page type
var ptype;
if (typeof RegPage != 'undefined') {
  ptype = RegPage;
}
else {
  (function(){
    var slashes = 0;
    var pos = 0;
    while ((pos = location.href.indexOf('/', pos)) != -1) {
      slashes++;
      pos++;
    }
    ptype = slashes >= 7 ? 'article' : 'index';
  })();
}

// Excats (!cat)
var excats='';
if (typeof(ExcA)!='undefined') {
 tempcat=ExcA.split('|');
 for(i=0; i<tempcat.length; i++) {
  if (!tempcat[i]=='') {
   excats+='!cat=' + tempcat[i] + ';';
  }
 }
}

// test var
var test = getQueryVar('test');

//maid
var maid = '';

