//var cLatitude = 31.525617;
//var cLongitude = 74.271011;  
var tmp_markers = new Array(); 
var lng;
var lat;
var zoom;
var last_selected_div = "";
var description = "You Have Reached To Tauqeer's House Walla !!!";
var descAkbar = "You Have Reached To Mr. Akbar's House Walla !!!";   
var map;
var latTarget = "";
var lngTarget = "";

var latfrom;
var lngfrom;
var htmlfrom;

var latto;
var lngto;
var htmlto;

var this_domain = document.domain ;
if (this_domain.indexOf("192.") > -1) this_domain = this_domain + "/bayut";
this_domain = "http://"+this_domain;

var markers;    

var w_div = null;
function OpenWaitingDiv()
{
    var waiting_div = null;
    var waiting_div_inner = null;
     w_div = document.createElement('div');
    
    w_div.setAttribute("id","wait_div");
    var height = $(window).height();
    var div_height = (height/2) - 100;
    var div_width =  ($(window).width()/2) - 150;
    $(w_div).css({"width":"100%","height":height,"background-color":"#F0F0F0","opacity":"0.75","z-index":"1000","position":"absolute","top":"0px","left":"0px"});
    if($('#waiting_div').html())
    {
       //alert($('#waiting_div').html());
        waiting_div_inner = $('#waiting_div').html();
        //waiting_div = "<img src='" + this_domain + "/gmaps/imgs/loading-1.gif' border='0'>"
    }
    else
    {
        waiting_div_inner = "<img src='" + this_domain + "/gmaps/imgs/loading-1.gif' border='0'>"
    }
    var waiting_div = $('<div style="position:absolute; top:'+div_height+'px; left:'+div_width+'px;"></div>');
    waiting_div.html(waiting_div_inner);
    $(w_div).append(waiting_div);
    
    $('body').prepend(w_div);
}

function CloseWaitingDiv()
{
    $(w_div).remove();
    w_div = null;
}      


  
function storeMarker()
{
    
    var lng = document.getElementById("mylongitude").value;
    var lat = document.getElementById("mylatitude").value;

    //alert(document.getElementById("clickinfo").value);
    
    //var getVars = "?clickinfo=abc" + "&lng=" + lng + "&lat=" + lat ;
    //var request = GXmlHttp.create();
    
    //open the request to storeMarker.php on your server
    /*request.open('GET', '../maps/store_marker.php' + getVars, true);
    request.onreadystatechange = function() 
    {
        if (request.readyState == 4) 
        {
            //the request is complete
            var xmlDoc = request.responseXML;
            //retrieve the root document element (response)
            var responseNode = xmlDoc.documentElement;
            //retrieve the type attribute of the node
            var type = responseNode.getAttribute("type");
            //retrieve the content of the responseNode
            var content = responseNode.firstChild.nodeValue;
            //check to see if it was an error or success
            if(type!='success') {
            alert(content);
            } else {
                //create a new marker and add its info window
                var latlng = new GLatLng(parseFloat(lat),parseFloat(lng));
                var marker = createMarker(latlng, content);
                map.addOverlay(marker);
                map.closeInfoWindow();
                }
            }
    }
    request.send(null); */
   // return false;
}                           

function createMarker(latlng, html) 
{
    var marker = new GMarker(latlng);
    GEvent.addListener(marker, 'click', function() 
    {
        var markerHTML = html;
        marker.openInfoWindowHtml(markerHTML);
    });
    return marker;
}         


