var UadTree;
var UadTreeRoot1;
var UadCategory;
var Uads = new Array();
var UadThread = 0;
var UpoiThread = 0;
var UadIcon;
var UadIconLife;	//花旗享樂生活的Icon
var UviewAd = false;
var Upois = new Array(); //基礎地標

var UpoiSource;
var UpoiType;
var listPageFlag = true;	//判斷是否要秀ListPage
var UadKeyWord;	//判斷是否有Key Word
var SelectedNode;

var popo_MapMove = true;	//泡泡造成地圖的移動
var UadSearchByAddr = false;	//地址搜尋列判斷式，是否要進adSearch
var imageFilePath = './imgs/customer_imgs/';
var citiBankUrlLink = 'http://citibank.urmap.com/citibank/';//'http://211.21.21.84/asp/citibank/';
function boxCallback(bounds) {
        var str = '最小緯度,最小經度,最大緯度,最大經度'+bounds.getSouthWest().lat();
	str += ','+bounds.getSouthWest().lng();
        str += ','+bounds.getNorthEast().lat();
        str += ','+bounds.getNorthEast().lng();
//        document.getElementById('message').innerHTML = str;
	alert(str);
}

function customInit() {
  // initialize tab content //
  UadTree = new treelist(U.gi('poiTreeListDiv'), poiTypeClick, false, 'tree.xml');
  UadTreeRoot0 = new treenode('紅利加速賺<img src="./imgs/hot.gif"/>', UadTree, true, 'citi;紅利加速賺','','',{treeItem:'treeItem',treeItemSelected:'treeItemSelected'});
  UadTreeRoot1 = new treenode('品味饗宴<img src="./imgs/hot.gif"/>', UadTree, true, 'citi;饗宴','','',{treeItem:'treeItem',treeItemSelected:'treeItemSelected'});
  //UadTreeRoot1 = new treenode('台灣優力加油優惠<img src="./imgs/new.gif"/>', UadTree, true, 'citi;台灣優力加油優惠','','',{treeItem:'treeItem',treeItemSelected:'treeItemSelected'});//0
  //setTimeout(function(){
  //    UadTreeRoot1 = new treenode('花旗享樂生活<img src="./imgs/new.gif"/>', UadTree, true, 'citi;花旗享樂生活','','',{treeItem:'treeItem2',treeItemSelected:'treeItem2Selected'});//0
  //},1000);
  // initialize tab pane //
  _Utabpane.addTab('poi', '特約商店', 'poiDiv', 0);
  //_Utabpane.changeTabLabel('list', '搜尋結果', 1);
  _Utabpane.addTab('ezGo', '優惠捷徑', 'citiEzGoDiv', 3);
  _Utabpane.selectTab('poi');
  //var banner = document.createElement('div');
  
  //U.gi('poiDiv').appendChild(banner);
  // initialize main function //
  if(U.gi('searchBtn'))
    U.gi('searchBtn').onclick = searchByKey;
  U.gi('forKeySearchForm').onsubmit = searchByKey;
  if(U.gi('closeAdBtn'))
  	U.gi('closeAdBtn').onclick = clearAllAdss;
  if(U.gi('citibankMsg'))
  	U.gi('citibankMsg').onclick = linkToCitiBankMsg;
  if(U.gi('citibankMsg2'))
  	U.gi('citibankMsg2').onclick = linkToCitiBankMsg;
  if(U.gi('teachLink'))
  	U.gi('teachLink').onclick = openTheTeach;
  
  // initialize event //
  _Umap.addListener('zoom', mapChange);
  _Umap.addListener('moveend', mapChange);
  _Umap.addListener('click', mapClick);
  _Umap.setBoxActionCallback(boxCallback);

  
  // initialize icon //
  UadIcon = new UIcon();
  //UadIcon.image = "./imgs/result.gif";	//7/14修改
  UadIcon.image = "./imgs/Citi-logo_mapList0714.jpg";
  UadIcon.iconWidth = 36;
  UadIcon.iconHeight = 28;
  UadIcon.iconAnchor = new UPoint(10, 10);
  UadIcon.infoWindowAnchor = new UPoint(10, 1);
  //花旗享樂生活
  UadIconLife = new UIcon();
  //UadIconLife.image = "./imgs/Usage_iconMap.gif";	//7/14修改
  UadIconLife.image = "./imgs/Citi-logo_mapList20x20-1.gif";
  UadIconLife.iconWidth = 20;
  UadIconLife.iconHeight = 20;
  UadIconLife.iconAnchor = new UPoint(10, 10);
  UadIconLife.infoWindowAnchor = new UPoint(10, 1);
  
  if(null != _link && '' != _link) {
	_decodeMap(_link);
	/*DWREngine.setAsync(false);
	SearchBean.decode(_link, getUrlLinkCallback);
	DWREngine.setAsync(true);*/
  } else {
	//var ll = new ULatLng(25.04, 121.55);
  	//_Umap.centerAndZoom(new ULatLng(25.04, 121.55), 9);
	//gotoCookieLocation();
  }
}

