function BpControl(){var _a=0;function l(_b,_c,_d,_f){if(!_b)_b='Loading...';if(!_c)_c=new GSize(100,100);if(!_d)_d=G_ANCHOR_TOP_LEFT;this._b=_b;this._c=_c;this._d=_d;this._f=_f;this._a=++_a;this._g='bpcontrol'+this._a;}l.prototype=new GControl();var _h=l.prototype;_h.getDivId=function(){return this._g;};_h.getDiv=function(){return this._i;};_h.getContent=function(){return this._i.innerHTML;};_h.setContent=function(_b){this._i.innerHTML=_b;};_h.show=function(){this._i.style.display='';};_h.hide=function(){this._i.style.display='none';};_h.getClassName=function(){return this._f;};_h.setClassName=function(_f){if(!this._f)return;this._f=_f;this._i.className=_f;};_h.initialize=function(_j){var _i=document.createElement('div');_i.setAttribute('id',this._a);var _k=_i.style;_k.display='none';if(this._f){_i.className=this._f;}else{_k.border='1px solid black';_k.backgroundColor='white';_k.fontWeight='bold';_k.paddingLeft='3px';_k.paddingRight='3px';}_i.innerHTML=this._b;_j.getContainer().appendChild(_i);this._i=_i;return _i;};_h.getDefaultPosition=function(){return new GControlPosition(this._d,this._c);};_h.printable=function(){return false;};_h.selectable=function(){return false;};window.BpControl=l;}BpControl();
// JavaScript Document
// A TextualZoomControl is a GControl that displays textual "Zoom In"
// and "Zoom Out" buttons (as opposed to the iconic buttons used in
// Google Maps).

AddmeBtnControl.prototype = new GControl();

// We define the function first , it will execute when button going to initilaize
function AddmeBtnControl() {}

// To "subclass" the GControl, we set the prototype object to
// an instance of the GControl object


// Creates a one DIV for each of the buttons and places them in a container
// DIV which is returned as our control element. We add the control to
// to the map container and return the element for the map class to
// position properly.
AddmeBtnControl.prototype.initialize = function(map) {
  var container = document.createElement("div");
  var button = document.createElement("div");
  this.setButtonStyle_(button);
  container.appendChild(button);
  
  GEvent.addDomListener(button, "click", function() {
	SIPL.SEEIMGREEN.OpenBb('Registration',"addme/",550,800);
  });

  map.getContainer().appendChild(container);
  return container;
}

// By default, the control will appear in the top left corner of the
// map with 7 pixels of padding.
AddmeBtnControl.prototype.getDefaultPosition = function(){
  var margin={left: 7,top :7 };
  return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(margin.left,margin.top));
 }
// Sets the proper CSS for the given button element.
AddmeBtnControl.prototype.setButtonStyle_ = function(button) {
  button.style.textDecoration = "underline";
  button.style.color = "#0000cc";
  button.style.backgroundImage = "url("+BASE_PATH + "images/addme.png)";
  button.style.backgroundRepeat="no-repeat";
  button.style.font = "small Arial";
  button.style.border = "0px";
  button.style.paddingTop = "30px";
  button.style.fontWeight="bold";
  button.style.textAlign = "center";
  button.style.width = "158px";
  button.style.height="122px";
  button.style.cursor = "pointer";
}

//reset button


resetBtn.prototype = new GControl();
function resetBtn(){}

resetBtn.prototype.initialize = function(map) {
	  var container = document.createElement("div");
	  var button = document.createElement("div");
	  this.setButtonStyle_(button);
	  container.appendChild(button);
	  
	  GEvent.addDomListener(button, "click", function() {
		  var mapZoom = 4;
		  var mapLat = 38.228517;
		  var mapLng = -98.437500;
					
		  map.setCenter(new GLatLng(mapLat, mapLng), mapZoom);		
	  });

	  map.getContainer().appendChild(container);
	  return container;
	}


resetBtn.prototype.getDefaultPosition = function(){
	  var margin={left: 7,top :7 };
	  return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(margin.left,margin.top));
	 }

resetBtn.prototype.setButtonStyle_ = function(button) {
	  button.style.textDecoration = "underline";
	  button.style.color = "#0000cc";
	  button.style.backgroundImage = "url("+BASE_PATH + "img/reset_map.gif)";
	  button.style.backgroundRepeat="no-repeat";
	  button.style.font = "small Arial";
	  button.style.border = "0px";
	  button.style.paddingTop = "30px";
	  button.style.fontWeight="bold";
	  button.style.textAlign = "center";
	  button.style.width = "158px";
	  button.style.height="122px";
	  button.style.cursor = "pointer";
	}



var map;
var CONTROL;
var SearchControlId;
var CFG = new Object();
CFG.points = [];

