﻿ //this is a function of fusioncharts that lets you know the chart is drawn
 
 function FC_Rendered(DOMId)
 {
      if (DOMId=="TrendChart"){
         if (document.getElementById("mnAll").value == ''){  //no data yet
            document.aspnetForm.rb[0].checked = true;        //initialize radiobuttons
            document.aspnetForm.vb[0].checked = true;
          }
            
          ESTrend.LoadCharts();
            //return;
       }
 }
//***********************************************************************************

var ESTrend = {}
//***********************************************************************************

ESTrend.CatChange = function()
{
    var chartObj = getChartFromId('TrendChart');
    //'aspnetForm' gets named by asp...and nested forms don't see to work
    var ym = '';
    if (document.aspnetForm.vb[0].checked) {
    ym = 'mn';
    }
    else {
    ym = 'yr';
    }

    if (document.aspnetForm.rb[0].checked) {
        chartObj.setDataXML(document.getElementById(ym + 'All').value);
    }
    else if (document.aspnetForm.rb[1].checked) {
        chartObj.setDataXML(document.getElementById(ym + 'Home').value);
    }
    else if (document.aspnetForm.rb[2].checked) {
        chartObj.setDataXML(document.getElementById(ym + 'Drive').value);
    }
    else if (document.aspnetForm.rb[3].checked){
        chartObj.setDataXML(document.getElementById(ym + 'Fly').value);
    }
    else if (document.aspnetForm.rb[4].checked){
        chartObj.setDataXML(document.getElementById(ym + 'Ride').value);
    }
}


//***********************************************************************************


ESTrend.LoadCharts= function()
{
    //alert('in ESTrent.LoadCharts before wsTrend.BuildCatChart');
    //ecoshiftB.WebService2.HelloWorld(ESTrend.onCompleteHW,ESTrend.OnTimeOut, ESTrend.OnError);
    //alert('past junkwebservice call');
    ecoshiftB.WebService2.BuildCatChart('home',ESTrend.OnCompleteHome, ESTrend.OnTimeOut, ESTrend.OnError);
    //alert ('in EStrend after first load chart call');
    ecoshiftB.WebService2.BuildCatChart('drive',ESTrend.OnCompleteDrive, ESTrend.OnTimeOut2, ESTrend.OnError);
    //alert ('in EStrend after second load chart call');

    ecoshiftB.WebService2.BuildCatChart('fly',ESTrend.OnCompleteFly, ESTrend.OnTimeOut2, ESTrend.OnError);
    ecoshiftB.WebService2.BuildCatChart('ride',ESTrend.OnCompleteRide, ESTrend.OnTimeOut2, ESTrend.OnError);

    var chartObj = getChartFromId('TrendChart');
    document.getElementById("mnAll").value = chartObj.getXML();

    ecoshiftB.WebService2.BuildYearCatChart('home',ESTrend.OnCompleteYrHome,ESTrend.OnTimeOut2,ESTrend.OnError);
    ecoshiftB.WebService2.BuildYearCatChart('drive',ESTrend.OnCompleteYrDrive,ESTrend.OnTimeOut2,ESTrend.OnError);
    ecoshiftB.WebService2.BuildYearCatChart('fly',ESTrend.OnCompleteYrFly,ESTrend.OnTimeOut2,ESTrend.OnError);
    ecoshiftB.WebService2.BuildYearCatChart('ride',ESTrend.OnCompleteYrRide,ESTrend.OnTimeOut2,ESTrend.OnError);
    ecoshiftB.WebService2.BuildYearCatChart('all',ESTrend.OnCompleteYrAll,ESTrend.OnTimeOut2,ESTrend.OnError);
}

//**********************************************************************************
//ESTrend.onCompleteHW = function(result)
//{
//alert('result');
//}

ESTrend.OnCompleteHome = function(result)
{
document.getElementById("mnHome").value = result;
document.getElementById("dvloading").style.display = 'none';
document.getElementById("dvSelect").style.display = '';
}

//***********************************************************************************

ESTrend.OnCompleteDrive = function(result)
{
    document.getElementById("mnDrive").value = result;
}

//***********************************************************************************

ESTrend.OnCompleteFly = function(result)
{
    document.getElementById("mnFly").value = result;
}

//***********************************************************************************


ESTrend.OnCompleteRide = function(result)
{
    document.getElementById("mnRide").value = result;
}

//***********************************************************************************

ESTrend.OnCompleteYrHome = function(result)
{
    document.getElementById("yrHome").value = result;
}

//***********************************************************************************

ESTrend.OnCompleteYrDrive = function(result)
{
    document.getElementById("yrDrive").value = result;
}

//***********************************************************************************

ESTrend.OnCompleteYrFly = function(result)
{
document.getElementById("yrFly").value = result;
}

//***********************************************************************************

ESTrend.OnCompleteYrRide = function(result)
{
document.getElementById("yrRide").value = result;
}

//***********************************************************************************

ESTrend.OnCompleteYrAll = function(result)
{
document.getElementById("yrAll").value = result;
}

//***********************************************************************************

ESTrend.OnTimeOut = function(error)
{
//alert('WSTrend TimeOut with result = ' + result);
alert('jsTrend.js  ESTrend.OnTimeOut with error.get_timedOut() = ' + error.get_timedOut() + "/r/n" +
    "Error: " + error.get_message() + "/r/n" +
    "Status Code: " + error.get_statusCode());
}

ESTrend.OnTimeOut2 = function(error)
{
//all but one of the webservice calls send their timeouts here to avoid repeat alerts.
}

//***********************************************************************************

ESTrend.OnError = function(result)
{
alert('WSTrend Error');
}

//***********************************************************************************

function updateChart(ct){
    var sid;
    sid = getSID();
    //alert('in update chart');

    if (ct == 1){
        ws2.GetEntryChartString(sid,OnCompleteGetChartString,OnTimeOut,OnError);
        //alert('finished ws for normal chart');
    }
    else {
       // alert('updatechartYOY');
        ws2.GetYoYChartString(sid,OnCompleteGetYoYChartString,OnTimeOut,OnError);
    }
}

//***********************************************************************************


function getSID() {
    //alert('in getSID');
    var query = location.search.substring(1); //see rhino pg 272
    //alert(query);
    var sid = query.slice(4); //see rhino pg 705
    //alert(sid);
    
    return sid;
}
//************************************************************************************

//***********************************************************************************