function adSearchCallback(xmlhttp) {
  //alert("press");
  clearAds();
  var doc = xmlhttp.responseText.trim();
  
  var ads = doc.split('；');	//；　＝＝＞全形
  //alert("ads="+ads);
  var html = '';
  var bounds = _Umap.getBounds();
  
  if(0 != doc.length) {
	  var chkLatLng = new Array(); //用來存放地標值，檢查是否有重覆
	  
	  var detail_list = '';
	  detail_list += '*分期門檻與期數，以及0手續費之商品，以特約商店公告為主<br>';
	  //放在泡泡中分期的logo	7/14 mark
	  //var logo = '<img src="imgs/EPP-logo.gif" />';
	  for(var i=0; i<ads.length; i++) {
		//alert(ads[i]);
		var data = ads[i].split('`');
		var citi_Id = data[16];	//店家ID
		var citiName = data[0];	//店名
		var cat = data[1];	//店家類別
		var address = data[2];	//住址
		
		var TEL1 = data[3];	//電話1	(測試用  記得改回來)
		var TEL2 = data[4];	//電話2
		var latestMsg = data[5];
		var alertMsgReg = /《[.]*》/ig;
		var reg_result = alertMsgReg.exec(latestMsg);
		var alertMsg = '';
//update 20100714 by BINGO start ↓↓
		if(reg_result){
			alertMsg = reg_result[0];
			latestMsg = latestMsg.replace(reg_result[0], "");
		}else{
  		  	var ss0 = latestMsg.indexOf('《');
  		  	var ss1 = latestMsg.indexOf('》'); 
  		  	alertMsg = latestMsg.substring(ss0+1, ss1);
  		  	latestMsg = latestMsg.replace('《'+alertMsg+'》', '');
}
		alertMsg = alertMsg.replace(/<\/?[^>]+>/gi, '');
//update 20100714 by BINGO end ↑↑
		var latestMsgByHtml = '<font color="#004287">'+latestMsg+'</font>';	//最新優惠<一串html語法>
		
		var imageFileName = data[6];	//圖檔名稱
		if(imageFileName==''){
		   imageFileName = 'popuBak2.jpg';
           //imageFileName = 'fed.gif';
		}
		var hyperlink = data[7];	//店家連結
		var actionlink = data[17]+ '';	//活動連結
		//alert("actionlink=="+actionlink);
		//var actionlink =  'http://www.citibank.com.tw/global_docs/chi/cc/epp_summer/index.htm';	//活動連結
		
		var flag = data[8];	//異動狀態
		
		var latitude = parseFloat(data[14]);	//y
		var lngitude = parseFloat(data[13]);	//x
		var stop_date = data[10];
		stop_date = stop_date.substring(0,10);
		stop_date = stop_date.replace(/-/g, "/");
		var is_over_date = false;

		if( stop_date ==='' ){//2010/5/18
			is_over_date = true;
		}
		else if ((Date.parse(stop_date)).valueOf() > (new Date()).valueOf()){
			is_over_date = true;
        }else {
			is_over_date = false;
        } 
		var _2_LatLng = new Array();
		//檢查坐標是否有重覆
		if(chkLatLng.length > 0) {
			for(var tmp_i=0;tmp_i<chkLatLng.length;tmp_i++) {
				var tmp_latitude = chkLatLng[tmp_i];
				var _1_Lat = parseFloat(tmp_latitude[0]);
				var _2_Lng = parseFloat(tmp_latitude[1]);
				
				if((_1_Lat == latitude) && (_2_Lng == lngitude)) {
					latitude = latitude + 10;
					lngitude = lngitude + 10;
					_2_LatLng[0] = latitude;
					_2_LatLng[1] = lngitude;
					//chkLatLng.push(_2_LatLng);
					tmp_i = 0;	//重新在與陣列中比對
					//continue;
				} else {
					_2_LatLng[0] = latitude;
					_2_LatLng[1] = lngitude;
					//chkLatLng.push(_2_LatLng);
				}
			}
			chkLatLng.push(_2_LatLng);
		} else {
			_2_LatLng[0] = latitude;
			_2_LatLng[1] = lngitude;
			chkLatLng.push(_2_LatLng);
		}
		//alert(citiName+'\n'+'y:'+latitude+'\tx:'+lngitude);
		//new ULatLng(parseFloat(location_y), parseFloat(location_x), U_TM2_COORDSYS);
		var latlng = new ULatLng(latitude, lngitude, U_TM2_COORDSYS);
		
		var _desc = '<table width="78%" border="0">';
		var title_Words = '';
		var _Column_add = 0;	//用於記錄資料  for 泡泡視窗
		var _Column_tel = 0;	//用於記錄資料  for 泡泡視窗
		var _Column_msg = 0;	//用於記錄資料  for 泡泡視窗
		var _Column_img = 0;	//用於記錄資料  for 泡泡視窗
		
		//分辨 花旗享樂生活 與其他地標
		var tmp_UadIcon;
		/*if('花旗享樂生活' == cat) {
			tmp_UadIcon = UadIcon;
		} else {
			tmp_UadIcon = UadIcon;
		}*/
		tmp_UadIcon = UadIcon;
		//alert(tmp_UadIcon.image);
		if(citiName) {
			title_Words += citiName;
			var _tmp_citiName = citiName;
			if('花旗享樂生活' == cat) {	//查詢結果 抬頭 第二行 跟第一行齊
				if(_tmp_citiName.indexOf('<br>') != -1) {
					_tmp_citiName = _tmp_citiName.replace('<br>','<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;');
				}
			}
			var tmp_Str = '';
			if(hyperlink) {
				if(hyperlink.indexOf('"') != -1) {	//過濾雙引號
					hyperlink = hyperlink.replace('"','');
				}
				tmp_Str = hyperlink;
				if(tmp_Str.indexOf('http://') == -1)
					tmp_Str = 'http://' + tmp_Str;
			}
			
			detail_list += '<table border="0"><tr><td>'
						+ '<a href="#" onmouseover="mouseOnShowMapData(\''+citiName+'\');" ';
			//如沒Link 則click 拿掉
			if('' != tmp_Str) {
				detail_list += ' onclick="javascript:{window.open(\''+tmp_Str+'\')};" ';
			}
			
			//動態抓取不同Icon的圖檔	height="36px" width="28px"
			detail_list += ' style="text-decoration:none"><img src="' + UadIconLife.image + '"  style="vertical-align: middle" /> &nbsp;'
					+ '<font color="#333333"><strong>' + _tmp_citiName + '</strong></font></a></td></tr>';
		}
		
		if('' != address) {
			_desc += '<tr><td colspan="4">' + ashWords(address) + '</td></tr>';
			
			detail_list += '<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' + ashWords(address) + '</td></tr>';
			_Column_add = 1;
		}
		
		if(TEL1 || TEL2) {
			_desc += '<tr><td colspan="4">';
			detail_list += '<tr><td>';
			if(TEL1) {
				_desc += ashWords(TEL1);
				detail_list += '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' + ashWords(TEL1);
			}
			
			if(TEL2) {
				_desc += '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' + ashWords(TEL2);
				detail_list += '<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' + ashWords(TEL2);
			}
			_desc += '</td></tr>';
			detail_list += '</td></tr>';
			_Column_tel = 1;
		}
		detail_list += '</table>';
		
		//_desc += '<tr>';//7/14 mark
		if(latestMsg && ('' != latestMsg.trim())) {
			_desc += '<tr><td colspan="2">' + latestMsgByHtml 
			_desc += '</td></tr>';
			_Column_msg = 1;
		}
		//_desc += '<td rowspan="2">' + logo + '</td>';	//7/14 mark
		//_desc += '</tr>';//7/14 mark
		
		_desc += '<tr>';
		//alert("imageFileName="+imageFileName);
		
		
		if(imageFileName && ('' != imageFileName.trim())) {
			_desc += '<td colspan="2" width="100px"><img src="'+(imageFilePath + imageFileName)+'" alt="" onerror="this.src=\''+imageFilePath+'Error_default.gif\'" />';
			_Column_img = 1;
			_desc += '</td>';
		} else {
			_desc += '<td colspan="3"><img src="'+(imageFilePath + imageFileName)+'/></td>';
		}
		
		_desc += '</tr>';
		_desc += '<tr><td colspan="4">';
		
		_desc += '<a href="javascript:void(0);" id="setStartLink">設為起點</a> | <a href="javascript:void(0);" id="setEndLink">設為終點</a>';
		
		//_desc += ' | <a href="javascript:void(0);" onclick="javascript:{clearUmapInfoWindow();};">關閉視窗</a>';
		if(hyperlink) {
		
			if(hyperlink.indexOf('http://') == -1)
				hyperlink = 'http://' + hyperlink;
			var store_info = '店家資訊';
			if('花旗享樂生活' == cat) {
				store_info = '活動詳情';
				_desc += ' | <a href="javascript:void(0);" onclick="javascript:{window.open(\''+hyperlink+'\')};">' + store_info + '</a>';
			}else if('台灣優力加油優惠' == cat){
                //活動詳情
				actionlink='http://www.citibank.com.tw/global_docs/chi/cc/rewards_upetrol/index.htm';
				_desc += ' | <a href="javascript:void(0);" onclick="javascript:{window.open(\''+actionlink+'\')};"> 活動詳情 </a>';
			    //店家資訊
				_desc += ' | <a href="javascript:void(0);" onclick="javascript:{window.open(\''+hyperlink+'\')};">' + store_info + '</a>';
			
			}else {
			    //alert("actionlink="+actionlink);
				//alert("latestMsg="+latestMsg);
				//if(actionlink.indexOf('http://') == -1)
				//	actionlink = 'http://' + actionlink;
				//一般的 活動詳情
				var action_str = '活動詳情';
				if(actionlink != "" && is_over_date){
				    //_desc += ' | <a href="javascript:void(0);" onclick="javascript:{window.open(\''+actionlink+'\')};">' + action_str + '</a>';
                    _desc += ' | <a href="javascript:void(0);" onclick="javascript:{window.open(\''+ 'http://' + actionlink+'\')};">' + action_str + '</a>';
				}
				//_desc += ' | <a href="javascript:void(0);" onclick="javascript:{window.open(\''+actionlink+'\')};">' + action_str + '</a>';
				//店家資訊
				_desc += ' | <a href="javascript:void(0);" onclick="javascript:{window.open(\''+hyperlink+'\')};">' + store_info + '</a>';
			}
		} else {
			if(actionlink.indexOf('http://') == -1)
				actionlink = 'http://' + actionlink;
			//一般的 活動詳情

			var action_str = '活動詳情';
			
			if(actionlink != "" && is_over_date){
			    _desc += ' | <a href="javascript:void(0);" onclick="javascript:{window.open(\''+actionlink+'\')};">' + action_str + '</a>';
		    }
			//店家資訊
				//_desc += ' | <a href="javascript:void(0);" onclick="javascript:{window.open(\''+hyperlink+'\')};">' + store_info + '</a>';
		}
		if(alertMsg){

		    _desc += ' | <a href="javascript:void(0);" onclick="alert(\''+alertMsg+'\')">條款限制 </a>';
		}
		
		_desc += '</td></tr></table>';
		var markerDesc = address + TEL1;
		var ad = new UMarker(latlng, tmp_UadIcon, citiName, markerDesc);
		ad.isAdPoi = true;
		ad.isCat = cat;	//店家類別
		ad.mylabel = title_Words;
		ad.mydesc = _desc;
		
		ad._Column_add = _Column_add;
		ad._Column_tel = _Column_tel;
		ad._Column_msg = _Column_msg;
		ad._Column_img = _Column_img;
		ad._poi_img = imageFileName;
		
		Uads.push(ad);
		_Umap.addOverlay(ad);
	  }
	  if(listPageFlag) {
		U.gi("listDiv_All2").style.display = 'block';
		if('花旗享樂生活'==UadCategory) {
			U.gi("listDiv_All2").style.display = 'none';
		}
		//列表頁內文
  		U.gi("listDiv").innerHTML = detail_list;
  		_Utabpane.selectTab('list');
	  }
  }
  //listPageFlag = false;	//點tree列表  也要秀結果  so  關閉它
  if(Uads.length==0) {
	//clearAllAdss();
	U.gi("listDiv").innerHTML = '';
    alert('目前的地圖範圍內無任何符合條件的資訊，請變更您的條件或地圖範圍');
  } 
}

