// 按照FLAG判断替换STR中那部分的指定字符串
  function trim(Str , Flag){
		Str	= ""+Str;
		if( Flag == "l" || Flag == "L" )/*trim left side only*/
		{
			RegularExp	= /^\s+/gi;
			return Str.replace( RegularExp,"" );
		}
		else if( Flag == "r" || Flag == "R" )/*trim right side only*/
		{
			RegularExp	= /\s+$/gi;
			return Str.replace( RegularExp,"" );
		}
		else/*defautly, trim both left and right side*/
		{
			RegularExp	= /^\s+|\s+$/gi;
			return Str.replace( RegularExp,"" );
		}
       }
//判断str是否为空
 function notBlank(str) {
  return str!=null && trim(str)!="";	
}
//通过label在地图上显示已经标注过的点
function enterperisemaplabel(label) {

	var markerOption = new MMarkerOptions();
		var tipOption = new MTipOptions(); 
		tipOption.tipType=HTML_BUBBLE_TIP;    
		tipOption.title="";   
		tipOption.content=this.getMTipOptionsContent(label);//tip内容
		tipOption.tipHeight="180px";
		markerOption.tipOption = tipOption;  
		markerOption.canShowTip= true;
		markerOption.isEditable = false;
		
		if (label.label && !/^\s*$/.test(label.label)) {
			var urlpic = label.label.split("|");
			markerOption.imageUrl=urlpic[0];
			markerOption.imageSize = new MSize(urlpic[1], urlpic[2]);
		} else {
		  var tempimp = new Image();
		  tempimp.src="/manager/images/map/map_tb1.gif";
		  if(tempimp.width==0 || tempimp.height==0) markerOption.imageSize = new MSize(12, 12);
		  
			markerOption.imageUrl="/manager/images/map/map_tb1.gif";
		}
		Mmarker = new MMarker(new MLngLat(label.longitude/100000,label.latitude/100000),markerOption);
		Mmarker.id=label.id;    
		frontMap.addOverlay(Mmarker,true); 
		//this.maps.addEventListener(Mmarker,MOUSE_OVER,this.mouseOver);  
		frontMap.addEventListener(Mmarker,MOUSE_OVER,function(e){frontMap.openOverlayTip(e.overlayId);});
	//	frontMap.setOverlayEditableById(Mmarker.id,false);
}
//通过label在地图上显示已经标注过的点
function enterperisemapguide(label) {

		var markerOption = new MMarkerOptions();
		var tipOption = new MTipOptions(); 
		tipOption.tipType=HTML_BUBBLE_TIP;    
		tipOption.title="";   
		tipOption.content=this.getGuideMTipOptionsContent(label);//tip内容
		tipOption.tipHeight="180px";
		markerOption.tipOption = tipOption;  
		markerOption.canShowTip= true;
		markerOption.isEditable = false;
		var tempimp = new Image();
		if (label.label && !/^\s*$/.test(label.label)) {
			var urlpic = label.label.split("|");
			markerOption.imageUrl=urlpic[0];
			markerOption.imageSize = new MSize(urlpic[1], urlpic[2]);
		} else {
		  tempimp.src="/manager/images/map/map_tb2_big.gif";
			markerOption.imageUrl= "/manager/images/map/map_tb2_big.gif";
			if(tempimp.width==0 || tempimp.height==0)markerOption.imageSize = new MSize(49, 31);
		}
		
		Mmarker = new MMarker(new MLngLat(label.longitude/100000,label.latitude/100000),markerOption);
		Mmarker.id=label.id;     
		frontMap.addOverlay(Mmarker,true); 
		frontMap.addEventListener(Mmarker,MOUSE_OVER,function(e){frontMap.openOverlayTip(e.overlayId);}); 
		//frontMap.setOverlayEditableById(Mmarker.id,false);
	
}
//通过HTML显示标注marker的label属性
function getMTipOptionsContent(label) { 
		var html = "<table>";
		html += generateInfo(i18n_FrontMap_show_map_label_corpname, label.corpname);
		html += generateInfo(i18n_FrontMap_show_map_label_address, label.address);
		html += generateInfo(i18n_FrontMap_show_map_label_liasion, label.liasion);
		html += generateInfo(i18n_FrontMap_show_map_label_phone, label.phone);
		html += generateInfo(i18n_FrontMap_show_map_label_fax, label.fax);
		html += generateInfo(i18n_FrontMap_show_map_label_zipcode, label.zipcode);
		html += generateInfo(i18n_FrontMap_show_map_label_website, label.website);
		html += generateInfo(i18n_FrontMap_show_map_label_description, label.description);
		html += "</table>";
		return html;
}

function specialCharConvert(nodeName){
	return nodeName.replace(/&#034;/g,"\"").replace(/&#039;/g,"\'");
}
//通过HTML显示标注marker的label属性
function getGuideMTipOptionsContent(label) { 
		var html = "<table>";
		html += generateInfo(i18n_FrontMap_show_map_label_name, label.name);
		html += generateInfo(i18n_FrontMap_show_map_label_description1, label.description);
		html += "</table>";
		return html;
} 
//显示name和str中的信息
function generateInfo(name, str) {
	str =specialCharConvert(str);
	if (str && !/^\s*$/.test(str)) {
		return "<tr><td style='width:60px'>" + name + ":</td><td style='word-break:break-all; word-wrap:break-word;'>" + str.replace(/</mg, "&lt;").replace(/>/mg, "&gt;") + "</td></tr>";
	}
	return "";
}

//通过longitude,latitude在地图上标注点
   function maplabel(longitude,latitude) {	
   	frontMap.panTo(new MLngLat(parseInt(longitude)/100000, parseInt(latitude)/100000));
  }
  
  
//通过longitude,latitude在地图上标注点
  function mapguide(longitude,latitude) {	
	 frontMap.panTo(new MLngLat(parseInt(longitude)/100000, parseInt(latitude)/100000)); 
  }
//切换城市地图。divid：包含地图组件的DIV。 targetname：目标城市名。 targetid：目标城市ID。
 function changeMapCity(divid,targetname,targetid) {
	//var oSelect = document.getElementById("mapCity");
	var oSelect = _getElementById(divid,targetname,targetid);
	var coll = oSelect.options;
	if (coll && coll.length>0) {
		for(i=0;i<coll.length;i++) {
			if (coll[i].selected) {
				var cityName = coll[i].value;
				frontMap.setCenter(new MLngLat(cityName.split(",")[0],cityName.split(",")[1]));
			}		
				
		}	
       }
 }
 
//初始化地图
  function end(longitude, latitude, scale) {
    if(longitude == null || longitude == '' || latitude == null || latitude == '' || scale == null || scale == '') {
	      longitude = 11639742;
	      latitude = 3990923;
	      scale = 7;
	   }
		frontMap.panTo(new MLngLat(parseInt(longitude)/100000, parseInt(latitude)/100000));
  }
