function initialize() 
{
      if (GBrowserIsCompatible()) 
       {
           var map = new GMap2(document.getElementById("map"));
           map.setMapType(G_PHYSICAL_MAP)
           map.setUIToDefault();
           map.setCenter(new GLatLng(52.268157373,14.677734375),3);
           map.disableScrollWheelZoom();
           //map.enableGoogleBar();
           geocoder = new GClientGeocoder();
       }
      else
        {
         alert("Your browser is not compatible for google maps.");
        }
 }

function showMap(address,map_type,x1,y1)
    {
if(map_type=='auto')
{
 //alert("auto");
 var mySplitResult = address.split(",");
        country=mySplitResult[0];	
	reg1=mySplitResult[1];
	reg2=mySplitResult[2];
	reg3=mySplitResult[3];
	reg4=mySplitResult[4];
	reg5=mySplitResult[5];
        //address=reg3+","+reg2+","+reg1+","+country;
        //alert(address);
        var mySplitResult = address.split(",");
        continent=mySplitResult[2];
    if (GBrowserIsCompatible())
     {
        var map = new GMap2(document.getElementById("map"));
        map.setMapType(G_PHYSICAL_MAP);
   var dd=9;   
   if (geocoder) 
         {
         //simple1(x1,y1,'user');
		//alert("This Fun0");
		geocoder.getLatLng(address,function(point) {   //simple1(point.lat(),point.lng(),'start'); 
							       //alert("lat: "+point.lat()+" lng:"+point.lng());  
		   if(!point){ Showreg1();  }else{ simple(point.lng(),point.lat(),'autosaved');  }   
                   map.setCenter(point,10);
                   map.setUIToDefault(); 
                   //map.enableGoogleBar();
                   map.disableScrollWheelZoom();
	           map.addOverlay(new GMarker(point));
		   
	           });
    
		function Showreg1()
		{
		//alert("This Fun");
		address=country+","+reg1+","+reg2+","+reg3+","+reg4;
		//address="France,Cote d'Azur - Riviera, Alpes-Maritimes,Cannes";
		geocoder.getLatLng(address,function(point) { //alert(point.lat()+"start1"); 
								if(!point){ Showreg2();  }else{ simple(point.lng(),point.lat(),'autosaved');  }      
                   map.setCenter(point,10);
                   map.setUIToDefault(); 
                   //map.enableGoogleBar();
                   map.disableScrollWheelZoom();
	           map.addOverlay(new GMarker(point));
	           });
		}
		function Showreg2()
		{
		//alert("This Fun1");
		address=country+","+reg1+","+reg2+","+reg3;
                //alert(address);
		geocoder.getLatLng(address,function(point) { if(!point){ Showreg3();  }else{ simple(point.lng(),point.lat(),'autosaved');  }      
                   map.setCenter(point,10);
                   map.setUIToDefault(); 
                   //map.enableGoogleBar();
                   map.disableScrollWheelZoom();
	           map.addOverlay(new GMarker(point));
	           });
		}
                //alert(address);
                function Showreg3()
		{
		//alert("This Fun2");
		address=country+","+reg1+","+reg2;
		//alert(address);
		geocoder.getLatLng(address,function(point) { if(!point){ Showreg4();  }else{ simple(point.lng(),point.lat(),'autosaved');  }      
                   map.setCenter(point,10);
                   map.setUIToDefault(); 
                   //map.enableGoogleBar();
                   map.disableScrollWheelZoom();
	           map.addOverlay(new GMarker(point));
	           });
		}
	        function Showreg4()
		{
		//alert("This Fun3");
		address=country+","+reg1;
		geocoder.getLatLng(address,function(point) { if(!point){ Showreg5();  }else{ simple(point.lng(),point.lat(),'autosaved');  }      
                   map.setCenter(point,10);
                   map.setUIToDefault(); 
                   //map.enableGoogleBar();
                   map.disableScrollWheelZoom();
	           map.addOverlay(new GMarker(point));
	           });
		}
		function Showreg5()
		{
		//alert("This Fun4");
		address=country;
		geocoder.getLatLng(address,function(point) { if(!point){ Showreg6();  }else{ simple(point.lng(),point.lat(),'autosaved');  }      
                   map.setCenter(point,10);
                   map.setUIToDefault(); 
                   //map.enableGoogleBar();
                   map.disableScrollWheelZoom();
	           map.addOverlay(new GMarker(point));
	           });
		}

              function Showreg6()
		{
		map.setMapType(G_PHYSICAL_MAP)
           	map.setUIToDefault();
          	map.setCenter(new GLatLng(52.268157373,14.677734375),3);
           	map.disableScrollWheelZoom();
           	//map.enableGoogleBar();
	        geocoder = new GClientGeocoder();   
		}

               //alert(point.lat()+"end");       
}		
 GEvent.addListener(map,"click", function(overlay, latlng) {     

                        if (latlng) 
                        { 
			       //get new latlng values and call fuction to insert it to database       
			       x1=latlng.x; 
			       y1=latlng.y;    

			       //simple(x1,y1,'user');
			       //simple1(x1,y1,'user');
                               //showMap(address,'user',x1,y1)
                        }

                                                                           });
    }
    else
    {
    	  alert("Your browser is not compatible for google maps.");
    }
  //alert(address);
}
else if(map_type=='user')
 {
//alert("user");

 if (GBrowserIsCompatible())
     {
        var map = new GMap2(document.getElementById("map"));
        map.setMapType(G_PHYSICAL_MAP);
 
   if (geocoder) 
         {
         
		//geocoder.getLatLng(address,function(point) { if(!point){ Showreg1();  }  
		   //alert("user map");
 		   map.setCenter(new GLatLng(y1,x1),10);
                   map.addOverlay(new GMarker(new GPoint(x1,y1))); 
                   map.setUIToDefault(); 
                   //map.enableGoogleBar();
                   map.disableScrollWheelZoom();
		              //    });
	}

	GEvent.addListener(map,"click", function(overlay, latlng) {     

                        if (latlng) 
                        { 
			       //get new latlng values and call fuction to insert it to database       
			       x1=latlng.x; 
			       y1=latlng.y;    

			       //simple(x1,y1,'user');
                               //simple1(x1,y1,'user');
                               //showMap(address,'user',x1,y1)
                        }

                                                                           });
    }
    else
    {
    	  alert("Your browser is not compatible for google maps.");
    }
 }
 else
 {   //alert("autosaved");
 if (GBrowserIsCompatible())
     {
        var map = new GMap2(document.getElementById("map"));
        map.setMapType(G_PHYSICAL_MAP);
 
   if (geocoder) 
         {
         
		//geocoder.getLatLng(address,function(point) { if(!point){ Showreg1();  }  
		   //alert("user map");
 		   map.setCenter(new GLatLng(y1,x1),10);
                   map.addOverlay(new GMarker(new GPoint(x1,y1))); 
                   map.setUIToDefault(); 
                   //map.enableGoogleBar();
                   map.disableScrollWheelZoom();
		              //    });
	}

GEvent.addListener(map,"click", function(overlay, latlng) {     

                        if (latlng) 
                        { 
			       //get new latlng values and call fuction to insert it to database       
			       x1=latlng.x; 
			       y1=latlng.y;    

			       //simple(x1,y1,'user');
			       //simple1(x1,y1,'user');
                               //showMap(address,'user',x1,y1)
                        }

                                                                           });
    }
    else
    {
    	  alert("Your browser is not compatible for google maps.");
    }
 }
}
function getXMLHTTP()
    { 
      //fuction to return the xml http object
		var xmlhttp=false;	
		try{
			xmlhttp=new XMLHttpRequest();
		}
		catch(e)	{		
			try{			
				xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e){
				try{
				xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
				}
				catch(e1){
					xmlhttp=false;
				}
			}
		}
		 	
		return xmlhttp;
    }
	
	
 function simple(x1,y1,map_type1)
    {
       
        var strURL="map_backend2.php?x="+x1+"&&y="+y1+'&&maptype='+map_type1;

		var req = getXMLHTTP();
		
		if (req) {
			
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200)   {						
						//document.getElementById('map').innerHTML=req.responseText;						
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}
				}				
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}		 //window.location="map_backend2.php?x="+x1+"&&y="+y1+'&&maptype='+map_type1; 
    } 