///////////////////////
function addMarker(Latitude,Longitude, Description,Type,index)
{
   // var latlng = new GLatLng();
	var icon = new GIcon();
    
    //alert(Description);
    
   Description =  Description.replace(/&lt;/g,"<");
   Description = Description.replace(/&gt;/g,">");
   Description = Description.replace(/&deg;/g,"°");
   
   
    
    //var strfun = new ActiveXObject("CkString.StrFun");
    //Description = strfun.HtmlEntityDecode(Description);
    
    /*if(!Type){icon.image = "http://www.imranalikhan.com/bayut/gmaps/imgs/factory.png";icon.iconSize = new GSize(54, 45);}
    if(Type == "3"){icon.image = "http://www.imranalikhan.com/bayut/gmaps/imgs/villas.png";icon.iconSize = new GSize(54, 26)}
    else if(Type == "4"){icon.image  = "http://www.imranalikhan.com/bayut/gmaps/imgs/building.png";icon.iconSize = new GSize(46, 29);}
    else if(Type == "5"){icon.image  = "http://www.imranalikhan.com/bayut/gmaps/imgs/offices.png";icon.iconSize = new GSize(43, 30);}
    else if(Type == "6"){icon.image  = "http://www.imranalikhan.com/bayut/gmaps/imgs/shops.png";icon.iconSize = new GSize(46, 29);}
    else if(Type == "7"){icon.image  = "http://www.imranalikhan.com/bayut/gmaps/imgs/warehouse.png";icon.iconSize = new GSize(54, 28);}
    else if(Type == "8"){icon.image  = "http://www.imranalikhan.com/bayut/gmaps/imgs/factory.png";icon.iconSize = new GSize(54, 45);}
    else if(Type == "9"){icon.image  = "http://www.imranalikhan.com/bayut/gmaps/imgs/building.png";icon.iconSize = new GSize(46, 29);}
    else if(Type == "11"){icon.image = "http://www.imranalikhan.com/bayut/gmaps/imgs/shops.png";icon.iconSize = new GSize(46, 29);}
    else if(Type == "10"){icon.image = "http://www.imranalikhan.com/bayut/gmaps/imgs/building.png";icon.iconSize = new GSize(46, 29);}*/
	
	var img_index = index + 1;
	icon.image = this_domain + "/gmaps/imgs/" + img_index + ".png";
	icon.iconSize = new GSize(41, 34);
	
    icon.iconAnchor = new GPoint(10, 33);
	icon.infoWindowAnchor = new GPoint(14, 14);  
    var marker = new GMarker(new GLatLng(Latitude,Longitude),icon);
    marker.geohtml = Description;
    
    tmp_markers[index] = marker;
    GEvent.addListener(marker,'mousedown',function(overlay, latlng)
    {
            var select_div = document.getElementById("list_div");
            var my_scroll = $('#list_id_'+index).offset({scroll:false}).top;
            
            my_scroll -= document.documentElement.clientHeight * 0.60; //250
            $('#list_div').animate({scrollTop: my_scroll}, 700);
            
			var div_id = 'list_id_'+ index;
            $('#' + div_id).css({"background-color":"#F5F5F5"});
            $('#' + div_id).css({"border":"1px solid #E0E0E0"});    
			if(div_id != last_selected_div)
			{
				$('#' + last_selected_div).css({"background-color":"#FFFFFF"});
                $('#' + last_selected_div).css({"border":"1px solid #FFFFFF"});      
            	last_selected_div = div_id;
            }
            marker.openInfoWindowHtml(Description);     
            
            //alert(last_selected_div);
    });
    map.addOverlay(marker);      
}

function my_scroll(i)
{   
 $('#list_div').scrollTop(i);    


}

function cancel_confirm_box()
{
    map.disableInfoWindow();
    map.enableInfoWindow();      
} 

function set_form_fields()
{
    $('#mylatitude').val(lat);
    $('#mylongitude').val(lng);
    map.disableInfoWindow();
    map.enableInfoWindow();
    var html ="<table><tr><td>This Marker Will Be Saved After Confirmation.<br><br>Please Press Esc to Close This Window<br><label style='margin-top:3px; margin-bottom:3px;'>OR<label><br>Click on Map To Choose a Different Location</td></tr></table>";
    map.clearOverlays();
	AddMemberMarker(html); 
	if($('#dev_latlng').html())
	{ //code is used for edit development
		$('#dev_cat_lat').val(lat);  
		$('#dev_cat_lng').val(lng);	
	}
}           

