﻿// JScript File



   var myFindPoint = ""
   var map = null;
   var geocoder = null;
   var placeWait = "<img src='../../images/icons/please_wait.gif' />"; 

   function initialize() {
   
   // alert("3");
              if (GBrowserIsCompatible()) {
                map = new GMap2(document.getElementById("map_canvas"));
               // map.setCenter(new GLatLng(37.4419, -122.1419), 13);
                map.addControl(new GLargeMapControl());
                map.addControl(new GMapTypeControl()); 
                
                geocoder = new GClientGeocoder();
               showAddress(); 
              }
    }





    function showAddress() {
                            //alert("20")
         
      var  pointCount = parseInt(document.getElementById("google_point_count").value);
      

      var myPoint;
       var myInfo;
       
       if (pointCount > 0){
               //alert("pointCount: " + pointCount )
       
                if (geocoder) {
                                    for(x=1;x<pointCount+1;x++){
                                                                                  
                                               myPoint = document.getElementById("google_point_" + x).value;
                                           //   alert(myPoint);
                                               
                                               myInfo = document.getElementById("google_info_" + x).value;
                                              myInfo = myInfo.replace(/#/g, "<br />");
 
                                               var myRegExp2 = new RegExp(/\,/)
                                               var myTotal2 = myPoint;
                                               var TotalArray2 = myTotal2.split(myRegExp2);     
                                                
                                                var point = new GLatLng(TotalArray2[0],TotalArray2[1]); 
                                                      if(x == 1){
                                                        map.setCenter(point, 13);
                                                       } 
                                              
                                              var marker =   createMarker(point, myInfo)
                                              map.addOverlay(marker); 
                                             } 
                              
                  }       
       
       }
       else
       {
         
                  if (geocoder) {
                   var address = document.getElementById("google_address").value
                                              address = address.replace(/#/g, "<br />");
                   var pointString = document.getElementById("google_point").value
                   
                                var myRegExp = new RegExp(/\|/)
                                var myTotal = pointString;
                                var TotalArray = myTotal.split(myRegExp);     
                                
                                
                                for(x=0;x<TotalArray.length;x++){
                               
                                           var myRegExp2 = new RegExp(/\,/)
                                           var myTotal2 = TotalArray[x];
                                           var TotalArray2 = myTotal2.split(myRegExp2);     
                                               //alert(TotalArray2[0] + " _ " + TotalArray2[1])
                                            var point = new GLatLng(TotalArray2[0],TotalArray2[1]); 
                                          if(x == 0){
                                            map.setCenter(point, 13);
                                           } 
                                          if(address != ""){
                                              var marker =   createMarker(point,address)
                                              map.addOverlay(marker); 
                                          }
                              
                                     }        
                  }
         } 
    }
   
    function createMarker(point,html) {
                var marker = new GMarker(point);
                GEvent.addListener(marker, "click", function() {
                    marker.openInfoWindowHtml(html);
                });
                return marker;
      } 
      
     function openGoogleDiv(myDiv)
          {
          
                    document.getElementById(myDiv).style.display = (document.getElementById(myDiv).style.display == "none") ? "inline" : "none";

                    var myPlus = document.getElementById(myDiv + "_plus");
                    
//                    if (document.getElementById(myDiv).style.display == "none"){
//                            //alert("1");
//                            myPlus.innerHTML = "<p class='header_12'><a href='javascript:openDiv(&quot;" + myDiv + "&quot;)'>+</a></p>"
//                    }
//                    else
//                    {
//                           //alert("2");
//                            myPlus.innerHTML = "<p class='header_12'><a href='javascript:openDiv(&quot;" + myDiv + "&quot;)'>–</a></p>"
//                    }
          } 
          
          
        function chechPlace(myVal) {
           
                  if (geocoder) {
                   address = document.getElementById("place_address_" + myVal).value + ", " + document.getElementById("place_suburb_" + myVal).value + ", " + document.getElementById("place_state_" + myVal).value + ", " + document.getElementById("place_postcode_" + myVal).value + ", " + document.getElementById("google_country").value
                    geocoder.getLatLng(address,
                                  function(point) {
                                                                if (!point) {
                                                                  alert(address + " not found. Please correct it or find alternate address formate.");
                                                                } else {
                                                                  alert(address + " found.");
                                                                }
                                                        }
                                                );
                                    }
                     
        }
       
       function addPlace(myVal){
                 //alert("0");             
                  var add_place_div = document.getElementById("add_place");
                  var add_place_plus = document.getElementById("add_place_plus");
                  var add_place_value = add_place_div.innerHTML;

                  myVal = myVal + 1;
                   
                  add_place_value = add_place_value + "<table border='0' cellpadding='0' cellspacing='0' width='100%'><tr valign='top'><td align='left' colspan='3'><input id='place_name_" + myVal + "' type='text' size='60' class='box_one' value='place name (e.g. Holy Martyrs Church)' onfocus='if (this.value==&quot;place name (e.g. Holy Martyrs Church)&quot;) this.value=&quot;&quot;;' onblur='if (this.value==&quot;&quot;) this.value=&quot;place name (e.g. Holy Martyrs Church)&quot;;'  /></td></tr><tr><td colspan='3'><input id='place_address_" + myVal + "' type='text' size='60' class='box_one' value='street address' onfocus='if (this.value==&quot;street address&quot;) this.value=&quot;&quot;;' onblur='if (this.value==&quot;&quot;) this.value=&quot;street address&quot;;'  /></td></tr><tr><td><input id='place_suburb_" + myVal + "' type='text' size='25' class='box_one' value='suburb' onfocus='if (this.value==&quot;suburb&quot;) this.value=&quot;&quot;;' onblur='if (this.value==&quot;&quot;) this.value=&quot;suburb&quot;;'  /></td><td><input id='place_state_" + myVal + "' type='text' size='15' class='box_one' value='state' onfocus='if (this.value==&quot;state&quot;) this.value=&quot;&quot;;' onblur='if (this.value==&quot;&quot;) this.value=&quot;state&quot;;'  /></td><td><input id='place_postcode_" + myVal + "' type='text' size='15' class='box_one' value='zip/postcode' onfocus='if (this.value==&quot;zip/postcode&quot;) this.value=&quot;&quot;;' onblur='if (this.value==&quot;&quot;) this.value=&quot;zip/postcode&quot;;'  /></td></tr><tr><td colspan='3'><p class='body_text_7'><select id='place_type_" + myVal + "' class='box_one'><option value='other' selected='selected'>type of place...</option><option value='church'>church</option><option value='presbytery'>presbytery</option><option value='office'>office</option><option value='school'>school</option><option value='religious house'>religious house</option><option value='chapel'>chapel</option><option value='sports facility'>sports facility</option><option value='hospital'>hospital</option><option value='church organisation'>church organisation</option><option value='local attration'>local attration</option></select>&nbsp;<input id='place_other_" + myVal + "' type='text' size='25' class='box_one' value='other' onfocus='if (this.value==&quot;other&quot;) this.value=&quot;&quot;;' onblur='if (this.value==&quot;&quot;) this.value=&quot;other&quot;;'  />&nbsp;<a href='javascript:chechPlace(" + myVal + ");'>check location</a><div id='place_check_wait'></div></p><hr /></td></tr></table>";
                   
                 //alert(add_place_value);
                  add_place_div.innerHTML =  add_place_value;
                  

              //    //alert("<p class='body_text_11' style='color:black' align='right'><a href='javascript:addplace(" + myVal + ");' title='add addtional place locations'>+</a></p>");
                  add_place_plus.innerHTML =  "<p class='body_text_11' style='color:black' align='right'><a href='javascript:addPlace(" + myVal + ");' title='add addtional place locations'>+</a><input id='numberPlace' type='hidden' value='" + myVal + "' /></p>";
                    
             //     //alert("4");
          }
          
 
        function GetGoogleFromServer(TotalStr, context){
                                //  alert(TotalStr);
           var myRegExp = new RegExp(/\|/)
           item_array = TotalStr.split(myRegExp);   
          
           switch (item_array[0]){ 
              
                case "60":
                        window.location.href=window.location.href
                        
                  break;
               case "40":
              
                      var edit_location_div = document.getElementById("edit_location");

                       for (j = 0; j < form1.length; j++)
                        {
                            form1.elements[j].disabled=false;
                        }
        
                        var edit_location = "<p class='body_text_7'>edit this current location:</p><table border='0' cellpadding='0' cellspacing='0' width='100%'><tr valign='top'><td align='left' colspan='3'><input id='place_name_0' type='text' size='60' class='box_one' value='" + item_array[1] + "'   /></td></tr><tr><td colspan='3'><input id='place_address_0' type='text' size='60' class='box_one' value='" + item_array[2] + "'   /></td></tr><tr><td><input id='place_suburb_0' type='text' size='25' class='box_one' value='" + item_array[3] + "'  /></td><td><input id='place_state_0' type='text' size='15' class='box_one' value='" + item_array[4] + "'   /></td><td><input id='place_postcode_0' type='text' size='15' class='box_one' value='" + item_array[5] + "'  /></td></tr><tr><td colspan='3'><input id='place_phone_0' type='text' size='60' class='box_one' value='" + item_array[7] + "'   /></td></tr><tr><td colspan='3'><p class='body_text_7'><input id='place_country_0' type='hidden' value='" + item_array[6] + "' /><input id='place_point_0' type='hidden' value='" + item_array[8] + "' /><input id='place_id_0' type='hidden' value='" + item_array[10] + "' /><input id='place_other_0' type='text' size='25' class='box_one' value='" + item_array[9] + "'   />&nbsp;<a href='javascript:chechPlace(0);'>check location</a><div id='place_check_wait'></div></p></td></tr></table><p class='body_text_7'><a href='javascript:updateLocation(0);'>update</a></p><hr />";

                        edit_location_div.innerHTML =  edit_location;
                        edit_location_div.style.display =  "inline";

                  break;
                                     
               case "80": 
                        window.location.href=window.location.href                      
                  break;
                 
              case "100": 
                        window.location.href=window.location.href       
                  break; 
                 
              case "120": 
                   var edit_location_div = document.getElementById("edit_location");
                   edit_location_div.innerHTML = "<p class='body_text_7'>location has been added to your profile.</p>";  
                      
                       for (j = 0; j < form1.length; j++)
                        {
                            form1.elements[j].disabled=false;
                        } 
                     break;  
           }
           
        }
     
     var myPlaceNum = 0; 
     var r = 1;  
     var myVar = "";
       
      function sendPlace(myType, myVar){
       
                    var myWait = document.getElementById('place_send_wait');
                    var y = 0;
                    myWait.innerHTML = "<img src='../../images/icons/please_wait.gif' />";  
           
                    myPlaceNum = document.getElementById('numberPlace').value
                    myPlaceNum = myPlaceNum*1 
                    
                    for (j = 0; j < form1.length; j++)
                    {
                        form1.elements[j].disabled=true;
                    }
                    
                    findPlace();
                        
       } 
       
      function findPlace() {
      
                address = document.getElementById("place_address_" + r).value + ", " + document.getElementById("place_suburb_" + r).value + ", "  + document.getElementById("place_state_" + r).value + ", " + document.getElementById("place_postcode_" + r).value + ", " + document.getElementById("google_country").value

                  if (geocoder) {
                    
                    geocoder.getLatLng(address,
                                  function(point) {
                                                                if (!point) {
                                                                        //alert(address + " not found. Please correct it or find alternate address format.");
                                                                        var myWait = document.getElementById('place_send_wait');
                                                                        myWait.innerHTML = "";  
                                                                       for (j = 0; j < form1.length; j++)
                                                                        {
                                                                            form1.elements[j].disabled=false;
                                                                        }
                                                                } else {
                                                                      //alert("1: " + point); 
                                                                      savePlace(point);
                                                                }
                                                        }
                                                );
                                    }
        }
       
      function savePlace(myVal) {
      
                        myPlaceType = document.getElementById("place_type_" + r).options[document.getElementById("place_type_" + r).selectedIndex].value
                        myVar = myVar + myVal + "~```~" + document.getElementById("place_name_" + r).value + "~```~" + document.getElementById("place_address_" + r ).value + "~```~" + document.getElementById("place_suburb_" + r).value + "~```~" + document.getElementById("place_state_" + r).value + "~```~" + document.getElementById("place_postcode_" + r).value + "~```~" + document.getElementById("google_country").value + "~```~" + myPlaceType + "~```~" + document.getElementById("place_other_" + r).value + "`~~`";
                        alert("r: " + r  + "        -    place_other_: " + document.getElementById("place_other_" + r).value);
                        if (r == myPlaceNum){
                           // alert("1b"); 
                            UseCallback_google("60|" +  myVar);    
                         }
                         else
                         {
                             //   alert("2b"); 
                                r = r + 1;
                                findPlace(r);
                        
                        }     
      
      }
      
      function getLocation(myPara){
    //  alert("1")
            var edit_location_div = document.getElementById("edit_location");
           edit_location_div.innerHTML = "<img src='../../images/icons/please_wait.gif' />";  
            for (j = 0; j < form1.length; j++)
            {
                form1.elements[j].disabled=true;
            }
            
             UseCallback_google("40|" +  myPara);    
      
      }
      
      
      function updateLocation(myPar){
            var edit_location_div = document.getElementById("edit_location");
            for (j = 0; j < form1.length; j++)
            {
                form1.elements[j].disabled=true;
            }
           var r = myPar
           var  myVar = document.getElementById("place_name_" + r).value + "~```~" + document.getElementById("place_address_" + r ).value + "~```~" + document.getElementById("place_suburb_" + r).value + "~```~" + document.getElementById("place_state_" + r).value + "~```~" + document.getElementById("place_postcode_" + r).value + "~```~" + document.getElementById("google_country").value + "~```~" + document.getElementById("place_other_" + r).value + "~```~" + document.getElementById("place_id_" + r).value + "~```~" + document.getElementById("place_point_" + r).value + "~```~" + document.getElementById("place_phone_" + r).value;

            edit_location_div.innerHTML = "<img src='../../images/icons/please_wait.gif' />";
             UseCallback_google("80|" +  myVar);
      
      }
      
   function deleteLocation(myPara){
    //  alert("1")
            var edit_location_div = document.getElementById("edit_location");
           edit_location_div.innerHTML = "<img src='../../images/icons/please_wait.gif' />";  
            for (j = 0; j < form1.length; j++)
            {
                form1.elements[j].disabled=true;
            }
            
             UseCallback_google("100|" +  myPara);    
      
      }
      
   function addLocationtoProfile(myPara){
    //  alert("1")
            var edit_location_div = document.getElementById("edit_location");
           edit_location_div.innerHTML = "<img src='../../images/icons/please_wait.gif' />";  
            for (j = 0; j < form1.length; j++)
            {
                form1.elements[j].disabled=true;
            }
            
             UseCallback_google("120|" +  myPara);    
      
      }
      