function ga(o,e) {
  var a,f,g,h,p,r,t; 
  if (document.getElementById) {
    a=o.id.substring(1); 
	p = "";
    r = "";
    g = e.target;
    if (g) { 
      t = g.id;
      f = g.parentNode;
      if (f) {
        p = f.id;
        h = f.parentNode;
        if (h) { 
          r = h.id;
        }
      }
    } else {
      h = e.srcElement;
      f = h.parentNode;
      if (f) { 
        p = f.id;
      }
      t = h.id;
    }
    if (t == a || p == a || r == a) {
      return true;
    }
    location.href = document.getElementById(a).href
  }
}


function show_date_select()
{
	document.getElementById("select_date").style.visibility = "visible";
	document.getElementById("select_date").style.display = "block";
}







var LOADING_DIV_ID = 'loadingDiv';
var TOOLTIP_IFRAME_ID = 'tooltipIframe';

var AGT_TAB_COOKIE_NAME = "AWFE_AG_TAB";

// The set of tabs to show.  Use AGT_setTabNames to set.
var AGT_ADGROUP_TABS;
function GetCookie(name) {
  var nameeq = name + "=";
  var cookie = String(document.cookie);
  for (var pos = -1; (pos = cookie.indexOf(nameeq, pos + 1)) >= 0;) {
    var i = pos;
    // walk back along string skipping whitespace and looking for a ; before
    // the name to make sure that we don't match cookies whose name contains
    // the given name as a suffix.
    while (--i >= 0) {
      var ch = cookie.charAt(i);
      if (ch == ';') {
        i = -1;  // indicate success
        break;
      } else if (' \t'.indexOf(ch) < 0) {
        break;
      }
    }
    if (-1 === i) {  // first cookie in the string or we found a ;
      var end = cookie.indexOf(';', pos);
      if (end < 0) { end = cookie.length; }
      return cookie.substring(pos + nameeq.length, end);
    }
  }
  return "";
}


function urchinTracker(page) {
 /*if (_udl.protocol=="file:") return;
 if (_uff && (!page || page=="")) return;
 var a,b,c,xx,v,z,k,x="",s="",f=0;
 var nx=" expires=Sun, 18 Jan 2038 00:00:00 GMT;";
 var dc=_ubd.cookie;
 _udh=_uDomain();
 if (!_uVG()) return;
 _uu=Math.round(Math.random()*2147483647);
 _udt=new Date();
 _ust=Math.round(_udt.getTime()/1000);
 a=dc.indexOf("__utma="+_udh);
 b=dc.indexOf("__utmb="+_udh);
 c=dc.indexOf("__utmc="+_udh);
 if (_udn && _udn!="") { _udo=" domain="+_udn+";"; }
 if (_utimeout && _utimeout!="") {
  x=new Date(_udt.getTime()+(_utimeout*1000));
  x=" expires="+x.toGMTString()+";";
 }
 if (_ulink) {
  if (_uanchor && _udlh && _udlh!="") s=_udlh+"&";
  s+=_udl.search;
  if(s && s!="" && s.indexOf("__utma=")>=0) {
   if (!(_uIN(a=_uGC(s,"__utma=","&")))) a="-";
   if (!(_uIN(b=_uGC(s,"__utmb=","&")))) b="-";
   if (!(_uIN(c=_uGC(s,"__utmc=","&")))) c="-";
   v=_uGC(s,"__utmv=","&");
   z=_uGC(s,"__utmz=","&");
   k=_uGC(s,"__utmk=","&");
   xx=_uGC(s,"__utmx=","&");
   if ((k*1) != ((_uHash(a+b+c+xx+z+v)*1)+(_udh*1))) {_ubl=1;a="-";b="-";c="-";xx="-";z="-";v="-";}
   if (a!="-" && b!="-" && c!="-") f=1;
   else if(a!="-") f=2;
  }
 }
 if(f==1) {
  _ubd.cookie="__utma="+a+"; path="+_utcp+";"+nx+_udo;
  _ubd.cookie="__utmb="+b+"; path="+_utcp+";"+x+_udo;
  _ubd.cookie="__utmc="+c+"; path="+_utcp+";"+_udo;
 } else if (f==2) {
  a=_uFixA(s,"&",_ust);
  _ubd.cookie="__utma="+a+"; path="+_utcp+";"+nx+_udo;
  _ubd.cookie="__utmb="+_udh+"; path="+_utcp+";"+x+_udo;
  _ubd.cookie="__utmc="+_udh+"; path="+_utcp+";"+_udo;
  _ufns=1;
 } else if (a>=0 && b>=0 && c>=0) {
  _ubd.cookie="__utmb="+_udh+"; path="+_utcp+";"+x+_udo;
 } else {
  if (a>=0) a=_uFixA(_ubd.cookie,";",_ust);
  else a=_udh+"."+_uu+"."+_ust+"."+_ust+"."+_ust+".1";
  _ubd.cookie="__utma="+a+"; path="+_utcp+";"+nx+_udo;
  _ubd.cookie="__utmb="+_udh+"; path="+_utcp+";"+x+_udo;
  _ubd.cookie="__utmc="+_udh+"; path="+_utcp+";"+_udo;
  _ufns=1;
 }
 if (_ulink && xx && xx!="" && xx!="-") {
   xx=_uUES(xx);
   if (xx.indexOf(";")==-1) _ubd.cookie="__utmx="+xx+"; path="+_utcp+";"+nx+_udo;
 }
 if (_ulink && v && v!="" && v!="-") {
  v=_uUES(v);
  if (v.indexOf(";")==-1) _ubd.cookie="__utmv="+v+"; path="+_utcp+";"+nx+_udo;
 }
 _uInfo(page);
 _ufns=0;
 _ufno=0;
 if (!page || page=="") _uff=1;
 */
}