function init(event,cLatitude,cLongitude,zoom,apptype,lat_target,lng_target,did,poslat,poslng,map_div)                     
{	
   if(!cLatitude)event = "false"; 
   if(!cLatitude)cLatitude = 25;
   if(!cLongitude)cLongitude = 55;
   if(!zoom)zoom = 7;
   if(!apptype)apptype = "user";
   
   
   /*alert(cLatitude);
    alert(cLongitude);
    alert(zoom);
    alert(apptype);*/
   /*
        var cLatitude = 25;
        var cLongitude = 55;
        var zoom = 13;
        var apptype = "user"; 
   */
    if(GBrowserIsCompatible())
    {	
    
        if(map_div)
		{
			map = new GMap2(document.getElementById(map_div));
		}
		else
		{
			map = new GMap2(document.getElementById("map"));
		}
		
		
        var location = new GLatLng(cLatitude,cLongitude);
        if(apptype != "view_small")
		{
			map.addControl(new GLargeMapControl());
	        map.addControl(new GMapTypeControl());
		}
        
        if(apptype == "user")
        {
            map.addControl(new GOverviewMapControl()); 
        }
        
        map.setCenter(location,parseInt(zoom));          

        //alert(apptype);
        //for(id in markers)
        //{
            //    addMarker(markers[id].latitude,markers[id].longitude,markers[id].name);
        //}
		
		//addMarker(cLatitude,cLongitude,"testing");
	    //map.openInfoWindowHtml (new GLatLng(cLatitude,cLongitude),"asdfsadf");       
		if(apptype == "member") 
		{
                //Display an alert Message on User Right Click
                //GEvent.addListener(map, "singlerightclick", function(point){
                
                 var m_lat = $('#mylatitude').val();
                 var m_lng = $('#mylongitude').val();
                 
                 if(m_lat > 0 && m_lng > 0)
                 {
                    
                     var icon = new GIcon();  
                     icon.image = this_domain + "/gmaps/imgs/empty.png";
                     icon.iconSize = new GSize(41, 34);
                     icon.iconAnchor = new GPoint(14, 25);
                     icon.infoWindowAnchor = new GPoint(14, 14);  
                    
                     var marker = new GMarker(new GLatLng(m_lat,m_lng),icon);
                     map.addOverlay(marker);
                     var html ="<table><tr><td>This is Your Last Selected Location<br><br>Please Press Esc to Close This Window<br><label style='margin-top:3px; margin-bottom:3px;'>OR<label><br>Click on Map To Choose a Different Location</td></tr></table>";
                     marker.openInfoWindowHtml(html);   
                 }

                
                GEvent.addListener(map, "click", function(overlay,latlng){
                //var latlng = map.fromContainerPixelToLatLng(point);
                //lng = latlng.lng();
                //lat = latlng.lat();
                /*var tmp_lat = latlng.lat();
                 var tmp_lng = latlng.lng();
                 $('#tlat').val(tmp_lat);
                 $('#tlng').val(tmp_lng);   */
                  
                 
                AddMemberConfirmBox(latlng);   
               
            }); 
            
                GEvent.addListener(map, "singlerightclick", function(point){
                var latlng = map.fromContainerPixelToLatLng(point);
                AddMemberConfirmBox(latlng);     

            });     
		
		}
      
        if(apptype == "cp") 
        {
                
				//Display an alert Message on User Right Click
                //GEvent.addListener(map, "singlerightclick", function(point){
                
                 var m_lat = $('#mylatitude').val();
                 var m_lng = $('#mylongitude').val();
                 
                 if(m_lat > 0 && m_lng > 0)
                 {
                    
                     var icon = new GIcon();  
                     icon.image = this_domain + "/gmaps/imgs/empty.png";
                     icon.iconSize = new GSize(41, 34);
                     icon.iconAnchor = new GPoint(14, 25);
                     icon.infoWindowAnchor = new GPoint(14, 14);  
                    
                     var marker = new GMarker(new GLatLng(m_lat,m_lng),icon);
                     map.addOverlay(marker);
                     var html ="<table><tr><td>This is the User selected location<br><br>Please Press Esc to Close This Window<br><label style='margin-top:3px; margin-bottom:3px;'>OR<label><br>Click on Map To Choose a Different Location</td></tr></table>";
                     marker.openInfoWindowHtml(html);   
                 }

                
                GEvent.addListener(map, "click", function(overlay,latlng){     
                AddMemberConfirmBox(latlng);   
               
                }); 
            
                GEvent.addListener(map, "singlerightclick", function(point){
                var latlng = map.fromContainerPixelToLatLng(point);
                AddMemberConfirmBox(latlng);     

            });     
        
        }
 
        if(apptype == "cp_adv") 
        {
                
                //Display an alert Message on User Right Click
                //GEvent.addListener(map, "singlerightclick", function(point){
                
                 latTarget =  lat_target;
                 lngTarget =  lng_target;
                 /*var m_lat = $('#' + lat_target).val();
                 var m_lng = $('#' + lng_target).val();   */
                 
                 var m_lat = $('#mylatitude').val();
                 var m_lng = $('#mylongitude').val();
                 
                 if(m_lat > 0 && m_lng > 0)
                 {
                     var icon = new GIcon();  
                     icon.image = this_domain + "/gmaps/imgs/empty.png";
                     icon.iconSize = new GSize(41, 34);
                     icon.iconAnchor = new GPoint(14, 25);
                     icon.infoWindowAnchor = new GPoint(14, 14);  
                    
                     var marker = new GMarker(new GLatLng(m_lat,m_lng),icon);
                     map.addOverlay(marker);
                     var html ="<table><tr><td>This is the Last selected location<br><br>Please Press Esc to Close This Window<br><label style='margin-top:3px; margin-bottom:3px;'>OR<label><br>Click on Map To Choose a Different Location</td></tr></table>";
                     marker.openInfoWindowHtml(html);   
                 }

                
                GEvent.addListener(map, "click", function(overlay,latlng){
                //var latlng = map.fromContainerPixelToLatLng(point);
                //lng = latlng.lng();
                //lat = latlng.lat();
                /*var tmp_lat = latlng.lat();
                 var tmp_lng = latlng.lng();
                 $('#tlat').val(tmp_lat);
                 $('#tlng').val(tmp_lng);   */
                 AddMemberConfirmBox_adv(latlng);   
               
                }); 
            
                GEvent.addListener(map, "singlerightclick", function(point){
                var latlng = map.fromContainerPixelToLatLng(point);
                AddMemberConfirmBox_adv(latlng);     

            });     
        
        }

		if(apptype == "cp1") 
        {
                
				//Display an alert Message on User Right Click
                //GEvent.addListener(map, "singlerightclick", function(point){
                
                 var m_lat = $('#mylatitude').val();
                 var m_lng = $('#mylongitude').val();
                 
                 if(m_lat > 0 && m_lng > 0)
                 {
                    
                     var icon = new GIcon();  
                     icon.image = this_domain + "/gmaps/imgs/empty.png";
                     icon.iconSize = new GSize(41, 34);
                     icon.iconAnchor = new GPoint(14, 25);
                     icon.infoWindowAnchor = new GPoint(14, 14);  
                    
                     var marker = new GMarker(new GLatLng(m_lat,m_lng),icon);
                     map.addOverlay(marker);
                     var html ="<table><tr><td>This is the User selected location<br><br>Please Press Esc to Close This Window</td></tr></table>";
                     marker.openInfoWindowHtml(html);   
                 }
        
        }
        
        if(apptype == "view") 
        {      
            lat =  cLatitude;
            lng =  cLongitude;
            var html = "Listing Locatiton"; 
            var html = $('#gmap_info_desc').html();
            //$('#gmap_info_desc').remove();
            AddMemberMarker(html);   
        }

		if(apptype == "view_small") 
        {      
            lat =  cLatitude;
            lng =  cLongitude;
            var html = "Property Locatiton"; 
            
            //$('#gmap_info_desc').remove();
            //AddMemberMarker(html);
			//AddMapMarker(lat,lng,"","",false,"");
			ViewMarker(lat,lng);
        }
             
        if(apptype == "nb_view" || apptype == "nbc_view") 
        {      
            lat =  cLatitude;
            lng =  cLongitude;
            
            var html = "Listing Locatiton"; 
            var title = $("#" + did + "_title").html();
			var logo = $("#" + did + "_logo").attr("src");
            var city = $("#" + did + "_city").html();
            var desc = $("#" + did + "_desc").html();
            
           
            
            latfrom  = lat;
            lngfrom  = lng;
            
            var html = "<table width=350 style=\"font-size:12px;\"><tr><td><table width=100%><tr><td><b>"+title+"</b></td><td><b>"+city+"</b></td></tr></table></td></tr><tr><td><table><tr><td valign=top><img src="+logo+" border=0 width=50 height=50 style=\"border:1px solid #BBBBBB\" /></td><td>"+desc+"</td></tr></table></td></tr></table><br>";
            htmlfrom = html;            
            htmlto = "<table width=350 style=\"font-size:12px;\"><tr><td>This is Your Selected Location:<br>Please Right Click on map to choose a different location</td></tr></table><br>";      
            
            
            if(apptype == "nbc_view")
            {   
                latTarget = "nb_latitude";
                lngTarget = "nb_longitude";
                 
                desc += " Right Click on map to calculte the distance for a different location";
                var html = "<table width=350><tr><td><table width=100%><tr><td><b></b></td><td><b></b></td></tr></table></td></tr><tr><td></td></tr></table>";
                htmlfrom = html;            
                submit_cform = null;   
                
                
				html1 = "<table width=350><tr><td>This is your last selected location. Please click on map to choose a new location.</td></tr></table><br>";
			    map.clearOverlays();          
			    AddNewMarker(lat,lng,html1);  

	
				//AddMemberMarker(htmlfrom);   
                GEvent.addListener(map, "click", function(overlay,latlng){
                latto = latlng.lat(); 
                lngto = latlng.lng(); 
                NB_AddMemberConfirmBox(latlng);   
                });
                
                GEvent.addListener(map, "singlerightclick", function(point){
                var latlng = map.fromContainerPixelToLatLng(point);
                latto = latlng.lat(); 
                lngto = latlng.lng(); 
                NB_AddMemberConfirmBox(latlng);   
                });                                 
                
             }
             else
             { 
				
                htmlto = "<table width=350 style=\"font-size:12px;\"><tr><td>This is Your Selected Location:</td></tr></table>";      
                if(poslat && poslng)
                {   
                    AddNewMarker(poslat,poslng,htmlto);
                     var polyline = new GPolyline([
                     new GLatLng(latfrom, lngfrom),
                     new GLatLng(poslat, poslng)
                    ], "#ff0000", 10);
                    map.addOverlay(polyline); 
                }
                

				$('#listing_display > div').each(function(){
					
					
					var id = $(this).attr('id');
					var tpl_lat = $("#tpl_lat" + id).val();
					var tpl_lng = $("#tpl_lng" + id).val();
					var tpl_desc = $("#" + id + "_desc").html();
					var tpl_logo = $("#" + id + "_logo").attr("src");
					var title = $("#" + id + "_title").html();
					var city = $("#" + id + "_city").html();
					var type = $("#place_type_" + id).val();
					var tpl_desc = "<table width=350 style=\"font-size:12px;\"><tr><td><table width=100%><tr><td><b>"+title+"</b></td><td><b>"+city+"</b></td></tr></table></td></tr><tr><td><table><tr><td valign=top><img src="+tpl_logo+" border=0 width=50 height=50 style=\"border:1px solid #BBBBBB\" /></td><td>"+tpl_desc+"</td></tr></table></td></tr></table><br>";
					var hide_window = 'true';
					if(id)
					{
						var icon_path = "";	
						icon_path = $("#" + id + "_icon").val();
						
						if(!icon_path)
						{
							icon_path = "/gmaps/imgs/empty.png";
							if(type == 1)icon_path = "/images/common/school.png"
							else if(type == 2)icon_path = "/images/common/hospital.png"
							else if(type == 3)icon_path = "/images/common/park.png"
							else if(type == 4)icon_path = "/images/common/shopping.png"
							else if(type == 25)icon_path = "/images/common/transport.png"
						}
						AddMapMarker(tpl_lat,tpl_lng,icon_path,tpl_desc,false,false);
					}
					//alert($(this).attr('id'));
				});
				map.openInfoWindowHtml(new GLatLng(lat, lng),htmlfrom);
             }         
               
        }
		if(apptype == "view_adv") //input based
		{
			var input_divs = "";
			var map_desc  = "";
			var map_desc_tmp = "";
			var title = "";
			var desc = "";
			var distance = "";
			var description = "";
			var div = "";
			var logo = "";
			var footer = "";
			var lat_end = "";
			var lng_end = "";
			var lat_start   =   cLatitude;
			var lng_start   =   cLongitude;
			var start_div   = "";
			var temp_position = "";
			var icon_path = "";
			var special_desc = "";
			var special_icon = "";
			// first map input can also tell about the template for description. default is map_desc
			
			if($("#map_template").val())
			{
				map_desc = $("#map_template").val();
			}
			
			if($(".input_divs").val())
			{
				input_divs = $(".input_divs").val();
			}
			
			
			if(input_divs != "" && map_desc != "")
			{
				//code for multiple divs
				$('.input_divs').each(function()
				{
					title = "";
					desc = "";
					distance = "";
					div = "";
					logo = "";
					footer = "";
					lat_end = "";
					lng_end = "";
					description = "";
					temp_position = "";
					
					input_divs = $(this).val();
					if(input_divs.search(/:/) != -1)
					{
						input_divs = input_divs.split(":");
						
						for(i=0; i<input_divs.length; i++) 
						{
							 div = input_divs[i];
							 
							if(div.search(/title/) != -1)
							{ 
								if(div.search(/value/) != -1)
								{
									title = $("#" + div).val();
								}
								else
								{
									title = $("#" + div).html();
								}
							} 
							else if(div.search(/desc/) != -1)
							{
								if(div.search(/value/) != -1)
								{
									description = $("#" + div).val();
								}
								else
								{
									description = $("#" + div).html();
								}
							}	
							else if(div.search(/position/) != -1)
							{ 
								if(div.search(/value/) != -1)
								{
									temp_position = $("#" + div).val();
								}
								else
								{
									temp_position = $("#" + div).html();
								}
								temp_position = temp_position.split(":");
								lat_end = temp_position[0];
								lng_end = temp_position[1];
							} 
							else if(div.search(/desc/) != -1)
							{
								if(div.search(/value/) != -1)
								{
									desc = $("#" + div).val();
								}
								else
								{
									desc = $("#" + div).html();
								}
							
							}
							else if(div.search(/distance/) != -1)
							{
								if(div.search(/value/) != -1)
								{
									distance = $("#" + div).val();
								}
								else
								{
									distance = $("#" + div).html();
								}
							}
							else if(div.search(/logo/) != -1)
							{
								if(div.search(/value/) != -1)
								{
									logo = $("#" + div).val();
								}
								else
								{
									logo = $("#" + div).html();
								}
							}
							else if(div.search(/icon/) != -1)
							{
								if(div.search(/value/) != -1)
								{
									icon_path = $("#" + div).val();
								}
								else
								{
									icon_path = $("#" + div).html();
								}
							}
								
						}
						
						map_desc_tmp = map_desc;
						
						map_desc_tmp = map_desc_tmp.replace(/@title_left@/g, logo);
						map_desc_tmp = map_desc_tmp.replace(/@title_right@/g, title);
						map_desc_tmp = map_desc_tmp.replace(/@description@/g, description);
						map_desc_tmp = map_desc_tmp.replace(/@footer@/g, footer);
						if(lat_end == cLatitude)
						{
							special_desc = map_desc_tmp;
							special_icon = icon_path;
						}
						else
						{
							AddMapMarker(lat_end,lng_end,icon_path,map_desc_tmp,false,false);
						}

						
					}
					else
					{
						//code for single div
						AddMapMarker(lat_start,lng_start,"",map_desc_tmp,true,true);
					}
					// addmembermarker
					
					
				});
				if($("#lat_start").val())
				{
					lat_start = $("#lat_start").val();
				}
				
				if($("#lng_start").val())
				{
					lng_start = $("#lng_start").val();
				}
				
				if($("#start_div").val())
				{
					start_div = $("#start_div").val();
					start_html = $("#" + start_div).html();
				}
				AddMapMarker(lat_start,lng_start,"",start_html,false,true);
				var polyline = new GPolyline([
                     new GLatLng(cLatitude, cLongitude),
                     new GLatLng(lat_start,lng_start)
                    ], "#ff0000", 10);
                    map.addOverlay(polyline); 
				
				if(special_desc)
				{
					AddMapMarker(cLatitude,cLongitude,special_icon,special_desc,true,false);
				}
				//alert("Property Check!! if you are reading this message. please press ok");
				
			}
			else
			{
				// input divs is not set. old code is running.
				AddMapMarker(lat_start,lng_start,"",map_desc,false,true);
			}
		}
    }                                                                           
}


