   ////// LETS GEOCODE THE ADDRESS;
		       var geocoder;
		       function Gload() {
		             geocoder = new GClientGeocoder();
		       }
    
		       function addToMap(response) {
		             if (!response || response.Status.code != 200) {
					      alert("Sorry, we were unable to geocode that address");
		             } else {
					      // Retrieve the object
					      place = response.Placemark[0];
					       // Retrieve the latitude and longitude
					      point = new GLatLng(place.Point.coordinates[1],
					      place.Point.coordinates[0]);
					      longitud= place.Point.coordinates[0];
					      latitud= place.Point.coordinates[1];
					      //alert(latitud);
                                              document.getElementById('latitud').value=latitud;
                                               document.getElementById('longitud').value=longitud;
		             }
		       }
                       
								 
		       function showLocation(){
			  //var address = "821 Mohawk Street, Columbus OH";
			Gload();
		          var address = document.getElementById('address1').value +" "+ document.register.abre.value +", "+ document.getElementById('city').value + " " + document.getElementById('state').value ;
			 geocoder.getLocations(address, addToMap);
                         //alert(address);
		       }
                        
                        
                        function compareToMap(response){
                               if (!response || response.Status.code != 200) {
					      alert("Sorry, we were unable to geocode that address");
		             } else {
                                     // Retrieve the object
					      place = response.Placemark[0];
					       // Retrieve the latitude and longitude
					      point = new GLatLng(place.Point.coordinates[1],
					      place.Point.coordinates[0]);
					      longitud= place.Point.coordinates[0];
					      latitud= place.Point.coordinates[1];
					      alert(latitud);
                                              //document.getElementById('latitud').value=latitud;
                                              // document.getElementById('longitud').value=longitud;
		             }
                        }
                        
                        
                        function findLocation(){
			  //var address = "821 Mohawk Street, Columbus OH";
			Gload();
		          var address = document.getElementById('addr').value +" "+ document.searchForm.abre.value +", "+ document.getElementById('city').value + " " + document.getElementById('state').value ;
			 geocoder.getLocations(address, compareToMap);
                        //alert(address);
		       }
                       

			function restoreMapDefault() {
			   map.checkResize();
			map.setCenter(new GLatLng(41.320084,-72.928929), 13);
			 }
			
			function resize_display()  { 
			   var w = $( window );
			   var H = w.height(); 
			   var W = w.width(); 
			   $('#projectList').css( {height: H-307} ); 
			   $('#scrollProjects').css( {height: H-343} ); 
			   $('#map').css( {height: H-80, width: W-255} );
			   $('#management').css( {height: H-80, width: W-255} ); 
			   $('#container').css( {height: H, width: W} ); 
			   if (typeof(map)!="undefined") { restoreMapDefault(); }
		       }
		       
		       function resize_manage()  { 
			   var w = $( window );
			   var H = w.height(); 
			   var W = w.width();
			   $('#projectList').css( {height: H-307} ); 
			   $('#scrollProjects').css( {height: H-343} );
			   $('#management').css( {height: H-80, width: W-255} ); 
			   $('#container').css( {height: H, width: W} ); 
		       }
		      


 function handleHttpResponse() {   
        if (http.readyState == 4) {
              if(http.status==200) {
                  var results=http.responseText;
              document.getElementById('divWait').value = results;
			 // document.program.slot.value = results;
              }
              }
        }
       
        function requestCustomerInfo(newLoc) { 
		 	ProgramID = newLoc.options[newLoc.selectedIndex].value    
		 	 var url = "lude/tils/waiting.php?id="+ProgramID+""; // The server-side script
           // var sId = document.getElementById("txtCustomerId").value;
            http.open("GET", url , true);
            http.onreadystatechange = handleHttpResponse;
            http.send(null);
        }
		function getHTTPObject() {
		  var xmlhttp;
		
		  if(window.XMLHttpRequest){
			xmlhttp = new XMLHttpRequest();
		  }
		  else if (window.ActiveXObject){
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
			if (!xmlhttp){
				xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
			}
		   
		}
		  return xmlhttp;
		
		 
		}
		var http = getHTTPObject(); // We create the HTTP Object
  
    var gmarkers = [];
   var gicons = [];
 
 //// create white icon ///////
 
	  gicons["g0"] = new GIcon(); 
	  gicons["g0"].image = "images/icons/guy_white.png"; 
      gicons["g0"].iconSize = new GSize(20, 20); 
      gicons["g0"].iconAnchor = new GPoint(6, 20); 
      gicons["g0"].infoWindowAnchor = new GPoint(5, 1);
      
      
	  //// create red icons ///////
	 gicons["g1"] = new GIcon(); 
	 gicons["g1"].image = "images/icons/guy_red.png"; 
     gicons["g1"].iconSize = new GSize(20, 20); 
    gicons["g1"].iconAnchor = new GPoint(6, 20); 
     gicons["g1"].infoWindowAnchor = new GPoint(5, 1);
      
	   //// create yellow icons ///////
	 gicons["g2"] = new GIcon(); 
	 gicons["g2"].image = "images/icons/guy_yellow.png"; 
     gicons["g2"].iconSize = new GSize(20, 20); 
    gicons["g2"].iconAnchor = new GPoint(6, 20); 
     gicons["g2"].infoWindowAnchor = new GPoint(5, 1);
	 
	  //// create orange icons ///////
	 gicons["g3"] = new GIcon(); 
	 gicons["g3"].image = "images/icons/guy_orange.png"; 
     gicons["g3"].iconSize = new GSize(20, 20); 
     gicons["g3"].iconAnchor = new GPoint(6, 20); 
     gicons["g3"].infoWindowAnchor = new GPoint(5, 1);
	 
	  //// create blue icons ///////
	 gicons["g4"] = new GIcon(); 
	 gicons["g4"].image = "images/icons/guy_blue.png"; 
     gicons["g4"].iconSize = new GSize(20, 20); 
     gicons["g4"].iconAnchor = new GPoint(6, 20); 
     gicons["g4"].infoWindowAnchor = new GPoint(5, 1);
	 
	  //// create aqua icons ///////
	 gicons["g5"] = new GIcon(); 
	 gicons["g5"].image = "images/icons/guy_aqua.png"; 
     gicons["g5"].iconSize = new GSize(20, 20); 
     gicons["g5"].iconAnchor = new GPoint(6, 20); 
     gicons["g5"].infoWindowAnchor = new GPoint(5, 1);
	 
	  //// create green icons ///////
	 gicons["g6"] = new GIcon(); 
	 gicons["g6"].image = "images/icons/guy_green.png"; 
     gicons["g6"].iconSize = new GSize(20, 20); 
     gicons["g6"].iconAnchor = new GPoint(6, 20); 
     gicons["g6"].infoWindowAnchor = new GPoint(5, 1);
	 
	  //// create darkgreen icons ///////
	 gicons["g7"] = new GIcon(); 
	 gicons["g7"].image = "images/icons/guy_darkgreen.png"; 
     gicons["g7"].iconSize = new GSize(20, 20); 
     gicons["g7"].iconAnchor = new GPoint(6, 20); 
     gicons["g7"].infoWindowAnchor = new GPoint(5, 1);
	 
	  //// create pink icons ///////
	 gicons["g8"] = new GIcon(); 
	 gicons["g8"].image = "images/icons/guy_pink.png"; 
     gicons["g8"].iconSize = new GSize(20, 20); 
     gicons["g8"].iconAnchor = new GPoint(6, 20); 
     gicons["g8"].infoWindowAnchor = new GPoint(5, 1);
 
 

////navigation funcitons 
function ZoomIn(lat,lon){
	      map.setCenter(new GLatLng(lat,lon), 16, G_NORMAL_MAP);
}
	  
function ZoomOut(){
	 map.setMapType(G_PHYSICAL_MAP);
         map.setCenter(new GLatLng(41.320084,-72.928929), 13);
} 
      
// Creates a marker for agencies whose info window displays the given number
function createMarker(point, number,type)
{
var marker = new GMarker(point,gicons[type]);
 // === Store the category and name info as a marker properties ===
marker.mytype = type;  
// Show this markers index in the info window when it is clicked
GEvent.addListener(marker, 'click', function(){ 
            marker.openExtInfoWindow(
              map,
              "custom_info_window_bubble",
              "<div>Loading Tabs...</div>",
              {beakOffset: 3, ajaxUrl: "lude/tils/descriptive.php?id="+number+""}
             );
            map.getExtInfoWindow().resize();
            }
      );
        GEvent.addDomListener(map, 'extinfowindowupdate',function(){
            var windowContent = document.getElementById("custom_info_window_bubble_contents");
            var tabs = new Array(document.getElementById("tab0"),document.getElementById("tab1"));
            if( tabs.length > 0 ){
              var tabContentsArray = new Array(tabs.length);
              for( i=0; i < tabs.length; i++){
                tabContentsArray[i] = document.getElementById("tab"+i+"_content");
                if( i > 0){
                  hideTab(tabContentsArray[i]);
                }
                tabs[i].setAttribute("name", i.toString());
              
                GEvent.addDomListener(tabs[i],"click",function(){
                  var tabIndex = this.getAttribute("name");
                
                  for(tabContentIndex=0; tabContentIndex < tabs.length; tabContentIndex++){
                    if( tabContentIndex == tabIndex ){
                      showTab(tabContentsArray[tabContentIndex]);
                    }else{
                      hideTab(tabContentsArray[tabContentIndex]);
                    }
                  }
                  map.getExtInfoWindow().resize();
                });
              }
            }
          });

gmarkers.push(marker);
return marker;
};