function poiTypeClick(node) {
  if(_Umap.getZoomLevel()<7)
    return;
  _Umap.closeInfoWindow();	//清除泡泡視窗
  if(node.isSelected()) {
	/*//Key Word 欄位放空
	U.gi('KeyWord').value = '';
	UadKeyWord = false;*/
	var data = node.data.split(';');
	//各個分類查詢/ 使用率
	var selUse = 'ASP花旗特約店_category_' + data[1];
  	UCounter.addCount(selUse);
	
	UadCategory = data[1];	//記錄特約商店分類ID
	adSearch(data[0], data[1]);
    //getPoi(data[0], data[1]);
	SelectedNode = node;
  } else {
    UadCategory = null;
	UadKeyWord = false;
    clearAds();	//清除廣告地標
	clearPoi();	//清除基礎地標
  }
}

function searchByKey() {
	if(U.gi('KeyWord').value.trim() == '') {
		alert('欄位請勿空白!!!');
		U.gi('KeyWord').focus();
		return false;
	}
	_Umap.closeInfoWindow();	//清除泡泡視窗
	listPageFlag = true;
	UadKeyWord = true;
	adSearch(null, null);
	return false;
}

function adSearchInAddr() {
	UadSearchByAddr = true;
	adSearch(null,null);
}

