var rightShow=true;
var allShow=true;
var miniMapShow=true;
var divMapHeight=0;
var type=[];
var panel=2;
type[0]=1;
type[1]=11;
var map=o_mapid;
var mapAction={action:'',argu:[]};
var isComplete=false;

window.onresize=doc_resize;
function doc_resize(){
	bodyWidth=document.body.clientWidth;
	bodyHeight=document.body.clientHeight;
	//if(bodyHeight!=document.body.scrollHeight){
		//bodyHeight=document.body.scrollHeight-75;
	//}
	if(allShow)$('divMap').style.height=bodyHeight-90;
	else $('divMap').style.height=bodyHeight;
	//$('divFullScreen').style.left=bodyWidth-360;
	if(bodyWidth<998){
		$('mainTable').style.width=998;
		//$('divFullScreen').style.left=650;
		$('mainTable').style.height=bodyHeight-100;
	}
	else{
		$('mainTable').style.width='100%';
		$('mainTable').style.height=bodyHeight-100;
	}
	//$('divFullScreen').style.left=$('divMap').offsetWidth-700;
	setPos1();
}
function body_onload(){
	doc_resize();
	doMapAction();
	setTimeout('loadend()',2000);
}
function loadend(){
	isComplete=true;
	switchObjView('loading',false);
}
function enterByNav(id,type){
	if(!isBodyLoaded()) return false;
	showResult(id,type);
}
function doMapAction(){
	if(typeof(popomap)&&popomap.getMapStatus()){
		switch(mapAction.action){
			case 'showResult':
				showResult(mapAction.argu[0],mapAction.argu[1]);
				break;
			case 'showNote':
				showNote(mapAction.argu[0]);
				break;
			case 'doRight':
				popomap.init(0,0,true);
				doRight(mapAction.argu);
				break;
			default:
				loadXY();
				break;
		}
		if(mapAction.action!='doRight')doRight(1);
	}
	else{
		setTimeout('doMapAction()',500);
	}
}
function showRight(){
	if(rightShow){
		if(panel==2){
			$('rightP').style.display='none';			
		}
		else{
			$('ifr').style.display='none';			
			//$('ifr_top2').style.display='none';
			$('rightP').width='39px';
		}
		rightShow=false;		
	}
	else{
		if(panel==2){
			$('rightP').style.display='';
		}
		else{
			$('ifr').style.display='';
			//$('ifr_top2').style.display='';
			$('rightP').width='348px';
		}
		rightShow=true;
	}
	setPos1();
}
function fullScreen(){
	if(allShow){
		$('headNav').style.display='none';
		$('rightP').style.display='none';
		$('rightButton').style.display='none';
		//$('searchTbl').style.display='';
		$('divMap').style.height=bodyHeight-1;
		//$('divFullScreen').style.top='0px';
		allShow=false;
	}
	else{
		if(rightShow){
			$('rightP').style.display='';
			$('rightButton').style.display='';
		}
		else{
			if(panel!=2)$('rightP').style.display='';
			$('rightButton').style.display='';
		}
		$('headNav').style.display='';
		//$('searchTbl').style.display='none';
		$('divMap').style.height=bodyHeight-90;
		//$('divFullScreen').style.top='96px';
		allShow=true;
	}
	//$('divFullScreen').style.left=$('divMap').offsetWidth-700;
	setPos1();
}
function setPos1(){
	if(allShow){
		$('divFullScreen').style.top='96px';
		$('divMapNav').style.top='89px';
		//$('divSpring').style.top='89px';
	}
	else {
		$('divFullScreen').style.top='0px';
		$('divMapNav').style.top='0px';
		//$('divSpring').style.top='0px';
	}
	$('divFullScreen').style.left=$('divMap').offsetWidth-660;
	//$('divSpring02').style.left=$('divMap').offsetWidth-130;
	$('divMapNav').style.width=$('divMap').offsetWidth;
	if($('divMapNav').style.display==''){
		$('divMapNav').style.height=$('divMap').offsetHeight;
		$('divMapNav_img').style.left=Math.floor(($('divMap').offsetWidth-671)/2);
		$('divMapNav_img').style.top=Math.floor(($('divMap').offsetHeight-549)/2);
		$('divMapNav_close').style.left=$('divMap').offsetWidth-560;
	}
	divMapHeight=$('divMap').offsetHeight;
}
function changePanel(i,flag){
	if(!flag&&!isBodyLoaded()) return false;
	if(!rightShow)showRight();
	//if(i==panel&&$('panel_btn'+i).className=='bt_hit') return;
	mapClear();
	$('panel_btn'+panel).className='bt';
	$('panel_btn'+i).className='bt_hit';
	if(i==2){
		$('panel'+1).style.display='none';
		if(panel!=2)$('tbl'+panel).style.display='none';
		//$("ifr_top1").style.display='';
		$('panel'+2).style.display='';
		//ifrRight.location='shouye.htm';
		ifrRight.location='shouye.htm';
	}
	else if(panel==2){
		$('panel'+2).style.display='none';
		//$("ifr_top1").style.display='none';
		$('panel'+1).style.display='';
		$('tbl'+i).style.display='';
	}
	else{
		$('panel'+2).style.display='none';
		$('tbl'+panel).style.display='none';
		//$("ifr_top1").style.display='none';
		$('tbl'+i).style.display='';
	}
	panel=i;
	//alert(i);
	if(i==2) return;
	//alert(i+','+type[i]);
	changeIfr(type[i]);
}

