﻿//

function styleSelectedProfile(rptID)
{
    var plist = document.getElementById(jsPrefix+'upnlSelectProfile');
    if (plist != null)
        {
        var alist = plist.getElementsByTagName('a');
        var i=0;
        for (i=0;i<alist.length;i++)
            {
            if (alist[i].id==rptID)
                {alist[i].style.fontWeight='bold';alist[i].style.textDecoration='none';}
            else    
                {alist[i].style.fontWeight='normal';alist[i].style.textDecoration='underline';}
            }
        }
    
}



//This function does a shadowbox affect for the SVG
function SVGShadowBox(action) {
    if (document.getElementById('svgMap')) {
        var svg = document.getElementById('svgMap');
        var light = document.getElementById('svgSBlight');
        var fade = document.getElementById('svgSBfade');

        if (action == 'open') {
            var returnValue = "" //svg.innerHTML
            if (navigator.appName=='Microsoft Internet Explorer')
                {
                var src = svg.childNodes(1).getAttribute("value");
                returnValue = returnValue + "<object type=\"image/svg+xml\" data=\"\" height=\"90%\" width=\"90%\"><param name=\"src\" value=\"" + src + "\"></object><br clear=\"all\"/>";}
            else
                {returnValue = returnValue + "<object type=\"image/svg+xml\" data=\"" + svg.getAttribute("data") + "\" height=\"90%\" width=\"90%\"><param name=\"src\" value=\"" + svg.getAttribute("data") + "\"></object><br clear=\"all\"/>";}
            
            returnValue = returnValue + "<br clear=\"all\"/><a href = \"javascript:void(0)\" onclick = \"SVGShadowBox(\'close\')\">Click here to return to the profile.</a><br />";
            //alert(returnValue);
            
            window.scrollTo(0, 0);
            svg.style.display = 'none';
            light.style.zIndex = 9000;
            light.innerHTML = returnValue;
            light.style.display = 'block';
            fade.style.display = 'block';
        }
        else {
            svg.style.display = 'inline';
            light.style.display = 'none';
            fade.style.display = 'none';
        }
    }
}


function SVGShadowBox2(action) {
    if (document.getElementById('imgMap')) {
        var img = document.getElementById('imgMap');
        var light = document.getElementById('svgSBlight');
        var fade = document.getElementById('svgSBfade');

        if (action == 'open') {
            var returnValue = ""

            returnValue = returnValue + "<img id=\"imgMap\" src=\"" + img.getAttribute("src") + "\" alt=\"Profile Map\" height=\"90%\" /><br clear=\"all\"/>"
            returnValue = returnValue + "<a href = \"javascript:void(0)\" onclick = \"SVGShadowBox2(\'close\')\">Click here to return to the profile.</a><br />";
            window.scrollTo(0, 0);
            img.style.display = 'none';
            light.innerHTML = returnValue;
            light.style.zIndex = 9000;
            light.style.display = 'block';
            fade.style.display = 'block';
        }
        else {
            img.style.display = 'inline';
            light.style.display = 'none';
            fade.style.display = 'none';
        }
    }
}

//The Script below is for the RadComboBox to query the web service
function OnClientItemsRequesting(sender, eventArgs) {
    var context = eventArgs.get_context();
    context["FilterString"] = eventArgs.get_text();

}


function HideTooltip() {
    var tooltip = $find("RadToolTip1");
    if (tooltip == null) {
        tooltip = $find(jsPrefix + "RadToolTip1");
    }
    if (tooltip == null) {
        tooltip = $find(jsPrefix + "DashboardProfileSearch1_RadToolTip1");
    }
    //API: hide the tooltip     
    tooltip.hide();
}

function ShowTooltip(type) {
    window.setTimeout(function() {
        if (type == 'postcode') {
            var tooltip = $find("RadToolTip1");
            if (tooltip == null) {
                tooltip = $find(jsPrefix+"RadToolTip1");
            }
            if (tooltip == null) {
                tooltip = $find(jsPrefix + "DashboardProfileSearch1_RadToolTip1");
            }
            tooltip.show();
        }
        else {
            var tooltip2 = $find("RadToolTip2");
            if (tooltip2 == null) {
                tooltip2 = $find(jsPrefix+"RadToolTip2");
            }
            if (tooltip2 == null) {
                tooltip2 = $find(jsPrefix + "DashboardProfileSearch1_RadToolTip2");
            }
            tooltip2.show();
        }
        //API: show the tooltip

    }, 10);
}

