﻿//Event handler to handle a click on a v-lab link.
function onVlabMouseDown(sender, eventArgs)
{
    switch(sender.name)
    {
        case "ts_btnPlayNow":           // Attack Defender
            // Call Javascript will record metric (found in default.aspx)
            PerformAtlasMetric("http://switch.atdmt.com/action/mrtyou_FY08HSWVlabsVendGameAttackDefFinal_10");

            openHSWWindow("http://go.microsoft.com/?linkid=8032795");
            break;
        case "ts_btnViewNow":           // Top Scores
            // Call Javascript will record metric (found in default.aspx)
            PerformAtlasMetric("http://switch.atdmt.com/action/mrtyou_FY08HSWVlabsVendGameHighScoreFinal_10");

            openHSWWindow("http://go.microsoft.com/?linkid=8032794");
            break;
        case "C2_vlab_body_link1":       // Cross-Site Scripting (XSS)
            // Call Javascript will record metric (found in default.aspx)
            PerformAtlasMetric("http://switch.atdmt.com/action/mrtyou_FY08HSWVlabsVendXSSFinal_10");

            openHSWWindow("http://go.microsoft.com/?linkid=8032789");
            break;
        case "C2_vlab_body_link2":      // SQL Injection
            // Call Javascript will record metric (found in default.aspx)
            PerformAtlasMetric("http://switch.atdmt.com/action/mrtyou_FY08HSWVlabsVendSQLFinal_10");

            openHSWWindow("http://go.microsoft.com/?linkid=8032790");
            break;
        case "C2_vlab_body_link3":      // Insecure Direct Object Reference
            // Call Javascript will record metric (found in default.aspx)
            PerformAtlasMetric("http://switch.atdmt.com/action/mrtyou_FY08HSWVlabsVendIDORFinal_10");

            openHSWWindow("http://go.microsoft.com/?linkid=8032793");
            break;
        case "C2_vlab_body_link4":      // One-Click Attack
            // Call Javascript will record metric (found in default.aspx)
            PerformAtlasMetric("http://switch.atdmt.com/action/mrtyou_FY08HSWVlabsVendOneClickFinal_10");

            openHSWWindow("http://go.microsoft.com/?linkid=8032792");
            break;
        case "C2_vlab_body_link5":      // Integer Overflow/Underflow
            // Call Javascript will record metric (found in default.aspx)
            PerformAtlasMetric("http://switch.atdmt.com/action/mrtyou_FY08HSWVlabsVendIntegerFinal_10");

            openHSWWindow("http://go.microsoft.com/?linkid=8032791");
            break;
        default:
            alert("Error: Unhandled click event for: " + sender.Name);
            break;         
    }
}

//A reference to the HSW page object.
var HSWObjectReference;

//Function to open a window and launch the vlab page.
function openHSWWindow(golink)
{
      if(HSWObjectReference == null || HSWObjectReference.closed)
      {
            var w = 1020;
            var h = 667;
            wleft = (screen.width - w) / 2;
            wtop = (screen.height - h - 95) / 2;
            if (wleft < 0) wleft = 0;
            if (wtop < 0) wtop = 0;
            HSWObjectReference = window.open(golink, "hswwindow", "height="+h+",width="+w+",left="+wleft+",top="+wtop+",scrollbars=yes,status=1,resizable=1",true);

            if (HSWObjectReference==null || typeof(HSWObjectReference)=="undefined") {
                  alert("You have a pop-up blocker that blocked the console window from being opened.\rPlease configure your pop-up blocker to allow pop-ups from this site.");
            }
      }
      else
      {
            HSWObjectReference.focus();
      }
}

// Function to enable the v-lab page controls and screen.
function enableVlab(sender)
{
        sender.findName("C2_dec_grp").Visibility = "Collapsed";
        sender.findName("C2_vlab_grp").Visibility = "Collapsed";
        sender.findName("C2_movie_grp").Visibility = "Collapsed";
        sender.findName("C2_comic_grp").Visibility = "Collapsed";
        sender.findName("C2_experts_grp").Visibility = "Collapsed";

        sender.findName("C2_btn_home_off").Visibility = "Visible";

        sender.findName("C2_vlab_grp").Visibility = "Visible";
        sender.findName("C2_vlab_bg").Visibility = "Visible";
        sender.findName("C2_hdr_vlab").Visibility = "Visible";
        sender.findName("C2_intro_vlab").Visibility = "Visible";
        sender.findName("C2_vlab").Visibility = "Visible";
        
        sender.findName("bs_strip").Visibility = "Collapsed";
        sender.findName("fs_strip").Visibility = "Collapsed";
        sender.findName("cs_strip").Visibility = "Collapsed";
    
        sender.findName("ts_strip") ["Canvas.Top"] = 80;
        sender.findName("ts_strip") ["Canvas.Left"] = 85;
     
        sender.findName("ts_scroll_mechanism") ["Canvas.Top"] = 40;
        sender.findName("ts_scroll_mechanism") ["Canvas.Left"] = 160;
        
        sender.findName("ts_strip").Visibility = "Visible";
        
        sender.findName("C2")["Canvas.Top"] = 80;
        sender.findName("C2")["Canvas.Left"] = 255;
        
        hideBlogs();
}
