function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function extendOnClick(el, func) {
  var oldonclick = el.onclick;
  if (typeof el.onclick != 'function') {
    el.onclick = func;
  } else {
    el.onclick = function(evt) {
      oldonclick(evt, this);
      func(evt,this);
      return false;
    }
  }
}

//************************************
//functions to bring up external pop ups
//************************************
window.onload = function() 
{
  if (!document.getElementsByTagName) return false;
  var links = document.getElementsByTagName("a");
  for (var i=0; i<links.length; i++) 
  {
    var linkRelAttribute = links[i].getAttribute("rel");    
    var linkClassAttribute = links[i].className;
    if(linkRelAttribute)
    {
        var parsedLinkAttribute = linkRelAttribute.split(" ");
        for(var j=0; j<parsedLinkAttribute.length; j++)
        {
            if ( parsedLinkAttribute[j] == "player") 
            {
                links[i].onclick = function() 
                {
                    showPlayer(this.getAttribute("href"));
                    return false;
                }
             }
             else
             {
                if (parsedLinkAttribute[j] == "external") 
                {
                  links[i].onclick = function(evt, el) 
                  {
                    if (el == null)
                        el = this;
                    href = el.getAttribute("href");
                    popUp(href);
                    return false;
                  }
                }
             }
         }
     } 
     
     if(linkClassAttribute) 
     {
        var parsedClassAttribute = linkClassAttribute.split(" ");
        for(var j=0; j<parsedClassAttribute.length; j++)
        {
            if ( parsedClassAttribute[j] == "promotion")
            { 
                extendOnClick(links[i], getPromotionOmnitureVars);
            }

            if ( parsedClassAttribute[j] == "order")
            {
                extendOnClick(links[i], getOrderOmnitureVars);
            }
        }       
     }
  } 
}

 
function getPromotionOmnitureVars(evt, link)
{
    if (link == null)
          link = this;
          
    var domain = link.getAttribute("href");
    domain = domain.substring(domain.search("//")+2,domain.length);
    if (domain.search("/") == -1)
    {
        domain = domain.substring(0,domain.length);
    }
    else
    {    
        domain = domain.substring(0,domain.search("/"));
    }
    
    var parsedClassAttribute = link.className.split(" ");
    var uniqueId = parsedClassAttribute[0];


    //s.pageName is passed in through omniture code. This is assuming
    //that omniture code exists on every page. It is currently inject thru treatments
    //hence currently omniture code does exist in every page. 
    if (isOmnitureExists())
    {
        s.linkTrackVars="eVar6,eVar13,eVar14,events";
        s.eVar6 = link.getAttribute("href");
        s.eVar13 = uniqueId;
        s.eVar14 = domain;
        s.linkTrackEvents = "event15";
        s.events = s.apl(s.events,"event15",",",2);
    }     
}

function getOrderOmnitureVars(evt, link)
{
    if (link == null)
          link = this;
    
    var domain = link.getAttribute("href");
    domain = domain.substring(domain.search("//")+2,domain.length);
    if (domain.search("/") == -1)
    {
        domain = domain.substring(0,domain.length);
    }
    else
    {    
        domain = domain.substring(0,domain.search("/"));
    }
    
    var parsedClassAttribute = link.className.split(" ");
    var uniqueId = parsedClassAttribute[0];
    
   //s.pageName is passed in through omniture code. This is assuming
    //that omniture code exists on every page. It is currently inject thru treatments
    //hence currently omniture code does exist in every page. 
    if (isOmnitureExists())
    {
        s.linkTrackVars="eVar6,eVar13,eVar14,events";
        s.eVar6 = link.getAttribute("href");
        s.eVar13 = uniqueId;
        s.eVar14 = domain;
        s.linkTrackEvents = "event16";
        s.events = s.apl(s.events,"event16",",",2);
    }
}
 
function isOmnitureExists()
{
    //s.pageName is passed in through omniture code. This is assuming
    //that omniture code exists on every page. It is currently inject thru treatments
    //hence currently omniture code does exist in every page. 
    if (s != null && (s.pageName.length != 0))
        return true;
    else return false;
}
 
function popUp(winURL) {
  window.open(winURL,'_blank');
  return false;
}

//*********************
function showPlayer(pURL) {
//*********************
displayWindow(pURL,"Player",620,460,"directories=0,location=0,menubar=0,resizable=0,scrollbars=0,status=0,titlebar=0,toolbar=0");
return false;
}

//****************************************
//End of function
//****************************************


//*********************
function displayWindow(theURL,winName,width,height,features) { //v3.1
//*********************
  var window_width = width;
  var window_height = height;
  var newfeatures= features;
  var window_top = (screen.height-window_height)/2;
  var window_left = (screen.width-window_width)/2;
  newWindow=window.open(''+ theURL + '',''+ winName + '','width=' + window_width + ',height=' + window_height + ',top=' + window_top + ',left=' + window_left + ','+ newfeatures + '');
  newWindow.focus();
}

//*********************
function MM_openBrWindow(theURL,winName,features) { //v2.0
//*********************
  window.open(theURL,winName,features);
}

//*********************
function mm_openbrwindow(theURL,winName,features) { //v2.0
//*********************
  window.open(theURL,winName,features);
}

//***************************************************
function popFull(url,name){
//***************************************************
var w = 480, h = 340;

if (document.all || document.layers) {
   w = screen.availWidth;
   h = screen.availHeight;
}else{
    w = screen.width;
    h = screen.height;
}

var url;
var popW;
var popH;

window.open(url,name,'width=' + w + ',height=' + h + ',top=0,left=0');
}



