﻿var LA = new VELatLong(53.47496, -1.867675);
var Opportunities = null;
var map = null;
var mapRestrictionZoomLevel = 16;
var count = 0;
var Refreshwhere = null;
var counter = -1;
var schools = 'Primary Schools, Secondary Schools';

var baseLayer = new VEShapeLayer();
var clusterLayer = new VEShapeLayer();
var TransportLayer = new VEShapeLayer();
var SchoolLayer = new VEShapeLayer();
var AttractionsLayer = new VEShapeLayer();
var polygonLayer = new VEShapeLayer();

var TansportClick = true;
var SchoolClick = true;
var AttractionClick = true;

var zoomLimit = 20;

var ImageUrl = null;
var Transport = 0;
var polygonID = 0;

var DRIVETIME_CONSTANT = "Mile";
var MEDIA_TYPE_ID_POSTER = 1;
var MEDIA_TYPE_ID_BUS = 2;

var MEDIA_TYPE_ID_4SHEET = 1;
var MEDIA_TYPE_ID_96SHEET = 2;
var MEDIA_TYPE_ID_48SHEET = 3;
var MEDIA_TYPE_ID_6SHEET = 4;
var MEDIA_TYPE_ID_PHONEBOX = 5;
var MEDIA_TYPE_ID_BUSSHELTER = 6;

var MEDIA_TYPE_ID_BUSREAR = 12;
var MEDIA_TYPE_ID_BUSSIDELINER = 9;

function fnChangeImage(objImage,collapsible) {
//    debugger;
//      objAjaxControl = document.getElementById(collapsible);
//    objhdnPanelPosition = document.getElementById(hdnPanelPos);
//    if(objhdnPanelPosition.value == "0")
//    {
//        objhdnPanelPosition.value = 1;
        if (objImage.innerText == "VIEW/EDIT")
            objImage.innerText = "CLOSE DETAILS";
        else if (objImage.innerText == "CLOSE DETAILS")
            objImage.innerText = "VIEW/EDIT";
//    }
    /*if(imgBtn.src.match('plus')=='plus')
    {
    objImage.src="../../App_Themes/SignPoster/images/minus_sign.gif";        
    }
    else if(imgBtn.src.match('minus')=='minus')
    {
    objImage.src="../../App_Themes/SignPoster/images/plus_sign.gif";
    }*/

}

function fnchangemouse(button) {
    var obj = document.getElementById(button);
    obj.style.cursor = "hand";
}

function fnOpenViewCampaignOnMap()
{
    window.open("../../ViewCampaignOnMap.aspx",'ViewCampaignOnMap',"toolbar=no,location=no,scrollbars=yes,resizable=yes,width=900,height=600,left=50,top=50;");  
}

function fnOpenStreetView(latitude, longitude)
{
    window.open("http://maps.google.co.uk/?layer=c&cbll="+latitude+","+longitude+"&cbp=12,0,0,0,0",'GoogleStreetView',"toolbar=yes,location=yes,scrollbars=yes,resizable=yes,width=900,height=600,left=50,top=30;");
}

//function fnViewOnMapClick(lnkViewEdit)
//{
//    debugger;
//    var objViewEdit = document.getElementById(lnkViewEdit);
//    if(objViewEdit.innerText == "CLOSE DETAILS")
//        objViewEdit.innerText = "CLOSE DETAILS";
//    else if(objViewEdit.innerText == "VIEW/EDIT")
//        objViewEdit.innerText = "VIEW/EDIT";
//}

function clearText() {
    document.getElementById(getBudgetClientID()).value = "";
}

function resetText() {

    var text = document.getElementById(getBudgetClientID());
    if (text.value == "")
        text.value = "£";
}

function ShowMap() {
    eval(formatImageMedia());
    map = new VEMap('VeMap');
    var searchResultDiv = document.getElementById(getdivSearchResultPage());
    
    var hdnButtonCallBackEvent = document.getElementById(gethdnButtonCallBackEventClientID());
    var hdnButtonEvent = document.getElementById(gethdnButtonEventClientID());
    
    try {
        document.getElementById(gettxtPostCodeClientID()).focus();
        var clientTokenVE = document.getElementById(gethdnClientToken());
        var clientTokenValue = clientTokenVE.value;
        map.SetClientToken(clientTokenValue);
        document.getElementById(gethdnClientToken()).value = "Done";
        map.SetDashboardSize(VEDashboardSize.Small);
        searchResultDiv.style.display = 'block';
        map.LoadMap(LA);
        searchResultDiv.style.display = 'none';
        searchResultDiv.style.visibility = 'hidden';
        map.EnableShapeDisplayThreshold(false);
        MoveDashboard(); //To move the dashboard rightside    
    }
    catch (e) {
        alert(e);
    }

    map.SetZoomLevel(6);
    map.AttachEvent("onmousewheel", removezoom); //To remove zoom level after certain extent
    map.AttachEvent("onmousedown", removezoom2);    
    document.getElementById('MSVE_navAction_tinyZoomBar_plus').setAttribute("onClick", removezoom);
    //CR0336
    //Following lines of code is used to search for 'from' string from the URL, where from is one among the QueryString used 
    var location = document.location.toString();
    var searchFor = /from/; //should be always given between backslahes
    var matchPosition = location.search(searchFor); //returns -1 if there is no match else returns the position of the matched string
    if(hdnButtonCallBackEvent.value=='kiauser')
    {
        matchPosition=0;
        hdnButtonEvent.value = 'btnSearch';
        hdnButtonCallBackEvent.value='';
    }
    if(matchPosition != -1) 
    {
        //To show that the map is loading  
        document.getElementById(getMapDiv()).style.display = "block";
        document.getElementById(getMapDiv()).style.filter = "alpha(opacity=50)";
        document.getElementById(getMapDiv()).style.opacity = "0.5";
        document.getElementById(getMapLoadingDiv()).style.display = "block";
        
        //Regular method call to obtain the latitude... etc and other params
        ValidateControls();
        
        //52212 corresponds to Want to buy Billboard call from 3rd party site
        //15193 corresponds to Search call from 3rd party site
        //If the call is from WantToBuyBillboard?, a coremetrics(Conversion) tag is thrown 
        var fromSearch = /52212/;
        var matchPos = location.search(fromSearch);
        if(matchPos != -1)
        {
            try
            {
                psNonCommerceView('Signposter');
            }
            catch(ex)
            {}
        }
    }    
}

function MoveDashboard() {
    var dashboardContainerDiv = document.getElementById('myMap_dashboard');
    if ((dashboardContainerDiv != null) || (typeof (dashboardContainerDiv) == 'myMap_dashboard')) {
        dashboardContainerDiv.style.borderTopWidth = "0px";
        dashboardContainerDiv.style.borderBottomWidth = "0px";
        dashboardContainerDiv.style.borderLeftWidth = "0px";
        dashboardContainerDiv.style.borderRightWidth = "0px";
    }

    if (navigator.appName == "Netscape") {
        //For Mozilla Firefox
        var zoomDiv = document.getElementById('MSVE_zoomDiv');
        if ((zoomDiv != null) || (typeof (zoomDiv) == 'undefined')) {
            zoomDiv.style.cssFloat = "right"; // For Mozilla
        }
        var styleRow = document.getElementById('MSVE_mapStyleRow');
        if ((styleRow != null) || (typeof (styleRow) == 'undefined')) {
            styleRow.style.cssFloat = "right"; // For Mozilla
        }
    }
    else {
        // For Internet Explorer
        if (navigator.appVersion.match("MSIE 6.0") != null) {
            var dashboardContainerDiv = document.getElementById('MSVE_dashboardContainer');
            if ((dashboardContainerDiv != null) || (typeof (dashboardContainerDiv) == 'undefined')) {
                dashboardContainerDiv.style.styleFloat = "right";
            }

            var zoomDiv = document.getElementById('MSVE_zoomDiv');
            if ((zoomDiv != null) || (typeof (zoomDiv) == 'undefined')) {
                zoomDiv.style.right = "-195px";
            }
            var styleRow = document.getElementById('MSVE_mapStyleRow');
            if ((styleRow != null) || (typeof (styleRow) == 'undefined')) {
                styleRow.style.right = "43px";
            }
        }
        else {
            var dashboardContainerDiv = document.getElementById('MSVE_dashboardContainer');
            if ((dashboardContainerDiv != null) || (typeof (dashboardContainerDiv) == 'undefined')) {
                dashboardContainerDiv.style.styleFloat = "right";
            }

            var zoomDiv = document.getElementById('MSVE_zoomDiv');
            if ((zoomDiv != null) || (typeof (zoomDiv) == 'undefined')) {
                zoomDiv.style.right = "-200px";
            }
            var styleRow = document.getElementById('MSVE_mapStyleRow');
            if ((styleRow != null) || (typeof (styleRow) == 'undefined')) {
                styleRow.style.right = "33px";
            }
        }
    }
}

function removethem() {
    document.getElementById('MSVE_navAction_tinyZoomBar_plus').style.visibility = 'hidden';
}

function bringback() {
    document.getElementById('MSVE_navAction_tinyZoomBar_plus').style.visibility = 'visible';
}

function removezoom(e) {
    if (e.zoomLevel == mapRestrictionZoomLevel) {
        if (e.mouseWheelChange < 0 && document.getElementById('MSVE_navAction_tinyZoomBar_plus').style.visibility == 'hidden') {
            map.SetZoomLevel(mapRestrictionZoomLevel - 1);
            bringback();
            //            if (Opportunities != null)
            //                onSucessMyPlans();
            return false;
        }
        //        if (Opportunities != null)
        //            onSucessMyPlans();
        removethem();
        return true;
    }
    else if (e.zoomLevel < mapRestrictionZoomLevel) {
        bringback();
        //        if (Opportunities != null)
        //            onSucessMyPlans();
        return false;
    }
    else {
        map.SetZoomLevel(mapRestrictionZoomLevel);
        removethem();
        //        if (Opportunities != null)
        //            onSucessMyPlans();
        return true;
    }

}

function removezoom2(e) {
    //    if (Opportunities != null)
    //        onSucessMyPlans();
    if (e.zoomLevel <= mapRestrictionZoomLevel) {
        return false;
    }
    else (e.zoomLevel = mapRestrictionZoomLevel)
    {
        return true;
    }

}

function CheckRefreshButton() {
    var RefreshMap = document.getElementById(getlnkRefreshMap());
    var hdnButtonEvent = document.getElementById(gethdnButtonEventClientID());

    if (RefreshMap.className == '') {
        var TransportLink = document.getElementById(getlnkTransport());
        TransportLink.className = '';
        TansportClick = true;
        var SchoolLink = document.getElementById(getlnkSchool());
        SchoolLink.className = '';
        SchoolClick = true;
        var AttractionLink = document.getElementById(getlnkAttraction());
        AttractionLink.className = '';
        AttractionClick = true;
        hdnButtonEvent.value = 'btnSearch';
        RefreshMap.className = 'disabled';
        GetMapCenter();
        return true;
    }
    else {
        return false;
    }
}

function GetMapCenter() {
    var hdnLat = document.getElementById(gethdnLatitude());
    var hdnLon = document.getElementById(gethdnLongitude());
    var hdnPostalCode = $get(gethdnPostalCode());

    map.DeleteAllPolygons(); //deletes all the shapes & polygons which are before
    map.DeleteAllPolylines();
    map.DeleteAllShapes();

    var center = map.GetCenter();
    var latitude = center.Latitude;
    var longitude = center.Longitude;
    Refreshwhere = new VELatLong(latitude, longitude);

    hdnLat.value = latitude;
    hdnLon.value = longitude;
    hdnPostalCode.value = '';

    map.FindLocations(Refreshwhere, LocationCallback);
}

function LocationCallback(locations) {
    var ImageUrl="../../App_Themes/SignPoster/images/PIN_youarehere.gif";
    var place = null;
    if (locations != null) {
        for (var i = 0; i < locations.length; i++) {
            place = locations[i].Name;
        }

        origin = new VEShape(VEShapeType.Pushpin, Refreshwhere);
        origin.SetDescription(place);
        var spec = new VECustomIconSpecification();
        spec.CustomHTML = "<div class='custIconYouAreHere' ><img src='"+ImageUrl+"' /></div>"; 
        spec.Image = '../../App_Themes/SignPoster/images/PIN_youarehere.gif';
        origin.SetCustomIcon(spec);
        map.AddShape(origin);
    }
    else {
        origin = new VEShape(VEShapeType.Pushpin, Refreshwhere);
        var spec = new VECustomIconSpecification();
        spec.CustomHTML = "<div class='custIconYouAreHere' ><img src='"+ImageUrl+"' /></div>"; 
        spec.Image = '../../App_Themes/SignPoster/images/PIN_youarehere.gif';
        origin.SetCustomIcon(spec);
        map.AddShape(origin);
    }

    FindOpportunity();
}

function RefreshMap() {
    var RefreshMap = document.getElementById(getlnkRefreshMap());
    RefreshMap.className = '';
    return false;
}