function adSearch(citiSource, citiType) {
  //清掉暫存資料
  clearAds();
  clearPoi();
  
  var bounds = _Umap.getBounds();
  var searchKeyWord = '';	//關鍵字
  if(U.gi('KeyWord').value.trim() != '')	searchKeyWord = U.gi('KeyWord').value.trim();
  //alert('***'+searchKeyWord+'****');
  
  var encode = '';
  if(xbDetectBrowser()){
	  encode = 'Big5';
  } else {
	  encode = 'UTF-8';
  }
  //alert(citiType + '\n' + UadCategory);
  if(citiType == null) {
	  if(UadCategory != null) {
		citiType = UadCategory;
	  } else {
	  	citiType = '';
	  }
  }
  
  var url = 'search.jsp?searchKeyWord='+searchKeyWord+'&citiType='+citiType
  			+'&encode='+encode
  			+'&NEx='+bounds.getNorthEast().x()+'&NEy='+bounds.getNorthEast().y()+'&SWx='+bounds.getSouthWest().x()+'&SWy='+bounds.getSouthWest().y()
            //+'&maxLat='+bounds.getNorthEast().lat()+'&minLat='+bounds.getSouthWest().lat()+'&maxLon='+bounds.getNorthEast().lng()+'&minLon='+bounds.getSouthWest().lng()
			;
  //alert(url);
  U.loadByAjax(url, adSearchCallback);
}
function clearAllAdss() {
  _Umap.closeInfoWindow();	//清除泡泡視窗
  clearAds();
  U.gi("listDiv").innerHTML = '';
  if(U.gi('KeyWord').value != '')
  	U.gi('KeyWord').value = '';
  if(SelectedNode != null) {
	  if(SelectedNode.isSelected())
	  	SelectedNode.select(false);
  }
  UadCategory = null;
  UadSearchByAddr = false;
}
function clearAds() {
  while(Uads.length>0)
    _Umap.removeOverlay(Uads.pop());
}
function clearPoi() {
  while(Upois.length>0)
    _Umap.removeOverlay(Upois.pop());
}
/*function clearUmapInfoWindow() {
	_Umap.closeInfoWindow();
}*/