/**
* Call this to override the default name for the tab cookie
*/
function AGT_setTabCookieName(name) {
  AGT_TAB_COOKIE_NAME = name;
}

/**
 * Returns the user-specified tab cookie name if it exists, else the default
 */
function AGT_getTabCookieName() {
  return AGT_TAB_COOKIE_NAME;
}

/**
* Call this method and pass in an array of strings to override the default
* tab names.  The first string in the array will be the default tab.
* See AdStatusHeader for example usage.
*/
function AGT_setTabNames(newTabArray) {
  AGT_ADGROUP_TABS = newTabArray;
}

/**
* Returns the user-specified tab names if they exist, else the default set
*/

function AGT_getTabNames() {
  return AGT_ADGROUP_TABS;
}

/**
* Saves raw value in cookie. Expires in 90 days.
*/
function SetCookie(name, value, opt_max_age, opt_path, opt_domain) {

  value = '' + value;
  AssertTrue((typeof name == 'string' &&
              typeof value == 'string' &&
              !name.match(ILLEGAL_COOKIE_CHARS_RE) &&
              !value.match(ILLEGAL_COOKIE_CHARS_RE)),
             'trying to set an invalid cookie');

  if (!IsDefined(opt_max_age)) opt_max_age = -1;
  if (!IsDefined(opt_path)) opt_path = '/';
  if (!IsDefined(opt_domain)) opt_domain = null;

  var domain_str = (opt_domain == null) ? '' : ';domain=' + opt_domain;
  var path_str = (opt_path == null) ? '' : ';path=' + opt_path;

  var expires_str;

  // Case 1: Set a session cookie.
  if (opt_max_age < 0) {
    expires_str = '';

  // Case 2: Expire the cookie.
  // Note: We don't tell people about this option in the function doc because
  // we prefer people to use ExpireCookie() to expire cookies.
  } else if (opt_max_age == 0) {
    // Note: Don't use Jan 1, 1970 for date because NS 4.76 will try to convert
    // it to local time, and if the local time is before Jan 1, 1970, then the
    // browser will ignore the Expires attribute altogether.
    var date = new Date(1970, 1 /*Feb*/, 1);  // Feb 1, 1970
    expires_str = ';expires=' + date.toUTCString();

  // Case 3: Set a persistent cookie.
  } else {
    var date = new Date( Now() + opt_max_age * 1000 );
    expires_str = ';expires=' + date.toUTCString();
  }

  document.cookie = name + '=' + value + domain_str + path_str + expires_str;
}
function AGT_saveTabCookie(value) {
  var expirationSecs = (60 * 60 * 24 * 90); // 90 days.
  //SetCookie(AGT_getTabCookieName(), encodeURIComponent(value),
     // expirationSecs, null, null);
}

