
/*
 * $Author: dbibbens $
 * $Revision: 1.25 $
 * $Date: 2010/12/16 22:38:17 $ 
 * $Source: /home/cvs/conversiontrac.com/local/lib/functions.js,v $
 */

function set_range(start, end)
{
  var select = null;

  var start_year = start.substr(0, 4);
  var start_month = start.substr(5, 2);
  var start_day = start.substr(8, 2);

  var end_year = end.substr(0, 4);
  var end_month = end.substr(5, 2);
  var end_day = end.substr(8, 2);

  select = document.getElementById("start_year");
  for(i = 0; i < select.options.length; i++) {
    if(select.options[i].value == start_year) {
      select.options[i].selected = true;
    }
  }

  select = document.getElementById("start_month");
  for(i = 0; i < select.options.length; i++) {
    if(select.options[i].value == start_month) {
      select.options[i].selected = true;
    }
  }

  select = document.getElementById("start_day");
  for(i = 0; i < select.options.length; i++) {
    if(select.options[i].value == start_day) {
      select.options[i].selected = true;
    }
  }

  select = document.getElementById("end_year");
  for(i = 0; i < select.options.length; i++) {
    if(select.options[i].value == end_year) {
      select.options[i].selected = true;
    }
  }

  select = document.getElementById("end_month");
  for(i = 0; i < select.options.length; i++) {
    if(select.options[i].value == end_month) {
      select.options[i].selected = true;
    }
  }

  select = document.getElementById("end_day");
  for(i = 0; i < select.options.length; i++) {
    if(select.options[i].value == end_day) {
      select.options[i].selected = true;
    }
  }
}

function do_today(uri, user_id, domain, aid) 
{ 
    if(domain == null) {
      document.location = uri + '?user-id=' + user_id;
  } else {
      document.location = uri + '?user-id=' + user_id + '&domain=' + domain + '&aid=' + aid;
  }
}

function do_range(uri, user_id, domain, aid) 
{
  var start_year = select = document.getElementById("start_year");
  var start_month = document.getElementById("start_month");
  var start_day = document.getElementById("start_day");

  var end_year = document.getElementById("end_year");
  var end_month = document.getElementById("end_month");
  var end_day = document.getElementById("end_day");


  var start = start_year.options[start_year.selectedIndex].value + '-' + start_month.options[start_month.selectedIndex].value + '-' + start_day.options[start_day.selectedIndex].value;

  var end = end_year.options[end_year.selectedIndex].value + '-' + end_month.options[end_month.selectedIndex].value + '-' + end_day.options[end_day.selectedIndex].value;

  document.location = uri + '?user-id='+ user_id + '&domain=' + domain + '&aid=' + aid + '&start=' + start + '&end=' + end;
}

function hide(pixel)
{
    var current = get_cookie("hidden");
    pixel = current + "," + pixel;
    set_cookie("hidden", pixel);    
    window.location.reload();
}

function hide_all(pixels)
{
    set_cookie("hidden", pixels);    
    window.location.reload();
}

function unhide(pixel)
{
    var current = get_cookie("hidden");
    pixel = current.replace(pixel, "");

    if(pixel.indexOf(",") == 0) {
	pixel = pixel.substr(1);
    }
    
    set_cookie("hidden", pixel);
    window.location.reload();
}

function get_cookie(name)
{
  var cookies = document.cookie.split(';');
  name = name + "=";
  for(var i = 0; i < cookies.length; i++) {
    var cookie = cookies[i];
    
    while(cookie.charAt(0) == ' ') {
      cookie = cookie.substring(1, cookie.length);
    }
    
    if(cookie.indexOf(name) == 0) {
      return cookie.substring(name.length, cookie.length);
    }
  }

  return false;
}

function set_cookie(name, value) 
{
    document.cookie = name + "=" + value + "; path=/";
}