function mapChange() {
  clearTimeout(UadThread);
  if(_Umap.getZoomLevel()<7) {
    clearAds();
	clearPoi();
  } else {
	if(U.gi('KeyWord').value.trim() == '')	UadKeyWord = false;
	listPageFlag = true;
	//UviewAd = false;
	if((UadKeyWord || UadCategory || UadSearchByAddr) && !UviewAd && popo_MapMove)
      UadThread = setTimeout(adSearch, 1500);
	popo_MapMove = true;
  }
  //writeCookieLocation();
  // about 基礎地標
  /*clearTimeout(UpoiThread);
  if(_Umap.getZoomLevel()<7) {
    clearPoi();
	clearPoi();
  } else {
	  if(UadCategory && UviewAd)
    	UpoiThread = setTimeout(function() {getPoi(UpoiSource, UpoiType);}, 1000);
  }*/
  UviewAd = false;	//回復移動map即search狀態
}

function mapClick(overlay, latlng) {
  if(overlay) {
    if(!overlay.isAdPoi)
      return;
    //UviewAd = true;
	popo_MapMove = false;
	//alert("overlay.desc="+overlay.desc);
	var size = overlay.mydesc.length;	//用字串長度在來判別一次泡泡的高度
	
	var _Column_add = overlay._Column_add;
	var _Column_tel = overlay._Column_tel;
	var _Column_msg = overlay._Column_msg;
	var _Column_img = overlay._Column_img;
	var _poi_img = overlay._poi_img;
    //alert("_poi_img="+_poi_img);
	var popoH = 0;
	if(_poi_img == 'popuBak2.jpg'){
	    popoH = 30;
	}
	var paopaoH = 0;
	var paopaoW = 0;
	//alert("overlay.desc="+overlay.desc);
    //alert("size="+size);
	if(('1'==_Column_add || '1'==_Column_tel) && '1'==_Column_msg && '1'==_Column_img) {
		if(size == 944){
		    paopaoH = 160 ;
		}else if(size > 860){
			paopaoH = 250 ;
		}else if(size > 800){
			paopaoH = 200 ;
		}else{
			paopaoH = 180 ;
		}
		paopaoW = 320;
	} else if('1'==_Column_msg && '0'==_Column_img) {
		if(size > 830 ){
			paopaoH = 210 ;
		}else if(size > 600 && size <700){ 
		   paopaoH = 300 ;
		}else{
			paopaoH = 150 ;
		}
		paopaoW = 320;
	} else if('0'==_Column_msg && '1'==_Column_img) {
		paopaoH = 130 ;
		paopaoW = 330;
	} else {
		paopaoH = 90 ;
		paopaoW = 290;
	}
    //alert("paopaoH="+paopaoH);
	//alert("paopaoW="+paopaoW);
	//因為花旗享樂多的抬頭多了一行，而且  泡泡中不要袋子(背景)
	var theH = 0;
	//alert("overlay.isCat===="+overlay.isCat);
	if('花旗享樂生活'==overlay.isCat) {
		theH += 20;
		overlay.openInfoWindow('<font color="#333333"><strong>'+overlay.mylabel+'</strong></font>'+ overlay.mydesc+getNearCityShopHTML(), (paopaoW+theH), (paopaoH+theH));
	} else if('台灣優力加油優惠'==overlay.isCat){
	    var popoW = 20;
		//alert("overlay.desc==="+overlay.desc);
		//alert("getNearCityShopHTML==="+getNearCityShopHTML());
	    overlay.openInfoWindow('<font color="#333333"><strong>'+overlay.mylabel+'</strong></font>'+ overlay.mydesc+getNearCityShopHTML(), (paopaoW+popoW), (paopaoH-30));
	}else {
	    
	    //overlay.openInfoWindow('<font color="#333333"><strong>'+overlay.mylabel+'</strong></font>'+ overlay.mydesc+getNearCityShopHTML(), (paopaoW), (paopaoH));
		if(overlay.isCat = '紅利加速賺'){
    		overlay.openInfoWindow('<div style="overflow-y:hidden; background-position:top right; background-repeat:no-repeat;"><font color="#333333"><strong>'+overlay.mylabel+'</strong></font>'+ overlay.mydesc +getNearCityShopHTML()+'</div>', (paopaoW), (paopaoH));
		}else{
	    	overlay.openInfoWindow('<div style="background-image:url(imgs/popuBak2.jpg);overflow-y:hidden; background-position:top right; background-repeat:no-repeat;"><font color="#333333"><strong>'+overlay.mylabel+'</strong></font>'+ overlay.mydesc +getNearCityShopHTML()+'</div>', (paopaoW), (paopaoH));
		}
	}
	
	U.gi('setStartLink').onclick = function() {_setRoutingStartLocation(overlay.getPoint(), overlay.mylabel);};
    U.gi('setEndLink').onclick = function() {_setRoutingEndLocation(overlay.getPoint(), overlay.mylabel);};
	
  }
}

