
        function CheckFrame()
        {
            try
            {
                if (typeof(external.DownloadManager) == "undefined")//this is IE
                {
                    //oddly, this executes in WMP if in the infocenter
                    if(top.location.search.indexOf("locale") != -1)//this is infocenter page in wmp
                    {
                        //document.getElementById('SearchText').value = top.location.href;
                    }
                    else
                    {
                        if(top.location.search.length > 0 && top.location.search.indexOf("redir") == -1)
                        {
                            path = location.pathname.replace("\/", "");
                            window.location = "/Main.aspx?redir=" + path + location.search;
                        }
                    }
                }
                else //this is wmp
                {   
                    //document.getElementById("SearchText").value = "foo"; 
                    //document.getElementById('SearchText').value = top.location.search;
                    //inside wmp
    //                if(top.location.search.indexOf("redir") == -1)
    //                {
    //                    window.location = "/Main.aspx?redir=" + location.pathname + location.search;
    //                }
                }
            }
            catch(Error){};
        }

//
//  MusicStore.js   -- client-side support script for the MusicGiants WMP on-line store.
//

    // The catch all...
function NotImplemented()
{
    alert("Not implemented yet");
}
    
function ExitSecureMode()
{
    // Stub for onload call
}

function TimeNow()
{
    return;
    var today = new Date();
    var h = today.getHours();
    if (h < 10)
        h = "0" + h;
    var m = today.getMinutes();
    if (m < 10)
        m = "0" + m;
    var s = today.getSeconds();
    if (s < 10)
        s = "0" + s;
    
    alert(h + ":" + m + ":" + s);
}

    // Called from the button bar buttons A..Z that are generated for the label browse page
function BrowseByLabelArtist(s)
{
    window.navigate("Labels.aspx?LABEL=" + document.getElementById(CurrentMusicLabel).value + "&INITIAL=" + s);
}

    // Called from the button bar buttons A..Z that are generated for the browsing pages
function WMP11_BrowseByArtist(s)
{
    window.navigate("Artists.aspx?INITIAL=" + s);
}

function WMP11_BrowseByAlbum(s)
{
    window.navigate("Albums.aspx?INITIAL=" + s);
}

    // Simple encode function used to encode some hidden field values so the server
    // doesn't squawk about "dangerous input". All you need to do is encode the chevrons.
function HTMLEncode(s)
{
        // Use regular expressions so we replace ALL of the < and > markers.
        // The server can use a real HTMLdecode to regenerate the data.
    var exp1 = /</g;
    var exp2 = />/g;
    s = s.replace(exp1, "&lt;");
    s = s.replace(exp2, "&gt;");
    return s;
}
    // Client side logout function. Called by a click on the lightning bolt.
function Logout(bForceAway)
{
    // OOB callback to login.aspx
	var pageUrl = "Login.aspx?OOB=LOGOUT";
	var X = new ActiveXObject("Microsoft.XMLHTTP");
	X.open("POST", pageUrl, false);
    X.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    X.send(null);
    var s = X.responseText;
    //document.getElementById("LoggedInButton").style.visibility = "hidden";
    if (bForceAway)
        window.location = "Service.aspx?LOGOUT=" + s;
    
    window.location = "Service.aspx";
}
    // Invokes the appropriate search function according to the user selection.
function GoSearch()
{
    var o = document.getElementById("SearchSelect");
    var s = o.options[o.selectedIndex].value;
    var sSearch = document.getElementById("SearchText").value;
    if (sSearch == "")
        return;
        
     
    if (s == "albums") window.location = "Albums.aspx?SEARCH=" + sSearch;
    if (s == "artists") window.location = "Artists.aspx?SEARCH=" + sSearch;
    if (s == "tracks") window.location = "Tracks.aspx?SEARCH=" + sSearch;
}

    // Default button is the "go" button for all pages
function KeyDownHandler()
{
        // Look for the Enter key only...
    if (event.keyCode == 13)
    {
            // cancel the default submit
        event.returnValue = false;
        event.cancel = true;
            // Invoke Search
        GoSearch();
    }
}

    // UI handlers for the Genre page My Account genre preferences
    
function GenreImgMouseOver(o)
{
    if (o == null) return;
	var s = o.src;
	s = s.replace(".png", "_over.png");
	o.src = s;
}

function GenreImgMouseOut(o)
{
    if (o == null) return;
	var s = o.src;
	s = s.replace("_over.png", ".png");
	o.src = s;
}

function GenreImgButtonClick(o)
{
    if (o == null) return;
	var s = o.src;
		// src property is of the form "Images/Genres/blues.png"
	var i = s.lastIndexOf("/");
	s = s.substr(i + 1);
	s = s.replace("_over", "");
	s = s.replace(".png", "");
	window.location = "Artists.aspx?GENRE=" + s;
}

   // Rollovers for the Master Page buttons