function FindLocation() {
    try {
         var hdnButtonCallBackEvent = document.getElementById(gethdnButtonCallBackEventClientID());
         hdnButtonCallBackEvent.value='callback';
        var where = document.getElementById(gettxtPostCodeClientID()).value + ',UK';
        //        map.Find(what, where, type [VEFindType.Business], layer [base map], startIndex [0], numberOfResults [10], showResults[true], createResults [true], useDefaultDisambiguation [true], setBestMapView [true], callback)
        var combo = getMediaClient();
        var mediatype = combo.SelectedItem.Value;
        if (mediatype == MEDIA_TYPE_ID_POSTER) {
            map.Find(null, where, null, null, null, null, null, null, true, false, findCallback);
        }
        else {
            map.Find(null, where, null, null, null, null, null, null, true, false, findCallback);
        }
        map.AttachEvent("onendpan", RefreshMap);
        //map.AttachEvent("onclick",OnPreClick);          
    }
    catch (e) {
        alert(e);
    }
}

function SetHiddenValues() {
    var combo = getMediaClient();
    var mediatype = combo.SelectedItem.Value;

//    var distanceCombo = getdrpClientID();
//    var distance = distanceCombo.SelectedItem.Value;
//    var Distance = distanceCombo.SelectedItem.Text;  

//    if (distance == 'Select') {
//        distance = '1';
//        distanceunit = '1 Mile';
//    }


    var formattype = "";
//    var formatCombo = getFormatCombo();
//    var formatPosterCombo = getrdcSelectFormat();
//    var formatBusCombo = getrdcSelectFormatBus();

//    if (mediatype == MEDIA_TYPE_ID_BUS) {
//        formattype = formatBusCombo.SelectedItem.Value;
//    }
//    else {
//        formattype = formatPosterCombo.SelectedItem.Value;
//    }

    var budget = document.getElementById(getBudgetClientID()).value;
    if (budget == "") {
        budget = 0;
    }

//    if (isNaN(formattype)) {
//        formattype = "";
//    }

    var startdate = document.getElementById(getStartDateClientID()).value;
    var postCode = document.getElementById(gettxtPostCodeClientID()).value;

    var hdnStartDate = $get(gethdnStartDate());
    var hdnPostalCode = $get(gethdnPostalCode());
//    var hdnDistance = $get(gethdnDistance());
//    var hdnDistanceUnit = $get(gethdnDistanceUnit());
    var hdnMediaType = $get(gethdnMediaType());
    var hdnFormatType = $get(gethdnFormatType());
    var hdnBudget = $get(gethdnBudget());


    hdnStartDate.value = startdate;
    hdnPostalCode.value = postCode;
//    hdnDistance.value = distance;
//    hdnDistanceUnit.value = distanceunit;
    hdnMediaType.value = mediatype;
    if(hdnFormatType.value=='')
       hdnFormatType.value = formattype;
    hdnBudget.value = budget;

    if (mediatype == MEDIA_TYPE_ID_POSTER) 
        setTimeout("SetZoomLevelPoster();", 500);
    else 
        setTimeout("SetZoomLevelBus();", 500);    
}

function GetDetails(places) {
    var ImageUrl="../../App_Themes/SignPoster/images/PIN_youarehere.gif";
    document.getElementById(gettxtPostCodeClientID()).value = places[0].Name;
    origin = new VEShape(VEShapeType.Pushpin, places[0].LatLong); //To find the origin and place a pushpin in the latitude and longitude
    origin.SetDescription(places[0].Name);
    var spec = new VECustomIconSpecification();
    spec.CustomHTML = "<div class='custIconYouAreHere' ><img src='"+ImageUrl+"' /></div>"; 
    spec.Image = '../../App_Themes/SignPoster/images/PIN_youarehere.gif';    
    if (document.location.toString().endsWith("ManageAccount_MyPlans.aspx") ||
        document.location.toString().endsWith("ManageAccount_MyCampaign.aspx") ||
        document.location.toString().endsWith("ViewCampaignOnMap.aspx"))
        spec.Image = spec.Image.replace("../../", "");
    origin.SetCustomIcon(spec);
    map.AddShape(origin);
    var l1 = places[0].LatLong;
    Lat = l1.Latitude;
    Lon = l1.Longitude;

    /*To get the latitude and longitude for the given search criteria*/
    var hdnLat = document.getElementById(gethdnLatitude());
    var hdnLon = document.getElementById(gethdnLongitude());

    hdnLat.value = Lat;
    hdnLon.value = Lon;

    /*Set Hidden values*/
    SetHiddenValues();

    var ffv = 0;
    var ffn = "Firefox/"
    var ffp = navigator.userAgent.indexOf(ffn);
    if (ffp != -1) {
        ffv = parseFloat(navigator.userAgent.substring(ffp + ffn.length));
    }

    // If we're using Firefox 1.5 or above override 
    // the Virtual Earth drawing functions to use SVG
    if (ffv >= 1.5) {
        Msn.Drawing.Graphic.CreateGraphic = function(f, b) { return new Msn.Drawing.SVGGraphic(f, b) }
    }

    /* To draw circle based on the drive time*/

    //        var pos = distanceunit.indexOf(DRIVETIME_CONSTANT);
    //        if (pos > 0 && mediatype != MEDIA_TYPE_ID_BUS)
    //        {
    //            var points = GetCirclePoints( new VELatLong(Lat,Lon), distance);

    //            for (var zz=0; zz < points.length; zz++)
    //            {
    //                map.AddPolygon(GetFilledPolygon(points[zz]));
    //            }
    //        }

    FindOpportunity();
}

function findCallback(layer, resultsArray, places, hasMore, veErrorMessage) {
    var hdnButtonCallBackEvent = document.getElementById(gethdnButtonCallBackEventClientID());
    hdnButtonCallBackEvent.value='';
    map.DeleteAllPolygons(); //deletes all the shapes & polygons which are before
    map.DeleteAllPolylines();
    map.DeleteAllShapes();
    var placeName = places[0].Name.toUpperCase().replace(' ', '');
    var where = document.getElementById(gettxtPostCodeClientID()).value.toUpperCase().replace(' ', '');

    if (places != null && placeName != 'UNITEDKINGDOM, UNITED KINGDOM') {
        GetDetails(places);
    }
    else if (placeName == 'UNITEDKINGDOM, UNITED KINGDOM' && placeName == where) {
        GetDetails(places);
    }
    else {
        alert("Please enter valid postcode");
        $get(gethdnRefresh()).value = false;
        return false;
    }
}



function GetCirclePoints(impactPoint, radius) {
    var R = 3959.872469777; // earth's mean radius in miles
    var lat = (impactPoint.Latitude * Math.PI) / 180; //rad
    var lon = (impactPoint.Longitude * Math.PI) / 180; //rad
    var d = parseFloat(radius) / R;  // d = angular distance covered on earth's surface
    var locs1 = new Array();
    var locs2 = new Array();
    var locs = new Array();
    var alreadyalerted = false;
    var absLongBoundary = 180;
    var absLatBoundary = 89.99995;

    for (x = 0; x <= 360; x++) {
        var p2 = new VELatLong(
        0)
        brng = x * Math.PI / 180; //rad
        p2.Latitude = Math.asin(Math.sin(lat) * Math.cos(d) + Math.cos(lat) * Math.sin(d) * Math.cos(brng));
        p2.Longitude = ((lon + Math.atan2(Math.sin(brng) * Math.sin(d) * Math.cos(lat), Math.cos(d) - Math.sin(lat) * Math.sin(p2.Latitude))) * 180) / Math.PI;
        p2.Latitude = (p2.Latitude * 180) / Math.PI;

        var absLong = Math.abs(p2.Longitude);
        var absLat = Math.abs(p2.Latitude);
        if (absLong > absLongBoundary || absLat > absLatBoundary) {
            if (absLong > absLongBoundary) {
                if (p2.Longitude > 0)
                    p2.Longitude = (p2.Longitude - absLongBoundary) - absLongBoundary;
                else
                    p2.Longitude = (p2.Longitude + absLongBoundary) + absLongBoundary;
            }
            if (absLat > absLatBoundary) {
                if (p2.Latitude > 0)
                    p2.Latitude = (p2.Latitude - absLatBoundary) - absLatBoundary;
                else
                    p2.Latitude = (p2.Latitude + absLatBoundary) + absLatBoundary;
            }
            locs2.push(p2);
        }
        else {
            locs1.push(p2);
        }
    }
    locs.push(locs1);
    locs.push(locs2);
    return locs;
}

//generates a filled in polygon based on passed in points
function GetFilledPolygon(points) {
    var poly = new VEPolygon(polygonID, points);
    polygonID++;

    poly.SetOutlineWidth(1);
    poly.SetOutlineColor(new VEColor(255, 0, 0, 1));
    poly.SetFillColor(new VEColor(255, 0, 0, 0.01));
    return poly;
}

function FindOpportunity() {
    var hdnRefresh = $get(gethdnRefresh());
    if (hdnRefresh) {
        hdnRefresh.value = (new Date()).getTime();
        __doPostBack(gethdnRefresh(), '');
    }
}

function FormatLoad() {
    var hdnRefresh = $get(gethdnFormatRefresh());
    if (hdnRefresh) {
        hdnRefresh.value = (new Date()).getTime();
        __doPostBack(gethdnFormatRefresh(), '');
    }
}

function OnPreClick(e) {
    // This function filters mouse clicks and trigger the real OnClick function, 
    //only for the pushpin you selected.    
    if (e.elementID != null) {
        var shape = map.GetShapeByID(e.elementID);
        if (shape && clickablePushpins[shape.GetID()]) {
            // Let's call the real click handler. We also pass it the shape, since we already retrieved it...
            callPopUp(e);
        }
    }
}

function callPopUp(e) {
    if (e.elementID != null) {
        var shape = map.GetShapeByID(e.elementID);
        var info = "";

        fnShowPosterDetails(shape.GetTitle());
        return false;
    }
    return false;
}

function fnShowPosterDetails(oppGuid) {
    document.getElementById(getpnlAvailabilityDetails()).style.display = "none";
    fnPopulate(oppGuid);
}
function fnShowPosterDetailsMap(oppGuid) {
    document.getElementById(getpnlAvailabilityDetails()).style.display = "none";
    var fps = $get(gethdnBoolFPS());
    fps.value = "2";
    fnPopulate(oppGuid);
}

function fnPopulate(opportunityGuid) {
    var hdnOpportunity = $get(gethdnOpportunity());
    hdnOpportunity.value = opportunityGuid;

    var hdnRefresh = $get(gethdnRefreshOpportunity());
    if (hdnRefresh) {
        hdnRefresh.value = (new Date()).getTime();
        __doPostBack(gethdnRefreshOpportunity(), '');
    }
}

function onSucess(strOpportunity) {
    if (strOpportunity != "") {
        var oppDetails = strOpportunity.split('+**+');
        var hdnButtonEvent = document.getElementById(gethdnButtonEventClientID());
        var hdnFormatType = document.getElementById(gethdnFormatType());
        var combo = getMediaClient();
        var mediatype = combo.SelectedItem.Value;
        var FormatPoster = document.getElementById(getulFormatPosterClientID());
        var FormatBus = document.getElementById(getulFormatBusClientID());
        var maxFormatType = oppDetails[0];
        baseLayer.DeleteAllShapes();
        polygonLayer.DeleteAllShapes();
//        map.DeleteAllPolygons(); //deletes all the shapes & polygons which are before
//        map.DeleteAllPolylines();
//        map.DeleteAllShapes();
        var xmlfile = $get(gethdnXMLFileClientID());
        xmlfile.value = oppDetails[2];
        var hdnBusShelterSelect = document.getElementById(gethdnBusShelterSelectClientID());
        mapStyle = map.GetMapStyle();

        if (xmlfile.value != "") {
            try {
                var veLayerSpec = new VEShapeSourceSpecification(VEDataType.GeoRSS, "../../" + xmlfile.value, baseLayer);
                map.ImportShapeLayerData(veLayerSpec, cluster);                
                baseLayer.Hide();
            }
            catch (e) {
                alert(e);
            }

            // Second shape layer to store the clustered data
            if (clusterLayer._mapGuid == null) {
                map.AddShapeLayer(clusterLayer);

            }
        }
    }
    else {
        //        alert("There are no posters currently available in this area, please search again");
        //        var hdnLat = document.getElementById(gethdnLatitude());
        //        var hdnLon = document.getElementById(gethdnLongitude());       
        //        var center = new VELatLong(hdnLat.value, hdnLon.value); 
        //        var initView = new VEMapViewSpecification(center,11);
        //        map.SetMapView(initView);                    
        //        return false;
    }

    if (mediatype == MEDIA_TYPE_ID_POSTER) //"Posters"
    {        
        map.AttachEvent("onendzoom", cluster);
        if (maxFormatType != "0") {
            if (hdnButtonEvent.value == "btnSearch" ) {
                MediaPoster(maxFormatType, "");
            }
            var location = document.location.toString();
            var searchFor = /from/; //should be always given between backslahes
            var matchPosition = location.search(searchFor); //returns -1 if there is no match else returns the position of the matched string
            if(matchPosition != -1) 
            {
                MediaPoster(maxFormatType, "");
            }
        }

        MediaFormatCount(oppDetails[1], oppDetails[3]);
    }
    else if (mediatype == MEDIA_TYPE_ID_BUS) {        
        if (maxFormatType != "0") {
            if (hdnButtonEvent.value == "btnSearch") {
                MediaBus(maxFormatType, "");
            }            
           
            var location = document.location.toString();
            var searchFor = /from/; //should be always given between backslahes
            var matchPosition = location.search(searchFor); //returns -1 if there is no match else returns the position of the matched string
            if(matchPosition != -1) 
            {
                MediaBus(maxFormatType, "");
            }
        }

        MediaFormatCount(oppDetails[1], oppDetails[3]);

        if (xmlfile.value != "") {
            if (oppDetails.length > 2 && hdnBusShelterSelect.value=="") {
                var polygonXmlFile = oppDetails[4];
                AddPolygonFromXml(polygonXmlFile);
            }
        }
    }
    hdnButtonEvent.value = '';
    hdnFormatType.value='';

}