var className=[];
className[0]='quan_';
className[1]='yp_';
var dir=[];
dir[0]='';
dir[1]='yp/yp/';
var urls={};
urls['0,1']='http://'+infoDomain+'/mapIndex.jspa?_flowId=search';
urls['0,2']='http://'+infoDomain+'/house/index.jspa?_flowId=search';
urls['0,3']='http://'+infoDomain+'/job/index.jspa?_flowId=search';
urls['0,4']='http://'+infoDomain+'/love/index.jspa?_flowId=search';
urls['0,5']='http://'+infoDomain+'/life/index.jspa?_flowId=search';
urls['0,6']='http://'+infoDomain+'/food/index.jspa?_flowId=search';
urls['0,7']='http://'+infoDomain+'/tour/index.jspa?_flowId=search';
urls['0,8']='http://'+infoDomain+'/typemore.jspa?_flowId=more';
urls['0,9']='http://'+infoDomain+'/news/index.jspa?_flowId=search';
urls['0,10']='http://'+infoDomain+'/shop/index.jspa?_flowId=search';
urls['1']='/newmap/yp.jspa?_flowId=sub&type={@id}&map={@map}';
urls['1,11']='/newmap/yp.jspa?_flowId=recommend&map={@map}';
function changeIfr(id,url){
	if(!rightShow)showRight();
	var obj=$('b_'+panel+'_'+id);
	if(id<10)var classN=className[panel]+'0'+id+'_hit';
	else{var classN=className[panel]+id+'_hit';}
	obj.className=classN;
	if(id!=type[panel]){
		if(type[panel]<10) var classN=className[panel]+'0'+type[panel];
		else{var classN=className[panel]+type[panel];}
		$('b_'+panel+'_'+type[panel]).className=classN;
		type[panel]=id;
	}
	if(!url){
		if(urls[panel+','+id]){
			url=urls[panel+','+id];
		}
		else if(urls[panel]){
			url=urls[panel];
		}
	}
	if(url.indexOf('@')!=-1){
		url=url.replace('{@id}',id).replace('{@map}',map);
	}
	if(url.indexOf('?')==-1)url=url+'?locale='+o_locale;
	else url=url+'&locale='+o_locale;
	ifr.location=url;
}
function changeInfoType(type,id){
	var type_panel={house:2,job:3,love:4,life:5,food:6,tour:7,news:9,shop:10};
	var url='http://'+infoDomain+'/'+type+'/index.jspa?_flowId=search&type='+id+'&map='+map;
	changeIfr(type_panel[type],url);
}
function changeYpType(type,subtype){
	var url='/newmap/yp.jspa?_flowId=sub&map='+map+'&type='+type+'&subtype='+subtype;
	changeIfr(type,url);
}
function switchCity(){
	var obj=$('divCity');
	if(obj.style.display==''){
		obj.style.display='none';
	}
	else{
		obj.style.display='';
		obj.style.left=bodyWidth-300;
	}
}
function getNavStatus(){
	if($('divMapNav').style.display=='')
		return true;
	else 
		return false;
}
function isBodyLoaded(){
	return isComplete;
}
var navTimer=null;
function switchNavView(flag){
	if(typeof(flag)=='undefined'){
		if($('divMapNav').style.display=='none'){
			$('divMapNav').style.display='';
			if(!navTimer)navTimer=setInterval('openNav()',10);
		}
		else{
			if(!navTimer)navTimer=setInterval('closeNav()',10);
		}
	}
	else{
		if(flag){
			$('divMapNav').style.display='';
			if(!navTimer)navTimer=setInterval('openNav()',10);
		}
		else{
			if(!navTimer)navTimer=setInterval('closeNav()',10);
		}
	}
}
function switchNavView2(){
	if(!isBodyLoaded()) return false;
	switchNavView();
}
function switchMapView(flag){
	if(flag=='undefined'){
		with($('divMap').style){
			display=display==''?'none':'';
		}
	}
	else{
		if(flag){
			$('divMap').style.display='';
		}
		else{
			$('divMap').style.display='none';
		}
	}
}
function switchObjView(id,flag){
	if(!$(id))return false;
	if(flag=='undefined'){
		with($(id).style){
			display=display==''?'none':'';
		}
	}
	else{
		if(flag){
			$(id).style.display='';
		}
		else{
			$(id).style.display='none';
		}
	}
}
function openNav(){
	var h=$('divMapNav').offsetHeight;
	var step=45;
	if(h<divMapHeight){
		if(h+step<=divMapHeight)$('divMapNav').style.height=h+step;
		else $('divMapNav').style.height=divMapHeight;
	}
	else{
		clearInterval(navTimer);
		navTimer=null;
	}
}
function closeNav(){
	var h=$('divMapNav').offsetHeight;
	var step=45;
	if(h>step){
		$('divMapNav').style.height=h-step;
	}
	else{switchObjView('loading',false);
		$('divMapNav').style.display='none';
		clearInterval(navTimer);
		navTimer=null;
	}
}

