// JavaScript Document

var point;
var request; 
var request1;
var map;
var point;
//<![CDATA[
if (GBrowserIsCompatible()) {
      function createMarker(point,html) 
	  {  
	  		var marker = new GMarker(point);
        	GEvent.addListener(marker, "click", function() 
			{     		 marker.openInfoWindowHtml(html);

        	});
	        return marker;
	 }


} else{
      alert("Sorry, the Google Maps API is not compatible with this browser");
}

function load(countryval,cityval)
{
    map = new GMap(document.getElementById("MapPlaceHolder"));
	//point = new GPoint(34.52466147177172,29.35546875);
	//point = new GPoint(37.3002752813443,23.818359375);
	//point = new GPoint(40.84706035607122,19.775390625);
	point = new GPoint(42.24997445586331,26.16796875);
    map.addControl(new GLargeMapControl());
	/*map.addControl(new GMapTypeControl());*/
    map.centerAndZoom(point, 13);
	request = GXmlHttp.create();
	if(countryval==0 && cityval==0)				//Default no country and No city Selected
	{
			MapChangeDefault('all',0);
	}
	else if(countryval>0 && cityval<=0)		//Country  Selected
	{
		MapChangeDefault('country',countryval);
	}
	else if(countryval<=0 && cityval>0)		//Country  Selected
	{
		MapChangeDefault('city',cityval);		
	}
 }

function MapChange(where)
{	
	var newcountry=document.getElementById('country').value; 
	try
	{
 		var newcity=document.getElementById('city').value; 
	}
	catch(e)
	{
		var newcity;
	}
	request.open("GET", "parks.xml", true);

	request.onreadystatechange = function()

	{



  		if (request.readyState == 4) 

		{

    		var xmlDoc = request.responseXML;   			



				if(where=="country")

				{

						var country = xmlDoc.documentElement.getElementsByTagName("country");					

						for (var i = 0; i < country.length; i++) 

						{

								if(country[i].getAttribute("ID")==newcountry)

								{

									var point = new GPoint(parseFloat(country[i].getAttribute("Longitude")),

									 parseFloat(country[i].getAttribute("Latitude")));

									var zoom= parseInt(country[i].getAttribute("Zoom"));

									map.centerAndZoom(point, zoom);

								}

						}

						



				}

				else if(where=="city")

				{		

						var city = xmlDoc.documentElement.getElementsByTagName("city");					

						for (var i = 0; i < city.length; i++) 

						{

								if(city[i].getAttribute("ID")==newcity)

								{

									var point = new GPoint(parseFloat(city[i].getAttribute("Longitude")),

									 parseFloat(city[i].getAttribute("Latitude")));									

									 map.centerAndZoom(point, 4);

								}

						}

				}



				



  		}



	}



	request.send(null);

 }



function FlagMapChange(where,cid)

 {



		 

		

   	  

	var newcountry=cid; 

	request.open("GET", "parks.xml?CACHID="+Math.floor(Math.random()*500000), true);
	
	request.onreadystatechange = function()

	{

   		if (request.readyState == 4) 

		{

    		var xmlDoc = request.responseXML;   			



				if(where=="country")

				{

						var country = xmlDoc.documentElement.getElementsByTagName("country");					

						for (var i = 0; i < country.length; i++) 

						{

								if(country[i].getAttribute("ID")==newcountry)

								{

									var point = new GPoint(parseFloat(country[i].getAttribute("Longitude")),

									 parseFloat(country[i].getAttribute("Latitude")));

									var zoom= parseInt(country[i].getAttribute("Zoom"));

									map.centerAndZoom(point, zoom);

								}

						}

						



				}

   		}



	}



	request.send(null);

 }