function ChangeMediaPoster(item) {

    MediaPoster(item.Value, "Change");
}

function ChangeMediaBus(item) {

    MediaBus(item.Value, "Change");
}

function OnFormatSelect(lblFormat, hdnButtonEvent, format) {
    document.getElementById(hdnButtonEvent).value = 'lnkFormat';    
    var objFormat = document.getElementById(lblFormat);
    if (objFormat.value != '0') {
        if ((format == MEDIA_TYPE_ID_BUSREAR) || (format == MEDIA_TYPE_ID_BUSSIDELINER) || (lblFormat.endsWith('BusShelter1')) ) {
            MediaBus(format, "");
        }
        else {
            MediaPoster(format, "");
        }

        FormatLoad();
    }
}

function MediaFormatCount(FormatCost, FormatCount) {
    var lnk4Sheet = document.getElementById(getlnk4SheetClientID());
    var lnk6Sheet = document.getElementById(getlnk6SheetClientID());
    var lnk48Sheet = document.getElementById(getlnk48SheetClientID());
    var lnk96Sheet = document.getElementById(getlnk96SheetClientID());
    var lnkPBSheet = document.getElementById(getlnkPBSheetClientID());
    var lnkBusShelter = document.getElementById(getlnkBusShelterClientID());
    var lnkBusRearSheet = document.getElementById(getlnkBusRearSheetClientID());
    var lnkBusLinearSheet = document.getElementById(getlnkBusLinearSheetClientID());
    var lnkBusShelter1 = document.getElementById(getlnkBusShelter1ClientID());

    FormatArray = FormatCost.split(',');
    FormatCountArray = FormatCount.split(',');

    for (index = 0; index < FormatArray.length; index++) {
        // Format --> OppGuid_*_address_*_latitude_*_longitude
        itemArray = FormatCountArray[index].split(':');
        costArray = FormatArray[index].split(':');

        if (itemArray[0] == MEDIA_TYPE_ID_96SHEET) {
            if ((itemArray[1] != '0') && (costArray[1] != '0')) {
                lnk96Sheet.innerText = '96 Sheet (from £' + costArray[1] + ')';
                lnk96Sheet.value = itemArray[1];
            }
            else {
                lnk96Sheet.innerText = '96 Sheet (not available)';
                lnk96Sheet.value = itemArray[1];
            }
        }
        else if (itemArray[0] == MEDIA_TYPE_ID_4SHEET) {
            if ((itemArray[1] != '0') && (costArray[1] != '0')) {
                lnk4Sheet.innerText = '4 Sheet (from £' + costArray[1] + ')';
                lnk4Sheet.value = itemArray[1];
            }
            else {
                lnk4Sheet.innerText = '4 Sheet (not available)';
                lnk4Sheet.value = itemArray[1];
            }
        }
        else if (itemArray[0] == MEDIA_TYPE_ID_48SHEET) {
            if ((itemArray[1] != '0') && (costArray[1] != '0')) {
                lnk48Sheet.innerText = '48 Sheet (from £' + costArray[1] + ')';
                lnk48Sheet.value = itemArray[1];
            }
            else {
                lnk48Sheet.innerText = '48 Sheet (not available)';
                lnk48Sheet.value = itemArray[1];
            }
        }
        else if (itemArray[0] == MEDIA_TYPE_ID_6SHEET) {
            if ((itemArray[1] != '0') && (costArray[1] != '0')) {
                lnk6Sheet.innerText = '6 Sheet (from £' + costArray[1] + ')';
                lnk6Sheet.value = itemArray[1];
            }
            else {
                lnk6Sheet.innerText = '6 Sheet (not available)';
                lnk6Sheet.value = itemArray[1];
            }
        }
        else if (itemArray[0] == MEDIA_TYPE_ID_PHONEBOX) {
            if ((itemArray[1] != '0') && (costArray[1] != '0')) {
                lnkPBSheet.innerText = 'Phone Box (from £' + costArray[1] + ')';
                lnkPBSheet.value = itemArray[1];
            }
            else {
                lnkPBSheet.innerText = 'Phone Box (not available)';
                lnkPBSheet.value = itemArray[1];
            }
        }
        else if (itemArray[0] == MEDIA_TYPE_ID_BUSSHELTER) {
            if ((itemArray[1] != '0') && (costArray[1] != '0')) {
                lnkBusShelter.innerText = 'Bus Shelter (from £' + costArray[1] + ')';
                lnkBusShelter.value = itemArray[1];
                lnkBusShelter1.innerText = 'Bus Shelter (from £' + costArray[1] + ')';
                lnkBusShelter1.value = itemArray[1];
            }
            else {
                lnkBusShelter.innerText = 'Bus Shelter (not available)';
                lnkBusShelter.value = itemArray[1];
                lnkBusShelter1.innerText = 'Bus Shelter (not available)';
                lnkBusShelter1.value = itemArray[1];
            }
        }
        else if (itemArray[0] == MEDIA_TYPE_ID_BUSSIDELINER) {
            if ((itemArray[1] != '0') && (costArray[1] != '0')) {
                lnkBusLinearSheet.innerText = 'Street Liner (from £' + costArray[1] + ')';
                lnkBusLinearSheet.value = itemArray[1];
            }
            else {
                lnkBusLinearSheet.innerText = 'Street Liner (not available)';
                lnkBusLinearSheet.value = itemArray[1];
            }
        }
        else if (itemArray[0] == MEDIA_TYPE_ID_BUSREAR) {
            if ((itemArray[1] != '0') && (costArray[1] != '0')) {
                lnkBusRearSheet.innerText = 'Standard Rear (from £' + costArray[1] + ')';
                lnkBusRearSheet.value = itemArray[1];
            }
            else {
                lnkBusRearSheet.innerText = 'Standard Rear (not available)';
                lnkBusRearSheet.value = itemArray[1];
            }
        }
    }
}

function MediaBus(media, eventHand) {
    var imgbtnBusStreetLiner = document.getElementById(getimgbtnBusStreetLinerClientID());
    var imgbtnBusRear = document.getElementById(getimgbtnBusRearClientID());
    var imgBusShelter1 = document.getElementById(getimgBusShelter1ClientID());

    imgbtnBusStreetLiner.className = '';
    imgbtnBusRear.className = '';
    imgBusShelter1.className = '';
//    var formatBusCombo = getrdcSelectFormatBus();

    var hdnFormatType = document.getElementById(gethdnFormatType());
    if (hdnFormatType != null) {
        hdnFormatType.value = media;
    }

//    if ((formatBusCombo.SelectedItem != null) && formatBusCombo.SelectedItem.Value != media) {
//        formatBusCombo.FindItemByValue(media).Select();
//    }

    if (media == MEDIA_TYPE_ID_BUSSIDELINER) {
        imgbtnBusStreetLiner.className = 'selected';
    }
    else if (media == MEDIA_TYPE_ID_BUSREAR) {
        imgbtnBusRear.className = 'selected';
    }
     else if (media == MEDIA_TYPE_ID_BUSSHELTER) {
        imgBusShelter1.className = 'selected';        
    }

}

function MediaPoster(media, eventHand) {

    var img4Sheet = document.getElementById(getimg4SheetClientID());
    var img6Sheet = document.getElementById(getimg6SheetClientID());
    var img48Sheet = document.getElementById(getimg48SheetClientID());
    var img96Sheet = document.getElementById(getimg96SheetClientID());
    var imgPBSheet = document.getElementById(getimgPBSheetClientID());
    var imgBusShelter = document.getElementById(getimgBusShelterClientID());

    img48Sheet.className = '';
    img4Sheet.className = '';
    img6Sheet.className = '';
    img96Sheet.className = '';
    imgBusShelter.className = '';
    imgPBSheet.className = '';

    var hdnFormatType = document.getElementById(gethdnFormatType());

    if (hdnFormatType != null) {
        hdnFormatType.value = media;
    }
//    var formatPosterCombo = getrdcSelectFormat();
//    if ((formatPosterCombo.SelectedItem != null) && formatPosterCombo.SelectedItem.Value != media) {
//        formatPosterCombo.FindItemByValue(media).Select();
//    }


    if (media == MEDIA_TYPE_ID_4SHEET) {
        img4Sheet.className = 'selected';
    }
    else if (media == MEDIA_TYPE_ID_96SHEET) {
        img96Sheet.className = 'selected';
    }
    else if (media == MEDIA_TYPE_ID_48SHEET) {
        img48Sheet.className = 'selected';
    }
    else if (media == MEDIA_TYPE_ID_6SHEET) {
        img6Sheet.className = 'selected';
    }
    else if (media == MEDIA_TYPE_ID_PHONEBOX) {
        imgPBSheet.className = 'selected';
    }
    else if (media == MEDIA_TYPE_ID_BUSSHELTER) {
        imgBusShelter.className = 'selected';
    }
}

function AddPolygonFromXml(polygonXmlFile) {
    var mapStyle = map.GetMapStyle();
    polygonXmlFile = "../../" + polygonXmlFile;
    if (document.location.toString().endsWith("ManageAccount_MyPlans.aspx") ||
        document.location.toString().endsWith("ManageAccount_MyCampaign.aspx") ||
        document.location.toString().endsWith("ViewCampaignOnMap.aspx")) polygonXmlFile = polygonXmlFile.replace("../../", "");
//    else
//    {
//       map.DeleteAllPolygons(); //deletes all the shapes & polygons which are before
//       map.DeleteAllPolylines();
//       map.DeleteAllShapes();
//    }
    var polygonLayerSpec = new VEShapeSourceSpecification(VEDataType.GeoRSS, polygonXmlFile, polygonLayer);
    map.ImportShapeLayerData(polygonLayerSpec, SetPolygonStyle, false);
}

function SetPolygonStyle() {
    var shapeCount = polygonLayer.GetShapeCount();
    var i = 0;
    var shape;
    for (i = 0; i < shapeCount; i++) {
        shape = polygonLayer.GetShapeByIndex(i);
        shape.HideIcon();
        shape.SetLineColor(new VEColor(255, 0, 0, 1));
        shape.SetLineWidth(1);
        shape.SetFillColor(new VEColor(255, 0, 0, 0.1));
        try {
            var hdnPolygonPoints = document.getElementById(gethdnPolygonPoints());
            if (i == 0) hdnPolygonPoints.value = "";
            var latLangs = shape.GetPoints();
            for (j = 0; j < latLangs.length; j++) {
                var pixel = map.LatLongToPixel(latLangs[j]);
                hdnPolygonPoints.value += pixel.x + ";" + pixel.y + ";";
            }
            hdnPolygonPoints.value += "&";
        }
        catch (ex) { }
    }
    if (!(document.location.toString().endsWith("ManageAccount_MyPlans.aspx") ||
        document.location.toString().endsWith("ManageAccount_MyCampaign.aspx") ||
        document.location.toString().endsWith("ViewCampaignOnMap.aspx"))) {
        setTimeout("SetZoomLevelBus();", 500);
    }
    return shapeCount;
}

function SetZoomLevelBus() {
    if (!(document.location.toString().endsWith("ManageAccount_MyPlans.aspx") ||
        document.location.toString().endsWith("ManageAccount_MyCampaign.aspx") ||
        document.location.toString().endsWith("ViewCampaignOnMap.aspx"))) {
        var distanceCombo = getdrpClientID();
        var index = distanceCombo.SelectedIndex;
    }

    var hdnLat = document.getElementById(gethdnLatitude());
    var hdnLon = document.getElementById(gethdnLongitude());

    var center = new VELatLong(hdnLat.value, hdnLon.value);

    var initView = new VEMapViewSpecification(center, 11);
    map.SetMapView(initView);
}