function isEmpty(fieldValue)
{
	var regEx = /\S+/i;
	if(regEx.test(fieldValue))
		return false;
	else
		return true;
}
function setMapValue(form){
	if(form&&form.locale){
		if(typeof(o_locale)=='string')form.locale.value=o_locale;
	}
	if(form&&form.map){
		if(typeof(map)=='number'){
			form.map.value=map;
			return true;
		}
		else{
			national.showMsg('%{NoMap:没有找到地图}');
			return false;
		}
	}
	return true;
}
function postInfo () {
    changePanel(2);
    ifrRight.location= 'http://'+infoDomain+'/typelist.jspa?locale='+o_locale;
}
function doRight(argu){
	var right=argu[0];
	var unit=argu[1];
	var param1=argu[2];
	switch(right){
		case '1':
			//rightOpen('shouye.htm');
			var url='/newmap/yp.jspa?_flowId=recommend&map=1';
			rightOpen(url,1,11);
			break;
		case '2':
			rightOpen('http://'+infoDomain+'/mapIndex.jspa?_flowId=search&locale='+o_locale,0,1);
			break;
		case '3':
			rightOpen('http://'+infoDomain+'/typelist.jspa?locale='+o_locale);
			break;
		case '4':
			var url='newmap/yp.jspa?_flowId=joinbyunit&unit='+unit+'&city='+city+'&locale='+o_locale;
			rightOpen(url);
			break;
		case '5':
			var url=decodeURIComponent(param1);
			rightOpen(url);
			break;
		case 'tour':
			var url='gztour.htm';
			rightOpen(url,0,7);
			break;
		default:
			//rightOpen('shouye.htm');
			var url='/newmap/yp.jspa?_flowId=recommend&map=1';
			rightOpen(url,1,11);
			break;
	}
}
function rightOpen(url,panel,type){
	if(!allShow){
		$('rightP').style.display='';
		$('rightButton').style.display='';
		rightShow=true;
		setPos1();
	}
	if(typeof(panel)=='number'){
		changePanel(panel,true);
		$('panel_btn0').className='bt';
		if(typeof(type)=='number')changeIfr(type);
		$('ifr').src=url;
	}
	else{
		changePanel(2);
		if(url!='shouye.htm')$('panel_btn2').className='bt';
		$('ifrRight').src=url;
	}
}
function setPanel2Style(){
	$('panel_btn2').className='bt';
}
function dosearch(form,keyword,initKey)
{
	if(!setMapValue(form)) return false;
	if(!keyword&&(isEmpty(form.keyword.value)||form.keyword.value==initKey)){
	  national.showMsg('%{EnterKeyword:请输入关键字}');
	  form.keyword.focus();
	  return false;
	}
	changePanel(2);
	setPanel2Style();
	if(keyword){
		form.keyword.value=keyword;
		form.submit();
	}
	return true;
}
function dosearch1(keyword){
	if(!isComplete) {
		national.showMsg('%{WaitMap:请在加载完以后再搜索,谢谢}!');
		return false;
	}
	var form=document.mapForm;
	form.action = '/newmap/map.jspa';
	form.target = 'ifrRight';
	if(form.screen){
		var d=getMapRang();
		form.lx.value=Math.floor(d.startX/2);
		form.ly.value=Math.floor(d.startY/2);
		form.ux.value=Math.floor(d.endX/2);
		form.uy.value=Math.floor(d.endY/2);
	}
	var initKey=national.getStr('Common','MapSearchValue','楼房实体 / 道路 / 河流');
	return dosearch(form,keyword,initKey);
}
function dosearch2(keyword){
	if(!isComplete) {
		national.showMsg('%{WaitMap:请在加载完以后再搜索,谢谢}!');
		return false;
	}
	var form=document.ypForm;
	form.action = 'newmap/yp.jspa';
	form.target = 'ifrRight';
	var initKey='医疗保健 / 维修中心 / 企业服务 / 美容健身 / 运动休闲...';
	return dosearch(form,keyword,initKey);
}
function dosearch3(keyword){
	if(!isComplete) {
		national.showMsg('%{WaitMap:请在加载完以后再搜索,谢谢}!');
		return false;
	}
	var form=document.infoForm;
	form.action = 'http://'+infoDomain+'/index.jspa';
	form.target = 'ifrRight';
	var initKey=national.getStr('Common','InfoSearchValue','房产 / 工作 / 美食 / 购物 / 旅游 / 交友 ...');
	return dosearch(form,keyword,initKey);
}
function dosearch5(){
	if(!isComplete) {
		national.showMsg('%{WaitMap:请在加载完以后再搜索,谢谢}!');
		return false;
	}
	var form=document.hallForm;
	form.action = 'hall.jspa';
	form.target = 'ifrRight';
    var initKey='';
    changePanel(2);
	return true;
}
function doquerySmart(){
	rightOpen('/newmap/busline.jspa?_flowId=smartSearch&map='+map+'&locale='+o_locale);
}
function doquery1(form)
{
	if(!isComplete) {
		national.showMsg('%{WaitMap:请在加载完以后再搜索,谢谢}!');
		return false;
	}
    if (isEmpty(form.from.value)||form.from.value=='所在地')
	{
   	   national.showMsg('%{EmptyFrom:起始不能为空}');
	   form.from.focus();
      return false;
     }
	 else if (isEmpty(form.to.value )||form.to.value=='目的地')
	 {
   	   national.showMsg('%{EmptyTo:终点不能为空}');
	   form.to.focus();
       return false;
     }else
	 {
	    form.action = '/newmap/busline.jspa';
		form.target = 'ifrRight';
		changePanel(2);
		setPanel2Style();
		//menuSwitch('search');
	 }
	 return setMapValue(form);
 } 