SIPL.MAP ={
		
	load: function(){
		 if (GBrowserIsCompatible()) {			
			map = new GMap2(document.getElementById("map"));
			if(BTN_ADDME_SHOW==1){
				map.addControl( new AddmeBtnControl());
				CONTROL = new BpControl("&nbsp;",new GSize(0,0));
				map.addControl(CONTROL);
				CONTROL.setClassName("searchbar");
				//CONTROL.show();
			} else {				
				CONTROL = new BpControl("&nbsp;",new GSize(0,0));
				map.addControl(CONTROL);
				CONTROL.setClassName("searchbar");
			}
			map.enableContinuousZoom();				
			map.addControl(new resetBtn());			
			
			//zoom and move listener -- dld 11/06/08
			GEvent.addListener(map, "zoomend", function(oldzoom,zoom) {
				if (zoom != 0){
					$.cookie('gmap_zoom', zoom);
					var latlng = map.getCenter();
					$.cookie('gmap_center_lat', latlng.lat());	
					$.cookie('gmap_center_lng', latlng.lng());	
				}
			}); 
			
			GEvent.addListener(map, "moveend", function() {
				var latlng = map.getCenter();
				$.cookie('gmap_center_lat', latlng.lat());	
				$.cookie('gmap_center_lng', latlng.lng());					
			}); 
			
			
			var bottomRight = new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(10,150));
		    map.addControl(new GLargeMapControl(),bottomRight);
			map.addControl(new GOverviewMapControl()); // small overview control
			
			var mapZoom = $.cookie('gmap_zoom') ? Number($.cookie('gmap_zoom')) : 4;
			var mapLat = $.cookie('gmap_center_lat') ? Number($.cookie('gmap_center_lat')) : 38.228517;
			var mapLng = $.cookie('gmap_center_lng') ? Number($.cookie('gmap_center_lng')) : -98.437500;
					
			map.setCenter(new GLatLng(mapLat, mapLng), mapZoom);			
		}
	},
	
	addPoint: function (point, obj, dbg){
		var icon = new GIcon();
		
		//check to see if point is on map
		if (CFG.points[obj.id]) return;
		
		if (obj.activity){
			var act = obj.activity.split(',');
			var ct_act = act.length;
			obj.acts = act;
		} else {
			act = ct_act = false;
			obj.acts = false;			
		}
		
		
		if (obj.type != 1){
			icon.image =BASE_PATH+ "images/markers/red.png";
			icon.shadow = BASE_PATH+ "images/markers/red_shadow.png";
			icon.iconSize=new GSize(35,38);
			icon.shadowSize = new GSize(55, 38);
			icon.iconAnchor = new GPoint(16, 38);
			icon.infoWindowAnchor = new GPoint(8, 1);
		} else if(ct_act<=20){
			icon.image =BASE_PATH+ "images/markers/green_small.gif";
			icon.shadow = BASE_PATH+ "images/markers/green_small_shadow.png";			
			icon.iconSize=new GSize(23,25);
			icon.shadowSize = new GSize(36, 25);
			icon.iconAnchor = new GPoint(16, 25);
			icon.infoWindowAnchor = new GPoint(5, 1);
		} else if(ct_act<=40){
			icon.image =BASE_PATH+ "images/markers/green_mid.gif";
			icon.shadow = BASE_PATH+ "images/markers/green_mid_shadow.png";
			icon.iconSize=new GSize(28,30);
			icon.shadowSize = new GSize(44, 30);
			icon.iconAnchor = new GPoint(16, 30);
			icon.infoWindowAnchor = new GPoint(8, 1);
		} else if(ct_act<=60){
			icon.image =BASE_PATH+ "images/markers/green.png";
			icon.shadow = BASE_PATH+ "images/markers/green_shadow.png";
			icon.iconSize=new GSize(32,38);
			icon.shadowSize = new GSize(55, 38);
			icon.iconAnchor = new GPoint(16, 38);
			icon.infoWindowAnchor = new GPoint(8, 1);
		}
		
		 var marker = new GMarker(point,{ icon: icon });
		 marker.id =obj.id;
		 //
	     var TABS = [];
	      if(obj.type == 1){          
	           TABS = ["About","Advice","Activities"];
	      } else if(obj.type == 2){
	    	  TABS = ["Contact","About Us","Products"];	        
	      } else if(obj.type == 3){
	    	  TABS = ["Contact","About Us"];	
	      }
	     // var infoTabs=createHTML(TABS,obj);
		 marker.value = obj.message;
		 var info = userInfo(TABS, obj);
		 /*
			 if(oParameter.is_return=='0'){
				  GEvent.addListener(marker, "click", function() {map.openInfoWindowTabsHtml(point, infoTabs);});
				  map.addOverlay(marker)
			 }else{
		 			map.openInfoWindowTabsHtml(point, infoTabs);
					return marker;
			 }
		*/
		 if (DBG){
			 //GEvent.addListener(marker, "click_action", function() { show_custom_info_window(info); });
		 }
		 GEvent.addListener(marker, "click", function() {map.openInfoWindowTabsHtml(point, info);});
		 map.addOverlay(marker);
		 CFG.points[obj.id] = obj.id;
		 
		 if (obj.featured) map.openInfoWindowTabsHtml(point, info);
	},
	
	createMarker: function (point,oParameter){
	      if(oParameter.type && oParameter.sel_activities >=0 &&  oParameter.sel_activities<=20){
			var icon = new GIcon();
			icon.image =BASE_PATH+ "images/markers/green_small.gif";
			icon.shadow = BASE_PATH+ "images/markers/green_small_shadow.png";
			
			icon.iconSize=new GSize(23,25);
			icon.shadowSize = new GSize(36, 25);
			icon.iconAnchor = new GPoint(16, 25);
			icon.infoWindowAnchor = new GPoint(5, 1);
			oParameter.tree_name='TWIG-branch-tree';
          }else  if(oParameter.type && oParameter.sel_activities >=21 &&  oParameter.sel_activities<= 40){
			var icon = new GIcon();
			icon.image =BASE_PATH+ "images/markers/green_mid.gif";
			icon.shadow = BASE_PATH+ "images/markers/green_mid_shadow.png";
			icon.iconSize=new GSize(28,30);
			icon.shadowSize = new GSize(44, 30);
			icon.iconAnchor = new GPoint(16, 30);
			icon.infoWindowAnchor = new GPoint(8, 1);
			
			oParameter.tree_name='twig-BRANCH-treee';
          } else if(oParameter.type && oParameter.sel_activities >=41 && oParameter.sel_activities<=60){
			var icon = new GIcon();
			icon.image =BASE_PATH+ "images/markers/green.png";
			icon.shadow = BASE_PATH+ "images/markers/green_shadow.png";
			icon.iconSize=new GSize(32,38);
			icon.shadowSize = new GSize(55, 38);
			icon.iconAnchor = new GPoint(16, 38);
			icon.infoWindowAnchor = new GPoint(8, 1);
			oParameter.tree_name='twig-branch-TREE';
          } else {
        	  var icon = new GIcon();
      			icon.image =BASE_PATH+ "images/markers/green.png";
      			icon.shadow = BASE_PATH+ "images/markers/green_shadow.png";
      			icon.iconSize=new GSize(32,38);
      			icon.shadowSize = new GSize(55, 38);
      			icon.iconAnchor = new GPoint(16, 38);
      			icon.infoWindowAnchor = new GPoint(8, 1);
      			oParameter.tree_name='twig-branch-TREE';
          }
		  
        if(oParameter.type==2){
         var icon = new GIcon();
			icon.image =BASE_PATH+ "images/markers/red.png";
			icon.shadow = BASE_PATH+ "images/markers/red_shadow.png";
			icon.iconSize=new GSize(35,38);
			icon.shadowSize = new GSize(55, 38);
			icon.iconAnchor = new GPoint(16, 38);
			icon.infoWindowAnchor = new GPoint(8, 1);
        }
		if(oParameter.type==3){
         var icon = new GIcon();
			icon.image =BASE_PATH+ "images/markers/red.png";
			icon.shadow = BASE_PATH+ "images/markers/red_shadow.png";
			icon.iconSize=new GSize(35,38);
			icon.shadowSize = new GSize(55, 38);
			icon.iconAnchor = new GPoint(16, 38);
			icon.infoWindowAnchor = new GPoint(8, 1);
        }
	  var marker = new GMarker(point,{ icon: icon });
	  marker.id =oParameter.user_id;
      var TAB_TITLE={};
      if(oParameter.type==1){           // that is individual account.
           TAB_TITLE={
             tab1_title:"About",
             tab2_title:"Advice",
             tab3_title:"Activities"
           };
      }else if(oParameter.type==2){
        TAB_TITLE={
          tab1_title:"Contact",
          tab2_title:"About Us",
          tab3_title:"Products"
        };
      }else if(oParameter.type==3){
        TAB_TITLE={
             tab1_title:"Contact",
             tab2_title:"About Us"
        };
      }
     var infoTabs=createHTML(TAB_TITLE,oParameter);
	 marker.value = oParameter.message;
		 if(oParameter.is_return=='0'){
			  GEvent.addListener(marker, "click", function() {map.openInfoWindowTabsHtml(point, infoTabs);});
			  map.addOverlay(marker)
		 }else{
	 			map.openInfoWindowTabsHtml(point, infoTabs);
				return marker;
		 }

	 }
 }