function newImage(arg) 
{
	if (document.images) 
	{
		var rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) 
	{
		for (var i = 0; i < changeImages.arguments.length; i += 2) 
		{
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

var preloadFlag = false;

function preloadImages() 
{
	if (document.images) 
	{
		var albums_01_over = newImage("images/albums_01-over.png");
		var albums_01_down = newImage("images/albums_01-down.png");
		var artists_01_over = newImage("images/artists_01-over.png");
		var artists_01_down = newImage("images/artists_01-down.png");
		var genres_01_over = newImage("images/genres_01-over.png");
		var genres_01_down = newImage("images/genres_01-down.png");
		var labels_01_over = newImage("images/labels_01-over.png");
		var labels_01_down = newImage("images/labels_01-down.png");
		var myaccount_01_over = newImage("images/myaccount_01-over.png");
		var myaccount_01_down = newImage("images/myaccount_01-down.png");
		var preferences_01_over = newImage("images/preferences_01-over.png");
		var preferences_01_down = newImage("images/preferences_01-down.png");
		preloadFlag = true;
	}
} 
    // These functions open the various "static" pages within the site.
    // When within WMP you are not allowed to do a popup window so we just navigate to the page.
    // TODO: Impove the layout when within WMP (which disallows all popup windows including alerts).

Options = "width=850,height=600,top=50,left=50,resizable=yes,status=no,scrollbars=yes,menubar=no,location=no,titlebar=no,toolbar=no"; 

function ArtistBio(sArtistID, sArtist)
{
    if (typeof(external.DownloadManager) == "undefined")
        window.open("artist.aspx?ID=" + sArtistID, "_blank", Options);  
    else
        window.navigate("artist.aspx?ID=" + sArtistID);
}

function Help()
{
    if (typeof(external.DownloadManager) == "undefined")
        window.open("Help.aspx", "_blank", Options);  
    else
        window.navigate("Help.aspx");
}

function Privacy()
{
    if (typeof(external.DownloadManager) == "undefined")
        window.open("Privacy.aspx", "_blank", Options);  
    else
        window.navigate("Privacy.aspx");
}

function Service()
{
    if (typeof(external.DownloadManager) == "undefined")
        window.open("TermsOfService.aspx", "_blank", Options);  
    else
        window.navigate("TermsOfService.aspx");
}

    // Called by a click on the little speaker icon embedded in the AlbumDetails.aspx page.
    // Starts the related URL playing.
function PlayerStart(sURL)
{
    var Player = document.getElementById("Player");

    Player.URL = sURL;
    Player.controls.play();
}

    // These functions control the player when it is is visible.
    // TODO: Hook these up so the user can stop or control a clip.
    // TODO: Right now they are never called.
function PlayerStop()
{
    var Player = document.getElementById("Player");
    Player.controls.stop();
}

function PlayerSkipBack()
{
    var Player = document.getElementById("Player");
    Player.controls.previous();
}

function PlayerSkipForward()
{
    var Player = document.getElementById("Player");
    Player.controls.next();
}

    // Artefact from the richer client browser. Responds to WMP player state changes.
    // Is called, but has no effect in this implementation.
function PlayerStateChanged(NewState)
{
    var Player = document.getElementById("Player");
    var s;
    switch (NewState){
        case 0:
            s = "Undefined";
            break;
        case 1:
            s = "Stopped";
            break;
        case 2:
            s = "Paused";
            break;
        case 3:
                // After starting a track
            s = "Playing";
            break;
        case 4:
            s = "ScanForward";
            break;
        case 5:
            s = "ScanReverse";
            break;
        case 6:
            s = "Buffering";
            break;
        case 7:
            s = "Waiting";
            break;
        case 8:
                // At the end of a track
            s = "MediaEnded";
            break;
        case 9:
                // One of these preceeds every other event
            s = "Transitioning";
            break;
        case 10:
                // After loading a playlist or a URL
            s = "Ready";
            break;
        case 11:
            s = "Reconnecting";
            break;
        default:
            s = "Unknown state " + NewState;
    }
}

    // This stuff sets the top nav bar text links. The script is generated server side.
    // Net result is all the little text links and arrows appear along the nav bar.

NavButtonSeparator = "</a>&nbsp;<IMG SRC='Images/arrowcut.gif' align='middle' />&nbsp;";
aHome = "<IMG SRC='Images/arrowcut.gif' align='middle' />&nbsp;";
aPart1 = "<a href='javascript:window.location=\"";
aPart2 = "\"' class='mediumwhitetext'>";

function NavButton(sLabel, sTarget)
{
    if (s == "Home")
        return (aHome + aPart1 + sTarget + aPart2 + sLabel + NavButtonSeparator);
    return (aPart1 + sTarget + aPart2 + sLabel + NavButtonSeparator);
}

function LastNavButton(sLabel, sTarget)
{
    if (sLabel == "Home")
        return (aHome + aPart1 + sTarget + aPart2 + sLabel);
    //return (aPart1 + sTarget + aPart2 + sLabel);
    return ("<span class='mediumwhitetext'>" + sLabel + "</span>");
}

function SetNavButtons(s, sTarget)
{
    document.getElementById("navbuttons").innerHTML = s;
}

    // Shopping cart functions
    //
    // This is the client-side reference the "Check Out" button so we can flip it on
    // whenever something is added to the cart. Should be an ASP control but ASP insists
    // on not rendering controls it figures out are invisible. No doubt there is some
    // funky event on the server side that would allow you to override this behavior,
    // but I haven't found it yet.
    //
function CheckoutButtonImageVisible(b)
{
    if (b)
    {
         document.getElementById("CheckoutButtonImage").style.visibility = "visible";
    }
    else
    {
         document.getElementById("CheckoutButtonImage").style.visibility = "hidden";
    }
}

    // Add an item to the shopping cart...
    //
    // Does a callback to place the item in the cart on the server side...
    // Refreshes the client-side HTML that lists the shopping cart items...
    // Flips on the "Checkout" button...
    //
function AddToCart(iAlbumID)
{
	var pageUrl = "AddToCart.aspx?ALBUMID=" + iAlbumID;
	var X = new ActiveXObject("Microsoft.XMLHTTP");
	if (X == null) return;
	X.open("POST", pageUrl, false);
    X.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    X.send(null);
    if (X.responseText == "ERROR")
    {
        alert("This item is already in your shopping cart");
        return;
    }
        // Otherwise OOB return is the URL of the album cover image we use for display
    var sCount = document.getElementById("CartItemCount");
    if (sCount != null)
    {
        var iCount = parseInt(sCount.innerText);
            // Count set to 0 if the innerText is empty or something else.
        if (isNaN(iCount))
            iCount = 0;
        iCount++;
        // TODO: Enumerate tracks and albums properly
        sCount.innerText = "" + iCount + (iCount==1?" item":" items");
        var sList = document.getElementById("CartItemList");
        var sItems = sList.innerHTML;
        sItems += "<img src='" + X.responseText + "' width='60'/><img src='Images/navback122.gif' />";
        sList.innerHTML = sItems;
            // Turn on the checkout button
        CheckoutButtonImageVisible(true);
    }
}

function AddMovieToCart(iAlbumID)
{
	var pageUrl = "AddToCart.aspx?MOVIEID=" + iAlbumID;
	var X = new ActiveXObject("Microsoft.XMLHTTP");
	if (X == null) return;
	X.open("POST", pageUrl, false);
    X.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    X.send(null);
    if (X.responseText == "ERROR")
    {
        alert("This item is already in your shopping cart");
        return;
    }
        // Otherwise OOB return is the URL of the album cover image we use for display
    var sCount = document.getElementById("CartItemCount");
    if (sCount != null)
    {
        var iCount = parseInt(sCount.innerText);
            // Count set to 0 if the innerText is empty or something else.
        if (isNaN(iCount))
            iCount = 0;
        iCount++;
        // TODO: Enumerate tracks and albums properly
        sCount.innerText = "" + iCount + (iCount==1?" item":" items");
        var sList = document.getElementById("CartItemList");
        var sItems = sList.innerHTML;
        sItems += "<img src='" + X.responseText + "' width='60'/><img src='Images/navback122.gif' />";
        sList.innerHTML = sItems;
            // Turn on the checkout button
        CheckoutButtonImageVisible(true);
    }
}

function LoadMachineData()
{
    // Dummy. Overridden by the version in Login.aspx
}


// Browser Window Size and Position
// copyright Stephen Chapman, 3rd Jan 2005, 8th Dec 2005
// you may copy these functions but please keep the copyright notice as well
function pageWidth() 
{
    return window.innerWidth != null? window.innerWidth : document.documentElement && document.documentElement.clientWidth ?       document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
} 
    function pageHeight() 
    {
        return  window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ?  document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;
    } 
    function posLeft() {return typeof window.pageXOffset != 'undefined' ? window.pageXOffset :document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0;} function posTop() {return typeof window.pageYOffset != 'undefined' ?  window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;} function posRight() {return posLeft()+pageWidth();} function posBottom() {return posTop()+pageHeight();}
                    
                    
                    
function CheckDownloadManager()
{
    try
    {
        // Will throw an exception if not installed
        var o = new ActiveXObject("clInetSuiteX6.clMultiDownLoader");
        // True if the DL manager is now really there
        if (o != null)
        {
            // It's installed
            return;
        }
    }
    catch (X)
    {
        // ActiveX not yet installed
        top.location.href = "UpdateWMP.aspx";
    }
}

function JumpOutOfSSL(){
    if(window.location.protocol == "https:")
    {
        var s = window.location.href;
        var newL = s.replace(/https:/i, "http:");
        //alert(newL);
        window.location.href = newL;
        
    }
    
}