function cluster() {

    var gridSize = getGridSize();
    
    if (mapStyle != map.GetMapStyle()) {
        // Store the current map style
        mapStyle = map.GetMapStyle();
    }

    //Fetching the media type to change the title heading
    
//    var mediaID;
   
//    if (document.location.toString().endsWith("ManageAccount_MyPlans.aspx") ||
//        document.location.toString().endsWith("ManageAccount_MyCampaign.aspx") ||
//        document.location.toString().endsWith("ViewCampaignOnMap.aspx"))
//    {
////        var hdnMedia = $get(gethdnMedia());
////        mediaID = hdnMedia.value;

//        // Assign a value other than MEDIA_TYPE_ID_POSTER(=1) and MEDIA_TYPE_ID_BUS(=2)
//        mediaID = 3;
//    }
//    else
//    {
//        var hdnMediaType = $get(gethdnMediaType());
//        mediaID = hdnMediaType.value;
//    }
            
    // Remove all pins from the cluster layer
    clusterLayer.DeleteAllShapes();

    // Calculate the size, in pixels, of the map
    try {
        document.getElementById(gethdnLatitude()).value = map.GetCenter().Latitude;
        document.getElementById(gethdnLongitude()).value = map.GetCenter().Longitude;
    }
    catch (ex) { }
    var mapView = map.GetMapView();
    var bottomRight = map.LatLongToPixel(mapView.BottomRightLatLong);
    var mapWidth = parseInt(Math.ceil(bottomRight.x));
    var mapHeight = parseInt(Math.ceil(bottomRight.y));
    var mom = "";
    var character = 0;
    var spec = new VECustomIconSpecification();
    // var IdentifierField = document.getElementById(gethdnIdentifier());
    var countalpha = new Array();
    //IdentifierField.value = "";

    // Break the map up into a grid
    var numXCells = parseInt(Math.ceil(mapWidth / gridSize));
    var numYCells = parseInt(Math.ceil(mapHeight / gridSize));

    // Create an array to store all the grid data
    var gridCells = new Array(numXCells * numYCells);

    // Initialize the grid array with a structure to store all the data
    for (var i = 0; i < numXCells; i++) {
        for (var j = 0; j < numYCells; j++) {
            gridCells[i + j * numXCells] = { latlong: new VELatLong(0, 0), title: "", description: "", length: 0, icon: "" ,billboardCount: 0,busCount: 0};
        }
    }
    // Iterate through the shapes in the base layer
    for (var cnt = 0; cnt < baseLayer.GetShapeCount(); cnt++) {
        // Convert the shapes latlong to a pixel location        
        var shape = baseLayer.GetShapeByIndex(cnt);
        var latLong = (shape.GetPoints())[0];
        var pixel = map.LatLongToPixel(latLong, map.GetZoomLevel());
        var xPixel = pixel.x;
        var yPixel = pixel.y;
        var sOppID = "";
        var sTempvar = "";
        var formatType="";
        var sThumbImage = "";

        // Check to see whether the shape is within the bounds of the viewable map
        if (mapWidth >= xPixel && mapHeight >= yPixel && xPixel >= 0 && yPixel >= 0) {
            // Calculate the grid position on the map of where the shape is located
            var i = Math.floor(xPixel / gridSize);
            var j = Math.floor(yPixel / gridSize);

            // Calculate the grid location in the array
            var key = i + j * numXCells;
            // Define a standard way to display an individual shape 
            if (gridCells[key].length == 0) {
                titleArray = shape.GetTitle().split("**__**"); 
                formatType=titleArray[1];
                sThumbImage = titleArray[2];
                GetAlpahabet(titleArray[3]);
                gridCells[key].icon = ImageUrl;
                gridCells[key].latlong = latLong;
                var desc = GetDescription(titleArray[0], sThumbImage, shape.GetDescription(), titleArray[1]);
//                if (document.location.toString().endsWith("ManageAccount_MyPlans.aspx") ||
//                    document.location.toString().endsWith("ManageAccount_MyCampaign.aspx") ||
//                    document.location.toString().endsWith("ViewCampaignOnMap.aspx")) desc = shape.GetDescription();
                gridCells[key].description = "<div class='alphabet'>" + titleArray[3] + "</div>&nbsp;" + desc;
                                
                 if(formatType==MEDIA_TYPE_ID_4SHEET||formatType==MEDIA_TYPE_ID_48SHEET||formatType==MEDIA_TYPE_ID_PHONEBOX||formatType==MEDIA_TYPE_ID_BUSSHELTER
                        ||formatType==MEDIA_TYPE_ID_96SHEET|| formatType==MEDIA_TYPE_ID_6SHEET)
                 {
                    gridCells[key].billboardCount++;
                    gridCells[key].title = " " + (gridCells[key].length+1) + " billboard is here <hr />";
                 }
                 else if(formatType==MEDIA_TYPE_ID_BUSSIDELINER||formatType==MEDIA_TYPE_ID_BUSREAR)
                 {
                    gridCells[key].busCount++;
                    gridCells[key].title = " " + (gridCells[key].length+1) + " bus pack is here <hr />";
                 }
//                 if(mediaID == MEDIA_TYPE_ID_POSTER)
//                {
//                    gridCells[key].title = " " + (gridCells[key].length+1) + " billboard is here <hr />";
//                }
//                else if(mediaID == MEDIA_TYPE_ID_BUS)
//                {
//                    gridCells[key].title = " " + (gridCells[key].length+1) + " bus pack is here <hr />";
//                }
//                else
//                {
//                    gridCells[key].title = " " + (gridCells[key].length+1) + " billboard/buspack is here <hr />";
//                }
            }            
            gridCells[key].length++;
            if (gridCells[key].length > 1 && map.GetZoomLevel() <= zoomLimit) {
                if (gridCells[key].length == 2) {
                    gridCells[key].description = "<div class='PushPinDesc'><div style='padding-right: 3px'>" + gridCells[key].description + "<br /><br /><hr /></div></div>";
                }
                //gridCells[key].alpha= gridCells[key].alpha.substring(0,1) + gridCells[key].length;
                titleArray = shape.GetTitle().split("**__**");
                sThumbImage = titleArray[2];
                formatType=titleArray[1];
                
                if(formatType==MEDIA_TYPE_ID_4SHEET||formatType==MEDIA_TYPE_ID_48SHEET||formatType==MEDIA_TYPE_ID_PHONEBOX||formatType==MEDIA_TYPE_ID_BUSSHELTER
                        ||formatType==MEDIA_TYPE_ID_96SHEET|| formatType==MEDIA_TYPE_ID_6SHEET)
                 {
                    gridCells[key].billboardCount++;
                    gridCells[key].title = " " + gridCells[key].length + " billboards are here <hr />";
                 }
                 else if(formatType==MEDIA_TYPE_ID_BUSSIDELINER||formatType==MEDIA_TYPE_ID_BUSREAR)
                 {
                     gridCells[key].busCount++;
                     gridCells[key].title = " " + gridCells[key].length + " bus packs are here <hr />";
                 }
//                if(mediaID == MEDIA_TYPE_ID_POSTER)
//                {
//                    gridCells[key].billboardCount++;
//                    gridCells[key].title = " " + gridCells[key].length + " billboards are here <hr />";
//                }
//                else if(mediaID == MEDIA_TYPE_ID_BUS)
//                {
//                    gridCells[key].busCount++;
//                    gridCells[key].title = " " + gridCells[key].length + " bus packs are here <hr />";
//                }
//                else
//                {
//                    gridCells[key].title = " " + gridCells[key].length + " billboards/buspacks are here <hr />";
//                }
                
                if(gridCells[key].billboardCount>0 && gridCells[key].busCount>0)
                {
                    if(gridCells[key].billboardCount==1 && gridCells[key].busCount==1)
                    {
                        gridCells[key].title = " " + gridCells[key].billboardCount + " billboard and "+ gridCells[key].busCount + " bus pack are here <hr />";
                    }
                    else
                    {
                        gridCells[key].title = " " + gridCells[key].billboardCount + " billboard(s) and "+ gridCells[key].busCount + " bus pack(s) are here <hr />";
                    }
                }

                var desc = GetDescription(titleArray[0], sThumbImage, shape.GetDescription(), titleArray[1]);
//                if (document.location.toString().endsWith("ManageAccount_MyPlans.aspx") ||
//                    document.location.toString().endsWith("ManageAccount_MyCampaign.aspx") ||
//                    document.location.toString().endsWith("ViewCampaignOnMap.aspx")) desc = shape.GetDescription();
                var clusterdesc = "<div class='alphabet'>" + titleArray[3] + "</div>&nbsp;" + desc;
                gridCells[key].description = gridCells[key].description.substring(0, gridCells[key].description.length - 12) +
                    "<br />" + clusterdesc + "<br /><br /><hr /></div></div>";
            }
        }
    }


    for (var key = 0; key < gridCells.length; key++) {
        //        if(gridCells[key].length==1)
        //        {        
        //            gridCells[key].alpha=gridCells[key].alpha.substring(0,1);
        //            var desc=gridCells[key].description.substring(30,gridCells[key].description.length);
        //            gridCells[key].description="<div class='alphabet'>"+gridCells[key].alpha+"</div>"+desc;
        //        }
        try {
            var hdnPushPinPoints = document.getElementById(gethdnPushPinPoints());
            var hdnClusterPoints = document.getElementById(gethdnClusterPoints());
            if (key == 0) {
                hdnPushPinPoints.value = "";
                hdnClusterPoints.value = "";
            }
        } catch (ex) { }
        if (gridCells[key].length > 0) {
            if (gridCells[key].length == 1) {
                var clusterShape = new VEShape(VEShapeType.Pushpin, gridCells[key].latlong);
                clusterShape.SetTitle(gridCells[key].title);
                clusterShape.SetDescription(gridCells[key].description);
                spec.CustomHTML = "<div class='custIconIdentifier' ><img src='"+gridCells[key].icon+"' /></div>"; 
                clusterShape.SetCustomIcon(spec);
                clusterLayer.AddShape(clusterShape);
                try {
                    var hdnPushPinPoints = document.getElementById(gethdnPushPinPoints());
                    var pixel = map.LatLongToPixel(gridCells[key].latlong);
                    hdnPushPinPoints.value += gridCells[key].icon + ";" + pixel.x + ";" + pixel.y + "&";
                }
                catch (ex) { }
            }
            else {                   
                var clusterShape = new VEShape(VEShapeType.Pushpin, gridCells[key].latlong);
                var ImageIcon="../../App_Themes/SignPoster/images/Push_Pin_Multi.gif";
                clusterShape.SetTitle(gridCells[key].title);
                clusterShape.SetDescription(gridCells[key].description);
                if (document.location.toString().endsWith("ManageAccount_MyPlans.aspx") ||
                    document.location.toString().endsWith("ManageAccount_MyCampaign.aspx") ||
                    document.location.toString().endsWith("ViewCampaignOnMap.aspx"))
                    {
                        ImageIcon = ImageIcon.replace("../../", "");
                        spec.CustomHTML = "<div class='custIconIdentifier' ><img src='"+ImageIcon+"' /></div>"; 
                    }
                else
                    spec.CustomHTML = "<div class='custIconIdentifier' ><img src='"+ImageIcon+"' /></div>"; 
                clusterShape.SetCustomIcon(spec);
                clusterLayer.AddShape(clusterShape);                
                try {
                    var hdnClusterPoints = document.getElementById(gethdnClusterPoints());
                    var pixel = map.LatLongToPixel(gridCells[key].latlong);
                    hdnClusterPoints.value += "App_Themes/SignPoster/images/Push_Pin_Multi.gif" + ";" + pixel.x + ";" + pixel.y;
                }
                catch (ex) { }
            }
        }
    }

    //    for(var cnt = 0; cnt < baseLayer.GetShapeCount(); cnt++)
    //    {
    //        // Convert the shapes latlong to a pixel location 
    //        var shape = baseLayer.GetShapeByIndex(cnt);       
    //        var latLong = (shape.GetPoints())[0];
    //        var pixel = map.LatLongToPixel(latLong);
    //        var xPixel = pixel.x;
    //        var yPixel = pixel.y;        
    //        var oldKey;
    //        
    //        // Check to see whether the shape is within the bounds of the viewable map
    //        if(mapWidth >= xPixel && mapHeight >= yPixel) 
    //        {             
    //             // Calculate the grid position on the map of where the shape is located
    //                var i = Math.floor(xPixel/gridSize);
    //                var j = Math.floor(yPixel/gridSize);

    //                // Calculate the grid location in the array
    //                var key = i+j*numXCells;                
    //                
    //                if(key!=oldKey)
    //                {
    //                    var count=1;
    //                }
    //                
    //                if(gridCells[key].length==1)
    //                {               
    //                    countalpha[cnt]=gridCells[key].alpha;
    //                }
    //                else if(gridCells[key].length>1)
    //                {
    //                    countalpha[cnt]=gridCells[key].alpha.substring(0,1)+count;
    //                    count++;
    //                }
    //                
    //                oldKey=key;
    //        }
    //    }    
    //   
    //    IdentifierField.value=countalpha.join();
}

function GetAlpahabet(character) {
    if (character.length > 1) {
        if (character.charCodeAt(0) == 65 && character.charCodeAt(1) <= 90)
            ImageUrl = '../../App_Themes/SignPoster/images/Push_Pin_' + character + '.gif';
        else
            ImageUrl = '../../App_Themes/SignPoster/images/Push_Pin_Multi.gif';
    }
    else {
        if (character.charCodeAt(0) >= 65 && character.charCodeAt(0) <= 90)
            ImageUrl = '../../App_Themes/SignPoster/images/Push_Pin_' + character + '.gif';
        else
            ImageUrl = '../../App_Themes/SignPoster/images/Push_Pin_Multi.gif';
    }
    if (document.location.toString().endsWith("ManageAccount_MyPlans.aspx") ||
        document.location.toString().endsWith("ManageAccount_MyCampaign.aspx") ||
        document.location.toString().endsWith("ViewCampaignOnMap.aspx")) ImageUrl = ImageUrl.replace("../../", "");
}