function html_actList(arr, obj){
	var html = '<h3>'+obj.linkname+'</h3>';
	
	var ct = arr.length;
	var curcat = '';
	
	html += '<h3>'+ct+' of 60 Activities</h3>';	
	html += '<ul class="invis">';
	
	if (ct > 0){
		for(a=0;a<arr.length;a++){
			var nn = arr[a];			
			var act = CFG.activity[nn];
			if (act.category != curcat){
				html += '</ul><h4>'+act.category+'</h4><ul class="activities">';
				curcat = act.category;
			}
			if (act) html += '<li><p>'+act.name+'</p></li>';
		}
		html += '</ul>';
	}
	return html;
}

function show_custom_info_window(marker){	
	map_point = map.fromLatLngToDivPixel(marker.getPoint());
	
	if (!pointshown || !$('#overlay')){ 
		var new_obj = document.createElement("div");
		new_obj.style.display = 'none';
		new_obj.innerHTML = $('#overlay_seed').html();
		new_obj.id = 'overlay';	
		
		var pane = map.getPane(G_MAP_MARKER_PANE);	
		$(pane).append(new_obj);
		
		$('#overlay div.inside').attr('id','overlay_info');		
		pointshown = true;
	}
	
	var my_window = $('#overlay');
	var winsel = '#overlay';
	
	// Attach the marker
	my_window.marker = marker;
	selected_marker = marker;	
	
	// Populate content
	var my_tab = $('#overlay_info');
	my_tab.html(marker.info.address);
	$(my_window).css('display','block');
	
	if (map.getZoom() < mcfg.dfzoom) map.setZoom(mcfg.dfzoom);
	var pan_to = new GLatLng( marker.getPoint().lat(), marker.getPoint().lng() )
	map.panTo( pan_to);	
	
	position_window(my_window, marker);	
}