function mouseOnShowMapData(str) {
  if(Uads.length > 0) {
	for(var i=0;i<Uads.length;i++) {
		var ad = Uads[i];
		var adLabel = ad.mylabel;
		
		if(str.trim() != adLabel.trim()) {
			continue;
		}
		
		var adFlag = ad.isAdPoi;
		
		if(!adFlag)
		  return;
		//UviewAd = true;

		_setRoutiongSE(ad);
		
	}
  }
}

function _setRoutiongSE(ad) {
	var adDesc = ad.mydesc;
    //alert(ad.isCat);
    var adLabel = ad.mylabel;
    if(ad.isCat.indexOf('饗宴') != -1 ){
        adLabel += '(' + ad.isCat + ')';
    }
	//adLabel += '(' + ad.isCat + ')';
	
	var _Column_add = ad._Column_add;
	var _Column_tel = ad._Column_tel;
	var _Column_msg = ad._Column_msg;
	var _Column_img = ad._Column_img;
	var _poi_img = ad._poi_img;
	var paopaoH = 0;
	var paopaoW = 0;
	
	var size = ad.mydesc.length;	//用字串長度在來判別一次泡泡的高度
	popo_MapMove = false;
	//alert("size="+size);
	if(('1'==_Column_add || '1'==_Column_tel) && '1'==_Column_msg && '1'==_Column_img) {
		if(size == 944){
		    paopaoH = 160 ;
		}else if(size > 860){
			paopaoH = 250 ;
		}else if(size > 800){
			paopaoH = 200 ;
		}else{
			paopaoH = 180 ;
		}
		paopaoW = 320;
	} else if('1'==_Column_msg && '0'==_Column_img) {
		if(size > 830 ){
			paopaoH = 210;
		}else if(size > 600 && size <700){ 
		   paopaoH = 300;
		}else{
			paopaoH = 150;
		}
		paopaoW = 320;
	} else if('0'==_Column_msg && '1'==_Column_img) {
		paopaoH = 130;
		paopaoW = 330;
	} else {
		paopaoH = 80;
		paopaoW = 290;
	}
	//因為花旗享樂多的抬頭多了一行，而且  泡泡中不要袋子(背景)
	var theH = 0;
	if('花旗享樂生活'==ad.isCat) {
		theH += 30;
		ad.openInfoWindow('<font color="#333333"><strong>'+adLabel+'</strong></font>'+adDesc+getNearCityShopHTML(), (paopaoW+theH), (paopaoH+theH));
	}else if('台灣優力加油優惠'==ad.isCat){
	    var popoW = 20;
		//alert("ad.desc==="+ad.desc);
		//alert("ad.mylabel==="+ad.mylabel);
		//_Umap.centerMap(ad.getPoint());
	    ad.openInfoWindow('<font color="#333333"><strong>'+ad.mylabel+'</strong></font>'+ ad.mydesc+getNearCityShopHTML(), (paopaoW+popoW), (paopaoH-30));
	} else {
		//ad.openInfoWindow('<div style="background-image:url(imgs/popuBak2.jpg); overflow-y:hidden; background-position:top right; background-repeat:no-repeat;"><font color="#333333"><strong>'+adLabel+'</strong></font>'+adDesc+getNearCityShopHTML()+'</div>', (paopaoW), (paopaoH));
          ad.openInfoWindow('<div style="overflow-y:hidden; background-position:top right; background-repeat:no-repeat;"><font color="#333333"><strong>'+adLabel+'</strong></font>'+adDesc+getNearCityShopHTML()+'</div>', (paopaoW), (paopaoH));
        }
	
	U.gi('setStartLink').onclick = function() {_setRoutingStartLocation(ad.getPoint(), ad.mylabel);};
    U.gi('setEndLink').onclick = function() {_setRoutingEndLocation(ad.getPoint(), ad.mylabel);};
}