function AddMapMarker(lat,lng,icon_path,Description,showPopupFirstTime,useDefaultIcon)
{
    var icon = new GIcon(); 
	if(icon_path == "")
	{
		icon_path = "/gmaps/imgs/empty.png";
		
	}
	icon.iconSize = new GSize(35, 31);
	
	if(useDefaultIcon)
	{
		icon.iconSize = new GSize(41, 34);
		icon.iconAnchor = new GPoint(11, 25);
	}
	else
	{
		icon.iconAnchor = new GPoint(5, 25);
	}
	 
    icon.image = this_domain + icon_path;    
	icon.infoWindowAnchor = new GPoint(14, 14);  
    
    
    
    
    var marker = new GMarker(new GLatLng(lat,lng),icon);
   // marker.openInfoWindowHtml("This Marker Will Be Saved After Confirmation");   
    //map.clearOverlays();   
    map.addOverlay(marker);
    
	if(Description != "")
	{
	    GEvent.addListener(marker,'click',function(overlay, latlng)
	    {
	      marker.openInfoWindowHtml(Description); 
	    });
		
		if(showPopupFirstTime == true)
		{	
			marker.openInfoWindowHtml(Description); 
			
		}
	}
   
   // marker.geohtml = Description;
   return false;
    

}

function AddMemberMarker(html)
{
    var icon = new GIcon();  
    icon.image = this_domain + "/gmaps/imgs/empty.png";
    icon.iconSize = new GSize(41, 34);
    
    icon.iconAnchor = new GPoint(10, 33);
    icon.infoWindowAnchor = new GPoint(14, 14);  
    
    
    
    var marker = new GMarker(new GLatLng(lat,lng),icon);
   // marker.openInfoWindowHtml("This Marker Will Be Saved After Confirmation");   
   /* map.clearOverlays();       */
    map.addOverlay(marker);
    
    GEvent.addListener(marker,'click',function(overlay, latlng)
    {
      marker.openInfoWindowHtml(html); 
    });
       
    marker.openInfoWindowHtml(html);   
   // marker.geohtml = Description;
   return false;
} 