function GetDescription(oppId, imageSrc, desc, formatType){
    var ImgStyle;
    if (imageSrc == "") {
        imageSrc = "../../App_Themes/SignPoster/images/no_image_avail_bubble.jpg";
        ImgStyle = "border:0px";
    }
    else {
        imageSrc = "../../"+imageSrc;
        ImgStyle = "border:solid 2px #cccccc; width:100px; height:100px;";

    }
    if (document.location.toString().endsWith("ManageAccount_MyPlans.aspx") ||
        document.location.toString().endsWith("ManageAccount_MyCampaign.aspx") ||
        document.location.toString().endsWith("ViewCampaignOnMap.aspx")) 
    {
        //Addded these lines as part of image size set as 100*100
        imageSrc = imageSrc.replace("../../", "");
        if(formatType==MEDIA_TYPE_ID_4SHEET || formatType==MEDIA_TYPE_ID_48SHEET || formatType==MEDIA_TYPE_ID_PHONEBOX
           || formatType==MEDIA_TYPE_ID_BUSSHELTER || formatType==MEDIA_TYPE_ID_96SHEET || formatType==MEDIA_TYPE_ID_6SHEET)
        {
            var description = "<img src='" + imageSrc + "'style='" + ImgStyle + "' alt='' class='align'>" + desc + "<br/></img>";
        }
        else if(formatType==MEDIA_TYPE_ID_BUSSIDELINER||formatType==MEDIA_TYPE_ID_BUSREAR)
        {
            var description = "<img src='" + imageSrc + "'style='" + ImgStyle + "' alt='' class='align'>" + desc + "<br/><br/><br/><br/></img>";
        }    
    }
    else
    {
        var description = "<img src='" + imageSrc + "'style='" + ImgStyle + "' alt='' class='align'>" + desc + "</img>";
        var avLink = "<div ><br /><a class='colorMap' href='#' onclick='fnShowPosterDetailsMap(\"" + oppId + "\")';>Check availability</a></div>";
        description = description + avLink;
    }
   
    return description;
}

function SetZoomLevelPoster() {
    var hdnLat = document.getElementById(gethdnLatitude());
    var hdnLon = document.getElementById(gethdnLongitude());
    var distanceCombo = getdrpClientID();
    var objPanelNo=document.getElementById(getPanelNoClientID());
    var center = new VELatLong(hdnLat.value, hdnLon.value);
    var zoomlevel = new Array(11, 15, 14, 14, 13, 12);
    var index = distanceCombo.SelectedIndex;
    if (index == 0) {        
        if(objPanelNo.value!="")
            index = 5;
        else
            index = 3;
    }
    var initView = new VEMapViewSpecification(center, zoomlevel[index]);
    map.SetMapView(initView);
}

//function FindMapOptions(what)
//{ 
//    var mapview=map.GetMapView(); 
//    var latlong=mapview.BottomRightLatLong;
//    var BottomLatitude=latlong.Latitude;
//    var BottomLongitude=latlong.Longitude;
//    var toplatlong=mapview.TopLeftLatLong;
//     var TopLatitude=toplatlong.Latitude;
//    var TopLongitude=toplatlong.Longitude;
//    var latitude=(BottomLatitude+TopLatitude)/2;
//    var longitude=(BottomLongitude+TopLongitude)/2;
//    var find=document.getElementById(what).innerText;       
////    var center=map.GetCenter();
////    var latitude=center.Latitude;
////    var longitude=center.Longitude;
//    var where=new VELatLong(latitude,longitude); 
//    var clusterShape = new VEShape(VEShapeType.Pushpin, where);
//    
//    
//    switch(find)
//    {
//        case 'Transport':
//            if(Transport===0)
//            {
//                map.Find(find,where,null,TransportLayer,null, null, null, null,true, null, null);
//                clusterShape.SetCustomIcon('../../App_Themes/SignPoster/images/Push_Pin_Bus.png');
//                TransportLayer.AddShape(clusterShape);
//                map.AddShapeLayer(TransportLayer);
//                Transport=1;
//            }
//            else
//            {
//                TransportLayer.DeleteAllShapes();
//                Transport=0;
//            }
//    }  
//            
//}

function ValidatePanelNumber(PanelNo)
{
	var numaric = PanelNo;
	for(var j=0; j<numaric.length; j++)
	{
		  var alphaa = numaric.charAt(j);
		  var hh = alphaa.charCodeAt(0);
		  if((hh > 47 && hh<58) || (hh > 64 && hh<91) || (hh > 96 && hh<123))
		  {
		  }
		else	
		{                         
			return false;
		}
 	} 
 return true;
}


function ValidateControls() {
    document.body.style.cursor = 'default';
    var xmlfile = $get(gethdnXMLFileClientID());
    xmlfile.value = "";
    var oldMessage = "The following details must be entered\n\n";
    var message = "The following details must be entered\n\n";
    var objPostCode = document.getElementById(gettxtPostCodeClientID());
    var objChooseMedia = getMediaClient();
    var searchDiv = document.getElementById(getdivSearchPage());
    var searchResultDiv = document.getElementById(getdivSearchResultPage());
    var FormatPoster = document.getElementById(getulFormatPosterClientID());
    var FormatBus = document.getElementById(getulFormatBusClientID());
    var objPanelNo=document.getElementById(getPanelNoClientID());
    
    var lnk4Sheet = document.getElementById(getlnk4SheetClientID());
    var lnk6Sheet = document.getElementById(getlnk6SheetClientID());
    var lnk48Sheet = document.getElementById(getlnk48SheetClientID());
    var lnk96Sheet = document.getElementById(getlnk96SheetClientID());
    var lnkPBSheet = document.getElementById(getlnkPBSheetClientID());
    var lnkBusShelter = document.getElementById(getlnkBusShelterClientID());
    var lnkBusRearSheet = document.getElementById(getlnkBusRearSheetClientID());
    var lnkBusLinearSheet = document.getElementById(getlnkBusLinearSheetClientID());
    var lnkBusShelter1 = document.getElementById(getlnkBusShelter1ClientID());
    
    var imgbtnBusStreetLiner = document.getElementById(getimgbtnBusStreetLinerClientID());
    var imgbtnBusRear = document.getElementById(getimgbtnBusRearClientID());
    var imgBusShelter1 = document.getElementById(getimgBusShelter1ClientID());
    var img4Sheet = document.getElementById(getimg4SheetClientID());
    var img6Sheet = document.getElementById(getimg6SheetClientID());
    var img48Sheet = document.getElementById(getimg48SheetClientID());
    var img96Sheet = document.getElementById(getimg96SheetClientID());
    var imgPBSheet = document.getElementById(getimgPBSheetClientID());
    var imgBusShelter = document.getElementById(getimgBusShelterClientID());

   
    if (objPostCode.value == "") {
        message += "* Please enter a postcode\n";
    }
    if (objChooseMedia.GetValue() == "-1") {
        message += "* Please select a media type\n";
    }
    if(objPanelNo.value!="")
    {
        var Validate = ValidatePanelNumber(objPanelNo.value);
        if(!Validate)
            message += "* Please enter the correct panel number\n";
    }

    if (message != oldMessage) {
        searchDiv.style.display = 'block';
        searchDiv.style.visibility = 'visible';
        searchResultDiv.style.display = 'none';
        searchResultDiv.style.visibility = 'hidden';
        document.body.style.cursor = 'default';
        alert(message);        
        return false;
    }
    
    else {
        lnk48Sheet.innerHTML="48 Sheet (Loading<IMG id=ctl00_ctl00_cphContent_cphContent_img48Sheet src='../../App_Themes/SignPoster/images/format-selection-loading.gif'>)";
        lnk4Sheet.innerHTML="4 Sheet (Loading<IMG id=ctl00_ctl00_cphContent_cphContent_img4Sheet src='../../App_Themes/SignPoster/images/format-selection-loading.gif'>)";
        lnk6Sheet.innerHTML="6 Sheet (Loading<IMG id=ctl00_ctl00_cphContent_cphContent_img6Sheet src='../../App_Themes/SignPoster/images/format-selection-loading.gif'>)";
        lnk96Sheet.innerHTML="96 Sheet (Loading<IMG id=ctl00_ctl00_cphContent_cphContent_img96Sheet src='../../App_Themes/SignPoster/images/format-selection-loading.gif'>)";
        lnkPBSheet.innerHTML="Phone Box (Loading<IMG id=ctl00_ctl00_cphContent_cphContent_imgPBSheet src='../../App_Themes/SignPoster/images/format-selection-loading.gif'>)";
        lnkBusShelter.innerHTML="Bus Shelter (Loading<IMG id=ctl00_ctl00_cphContent_cphContent_imgBusShelters src='../../App_Themes/SignPoster/images/format-selection-loading.gif'>)";
        lnkBusRearSheet.innerHTML="Standard Rear (Loading<IMG id=ctl00_ctl00_cphContent_cphContent_imgBusRear src='../../App_Themes/SignPoster/images/format-selection-loading.gif'>)";
        lnkBusLinearSheet.innerHTML="Street Liner (Loading<IMG id=ctl00_ctl00_cphContent_cphContent_imgStreetLiner src='../../App_Themes/SignPoster/images/format-selection-loading.gif'>)";
        lnkBusShelter1.innerHTML="Bus Shelter (Loading<IMG id=ctl00_ctl00_cphContent_cphContent_imgBusShelter1 src='../../App_Themes/SignPoster/images/format-selection-loading.gif'>)";
        
        img48Sheet.className = '';
        img4Sheet.className = '';
        img6Sheet.className = '';
        img96Sheet.className = '';
        imgBusShelter.className = '';
        imgPBSheet.className = '';
        imgbtnBusStreetLiner.className = '';
        imgbtnBusRear.className = '';
        imgBusShelter1.className = '';
        
        if (objChooseMedia.GetValue() == "1") {
            FormatPoster.style.display = 'block';
            FormatBus.style.display = 'none';
        }
        else {
            FormatPoster.style.display = 'none';
            FormatBus.style.display = 'block';
        }
        searchDiv.style.display = 'none';
        searchDiv.style.visibility = 'hidden';
        searchResultDiv.style.display = 'block';
        searchResultDiv.style.visibility = 'visible';
        //SelectDefaultFormat();

       //CR0336 Added the if condition to skip showing of named places.
        var location = document.location.toString();
        var searchFor = /from/;
        var matchPosition = location.search(searchFor);
        if(matchPosition == -1)
        {
            /*Added this block of code for Named Places or Autocomplete*/
            if ($get(gethdnRefresh()).value != 'true' || $get(gethdnRefresh()).value == 'false') {
                $get(gethdnRefresh()).value = $get(gethdnRefresh()).value == 'false' ? false : true;
                __doPostBack(gethdnRefresh(), '');
                return false;
            }
        }

        $get(gethdnRefresh()).value = (new Date()).getTime();
        FindLocation();
        return false;
    }
}

function sampleShowMap() {
    //eval(formatImageMedia());
    map = new VEMap('VeMap');
    try {
        var clientTokenVE = document.getElementById(gethdnClientToken());
        var clientTokenValue = clientTokenVE.value;
        map.SetClientToken(clientTokenValue);
        document.getElementById(gethdnClientToken()).value = "Done";
        map.SetDashboardSize(VEDashboardSize.Small);
        map.LoadMap(LA);
        map.EnableShapeDisplayThreshold(false);
        MoveDashboard(); //To move the dashboard rightside        
    }
    catch (e) {
        alert(e);
    }

    map.SetZoomLevel(6);
    map.AttachEvent("onmousewheel", removezoom); //To remove zoom level after certain extent
    map.AttachEvent("onmousedown", removezoom2);
    document.getElementById('MSVE_navAction_tinyZoomBar_plus').setAttribute("onClick", removezoom);
}

