﻿Event.observe(window, "load", window_onLoad);

var currentTab = 'WebcastsTabMoreRecent';
var currentTabSwitcher = 'moreRecentWebcastsTabSwitcher';
var webcastIds = {     
            "988": {"inlineFormId": "1_988","img":"/images/webcasts/geek_webcast_watch-white.gif","link":"http://www.solarwinds.com/register/index.aspx?program=988&c=70150000000FbRk"},
            "957": {"inlineFormId": "1_957","img":"/images/webcasts/geek_webcast_watch-white.gif","link":"http://www.solarwinds.com/register/index.aspx?program=957&c=70150000000FIjA"},
            "952": {"inlineFormId": "1_952","img":"/images/webcasts/geek_webcast_watch-white.gif","link":"http://www.solarwinds.com/register/index.aspx?program=952&c=70150000000FDUG"},
            "944": {"inlineFormId": "1_944","img":"/images/webcasts/geek_webcast_watch-white.gif","link":"http://www.solarwinds.com/register/?Program=944&c=70150000000F6Cc"},
            "941": {"inlineFormId": "1_941","img":"/images/webcasts/geek_webcast_watch-white.gif","link":"http://www.solarwinds.com/register/?Program=941&c=70150000000F4HB"},
            "936": {"inlineFormId": "1_936","img":"/images/webcasts/geek_webcast_watch-white.gif","link":"http://www.solarwinds.com/register/?Program=936&c=70150000000ExSW"},
            "923": {"inlineFormId": "1_923","img":"/images/webcasts/geek_webcast_watch-white.gif","link":"http://www.solarwinds.com/register/index.aspx?program=923&c=70150000000EmIM"},
            "929": {"inlineFormId": "1_929","img":"/images/webcasts/geek_webcast_watch-white.gif","link":"http://www.solarwinds.com/register/index.aspx?Program=929&c=70150000000Ep6A"},
            "920": {"inlineFormId": "1_920","img":"/images/webcasts/geek_webcast_watch-white.gif","link":"http://www.solarwinds.com/register/?Program=920&c=70150000000Ejj5"},

            "814": {"inlineFormId": "2_814","img":"/images/webcasts/geek_webcast_watch-white.gif","link":"http://www.solarwinds.com/register/index.aspx?Program=814&c=70150000000Daqd"},
            "923": {"inlineFormId": "2_923","img":"/images/webcasts/geek_webcast_watch-white.gif","link":"http://www.solarwinds.com/register/index.aspx?program=923&c=70150000000EmIM"},
            "941": {"inlineFormId": "2_941","img":"/images/webcasts/geek_webcast_watch-white.gif","link":"http://www.solarwinds.com/register/?Program=941&c=70150000000F4HB"},
            "811": {"inlineFormId": "2_811","img":"/images/webcasts/geek_webcast_watch-white.gif","link":"http://www.solarwinds.com/register/index.aspx?Program=811&c=70150000000DZAL"},
            "936": {"inlineFormId": "2_936","img":"/images/webcasts/geek_webcast_watch-white.gif","link":"http://www.solarwinds.com/register/?Program=936&c=70150000000ExSW"},
            "824": {"inlineFormId": "2_824","img":"/images/webcasts/geek_webcast_watch-white.gif'","link":"http://www.solarwinds.com/register/index.aspx?Program=824&c=70150000000DhqJ"},

            "971": {"inlineFormId": "3_971","img":"/images/webcasts/geek_webcast_watch-white.gif","link":"http://www.solarwinds.com/register/index.aspx?program=971&c=70150000000FOue"},
            "967": {"inlineFormId": "3_967","img":"/images/webcasts/geek_webcast_watch-white.gif","link":"http://www.solarwinds.com/register/index.aspx?program=967&c=70150000000FMsK"},
            "957": {"inlineFormId": "3_957","img":"/images/webcasts/geek_webcast_watch-white.gif","link":"http://www.solarwinds.com/register/index.aspx?program=957&c=70150000000FIjA"},
            "952": {"inlineFormId": "3_952","img":"/images/webcasts/geek_webcast_watch-white.gif","link":"http://www.solarwinds.com/register/index.aspx?program=952&c=70150000000FDUG"},
            "944": {"inlineFormId": "3_944","img":"/images/webcasts/geek_webcast_watch-white.gif","link":"http://www.solarwinds.com/register/?Program=944&c=70150000000F6Cc"},
            "941": {"inlineFormId": "3_941","img":"/images/webcasts/geek_webcast_watch-white.gif","link":"http://www.solarwinds.com/register/?Program=941&c=70150000000F4HB"},
            "936": {"inlineFormId": "3_936","img":"/images/webcasts/geek_webcast_watch-white.gif","link":"http://www.solarwinds.com/register/?Program=936&c=70150000000ExSW"},
            "923": {"inlineFormId": "3_923","img":"/images/webcasts/geek_webcast_watch-white.gif","link":"http://www.solarwinds.com/register/index.aspx?program=923&c=70150000000EmIM"},
            "929": {"inlineFormId": "3_929","img":"/images/webcasts/geek_webcast_watch-white.gif","link":"http://www.solarwinds.com/register/index.aspx?Program=929&c=70150000000Ep6A"},
            "920": {"inlineFormId": "3_920","img":"/images/webcasts/geek_webcast_watch-white.gif","link":"http://www.solarwinds.com/register/?Program=920&c=70150000000Ejj5"},
            "914": {"inlineFormId": "3_914","img":"/images/webcasts/geek_webcast_watch-white.gif","link":"http://www.solarwinds.com/register/?Program=914&c=70150000000Eexb"},
            "907": {"inlineFormId": "3_907","img":"/images/webcasts/geek_webcast_watch-white.gif","link":"http://www.solarwinds.com/register/index.aspx?Program=907&c=70150000000EWuG"},
            "900": {"inlineFormId": "3_900","img":"/images/webcasts/geek_webcast_watch-white.gif","link":"http://www.solarwinds.com/register/index.aspx?Program=900&c=70150000000EPYJ"},
            "887": {"inlineFormId": "3_887","img":"/images/webcasts/geek_webcast_watch-white.gif","link":"http://www.solarwinds.com/register/index.aspx?Program=887&c=70150000000EJJn"},
            "871": {"inlineFormId": "3_871","img":"/images/webcasts/geek_webcast_watch-white.gif","link":"http://www.solarwinds.com/register/index.aspx?Program=871&c=70150000000ED0x"},
            "863": {"inlineFormId": "3_863","img":"/images/webcasts/geek_webcast_watch-white.gif","link":"http://www.solarwinds.com/register/index.aspx?Program=863&c=70150000000E2No"},
            "861": {"inlineFormId": "3_861","img":"/images/webcasts/geek_webcast_watch-white.gif","link":"http://www.solarwinds.com/register/index.aspx?Program=861&c=70150000000Dyeo"},
            "859": {"inlineFormId": "3_859","img":"/images/webcasts/geek_webcast_watch-white.gif","link":"http://www.solarwinds.com/register/index.aspx?Program=859&c=70150000000DuAi"},
            "851": {"inlineFormId": "3_851","img":"/images/webcasts/geek_webcast_watch-white.gif","link":"http://www.solarwinds.com/register/index.aspx?Program=851&c=70150000000DpGD"},
            "848": {"inlineFormId": "3_848","img":"/images/webcasts/geek_webcast_watch-white.gif","link":"http://www.solarwinds.com/register/index.aspx?program=848&c=70150000000Dmwh"},
            "824": {"inlineFormId": "3_824","img":"/images/webcasts/geek_webcast_watch-white.gif","link":"http://www.solarwinds.com/register/index.aspx?Program=824&c=70150000000DhqJ"},
            "819": {"inlineFormId": "3_819","img":"/images/webcasts/geek_webcast_watch-white.gif","link":"http://www.solarwinds.com/register/index.aspx?Program=819&c=70150000000DdVW"},
            "814": {"inlineFormId": "3_814","img":"/images/webcasts/geek_webcast_watch-white.gif","link":"http://www.solarwinds.com/register/index.aspx?Program=814&c=70150000000Daqd"},
            "811": {"inlineFormId": "3_811","img":"/images/webcasts/geek_webcast_watch-white.gif","link":"http://www.solarwinds.com/register/index.aspx?Program=811&c=70150000000DZAL"},
            "805": {"inlineFormId": "3_805","img":"/images/webcasts/geek_webcast_watch-white.gif","link":"http://www.solarwinds.com/register/index.aspx?Program=805&c=70150000000DXmc"},
            "803": {"inlineFormId": "3_803","img":"/images/webcasts/geek_webcast_watch-white.gif","link":"http://www.solarwinds.com/register/index.aspx?Program=803&c=70150000000DUdR"},
            "804": {"inlineFormId": "3_804","img":"/images/webcasts/geek_webcast_watch-white.gif","link":"http://www.solarwinds.com/register/index.aspx?Program=804&c=70150000000DUdW"},
            "801": {"inlineFormId": "3_801","img":"/images/webcasts/geek_webcast_watch-white.gif","link":"http://www.solarwinds.com/register/index.aspx?Program=801&c=70150000000DBZi"},
            "802": {"inlineFormId": "3_802","img":"/images/webcasts/geek_webcast_watch-white.gif","link":"http://www.solarwinds.com/register/index.aspx?Program=802&c=70150000000DNo5"}
};
    