function AddMemberConfirmBox(latlng)
{
    
    if(latlng)
    {
        lng = latlng.lng();
        lat = latlng.lat();
        
        //create an HTML DOM form element
        var new_input_form = "<form action='' onsubmit='storeMarker(); return false;'>"
        + "<table width='235' height='40' border='0'><tr><td>"                 
        + "<fieldset>" 
        + "<legend style='margin-left:5px'><label style='margin-right:2px; margin-left:2px;'>Please Confirm Your Location</label></legend>"
        + "<div style='margin-top:10px; margin-bottom:6px; margin-left:3px'>"
        + "<input type='Submit' id='sub_btn' value='Confirm' onclick='set_form_fields();'/>" 
        + "<input style='margin-left:5px; width:55px' type='button' value='Cancel' onclick='cancel_confirm_box(); return false;'/>"
        + "<input type='hidden' id='myinfo' value='clicked'/>"
        + "<input type='hidden' id='longitude' value='" + lng + "'/>"
        + "<input type='hidden' id='latitude'  value='" + lat + "'/>"
        + "</div>"   
        + "</fieldset>"
        + "</td></tr></table>"  
        + "</form>"; 
        
        map.openInfoWindowHtml (latlng,new_input_form);
    }
}

function AddMemberConfirmBox_adv(latlng)    
{

    if(latlng)
    {
        lng = latlng.lng();
        lat = latlng.lat();
        
        //create an HTML DOM form element
        var new_input_form = "<form action='' onsubmit='storeMarker(); return false;'>"
        + "<table width='235' height='40' border='0'><tr><td>"                 
        + "<fieldset>" 
        + "<legend style='margin-left:5px'><label style='margin-right:2px; margin-left:2px;'>Please Confirm Your Location</label></legend>"
        + "<div style='margin-top:10px; margin-bottom:6px; margin-left:3px'>"
        + "<input type='Submit' id='sub_btn' value='Confirm' onclick='set_form_fields_adv();'/>" 
        + "<input style='margin-left:5px; width:55px' type='button' value='Cancel' onclick='cancel_confirm_box(); return false;'/>"
        + "<input type='hidden' id='myinfo' value='clicked'/>"
        + "<input type='hidden' id='longitude' value='" + lng + "'/>"
        + "<input type='hidden' id='latitude'  value='" + lat + "'/>"
        + "</div>"   
        + "</fieldset>"
        + "</td></tr></table>"  
        + "</form>"; 
        
        map.openInfoWindowHtml (latlng,new_input_form);
    }
}