/**
 * Parses cookie value into a map.
 */
function AGT_parseCookieValue(cookieValue) {
  var ret = {};
  var versionValue = cookieValue.split(":");
  var pages = versionValue[1].split("&");

  for (var i = 0; i < pages.length; ++i) {
    var pairs = pages[i].split("=");
    ret[pairs[0]] = pairs[1];
  }

  return ret;
}

/**
 * Parses and returns current sticky status for the adgroup page.
 *
 * @param index option requested.
 */
function AGT_parseStatusFromCookie(index) {

  var ret = null;
  var cookieValue = decodeURIComponent(GetCookie(AGT_getTabCookieName()));

  if (cookieValue != "") {
    var result = AGT_parseCookieValue(cookieValue);
    if (result.adgroup != null) {
      ret = result.adgroup.split("|")[index];
    }
  }

  return ret;
}

/**
 * Parses and returns current sticky status for the adgroup page if it exists.
 * Otherwise returns defaultValue.
 *
 * @param index option requested.
 * @defualtValue default value if cookie has not yet been set.
 */
function AGT_getStatusFromCookieOrDefault(index, defaultValue) {

  var status = AGT_parseStatusFromCookie(index);

  if (status == null) {
   status = defaultValue;
  }

  return status;
}

/**
 * Gets current tab selected. First component o the cookie value.
 */
function AGT_getCurrentTab() {
  var tabDefault = "no_tab_found";

  return AGT_getStatusFromCookieOrDefault(0, tabDefault);
}

/**
 * Gets zip state. Second component of the cookie value.
 */
function AGT_getCurrentZipState() {
  var zipStateDefault = "true";

  return AGT_getStatusFromCookieOrDefault(1, zipStateDefault);
}

/**
 * Gets date picker state. Third component of the cookie value.
 */
function AGT_getDatePickerState() {
  var pickerStateDefault = "close";

  return AGT_getStatusFromCookieOrDefault(2, pickerStateDefault);
}

/**
 * Gets settings state. Fourth component of the cookie value.
 */
function AGT_getSettingsState() {
  var settingsStateDefault = "close";

  return AGT_getStatusFromCookieOrDefault(3, settingsStateDefault);
}

/**
* Formats cookie values.
* FORMAT : See above.
*/
function AGT_formatCookieValues(tab, zipState, datePickerState, settingsState) {

  // Only one tab for the moment.
  var cookieValue = "v1:adgroup=" + tab + "|" + zipState + "|" + datePickerState
      + "|" + settingsState;
  return cookieValue;
}

/**
 * Saves 'tab' in cookie. When a tab is selected the zip state is "true".
 * Keeps track of current date picker and settings states too.
 */
function AGT_saveCurrentTab(tab) {
  var pickerState = AGT_getDatePickerState();
  var settingsState = AGT_getSettingsState();
  var cookieValue = AGT_formatCookieValues(tab, "true",
                                           pickerState, settingsState);
  AGT_saveTabCookie(cookieValue);
}

/**
 * Saves 'zip' state in the cookie. Keeps track of currently selected tab, date
 * picker and settings states too.
 */
function AGT_saveZipState(state) {
  var currentTab = AGT_getCurrentTab();
  var pickerState = AGT_getDatePickerState();
  var settingsState = AGT_getSettingsState();
  var cookieValue = AGT_formatCookieValues(currentTab, state,
                                           pickerState, settingsState);
  AGT_saveTabCookie(cookieValue);
}

/**
 * Saves 'date picker' state in the cookie. Keeps track of currently selected
 * tab, zip and settings states too.
 */
function AGT_saveDatePickerState(state) {
  var currentTab = AGT_getCurrentTab();
  var zipState = AGT_getCurrentZipState();
  var settingsState = AGT_getSettingsState();
  var cookieValue = AGT_formatCookieValues(currentTab, zipState,
                                           state, settingsState);
  AGT_saveTabCookie(cookieValue);
}

/**
 * Saves 'settings' state in the cookie. Keeps track of currently selected tab,
 * zip and date picker states too.
 */