function CheckIfShow(sender, args) {
    //var summaryElem = document.getElementById("ValidationSummary1");
    var combo = $find("rcbPostcodeSearch");
    if (combo == null) {
        combo = $find(jsPrefix + "rcbPostcodeSearch");
    }
    if (combo == null) {
        combo = $find(jsPrefix + "DashboardProfileSearch1_rcbPostcodeSearch");
    }
    var mes = combo._showMoreMessage;

    //check if summary is visible
    if (mes != "No matches") {
        //API: if there are no errors, do not show the tooltip
        if (combo._value != "") {
            args.set_cancel(true);
        }
    }
}

function WardCheckIfShow(sender, args) {
    //var summaryElem = document.getElementById("ValidationSummary1");
    var combo = $find("rcbWardSearch");
    if (combo == null) {
        combo = $find(jsPrefix + "rcbWardSearch");
    }
    if (combo == null) {
        combo = $find(jsPrefix + "DashboardProfileSearch1_rcbWardSearch");
    }
    var mes = combo._showMoreMessage;

    //check if summary is visible
    if (mes != "No matches") {
        //API: if there are no errors, do not show the tooltip
        if (combo._value != "") {
            args.set_cancel(true);
        }
    }
}

function OnSubmitCheckIfShow(sender, args) {
    var combo = $find("rcbPostcodeSearch");
    if (combo == null) {
        combo = $find(jsPrefix + "rcbPostcodeSearch");
    }
    if (combo == null) {
        combo = $find(jsPrefix + "DashboardProfileSearch1_rcbPostcodeSearch");
    }
    var mes = combo._showMoreMessage;

    //check for blanks
    if (combo._value == "") {
        ShowTooltip('postcode'); return false;
    }
    //check if summary is visible
    if (mes != "No matches") {
        if (combo._value != "") {
            return true;
        }
    }
    else { return false; }
}

function OnSubmitWardCheckIfShow(sender, args) {
    var combo = $find("rcbWardSearch");
    if (combo == null) {
        combo = $find(jsPrefix + "rcbWardSearch");
    }
    if (combo == null) {
        combo = $find(jsPrefix + "DashboardProfileSearch1_rcbWardSearch");
    }
    var mes = combo._showMoreMessage;

    //check for blanks
    if (combo._value == "") {
        ShowTooltip('ward'); return false;
    }
    //check if summary is visible
    if (mes != "No matches") {
        if (combo._value != "") {
            return true;
        }
    }
    else { return false; }
}

function onTabSelecting(sender, args) {
    if (args.get_tab().get_pageViewID()) {
        args.get_tab().set_postBack(false);
    }
}

var mapviewer;

function onLoad() {
    var postcode = document.getElementById(jsPrefix+'lblPostcode').value;
    //Add the map

    if (postcode != "") {
        mapviewer = new MMFactory.createViewer(document.getElementById(jsPrefix+'divPostcodeProfileMultimapMap'));

        //Add three new event handlers to detect when a geocode request has been made so we can inform the user
        mapviewer.addEventHandler('startGeocode', updateGeocodeStatus);
        mapviewer.addEventHandler('endGeocode', updateGeocodeStatus);
        mapviewer.addEventHandler('endGeocode', endGeocode);

        //mapviewer.goToPosition(new MMLatLon(-48.63291, 2.37305));
        mapviewer.goToPosition(new MMLocation(new MMAddress({ postal_code: postcode, country_code: 'GB' })));
        small_pan_zoom_widget = new MMSmallPanZoomWidget();
        mapviewer.addWidget(small_pan_zoom_widget);
        overview_widget = new MMOverviewWidget();
        mapviewer.addWidget(overview_widget);
    }

}