function window_onLoad()
{  
    $("container").removeClassName("Hidden");
    var bottomWebcastsArea = $("geekWebcastsBottomArea");
    
    var currentElement = bottomWebcastsArea;
    while(true)
    {
        try
        {                 
            //get View more link
            var viewMoreLink = currentElement.down("a.geekWebcastViewMore");
            if (viewMoreLink)
            {
                //if exists - add the event
                Event.observe(viewMoreLink, "click", ShowMoreInfo);
                currentElement = viewMoreLink;
            }
            else
            {
                // if not exist - just move to nearest div to not break the logic
                currentElement = currentElement.down("div");
            }
            //find next webcast block
            newBlock = currentElement.up("div.geekWebcastBlock").next("div.geekWebcastBlock");
            if (!newBlock)
            {
                //if not exists - move to the second tab
                newBlock = currentElement.up("div.geekWebcastBlock").up("div.geekBrowseWebcastsContent").next("div.geekBrowseWebcastsContent").down("div.geekWebcastBlock");
                //if not exists - all tabs were processed
                if (!newBlock)
                    break;
            }
            currentElement = newBlock;          
        }
        catch(exception)
        {
            break;
        }   
    }   
     
    var webcastId = queryString('webcastId');
    if (webcastId!="")
    {
     var inlineFormId_ = webcastIds[webcastId].inlineFormId;
     if (inlineFormId_.indexOf("2_")>=0)
        switchTab("mostPopularWebcastsTabSwitcher", "WebcastsTabMostPopular");
     if (inlineFormId_.indexOf("3_")>=0)
        switchTab("allWebcastsTabSwitcher", "WebcastsTabAllWebcasts");
     show_inline_registration_webcasts(webcastId, inlineFormId_, webcastIds[webcastId].img, webcastIds[webcastId].link);

     document.getElementById("modalRegformContent"+inlineFormId_).scrollIntoView();

    }
}

