
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function adjust(o){
	var nbc= $('neighbor_content');
	var drc= $('direction_content');
	var reE = $('reEnter');
	if(o =='d'){
		if(drc.style.display == '') return ;
		drc.style.display = '';
		nbc.style.display = 'none';
		if(reE) reE.style.display='none';
	}else{
		if(nbc.style.display == '') return ;
		drc.style.display = 'none';
		nbc.style.display = '';
	}
	var no = 0;
	try{
		var s = setInterval(
			function(){
				no++;
				if(o == 'd'){
					nbc.style.height= (416-no*52)+'px';
					drc.style.height= no*52+'px';
				}else{
					drc.style.height= (416-no*52)+'px';
					nbc.style.height= no*52+'px';
				}
				if(no == 8) clearInterval(s);
			}
		,1);
	}catch(e){;}		
}

function adjust1(o){
	var nbc= $('neighbor_content');
	var drc= $('direction_content');
	var reE = $('reEnter');
	if(o =='d'){
		if(drc.style.display == '') return ;
		drc.style.display = '';
		nbc.style.display = 'none';
		if(reE) reE.style.display='none';
	}else{
		if(nbc.style.display == '') return ;
		if(nbc.style.display == 'none' && reE.style.display == '') return ;
		drc.style.display = 'none';
		nbc.style.display = '';
	}
	var no = 0;
	try{
		var s = setInterval(
			function(){
				no++;
				if(o == 'd'){
					nbc.style.height= (416-no*52)+'px';
					drc.style.height= no*52+'px';
				}else{
					drc.style.height= (400-no*50)+'px';
					nbc.style.height= no*50+'px';
				}
				if(no == 8) clearInterval(s);
			}
		,1);
	}catch(e){;}		
}

function showDir(){
	adjust('d');
	if($('result')) Element.hide('result');
	$('nei_img').src='../images/map/arrow_down_2.gif';
	$('dir_img').src='../images/map/arrow_right.gif';
}
function showNei(){
	adjust('n');
	if($('result')) Element.show('result');
	$('dir_img').src='../images/map/arrow_down_2.gif';
	$('nei_img').src='../images/map/arrow_right.gif';
}

function showDir1(){
	adjust1('d');
	if($('result')) Element.hide('result');
	$('nei_img').src='../images/map/arrow_down_2.gif';
	$('dir_img').src='../images/map/arrow_right.gif';
}
function showNei1(){
	adjust1('n');
	var reE = $('reEnter');
	if(reE.style.display == 'none' && $('result')) Element.show('result');
	$('dir_img').src='../images/map/arrow_down_2.gif';
	$('nei_img').src='../images/map/arrow_right.gif';
}

 function getRecentHistory(cookieName,cn){
     var cns = JONGO.getCookie(cookieName);
     var flag = false;
     if(cns != null && cns != ''){
     	var all = cns.split('&sp;'); 
     	for(var j= 0;j< all.length;j++){
     		if(all[j] == cn) flag = true;
     	}
     	if(!flag){         	 
     		if(all.length >=5){
     			for(var k =0;k< all.length-1;k++){
     				all[k] = all[k+1];
     			}
     			all[all.length-1] = cn;
     			var tmp='';
   				for(var g=0;g< all.length-1;g++){
   					tmp += all[g]+"&sp;";
   				}
   				tmp += all[all.length-1];
   				JONGO.setCookie(cookieName,tmp);
     			
     		}else{
     			var tmp='';
   				for(var g=0;g< all.length;g++){
   					tmp += all[g]+"&sp;";
   				}
   				JONGO.setCookie(cookieName,tmp+cn);
     		}         		
     	}
     }else{
     	cns = cn;
     	JONGO.setCookie(cookieName,cns);
       }       
   }

JONGO.CityCover = {};
JONGO.CityCover.CHINA = {
'BEIJING' : 'beijing.gif',
'SHANGHAI' : 'shanghai.gif',
'GUANGZHOU' : 'Guangzhou.gif',
'HANGZHOU' : 'Hangzhou.gif',
'SHENZHEN' : 'Shenzhen.gif',
'HONGKONG' : 'Hongkong.gif'
};

JONGO.Knows = {};
JONGO.Knows.CHINA = {
'BEIJING' : 'http://knows.jongo.com/res/index.jng?cate=701&pageSize=20&sortby=passedAt&direction=desc',
'SHANGHAI' : 'http://knows.jongo.com/res/index.jng?cate=695&pageSize=20&sortby=passedAt&direction=desc',
'GUANGZHOU' : 'http://knows.jongo.com/',
'HANGZHOU' : 'http://knows.jongo.com/',
'SHENZHEN' : 'http://knows.jongo.com/',
'HONGKONG' : 'http://knows.jongo.com/'
}; 

