﻿// JScript File

function myCleanOverlay(markersArray)
{
  if (markersArray) { 
    for (i in markersArray) { 
      markersArray[i].setMap(null); 
    } 
    markersArray.length = 0; 
  } 
}

function redraw(mapLocation, form){

    var latLngBounds = mapLocation.getBounds();
    latitude1 = latLngBounds.getSouthWest().lat();
    longitude1 = latLngBounds.getSouthWest().lng();
    latitude2 = latLngBounds.getNorthEast().lat();
    longitude2 = latLngBounds.getNorthEast().lng();


    fillHiddenParametrs(mapLocation, latitude1, longitude1, latitude2, 
        longitude2, mapLocation.getZoom(), 
        mapLocation.getCenter().lat(),
        mapLocation.getCenter().lng(),
        document.forms.item(0)
        )

    form.submit();

}



    function showLocationMap(mapLocation, markersArray) 
    {
//       alert("showLocationMap");
       // mapLocation.clearOverlays();  ???????????????? need it 
      

var image = new google.maps.MarkerImage('http://www.salesanddiscounts.ca/googleicons/my_custom_icon1.png', 
      new google.maps.Size(22, 31), 
      new google.maps.Point(0,0), 
      new google.maps.Point(0, 31)); 
  var shadow = new google.maps.MarkerImage('http://www.salesanddiscounts.ca/googleicons/my_custom_icon_shadow.png', 
      new google.maps.Size(42, 31), 
      new google.maps.Point(0,0), 
      new google.maps.Point(10, 31)); 
  var shape = { 
      coord: [1, 1, 1, 20, 18, 20, 18 , 1], 
      type: 'poly' 
  }; 

          var item
          var isFound
          var latLoc
          var lngLoc

          for (j = 0; j < document.forms.item(0).length; j++)  
          {  

        ////////////// 1 ////////////
           item = document.forms.item(0).elements[j] 
           isFound = item.name.indexOf("TextBoxLat1")
           
           if(isFound >= 0)
           {
               if(item.value != "")    
                latLoc = parseFloat(item.value)
               else
                 break; 
           }    
           isFound = item.name.indexOf("TextBoxLng1")
           if(isFound >= 0)
           { 
                lngLoc = parseFloat(item.value)
                var myLatLng = new google.maps.LatLng(latLoc, lngLoc); 
                image1 = "http://www.salesanddiscounts.ca/googleicons/my_custom_icon1.png";
                var marker1 = new google.maps.Marker({zIndex: 1, position: myLatLng, map: mapLocation, shadow: shadow, icon: image1, shape: shape });   
                markersArray.push(marker1);
                  
           }
           

        ////////////// 2 ////////////
           item = document.forms.item(0).elements[j] 
           isFound = item.name.indexOf("TextBoxLat2")
           
           if(isFound >= 0)
           {
               if(item.value != "")    
                latLoc = parseFloat(item.value)
               else
                 break; 
           }    
           isFound = item.name.indexOf("TextBoxLng2")
           if(isFound >= 0)
           { 
                lngLoc = parseFloat(item.value);
                myLatLng = new google.maps.LatLng(latLoc, lngLoc); 
                image2 = "http://www.salesanddiscounts.ca/googleicons/my_custom_icon2.png";
                var marker2 = new google.maps.Marker({zIndex: 2, position: myLatLng, map: mapLocation, shadow: shadow, icon: image2, shape: shape });   
                markersArray.push(marker2);
           }

        ////////////// 3 ////////////
           item = document.forms.item(0).elements[j] 
           isFound = item.name.indexOf("TextBoxLat3")
           
           if(isFound >= 0)
           {
               if(item.value != "")    
                latLoc = parseFloat(item.value)
               else
                 break; 
           }    
           isFound = item.name.indexOf("TextBoxLng3")
           if(isFound >= 0)
           { 
                lngLoc = parseFloat(item.value);
                myLatLng = new google.maps.LatLng(latLoc, lngLoc); 
                image3 = "http://www.salesanddiscounts.ca/googleicons/my_custom_icon3.png";
                var marker3 = new google.maps.Marker({zIndex: 3, position: myLatLng, map: mapLocation, shadow: shadow, icon: image3, shape: shape });   
                markersArray.push(marker3);
           }

        ////////////// 4 ////////////
           item = document.forms.item(0).elements[j] 
           isFound = item.name.indexOf("TextBoxLat4")
           
           if(isFound >= 0)
           {
               if(item.value != "")    
                latLoc = parseFloat(item.value)
               else
                 break; 
           }    
           isFound = item.name.indexOf("TextBoxLng4")
           if(isFound >= 0)
           { 
                lngLoc = parseFloat(item.value);
                myLatLng = new google.maps.LatLng(latLoc, lngLoc); 
                image4 = "http://www.salesanddiscounts.ca/googleicons/my_custom_icon4.png";
                var marker4 = new google.maps.Marker({zIndex: 4, position: myLatLng, map: mapLocation, shadow: shadow, icon: image4, shape: shape });   
                markersArray.push(marker4);
           }

        ////////////// 5 ////////////
           item = document.forms.item(0).elements[j] 
           isFound = item.name.indexOf("TextBoxLat5")
           
           if(isFound >= 0)
           {
               if(item.value != "")    
                latLoc = parseFloat(item.value)
               else
                 break; 
           }    
           isFound = item.name.indexOf("TextBoxLng5")
           if(isFound >= 0)
           { 
                lngLoc = parseFloat(item.value);
                myLatLng = new google.maps.LatLng(latLoc, lngLoc); 
                image5 = "http://www.salesanddiscounts.ca/googleicons/my_custom_icon5.png";
                var marker5 = new google.maps.Marker({zIndex: 5, position: myLatLng, map: mapLocation, shadow: shadow, icon: image5, shape: shape });   
                markersArray.push(marker5);
           }

        ////////////// 6 ////////////
           item = document.forms.item(0).elements[j] 
           isFound = item.name.indexOf("TextBoxLat6")
           
           if(isFound >= 0)
           {
               if(item.value != "")    
                latLoc = parseFloat(item.value)
               else
                 break; 
           }    
           isFound = item.name.indexOf("TextBoxLng6")
           if(isFound >= 0)
           { 
                lngLoc = parseFloat(item.value);
                myLatLng = new google.maps.LatLng(latLoc, lngLoc); 
                image6 = "http://www.salesanddiscounts.ca/googleicons/my_custom_icon6.png";
                var marker6 = new google.maps.Marker({zIndex: 6, position: myLatLng, map: mapLocation, shadow: shadow, icon: image6, shape: shape });   
                markersArray.push(marker6);
           }

        ////////////// 7 ////////////
           item = document.forms.item(0).elements[j] 
           isFound = item.name.indexOf("TextBoxLat7")
           
           if(isFound >= 0)
           {
               if(item.value != "")    
                latLoc = parseFloat(item.value)
               else
                 break; 
           }    
           isFound = item.name.indexOf("TextBoxLng7")
           if(isFound >= 0)
           { 
                lngLoc = parseFloat(item.value);
                myLatLng = new google.maps.LatLng(latLoc, lngLoc); 
                image7 = "http://www.salesanddiscounts.ca/googleicons/my_custom_icon7.png";
                var marker7 = new google.maps.Marker({zIndex: 7, position: myLatLng, map: mapLocation, shadow: shadow, icon: image7, shape: shape });   
                markersArray.push(marker7);
           }

        ////////////// 8 ////////////
           item = document.forms.item(0).elements[j] 
           isFound = item.name.indexOf("TextBoxLat8")
           
           if(isFound >= 0)
           {
               if(item.value != "")    
                latLoc = parseFloat(item.value)
               else
                 break; 
           }    
           isFound = item.name.indexOf("TextBoxLng8")
           if(isFound >= 0)
           { 
                lngLoc = parseFloat(item.value);
                myLatLng = new google.maps.LatLng(latLoc, lngLoc); 
                image8 = "http://www.salesanddiscounts.ca/googleicons/my_custom_icon8.png";
                var marker8 = new google.maps.Marker({zIndex: 8, position: myLatLng, map: mapLocation, shadow: shadow, icon: image8, shape: shape });   
                markersArray.push(marker8);
           }

        ////////////// 9 ////////////
           item = document.forms.item(0).elements[j] 
           isFound = item.name.indexOf("TextBoxLat9")
           
           if(isFound >= 0)
           {
               if(item.value != "")    
                latLoc = parseFloat(item.value)
               else
                 break; 
           }    
           isFound = item.name.indexOf("TextBoxLng9")
           if(isFound >= 0)
           { 
                lngLoc = parseFloat(item.value);
                myLatLng = new google.maps.LatLng(latLoc, lngLoc); 
                image9 = "http://www.salesanddiscounts.ca/googleicons/my_custom_icon9.png";
                var marker9 = new google.maps.Marker({zIndex: 9, position: myLatLng, map: mapLocation, shadow: shadow, icon: image9, shape: shape });   
                markersArray.push(marker9);
           }

        ////////////// 10 ////////////
           item = document.forms.item(0).elements[j] 
           isFound = item.name.indexOf("TextBoxLat10")
           
           if(isFound >= 0)
           {
               if(item.value != "")    
                latLoc = parseFloat(item.value)
               else
                 break; 
           }    
           isFound = item.name.indexOf("TextBoxLng10")
           if(isFound >= 0)
           { 
                lngLoc = parseFloat(item.value);
                myLatLng = new google.maps.LatLng(latLoc, lngLoc); 
                image10 = "http://www.salesanddiscounts.ca/googleicons/my_custom_icon10.png";
                var marker10 = new google.maps.Marker({zIndex: 10, position: myLatLng, map: mapLocation, shadow: shadow, icon: image10, shape: shape });   
                markersArray.push(marker10);
           }
          
       }
       
      
       
          for (j = 0; j < document.forms.item(0).length; j++)  
          {  

////////////// selected ////////////
           item = document.forms.item(0).elements[j] 
           isFound = item.name.indexOf("SelectedTextBoxLat")
           
           if(isFound >= 0)
           {
              if(item.value != "")    
                latLoc = parseFloat(item.value)
                //alert(latLoc)
               else
                 break; 
           }    
           isFound = item.name.indexOf("SelectedTextBoxLng")
           if(isFound >= 0)
           { 
                lngLoc = parseFloat(item.value);
                myLatLng = new google.maps.LatLng(latLoc, lngLoc); 
                image = "http://www.salesanddiscounts.ca/googleicons/my_custom_selected_icon1.png";
                var markerSelected = new google.maps.Marker({zIndex: 11, position: myLatLng, map: mapLocation, shadow: shadow, icon: image, shape: shape });   
                markersArray.push(markerSelected);
           }
          }
     
    }







function fillHiddenParametrs(map, lat1, lng1, lat2, lng2, zoom, 
    mapCenterLat, mapCenterLng, form)
{
  var item 
  var isFound
  for (i = 0; i < form.length; i++)  
  {  
   item = form.elements[i] 

  isFound = item.name.indexOf("latitude1")
  if(isFound >= 0) 
  {
       form.elements[i].value = lat1;
       
  }     
    
  isFound = item.name.indexOf("longitude1")
  if(isFound >= 0) 
        form.elements[i].value = lng1;

  isFound = item.name.indexOf("latitude2")
  if(isFound >= 0) 
       form.elements[i].value = lat2;
    
  isFound = item.name.indexOf("longitude2")
  if(isFound >= 0) 
        form.elements[i].value = lng2;
  
  isFound = item.name.indexOf("zoom")
  if(isFound >= 0) 
        form.elements[i].value = zoom;

  isFound = item.name.indexOf("mapCenterLat")
  if(isFound >= 0) 
        form.elements[i].value = mapCenterLat;

  isFound = item.name.indexOf("mapCenterLng")
  if(isFound >= 0) 
        form.elements[i].value = mapCenterLng;

    }
}