function onWardLoad() {
    var postcode = "";
    if (postcode != "") {
        mapviewer = new MMFactory.createViewer(document.getElementById(jsPrefix+'divPostcodeProfileMultimapMap'));

        //Add three new event handlers to detect when a geocode request has been made so we can inform the user
        mapviewer.addEventHandler('startGeocode', updateGeocodeStatus);
        mapviewer.addEventHandler('endGeocode', updateGeocodeStatus);
        mapviewer.addEventHandler('endGeocode', endGeocode);

        //mapviewer.goToPosition(new MMLatLon(-48.63291, 2.37305));
        mapviewer.goToPosition(new MMLocation(new MMAddress({ postal_code: postcode, country_code: 'GB' })));
        small_pan_zoom_widget = new MMSmallPanZoomWidget();
        mapviewer.addWidget(small_pan_zoom_widget);
        overview_widget = new MMOverviewWidget();
        mapviewer.addWidget(overview_widget);
    }

}

function updateGeocodeStatus(type) {
    //var gs = document.getElementById('geocode_status');

    if (type == 'startGeocode') {
        //if we are starting a geocode request, display the flashing "Geocoding..." message
        //gs.style.display = 'block';
    } else {
        //if we are ending a geocode request, hide the flashing "Geocoding..." message
        //gs.style.display = 'none';
    }
}

function endGeocode(type, target, location, error_code) {
    if (error_code && error_code != 'MM_GEOCODE_MULTIPLE_MATCHES') {
        //alert('There was a problem geocoding that address: ' + error_code);
        document.getElementById(jsPrefix+'divPostcodeProfileMultimapMap').style.display = 'none';
        document.getElementById(jsPrefix+'lblPostcodeError').style.display = '';
        return;
    }
    else if (error_code == 'MM_GEOCODE_MULTIPLE_MATCHES') {
        //alert('Please note that multiple possible locations have been found for this address');
    document.getElementById(jsPrefix+'divPostcodeProfileMultimapMap').style.display = 'none';
    document.getElementById(jsPrefix+'lblPostcodeError').style.display = '';
    }
    else {
        document.getElementById(jsPrefix+'divPostcodeProfileMultimapMap').style.display = '';
        document.getElementById(jsPrefix+'lblPostcodeError').style.display = 'none';
        var pos = mapviewer.getCurrentPosition();
        var icon = new MMIcon('images/skin/red-circle2.gif');
        icon.iconSize = new MMDimensions(32, 32);
        icon.iconAnchor = new MMPoint(16, 16);
        mapviewer.createMarker(location, { 'label': location.address.toString(), 'icon': icon });
    }

}

function ChangeBodyCursor(cursor)
{
    document.body.style.cursor=cursor;
}

function HideMapPanel() {
    document.getElementById(jsPrefix+'divMap').style.display = 'none';
    document.getElementById(jsPrefix+'divThematicMap').style.display = '';
}

function ShowMapPanel() {
    document.getElementById(jsPrefix+'divMap').style.display = '';
    document.getElementById(jsPrefix+'divThematicMap').style.display = 'none'
}

function FocusOnSearchButton(sender, args) {
    //alert("blur");
    if (sender._uniqueId == jsPrefix+"rcbPostcodeSearch") {
        if (document.getElementById(jsPrefix+'btnPostcodeSearch')!=null) {document.getElementById(jsPrefix+'btnPostcodeSearch').focus()};
    }
    else {
        if (document.getElementById(jsPrefix+'btnSearch')!=null)
            {document.getElementById(jsPrefix+'btnSearch').focus();}
    }
}

function ClearPostcode() {
    var combo = $find(jsPrefix+"rcbPostcodeSearch");
    combo.set_text("");
    combo.set_value("");
    return false;
}

function ClearWard() {
    var combo = $find(jsPrefix+"rcbWardSearch");
    combo.set_text("");
    combo.set_value("");
    return false;
}

    function showPPchart(charttype) {
       if(charttype == 'bar')
       {
            document.getElementById(jsPrefix+'PPTrend1_divPPTrendLineBody').style.display = 'none';
            document.getElementById(jsPrefix+'PPTrend1_divPPTrendBarBody').style.display = '';
            
       }
       else
       {
            document.getElementById(jsPrefix+'PPTrend1_divPPTrendLineBody').style.display = '';
            document.getElementById(jsPrefix+'PPTrend1_divPPTrendBarBody').style.display = 'none';
            
       }
    }