///create markers for Programs with different location
function createMarkerPro(point, number,type)
{
var marker = new GMarker(point,gicons[type]);
 // === Store the category and name info as a marker properties ===
marker.mytype = type;  
// Show this markers index in the info window when it is clicked
GEvent.addListener(marker, 'click', function(){ 
            marker.openExtInfoWindow(
              map,
              "custom_info_window_bubble",
              "<div>Loading Tabs...</div>",
              {beakOffset: 3, ajaxUrl: "lude/tils/descriptivePro.php?id="+number+""}
            ); 
            }
      );
        GEvent.addDomListener(map, 'extinfowindowupdate',function(){
            var windowContent = document.getElementById("custom_info_window_bubble_contents");
            var tabs = new Array(document.getElementById("tab0"),document.getElementById("tab1"));
            if( tabs.length > 0 ){
              var tabContentsArray = new Array(tabs.length);
              for( i=0; i < tabs.length; i++){
                tabContentsArray[i] = document.getElementById("tab"+i+"_content");
                if( i > 0){
                  hideTab(tabContentsArray[i]);
                }
                tabs[i].setAttribute("name", i.toString());
              
                GEvent.addDomListener(tabs[i],"click",function(){
                  var tabIndex = this.getAttribute("name");
                
                  for(tabContentIndex=0; tabContentIndex < tabs.length; tabContentIndex++){
                    if( tabContentIndex == tabIndex ){
                      showTab(tabContentsArray[tabContentIndex]);
                    }else{
                      hideTab(tabContentsArray[tabContentIndex]);
                    }
                  }
                  map.getExtInfoWindow().resize();
                });
              }
            }
          });

gmarkers.push(marker);
return marker;
};


function handleHttpResponse2() {   
        if (http.readyState == 4) {
              if(http.status==200) {
                  var results=http.responseText;
              document.getElementById('tab1_content').innerHTML = results;
              map.getExtInfoWindow().resize();
              }
              }
        }
function handleHttpResponse3() {   
        if (http.readyState == 4) {
              if(http.status==200) {
                  var results=http.responseText;
              document.getElementById('tab0_content').innerHTML = results;
              map.getExtInfoWindow().resize();
              }
              }
        }
function getmore(id, type){  
      var url = "lude/tils/descriptivemore.php?id="+id+"&type="+type+""; // The server-side script
      http.open("GET", url , true);
      if(type=="program"){  
       http.onreadystatechange = handleHttpResponse3;
      }else if(type=="agency"){
         http.onreadystatechange = handleHttpResponse2;   
      }
   http.send(null);
      
}


function viewall(id){  
      var url = "lude/tils/descriptiveall.php?id="+id+""; // The server-side script
      http.open("GET", url , true);
      http.onreadystatechange = handleHttpResponse2;
      http.send(null);
}

function viewPro(id){
      var url = "lude/tils/descriptivePro.php?id="+id+""; // The server-side script
      http.open("GET", url , true);
      http.onreadystatechange = handleHttpResponse3;
      http.send(null);
}


/**
       * Helper function to hide the given DOM element
       * @param {Object} element The DOM element that should be hidden
       */
      function hideTab(element){
        element.style.display = "none";
        element.style.position = "absolute";
      }
      /**
       * Helper function to show the given DOM element
       * @param {Object} element The DOM element that should be displayed
       */
      function showTab(element){
        element.style.display = "block";
        element.style.position = "relative";
      }