function doquery2(form)
{  
	if(!isComplete) {
		national.showMsg('%{WaitMap:请在加载完以后再搜索,谢谢}!');
		return false;
	}
     if (isEmpty(form.stationName.value )||form.stationName.value==national.getStr('Common','StationSearchValue','例如:体育中心'))
	{
   	   national.showMsg('%{EmptyStation:站点不能为空}');
	   form.stationName.focus();
       return false;
     }else
	 {
	    form.action = '/newmap/busline.jspa';
		form.target = 'ifrRight';
		changePanel(2);
		setPanel2Style();
		//menuSwitch('search');
	 }
	 return setMapValue(form);
 }
function doquery3(form)
{
	if(!isComplete) {
		national.showMsg('%{WaitMap:请在加载完以后再搜索,谢谢}!');
		return false;
	}
     if (isEmpty(form.name.value )||form.name.value==national.getStr('Common','LineSearchValue','例如:178'))
	 {
   	   national.showMsg('%{EmptyLine:路线不能为空}');
	   form.name.focus();
      return false;
     }else
	 {
	    form.action = '/newmap/busline.jspa';
		form.target = 'ifrRight';
		changePanel(2);
		setPanel2Style();
		//menuSwitch('search');
	 }
	 return setMapValue(form);
 }
var maptype=3;
function changeMapType(id){
	maptype=id;
	popomap.changeMapType(id);
}
var isloadSign={};
isloadSign['1']=false;
isloadSign['2']=false;
isloadSign['mobileBuilding']=false;
isloadSign['hall']=false;
isloadSign['basesite']=false;
function loadSign(id){
	if(isloadSign[id]) isloadSign[id]=false;
	else isloadSign[id]=true;
	var value=isloadSign[id];
	switch(id){
		case 1:
			break;
		case 2:
			if(value) popomap.loadSign('BusStation');
			else popomap.removeSign('BusStation');
			break;
		case 3:
			break;
		case 'mobileBuilding':
			if(value)loadMobileBuilding_temp();
			else removeBuilding_temp();
			break;
		case 'hall':
			if(value)popomap.loadSign('Hall');
			else popomap.removeSign('Hall');
			break;
		case 'basesite':
			if(value)popomap.loadSign('BaseSite');
			else popomap.removeSign('BaseSite');
			break;
		default:
			break;
	}
}
function loadMobileBuilding_temp(){
	var id=426638;
	var x=550634;
	var y=529292;
	showResult(id,1);
	var htmlStr='<img src="/images/jmcmcc/mobileBuilding.gif" style="cursor:pointer" onclick="mapApi.showOCInfo('+x+','+y+','+id+')">';
	popomap.createPop('jmcmcc_build',htmlStr,x,y,14,37,5);
}
function removeBuilding_temp(){
	popomap.removePop('jmcmcc_build');
}
function $() {
  var elements = new Array();

  for (var i = 0; i < arguments.length; i++) {
    var element = arguments[i];
    if (typeof element == 'string')
      element = document.getElementById(element);

    if (arguments.length == 1)
      return element;

    elements.push(element);
  }

  return elements;
}

