﻿var PlotSize = { Width:665, Height:450 };

function CreateSilverlightTrackPlugin( hostElement,trckid)
{
    var now = new Date();
    Silverlight.createObject(
        "http://www.sciscope.org/datadepot/LoadTrackData.ashx?t=" + trckid + "&d1=" + beginDate + "&d2=" + endDate,
                    
        hostElement,                       // DOM reference to hosting DIV tag.
        "TrackSilverlightPlugin",         // Unique plug-in ID value.
        {                               // Per-instance properties.
            width:PlotSize.Width+'',                // Width of rectangular region of 
                                        // plug-in area in pixels.
            height:PlotSize.Height+'',               // Height of rectangular region of 
                                        // plug-in area in pixels.
            inplaceInstallPrompt:false, // Determines whether to display 
                                        // in-place install prompt if 
                                        // invalid version detected.
            background:'#FFFFFF',       // Background color of plug-in.
           
            isWindowless:'true',       // Determines whether to display plug-in 
                                        // in Windowless mode.
            framerate:'24',             // MaxFrameRate property value.
            version:'1.0'               // Silverlight version to use.
            
        },
        {
            onError:null,               // OnError property value -- 
                                        // event handler function name.
            onLoad:LoadTrackData             // OnLoad property value -- 
                                        // event handler function name.
        },
        null);                          // Context value -- event handler function name.

}

///DataDepotService.asmx/GetTimeSeriesDataForPlotting?SeriesID=90918&beginDate=01/01/1990&endDate=01/01/2009


function UpdatePlotContent(sid){
//alert(sid);
//var slp = GetPlugin();
//alert(slp.source);
//slp.source ="http://www.sciscope.org/datadepot/DataDepotService.asmx/GetTrack?SeriesID="+sid+"&beginDate=&endDate=";
//alert(slp.source);
document.getElementById("PlotContainer").style.visibility= "visible";
document.getElementById("LoadMessagePanel").style.display= "block";
DataDepotService.GetTrackID(sid, '', '',OnTrackIDRetrievalSucceeded, OnFailed);

}

function OnTrackIDRetrievalSucceeded(trid){
plotseriesid=trid;
tid = "?t=" + plotseriesid;
CreateSilverlightTrackPlugin(document.getElementById("TrackPlotDiv"),trid);
 /*  var sl = GetPlugin();
   var plotCanvas = sl.content.findName("line-"+trid);
   plotCanvas.stroke="#FF8401";*/
}

function OnFailed(error) {
    var stackTrace = error.get_stackTrace();
    var message = error.get_message();
    var statusCode = error.get_statusCode();
    var exceptionType = error.get_exceptionType();
    var timedout = error.get_timedOut();

    if ($('handtool').style.display != "none") {
        map.AttachEvent('onclick', mapClick);
    }

    var RsltElem =
        "Stack Trace: " + stackTrace + "<br/>" +
        "Service Error: " + message + "<br/>" +
        "Status Code: " + statusCode + "<br/>" +
        "Exception Type: " + exceptionType + "<br/>" +
        "Timedout: " + timedout;

      alert(RsltElem);
}
