﻿// JScript File

//Get the Love's Store Detail
function getStoreDetail(StoreNumber)
{
    //get the content for the pin.
    getAJAXDetail(StoreNumber);
}

//request content for popup
function getAJAXDetail(StoreNumber)
{
    //call the web service
    Loves.VirtualEarthAjax.MapService.GetDetail(StoreNumber, OnGetDetailSucceeded, OnGetDetailFailed);
} 


//Receive content for popup
function OnGetDetailSucceeded(result, eventargs)
{ 
    //Show the modal popup
    $find("StoreDetail").show();

    var detail = "<table style='font-size: 8pt; margin: 10px; width: 400px;'>" +
                    "<tr>" +
                        "<td style='height: 10px; font-size: 10pt; font-weight: bold;' colspan='4'>Love's " + result.StoreType + " # " + result.StoreNumber + "</td>" +
                    "</tr>" +
                    "<tr>" +
                        "<td style='width: 50%;' colspan='2'>" + checkNull(result.Address) + "<br>" + checkNull(result.City) + ", " + checkNull(result.State) + " " + checkNull(result.Zip) + "<br><br><b>Phone:</b> (" + checkNull(result.Areacode) + ") " + checkNull(result.Phone) + "" + checkEmptyReturnValue(result.PhoneRoadSide, "<br><b>Road Side: </b> (" + checkNull(result.Areacode) + ") " + checkNull(result.PhoneRoadSide) + "") + "<br><b>Fax:</b> (" + checkNull(result.Areacode) + ") " + checkNull(result.Fax) + "</td>" +
                        "<td style='text-align: center; vertical-align: middle; width: 50%;' colspan='2'><img src='StoreImages/" + result.StoreImage + "' alt='' style='border: none;' /></td>" +
                    "</tr>" + 
                    "<tr>" +
                        "<td colspan='4'>&nbsp;</td>" +
                    "</tr>" +
                    "<tr>" +
                        "<td colspan='2'><b>Latitude: </b>" + checkNull(result.Latitude) + "<br><b>Longitude: </b>" + checkNull(result.Longitude) + "<br></td>" +
                        "<td colspan='2'><b>Highway: </b>" + checkNull(result.Highway) + "<br><b>Highway Exit: </b>" + checkNull(result.HighwayExit) + "<br></td>" +
                    "</tr>" +
                    "<tr>" +
                        "<td colspan='4'>&nbsp;</td>" +
                    "</tr>" +
                    "<tr>" +
                        "<td style='vertical-align: top;' colspan='2'><b>Restaurants</b><br>" + checkNull(result.Restaurants.replace(/,/g, "<br>")) + "</td>" +
                        "<td style='vertical-align: top;' colspan='2'><b>Available Fuels</b><br>" + checkNull(result.FuelGrades.replace(/,/g, "<br>")) + "</td>" +
                    "</tr>" +
                    "<tr>" +
                        "<td colspan='4'>&nbsp;</td>" +
                    "</tr>" +
                    "<tr>" +
                        "<td style='text-align: left; width: 20%;'><b>Internet</b></td>" +
                        "<td style='text-align: left; width: 30%;'>" + result.WANType + "</td>" +
                        "<td style='text-align: left; width: 20%;'><b>Scales</b></td>" +
                        "<td style='text-align: left; width: 30%;'>" + result.Scales + "</td>" +
                    "</tr>" +
                    "<tr>" +
                        "<td style='text-align: left;'><b>Showers</b></td>" +
                        "<td style='text-align: left;'>" + result.Showers + "</td>" +
                        "<td style='text-align: left;'><b>Parking</b></td>" +
                        "<td style='text-align: left;'>" + result.TruckParking + "</td>" +
                    "</tr>" +
                 "</table>" +
                 "<table style='font-size: 8pt; margin: 10px; width: 400px;'>" +
                    "<tr>" +
                        "<td colspan='4' style='text-align: center;'><hr style='text-align: center; width: 90%;'></td>" +
                    "</tr>" +
                    "<tr>" +
                        "<td style='text-align: left; width: 150px;'><b>ATM</b></td>" +
                        "<td style='text-align: left; width: 50px;'>" + DecodeTrueFalse(checkNull(result.ATM)) + "</td>" +
                        "<td style='text-align: left; width: 150px;'><b>Driver Rest Area</b></td>" +
                        "<td style='text-align: left; width: 50px;'>" + DecodeTrueFalse(checkNull(result.DriverRestArea)) + "</td>" +
                    "</tr>" +
                    "<tr>" +
                        "<td style='text-align: left;'><b>Overnight Parking</b></td>" +
                        "<td style='text-align: left;'>" + DecodeTrueFalse(checkNull(result.OvernightParking)) + "</td>" +
                        "<td style='text-align: left;'><b>Pay At Pump</b></td>" +
                        "<td style='text-align: left;'>" + DecodeTrueFalse(checkNull(result.PayAtPump)) + "</td>" +
                    "</tr>" +
                    "<tr>" +
                        "<td style='text-align: left;'><b>Pay Phones</b></td>" +
                        "<td style='text-align: left;'>" + DecodeTrueFalse(checkNull(result.PayPhones)) + "</td>" +
                        "<td style='text-align: left;'><b>Pegasus Trans-flo</b></td>" +
                        "<td style='text-align: left;'>" + DecodeTrueFalse(checkNull(result.PegasusTransFlo)) + "</td>" +
                    "</tr>" +
                    "<tr>" +
                        "<td style='text-align: left;'><b>RV Dump Station</b></td>" +
                        "<td style='text-align: left;'>" + DecodeTrueFalse(checkNull(result.RVDumpStation)) + "</td>" +
                        "<td style='text-align: left;'><b>Tire Care Center</b></td>" +
                        "<td style='text-align: left;'>" + DecodeTrueFalse(checkNull(result.TireCareCenter)) + "</td>" +
                    "</tr>" +
                    "<tr>" +
                        "<td style='text-align: left;'><b>TripPak Box</b></td>" +
                        "<td style='text-align: left;'>" + DecodeTrueFalse(checkNull(result.TripPakBox)) + "</td>" +
                        "<td style='text-align: left;'><b>Trucking Supplies</b></td>" +
                        "<td style='text-align: left;'>" + DecodeTrueFalse(checkNull(result.TruckingSupplies)) + "</td>" +
                    "</tr>" +
                    "<tr>" +
                        "<td style='text-align: left;'><b>Boss Truck Shops</b></td>" +
                        "<td style='text-align: left;'>" + DecodeTrueFalse(checkNull(result.BossTruckShops)) + "</td>" +
                        "<td style='text-align: left;'><b>Wingfoot Commercial Tire Systems</b></td>" +
                        "<td style='text-align: left;'>" + DecodeTrueFalse(checkNull(result.WingfootCommercialTireSystems)) + "</td>" +
                    "</tr>" +
                    "<tr>" +
                        "<td colspan='2'>&nbsp;</td>" +
                    "</tr>" +
                 "</table>";

    //set the content       
    $get("StoreDetailContent").innerHTML = detail;

}


// This is the failed callback function for all webservices.
function OnGetDetailFailed(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();
   
    // Display the error.    
    var RsltElem = 
        "Stack Trace: " +  stackTrace + "<br/>" +
        "Service Error: " + message + "<br/>" +
        "Status Code: " + statusCode + "<br/>" +
        "Exception Type: " + exceptionType + "<br/>" +
        "Timedout: " + timedout;
        
        alert(RsltElem);
}

function DecodeTrueFalse(value)
{
    if (value == true)
    {
        return "<img src='DesktopModules/Loves.VirtualEarthAjax/images/Yes.png' style='border: none;' alt='Yes' />";
    }
    else
    {
         return "<img src='DesktopModules/Loves.VirtualEarthAjax/images/No.png' style='border: none;' alt='No' />";
    }
}