function close_window(){
	$('#overlay').css('display','none');
	//deactivate_marker( $("#location_"+$('#overlay').marker.iid) );
	deactivate_marker(selected_location);
	return false;
}
		
function position_window(my_window, marker){	
	var map_point = map.fromLatLngToDivPixel(marker.getPoint());
		
	var wh = parseInt(map_point.y) - $(my_window).height()-15;
	$(my_window).css('top',wh + "px");
	
	var horiz_loc = parseInt(map_point.x) - 67;
	$(my_window).css('left',horiz_loc + "px");
	
	$(my_window).css('z-index',99999);	
} 

function userInfo(tabs,obj){
	 var about_html='<table border="0" cellspacing="1" cellpadding="1" width="500"><tr>';
	 var uid = obj['id'];
	  
	  if(obj.photo_name){
		about_html=about_html + '<td  valign="top" width="100"><img src="'+ROOT_URL+obj.photo_name+'" border="1" width="90" ></td><td valign="top" align="left">';
	  }else{
		about_html=about_html + '<td valign="top" colspan="2">';
	  }		  
	  
	  about_html += '<b>'+obj.username+'</b><br/>'+ obj.message +'</td></tr>';
	  //<tr><td valign="top"><b>'+obj.tree_name+'</b></td> <td>&nbsp;</td></tr></table>';
	  if (CFG.islogged) about_html += '<tr ><td valign="top" colspan="2"><br/><a href="user/'+obj.user_id+'">Click here</a> to add '+obj.username+' as a friend or leave a comment</td> <td>&nbsp;</td></tr>';
	  else about_html += '<tr><td valign="top" colspan="2"><br/><a href="register" onclick="ajaxURL(this);return false">Register now to view full profile</a></td></tr>';
	  about_html += '</table>';

	if(obj.type == 1){	
		obj.linkname = obj.username;
	} else{	
		var cname = (obj.type == 2) ? 'Company' : 'Organization';
		obj.linkname = obj.real_name;
	
		 var contact_html='<table width="500">';
		 contact_html += '<tr><th><b>'+cname+':</b></th><td><a href="user/'+obj.user_id+'">'+obj.real_name+'</a></td><td>&nbsp;</td></tr>';		 
		 contact_html += '<tr><th><b>Street Address:</b></th><td>'+ obj.street +'</td><td>&nbsp;</td></tr>';
		 contact_html += '<tr><th><b>City:</b></th><td>'+ obj.city + '</td><td>&nbsp;</td></tr>';
		 contact_html += '<tr><th><b>State/Region:</b></th><td>'+obj.state+'</td><td>&nbsp;</td></tr>';
		 contact_html += '<tr><th><b>Postal Code:</b></th><td>'+obj.postal_code +'</td><td>&nbsp;</td></tr>';
		 contact_html += '<tr><th><b>Phone:</b></th><td>'+obj.telephone_no +'</td><td>&nbsp;</td></tr>';
			
		 if(obj.website) 	contact_html += '<tr><th><b>Website:</b></th><td><a href="'+obj.website+'" target="_blank">'+obj.website+'</a></td><td>&nbsp;</td></tr>';
		 if(obj.email)		contact_html += '<tr><td><b>Email:</b></td><td>'+obj.email +'</td><td>&nbsp;</td></tr>';
		 	 
		 if (obj.logo_name) contact_html += '<a href="'+obj.website+'" target="_blank"><img class="popup_logo" align="right" src="'+ROOT_URL+obj.logo_name+'" /></a>';
	}
	if (obj.advice) var advice_html='<table border="0" cellspacing="1" cellpadding="1" width="500"><tr><td><b>'+obj.linkname+'</b></td></tr><tr><td valign="top" align="left">'+obj.advice+'</td></tr></table>';
    if (obj.acts) var act_html= '<div style="overflow:auto;height:300px;width:500px">'+html_actList(obj.acts,obj)+'</div>';    
    contact_html += '</table>';
    
  if (CFG.islogged) contact_html += '<br/><p><a href="user/'+uid+'">Click here</a> to add '+obj.linkname+' as a friend or leave a comment</p>';
	else contact_html += '<br/><p><a href="user/'+uid+'">View '+cname+' Profile</a></p>';
	contact_html += '</div>';		
	advice_html = '<div style="overflow:auto;width:500px">'+advice_html+'</div>';

	
    var infoTabs = Array ();
     if(obj.type==1){
        infoTabs.push(new GInfoWindowTab(tabs[0],about_html));
        if(obj.advice) infoTabs.push(new GInfoWindowTab(tabs[1], advice_html));
        if(act_html) infoTabs.push(new GInfoWindowTab(tabs[2], act_html));
     } else if(obj.type == 2){
  		 // var advice_html='<div style="overflow:auto;height:200px;"><table border="0" cellspacing="1" cellpadding="1"><tr><td><b>'+obj.company_link +'</b></td></tr><tr><td valign="top" align="left" >'+obj.message+'</td></tr></table></div>';
    	 var about_html='<table width="500" border="0" cellspacing="1" cellpadding="1"><tr><td><b><a href="user/'+uid+'">'+obj.real_name+'</a></b></td></tr>';
		  about_html +=  '<tr><td>'+obj.message +'</td></tr></table>';
		  infoTabs.push(new GInfoWindowTab(tabs[0],contact_html));
		  infoTabs.push(new GInfoWindowTab(tabs[1], about_html));
     } else if(obj.type==3){
    	 var about_html='<table width="500" border="0" cellspacing="1" cellpadding="1"><tr><td><b><a href="user/'+uid+'">'+obj.real_name+'</a></b></td></tr>';
		  about_html +=  '<tr><td>'+obj.message +'</td></tr></table>';		   
		  infoTabs.push(new GInfoWindowTab(tabs[0],contact_html));
		  infoTabs.push(new GInfoWindowTab(tabs[1], about_html));		 
	   }
	   
 infoTabs.onCloseFn = function(){  CFG.tabOpen = false;alert('close'); };		   
 CFG.tabOpen = true;
return infoTabs;
}
 
 
function createHTML(TAB_TITLE,oData){	
		  var about_html='<table border="0" cellspacing="1" cellpadding="1" width="500"><tr>';
		  
		  if(oData.aboutimage !=''){
			about_html=about_html + '<td  valign="top" width="100"><img src="'+oData.aboutimage+'" border="1" width="90" ></td><td valign="top" align="left">';
		  }else{
			about_html=about_html + '<td valign="top" colspan="2">';
		  }		  
		  
		  about_html += '<b>'+oData.username+'</b><br/>'+ oData.message +'</td></tr>';
		  //<tr><td valign="top"><b>'+oData.tree_name+'</b></td> <td>&nbsp;</td></tr></table>';
		  if (CFG.islogged) about_html += '<tr ><td valign="top" colspan="2"><br/><a href="user/'+oData.user_id+'">Click here</a> to add '+oData.username+' as a friend or leave a comment</td> <td>&nbsp;</td></tr>';
		  else about_html += '<tr><td valign="top" colspan="2"><br/><a href="register" onclick="ajaxURL(this);return false">Register now to view full profile</a></td></tr>';
		  about_html += '</table>';

	if(oData.type==1){	
		  var contact_html='<div style="position:relative"><table><tr><td>'+oData.photo_name +'</td><td>'+oData.username+'</td><td>&nbsp;</td></tr><tr><td><b>Street Address:</b></td><td>'+ oData.street +','+oData.country + oData.state_province+'</td><td>&nbsp;</td></tr><tr><td><b>Postal Code:</b></td><td>'+oData.postal_code +'</td><td>&nbsp;</td></tr><tr><td><b>Phone Number:</b></td><td>'+oData.telephone_no +'</td><td>&nbsp;</td></tr></table>';
		  var linkname = oData.username;
	} else{	
		var cname = (oData.type == 2) ? 'Company' : 'Organization';
		var linkname = oData.real_name;
	
		if(oData.aboutimage!=''){
			about_html=about_html + '<td  valign="top" width="100px;"><img src="'+oData.aboutimage+'" border="1" width="100" height="80"></td><td valign="top" align="left">';
		 }else{
			about_html=about_html + '<td valign="top" width="100px;" colspan="2">';
		 }

		 var contact_html='<table width="500">';
		 if(oData.aboutimage!=''){
			contact_html=contact_html + '<tr><td  valign="top" width="100px;"><img src="'+oData.aboutimage+'" border="1" width="100" height="80"></td><td>&nbsp;</td><td>&nbsp;</td></tr>';
		 }
		 contact_html += '<tr><th><b>'+cname+':</b></th><td><a href="user/'+oData.user_id+'">'+oData.real_name+'</a></td><td>&nbsp;</td></tr>';		 
		 contact_html += '<tr><th><b>Street Address:</b></th><td>'+ oData.street +'</td><td>&nbsp;</td></tr>';
		 contact_html += '<tr><th><b>City:</b></th><td>'+ oData.city + '</td><td>&nbsp;</td></tr>';
		 contact_html += '<tr><th><b>State/Region:</b></th><td>'+oData.state_province+'</td><td>&nbsp;</td></tr>';
		 contact_html += '<tr><th><b>Postal Code:</b></th><td>'+oData.postal_code +'</td><td>&nbsp;</td></tr>';
		 contact_html += '<tr><th><b>Phone:</b></th><td>'+oData.telephone_no +'</td><td>&nbsp;</td></tr>';
			
		 if(cname == 'Company' && oData.amount>=39.5){			
		 	contact_html=contact_html+'<tr><th><b>Website:</b></th><td><a href="'+oData.website+'" target="_blank">'+oData.website+'</a></td><td>&nbsp;</td></tr><tr><td><b>Email:</b></td><td>'+oData.email +'</td><td>&nbsp;</td></tr></table>';
			contact_html += '<a href="'+oData.website+'" target="_blank"><img width="200" class="popup_logo" align="right" src="'+ROOT_URL+'logoimg/'+oData.user_id+'.jpg" /></a>';
		 } else if(oData.amount == 20 && cname == 'Organization'){			
			 contact_html=contact_html+'<tr><th><b>Website:</b></th><td><a href="'+oData.website+'" target="_blank">'+oData.website+'</a></td><td>&nbsp;</td></tr><tr><td><b>Email:</b></td><td>'+oData.email +'</td><td>&nbsp;</td></tr></table>';
			 contact_html += '<a href="'+oData.website+'" target="_blank"><img class="popup_logo" align="right" src="'+ROOT_URL+'logoimg/'+oData.user_id+'.jpg" /></a>';
		}
	}
		  var advice_html='<table border="0" cellspacing="1" cellpadding="1" width="500"><tr><td><b>'+linkname+'</b></td></tr><tr><td valign="top" align="left">'+oData.advice+'</td></tr></table>';
          var tab_3html= '<div style="overflow:auto;height:200px;width:500px">'+oData.activity_html+'</div>';
		
          
       contact_html += '</table>';
          
        if (CFG.islogged) contact_html += '<br/><p><a href="user/'+oData.user_id+'">Click here</a> to add '+linkname+' as a friend or leave a comment</p>';
  		else contact_html += '<br/><p><a href="user/'+oData.user_id+'">View '+cname+' Profile</a></p>';
		contact_html += '</div>';		
		advice_html = '<div style="overflow:auto;height:200px;width:500px">'+advice_html+'</div>';

          var infoTabs = Array ();
           if(oData.type==1){

              infoTabs.push(new GInfoWindowTab(TAB_TITLE.tab1_title,about_html));
              if(oData.advice!="none" ){
                  infoTabs.push(new GInfoWindowTab(TAB_TITLE.tab2_title, advice_html));
              }
			  if(oData.activity_html!=""){
	              infoTabs.push(new GInfoWindowTab(TAB_TITLE.tab3_title, tab_3html));
			  }

           }else if(oData.type == 2){
	   		 // var advice_html='<div style="overflow:auto;height:200px;"><table border="0" cellspacing="1" cellpadding="1"><tr><td><b>'+oData.company_link +'</b></td></tr><tr><td valign="top" align="left" >'+oData.message+'</td></tr></table></div>';
        	  var about_html='<table width="500" border="0" cellspacing="1" cellpadding="1"><tr><td><b><a href="user/'+oData.user_id+'">'+oData.real_name+'</a></b></td></tr>';
			  about_html +=  '<tr><td>'+oData.message +'</td></tr></table>';
              infoTabs.push(new GInfoWindowTab(TAB_TITLE.tab1_title,contact_html));
			  infoTabs.push(new GInfoWindowTab(TAB_TITLE.tab2_title, about_html));
			  
			  /*			  
              if(oData.advice!=""){
                  infoTabs.push(new GInfoWindowTab(TAB_TITLE.tab2_title, advice_html));
              }
			   
			  if(oData.activity_html!=""){
	              infoTabs.push(new GInfoWindowTab(TAB_TITLE.tab3_title, tab_3html));
			  }
			  */
			  
             // infoTabs.push(new GInfoWindowTab(TAB_TITLE.tab3_title, tab_3html));

           }else if(oData.type==3){
        	  var about_html='<table width="500" border="0" cellspacing="1" cellpadding="1"><tr><td><b><a href="user/'+oData.user_id+'">'+oData.real_name+'</a></b></td></tr>';
 			  about_html +=  '<tr><td>'+oData.message +'</td></tr></table>';
			   
              infoTabs.push(new GInfoWindowTab(TAB_TITLE.tab1_title,contact_html));
		      infoTabs.push(new GInfoWindowTab(TAB_TITLE.tab2_title,about_html));
			 
			  //tab_3html="<h1>Pending.. work in progress...</h1>"
              //infoTabs.push(new GInfoWindowTab(TAB_TITLE.tab1_title,about_html));
              //infoTabs.push(new GInfoWindowTab(TAB_TITLE.tab3_title, tab_3html));
          
		   }
		   
	  infoTabs.onCloseFn = function(){  CFG.tabOpen = false;alert('close'); };		   
	  CFG.tabOpen = true;
      return infoTabs;
 }