function myclick(i) {
        GEvent.trigger(gmarkers[i],"click");
      }




 function show(type) {
        for (var i=0; i<gmarkers.length; i++) {
          if (gmarkers[i].mytype == type) {
            gmarkers[i].show();
          }
        }
        // == check the checkbox ==
        document.getElementById(type+"box").checked = true;
      }

      // == hides all markers of a particular type, and ensures the checkbox is cleared ==
      function hide(type) {
        for (var i=0; i<gmarkers.length; i++) {
          if (gmarkers[i].mytype == type) {
            gmarkers[i].hide();
          }
        }
        // == clear the checkbox ==
        document.getElementById(type+"box").checked = false;
        // == close the info window, in case its open on a marker that we just hid
        map.closeInfoWindow();
      }

      // == a checkbox has been clicked ==
      function boxclick(box,type) {
        if (box.checked) {
            if (document.getElementById('g0box').checked) {
            hideA('g0');
            }
            show(type);

        } else {
          hide(type);
        }
        // == rebuild the side bar
       // makeSidebar();
      }

      function hideAll(){
          if (document.getElementById('g1box').checked) {
          hide('g1');
          }
          if (document.getElementById('g2box').checked) {
          hide('g2');
          }
          if (document.getElementById('g3box').checked) {
          hide('g3');
          }
          if (document.getElementById('g4box').checked) {
          hide('g4');
          }
          if (document.getElementById('g5box').checked) {
          hide('g5');
          }
          if (document.getElementById('g6box').checked) {
          hide('g6');
          }
          if (document.getElementById('g7box').checked) {
          hide('g7');
          }
          if (document.getElementById('g8box').checked) {
          hide('g8');
          }   
      }
      
      function hideRefine(){
            
           if (document.getElementById('slots').checked) {
            document.getElementById('slots').checked = false;
            //refine(0);
            }
            if (document.getElementById('register').checked) {
                  document.getElementById('register').checked = false;
            //refine(0);
            }
            if (document.getElementById('intern').checked) {
                  document.getElementById('intern').checked = false;
            //refine(0);
            }
            if (document.getElementById('moreop').checked) {
                  document.getElementById('moreop').checked = false;
            //refine(0);
            }
      }

    ///SHOW ALL
    
     function showA(type) {
       /*
        for (var i=0; i<gmarkers.length; i++) {
        gmarkers[i].show();
        }
       */
       refine(0);
        // == check the checkbox ==
        document.getElementById(type+"box").checked = true;
      }

      // == hides all markers of a particular type, and ensures the checkbox is cleared ==
      function hideA(type) {
       for (var i=0; i<gmarkers.length; i++) {
       //   if (gmarkers[i].mytype == type) {
            gmarkers[i].hide();
       //  }
        } 
        // == clear the checkbox ==
        document.getElementById(type+"box").checked = false;
        // == close the info window, in case its open on a marker that we just hid
        map.closeInfoWindow();
      }
      // == a checkbox has been clicked ==
      function boxclickA(box,type) {
        if (box.checked) {
         //refine(0);
          hideAll();
          hideRefine();
          showA(type);
        } else {
          hideA(type);
        }
        // == rebuild the side bar
       // makeSidebar();
      }
   
   
 /*     
   ////show agencies with slots available

   
function showslots(box){
      
      if(box.checked){
          var val="1";  
      }else{
          var val="0";  
      }
        
         // A function to read the programs data
      var url2 = "lude/tils/slotsPro.php?val="+val+""; // The server-side script
      var request2 = GXmlHttp.create();
      request2.open("GET", url2, true);
      request2.onreadystatechange = function() {
            if (request2.readyState == 4) {
           
            // var results=http.responseText;
            var xmlDoc2 = GXml.parse(request2.responseText);
            // obtain the array of markers and loop through it
            var markers2 = xmlDoc2.documentElement.getElementsByTagName("marker");
            
            map.clearOverlays();
             // empty the arrays
            ii = 0;

             for (var i = 0; i < markers2.length; i++) {
                   // obtain the attribues of each marker
              var lat2 = parseFloat(markers2[i].getAttribute("lat"));
              var lng2 = parseFloat(markers2[i].getAttribute("lng"));
              var point2 = new GLatLng(lat2,lng2);
              var number2 = markers2[i].getAttribute("AgencyID");
              var type2 = markers2[i].getAttribute("type_id");
              // create the marker
              var marker2 = createMarkerPro(point2,number2,type2);
              map.addOverlay(marker2);
            }

         
          }
      }
      
        request2.send(null);
      // A function to read the agencies data
      var url = "lude/tils/slots.php?val="+val+""; // The server-side script
      var request = GXmlHttp.create();
      request.open("GET", url, true);
      request.onreadystatechange = function() {
            if (request.readyState == 4) {
           
            // var results=http.responseText;
            var xmlDoc = GXml.parse(request.responseText);
            // obtain the array of markers and loop through it
            var markers = xmlDoc.documentElement.getElementsByTagName("marker");
            
             // empty the arrays
            ii = 0;

             for (var i = 0; i < markers.length; i++) {
                   // obtain the attribues of each marker
              var lat = parseFloat(markers[i].getAttribute("lat"));
              var lng = parseFloat(markers[i].getAttribute("lng"));
              var point = new GLatLng(lat,lng);
              var number = markers[i].getAttribute("AgencyID");
              var type = markers[i].getAttribute("type_id");
              // create the marker
              var marker = createMarker(point,number,type);
              map.addOverlay(marker);
            }

         
          }
      }
    request.send(null);
   
}
*/

      	// == shows all spatial layers, and ensures the checkbox is checked ==
      function showS(group) {
            if(group=="minor"){
                map.addOverlay(minor);
                document.getElementById('legend').innerHTML="<img src=\"images/bar2.gif\">";
            }else if(group=="bus"){
                map.addOverlay(bus);
            }else if(group=="income"){
                map.addOverlay(income);
                document.getElementById('legend').innerHTML="<img src=\"images/bar2.gif\">";
            }else if(group=="english"){
                map.addOverlay(english);
                document.getElementById('legend').innerHTML="<img src=\"images/bar2.gif\">";
            }else if(group=="foreign"){
                map.addOverlay(foreign);
                document.getElementById('legend').innerHTML="<img src=\"images/bar2.gif\">";
            }else if(group=="census"){
                map.addOverlay(census);  
            }else if(group=="programs"){
				map.addOverlay(programs);
				 document.getElementById('legend').innerHTML="<img src=\"images/bar20.gif\">";
			}else if(group=="nums"){
				map.addOverlay(nums);
				 document.getElementById('legend').innerHTML="<img src=\"images/bar2.gif\">";
			}

        // == check the checkbox ==
        document.getElementById(group+"box").checked = true;
      }
 
    // == hides all markers of Ecosystem, and ensures the checkbox is cleared ==
      function hideS(group) {
            if(group=="minor"){
                  map.removeOverlay(minor);
                  document.getElementById('legend').innerHTML="";
            }else if(group=="bus"){
                  map.removeOverlay(bus);
            }else if(group=="income"){
                  map.removeOverlay(income);
                  document.getElementById('legend').innerHTML="";
            }else if(group=="english"){
                  map.removeOverlay(english);
                  document.getElementById('legend').innerHTML="";
            }else if(group=="foreign"){
                  map.removeOverlay(foreign);
                  document.getElementById('legend').innerHTML="";
            }else if(group=="census"){
                map.removeOverlay(census);  
            }else if(group=="programs"){
				map.removeOverlay(programs);
                  document.getElementById('legend').innerHTML="";
			}else if(group=="nums"){
				map.removeOverlay(nums);
                  document.getElementById('legend').innerHTML="";
			}
        // == clear the checkbox ==
		
		document.getElementById(group+"box").checked = false;
      }

      // == a checkbox has been clicked ==
      function boxclickS(box,group) {
        if (box.checked) {
          showS(group);
        } else {
          hideS(group);
        }
        // == rebuild the side bar
       // makeSidebar();
      }
 

 
 function refine(val){
      
      ///hidde other checkboxes
      hideAll();
      if (document.getElementById('g0box').checked) {
      hideA('g0');
      }
      
          // A function to read the programs data
      var url2 = "lude/tils/slotsPro.php?val="+val+""; // The server-side script
      var request2 = GXmlHttp.create();
      request2.open("GET", url2, true);
      request2.onreadystatechange = function() {
            if (request2.readyState == 4) {
           
            // var results=http.responseText;
            var xmlDoc2 = GXml.parse(request2.responseText);
            // obtain the array of markers and loop through it
            var markers2 = xmlDoc2.documentElement.getElementsByTagName("marker");
            
            map.clearOverlays();
             // empty the arrays
            i = 0;

             for (var i = 0; i < markers2.length; i++) {
                   // obtain the attribues of each marker
              var lat2 = parseFloat(markers2[i].getAttribute("lat"));
              var lng2 = parseFloat(markers2[i].getAttribute("lng"));
              var point2 = new GLatLng(lat2,lng2);
              var number2 = markers2[i].getAttribute("AgencyID");
              var type2 = markers2[i].getAttribute("type_id");
              // create the marker
              var marker2 = createMarkerPro(point2,number2,type2);
              map.addOverlay(marker2);
            }

         
          }
      }
      
        request2.send(null);
      // A function to read the agencies data
      var url = "lude/tils/slots.php?val="+val+""; // The server-side script
      var request = GXmlHttp.create();
      request.open("GET", url, true);
      request.onreadystatechange = function() {
            if (request.readyState == 4) {
           
            // var results=http.responseText;
            var xmlDoc = GXml.parse(request.responseText);
            // obtain the array of markers and loop through it
            var markers = xmlDoc.documentElement.getElementsByTagName("marker");
            
             // empty the arrays
            ii = 0;

             for (var ii = 0; ii < markers.length; ii++) {
                   // obtain the attribues of each marker
              var lat = parseFloat(markers[ii].getAttribute("lat"));
              var lng = parseFloat(markers[ii].getAttribute("lng"));
              var point = new GLatLng(lat,lng);
              var number = markers[ii].getAttribute("AgencyID");
              var type = markers[ii].getAttribute("type_id");
              // create the marker
              var marker = createMarker(point,number,type);
              map.addOverlay(marker);
            }

         
          }
      }
    request.send(null);
 }

 
 function refineMore(val,age,type,monthIn,dayIn,yearIn,monthTo,dayTo,yearTo,keyword){
        // A function to read the data for Programs
      var url = "lude/tils/slotsPro.php?val="+val+"&age="+age+"&type="+type+"&monthIn="+monthIn+"&dayIn="+dayIn+"&yearIn="+yearIn+"&monthTo="+monthTo+"&dayTo="+dayTo+"&yearTo="+yearTo+"&keyword="+keyword+""; // The server-side script
      var request2 = GXmlHttp.create();
      request2.open("GET", url, true);
      request2.onreadystatechange = function() {
            if (request2.readyState == 4) {
           
            // var results=http.responseText;
            var xmlDoc2 = GXml.parse(request2.responseText);
            // obtain the array of markers and loop through it
            var markers2 = xmlDoc2.documentElement.getElementsByTagName("marker");
            
           
            map.clearOverlays();
             // empty the arrays
            i = 0;

             for (var i = 0; i < markers2.length; i++) {
                   // obtain the attribues of each marker
              var lat2 = parseFloat(markers2[i].getAttribute("lat"));
              var lng2 = parseFloat(markers2[i].getAttribute("lng"));
              var point2 = new GLatLng(lat2,lng2);
              var number2 = markers2[i].getAttribute("AgencyID");
              var type2 = markers2[i].getAttribute("type_id");
              // create the marker
              var marker2 = createMarkerPro(point2,number2,type2);
              map.addOverlay(marker2);
            }

         
          }
      }
        request2.send(null);
            // A function to read the data
      var url = "lude/tils/slots.php?val="+val+"&age="+age+"&type="+type+"&monthIn="+monthIn+"&dayIn="+dayIn+"&yearIn="+yearIn+"&monthTo="+monthTo+"&dayTo="+dayTo+"&yearTo="+yearTo+"&keyword="+keyword+""; // The server-side script
      var request = GXmlHttp.create();
      request.open("GET", url, true);
      request.onreadystatechange = function() {
            if (request.readyState == 4) {
           
            // var results=http.responseText;
            var xmlDoc = GXml.parse(request.responseText);
            // obtain the array of markers and loop through it
            var markers = xmlDoc.documentElement.getElementsByTagName("marker");
            
             // empty the arrays
            ii= 0;

             for (var ii = 0; ii < markers.length; ii++) {
                   // obtain the attribues of each marker
              var lat = parseFloat(markers[ii].getAttribute("lat"));
              var lng = parseFloat(markers[ii].getAttribute("lng"));
              var point = new GLatLng(lat,lng);
              var number = markers[ii].getAttribute("AgencyID");
              var type = markers[ii].getAttribute("type_id");
              // create the marker
              var marker = createMarker(point,number,type);
              map.addOverlay(marker);
            }

         
          }
      }
        request.send(null);
 }
 
 
 function showslots(box){
       if(box.checked){
            if (document.getElementById('register').checked) {
                  document.getElementById('register').checked = false;
            //refine(0);
            }
            if (document.getElementById('intern').checked) {
                  document.getElementById('intern').checked = false;
            //refine(0);
            }
            if (document.getElementById('moreop').checked) {
                  document.getElementById('moreop').checked = false;
            //refine(0);
            }
            hideAll();
            if (document.getElementById('g0box').checked) {
            hideA('g0');
            }
      refine(1);
      }else{
      refine(0);  
      }  
 }
 
 function showregister(box){
      if(box.checked){
             if (document.getElementById('slots').checked) {
            document.getElementById('slots').checked = false;
           // refine(0);
            }
            if (document.getElementById('intern').checked) {
                  document.getElementById('intern').checked = false;
           // refine(0);
            }
            if (document.getElementById('moreop').checked) {
                  document.getElementById('moreop').checked = false;
           // refine(0);
            }
            hideAll();
            if (document.getElementById('g0box').checked) {
            hideA('g0');
            }
      refine(2);
      }else{
      refine(0);  
      } 
 }
 
 function showinterns(box){
      if(box.checked){
             if (document.getElementById('slots').checked) {
            document.getElementById('slots').checked = false;
           // refine(0);
            }
            if (document.getElementById('register').checked) {
                  document.getElementById('register').checked = false;
           //refine(0);
            }
            if (document.getElementById('moreop').checked) {
                  document.getElementById('moreop').checked = false;
           // refine(0);
            }
            hideAll();
            if (document.getElementById('g0box').checked) {
            hideA('g0');
            }
      refine(3);
      }else{
      refine(0);  
      } 
 }

 