function linkToCitiBankMsg() {
	//線上辦卡的點閱率
	UCounter.addCount('ASP花旗特約店_function_線上辦卡');
	
	javascript:{window.open('https://taiwan.citicards.com/LeadsPage.aspx?MediaCodeNew=I72080008&MediaCodeExist=I72081008&CardType=2')};
}

//get cookie
function gotoCookieLocation() {
  var str = document.cookie;
  if(!str) {
    _Umap.centerAndZoom(new ULatLng(25.04, 121.55), 9);
    return;
  }
  str = unescape(str)+';';
  var idx = str.indexOf('lastLocation=');
  if(idx<0) {
    _Umap.centerAndZoom(new ULatLng(25.04, 121.55), 9);
    return;
  }
  str = str.substring(idx+13, str.indexOf(';', idx));
  var xyz = str.split(',');
  var lat = parseFloat(xyz[0]);
  var lng = parseFloat(xyz[1]);
  var lv = parseInt(xyz[2]);
  
  _Umap.centerAndZoom(new ULatLng(lat, lng), lv);	//20071206:修改預設層級為 8級
  //_Umap.centerAndZoom(new ULatLng(lat, lng), 9);
}
function writeCookieLocation() {
  document.cookie = 'lastLocation='+escape(_Umap.getCenter().lat()+','+_Umap.getCenter().lng()+','+_Umap.getZoomLevel())+';expires=Wed, 01 Jan 2020 00:00:00 GMT';
}
/*function getPoi(poiSource, poiType) {
  UpoiSource = poiSource;
  UpoiType = poiType;
  if(!UpoiType) {
    clearPoi();
    return;
  }
  if(_Umap.getZoomLevel()<7)
    return;
  var center = _Umap.getCenter();
  var bounds = _Umap.getBounds();
  
  if(UpoiSource=='asp')
    SearchBean.findAspPoi(center.x(), center.y(), bounds.getWidth(U_TM2_COORDSYS), bounds.getHeight(U_TM2_COORDSYS), UpoiType, false, getAspPoiCallback);
}*/