function AGT_saveSettingsState(state) {
  var currentTab = AGT_getCurrentTab();
  var zipState = AGT_getCurrentZipState();
  var pickerState = AGT_getDatePickerState();
  var cookieValue = AGT_formatCookieValues(currentTab, zipState,
                                           pickerState, state);
  AGT_saveTabCookie(cookieValue);
}

/**
 * Reads the cookie and switches to that tab. Called when page is being loaded.
 */
function AGT_setAdGroupTab() {

  var secondaryTab = document.getElementById("subTabs2");

  if (secondaryTab) { // Verify there are secondary tabs.
    var defaultTab = AGT_getTabNames()[0]; // Default = first tab in array
    var currentTab = AGT_getCurrentTab();

    if (currentTab == "no_tab_found" || !AGT_isTabPresentOnPage(currentTab)) {
      currentTab = defaultTab;
      AGT_saveCurrentTab(currentTab); // First time. Set cookie to default.
    }

    flipTabs("secondary", currentTab); // Function in 'TabItem.gxp'
  }
}

function AGT_isTabPresentOnPage(tabId) {
  return document.getElementById("ttab" + tabId);
}

/**
* Callback function called by date picker zippedSection module. Set the
* cookie value appropriately.
*/
function AGT_setDatePickerState(id, isOpen) {

  var secondaryTab = document.getElementById("subTabs2");

  if (secondaryTab) { // Verify there are secondary tabs.
    var datePickerState = isOpen ? "open" : "close";
    AGT_saveDatePickerState(datePickerState);
  }
}

/**
 * Function called by showSettings/hideSettings link. Set the
 * cookie value appropriately.
 */
function AGT_setSettingsState(id) {

  var elem = document.getElementById(id);

  if (elem) { // Verify that the element exists
    var settingsState = (elem.style.display == "block") ? "open" : "close";
    AGT_saveSettingsState(settingsState);
  }
}


function changeObjectDisplay(objectId, newDisplay) {
  // get a reference to the cross-browser style object and make sure the object exists
  var styleObject = getStyleObject(objectId);
  if(styleObject) {
    styleObject.display = newDisplay;
    return true;
  } else {
    // we couldn't find the object, so we can't change its visibility
    return false;
  }
}

/** 
 * Sets the style.display property of the given object to either display or
 * un-display the object.  Displaying the object means the object will take
 * up its allotted space in its container; undisplaying means it will take up
 * no space.
 */
function setObjectDisplay(objectId, showObject) {
  return changeObjectDisplay(objectId, showObject ? '' : 'none');
}

function getStyleObject(objectId) {
  // cross-browser function to get an object's style object given its id
  if(document.getElementById && document.getElementById(objectId)) {
    // W3C DOM
    return document.getElementById(objectId).style;
  } else if (document.all && document.all(objectId)) {
    // MSIE 4 DOM
    return document.all(objectId).style;
  } else if (document.layers && document.layers[objectId]) {
    // NN 4 DOM.. note: this won't find nested layers
    return document.layers[objectId];
  } else {
    return false;
  }
}
function isBoolean(a) {
    return typeof a == 'boolean';
}

function isString(a) {
    return typeof a == 'string';
}

function ron(myId) {
  rowRollover(myId, 1);
}

function roff(myId) {
  rowRollover(myId, 0);
}

function isAllSelected(f) {
  for (var i=0; i < f.elements.length; i++) {
	var box = f.elements[i];
	if (isElemBox(box) && box.checked == false) {
	  return false;
	}
  }
  return true;
}

function toggleRow(element) {
  rowToggle(element.value);
}

function rowToggle(myId) {
  var row = document.getElementById('tr_' + myId);
  var box = document.getElementById('box_' + myId);
  var f = box.form;
  if (box.checked == false) {
	rowSelect(row, box);
	f.toggleAll.checked = isAllSelected(f);
  } else {
	rowUnselect(row, box);
	f.toggleAll.checked = false;
  }
}

function rowToggleAll(tabox) {
  var f = tabox.form;
  for (var i=0; i < f.elements.length; i++) {
	var box = f.elements[i];
	if (isElemBox(box) && box.checked != tabox.checked) {
	  var row = getRowFromBox(box);
	  if (tabox.checked) {
		rowSelect(row, box);
	  } else {
		rowUnselect(row, box);
	  }
	}
  }
}