function closeWindow(){
	postData('chat/chat.jspa?_flowId=exit','',getMsg);
	$('divChat').style.display='none';
	$('ifrChat').src='';
}
function miniWindow(){
  $('divChat').style.display='none';
  ismini = true;

}

function getMsg(data){
	var d = data.replace(/^\s*|\s*$/,'');
	if (d.length>0){
	  var sp1=document.createElement('div');
	  sp1.innerHTML=data;
      alert(sp1.innerText);
	}
}
function showChat(){
	if($('divChat').style.display==''){
		$('divChat').style.display='none';
		ismini = true;
		//$('chatImage').src = 'images/skin/chart.gif';
	}
	else{
		$('divChat').style.display='';
		if($('ifrChat').src=='') $('ifrChat').src='/chat/chat.jspa?_flowId=port&locale='+o_locale;
		ismini = false;
		//$('chatImage').src = 'images/skin/chart.gif';
		
	}
}
var ismini = false;//如果聊天窗口最小化；
var moveSx=0,moveSy=0,moveElm=null;
function elmdown(evt,obj){
	evt=evt?evt:event;
	moveElm=obj?$(obj):evt.srcElement?evt.srcElement:evt.target;
	moveSx=evt.clientX-moveElm.offsetLeft;
	moveSy=evt.clientY-moveElm.offsetTop;
	moveElm.style.position='absolute';
	moveElm.setCapture();
}
function elmmove(evt){
	evt=evt?evt:event;
	if(moveElm==null) return;

	if (evt.clientX-moveSx<0){
		moveElm.style.left = 0;
	}else{
		moveElm.style.left=evt.clientX-moveSx;
	}


	if (evt.clientY-moveSy<0){
		moveElm.style.top = 0;
	}else{
      moveElm.style.top=evt.clientY-moveSy;
	}

}
function elmup(evt){
	moveElm=null;
	document.releaseCapture();
}
function writeLocaleSwitch(){
	var str1='<a href="http://'+domain+'.o.cn/index.jspa?locale=zh_cn" class="l000">'+national.getStr('Common','GB','简')+'</a>/<a href="http://'+domain+'.o.cn/index.jspa?locale=zh_tw" class="l000">'+national.getStr('Common','BIG5','繁体')+'</a>';
	var str2='/<a href="http://en.'+domain+'.o.cn/index.jspa" class="l000">English</a>';
	document.write(str1);
	if(domain=='yiwu'){
		document.write(str2);
	}
}
Object.extend = function(dest, source, replace) {
	for(prop in source) {
		if(replace == false && dest[prop] != null) continue;
		dest[prop] = source[prop];
	}
	return dest;
};

Object.extend(Function.prototype, {
	apply: function(o, a) {
		var r, x = "__fapply";
		if(typeof o != "object") o = {};
		o[x] = this;
		var s = "r = o." + x + "(";
		for(var i=0; i<a.length; i++) {
			if(i>0) s += ",";
			s += "a[" + i + "]";
		}
		s += ");";
		eval(s);
		delete o[x];
		return r;
	},
	bind: function(o) {
		if(!window.__objs) {
			window.__objs = [];
			window.__funcs = [];
		}

		var objId = o.__oid;
		if(!objId)
			__objs[objId = o.__oid = __objs.length] = o;

		var me = this;
		var funcId = me.__fid;
		if(!funcId)
			__funcs[funcId = me.__fid = __funcs.length] = me;

		if(!o.__closures)
			o.__closures = [];

		var closure = o.__closures[funcId];
		if(closure)
			return closure;

		o = null;
		me = null;

		return __objs[objId].__closures[funcId] = function() {
			return __funcs[funcId].apply(__objs[objId], arguments);
		};
	},
	bindAsEventListener:function(object) {
		var __method = this;
		return function(event) {
			return __method.call(object, event || window.event);
		}
	}
}, false);

function doswitchBBS(){
    window.open('http://club.eqj.cn');
}