/*function getAspPoiCallback(result) {
  clearPoi();
  var da = result.split(';');
  for(i=0; i<da.length; i++) {
    var at = da[i].split(',');
    if(at.length<13)
      continue;
    var icon = new UIcon();
    icon.image = 'http://apam.urmap.com/apam/'+at[3];
    icon.iconWidth = parseInt(at[11]);
    icon.iconHeight = parseInt(at[12]);
    icon.iconAnchor = new UPoint(Math.round(icon.iconWidth/2), Math.round(icon.iconHeight/2));
    icon.infoWindowAnchor = new UPoint(Math.round(icon.iconWidth/2), 0);
    var poi = new UMarker(new ULatLng(parseInt(at[2]), parseInt(at[1]), U_TM2_COORDSYS), icon, at[4], at[5]);
    poi.pid = at[0];
    poi.mylabel = at[4];
    poi.desc = at[5];
    poi.isPoi = true;
    poi.passiveAction = at[6];
    poi.extLink = at[7];
    poi.activeAction = at[8];
    poi.contentId = at[9];
    Upois.push(poi);
    _Umap.addOverlay(poi);
    if(poi.activeAction!='0' && !UdisplayedActiveAd[poi.contentId]) {
      UactivePoi = poi;
      UdisplayedActiveAd[poi.contentId] = 'displayed';
      if(poi.contentId=='0')
        SearchBean.getAsppoiContent(poi.pid, showPopupContent);
      else
        SearchBean.getAdvert(poi.contentId, showPopupContent);
    }
  }
}*/

function openTheTeach() {
	//搜尋小撇步的點閱率
	UCounter.addCount('ASP花旗特約店_function_搜尋小撇步');
	javascript:{window.open('./theTeachhtml/index.htm')};
}

function xbDetectBrowser(){
	//alert(window.navigator.appName);
	if(window.navigator.appName.toLowerCase().indexOf("microsoft") != -1) {
		return true;
	} else {
		return false;
	}
}

function ashWords(word) {
	return '<font color="#333333">' + word + '</font>';
}

String.prototype.trim=trim;
function trim() {
	return this.replace(/^\s+|\s+$/g,"");
}

//bingo add start
function getNearCityShop(){
	var encode = '';
	if(xbDetectBrowser()){
	  encode = 'Big5';
	} else {
	  encode = 'UTF-8';
	}
	var bounds = _Umap.getBounds();
	var url = 'search.jsp?searchKeyWord='+''+'&citiType='+''
  			+'&encode='+encode
  			+'&NEx='+bounds.getNorthEast().x()+'&NEy='+bounds.getNorthEast().y()+'&SWx='+bounds.getSouthWest().x()+'&SWy='+bounds.getSouthWest().y();
  //alert(url);
  U.loadByAjax(url, adSearchCallback);
}
function getNearCityShopHTML(){
	//return '<a style="background-image:url(imgs/bag_16x19.gif);background-repeat:no-repeat;padding-left:18px;position:absolute;right:5px;bottom:5px;" href="javascript:getNearCityShop();">附近花旗分期商店</a>';
	return '';
}
function searchByKeyword(kw){
	U.gi('KeyWord').value = kw;
	searchByKey();
}
//bingo add end