//////validate email
//////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////

function emailCheck (emailStr) {

/* The following variable tells the rest of the function whether or not
to verify that the address ends in a two-letter country or well-known
TLD.  1 means check it, 0 means don't. */

var checkTLD=1;

/* The following is the list of known TLDs that an e-mail address must end with. */

var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

/* The following pattern is used to check if the entered e-mail address
fits the user@domain format.  It also is used to separate the username
from the domain. */

var emailPat=/^(.+)@(.+)$/;

/* The following string represents the pattern for matching all special
characters.  We don't want to allow special characters in the address. 
These characters include ( ) < > @ , ; : \ " . [ ] */

var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

/* The following string represents the range of characters allowed in a 
username or domainname.  It really states which chars aren't allowed.*/

var validChars="\[^\\s" + specialChars + "\]";

/* The following pattern applies if the "user" is a quoted string (in
which case, there are no rules about which characters are allowed
and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
is a legal e-mail address. */

var quotedUser="(\"[^\"]*\")";

/* The following pattern applies for domains that are IP addresses,
rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
e-mail address. NOTE: The square brackets are required. */

var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

/* The following string represents an atom (basically a series of non-special characters.) */

var atom=validChars + '+';

/* The following string represents one word in the typical username.
For example, in john.doe@somewhere.com, john and doe are words.
Basically, a word is either an atom or quoted string. */

var word="(" + atom + "|" + quotedUser + ")";

// The following pattern describes the structure of the user

var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

/* The following pattern describes the structure of a normal symbolic
domain, as opposed to ipDomainPat, shown above. */

var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

/* Finally, let's start trying to figure out if the supplied address is valid. */

/* Begin with the coarse pattern to simply break up user@domain into
different pieces that are easy to analyze. */

var matchArray=emailStr.match(emailPat);

if (matchArray==null) {

/* Too many/few @'s or something; basically, this address doesn't
even fit the general mould of a valid e-mail address. */

alert("Email address seems incorrect (check @ and .'s)");
return false;
}
var user=matchArray[1];
var domain=matchArray[2];

// Start by checking that only basic ASCII characters are in the strings (0-127).

for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
alert("Ths username contains invalid characters.");
return false;
   }
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
alert("Ths domain name contains invalid characters.");
return false;
   }
}

// See if "user" is valid 

if (user.match(userPat)==null) {

// user is not valid

alert("The username doesn't seem to be valid.");
return false;
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
host name) make sure the IP address is valid. */

var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {

// this is an IP address

for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
alert("Destination IP address is invalid!");
return false;
   }
}
return true;
}

// Domain is symbolic name.  Check if it's valid.
 
var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {
alert("The domain name does not seem to be valid.");
return false;
   }
}

/* domain name seems valid, but now make sure that it ends in a
known top-level domain (like com, edu, gov) or a two-letter word,
representing country (uk, nl), and that there's a hostname preceding 
the domain or country. */

if (checkTLD && domArr[domArr.length-1].length!=2 && 
domArr[domArr.length-1].search(knownDomsPat)==-1) {
alert("The email address must end in a well-known domain or two letter " + "country.");
return false;
}

// Make sure there's a host name preceding the domain.

if (len<2) {
alert("This address is missing a hostname!");
return false;
}

// If we've gotten this far, everything's valid!
return true;
}

//  End -->
////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////