function formatImageMedia() {
//    var formatCombo = getFormatCombo();
//    var formatPosterCombo = getrdcSelectFormat();
//    var formatBusCombo = getrdcSelectFormatBus();

    var LocationCombo = getrdcLocation();
    var LocationPosterCombo = getrdcLocationPoster();
    var LocationBusCombo = getrdcLocationBus();

    var combo = getMediaClient();
    var mediatype = combo.SelectedItem.Value;
    var intmediatype = parseInt(mediatype);
    var divWeightCamp = document.getElementById('divWeightCampaign');

    if (intmediatype == MEDIA_TYPE_ID_BUS) //"Buses"
    {

//        formatBusCombo.DomElement.style.display = "block";
//        formatPosterCombo.DomElement.style.display = "none";
//        formatCombo.DomElement.style.display = "none";

        LocationBusCombo.DomElement.style.display = "block";
        LocationPosterCombo.DomElement.style.display = "none";
        LocationCombo.DomElement.style.display = "none";

//        formatBusCombo.FindItemByValue("Select").Select();
        LocationBusCombo.FindItemByValue("Select").Select();

    }
    else if (intmediatype == MEDIA_TYPE_ID_POSTER) {
//        formatBusCombo.DomElement.style.display = "none";
//        formatPosterCombo.DomElement.style.display = "block";
//        formatCombo.DomElement.style.display = "none";

        LocationBusCombo.DomElement.style.display = "none";
        LocationPosterCombo.DomElement.style.display = "block";
        LocationCombo.DomElement.style.display = "none";

//        formatPosterCombo.FindItemByValue("Select").Select();
        LocationPosterCombo.FindItemByValue("Select").Select();
    }
    else {
//        formatBusCombo.DomElement.style.display = "none";
//        formatPosterCombo.DomElement.style.display = "none";
//        formatCombo.DomElement.style.display = "block";

        LocationBusCombo.DomElement.style.display = "none";
        LocationPosterCombo.DomElement.style.display = "none";
        LocationCombo.DomElement.style.display = "block";
    }
}
function sampleValidateControls()
{
    var xmlfile = $get(gethdnXMLFileClientID());
    xmlfile.value = "";
    var oldMessage = "The following details must be entered\n\n";
    var message = "The following details must be entered\n\n";
    var objPostCode = document.getElementById(gettxtPostCodeClientID());
    var objChooseMedia = document.getElementById(getddlMediaClientID());
    
    if (objPostCode.value == "") {
        message += "* Please enter a postcode\n";
    }
    if (objChooseMedia.value == "-1") {
        message += "* Please select a media type\n";
    }
    
    if (message != oldMessage) {
        document.body.style.cursor = 'default';
        alert(message);
        return false;
    }
    
    sampleFindLocation();
    return false;
}

function sampleFindLocation()
{
    try {
        var where = document.getElementById(gettxtPostCodeClientID()).value + ',UK';
        var combo = document.getElementById(getddlMediaClientID());
        var mediatype = combo.value;
        if (mediatype == MEDIA_TYPE_ID_POSTER) {
            map.Find(null, where, null, null, null, null, null, null, true, false, samplefindCallback);
        }
        else {
            map.Find(null, where, null, null, null, null, null, null, true, false, samplefindCallback);
        }
        map.AttachEvent("onendpan", RefreshMap);
        //map.AttachEvent("onclick",OnPreClick);          
    }
    catch (e) {
        alert(e);
    }
}

function samplefindCallback(layer, resultsArray, places, hasMore, veErrorMessage) {
    map.DeleteAllPolygons(); //deletes all the shapes & polygons which are before
    map.DeleteAllPolylines();
    map.DeleteAllShapes();
    var placeName = places[0].Name.toUpperCase().replace(' ', '');
    var where = document.getElementById(gettxtPostCodeClientID()).value.toUpperCase().replace(' ', '');

    if (places != null && placeName != 'UNITEDKINGDOM') {
        sampleGetDetails(places);
    }
    else if (placeName == 'UNITEDKINGDOM' && placeName == where) {
        sampleGetDetails(places);
    }
    else {
        alert("Please enter valid postcode");
        $get(gethdnRefresh()).value = false;
        return false;
    }
}

function sampleGetDetails(places) {
    var ImageUrl="../../App_Themes/SignPoster/images/PIN_youarehere.gif";
    document.getElementById(gettxtPostCodeClientID()).value = places[0].Name;
    origin = new VEShape(VEShapeType.Pushpin, places[0].LatLong); //To find the origin and place a pushpin in the latitude and longitude
    origin.SetDescription(places[0].Name);
    var spec = new VECustomIconSpecification();
    spec.CustomHTML = "<div class='custIconYouAreHere' ><img src='"+ImageUrl+"' /></div>"; 
    spec.Image = '../../App_Themes/SignPoster/images/PIN_youarehere.gif';
    if (document.location.toString().endsWith("ManageAccount_MyPlans.aspx") ||
        document.location.toString().endsWith("ManageAccount_MyCampaign.aspx") ||
        document.location.toString().endsWith("ViewCampaignOnMap.aspx"))
        spec.Image = spec.Image.replace("../../", "");
    origin.SetCustomIcon(spec);
    map.AddShape(origin);
    var l1 = places[0].LatLong;
    Lat = l1.Latitude;
    Lon = l1.Longitude;

    /*To get the latitude and longitude for the given search criteria*/
    var hdnLat = document.getElementById(gethdnLatitude());
    var hdnLon = document.getElementById(gethdnLongitude());

    hdnLat.value = Lat;
    hdnLon.value = Lon;

    /*Set Hidden values*/
    sampleSetHiddenValues();

    var ffv = 0;
    var ffn = "Firefox/"
    var ffp = navigator.userAgent.indexOf(ffn);
    if (ffp != -1) {
        ffv = parseFloat(navigator.userAgent.substring(ffp + ffn.length));
    }

    // If we're using Firefox 1.5 or above override 
    // the Virtual Earth drawing functions to use SVG
    if (ffv >= 1.5) {
        Msn.Drawing.Graphic.CreateGraphic = function(f, b) { return new Msn.Drawing.SVGGraphic(f, b) }
    }

    FindOpportunity();
}

function sampleSetHiddenValues() {
    var combo = document.getElementById(getddlMediaClientID());
    var mediatype = combo.value;

    var distanceCombo = document.getElementById(getddlSelectDistanceClientID());
    var distance = distanceCombo.value;
    var index = distanceCombo.selectedIndex;
    var distanceunit = distanceCombo[index].text;

    if (distance == "-1") {
        distance = '1';
        distanceunit = '1 Mile';
    }


    var formattype = "";
//    var formatCombo = getFormatCombo();
//    var formatPosterCombo = getrdcSelectFormat();
//    var formatBusCombo = getrdcSelectFormatBus();

    if (mediatype == MEDIA_TYPE_ID_BUS) {
        //formattype = formatBusCombo.SelectedItem.Value;
        formattype = "9";
    }
    else {
        //formattype = formatPosterCombo.SelectedItem.Value;
        formattype = "3";
    }

    var budget = document.getElementById(getBudgetClientID()).value;
    if (budget == "") {
        budget = 0;
    }

    if (isNaN(formattype)) {
        formattype = "";
    }

    //var startdate = document.getElementById(getStartDateClientID()).value;
    var postCode = document.getElementById(gettxtPostCodeClientID()).value;

    //var hdnStartDate = $get(gethdnStartDate());
    var hdnPostalCode = $get(gethdnPostalCode());
    var hdnDistance = $get(gethdnDistance());
    var hdnDistanceUnit = $get(gethdnDistanceUnit());
    var hdnMediaType = $get(gethdnMediaType());
    var hdnFormatType = $get(gethdnFormatType());
    
//    var pnlResults = document.getElementById(getpnlResults());
//    pnlResults.style.display = "block";
//    pnlResults.style.visibility = "visible";
    
    var hdnBudget = $get(gethdnBudget());


    //hdnStartDate.value = startdate;
    hdnPostalCode.value = postCode;
    hdnDistance.value = distance;
    hdnDistanceUnit.value = distanceunit;
    hdnMediaType.value = mediatype;
    hdnFormatType.value = formattype;
    hdnBudget.value = budget;

    if (mediatype == MEDIA_TYPE_ID_POSTER)     
        setTimeout("sampleSetZoomLevelPoster();", 500);
    else 
        setTimeout("sampleSetZoomLevelBus();", 500);
            
}

function sampleSetZoomLevelPoster() {
    var hdnLat = document.getElementById(gethdnLatitude());
    var hdnLon = document.getElementById(gethdnLongitude());
    
//    var distanceCombo = getdrpClientID();
    var distanceCombo = document.getElementById(getddlSelectDistanceClientID());
    var center = new VELatLong(hdnLat.value, hdnLon.value);
    var zoomlevel = new Array(11, 15, 14, 14, 13, 12);
    var index = distanceCombo.selectedIndex;
    if (index == 0) {    
        index=3;
    }
    var initView = new VEMapViewSpecification(center, zoomlevel[index]);
    map.SetMapView(initView);
}

function sampleSetZoomLevelBus() {
    if (!(document.location.toString().endsWith("ManageAccount_MyPlans.aspx") ||
        document.location.toString().endsWith("ManageAccount_MyCampaign.aspx") ||
        document.location.toString().endsWith("ViewCampaignOnMap.aspx"))) {
//        var distanceCombo = getdrpClientID();
        var distanceCombo = document.getElementById(getddlSelectDistanceClientID());
        var index = distanceCombo.SelectedIndex;
    }

    var hdnLat = document.getElementById(gethdnLatitude());
    var hdnLon = document.getElementById(gethdnLongitude());

    var center = new VELatLong(hdnLat.value, hdnLon.value);

    var initView = new VEMapViewSpecification(center, 11);
    map.SetMapView(initView);
}

/*Added this function for Named Places*/
function SetLatLong() {
    var isSearchAgainSelected = false;
    var isSelected = false;
    var hdnLat = $get(gethdnLatitude());
    var hdnLon = $get(gethdnLongitude());
    var namedPlaces = document.getElementsByName(getNPListClientID().replaceAll('_', '$'));
    for (var i = 0; i < namedPlaces.length; i++) {
        if (namedPlaces[i].checked) {
            if (namedPlaces[i].value == "0;0") {
                isSearchAgainSelected = true;
            }
            else {
                hdnLat.value = namedPlaces[i].value.split(';')[0];
                hdnLon.value = namedPlaces[i].value.split(';')[1];
                $get(gethdnRefresh()).value = 'true';
                isSelected = true;
                break;
            }
        }
    }
    if (isSearchAgainSelected == false) {
        if (!isSelected) {
            alert('Please choose a location to proceed.');
            return false;
        }
        else {
            map.SetCenter(new VELatLong(hdnLat.value, hdnLon.value));
            SetHiddenValues();
            map.SetCenter(new VELatLong(hdnLat.value, hdnLon.value));
            GetMapCenter();
             map.AttachEvent("onendpan", RefreshMap);
            FindOpportunity();
            return false;
        }
    }
    else {
        $get(gethdnRefresh()).value = 'true';
        ValidateControls();
        return false;
    }
}

/*Added this block of code for AutoComplete*/
function SetMapCenterWithLatLong(latitude, longitude)
{
    var hdnLat = $get(gethdnLatitude());
    var hdnLon = $get(gethdnLongitude());
    hdnLat.value = latitude;
    hdnLon.value = longitude;
    map.SetCenter(new VELatLong(hdnLat.value, hdnLon.value));
    SetHiddenValues();
    map.SetCenter(new VELatLong(hdnLat.value, hdnLon.value));
    GetMapCenter();
    map.AttachEvent("onendpan", RefreshMap);    
    FindOpportunity();
    return false;
}

function SelectDefaultFormat() {
    var tabClientID = document.getElementById(getHiddenFormatSelectorTab());
    var formatClientID = document.getElementById(getHiddenFormatSelector());
    selectedTab = tabClientID.value
    selectedFormat = formatClientID.value
    if ((selectedTab != "") && (selectedFormat != "")) {
        var selected = document.getElementById(selectedTab);
        if (selected != null) {
            selected.className = "SelectedFormat";
        }
    }
    var tabBusClientID = document.getElementById(getHiddenFormatSelectorTabBus());
    var formatBusClientID = document.getElementById(getHiddenFormatSelectorBus());
    selectedTabBus = tabBusClientID.value
    selectedFormatBus = formatBusClientID.value
    if ((selectedTabBus != "") && (selectedFormatBus != "")) {
        var selectedBus = document.getElementById(selectedTabBus);
        if (selectedBus != null) {
            selectedBus.className = "SelectedFormat";
        }
    }
}
function LnkFormatClick(lnkId, format) {

    var tabClientID = document.getElementById(getHiddenFormatSelectorTab());
    document.getElementById(lnkId).className = "SelectedFormat";
    selectedTab = tabClientID.value
    if (selectedTab != null) {
        if (selectedTab != "") {
            var tab = document.getElementById(selectedTab);
        }
        if (tab != null) {
            document.getElementById(selectedTab).className = "UnSelectedCells";
        }

        tabClientID.value = lnkId;

    }
}
function LnkFormatBusClick(lnkId, format) {

    var tabClientID = document.getElementById(getHiddenFormatSelectorTabBus());
    document.getElementById(lnkId).className = "SelectedFormat";
    selectedTab = tabClientID.value
    if (selectedTab != null) {
        if (selectedTab != "") {
            var tab = document.getElementById(selectedTab);
        }
        if (tab != null) {
            document.getElementById(selectedTab).className = "UnSelectedCells";
        }

        tabClientID.value = lnkId;

    }
}


function SelectDefault() {
    var tabClientID = document.getElementById(getHiddenSelectedTab());
    var formatClientID = document.getElementById(getHiddenFormat());
    selectedTab = tabClientID.value
    selectedFormat = formatClientID.value
    if ((selectedTab != "") && (selectedFormat != "")) {
        var selected = document.getElementById(selectedTab);
        if (selected != null) {
            selected.className = "Selected";
            formatDisplay(selectedFormat);
        }
    }
}