function NB_AddMemberConfirmBox(latlng)    
{
        //create an HTML DOM form element
        var new_input_form = "<form action=''>"
        + "<table width='235' height='40' border='0'><tr><td>"                 
        + "<fieldset>" 
        + "<legend style='margin-left:5px'><label style='margin-right:2px; margin-left:2px;'>Please Confirm Your Location</label></legend>"
        + "<div style='margin-top:10px; margin-bottom:6px; margin-left:3px'>"
        + "<input type='Button' id='sub_btn' value='Confirm' onclick='NB_set_form_fields();'/>" 
        + "<input style='margin-left:5px; width:55px' type='button' value='Cancel' onclick='cancel_confirm_box(); return false;'/>"
        + "<input type='hidden' id='myinfo' value='clicked'/>"
        + "</div>"   
        + "</fieldset>"
        + "</td></tr></table>"  
        + "</form>"; 
        
        
        
        map.openInfoWindowHtml(latlng,new_input_form);

}

function NB_set_form_fields()
{
      html1 = "This is your last Selected Location. Please click on map to choose a new location";
      map.clearOverlays();       
      //AddNewMarker(latfrom,lngfrom,htmlfrom);         
      //AddNewMarker(latto,lngto,html1);  
      $('#' + latTarget).val(latto);
      $('#' + lngTarget).val(lngto);
	  var map_link = "#TB_inline?height=500&width=700&inlineId=mapbody&zoom=14&opt=nbc&apptype=view&did=2&tlat=" + latto + "&tlng=" + lngto;
      $("#nb_cmap").attr("href",map_link);	
      CloseThickBox();  
	  $('#nb_cmap').html("(Location - click to change)");
	  $('#nb_clocation').val("true");
	  
             
}