JONGO.Local = {};
JONGO.Local.CategoryIcons = {
'Food & Dining':'restaurants.gif',
'Shopping':'shopping.gif',
'Entertainment & Recreation':'entertainments_recreations.gif',
'Sports':'sports_games.gif',
'Electronic & Computer':'electronic_computer.gif',
'Education & Culture':'education_culture.gif',
'Government & Organization':'governments_organizations.gif',
'Health & Beauty':'health_beauty.gif',
'Legal & Finance':'legal_finance.gif',
'Real Estate':'real_estates.gif',
'Travel & Lodging':'travel_lodging.gif"',
'Professional Services':'professional_services.gif',
'Automotive':'automotive.gif',
'Landmark':'landmarks.gif',
'International Company':'international_companies.gif'
};

function trim(){
	return this.replace(/^\s*|\s*$/g,"");
}

JONGO.Local.initEventFromCalendar = function(inputField, displayArea, button) {
			  Calendar.setup(
			    {
			      inputField  : inputField,         // ID of the input field
			      displayArea : displayArea,
			      ifFormat    : "%y %b %e",    // the date format
 		          daFormat    : "%b %e",    // the date format
			      button      : button,      // ID of the button
			      singleClick    :    true,
			      onUpdate	  : function(cal) {
			      	var self = new Date(cal.date);
			      	var d = Date.parseDate($('eventSearchToDate').value,'%y %b %e');
			      	if (d < self) {
			      		$('eventSearchToDate').value = self.print('%y %b %e');
			      		$('eventSearchToDateDisplay').innerHTML = self.print('%b %e');			      		
			      	}
			      }
			    }
			  ); 
}

JONGO.Local.initEventToCalendar = function(inputField, displayArea, button) {
			  Calendar.setup(
			    {
			      inputField  : inputField,         // ID of the input field
			      displayArea : displayArea,
			      ifFormat    : "%y %b %e",    // the date format
 		          daFormat    : "%b %e",    // the date format
			      button      : button,      // ID of the button
			      singleClick    :    true
			    }
			  ); 
}

function popSearch(sender, type, poi, name) {
	sender = $(sender);
	var data = {contextPath:JONGO.Config.ContextPath};
	if (type.match(/^dir\-/)) {
		if (type.match(/to$/)) {
			data.fromPoiId = '';
			data.toPoiId  = poi;
			data.fromName = '';
			data.toName = name;
			data.fromInputClass = 'InputBorder3';
			data.toInputClass = 'InputBorder';
		}else{
			data.fromPoiId = poi;
			data.toPoiId  = '';	
			data.fromName = name;
			data.toName = '';		
			data.fromInputClass = 'InputBorder';
			data.toInputClass = 'InputBorder3';				
		}
		data.centerPoiId = '';
		data.routeFormContainerStyle = '';
		data.nearFormContainerStyle = 'display:none';
	}else{
		data.fromPoiId = '';
		data.toPoiId  = '';
		data.centerPoiId = poi;
		data.fromName = '';
		data.toName = '';
		data.routeFormContainerStyle = 'display:none';
		data.nearFormContainerStyle = '';
		data.fromInputClass = 'InputBorder';
		data.toInputClass = 'InputBorder';		
	}
	new JONGO.RemoteJST(JONGO.Config.ContextPath+'/_jst/pop_search_form.jst',data,
			function(result) {
				var container = Builder.node('div', {style:'display:none;z-index:999;'});
				container.innerHTML = result;
				document.body.appendChild(container);
  				
		    	if (Effect.Dropshadow) {
		    		if (!container._shadow) {
						container= Effect.Dropshadow(container);
						Element.hide(container);
						Element.show(container._original);
					}else{
						container = container._shadow;
					}		
				}
				
				var pos = Position.positionedOffset(sender);
				var eh = Element.getDimensions( sender ).height;
				var ew = Element.getDimensions( sender ).width;	
			  	var focus  = function() {
			  		this.hasFocus = true;
			  	};
			  	
			  	var blur = function() {
			 		this.hasFocus = false;  	
			  	};						
				var hide = function() {
					if (this.hasFocus) 
			  			return;
					Event.stopObserving(document, 'click', 
		  						this.__hideEventListener,
		  						false);
		  			var o = this;
					Effect.Fade(this, {duration:0.15,afterFinish:function() {
						document.body.removeChild(o);
					}});
				}
				
				container.__hideEventListener = hide.bindAsEventListener(container);
				Event.observe(container,'mouseover',focus.bindAsEventListener(container),false);
				Event.observe(container,'mouseout',blur.bindAsEventListener(container),false);
				
				setTimeout(function() {
					Event.observe(document,'click',container.__hideEventListener,false);
				},150);
				
			    if(!container.style.position || container.style.position!='absolute') {
			      container.style.position = 'absolute';
			    }					
				container.style.left = (pos[0])+'px';
  				container.style.top = (pos[1]+eh+10)+'px';
  				
				Effect.Appear(container,{duration:0.15});
			});
}