function MapChangeDefault(where,value)   // DEFAULT SELECTED VALUE //

 {  



	request1 = GXmlHttp.create();

	request1.open("GET", "parks.xml", true);

	request1.onreadystatechange = function()

	{

			if (request1.readyState == 4) 

			{

					var xmlDoc = request1.responseXML;   			

					if(where=="country")

					{

								

							var country = xmlDoc.documentElement.getElementsByTagName("country");		

							var newcountry=value;

							for (var i = 0; i < country.length; i++) 

							{

									if(country[i].getAttribute("ID")==newcountry)

									{

										var point = new GPoint(parseFloat(country[i].getAttribute("Longitude")),

										 parseFloat(country[i].getAttribute("Latitude")));

										var zoom= parseInt(country[i].getAttribute("Zoom"));
								
										map.centerAndZoom(point, zoom);

										

									}

							}

						



					}

					else if(where=="city")

					{

							var city = xmlDoc.documentElement.getElementsByTagName("city");		

							var newcity=value;

							for (var i = 0; i < city.length; i++) 

							{

									if(city[i].getAttribute("ID")==newcity)

									{

										var point = new GPoint(parseFloat(city[i].getAttribute("Longitude")),

										 parseFloat(city[i].getAttribute("Latitude")));

										

										map.centerAndZoom(point, 4);

									}

							}

					}

					else if(where=="all")

					{

						

						

					}

						

					//====================================== START  =====================

					/*var baseIcon = new GIcon();

					baseIcon.iconSize=new GSize(32,32);

					baseIcon.shadowSize=new GSize(56,32);

					baseIcon.iconAnchor=new GPoint(16,32);

					baseIcon.infoWindowAnchor=new GPoint(16,0);

					baseIcon.image = "http://localhost:82/century21/images/officemark.png";  */

					//var martini = new GIcon(baseIcon, "http://maps.google.com/mapfiles/kml/pal2/icon27.png", null, "http://maps.google.com/mapfiles/kml/pal2/icon27s.png");

					

					

					var baseIcon = new GIcon();

			        //baseIcon.iconSize=new GSize(50,50);

			        //baseIcon.shadowSize=new GSize(56,32);

			        //baseIcon.iconAnchor=new GPoint(16,32);

			        //baseIcon.infoWindowAnchor=new GPoint(16,0);

		

					var martini = new GIcon(baseIcon, "http://maps.google.com/mapfiles/kml/pal2/icon27.png", null, "http://maps.google.com/mapfiles/kml/pal2/icon27s.png");



					// Create our "tiny" marker icon

					

					

					/*var blueIcon = new GIcon(G_DEFAULT_ICON);

					baseIcon.iconSize=new GSize(10,10);

					blueIcon.image = "./images/officemid.png";

	                baseIcon.infoWindowAnchor=new GPoint(16,0);

					

					// Set up our GMarkerOptions object

					markerOptions  = { icon:blueIcon }; */

					

					var office = xmlDoc.documentElement.getElementsByTagName("Office");	  
					//alert("Length : "+office.length);
					for (var i = 0; i < office.length; i++) 

					{

								
								 //alert("ID :"+parseFloat(office[i].getAttribute("ID")));
								 var point =  new GPoint(parseFloat(office[i].getAttribute("Longitude")),

								 parseFloat(office[i].getAttribute("Latitude")));

							     

								 var contain='<div style="width:240px;height:50px;">11</div>';

								 

								 //var marker = createMarker1(point,contain)

							      //map.addOverlay(marker);

								  var image =office[i].getAttribute("Image");

								  var name =office[i].getAttribute("Name");

								  var area =office[i].getAttribute("Area");

								  var officeid=office[i].getAttribute("ID");

								  var marker = createMarker1(point, image,name,area,officeid) 

									map.addOverlay(marker);

								  

								  //map.addOverlay(new GMarker(point, markerOptions));

					}



					//====================================== END ======================

				  

  			}



	}



	request1.send(null);  

 }



function ChangeView(vname)

{

	if(vname=="SMap")

	{

		map.setMapType(G_NORMAL_MAP);  

	}

	else if(vname=="Satellite")

	{

		map.setMapType(G_SATELLITE_MAP);  

	}

	else if(vname=="Hybrid")

	{

		map.setMapType(G_HYBRID_MAP);  

	}

}



function createMarker(point, iconname) {



        var icon = new GIcon(baseIcon);



        icon.image = iconname.getAttribute("image");



        var marker = new GMarker(point, icon);



        return marker;



      }

	  

	  

	 function createMarker1(point, image,name,area,officeid) 

	{

  			// Create a lettered icon for this point using our icon class

  			//var baseIcon = new GIcon();

			var blueIcon = new GIcon(G_DEFAULT_ICON);

	 		 blueIcon.iconSize=new GSize(22,17);

	  		blueIcon.image = "./images/officemid.png";

	  		blueIcon.infoWindowAnchor=new GPoint(16,13);

					

			// Set up our GMarkerOptions object

			markerOptions  = { icon:blueIcon };

			var marker = new GMarker(point, markerOptions);



			  GEvent.addListener(marker, "click", function() {

					

				officesearchres(officeid)

				marker.openInfoWindowHtml("<div style='width:240px;height:50px;'><table width='100%'  border='0' cellspacing='1' cellpadding='1'><tr><td width='8%' rowspan='2' valign='middle'><image src='./images/user/THUMB/" +image+ "'</image></td><td width='92%'><b>"+name+"</b></td></tr><tr><td>"+area+"</td></tr></table></div>");

			  });

			  return marker;

	}

//]]>