function set_form_fields_adv()
{
    $('#mylatitude').val(lat);
    $('#mylongitude').val(lng);
    $('#' + latTarget).val(lat);
    $('#' + lngTarget).val(lng);
    map.disableInfoWindow();
    map.enableInfoWindow();
    var html ="<table><tr><td>This Marker Will Be Saved After Confirmation.<br><br>Please Press Esc to Close This Window<br><label style='margin-top:3px; margin-bottom:3px;'>OR<label><br>Click on Map To Choose a Different Location</td></tr></table>";
    AddMemberMarker(html);    
     
}

function AddNewMarker(lat,lng,html,hidewindow)
{
   
       //icon.image = "http://www.imranalikhan.com/bayut/gmaps/imgs/" + img_index + ".png";
    //icon.iconSize = new GSize(41, 34);
    
    //icon.iconAnchor = new GPoint(14, 25);
    //icon.infoWindowAnchor = new GPoint(14, 14);  
    //var marker = new GMarker(new GLatLng(Latitude,Longitude),icon);
    var icon = new GIcon();  
    icon.image = this_domain + "/gmaps/imgs/empty.png";
    icon.iconSize = new GSize(41, 34);
    
    icon.iconAnchor = new GPoint(10, 33);
    icon.infoWindowAnchor = new GPoint(14, 14);  
    
    
    
    var marker = new GMarker(new GLatLng(lat,lng),icon);
   // marker.openInfoWindowHtml("This Marker Will Be Saved After Confirmation");   
    //map.clearOverlays();   
    map.addOverlay(marker);
    
    GEvent.addListener(marker,'click',function(overlay, latlng)
    {
      marker.openInfoWindowHtml(html); 
    });
    if(!hidewindow)
	{	
		marker.openInfoWindowHtml(html); 
		
	}
   // marker.geohtml = Description;
   return false;
    

}