function ShowMoreInfo()
{
    var element = this;
    var hiddenContent = element.up("p").next("div.geekWebcastLongDesc");
    
    hiddenContent.removeClassName("Hidden");
    new Effect.BlindDown(hiddenContent, { duration: 0.4})
    Event.observe(element, "click", HideMoreInfo);
    Event.stopObserving(element, "click",ShowMoreInfo); 
    element.innerHTML = "View Less &raquo;";
}

function HideMoreInfo()
{
    var element = this;
    
    var hiddenContent = element.up("p").next("div.geekWebcastLongDesc");
    new Effect.BlindUp(hiddenContent, {afterFinish: function (obj) { hiddenContent.addClassName("Hidden"); }, duration: 0.4})
    Event.observe(element, "click", ShowMoreInfo);
    Event.stopObserving(element, "click",HideMoreInfo);
    element.innerHTML = "View More &raquo;";
}

function switchTab(tabswitcherId, tabId)
{
    if (tabId != currentTab)
    {
        $(currentTabSwitcher).addClassName('inactiveTab');
        $(currentTabSwitcher).removeClassName('activeTab');
        
        $(tabswitcherId).addClassName('activeTab');        
        $(tabswitcherId).removeClassName('inactiveTab');
        
        $(currentTab).addClassName('Hidden');
        $(tabId).removeClassName('Hidden');
        
        currentTab = tabId;
        currentTabSwitcher = tabswitcherId;
    }
}

function queryString(parameter) { 
  var loc = location.search.substring(1, location.search.length);
  var param_value = false;

  var params = loc.split("&");
  for (i=0; i<params.length;i++) {
      param_name = params[i].substring(0,params[i].indexOf('='));
      if (param_name.toLowerCase() == parameter.toLowerCase()) {
          param_value = params[i].substring(params[i].indexOf('=')+1)
      }
  }
  if (param_value) {
      return param_value;
  }
  else {
      return ""; //Here determine return if no parameter is found
  }
}
    