//that function will be use for set zoom to location.
function hideBar(){
	$("#search_content").slideToggle();
}
function closeBar(){
	CONTROL.hide();
}
function showData(user_id){
	var search_type=$("#current_selected_search_type").val();
	textsearch(user_id,search_type);
}

function _makeaddress(city,state,country){
	var address = '';
	if (city == 'Type a city or Postal Code') city = '';
	if (state == 'Select State/Region') state = '';
	if (Number(city && !state) > 0) return city+', '+country;
	
	if (city != '' && state != '') address = city+', '+state;
	else if (city != '' || state != '') address = city+state+',';
	address += ' '+country;	
	return address;	
}

function normalsearch(){
//	CONTROL.hide();
	var country_name=document.getElementById("Country").options[document.getElementById("Country").selectedIndex].text;
	var state_name=document.getElementById("state_id").options[document.getElementById("state_id").selectedIndex].text;
	var city_name=$("#suggest").val();
	var geocoder = new GClientGeocoder();
	var zoomlevel=13;
	var address="";
	
	address = _makeaddress(city_name,state_name,country_name);
	
	if (DBG) {
		alert(address);
		var data = new Object();
		data.country = country_name;
		data.zone = state_name;
		data.city = city_name;
		$.post(BASE_PATH + "home/json_search",data, initmap, 'json'); 
	}
	
	
	
	geocoder.getLocations(address, function(response){
				if (!response || response.Status.code != 200) {
					address=state_name +", " + country_name;
						geocoder.getLocations(address,function(response){
							if (!response || response.Status.code != 200) {
								alert("Sorry, we were unable to geocode that address");
							}else{
								zoomlevel=7;
								place = response.Placemark[0];
								map.setCenter(new GLatLng(place.Point.coordinates[1],place.Point.coordinates[0]), zoomlevel);
								var html="<div align='center'><h3> "+address+"<h3></div>";
								map.openInfoWindow(map.getCenter(),html);
							}
						});
						
					}else{
						place = response.Placemark[0];
						map.setCenter(new GLatLng(place.Point.coordinates[1],place.Point.coordinates[0]), zoomlevel);
						var html="<div align='center'><h3> "+address+"<h3></div>";
						map.openInfoWindow(map.getCenter(),html);
					}
				});
	
}
/* search marker to database in both condition advance and normal.*/
function textsearch(user_id,search_type){ // search type show, search is normal or advance.
//basic requierment for normal search.	
	
	var keyword=$("#suggest").val();
	var country_id=$("#Country").val();
	var state_id=$("#state_id").val();
	var city_name=$("#suggest").val();
	$("#current_selected_search_type").val(search_type);
    var oData={}; // object for holding marker data.
	var links=""; // concating.. 
	var url= BASE_PATH + "home/xml_markers";
	if(search_type=="") search_type="normal";
	var send_data= "keyword="+keyword+"&country_id="+country_id+"&state_id="+state_id+"&user_id="+user_id+"&search_type="+search_type; // request sent lists of params.
	
//if search not found recored into datbase.. then use text for geocode.
	var country_name=document.getElementById("Country").options[document.getElementById("Country").selectedIndex].text;
	var state_name=document.getElementById("state_id").options[document.getElementById("state_id").selectedIndex].text;
	
	//require keyword
	if (keyword == 'Type a Search Term' || keyword == ''){
		alert('Please enter a keyword to search for');
		return;
	}
	
//start logic.
	if(user_id==0){
	 if (CONTROL) {
	 	CONTROL.setContent("<div id='search_inner' style='color:red;text-align:center;padding:5px;'>Loading...!</div>");
	 	CONTROL.show();
	 }
		
	}
	
	if(search_type=="advance"){ // if search is advance then change parameter
	 country_name=document.getElementById("advance_Country").options[document.getElementById("advance_Country").selectedIndex].text;
	 state_name=document.getElementById("advance_state_id").options[document.getElementById("advance_state_id").selectedIndex].text;
		keyword=$("#advance_keyword").val();
		country_id=$("#advance_Country").val();
		state_id=$("#advance_state_id").val();
		
		city_name=$("#txtpostal_code").val();
		miles=$("#txt_miles").val()
		send_data= "keyword="+keyword+"&country_id="+country_id+"&state_id="+state_id+"&user_id="+user_id+"&city="+city_name+"&search_type="+search_type+"&miles="+miles;
	}
	var geocoder = new GClientGeocoder();
		
	
	//zipcode hack
	if (Number(city_name) > 0) address = city_name;
	else address=city_name + " " +state_name +", "+country_name;
	
		
	geocoder.getLocations(address,function(response){
					if (!response || response.Status.code != 200) {
						alert("Sorry, we were unable to geocode that address");
					}else{
						zoomlevel=7;
						place = response.Placemark[0];
						var lat=place.Point.coordinates[1];
						var long=place.Point.coordinates[0];
						send_data=send_data+ "&lat="+lat+"&long="+long;
						// end search. parameter setting.
						$.ajax({
							type: "POST",
							url:url,
							data:send_data,
							dataType: "xml",
							complete: function(data,status){
								SIPL.DG.XHR_Status=status;
								retResponse=data.responseXML;
									var xmlDoc = retResponse;
									var mem=xmlDoc.documentElement.getElementsByTagName("member");
									var aboutImage=xmlDoc.documentElement.getElementsByTagName("about");
									var points = xmlDoc.documentElement.getElementsByTagName("point");
									var icon= xmlDoc.documentElement.getElementsByTagName("about");
									var header="Results "+ points.length +" for "+ keyword;
								   // var info= xmlDoc.documentElement.getElementsByTagName("info");
									for (var i = 0; i < points.length; i++) {
											var point = new GLatLng(points[i].getAttribute("lat"),points[i].getAttribute("lng"));
											var ab_image=aboutImage[i].getAttribute("image");
											var msg= GXml.value(mem[i].getElementsByTagName("message")[0]);
											var advice= GXml.value(mem[i].getElementsByTagName("advice")[0]);
											var selactivities=GXml.value(mem[i].getElementsByTagName("selactivities")[0]);
											var type=GXml.value(mem[i].getElementsByTagName("type")[0]);
											var activity_html=GXml.value(mem[i].getElementsByTagName("activity_html")[0]);
											var username=GXml.value(mem[i].getElementsByTagName("username")[0]);
											var visible=GXml.value(mem[i].getElementsByTagName("visible")[0]);
											var city=GXml.value(mem[i].getElementsByTagName("city")[0]);
											var country=GXml.value(mem[i].getElementsByTagName("country")[0]);
											var street=GXml.value(mem[i].getElementsByTagName("street")[0]);
											var state_province=GXml.value(mem[i].getElementsByTagName("state_province")[0]);
											var postal_code=GXml.value(mem[i].getElementsByTagName("postal_code")[0]);
											var telephone_no=GXml.value(mem[i].getElementsByTagName("telephone_no")[0]);
											var photo_name=GXml.value(mem[i].getElementsByTagName("photo_name")[0]);
											var real_name=GXml.value(mem[i].getElementsByTagName("real_name")[0]);
											var user_id=GXml.value(mem[i].getElementsByTagName("user_id")[0]); 
											var username_withoutlink=GXml.value(mem[i].getElementsByTagName("username_withoutlink")[0]); 
											oData={
												lat:points[i].getAttribute("lat"),
												lng:points[i].getAttribute("lng"),
												type:type,
												sel_activities:selactivities,
												message:msg,
												advice:advice,
												activity_html:activity_html,
												aboutimage:ab_image,
												username:username,
												username_withoutlink:username_withoutlink,
												country:country,
												visible:visible,
												city:city,
												street:street,
												state_province:state_province,
												postal_code:postal_code,
												telephone_no:telephone_no,
												photo_name:photo_name,
												real_name:real_name,
												tree_name:'',
												user_id:user_id
											};
											if(links==""){
												links=  "<a href='#' onClick='showData(\""+ user_id +"\");'>["+ username_withoutlink + "] " +street + " " +postal_code +"</a><br/>";
											}else{
												links+="<a href='#' onClick='showData(\""+ user_id +"\");'>["+ username_withoutlink + "] " +street + " " +postal_code +"</a><br/>";
											}
										} 
										
									if(points.length<=0){
										var geocoder = new GClientGeocoder();
										var zoomlevel=13;
										var address="";
											if(city_name !="")
												address=city_name +" ";
											if(state_name !=""){
												address=address + state_name +", ";
												zoomlevel=13
											}
											if(country_name !="")
											address=address + country_name;
									
										geocoder.getLocations(address, function(response){
										if (!response || response.Status.code != 200) {
											address=state_name +", " + country_name;
												geocoder.getLocations(address,function(response){
													if (!response || response.Status.code != 200) {
														alert("Sorry, we were unable to geocode that address");
													}else{
														zoomlevel=7;
														place = response.Placemark[0];
														map.setCenter(new GLatLng(place.Point.coordinates[1],place.Point.coordinates[0]), zoomlevel);
														var html="<div align='center'><h3> "+address+"<h3></div>";
														map.openInfoWindow(map.getCenter(),html);
													}
												});
												
											}else{
												place = response.Placemark[0];
												map.setCenter(new GLatLng(place.Point.coordinates[1],place.Point.coordinates[0]), zoomlevel);
												var html="<div align='center'><h3> "+address+"<h3></div>";
												map.openInfoWindow(map.getCenter(),html);
											}
										});
										 if (CONTROL){
										 	CONTROL.setContent("<div id='search_inner' style='color:red;text-align=:center;padding:5px;'>Your search doesn\'t match our records, please try again.</div>");
										 	CONTROL.show();
										 }
									}else if(points.length==1){
										//CONTROL.hide();
										SIPL.MAP.createMarker(point,oData);
										map.setCenter(new GLatLng(points[0].getAttribute("lat"),points[0].getAttribute("lng")), 10);
												  
					
									 }else{
										 var text=header;
										 text=header.links;
										 CONTROL.setContent("<div id='search_inner'>Advanced Search Results - <a href='#' onClick='hideBar();'>Collapse/Expand </a>  <a href='#' onClick='closeBar();'> [x]</a></div><div id='search_content'>"+links+"</div>");
										
										 CONTROL.show();
									 }
									
									
							}
						});
					}
	});
		
}