function CloseThickBox()
{
     if(tparams['apptype'] == 'view' || tparams['apptype'] == 'member' || tparams['apptype'] == 'cp' || tparams['apptype'] == 'cp_adv' || tparams['apptype'] == 'cp1')
    {
        if(document.getElementById("map"))
        {
            document.getElementById("map").style.display = "none";
         }
    }
    $("#TB_imageOff").unbind("click");
    $("#TB_closeWindowButton").unbind("click");
    $("#TB_window").fadeOut("fast",function(){$('#TB_window,#TB_overlay,#TB_HideSelect').trigger("unload").unbind().remove();});
    $("#TB_load").remove();
    if (typeof document.body.style.maxHeight == "undefined") {//if IE 6
        $("body","html").css({height: "auto", width: "auto"});
        $("html").css("overflow","");
    }
    document.onkeydown = "";
    document.onkeyup = "";
    if(tparams['apptype'] == 'view' || tparams['apptype'] == 'member' || tparams['apptype'] == 'cp' || tparams['apptype'] == 'cp_adv' || tparams['apptype'] == 'cp1')
    {
        if(document.getElementById("map"))   
        {
            GUnload();
        }
    }
    if(tparams['apptype'] == 'registration')
    {
        if($('#role_text').html())
        {
            nd();
            confirm_open = 0;  
        }
    }

    return false;       
}

function ViewMarker(lan,lon)
{
    var icon = new GIcon();  
    icon.image = this_domain + "/gmaps/imgs/empty.png";
    icon.iconSize = new GSize(41, 34);
    
    icon.iconAnchor = new GPoint(10, 34);
    icon.infoWindowAnchor = new GPoint(14, 14);  
    
    
    
    var marker = new GMarker(new GLatLng(lat,lng),icon);
   // marker.openInfoWindowHtml("This Marker Will Be Saved After Confirmation");   
   /* map.clearOverlays();       */
    map.addOverlay(marker);
    
    GEvent.addListener(marker,'click',function(overlay, latlng)
    {
      url = "#TB_inline?height=500&width=700&inlineId=mapbody&zoom=14&apptype=view&tlat="+lan+"&tlng="+lon;
	  tb_show("",url);
    });
       
   
   // marker.geohtml = Description;
   return false;
} 