 dojo.require("dojo.parser");
 dojo.require("dijit.layout.ContentPane");
         dojo.require("dijit.layout.TabContainer"); 
         dojo.require("dijit.Menu");
         dojo.require("dijit.form.CheckBox");
         dojo.require("dijit.ColorPalette");
         dojo.require("dijit.Tooltip");
         dojo.require("dijit.form.Button");
         dojo.require("dijit.Dialog");
         dojo.require("dijit.ProgressBar");
         dojo.require("dijit.form.FilteringSelect");
         dojo.require("dijit.layout.AccordionContainer");
         dojo.require("dijit.TitlePane");
         dojo.require("dijit.form.ValidationTextBox");

            
            //Define Icons for Google map
            IcnMyDot = new GIcon;
            IcnMyDot.iconSize = new GSize(12,19);
            IcnMyDot.iconAnchor = new GPoint(3,3);
            IcnMyDot.infoWindowAnchor = new GPoint(3,3);

            IcnBluDot = new GIcon;
            IcnBluDot.image = "images/icon_arts.png";
            IcnBluDot.iconSize = new GSize(12,19);
            IcnBluDot.iconAnchor = new GPoint(3,3);
            IcnBluDot.infoWindowAnchor = new GPoint(3,3);

            IcnOrngDot = new GIcon;
            IcnOrngDot.image = "images/icon_business.png";
            IcnOrngDot.iconSize = new GSize(12,19);
            IcnOrngDot.iconAnchor = new GPoint(3,3);
            IcnOrngDot.infoWindowAnchor = new GPoint(3,3);

            IcnMarnDot = new GIcon;
            IcnMarnDot.image = "images/icon_edu.png";
            IcnMarnDot.iconSize = new GSize(12,19);
            IcnMarnDot.iconAnchor = new GPoint(3,3);
            IcnMarnDot.infoWindowAnchor = new GPoint(3,3);

            IcnGrnDot = new GIcon;
            IcnGrnDot.image = "images/icon_environ.png";
            IcnGrnDot.iconSize = new GSize(12,19);
            IcnGrnDot.iconAnchor = new GPoint(3,3);
            IcnGrnDot.infoWindowAnchor = new GPoint(3,3);

            IcnRedDot = new GIcon;
            IcnRedDot.image = "images/icon_health.png";
            IcnRedDot.iconSize = new GSize(12,19);
            IcnRedDot.iconAnchor = new GPoint(3,3);
            IcnRedDot.infoWindowAnchor = new GPoint(3,3);

            IcnCynDot = new GIcon;
            IcnCynDot.image = "images/icon_humanrights.png";
            IcnCynDot.iconSize = new GSize(12,19);
            IcnCynDot.iconAnchor = new GPoint(3,3);
            IcnCynDot.infoWindowAnchor = new GPoint(3,3);

            IcnNavDot = new GIcon;
            IcnNavDot.image = "images/icon_other.png";
            IcnNavDot.iconSize = new GSize(12,19);
            IcnNavDot.iconAnchor = new GPoint(3,3);
            IcnNavDot.infoWindowAnchor = new GPoint(3,3);

            IcnMagDot = new GIcon;
            IcnMagDot.image = "images/icon_public.png";
            IcnMagDot.iconSize = new GSize(12,19);
            IcnMagDot.iconAnchor = new GPoint(3,3);
            IcnMagDot.infoWindowAnchor = new GPoint(3,3);

            IcnYelDot = new GIcon;
            IcnYelDot.image = "images/icon_tech.png";
            IcnYelDot.iconSize = new GSize(12,19);
            IcnYelDot.iconAnchor = new GPoint(3,3);
            IcnYelDot.infoWindowAnchor = new GPoint(3,3);

            IcnSparky = new GIcon;
            IcnSparky.image = "images/Sparky.png";
            IcnSparky.iconSize = new GSize(37,49);
            IcnSparky.iconAnchor = new GPoint(34,47);

            IcnStar = new GIcon;
            IcnStar.image = "images/ASUStar.png";
            IcnStar.iconSize = new GSize(28,28);
            IcnStar.iconAnchor = new GPoint(14,14);
            IcnStar.infoWindowAnchor = new GPoint(14, 14);

            //add custom controls
            //define the function first
            function TextualControl() {
            }

            // To "subclass" the GControl, we set the prototype object to
            // an instance of the GControl object
            TextualControl.prototype = new GControl();

            // Creates a one DIV for each of the buttons and places them in a container
            // DIV which is returned as our control element. We add the control to
            // to the map container and return the element for the map class to
            // position properly.
            TextualControl.prototype.initialize = function(map) {
                var container = document.createElement("div");

                var zoomInDiv = document.createElement("div");
                this.setButtonStyle_(zoomInDiv);
                container.appendChild(zoomInDiv);
                zoomInDiv.appendChild(document.createTextNode("Search For Programs"));
                GEvent.addDomListener(zoomInDiv, "click", function() {
                    dijit.byId('Div_query').show();
                });



                map.getContainer().appendChild(container);
                return container;
            }

            // By default, the control will appear in the top left corner of the
            // map with 7 pixels of padding.
            TextualControl.prototype.getDefaultPosition = function() {
                return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(8, 30));
            }

            // Sets the proper CSS for the given button element.
            TextualControl.prototype.setButtonStyle_ = function(button) {

                button.style.color = "#8B0000";
                button.style.backgroundColor = "white";
                button.style.font = "small Arial";
                button.style.border = "1px solid black";
                button.style.padding = "1px";
                button.style.marginBottom = "1px";
                button.style.textAlign = "center";
                button.style.width = "10em";
                button.style.cursor = "pointer";
            }


            //end add custom controls

            //define map control
                 
         var map;
         //<![CDATA[
         function load() {
             if (GBrowserIsCompatible()) {
                 map = new GMap2(document.getElementById("map"));
                 map.setCenter(new GLatLng(33.545, -112.125), 9);
                 map.addControl(new GSmallMapControl());
                 map.addControl(new GMapTypeControl());
                 map.addControl(new TextualControl());

                 LoadAllImpact();

             }
         }
         var c_lat;
         var c_lon;
         var c_zoom;
            
         //Center map given lat lon   
         function MapZoomToPoint(lat, lon) {
             
             map.setCenter(new GLatLng(lat, lon), 16);

         }
        
        //Center map open info given lat lon
         function MapZoomToPointInfo(lat,lon,text,link) {
             var t_html;         
             t_html = "<a class='marker_infos' href='" + link + "' target='_blank'> " + text + "</a><br/>";
             map.setCenter(new GLatLng(lat, lon), 16);
             map.openInfoWindowHtml(new GLatLng(lat, lon), t_html);
         }

         function LoadAllImpact() {
            
             map.clearOverlays();
             for (var i_cntr = 0; i_cntr < ai_lat.length; i_cntr++) {

                 var temp_marker;
                 var temp_ai_html = "";
                 temp_ai_html = ai_html[i_cntr] + "<br/><div class='ai_zin'><a href='Javascript:MapZoomToPoint(" + ai_lat[i_cntr] + "," + ai_lon[i_cntr] + ")'>Zoom In</a></div>";
                 
                 var temp_point = new GLatLng(ai_lat[i_cntr], ai_lon[i_cntr]);
                 temp_marker = createMarker(temp_point, temp_ai_html, ai_ipar[i_cntr]);
                 map.addOverlay(temp_marker);

             }

             document.getElementById('load_text').innerHTML = "";

             AddASUMarkers();
             
         }

         function LoadImpact(impactarea) {
                
                map.clearOverlays();
                map.setCenter(new GLatLng(33.545, -112.125), 9);
                var temp_ai_area_html = "";
                //Education
                if(impactarea==0){
                    for (var p_cntr = 0; p_cntr < ai_lat0.length; p_cntr++) {
                        
                        var temp_marker;
                        temp_ai_area_html = ai_html0[p_cntr] + "<br/><div class='ai_zin'><a href='Javascript:MapZoomToPoint(" + ai_lat0[p_cntr] + "," + ai_lon0[p_cntr] + ")'>Zoom In</a></div>";
                 
                        var temp_point = new GLatLng(ai_lat0[p_cntr], ai_lon0[p_cntr]);
                        temp_marker = createMarker(temp_point, temp_ai_area_html, ai_ipar0[p_cntr]);
                        map.addOverlay(temp_marker);
                        
                    }

                    document.getElementById('load_text').innerHTML = "";
                    IAQuery('Education');
                }

                //Business and Economic Development
                if (impactarea == 1) {
                    for (var p_cntr = 0; p_cntr < ai_lat1.length; p_cntr++) {
                    
                        temp_ai_area_html = ai_html1[p_cntr] + "<br/><div class='ai_zin'><a href='Javascript:MapZoomToPoint(" + ai_lat1[p_cntr] + "," + ai_lon1[p_cntr] + ")'>Zoom In</a></div>";
                        var temp_marker;
                        var temp_point = new GLatLng(ai_lat1[p_cntr], ai_lon1[p_cntr]);
                        temp_marker = createMarker(temp_point, temp_ai_area_html, ai_ipar1[p_cntr]);
                        map.addOverlay(temp_marker);

                    }

                    document.getElementById('load_text').innerHTML = "";
                    IAQuery('Business and Economic Development');
                }

                //Arts and Culture
                if (impactarea == 2) {
                    for (var p_cntr = 0; p_cntr < ai_lat2.length; p_cntr++) {

                        temp_ai_area_html = ai_html2[p_cntr] + "<br/><div class='ai_zin'><a href='Javascript:MapZoomToPoint(" + ai_lat2[p_cntr] + "," + ai_lon2[p_cntr] + ")'>Zoom In</a></div>";
                 
                        var temp_marker;
                        var temp_point = new GLatLng(ai_lat2[p_cntr], ai_lon2[p_cntr]);
                        temp_marker = createMarker(temp_point, temp_ai_area_html, ai_ipar2[p_cntr]);
                        map.addOverlay(temp_marker);

                    }

                    document.getElementById('load_text').innerHTML = "";
                    IAQuery('Arts and Culture');
                }

                //Human Rights
                if (impactarea == 3) {
                    for (var p_cntr = 0; p_cntr < ai_lat3.length; p_cntr++) {

                        temp_ai_area_html = ai_html3[p_cntr] + "<br/><div class='ai_zin'><a href='Javascript:MapZoomToPoint(" + ai_lat3[p_cntr] + "," + ai_lon3[p_cntr] + ")'>Zoom In</a></div>";
                 
                        var temp_marker;
                        var temp_point = new GLatLng(ai_lat3[p_cntr], ai_lon3[p_cntr]);
                        temp_marker = createMarker(temp_point, temp_ai_area_html, ai_ipar3[p_cntr]);
                        map.addOverlay(temp_marker);

                    }

                    document.getElementById('load_text').innerHTML = "";
                    IAQuery('Human Rights');
                }

                //Environment
                if (impactarea == 4) {
                    for (var p_cntr = 0; p_cntr < ai_lat4.length; p_cntr++) {

                        temp_ai_area_html = ai_html4[p_cntr] + "<br/><div class='ai_zin'><a href='Javascript:MapZoomToPoint(" + ai_lat4[p_cntr] + "," + ai_lon4[p_cntr] + ")'>Zoom In</a></div>";
                 
                        var temp_marker;
                        var temp_point = new GLatLng(ai_lat4[p_cntr], ai_lon4[p_cntr]);
                        temp_marker = createMarker(temp_point, temp_ai_area_html, ai_ipar4[p_cntr]);
                        map.addOverlay(temp_marker);

                    }

                    document.getElementById('load_text').innerHTML = "";
                    IAQuery('Environment');
                }

                //Public Policy
                if (impactarea == 5) {
                    for (var p_cntr = 0; p_cntr < ai_lat5.length; p_cntr++) {

                        temp_ai_area_html = ai_html5[p_cntr] + "<br/><div class='ai_zin'><a href='Javascript:MapZoomToPoint(" + ai_lat5[p_cntr] + "," + ai_lon5[p_cntr] + ")'>Zoom In</a></div>";
                 
                        var temp_marker;
                        var temp_point = new GLatLng(ai_lat5[p_cntr], ai_lon5[p_cntr]);
                        temp_marker = createMarker(temp_point, temp_ai_area_html, ai_ipar5[p_cntr]);
                        map.addOverlay(temp_marker);

                    }

                    document.getElementById('load_text').innerHTML = "";
                    IAQuery('Public Policy');
                }


                //Health and Wellness
                if (impactarea == 6) {
                    for (var p_cntr = 0; p_cntr < ai_lat6.length; p_cntr++) {

                        temp_ai_area_html = ai_html6[p_cntr] + "<br/><div class='ai_zin'><a href='Javascript:MapZoomToPoint(" + ai_lat6[p_cntr] + "," + ai_lon6[p_cntr] + ")'>Zoom In</a></div>";
                 
                        var temp_marker;
                        
                        var temp_point = new GLatLng(ai_lat6[p_cntr], ai_lon6[p_cntr]);
                        temp_marker = createMarker(temp_point, temp_ai_area_html, ai_ipar6[p_cntr]);
                        map.addOverlay(temp_marker);

                    }

                    document.getElementById('load_text').innerHTML = "";
                    IAQuery('Health and Wellness');
                }

                //Other
                if (impactarea == 7) {
                    for (var p_cntr = 0; p_cntr < ai_lat7.length; p_cntr++) {


                        temp_ai_area_html = ai_html7[p_cntr] + "<br/><div class='ai_zin'><a href='Javascript:MapZoomToPoint(" + ai_lat7[p_cntr] + "," + ai_lon7[p_cntr] + ")'>Zoom In</a></div>";
                 
                        var temp_marker;
                        var temp_point = new GLatLng(ai_lat7[p_cntr], ai_lon7[p_cntr]);
                        temp_marker = createMarker(temp_point, temp_ai_area_html, ai_ipar7[p_cntr]);
                        map.addOverlay(temp_marker);

                    }

                    document.getElementById('load_text').innerHTML = "";
                    IAQuery('Other');
                }

                //Technology
                if (impactarea == 8) {
                    for (var p_cntr = 0; p_cntr < ai_lat8.length; p_cntr++) {

                        temp_ai_area_html = ai_html8[p_cntr] + "<br/><div class='ai_zin'><a href='Javascript:MapZoomToPoint(" + ai_lat8[p_cntr] + "," + ai_lon8[p_cntr] + ")'>Zoom In</a></div>";
                 
                        var temp_marker;
                        var temp_point = new GLatLng(ai_lat8[p_cntr], ai_lon8[p_cntr]);
                        temp_marker = createMarker(temp_point, temp_ai_area_html, ai_ipar8[p_cntr]);
                        map.addOverlay(temp_marker);

                    }

                    document.getElementById('load_text').innerHTML = "";
                    IAQuery('Technology');
                }


                AddASUMarkers();
         
         
         
         
         
         }


         function SearchMarker(lat,lon,html,layer) {
             //map.clearOverlays();
             //var sm_html = "<a href='" + html;
             var sm_point = new GLatLng(lat,lon);
             var sm_marker = createMarker(sm_point, html, layer);
             map.addOverlay(sm_marker);

         }
            
            
         //--------------------------------------------------------------------------------------------
         // Creates a marker whose info window displays the given number.  In this case, passing in a
         // layer value will result in selection of different color markers.  This is used when the
         // script displays all the layers.  When the script is only displaying one layer it will use
         // the IcnMyDot image, which is defined at load time based on the layer to be drawn (using
         // one of the images in the  switch $Layer loop above); to make this happen here, we 
         // simply send no value for layer when createMarker is called--switch defaults to IcnMyDot.
         //--------------------------------------------------------------------------------------------
         function createMarker(point, html, layer) {
             switch (layer) {
                 case "Arts and Culture":
                     var marker = new GMarker(point, IcnBluDot);
                     break;
                 case "Business and Economic Development":
                     var marker = new GMarker(point, IcnOrngDot);
                     break;
                 case "Education":
                     var marker = new GMarker(point, IcnMarnDot);
                     break;
                 case "Environment":
                     var marker = new GMarker(point, IcnGrnDot);
                     break;
                 case "Health and Wellness":
                     var marker = new GMarker(point, IcnRedDot);
                     break;
                 case "Human Rights":
                     var marker = new GMarker(point, IcnCynDot);
                     break;
                 case "Other":
                     var marker = new GMarker(point, IcnNavDot);
                     break;
                 case "Public Policy":
                     var marker = new GMarker(point, IcnMagDot);
                     break;
                 case "Technology":
                     var marker = new GMarker(point, IcnYelDot);
                     break;
                 case "Campus":
                     var marker = new GMarker(point, IcnStar);
                     break;
                 default:
                     var marker = new GMarker(point, IcnMyDot);
             }
             GEvent.addListener(marker, 'click',
		function() {
		    var markerHTML = html;
		    marker.openInfoWindowHtml(markerHTML);
		});
             return marker;
         }

         //-----------------------------------------------------------------------------------------

         //]]>

 

        function IAQuery(impactarea) {
            dijit.byId('Div_indicator').show();
            //hello
            document.getElementById('load_text').innerHTML = "Querying Database...";
            var tquer1 = new Sys.Data.DataService("AIC.svc/");
            tquer1.query("/GG_MAPT?$filter=IMPACTAREA eq '" + impactarea + "'" + "&$orderby=PROGTITLE", tquerSuccess, cbFailure);
            //tquer1.query("/aicprod", cbSuccess, cbFailure);
           
           // alert(tquer1);
            document.getElementById('load_text').innerHTML = "Sending inner query to server...";
            
            
            //try the dynaquery
            //DynaQuery('', '', 'ASU at the Tempe campus');
            
            
        }


        function DynaQuery(location) {
            //hello
            dijit.byId('Div_indicator').show();
            document.getElementById('load_text').innerHTML = "Querying Database...";
            var tquer3 = new Sys.Data.DataService("AIC.svc/");
            var temp_querystring = "";
            //temp_querystring = "/aicprod?$filter=LOCATION eq '" + location +"' and IMPACTAREA eq 'Education'";
            temp_querystring = "/GG_MAPT?$filter=LOCATION eq '" + location + "'" + "&$orderby=PROGTITLE";
            tquer3.query(temp_querystring, tquerSuccess, cbFailure);
            //tquer1.query("/aicprod", cbSuccess, cbFailure);

            // alert(tquer1);
            document.getElementById('load_text').innerHTML = "Sending inner query to server...";
            
        }


        function cbSuccess(result, context, operation) {
            
            
            document.getElementById('load_text').innerHTML = "Query Successful, Drawing Points...";
            //var rList = document.getElementById("resultList");
            map.clearOverlays();
            for (var i in result) {
                var thisCat = result[i];
                //var li = document.createElement("li");
                //li.appendChild(document.createTextNode(thisCat.LATITUDE + ": " + thisCat.LONGITUDE));
                //rList.appendChild(li);

                var point = new GLatLng(thisCat.LATITUDE, thisCat.LONGITUDE);
                var str_html = '';
                str_html = ' <div id="marker_info"><a href="' + thisCat.PROGURL + '" target="_blank">' + thisCat.PROGTITLE + '</a><br/>';
                str_html = str_html + ' <a href="Javascript:MapZoomToPoint(' + thisCat.LATITUDE + ',' + thisCat.LONGITUDE + ');"> Zoom in</a><br/>';
                str_html = str_html + ' <a href="Javascript:DynaQuery(' + '\'' + thisCat.LOCATION + '\'' + ');"> Run Temp Query for location</a></div>';
                
                var temp_marker;
                temp_marker = createMarker(point, str_html, thisCat.IMPACTAREA);
                map.addOverlay(temp_marker);
                //map.addOverlay(new GMarker(point));
            }
            
            //alert(result.PROGTITLE);
            document.getElementById('load_text').innerHTML = "ADO.net FTW!";

        }

        function tquerSuccess(result, context, operation) {

            
            document.getElementById('load_text').innerHTML = "Inner Query Successful...";
            //var rList = document.getElementById("resultList");
            //rList.innerHTML = "";
            var str_counter = document.getElementById("str1");
            //map.clearOverlays();
            var temp_counter = 0;
            var html_temp_query = "";
            var temp_html = [];
            //clear out array
            temp_html.length = 0;
            temp_html.push("<br/>");
             for (var ki in result) {
                var thisCat1 = result[ki];
                //html_temp_query = html_temp_query + "<a href='" + thisCat1.PROGURL + "' target='_blank'> " + thisCat1.PROGTITLE + "</a>";
                //html_temp_query = html_temp_query + "<a href='Javascript:MapZoomToPoint(" + thisCat1.LATITUDE + "," + thisCat1.LONGITUDE + ");'>" + " <div id='zoomer'>Zoom in to this location</div></a><br/>";

                // this is faster due to ie string manipulation speed problems 
                
                temp_html.push("<a href='");
                temp_html.push(thisCat1.PROGURL);
                temp_html.push("' target='_blank'> ");
                temp_html.push(thisCat1.PROGTITLE);
                temp_html.push("</a>");

                temp_html.push("<a href='Javascript:MapZoomToPoint(");
                temp_html.push(thisCat1.LATITUDE);
                temp_html.push(",");
                temp_html.push(thisCat1.LONGITUDE);
                temp_html.push(");'>");
                temp_html.push(" <div id='zoomer'>Zoom in to this location</div></a><br/>");
                
                temp_counter++;
            }

            str_counter.innerHTML = "There are " + temp_counter + " program locations that meet your search criteria " + "<br/><br/> <img src='images/new_search.png' alt='New Search' onclick='dijit_helper1();' style='cursor: pointer;' /><br /><br />";
            //document.getElementById('results_txt').innerHTML = html_temp_query;
            //join the smaller pushed arrays and add to the inner html
            document.getElementById('results_txt').innerHTML = temp_html.join('');
            //alert('done dynamic query');
            document.getElementById('load_text').innerHTML = "";
            dijit.byId('Div_indicator').hide();
        }

        function tsearchSuccess(result, context, operation) {

            var showdiv=dijit.byId('Div_indicator').show();
            document.getElementById('load_text').innerHTML = "Inner Query Successful...";
            //var rList = document.getElementById("resultList");
            //rList.innerHTML = "";
            var str_counter = document.getElementById("str1");
            map.clearOverlays();
            var temp_counter = 0;
            var html_temp_query = "";
            var temp_html = [];
            //clear out array
            temp_html.length = 0;
            temp_html.push("<br/>");
            for (var ki in result) {
                var thisCat1 = result[ki];
                //html_temp_query = html_temp_query + "<a href='" + thisCat1.PROGURL + "' target='_blank'> " + thisCat1.PROGTITLE + "</a>";
                //html_temp_query = html_temp_query + "<a href='Javascript:MapZoomToPoint(" + thisCat1.LATITUDE + "," + thisCat1.LONGITUDE + ");'>" + " <div id='zoomer'>Zoom in to this location</div></a><br/>";

                // this is faster due to ie string manipulation speed problems 

                temp_html.push("<a href='");
                temp_html.push(thisCat1.PROGURL);
                temp_html.push("' target='_blank'> ");
                temp_html.push(thisCat1.PROGTITLE);
                temp_html.push("</a>");

                temp_html.push("<a href='Javascript:MapZoomToPoint(");
                temp_html.push(thisCat1.LATITUDE);
                temp_html.push(",");
                temp_html.push(thisCat1.LONGITUDE);
                temp_html.push(");");

                temp_html.push("SearchMarker(");
                temp_html.push(thisCat1.LATITUDE);
                temp_html.push(",");
                temp_html.push(thisCat1.LONGITUDE);
                temp_html.push(",");
                temp_html.push("\"");
                temp_html.push(thisCat1.PROGTITLE);
                temp_html.push("\"");
                temp_html.push(",");
                temp_html.push("\"");
                temp_html.push(thisCat1.IMPACTAREA);
                temp_html.push("\""); 
                temp_html.push(");'>");
                
                temp_html.push(" <div id='zoomer'>Zoom in to this location</div></a><br/>");

                temp_counter++;
            }

            str_counter.innerHTML = "There are " + temp_counter + " program locations that meet your search criteria " + "<br/><br/><img src='images/new_search.png' alt='New Search' onclick='dijit_helper1();' style='cursor: pointer;' /><br /><br />";
            //document.getElementById('results_txt').innerHTML = html_temp_query;
            //join the smaller pushed arrays and add to the inner html
            document.getElementById('results_txt').innerHTML = temp_html.join('');
            //alert('done dynamic query');
            document.getElementById('load_text').innerHTML = "";
            dijit.byId('Div_indicator').hide();
        }

        //globals for tsearchSucess_page and process_page_elements
        var temp_html_title = [];
        var temp_html_link = [];
        var temp_html_lat = [];
        var temp_html_lon = [];
        var temp_html_imparea = [];
        
        function tsearchSuccess_page(result, context, operation) {

            var showdiv = dijit.byId('Div_indicator').show();
            document.getElementById('load_text').innerHTML = "Inner Query Successful...";
            //var rList = document.getElementById("resultList");
            //rList.innerHTML = "";
            var str_counter = document.getElementById("str1");
            map.clearOverlays();
            var temp_counter = 0;
            var html_temp_query = "";
            
            //clear out axrray
            temp_html_title.length = 0;
            temp_html_link.length = 0;
            temp_html_lat.length = 0;
            temp_html_lon.length = 0;
            temp_html_imparea.length = 0;
            
            var final_count = 0;

            for (var ki in result) {
                var thisCat1 = result[ki];
                //html_temp_query = html_temp_query + "<a href='" + thisCat1.PROGURL + "' target='_blank'> " + thisCat1.PROGTITLE + "</a>";
                //html_temp_query = html_temp_query + "<a href='Javascript:MapZoomToPoint(" + thisCat1.LATITUDE + "," + thisCat1.LONGITUDE + ");'>" + " <div id='zoomer'>Zoom in to this location</div></a><br/>";

                // this is faster due to ie string manipulation speed problems

                temp_html_title[temp_counter] = thisCat1.PROGTITLE;
                temp_html_link[temp_counter] = thisCat1.PROGURL;
                temp_html_lat[temp_counter] = thisCat1.LATITUDE;
                temp_html_lon[temp_counter] = thisCat1.LONGITUDE;
                temp_html_imparea[temp_counter] = thisCat1.IMPACTAREA;
                temp_counter++;
            }
            //assign final count to temp counter
            final_count = temp_counter;
            
            var pagesize = 100;
            var num_pages;
            var whole_pages = parseInt(final_count / pagesize);
            var leftover_page = final_count % pagesize;

            if (leftover_page > 0) {
                num_pages = whole_pages + 1;

            }
            var startofpage = 0;
            var endofpage = pagesize - 1;
            var pagecount = 1;
            
            
            
            
            //clear the search area inner html
            document.getElementById('results_txt').innerHTML = " ";
            
            //alert('done dynamic query');
            if (final_count < pagesize) {
                str_counter.innerHTML = "There are " + temp_counter + " program locations that meet your search criteria ";
            
                process_page_elements(0, final_count);
            }
            else {
                str_counter.innerHTML = "There are " + temp_counter + " program locations that meet your search criteria " + "<br/>Cycle through the results -> ";
                var cg_logic;
                for (cg_v = 0; cg_v < whole_pages; cg_v++) {
                    cg_logic = cg_v * 100;
                    cg_q = cg_v + 1;
                    str_counter.innerHTML = str_counter.innerHTML + "<a href='Javascript:process_page_elements(" + cg_logic + "," + pagesize + ");'>" + cg_q + "</a>" + "<span>&nbsp </span>";

                }
                //add the last page
                cg_logic = 100 + cg_logic;
                str_counter.innerHTML = str_counter.innerHTML + "<a href='Javascript:process_page_elements(" + cg_logic + "," + leftover_page + ");'>" + num_pages + "</a>";
                //add the first page of results to search display pane
                process_page_elements(0, pagesize);
                

            }
            
            dijit.byId('Div_indicator').hide();
            document.getElementById('load_text').innerHTML = "";
        }

        function process_page_elements(start_index,pagesize) { 
            
        //add the values to the html search pane
            dijit.byId('Div_indicator').show();
            var endofpage = start_index + pagesize;
            var true_start = start_index + 1;
            
            var html_temp = "You are viewing records " + true_start + " to " + endofpage + "<br/><br/>";
            document.getElementById('results_txt').innerHTML = html_temp;
            //alert(document.getElementById('results_txt').innerHTML);
            //clear any overlays
            map.clearOverlays();
            
            for (count = start_index; count < endofpage; count++) {
                html_temp = html_temp + "<a href='" + temp_html_link[count] + "' target='_blank'> " + temp_html_title[count] + "</a><br/>";
                html_temp = html_temp + "<a href='Javascript:MapZoomToPointInfo(" + temp_html_lat[count] + "," + temp_html_lon[count] + ",\"" + temp_html_title[count]+"\",\""+temp_html_link[count]+"\");'>" + " <div id='zoomer'>Zoom in to this location</div></a><br/>";
                //add marker to map
                SearchMarker(temp_html_lat[count], temp_html_lon[count], "<a class='marker_infos' href='" + temp_html_link[count] + "' target='_blank'> " + temp_html_title[count] + "</a><br/>", temp_html_imparea[count]);

            }
            document.getElementById('results_txt').innerHTML = " ";
            document.getElementById('results_txt').innerHTML = html_temp;
            
        //zoom map back out to full extent
            map.setCenter(new GLatLng(33.545, -112.125), 9);


            dijit.byId('Div_indicator').hide();
            
        }

        function cbFailure(error, context, operation) {
            alert(error.get_message());
        }

        function dijit_helper1() {

            var temp_1 = dijit.byId('Div_query').show();
        
        }
        function ImpactQuery(location,impactarea) {
            //hello
            document.getElementById('load_text').innerHTML = "Querying Database...";
            var tquer4 = new Sys.Data.DataService("AIC.svc/");
            var imp_area_qstr = "";
            imp_area_qstr = "/GG_MAPT?$filter=LOCATION eq '" + location + "' and IMPACTAREA eq '" + impactarea + "'" + "&$orderby=PROGTITLE";

            tquer4.query(imp_area_qstr, tquerSuccess, cbFailure);
            //tquer1.query("/aicprod", cbSuccess, cbFailure);

            // alert(tquer1);
            document.getElementById('load_text').innerHTML = "Sending inner query to server...";

        }

        function AddASUMarkers() { 
        
        var point = new GLatLng(33.4199253044, -111.937855771);
        var marker = createMarker(point, '<a href="http://www.asu.edu" target="_blank"><font face="Arial" size=1>Tempe campus</font></a><br>', "Campus");
        map.addOverlay(marker);
        
        var point = new GLatLng(33.4501273504, -112.063792605);
        var marker = createMarker(point, '<a href="http://campus.asu.edu/downtown/" target="_blank"><font face="Arial" size=1>Downtown Phoenix campus</font></a><br>', "Campus");
        map.addOverlay(marker);
        
        var point = new GLatLng(33.610825029, -112.160382167);
        var marker = createMarker(point, '<a href="http://www.west.asu.edu/" target="_blank"><font face="Arial" size=1>West campus</font></a><br>', "Campus");
        map.addOverlay(marker);

        var point = new GLatLng(33.3062402445, -111.681138381);
        var marker = createMarker(point, '<a href="http://www.poly.asu.edu/" target="_blank"><font face="Arial" size=1>Polytechnic campus</font></a><br>', "Campus");
        map.addOverlay(marker);
        
        }



    function ShowASUMarkers() {

        map.clearOverlays();
        AddASUMarkers();
    }

    function SearchQuery() {

        document.getElementById('load_text').innerHTML = "Querying Database...";
        var tquer5 = new Sys.Data.DataService("AIC.svc/");
        var search_str = document.getElementById('searchtxt').value;
        //alert(search_str);
        if (search_str == '') {
            alert("please enter a value");

        }

        else {
            temp_querystring5 = "/GG_MAPT?$filter=(substringof('" + search_str + "',PROGTITLE))or(substringof('" + search_str + "',LOCATION))or(substringof('" + search_str + "',PROGADDR))or(substringof('" + search_str + "',CITY))or(substringof('" + search_str + "',STATE))or(substringof('" + search_str + "',ZIP))" + "&$orderby=PROGTITLE";
            
            //temp_querystring = "/aicprod?$filter=LOCATION eq '" + location + "'";
            tquer5.query(temp_querystring5, tsearchSuccess_page, cbFailure);
            //tquer1.query("/aicprod", cbSuccess, cbFailure);

            //alert(temp_querystring5);
            document.getElementById('load_text').innerHTML = "Sending inner query to server...";
        
        }
        
    
    
    }
        
        
        
   