function LnkClick(lnkId, format) {

    var tabClientID = document.getElementById(getHiddenSelectedTab());
    var selectFormat = document.getElementById(getHiddenFormat());
    selectedTab = tabClientID.value
    if (selectedTab != null) {
        if (selectedTab != "") {
            var tab = document.getElementById(selectedTab);
        }
        if (tab != null) {
            document.getElementById(selectedTab).className = "UnSelected";
        }

        tabClientID.value = lnkId;
        document.getElementById(lnkId).className = "Selected";
        selectFormat.value = format;
        formatDisplay(format);
    }
}
function formatDisplayNone() {
    document.getElementById(getTabBusShelter()).style.display = "none";
    document.getElementById(getTabBusShelter()).style.visibility = "hidden";
    document.getElementById(getTabPhonebox()).style.display = "none";
    document.getElementById(getTabPhonebox()).style.visibility = "hidden";
    document.getElementById(getTabSheet6()).style.display = "none";
    document.getElementById(getTabSheet6()).style.visibility = "hidden";
    document.getElementById(getTabSheet48()).style.display = "none";
    document.getElementById(getTabSheet48()).style.visibility = "hidden";
    document.getElementById(getTabSheet96()).style.display = "none";
    document.getElementById(getTabSheet96()).style.visibility = "hidden";
    document.getElementById(getTabSheet4()).style.display = "none";
    document.getElementById(getTabSheet4()).style.visibility = "hidden";

    document.getElementById(getTabStreetLiner()).style.display = "none";
    document.getElementById(getTabStreetLiner()).style.visibility = "hidden";
    document.getElementById(getTabBusRear()).style.display = "none";
    document.getElementById(getTabBusRear()).style.visibility = "hidden";
}
function formatDisplay(format) {
    formatDisplayNone();
    if (format == MEDIA_TYPE_ID_4SHEET) {
        document.getElementById(getTabSheet4()).style.display = "block";
        document.getElementById(getTabSheet4()).style.visibility = "visible";
    }
    else if (format == MEDIA_TYPE_ID_96SHEET) {
        document.getElementById(getTabSheet96()).style.display = "block";
        document.getElementById(getTabSheet96()).style.visibility = "visible";
    }
    else if (format == MEDIA_TYPE_ID_48SHEET) {
        document.getElementById(getTabSheet48()).style.display = "block";
        document.getElementById(getTabSheet48()).style.visibility = "visible";
    }
    else if (format == MEDIA_TYPE_ID_6SHEET) {
        document.getElementById(getTabSheet6()).style.display = "block";
        document.getElementById(getTabSheet6()).style.visibility = "visible";
    }
    else if (format == MEDIA_TYPE_ID_PHONEBOX) {
        document.getElementById(getTabPhonebox()).style.display = "block";
        document.getElementById(getTabPhonebox()).style.visibility = "visible";
    }
    else if (format == MEDIA_TYPE_ID_BUSREAR) {
        document.getElementById(getTabBusRear()).style.display = "block";
        document.getElementById(getTabBusRear()).style.visibility = "visible";
    }
    else if (format == MEDIA_TYPE_ID_BUSSIDELINER) {
        document.getElementById(getTabStreetLiner()).style.display = "block";
        document.getElementById(getTabStreetLiner()).style.visibility = "visible";
    }
    else if (format == MEDIA_TYPE_ID_BUSSHELTER) {
        document.getElementById(getTabBusShelter()).style.display = "block";
        document.getElementById(getTabBusShelter()).style.visibility = "visible";
    }

}
function OnClientSelectedIndexChanged(item) {
//    var formatCombo = getFormatCombo();
//    var formatPosterCombo = getrdcSelectFormat();
//    var formatBusCombo = getrdcSelectFormatBus();

    var LocationCombo = getrdcLocation();
    var LocationPosterCombo = getrdcLocationPoster();
    var LocationBusCombo = getrdcLocationBus();
    document.getElementById(getPanelNoClientID()).disabled=false;
    
    var combo = getMediaClient();
    var mediatype = combo.SelectedItem.Value;
    var intmediatype = parseInt(mediatype);
    var divWeightCamp = document.getElementById('divWeightCampaign');


    if (intmediatype == MEDIA_TYPE_ID_BUS) //"Buses"
    {

//        formatBusCombo.DomElement.style.display = "block";
//        formatPosterCombo.DomElement.style.display = "none";
//        formatCombo.DomElement.style.display = "none";

        LocationBusCombo.DomElement.style.display = "block";
        LocationPosterCombo.DomElement.style.display = "none";
        LocationCombo.DomElement.style.display = "none";
        document.getElementById(getPanelNoClientID()).disabled=true;
        LocationBusCombo.Disable();
        LocationPosterCombo.Disable();
        LocationCombo.Disable();       
//        formatBusCombo.FindItemByValue("Select").Select();
        LocationBusCombo.FindItemByValue("Select").Select();

    }
    else if (intmediatype == MEDIA_TYPE_ID_POSTER) {
//        formatBusCombo.DomElement.style.display = "none";
//        formatPosterCombo.DomElement.style.display = "block";
//        formatCombo.DomElement.style.display = "none";

        LocationBusCombo.Enable();
        LocationPosterCombo.Enable();
        LocationCombo.Enable();        
        LocationBusCombo.DomElement.style.display = "none";
        LocationPosterCombo.DomElement.style.display = "block";
        LocationCombo.DomElement.style.display = "none";

//        formatPosterCombo.FindItemByValue("Select").Select();
        LocationPosterCombo.FindItemByValue("Select").Select();
    }
    else {
//        formatBusCombo.DomElement.style.display = "none";
//        formatPosterCombo.DomElement.style.display = "none";
//        formatCombo.DomElement.style.display = "block";

        LocationBusCombo.Enable();
        LocationPosterCombo.Enable();
        LocationCombo.Enable();

        LocationBusCombo.DomElement.style.display = "none";
        LocationPosterCombo.DomElement.style.display = "none";
        LocationCombo.DomElement.style.display = "block";
    }
}

function formatImageMedia() {
//    var formatCombo = getFormatCombo();
//    var formatPosterCombo = getrdcSelectFormat();
//    var formatBusCombo = getrdcSelectFormatBus();

    var LocationCombo = getrdcLocation();
    var LocationPosterCombo = getrdcLocationPoster();
    var LocationBusCombo = getrdcLocationBus();

    var combo = getMediaClient();
    var mediatype = combo.SelectedItem.Value;
    var intmediatype = parseInt(mediatype);
    var divWeightCamp = document.getElementById('divWeightCampaign');

    if (intmediatype == MEDIA_TYPE_ID_BUS) //"Buses"
    {

//        formatBusCombo.DomElement.style.display = "block";
//        formatPosterCombo.DomElement.style.display = "none";
//        formatCombo.DomElement.style.display = "none";

        LocationBusCombo.DomElement.style.display = "block";
        LocationPosterCombo.DomElement.style.display = "none";
        LocationCombo.DomElement.style.display = "none";

//        formatBusCombo.FindItemByValue("Select").Select();
        LocationBusCombo.FindItemByValue("Select").Select();

    }
    else if (intmediatype == MEDIA_TYPE_ID_POSTER) {
//        formatBusCombo.DomElement.style.display = "none";
//        formatPosterCombo.DomElement.style.display = "block";
//        formatCombo.DomElement.style.display = "none";

        LocationBusCombo.DomElement.style.display = "none";
        LocationPosterCombo.DomElement.style.display = "block";
        LocationCombo.DomElement.style.display = "none";

//        formatPosterCombo.FindItemByValue("Select").Select();
        LocationPosterCombo.FindItemByValue("Select").Select();
    }
    else {
//        formatBusCombo.DomElement.style.display = "none";
//        formatPosterCombo.DomElement.style.display = "none";
//        formatCombo.DomElement.style.display = "block";

        LocationBusCombo.DomElement.style.display = "none";
        LocationPosterCombo.DomElement.style.display = "none";
        LocationCombo.DomElement.style.display = "block";
    }
}


function TransportCount() {
    var TransportLink = document.getElementById(getlnkTransport());

    if (TansportClick) {
        TransportLink.className = 'selected';
        TansportClick = false;
    }
    else {
        TransportLink.className = '';
        TansportClick = true;
    }
    return true;
}
var entityName;
function Geocode(entity) {
    entityName = entity;
    AddRooftopGeocode();
}

var xmlhttp = false;
function InitXmlHttp() {
    // Attempt to initialize xmlhttp object
    try {
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e) {
        // Try to use different activex object
        try {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch (E) {
            xmlhttp = false;
        }
    }
    // If not initialized, create XMLHttpRequest object
    if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
        xmlhttp = new XMLHttpRequest();
    }
    // Define function call for when Request obj state has changed
    xmlhttp.onreadystatechange = SearchHandler;
}

function SearchHandler() {
    if (xmlhttp.readyState == 4) {
        eval(xmlhttp.responseText);
    }
}

function AddRooftopGeocode() {
    try {
        document.getElementById(getMapDiv()).style.display = "block";
        document.getElementById(getMapDiv()).style.filter = "alpha(opacity=50)";
        document.getElementById(getMapDiv()).style.opacity = "0.5";
        document.getElementById(getMapLoadingDiv()).style.display = "block";
 
    var center = map.GetCenter();
    var latitude = center.Latitude;
    var longitude = center.Longitude;
    InitXmlHttp();
    var msg = "../../GeoCodingHandler.ashx?latitude=" + escape(latitude) + "&longitude=" + escape(longitude) + "&entity=" + escape(entityName);
    xmlhttp.open("GET", msg, true);
    xmlhttp.send(null);
       }
    catch (e) {
    }
}

function HideLoading() {
    try {
        document.getElementById(getMapDiv()).style.filter = "alpha(opacity=100)";
        document.getElementById(getMapDiv()).style.opacity = "1.0";
        document.getElementById(getMapLoadingDiv()).style.display = "none";
    }
    catch (e) {
    }
}

function PlotTransport(results) {
    if (!TansportClick) {
        //map.Find("Transports",null, null, null, null, null, true, false, null, false, TransportCallback); 
        HideLoading();
        results = results.toString().replaceAll("~", "\'");
        var resArray = results.toString().split('|&quot|');
        TransportCallback(resArray);
        map.AttachEvent("onendpan", AddRooftopGeocode);
        map.AttachEvent("onendzoom", AddRooftopGeocode);
    }
    else {
        HideLoading();
        map.DeleteShapeLayer(TransportLayer);
        map.DetachEvent("onendpan", AddRooftopGeocode);
        map.DetachEvent("onendzoom", AddRooftopGeocode);
    }
}

function TransportCallback(resultsArray) {
    if (resultsArray != null) {
        TransportLayer.DeleteAllShapes();
        TransportLayer = new VEShapeLayer();
        var TransportArray = new Array();

        for (x = 0; x < resultsArray.length; x++) {
            var data = resultsArray[x].split('&');
            shape = new VEShape(VEShapeType.Pushpin, new VELatLong(parseFloat(data[0]), parseFloat(data[1])));
            shape.SetTitle(data[2]);
            shape.SetDescription(data[3].replaceAll("||", "</br>"));
            shape.SetCustomIcon('../../App_Themes/SignPoster/images/Push_Pin_Bus.gif');
            TransportArray.push(shape);
        }

        map.AddShapeLayer(TransportLayer);
        for (i = 0; i < TransportArray.length; i++) {
            TransportLayer.AddShape(TransportArray[i]);
        }
    }
}

function SchoolCount() {
    var SchoolLink = document.getElementById(getlnkSchool());

    if (SchoolClick) {
        SchoolLink.className = 'selected';
        //        SchoolLayer.DeleteAllShapes(); 
        //        counter=0;
        SchoolClick = false;
        //        PlotSchool(schools[0]);
    }
    else {
        SchoolLink.className = '';
        SchoolClick = true;
    }
    return true;
}
String.prototype.replaceAll = function(
    strTarget, // The substring you want to replace
    strSubString // The string you want to replace in.
    ) {
    var strText = this;
    var intIndexOfMatch = strText.indexOf(strTarget);


    // Keep looping while an instance of the target string
    // still exists in the string.
    while (intIndexOfMatch != -1) {
        // Relace out the current instance.
        strText = strText.replace(strTarget, strSubString)


        // Get the index of any next matching substring.
        intIndexOfMatch = strText.indexOf(strTarget);
    }


    // Return the updated string with ALL the target strings
    // replaced out with the new substring.
    return (strText);
}

