

function getCookie( key ) {
  var tmp1, tmp2, xx1, xx2, xx3;

  tmp1 = " " + document.cookie + ";";
  xx1 = xx2 = 0;
  var len = tmp1.length;

  while (xx1 < len) {
    xx2 = tmp1.indexOf(";", xx1);
    tmp2 = tmp1.substring(xx1 + 1, xx2);
    xx3 = tmp2.indexOf("=");
    if (tmp2.substring(0, xx3) == key) {
      return(unescape(tmp2.substring(xx3 + 1, xx2 - xx1 - 1)));
    }
    xx1 = xx2 + 1;
  }
  return null;
}


function setCookie( key, val ) {

    var tmp = key + "=" + escape(val) + "; ";
    // tmp += "path=" + location.pathname + "; ";
    tmp += "expires=Tue, 31-Dec-2030 23:59:59; ";
    document.cookie = tmp;
}


function setCookieOnSession( key, val ) {
    var tmp = key + "=" + escape(val) + "; ";
    document.cookie = tmp;
}


function getCookieNames(){
  var cookies = document.cookie.split( /\s*;\s*/ );
  var names = new Array();

  for( var i=0; i<cookies.length; i++ ){
    var param = cookies[i].split( "=" );
    names.push( param[0] );
  }

  return names;
}


function clearCookie( key ) {
    document.cookie = key + "=" + "xx; expires=Tue, 1-Jan-1980 00:00:00;";
}
