function logProfileWidget(widget) {
  
  var status = 'success';
  
  new Ajax.Request('/pfwg/profile_widgets.jsp', {
    method: 'post',
    parameters : {
      widget: widget
    },
    onComplete: function() {
      $('status').update(status);
    },
    onFailure: function() {
      status = 'fail'
    }
  });
}

function createCookie(name, value, domain) {
  document.cookie = name + "=" + value + '; domain=' + domain + '; path=/';
}

function getCookie(name) {
  var cookie = " " + document.cookie;
  var search = " " + name + "=";
  var setStr = null;
  var offset = 0;
  var end = 0;
  if (cookie.length > 0) {
    offset = cookie.indexOf(search);
    if (offset != -1) {
      offset += search.length;
      end = cookie.indexOf(";", offset)
      if (end == -1) {
        end = cookie.length;
      }
      setStr = unescape(cookie.substring(offset, end));
    }
  }
  return(setStr);
}

function setProfileCookie(link) {
  var usernameCookieName = "harpo-loggedin";
  var domain = ".oprah.com";

  if (getCookie(usernameCookieName)) {
    new Ajax.Request('/pfwg/profile_data.jsp', {
      method: 'get',
      onComplete: function(transport) {
        var profile = eval("("+transport.responseText+")");
        createCookie('ocomuser', profile.firstname + ':' + profile.lastname + ':' + profile.email + ':' + profile.birthYear, domain);
        window.location = link.href;
      },
      onFailure: function() {
        window.location = link.href;
      }
    })
  } else {
    window.location = link.href;
  }
}