function initRolloverTables() {
  for (var i=0; i < document.forms.length; i++) {
	var f = document.forms[i];
	if (f.className == 'rollover' && f.toggleAll) {
	  for (var j=0; j < f.elements.length; j++) {
		var box = f.elements[j];
		if (isElemBox(box) && box.checked == true) {
		  var row = getRowFromBox(box);
		  rowUpdateBg(row, box);
		}
	  }
	  f.toggleAll.checked = isAllSelected(f);
	}
  }
}

function rowUpdateBg(row, box) {
  if (box && box.checked) {
	row.style.backgroundColor = "#DDE4F2";
  } else {
	row.style.backgroundColor = (row == rowWithMouse) ? '#FFFFD9' : '#FFFFFF';
  }
}


var rolloverWarning = null;
function beforeRolloverSubmit(f, msg) {
  var numElemBoxes = 0;
  for (var i=0; i < f.elements.length; i++) {
	var box = f.elements[i];
	if (isElemBox(box)) {
	  numElemBoxes++;
	  if (box.checked == true) {
		if (rolloverWarning) {
		  var r = confirm(rolloverWarning);
		  rolloverWarning = null;
		  return r;
		}
		return true;
	  }
	}
  }
  if (numElemBoxes == 1) {
	<!-- If the table has only one row, automatically selects the row. -->
	  f.toggleAll.checked = true;
	rowToggleAll(f.toggleAll);
	if (rolloverWarning) {
	  var r = confirm(rolloverWarning);
	  rolloverWarning = null;
	  return r;
	}        
	return true;
  }
  alert(msg);
  rolloverWarning = null;
  return false;
}


function rowRollover(myId, isInRow) {
  // myId is our own integer id, not the DOM id
  // isInRow is 1 for onmouseover, 0 for onmouseout
  var row = document.getElementById('tr_' + myId);
  var box = document.getElementById('box_' + myId);
  rowWithMouse = (isInRow) ? row : null;
  rowUpdateBg(row, box);
}

function changeObjectVisibility(objectId, newVisibilityParam) {

  if (isBoolean (newVisibilityParam)) {
    newVisibility = newVisibilityParam ? 'visible' : 'hidden';
  } else if (isString (newVisibilityParam)) {
    newVisibility = newVisibilityParam;
  } else {
    throw "Illegal newVisibilityParam " + newVisibilityParam;
  }
  // get a reference to the cross-browser style object and make sure the object exists
  var styleObject = getStyleObject(objectId);
  if(styleObject) {
    styleObject.visibility = newVisibility;
    return true;
  } else {
    // we couldn't find the object, so we can't change its visibility
    return false;
  }
}


function TooltipLoader(baseUrl) {
  // Base URL.
  this.baseUrl = baseUrl;

  // Elements for which an info request has been sent but no response received.
  this.waitingForResponse = {};
  // Elements for which content has already been loaded.
  this.contentLoaded = {};
  // Elements which are currently being touched.
  this.currentElement = {};
  // Request information.
  this.xmlHttpRequest = new XMLHttpRequest();
  // CSS style.display values for elements when they are visible.
  this.displayStyles = {};

  // Delay before tooltip is displayed on loadContent call.
  this.loadTimeout = 1000;
  // Delay before tooltip is hidden on hideContent call.
  this.hideTimeout = 300;

  // z-index of div.
  this.divZIndex = 100;

  // Div to be displayed when tooltip should be visible but the data is not yet
  // loaded.
  this.setLoadingDiv(LOADING_DIV_ID);
  // iframe to be displayed behind tooltip (needed for internet explorer).
  this.setTooltipIframe(TOOLTIP_IFRAME_ID);

  // Function to clear the loaded elements.
  this.resetContentCache = function() {
    this.contentLoaded = {};
  }
}

TooltipLoader.prototype.setLoadingDiv = function(loadingDivId) {
  this.loadingDiv = document.getElementById(loadingDivId);
}

TooltipLoader.prototype.setTooltipIframe = function(tooltipIframeId) {
  this.tooltipIframe = document.getElementById(tooltipIframeId);
}