function PlotSchool(results) {
    if (!SchoolClick) {
        if (results != '') {
            map.Find(schools, null, null, null, null, null, true, false, null, false, CallbackSchool);
            HideLoading();
            results = results.toString().replaceAll("~", "\'");
            var resArray = results.toString().split('|&quot|');
            SchoolCallBack(resArray);
            map.AttachEvent("onendpan", AddRooftopGeocode);
            map.AttachEvent("onendzoom", AddRooftopGeocode);
        }
    }
    else {
        HideLoading();
        map.DeleteShapeLayer(SchoolLayer);
        map.DetachEvent("onendpan", AddRooftopGeocode);
        map.DetachEvent("onendzoom", AddRooftopGeocode);
    }
}
function CallbackSchool(shape, resultsArray, places, hasmore) {
    if (resultsArray != null) {
        var SchoolArray = new Array();

        for (x = 0; x < resultsArray.length; x++) {
            shape = new VEShape(VEShapeType.Pushpin, resultsArray[x].LatLong);
            shape.SetTitle(resultsArray[x].Name);
            shape.SetDescription(resultsArray[x].Description);
            shape.SetCustomIcon('../../App_Themes/SignPoster/images/Push_Pin_School.gif');
            SchoolArray.push(shape);
        }
        for (i = 0; i < SchoolArray.length; i++) {
            SchoolLayer.AddShape(SchoolArray[i]);
        }
    }
}

function SchoolCallBack(resultsArray) {
    if (resultsArray != null) {
        SchoolLayer.DeleteAllShapes();
        SchoolLayer = new VEShapeLayer();
        var SchoolArray = new Array();

        for (x = 0; x < resultsArray.length; x++) {
            var data = resultsArray[x].split('&');
            shape = new VEShape(VEShapeType.Pushpin, new VELatLong(parseFloat(data[0]), parseFloat(data[1])));
            shape.SetTitle(data[2]);
            shape.SetDescription(data[3].replaceAll("||", "</br>"));
            shape.SetCustomIcon('../../App_Themes/SignPoster/images/Push_Pin_School.gif');
            SchoolArray.push(shape);
        }

        map.AddShapeLayer(SchoolLayer);
        for (i = 0; i < SchoolArray.length; i++) {
            SchoolLayer.AddShape(SchoolArray[i]);
        }
    }

    //     counter++;
    //      
    //     if(counter<schools.length)
    //     {
    //        PlotSchool(schools[counter]);
    //     } 
    //     else
    //     {
    //        SchoolClick=true;
    //     }   
}

function AttractionCount() {
    var AttractionLink = document.getElementById(getlnkAttraction());

    if (AttractionClick) {
        AttractionLink.className = 'selected';
        AttractionClick = false;
    }
    else {
        AttractionLink.className = '';
        AttractionClick = true;
    }
    return true;
}

function PlotAttraction(results) {
    if (!AttractionClick) {
        //map.Find("Attractions",null, null, null, null, null, true, false, null, false, AttractionCallBack); 
        HideLoading();
        results = results.toString().replaceAll("~", "\'");
        var resArray = results.toString().split('|&quot|');
        AttractionCallBack(resArray);
        map.AttachEvent("onendpan", AddRooftopGeocode);
        map.AttachEvent("onendzoom", AddRooftopGeocode);
    }
    else {
        HideLoading();
        map.DeleteShapeLayer(AttractionsLayer);
        map.DetachEvent("onendpan", AddRooftopGeocode);
        map.DetachEvent("onendzoom", AddRooftopGeocode);
    }
}

function AttractionCallBack(resultsArray) {
    if (resultsArray != null) {
        AttractionsLayer.DeleteAllShapes();

        AttractionsLayer = new VEShapeLayer();
        var AttractionArray = new Array();

        for (x = 0; x < resultsArray.length; x++) {
            var data = resultsArray[x].split('&');
            shape = new VEShape(VEShapeType.Pushpin, new VELatLong(parseFloat(data[0]), parseFloat(data[1])));
            shape.SetTitle(data[2]);
            shape.SetDescription(data[3].replaceAll("||", "</br>"));
            shape.SetCustomIcon('../../App_Themes/SignPoster/images/Push_Pin_Attraction.gif');
            AttractionArray.push(shape);
        }

        map.AddShapeLayer(AttractionsLayer);
        for (i = 0; i < AttractionArray.length; i++) {
            AttractionsLayer.AddShape(AttractionArray[i]);
        }
    }
}

function OnClientSelectedIndexChangedSort(item) {
    var hdnSort = document.getElementById(getHiddenSort());
    hdnSort.value = item.ComboBox.GetValue();
}
function NextEvent(index) {
    var hdnIndex = document.getElementById(gethdnPageIndex());
    hdnIndex.value = index + 1;

}
function PrevEvent(index) {
    var hdnIndex = document.getElementById(gethdnPageIndex());
    hdnIndex.value = index - 1;

}

function ShowMapForItems() {
    var lat = parseFloat(document.getElementById(gethdnLatitude()).value);
    var lon = parseFloat(document.getElementById(gethdnLongitude()).value);
    var media = document.getElementById(gethdnMedia()).value;
    map = new VEMap('VeMapMyPlans');
    try {
        var clientTokenVE = document.getElementById(gethdnClientTokenMyPlans());
        var clientTokenValue = clientTokenVE.value;
        map.SetClientToken(clientTokenValue);
        document.getElementById(gethdnClientTokenMyPlans()).value = "Done";
        map.SetDashboardSize(VEDashboardSize.Small);
        if (lat == 0 || lon == 0 || isNaN(lat) || isNaN(lon)) {
            map.LoadMap(LA);
        }
        else {
            var latLong = new VELatLong(lat, lon);
            map.LoadMap(latLong);
        }
        map.SetCenter(latLong);
        map.EnableShapeDisplayThreshold(false);
        MoveDashboard(); //To move the dashboard rightside        
    }
    catch (e) {

    }
    map.AttachEvent("onmousewheel", removezoom); //To remove zoom level after certain extent
    map.AttachEvent("onmousedown", removezoom2);
    document.getElementById('MSVE_navAction_tinyZoomBar_plus').setAttribute("onClick", removezoom);
    if (document.getElementById(gethdnIdentifier()).value != "") {
        Opportunities = document.getElementById(gethdnIdentifier()).value;
        map.AttachEvent("onendzoom", GetMapZoomLevel);

        if (media == MEDIA_TYPE_ID_POSTER) {
            map.SetZoomLevel(13);
        }
        else {
            map.SetZoomLevel(11);
        }
    }
}

function GetMapZoomLevel() {
    var hdnZoomLevel = document.getElementById(gethdnZoomLevel());
    hdnZoomLevel.value = map.GetZoomLevel();
    map.DeleteAllPolygons(); //deletes all the shapes & polygons which are before
    map.DeleteAllPolylines();
    map.DeleteAllShapes();
    onSucessMyPlans();
}

function RefreshShowMap() {
    var lat = parseFloat(document.getElementById(gethdnLatitude()).value);
    var lon = parseFloat(document.getElementById(gethdnLongitude()).value);
    var media = document.getElementById(gethdnMedia()).value;
    Opportunities = document.getElementById(gethdnXMLArgumentClientID()).value;
    map.DeleteAllPolygons(); //deletes all the shapes & polygons which are before
    map.DeleteAllPolylines();
    map.DeleteAllShapes();
    document.getElementById(gethdnPolygonPoints()).value = "";
    document.getElementById(gethdnPushPinPoints()).value = "";
    document.getElementById(gethdnClusterPoints()).value = "";

    var latLong = new VELatLong(lat, lon);
    map.SetCenter(latLong);
    if (media == MEDIA_TYPE_ID_POSTER) {
        map.SetZoomLevel(13);
    }
    else {
        map.SetZoomLevel(11);
    }
    onSucessMyPlans();
}

function onSucessMyPlans() {
    if (Opportunities != "") {
        var oppDetails = Opportunities.split('+**+');
        baseLayer.DeleteAllShapes();
        var xmlfile = $get(gethdnXMLFileMyPlansClientID());
        xmlfile.value = oppDetails[2];
        mapStyle = map.GetMapStyle();
        if (xmlfile.value != "") {
            try {
                var veLayerSpec = new VEShapeSourceSpecification(VEDataType.GeoRSS, xmlfile.value, baseLayer);
                map.ImportShapeLayerData(veLayerSpec, cluster);
                baseLayer.Hide();
            }
            catch (e) {

            }

            // Second shape layer to store the clustered data
            if (clusterLayer._mapGuid == null) {
                map.AddShapeLayer(clusterLayer);
            }
        }
    }

    if (xmlfile.value != "") {
        if (oppDetails.length > 4) {
            var polygonXmlFile = oppDetails[4];
            AddPolygonFromXml(polygonXmlFile);
        }
    }
}

//Google Street View Image Hover
function fnChangePegmanImage()
{
    $(".imgStreetView").mouseover(function() {
        var src = "../../App_Themes/SignPoster/images/WalkingPegman.png";
        $(this).attr("src", src);
    });
    $(".imgStreetView").mouseout(function() {
        var src = "../../App_Themes/SignPoster/images/Pegman.png";
        $(this).attr("src", src);
    });
}

function ChangeImageSource(objli)
{
        if(objli.endsWith("liPBSheet"))
        {
            var obj = document.getElementById(getPBSheetClientID());
            if(obj != null)
            {
                obj.src = "../../App_Themes/SignPoster/images/format-selection-loading-pink.gif";
            }
        }
        else if(objli.endsWith("li4Sheet"))
        {
            var obj = document.getElementById(get4SheetClientID());
            if(obj != null)
            {
                obj.src = "../../App_Themes/SignPoster/images/format-selection-loading-pink.gif";
            }
        }
        else if(objli.endsWith("li6Sheet"))
        {
            var obj = document.getElementById(get6SheetClientID());
            if(obj != null)
            {
                obj.src = "../../App_Themes/SignPoster/images/format-selection-loading-pink.gif";
            }
        }
        else if(objli.endsWith("liBusShelters"))
        {
            var obj = document.getElementById(getBusShelterClientID());
            if(obj != null)
            {
                obj.src = "../../App_Themes/SignPoster/images/format-selection-loading-pink.gif";
            }
        }
        else if(objli.endsWith("li48Sheet"))
        {
            var obj = document.getElementById(get48SheetClientID());
            if(obj != null)
            {
                obj.src = "../../App_Themes/SignPoster/images/format-selection-loading-pink.gif";
            }
        }
        else if(objli.endsWith("li96Sheet"))
        {
            var obj = document.getElementById(get96SheetClientID());
            if(obj != null)
            {
                obj.src = "../../App_Themes/SignPoster/images/format-selection-loading-pink.gif";
            }
        }
        else if(objli.endsWith("liStreetLiner"))
        {
            var obj = document.getElementById(getBusStreetLinerClientID());
            if(obj != null)
            {
                obj.src = "../../App_Themes/SignPoster/images/format-selection-loading-pink.gif";
            }
        }
        else if(objli.endsWith("liBusRear"))
        {
            var obj = document.getElementById(getBusRearClientID());
            if(obj != null)
            {
                obj.src = "../../App_Themes/SignPoster/images/format-selection-loading-pink.gif";
            }
        }
          else if(objli.endsWith("liBusShelter1"))
        {
            var obj = document.getElementById(getBusShelter1ClientID());
            if(obj != null)
            {
                obj.src = "../../App_Themes/SignPoster/images/format-selection-loading-pink.gif";
            }
        }

}

function RevertImageSource(objli)
{
        if(objli.endsWith("liPBSheet"))
        {
            var obj = document.getElementById(getPBSheetClientID());
            if(obj != null)
            {
                obj.src = "../../App_Themes/SignPoster/images/format-selection-loading.gif";
            }
        }
        else if(objli.endsWith("li4Sheet"))
        {
            var obj = document.getElementById(get4SheetClientID());
            if(obj != null)
            {
                obj.src = "../../App_Themes/SignPoster/images/format-selection-loading.gif";
            }
        }
        else if(objli.endsWith("li6Sheet"))
        {
            var obj = document.getElementById(get6SheetClientID());
            if(obj != null)
            {
                obj.src = "../../App_Themes/SignPoster/images/format-selection-loading.gif";
            }
        }
        else if(objli.endsWith("liBusShelters"))
        {
            var obj = document.getElementById(getBusShelterClientID());
            if(obj != null)
            {
                obj.src = "../../App_Themes/SignPoster/images/format-selection-loading.gif";
            }
        }
        else if(objli.endsWith("li48Sheet"))
        {
            var obj = document.getElementById(get48SheetClientID());
            if(obj != null)
            {
                obj.src = "../../App_Themes/SignPoster/images/format-selection-loading.gif";
            }
        }
        else if(objli.endsWith("li96Sheet"))
        {
            var obj = document.getElementById(get96SheetClientID());
            if(obj != null)
            {
                obj.src = "../../App_Themes/SignPoster/images/format-selection-loading.gif";
            }
        }
        else if(objli.endsWith("liStreetLiner"))
        {
            var obj = document.getElementById(getBusStreetLinerClientID());
            if(obj != null)
            {
                obj.src = "../../App_Themes/SignPoster/images/format-selection-loading.gif";
            }
        }
        else if(objli.endsWith("liBusRear"))
        {
            var obj = document.getElementById(getBusRearClientID());
            if(obj != null)
            {
                obj.src = "../../App_Themes/SignPoster/images/format-selection-loading.gif";
            }
        }
           else if(objli.endsWith("liBusShelter1"))
        {
            var obj = document.getElementById(getBusShelter1ClientID());
            if(obj != null)
            {
                obj.src = "../../App_Themes/SignPoster/images/format-selection-loading.gif";
            }
        }
}