/* validate website */
function validWeb(website){
      var RegExp = /^(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/; 
      if(RegExp.test(website)){
        return true;
       }else{
        return false;
       }
}

function checkField(field){
    var frm = document.frmValidate, error = "";
    if(!validWeb(field.value)){
        alert('Please enter a valid URL');
    }
   
    if(error != ""){
        alert(error);
        return false;
    }else{
        return true;
    }
}

//////////////////////////////////////////////////////////////////////////////////////////
 
 /*pick field to validate*/
function validate_required(field,alerttxt)
{
with (field)
  {
  if (value==null||value=="")
    {
    alert(alerttxt);return false;
    }
  else
    {
    return true;
    }
  }
}

////validate numeric value

function IsNumeric(sText)

{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }




///validation for Register Agency

function validRegister(thisform)
{
      
/////validate email
emailCheck(document.register.email.value);

      with (thisform){
            if (validate_required(name,"Program Name must be filled out!")==false)
            {name.focus();return false;}
  
            if (validate_required(address1,"Address must be filled out!")==false)
            {address1.focus();return false;}
            
             if (validate_required(abre,"Street type must be filled out!")==false)
            {abre.focus();return false;}
            
            if (validate_required(fname,"First Name must be filled out!")==false)
            {fname.focus();return false;}
            
            if (validate_required(lname,"Last Name must be filled out!")==false)
            {lname.focus();return false;}
            
            if (validate_required(email,"Email must be filled out!")==false)
            {email.focus();return false;}
      }
}

////validation for Agency

function validProfile(thisform){
with (thisform){
     if (validate_required(name,"Agency Name must be filled out!")==false)
      {name.focus();return false;}
      var illegalChars = /[\\\#%\^\*\[\]\+\_\{\}\`\~\=\|]/;
      // allow only letters, numbers, and underscores
      if (illegalChars.test(thisform.name.value)) {
       alert('Sorry, but the following characters\n\r\n\r % ^  * # [ ] \\ { + } ` ~ =  | \n\r\n\rare not allowed!');
       thisform.name.focus();
       return false;
      }
      if(thisform.name.value.length>200){
      alert("The Name field cannot contain more than 200 characters!");
      thisform.name.focus();
        return false;
      }
   
      if (illegalChars.test(thisform.address1.value)) {
       alert('Sorry, but the following characters\n\r\n\r % ^  * # [ ] \\ { + } ` ~ =  | \n\r\n\rare not allowed!');
       thisform.address1.focus();
       return false;
      }
      if(thisform.address1.value.length>150){
      alert("The Address field cannot contain more than 150 characters!");
      thisform.address1.focus();
        return false;
      }
      if (illegalChars.test(thisform.address2.value)) {
       alert('Sorry, but the following characters\n\r\n\r % ^  * # [ ] \\ { + } ` ~ =  | \n\r\n\rare not allowed!');
       thisform.address2.focus();
       return false;
      }
      if(thisform.address2.value.length>100){
      alert("The Address 2 field cannot contain more than 100 characters!");
      thisform.address2.focus();
        return false;
      }
       if (illegalChars.test(thisform.city.value)) {
       alert('Sorry, but the following characters\n\r\n\r % ^  * # [ ] \\ { + } ` ~ =  | \n\r\n\rare not allowed!');
       thisform.city.focus();
       return false;
      }
      if(thisform.city.value.length>100){
      alert("The City field cannot contain more than 100 characters!");
      thisform.city.focus();
        return false;
      }     
       if (illegalChars.test(thisform.zip1.value)) {
       alert('Sorry, but the following characters\n\r\n\r % ^  * # [ ] \\ { + } ` ~ =  | \n\r\n\rare not allowed!');
       thisform.zip1.focus();
       return false;
      }
      /*
      if(thisform.zip1.value.length>5){
      alert("The Zip field cannot contain more than 5 characters!");
      thisform.zip1.focus();
        return false;
      }
      if (!IsNumeric(thisform.zip1.value)){ 
      alert('Please enter only numbers in the zip field') 
      thisform.zip1.focus(); 
      return false; 
      }     
       if (illegalChars.test(thisform.zip2.value)) {
       alert('Sorry, but the following characters\n\r\n\r % ^  * # [ ] \\ { + } ` ~ =  | \n\r\n\rare not allowed!');
       thisform.zip2.focus();
       return false;
      }
      if(thisform.zip2.value.length>5){
      alert("The Zip field cannot contain more than 5 characters!");
      thisform.zip2.focus();
        return false;
      }  
       if (!IsNumeric(thisform.zip2.value)){ 
      alert('Please enter only numbers in the zip field') 
      thisform.zip2.focus(); 
      return false; 
      }
      */
       if (illegalChars.test(thisform.phone1.value)) {
       alert('Sorry, but the following characters\n\r\n\r % ^  * # [ ] \\ { + } ` ~ =  | \n\r\n\rare not allowed!');
       thisform.phone1.focus();
       return false;
      }
/*
      if(thisform.phone1.value.search(/\d{3}\-\d{3}\-\d{4}/)==-1){
      alert('The phone number you entered is not valid.\r\nPlease enter a phone number with the format xxx-xxx-xxxx.');
      return false;
      }
*/
       if(thisform.phone1.value.length>15){
      alert("The Phone field cannot contain more than 15 characters!");
      thisform.phone1.focus();
        return false;
      }  
       if (illegalChars.test(thisform.phone2.value)) {
       alert('Sorry, but the following characters\n\r\n\r % ^  * # [ ] \\ { + } ` ~ =  | \n\r\n\rare not allowed!');
       thisform.phone2.focus();
       return false;
      }
       if(thisform.phone2.value.length>5){
      alert("The Phone field cannot contain more than 5 characters!");
      thisform.phone2.focus();
        return false;
      }  
      /*
       if(thisform.fax.value.search(/\d{3}\-\d{3}\-\d{4}/)==-1){
      alert('The fax number you entered is not valid.\r\nPlease enter a phone number with the format xxx-xxx-xxxx.');
      return false;
      }
      */
       if(thisform.fax.value.length>15){
      alert("The Fax field cannot contain more than 15 characters!");
      thisform.fax.focus();
        return false;
      }       
      /////validate email
      emailCheck(document.org.email.value);
       if (illegalChars.test(thisform.POBox.value)) {
       alert('Sorry, but the following characters\n\r\n\r % ^  * # [ ] \\ { + } ` ~ =  | \n\r\n\rare not allowed!');
       thisform.POBox.focus();
       return false;
      }
       if(thisform.POBox.value.length>5){
      alert("The POBox field cannot contain more than 5 characters!");
      thisform.POBox.focus();
        return false;
      }  
      if (!IsNumeric(thisform.POBox.value)) { 
      alert('Please enter only numbers in the PO Box field') 
      thisform.POBox.focus(); 
      return false; 
      }
      if (illegalChars.test(thisform.tag1.value)) {
       alert('Sorry, but the following characters\n\r\n\r % ^  * # [ ] \\ { + } ` ~ =  | \n\r\n\rare not allowed!');
       thisform.tag1.focus();
       return false;
       }
      if(thisform.tag1.value.length>20){
      alert("The Tag1 field cannot contain more than 20 characters!");
      thisform.tag1.focus();
        return false;
      }
      if (illegalChars.test(thisform.tag2.value)) {
       alert('Sorry, but the following characters\n\r\n\r % ^  * # [ ] \\ { + } ` ~ =  | \n\r\n\rare not allowed!');
       thisform.tag2.focus();
       return false;
      }
     if(thisform.tag2.value.length>20){
      alert("The Tag2 field cannot contain more than 20 characters!");
      thisform.tag2.focus();
        return false;
      }
     
      if (illegalChars.test(thisform.description.value)) {
       alert('Sorry, but the following characters\n\r\n\r $ % ^ * # [ ] \\ { + } ` ~ =  | \n\r\n\rare not allowed!');
       thisform.description.focus();
       return false;
      }
       if (!IsNumeric(thisform.yearcreated.value)) { 
      alert('Please enter only numbers in the Year Created field') 
      thisform.yearcreated.focus(); 
      return false; 
      }
      if (illegalChars.test(thisform.attachName.value)) {
       alert('Sorry, but the following characters\n\r\n\r % ^  * # [ ] \\ { + } ` ~ =  | \n\r\n\rare not allowed!');
       thisform.attachName.focus();
       return false;
    }
    if(thisform.attachName.value.length>50){
      alert("The Document Title field cannot contain more than 50 characters!");
      thisform.attachName.focus();
        return false;
    }
      if (validate_required(numPrograms,"Number of Programs must be filled out!")==false)
      {numPrograms.focus();return false;}
      
       if (!IsNumeric(thisform.numPrograms.value)) { 
      alert('Please enter only numbers in the PO Box field') 
      thisform.numPrograms.focus(); 
      return false; 
      }
      if (illegalChars.test(thisform.first.value)) {
       alert('Sorry, but the following characters\n\r\n\r % ^  * # [ ] \\ { + } ` ~ =  | \n\r\n\rare not allowed!');
       thisform.first.focus();
       return false;
    }
     if(thisform.first.value.length>50){
      alert("The Contact First Name field cannot contain more than 50 characters!");
      thisform.contactFname.focus();
        return false;
    }
     if (illegalChars.test(thisform.last.value)) {
       alert('Sorry, but the following characters\n\r\n\r % ^  * # [ ] \\ { + } ` ~ =  | \n\r\n\rare not allowed!');
       thisform.last.focus();
       return false;
    }
     if(thisform.last.value.length>50){
      alert("The Contact Last Name field cannot contain more than 50 characters!");
      thisform.last.focus();
        return false;
    }
     if (illegalChars.test(thisform.position.value)) {
       alert('Sorry, but the following characters\n\r\n\r@ $ % ^ * # ( ) [ ] \\ { + } ` ~ =  | \n\r\n\rare not allowed!');
       thisform.position.focus();
       return false;
    }
     if(thisform.position.value.length>50){
      alert("The Position field cannot contain more than 50 characters!");
      thisform.position.focus();
        return false;
    }
      if (!IsNumeric(thisform.cphone2.value)) { 
      alert('Please enter only numbers in the PO Box field') 
      thisform.cphone2.focus(); 
      return false; 
      }
      /*
      if(thisform.cphone1.value.search(/\d{3}\-\d{3}\-\d{4}/)==-1){
      alert('The phone number you entered is not valid.\r\nPlease enter a phone number with the format xxx-xxx-xxxx.');
      return false;
      }
      */
      if (!IsNumeric(thisform.cphone2.value)) { 
      alert('Please enter only numbers in the phone extension field') 
      thisform.cphone2.focus(); 
      return false; 
      }
      /////validate email
      emailCheck(document.org.cemail.value);
      //validate website
      
}
}




/////validation for Add Program

function validProgr(thisform)
{
with (thisform)
  {
  if (validate_required(name,"Program Name must be filled out!")==false)
  {name.focus();return false;}
   if (validate_required(youthnum,"Number of Youth Served must be filled out!")==false)
  {youthnum.focus();return false;}
  }
  if (!IsNumeric(thisform.YearCreated.value)) 
      { 
      alert('Please enter only numbers in the account field') 
      thisform.YearCreated.focus(); 
      return false; 
      }
   if (!IsNumeric(thisform.youthnum.value)) 
      { 
      alert('Please enter only numbers in the account field') 
      thisform.youthnum.focus(); 
      return false; 
      }
   if (!IsNumeric(thisform.agefrom.value)) 
      { 
      alert('Please enter only numbers in the account field') 
      thisform.agefrom.focus(); 
      return false; 
      }
      if (!IsNumeric(thisform.ageto.value)) 
      { 
      alert('Please enter only numbers in the account field') 
      thisform.ageto.focus(); 
      return false; 
      }
      var illegalChars = /[\\\#%\^\*\[\]\+\_\{\}\`\~\=\|]/;
  // allow only letters, numbers, and underscores
  if (illegalChars.test(thisform.name.value)) {
       alert('Sorry, but the following characters\n\r\n\r % ^ * # [ ] \\ { + } ` ~ =  | \n\r\n\rare not allowed!');
       thisform.name.focus();
       return false;
    }
    if(thisform.name.value.length>200){
      alert("The Name field cannot contain more than 200 characters!");
      thisform.name.focus();
        return false;
    }
     if (illegalChars.test(thisform.description.value)) {
       alert('Sorry, but the following characters\n\r\n\r  % ^ * # [ ] \\ { + } ` ~ =  | \n\r\n\rare not allowed!');
       thisform.description.focus();
       return false;
    }
    
     if (illegalChars.test(thisform.tag1.value)) {
       alert('Sorry, but the following characters\n\r\n\r % ^  * # [ ] \\ { + } ` ~ =  | \n\r\n\rare not allowed!');
       thisform.tag1.focus();
       return false;
    }
    if(thisform.tag1.value.length>20){
      alert("The Tag1 field cannot contain more than 20 characters!");
      thisform.tag1.focus();
        return false;
    }
    if (illegalChars.test(thisform.tag2.value)) {
       alert('Sorry, but the following characters\n\r\n\r % ^ * #  [ ] \\ { + } ` ~ =  | \n\r\n\rare not allowed!');
       thisform.tag2.focus();
       return false;
    }
     if(thisform.tag2.value.length>20){
      alert("The Tag2 field cannot contain more than 20 characters!");
      thisform.tag2.focus();
        return false;
    }
    if (illegalChars.test(thisform.YearCreated.value)) {
       alert('Sorry, but the following characters\n\r\n\r % ^ * # [ ] \\ { + } ` ~ =  | \n\r\n\rare not allowed!');
       thisform.YearCreated.focus();
       return false;
    }
         if(thisform.YearCreated.value.length>4){
      alert("The Year Created field cannot contain more than 4 characters!");
      thisform.YearCreated.focus();
        return false;
    }

    if (illegalChars.test(thisform.fee.value)) {
       alert('Sorry, but the following characters\n\r\n\r % ^ * # ( ) [ ] \\ { + } ` ~ =  | \n\r\n\rare not allowed!');
       thisform.fee.focus();
       return false;
    }
       if(thisform.fee.value.length>50){
      alert("The Fee field cannot contain more than 50 characters!");
      thisform.fee.focus();
        return false;
    }
     if (illegalChars.test(thisform.municipalities.value)) {
       alert('Sorry, but the following characters\n\r\n\r % ^ * # [ ] \\ { + } ` ~ =  | \n\r\n\rare not allowed!');
       thisform.municipalities.focus();
       return false;
    }
     if(thisform.municipalities.value.length>100){
      alert("The Municipalities field cannot contain more than 100 characters!");
      thisform.municipalities.focus();
        return false;
    }
     if (illegalChars.test(thisform.requirements.value)) {
       alert('Sorry, but the following characters\n\r\n\r % ^ * # [ ] \\ { + } ` ~ =  | \n\r\n\rare not allowed!');
       thisform.requirements.focus();
       return false;
    }
     if(thisform.requirements.value.length>150){
      alert("The Requirements field cannot contain more than 150 characters!");
      thisform.requirements.focus();
        return false;
    }
     if (illegalChars.test(thisform.othername.value)) {
       alert('Sorry, but the following characters\n\r\n\r % ^  * #  [ ] \\ { + } ` ~ =  | \n\r\n\rare not allowed!');
       thisform.othername.focus();
       return false;
    }
    if(thisform.othername.value.length>50){
      alert("The Other Name field cannot contain more than 50 characters!");
      thisform.othername.focus();
        return false;
    }
     if (illegalChars.test(thisform.contactFname.value)) {
       alert('Sorry, but the following characters\n\r\n\r % ^ * #  [ ] \\ { + } ` ~ =  | \n\r\n\rare not allowed!');
       thisform.contactFname.focus();
       return false;
    }
     if(thisform.contactFname.value.length>50){
      alert("The Contact First Name field cannot contain more than 50 characters!");
      thisform.contactFname.focus();
        return false;
    }
     if (illegalChars.test(thisform.contactLname.value)) {
       alert('Sorry, but the following characters\n\r\n\r % ^  * #  [ ] \\ { + } ` ~ =  | \n\r\n\rare not allowed!');
       thisform.contactLname.focus();
       return false;
    }
     if(thisform.contactLname.value.length>50){
      alert("The Contact Last Name field cannot contain more than 50 characters!");
      thisform.contactLname.focus();
        return false;
    }
     if (illegalChars.test(thisform.comment.value)) {
       alert('Sorry, but the following characters\n\r\n\r  % ^ * # [ ] \\ { + } ` ~ =  | \n\r\n\rare not allowed!');
       thisform.comment.focus();
       return false;
    }
    ///check phone
    var stripped = thisform.phone1.value.replace(/[\(\)\.\-\ ]/g, '');
      //strip out acceptable non-numeric characters
      if (isNaN(parseInt(stripped))) {
         alert('The phone number contains illegal characters.');
         thisform.phone1.focus();
         return false;
      }
      if (!(stripped.length == 10)) {
	alert('The phone number is the wrong length. Make sure you included an area code.');
        thisform.phone1.focus();
         return false;
      }
      /////validate email
      //emailCheck(document.org.email.value);
}


/*validate file uploaded*/
function validateFileExtension(fld) {
	if(!/(\.pdf|\.doc|\.txt)$/i.test(fld.value)) {
		alert("Invalid file type. Please submit pdf, word, or txt documents only");
		//fld.form.reset();
		fld.focus();
		return false;
	}
	return true;
}
function validatePicExtension(fld) {
	if(!/(\.bmp|\.gif|\.jpg|\.jpeg|\.png)$/i.test(fld.value)) {
		alert("Invalid image file type. Please submit either jpg, jpeg, png, gif, or bmp only");
		//fld.form.reset();
		fld.focus();
		return false;
	}
	return true;
}


/*deal with old picture*/

function dealpic(id,type){  
       if(type=="age"){
            tp="age";
       }else if(type=="pro"){
            tp="pro";
       }
       // A function to read the data
     var url = "/lude/tils/deal.php?id="+id+"&tp="+tp+""; // The server-side script
      var request = GXmlHttp.create();
      request.open("GET", url, true);
      request.onreadystatechange = function() {
            if (request.readyState == 4) {
                   // var results=http.responseText;
            var Res = request.responseText;
                document.getElementById('delMess').innerHTML = Res;  
            }
      }
       request.send(null);
}


/*agencies*/
function deletePicture(id){
      
      input_box=confirm("You are going to delete this picture. Do you want to proceed? ");
      if(input_box==true){
         dealpic(id,"age");
      }
}
/*programs*/
function deletePictureP(id){
      
      input_box=confirm("You are going to delete this picture. Do you want to proceed? ");
      if(input_box==true){
         dealpic(id,"pro");
      }
}

/*brochure*/
function deleteBrochureP(id){
      
      input_box=confirm("You are going to delete this file. Do you want to proceed? ");
      if(input_box==true){
         dealpic(id,"bro");
      }
}
/*application*/
function deleteApplicationP(id){
      
      input_box=confirm("You are going to delete this file. Do you want to proceed? ");
      if(input_box==true){
         dealpic(id,"apl");
      }
}
/*other document*/
/*application*/
function deleteFileP(id){
      
      input_box=confirm("You are going to delete this file. Do you want to proceed? ");
      if(input_box==true){
         dealpic(id,"file");
      }
}

/*Agency attachment*/
function deleteAttach(id){
      
      input_box=confirm("You are going to delete this file. Do you want to proceed? ");
      if(input_box==true){
         dealpic(id,"att");
      }
}

function checkdelete(){
      input_box=confirm("You are going to delete this agency. Do you want to proceed? ");
      if(input_box==true){
         return true;
      }else if(input_box==false){
          return false;  
      }
}

function checkproject(){
      input_box=confirm("You are going to delete this project. Do you want to proceed? ");
      if(input_box==true){
         return true;
      }else if(input_box==false){
          return false;  
      }
}

function checkuser(){
      input_box=confirm("You are going to delete this user. Do you want to proceed? ");
      if(input_box==true){
         return true;
      }else if(input_box==false){
          return false;  
      }
}
function checkintership(){
      input_box=confirm("You are going to delete this intership. Do you want to proceed? ");
      if(input_box==true){
         return true;
      } else if(input_box==false){
          return false;  
      }    
}




function explain(id){
	if(document.getElementById('box').style.display == 'none'){
                 //document.getElementById('box').style.left=id.clientX
                 //document.getElementById('box').style.top=id.clientY
           // alert("X coords: " + x + ", Y coords: " + y);
		document.getElementById('box').style.display = 'block';
		
	}
            
          
            
            ///explain profile
		if(id=="ea"){	      
		document.getElementById('infoBox').innerHTML ="<br /><br />This field describes the main scope of your organization. ";	
		}else if(id=="created"){
                  document.getElementById('infoBox').innerHTML ="<br /><br />This field explains what year your organization was created.";	
                }else if(id=="est"){
                  document.getElementById('infoBox').innerHTML ="<br /><br />This field identifies your organization as a non profit, public institution or other";	
                }else if(id=="ean"){
                  document.getElementById('infoBox').innerHTML ="<br /><br />If you attach any documents you should give them each a specific name that allows them to be identified. You would include that name in this field. ";	
                }else if(id=="ep"){
                  document.getElementById('infoBox').innerHTML ="<br /><br />How many programs does your organization provide to the community. This is the number of programs you add to the site under the program section. ";	
                }else if(id=="ewl"){
                  document.getElementById('infoBox').innerHTML ="<br /><br />Check the option that applies to your organization. This is a general question.  ";	
                }else if(id=="eod"){
                  document.getElementById('infoBox').innerHTML ="<br /><br />If you would like your organization to always appear in the search results even if you do not have slots available check this box. ";	
                }else if(id=="eor"){
                  document.getElementById('infoBox').innerHTML ="<br /><br />If you would like your organization to always appear in the search results even if you do not have open registration check this box.";	
                }else if(id=="ers"){
                  document.getElementById('infoBox').innerHTML ="<br /><br />Check this otion if you want to be remainded by email when your information becomes outdated.";	
                }else if(id=="eci"){
                  document.getElementById('infoBox').innerHTML ="<br /><br />The contact information should be for the person who is in charge of the data input. This information is not displayed on the main site. ";	
                }
                //////explain program
                if(id=="eps"){	      
		document.getElementById('infoBox').innerHTML ="<br /><br />Only fill in this information if your program site is different from the location of your agency. ";	
		}else if(id=="et"){
                  document.getElementById('infoBox').innerHTML ="<br /><br />Use words that identify this program.  ";	
                }else if(id=="etp"){
                  document.getElementById('infoBox').innerHTML ="<br /><br />Select the description that best suits this program. ";	
                }else if(id=="eyc"){
                  document.getElementById('infoBox').innerHTML ="<br /><br />This field explains what year this program was created.";	
                }else if(id=="ens"){
                  document.getElementById('infoBox').innerHTML ="<br /><br />Select all the neighborhoods that the program works in. ";	
                }else if(id=="erp"){
                  document.getElementById('infoBox').innerHTML ="<br /><br />Type the beginning of the registration period and the end. This allows users to find this program when searching for programs with open registration processes. ";	
                }else if(id=="eop"){
                  document.getElementById('infoBox').innerHTML ="<br /><br />If your organization does not have a registration period and allows new enrollees at any time during the program.";	
                }else if(id=="epo"){
                  document.getElementById('infoBox').innerHTML ="<br /><br />This is the time period that the program operates from beginning to end. Be specific on dates to help users. ";	
                }
                
               
}

function explainM(id){
      if(document.getElementById('welcome').style.display == 'none'){
                 //document.getElementById('box').style.left=id.clientX
                 //document.getElementById('box').style.top=id.clientY
           // alert("X coords: " + x + ", Y coords: " + y);
		document.getElementById('welcome').style.display = 'block';
		
	}
      ///////explain spatial layers
                if(id=="emo"){
                  document.getElementById('welcometext').innerHTML ="<div id='close2'><A HREF='javascript:removeElement()'><img src='images/close_window_x.gif'></A></div><br /><br /> Display panel to search for programs that match more criteria</span>";	
                }else if(id=="ect"){
                  document.getElementById('welcometext').innerHTML ="<div id='close2'><A HREF='javascript:removeElement()'><img src='images/close_window_x.gif'></A></div><br /><br /> The layer was produced by identifying polygons from the Census Tract level layer from 2000 U.S. Census data ";	
                }else if(id=="epc"){
                  document.getElementById('welcometext').innerHTML ="<div id='close2'><A HREF='javascript:removeElement()'><img src='images/close_window_x.gif'></A></div><br /><br /> Data in this layer were derived from information entered and mantained by local youth agencies and Summary File 3 at the census tract level from 2000 U.S. Census data (from the SF3 table). <br /><br /><span style='font-size:0.9em'>% Programs Coverage = (Total programs in Tract/ Total Population under 19 years old) * 100<br /><br />% Programs Coverage = { [(SUM(programs)/(P012003 + P012004 + P012005 + P012006 + P012007 + P012027 + P012028 + P012029 + P012030 + P012031))]} * 100</span>";	
                }else if(id=="esc"){
                  document.getElementById('welcometext').innerHTML ="<div id='close2'><A HREF='javascript:removeElement()'><img src='images/close_window_x.gif'></A></div><br /><br /> Data in this layer were derived from information entered and mantained by local youth agencies and Summary File 3 at the census tract level from 2000 U.S. Census data ( from the SF3 table). <br /><br /><span style='font-size:0.9em'>% Slots Coverage = (Total slots in Tract/ Total Population under 19 years old) * 100<br /><br />% Slots Coverage = { [(SUM(slots)/(P012003 + P012004 + P012005 + P012006 + P012007 + P012027 + P012028 + P012029 + P012030 + P012031))]} * 100</span>";	
                }else if(id=="epm"){
                  document.getElementById('welcometext').innerHTML ="<div id='close2'><A HREF='javascript:removeElement()'><img src='images/close_window_x.gif'></A></div><br /><br /> Data in this layer were derived from Summary File 3 at the census tract level from 2000 U.S. Census data (items in parentheses beginning with 'P00' are field names from the SF3 table). <br /><br /><span style='font-size:0.9em'>% Minority = { [ (P007001 - P007003) / P007001 ] } * 100</span>";	
                }else if(id=="epi"){
                  document.getElementById('welcometext').innerHTML ="<div id='close2'><A HREF='javascript:removeElement()'><img src='images/close_window_x.gif'></A></div><br /><br /> Data in this layer were derived from Summary File 3 at the census tract level from 2000 U.S. Census data (items in parentheses beginning with 'P00' are field names from the SF3 table). <br /><br /><span style='font-size:0.9em'>New Haven median household income in 2000:  $63,640<br /><br />Income percentile= {(P053001*100)/63640} </span>";	
                }else if(id=="epep"){
                  document.getElementById('welcometext').innerHTML ="<div id='close2'><A HREF='javascript:removeElement()'><img src='images/close_window_x.gif'></A></div><br /><br /> Data in this layer were derived from Summary File 3 at the census tract level from 2000 U.S. Census data (items in parentheses beginning with 'P00' are field names from the SF3 table). <br /><br /><span style='font-size:0.9em'>Total # of linguistically isolated households = S [ (P020004) + (P020007) + (P020010) + (P020013) ] <br /><br />% of English Proficient households =  [ (P020001 - # of linguistically isolated households) /  P020001] * 100</span>";	
                }else if(id=="epfb"){
                  document.getElementById('welcometext').innerHTML ="<div id='close2'><A HREF='javascript:removeElement()'><img src='images/close_window_x.gif'></A></div><br /><br /> Data in this layer were derived from Summary File 3 at the census tract level from 2000 U.S. Census data (items in parentheses beginning with 'P00' are field names from the SF3 table). <br /><br /><span style='font-size:0.9em'>% of population that is foreign-born = { 1 - [ (P007001 - P021013) / P007001 ] }* 100</span>";	
                }else if(id=="esa"){
                  document.getElementById('welcometext').innerHTML ="<div id='close2'><A HREF='javascript:removeElement()'><img src='images/close_window_x.gif'></A></div><br /><br /> Check this button to find programs that have open slots in their programs.";	
                }else if(id=="esor"){
                  document.getElementById('welcometext').innerHTML ="<div id='close2'><A HREF='javascript:removeElement()'><img src='images/close_window_x.gif'></A></div><br /><br /> Check this button to find programs that allow you to enroll at any point during the year. There are no registration restrictions.";	
                }else if(id=="eio"){
                  document.getElementById('welcometext').innerHTML ="<div id='close2'><A HREF='javascript:removeElement()'><img src='images/close_window_x.gif'></A></div><br /><br /> Click this button to find programs with available internships.";	
                }  
      
}


function helpHidden(){
      
		document.getElementById('box').style.display = 'none';    
}


/* Show search box */

function showSearch(){
      hideA('g0');
      hideAll();
       if (document.getElementById('slots').checked) {
            document.getElementById('slots').checked = false;
            refine(0);
            }
            if (document.getElementById('register').checked) {
                  document.getElementById('register').checked = false;
            refine(0);
            }
            if (document.getElementById('intern').checked) {
                  document.getElementById('intern').checked = false;
            refine(0);
            }
            
     document.getElementById('searchPane').style.display= 'block';
}

/*  hide search box*/

function hideSearch(){
      document.getElementById('searchPane').style.display= 'none';
      document.getElementById('moreop').checked = false;
}

/*drag searchBox*/

 function playsearch(searchId) {
      if (searchPaneID.style.display=='block') {
         searchPaneID.style.display='none';
         searchPaneID.innerHTML=''; 
      } else {
         searchPaneID.style.display='block';
         searchPaneID.innerHTML='<A HREF="javascript:playsearch()"><img src="images/close_window_x.gif"></A>';
         var searchstring ='<p>Hre goes the search form</p>';
        
         searchPaneID.innerHTML+=searchstring;
      }
   }

   function moveHandler(e){
      if (e == null) { e = window.event } 
      if (e.button<=1&&dragOK){
         savedTarget.style.left=e.clientX-dragXoffset+'px';
         savedTarget.style.top=e.clientY-dragYoffset+'px';
         return false;
      }
   }

   function cleanup(e) {
      document.onmousemove=null;
      document.onmouseup=null;
      savedTarget.style.cursor=orgCursor;
      dragOK=false;
   }

   function dragHandler(e){
      var htype='-moz-grabbing';
      if (e == null) { e = window.event; htype='move';} 
      var target = e.target != null ? e.target : e.srcElement;
      orgCursor=target.style.cursor;
      if (target.className=="searchFrame") {
         savedTarget=target;       
         target.style.cursor=htype;
         dragOK=true;
         dragXoffset=e.clientX-parseInt(searchPaneID.style.left);
         dragYoffset=e.clientY-parseInt(searchPaneID.style.top);
         document.onmousemove=moveHandler;
         document.onmouseup=cleanup;
         return false;
      }else if (target.className=="welcome") {
         savedTarget=target;       
         target.style.cursor=htype;
         dragOK=true;
         dragXoffset=e.clientX-parseInt(searchPaneID.style.left);
         dragYoffset=e.clientY-parseInt(searchPaneID.style.top);
         document.onmousemove=moveHandler;
         document.onmouseup=cleanup;
         return false;
      }
   }
	 
	 document.onmousedown=dragHandler;


/*Remove welcome message 
function removeElement() {
var d1=document.getElementById('welcometext').parentNode;
var d2=document.getElementById('welcometext');
d1.removeChild(d2); 
  // document.getElementById('welcometext').parentNode  
}
*/
function removeElement() {
   document.getElementById('welcome').style.display= 'none';   
}


function about(){
      if(document.getElementById('welcome').style.display == 'none'){
		document.getElementById('welcome').style.display = 'block';	
      }
       document.getElementById('welcometext').innerHTML ="<div id='close2'><A HREF='javascript:removeElement()'><img src='images/close_window_x.gif'></A></div><br /><p><span class='headorange'>ABOUT US</span></p><span style='text-align: justify;font-size:0.8em'><p>New Haven Youth Map was created by the <a href='http://www.cityofnewhaven.com' target='_blank'><span style='color:#598aa4;'>City of New Haven's Department of Youth</span></a> in collaboration with <a href='http://www.ctdatahaven.org' target='_blank'><span style='color:#598aa4;'>DataHaven</span></a>,<a href='http://www.digitalecologies.com' target='_blank'><span style='color:#598aa4;'>Digital Ecologies</span></a> and youth organizations in the city.</p><p>We wanted to create a useful tool for parents, youth and organizations that would allow them to see what services are provided in our community. With many parents struggling to balance work and family life in New Haven, our tool can provide a valuable community resource. It will allow city government to directly assist families by providing online access to New Haven's wealth of community services. Our site will provide the public with a direct connection to youth organizations and their community offerings.</p><p>The Youth Map will serve as an online bulletin board for youth activities, ranging from summer camps to health services. In many cases, community members will be able to find out about organizations that previously they did not know existed. It will also provide the public with the ability to interact directly with youth organizations in an online community. Parents will be able to access up-to-date information on programs, internship openings, public services, and other community opportunities for New Haven's youth.</p><p>We are very proud of introducing this resource to our community and we invite all to join us.</p><p><b>Youth Map Feature</b><br />Original Idea: Eudald Lerga & Juan Camilo Osorio<br />Created by: <a href='mailto:eudald@digitalecologies.com'><span style='color:#598aa4;'>Digital Ecologies</span></a><br />Project Director: Adriana Arreola<br />Logo design: Kinoy Luangsay</p></span> ";
      
}

function gfaq(){
if(document.getElementById('welcome').style.display == 'none'){
		document.getElementById('welcome').style.display = 'block';	
}
document.getElementById('welcometext').innerHTML ="<div id='close2'><A HREF='javascript:removeElement()'><img src='images/close_window_x.gif'></A></div><br /><p><span class='headorange'>Frequent Asked Questions</span></p><span style='text-align: justify;font-size:0.8em'><p><b>How do I register for New Haven Youth Map?</b><br />To register as a user just click on the REGISTER button and fill out the form. You will have access to the site and the ability to contact agencies directly.</p><p><b>How do I contact an agency on the map?</b><br />When you click on an organization icon you will see the contact information for each agency. You can call, email or visit the organization.</p><p><b>What is New Haven Youth Map?</b><br />New Haven Youth Map is an interactive mapping tool that allows users to see all youth organizations on one map.  By using our search filters you are able to refine your searches and find programs based on specific keywords. This resource is useful to youth and guardians who are looking for programs in the community that are tailored to youth.</p><p><b>How do I search for a program?</b><br />You can search for a program by using the filters on the left hand side of the page. Just click on filters you want and unclick filters you donŐt want to see your search results. If you click on the icon you will see the name of the organization, contact information and programs.</p><p><b>What are Census Tracts?</b><br />Census tracts are small, relatively permanent statistical subdivisions of a county. Census tracts are delineated for most metropolitan areas and other densely populated counties. Census tracts usually have between 2,500 and 8,000 persons and show population characteristics, economic status, and living conditions.We include minority, income, English proficiency and foreign born percentages for New Haven, CT.</p><p><b>HOW DO I CONTACT THE SITE ADMINISTRATOR?</b><br />Just click on the contact us like on the home page.</p>";
}

function contact(){
if(document.getElementById('welcome').style.display == 'none'){
		document.getElementById('welcome').style.display = 'block';	
}
document.getElementById('welcometext').innerHTML ="<div id='close2'><A HREF='javascript:removeElement()'><img src='images/close_window_x.gif'></A></div><br /><p><span class='headorange'>Contact Information</span></p><span style='text-align: justify;font-size:0.8em'><p>Main Contact: Adriana Arreola<br />Department of Youth<br />City of New Haven<br />(203)946-2394<br /><a href='mailto:info@newhavenyouthmap.net'><span style='color:#598aa4;'>info@newhavenyouthmap.net</span></a></p>";
}


function sendemail(email,id,subject,compose,youremail){
        // A function to read the data
     var url = "/lude/tils/sendemail.php?email="+email+"&id="+id+"&subject="+subject+"&compose="+compose+"&youremail="+youremail+""; // The server-side script
      var request = GXmlHttp.create();
      request.open("GET", url, true);
      request.onreadystatechange = function() {
            if (request.readyState == 4) {
                   // var results=http.responseText;
            var Res = request.responseText;
                document.getElementById('welcometext').innerHTML = Res;
            }else{
                document.getElementById('welcometext').innerHTML = "<div id='close2'><A HREF='javascript:removeElement()'><img src='images/close_window_x.gif'></A></div><br /><p><span class='headorange'>Error message</span></p><span style='text-align: justify;font-size:0.8em'><p> There was some problem processing your request. Please try agian. Thank you!.</p></span>";   
            }
      }
       request.send(null);
}


function sendMssg(email,id){
   if(document.getElementById('welcome').style.display == 'none'){
		document.getElementById('welcome').style.display = 'block';	
}
 mail=email;
 ID=id;
   document.getElementById('welcometext').innerHTML ="<div id='close2'><A HREF='javascript:removeElement()'><img src='images/close_window_x.gif'></A></div><br /><p><span class='headorange'>Compose your message</span></p><span style='text-align: justify;font-size:0.8em'><form name='mssg' method='POST' action=''><p><label>Subject*<br><input type='text' size='50' name='subject' id='subject'></label></p><p><label>Message*<br /><textarea cols='43' rows='10' name='compose' id='compose'></textarea></label></p><p><label>Your Email*<br /><input type='text' size='50' name='youremail' id='email' onchange='emailCheck(this.value);'></label></p><p><input type='button' name='Submit' value='Send' onclick=\"sendemail(mail,ID,mssg.subject.value,mssg.compose.value,mssg.youremail.value)\"></p></form></p>";   
      
}

function viewIntern(optnt){
   if(document.getElementById('welcome').style.display == 'none'){
		document.getElementById('welcome').style.display = 'block';	
}   
   document.getElementById('welcometext').innerHTML ="<div id='close2'><A HREF='javascript:removeElement()'><img src='images/close_window_x.gif'></A></div><br /><p><span class='headorange'>View Internship Opportunity</span></p><span style='text-align: justify;font-size:0.8em'><form name='mssg' method='POST' action=''><p></p>";   
      
}