var skin="default";
var boardid=1;
var comTypeId=1;
var rightShow=true;
var topShow=true;
var allShow=true;
var bodyWidth=0,bodyHeight=0,sWidth=0,sHeight=0;
var mainMenu='city';
var rightBody_w=240;
var rightToolBar_w=45;
var rightMain_w=rightBody_w+rightToolBar_w+11;
var rightMain_l=new Array();
rightBodyShow=new Array();
rightBodyShow['city']=true;
rightBodyShow['bbs']=true;
rightBodyShow['search']=true;

//doc1_resize();
window.onresize=doc1_resize;
function doc1_resize()
{
	bodyWidth=document.body.clientWidth;
	bodyHeight=document.body.clientHeight;
	switch(skin)
	{
		case "default":
			skinDefaultRZ();
			break;
		default:
			skinDefaultRZ();
			break;
	};
}
function skinDefaultRZ()
{
	try
	{
		bodyWidth=bodyWidth>1000?bodyWidth:1000;
		bodyHeight=bodyHeight>600?bodyHeight:600;
		//alert(bodyWidth+':'+bodyHeight);
		$('divMain').style.width=bodyWidth+'px';
		$('divMain').style.height=bodyHeight+'px';
		$('divTop').style.width=bodyWidth+'px';
		//return;
		menuSwitch(mainMenu);
		//$('divRight').style.height=bodyHeight-88+'px';
		$('divRightMain').style.height=bodyHeight-88+'px';
		$('divRightBtn').style.height=bodyHeight-88+'px';
		$('divTB').style.height=bodyHeight-88+'px';
		$('divDown').style.top=bodyHeight-88-16+'px';
		$('divTB2').style.height=bodyHeight-88+'px';
		$('divRightBody').style.height=bodyHeight-88+'px';
		$('divRightBody2').style.height=bodyHeight-88+'px';
		$('divHistory').style.height=bodyHeight-88+'px';
		$('divSearch').style.height=bodyHeight-88+'px';
		$('divMain').style.display='';
		//$('divMap').setActive();
	}
	catch(e)
	{
		alert("皮肤初始化失败");
	}
}

function menuSwitch(type)
{
	mainMenu=type;
	if(type=='city')
	{
		$('divRightBody').style.display='';
		if(allShow) $('divTB').style.display='';
		$('divRightBody2').style.display='none';
		$('divTB2').style.display='none';
		$('divHistory').style.display='none';
		$('divSearch').style.display='none';
		rightBody_w=240;
		rightToolBar_w=45;
		rightMain_w=rightBody_w+rightToolBar_w+11;
		$('divRightMain').style.left=bodyWidth-rightMain_w+'px';
		$('divTB').style.left=bodyWidth-rightToolBar_w+'px';
		changeUrl();
	}
	else if(type=='bbs')
	{
		$('divRightBody').style.display='none';
		$('divTB').style.display='none';
		$('divRightBody2').style.display='';
		if(allShow) $('divTB2').style.display='';
		$('divHistory').style.display='none';
		$('divSearch').style.display='none';
		rightBody_w=382;
		rightToolBar_w=69;
		rightMain_w=rightBody_w+rightToolBar_w+11;
		$('divRightMain').style.left=bodyWidth-rightMain_w+'px';
		$('divTB2').style.left=bodyWidth-rightToolBar_w+'px';
		changenews(0,true);
	}
	else if(type=='search')
	{
		$('divRightBody').style.display='none';
		$('divTB').style.display='none';
		$('divRightBody2').style.display='none';
		$('divTB2').style.display='none';
		$('divHistory').style.display='none';
		$('divSearch').style.display='';
		rightBody_w=286;
		rightToolBar_w=0;
		rightMain_w=rightBody_w+rightToolBar_w+11;
		$('divRightMain').style.left=bodyWidth-rightMain_w+'px';
	}
	try{
		
		$('divRightMain').style.left=rightMain_l[type]+'px';
	}catch(e){
		//$('divRightMain').style.left='0px'
	}
	//$('divRight').style.left=bodyWidth-rightMain_w+'px';
	$('divMapNav').style.width=(bodyWidth-rightMain_w)+'px';
	$('divMapNav').style.height=(bodyHeight-88)+'px';
	menuImgSwitch();
	mapResize(allShow,rightBodyShow[mainMenu]);
}

function menuImgSwitch()
{
	$('nodivFullScreen').style.left=bodyWidth-20+'px';

	if(rightBodyShow[mainMenu]){
		$('divFullScreen').style.left=bodyWidth-(rightMain_w+24)+'px';
		$('menuSwitch1').src='images/yin.gif';
	}
	else{
		$('divFullScreen').style.left=bodyWidth-(rightMain_w+24-rightBody_w)+'px';
		$('menuSwitch1').src='images/xian.gif';
	}

	if(allShow)
		$('divFullScreen').style.display="";
	else
		$('divFullScreen').style.display="none";
}

function switchBusSearch(id){
	$('divBus1').style.display='none';
	$('divBus2').style.display='none';	
	$('divBus3').style.display='none';	
	$('divBus'+id).style.display='';	
}
function switchSearch(type){
	if(type==1){
		$('divSearchAll').style.display='';
		$('divBus').style.display='none';
		$('td_1').src='images/topso_bt1_hit.gif';
		$('td_2').src='images/topso_bt2.gif';
	}
	else{
		$('divSearchAll').style.display='none';
		$('divBus').style.display='';
		$('td_1').src='images/topso_bt1.gif';
		$('td_2').src='images/topso_bt2_hit.gif';	
	}
}
function isEmpty(fieldValue)
{
	var regEx = /\S+/i;
	if(regEx.test(fieldValue))
		return false;
	else
		return true;
}
function dosearch(form)
{
	if(form.name.value==''){
	  alert('请输入关键字');
	  form.name.focus();
	  return false;
	}
	else{
		form.action = 'search.jspa';
		form.target = 'ifrSearch';
		menuSwitch('search');
	}
	return true;
}
function doquery1()
{
    if (isEmpty(document.query1.from.value))
	{
   	   alert('起始不能为空');
	   document.query1.from.focus();
      return false;
     }
	 else if (isEmpty(document.query1.to.value ))
	 {
   	   alert('终点不能为空');
	   document.query1.to.focus();
       return false;
     }else
	 {
	    document.query1.action = 'search.jspa';
		document.query1.target = 'ifrSearch';
		menuSwitch('search');
	 }
	 return true;
 } 
function doquery2()
{  
     if (isEmpty(document.query2.name1.value ))
	{
   	   alert('站点不能为空');
	   document.query2.name1.focus();
       return false;
     }else
	 {
	    document.query2.action = 'search.jspa?_flowId=busListByStation';
		document.query2.target = 'ifrSearch';
		menuSwitch('search');
	 }
	 return true;
 }
function doquery3()
{
     if (isEmpty(document.query3.name.value ))
	 {
   	   alert('路线不能为空');
	   document.query3.name.focus();
      return false;
     }else
	 {
	    document.query3.action = 'search.jspa?_flowId=busListByLine';
		document.query3.target = 'ifrSearch';
		menuSwitch('search');
	 }
	 return true;
 } 

function dosearch1(form)
{
	if(form.name.value==''){
	  alert('请输入关键字');
	  form.name.focus();
	  return false;
	}
	var objectpage =  '/'+document.popo.infoType.value;
	if ((objectpage == null)||(objectpage =="")){
		alert("请选择要查找的类型");
		document.popo.infoType.focus();
		return false;
	}
	else{
		document.popo.action = objectpage;
		document.popo.target = "ifrSearch";
		//document.popo.submit();
		menuSwitch('search');
	}
	return true;
}

var maptype=3;
function changeMapType(id){
	if(getNavStatus()||id==maptype) return;
	if(maptype!=0) $('maptype'+maptype).className='botton_unhit';
	$('maptype'+id).className='botton_hit_blue';
	maptype=id;
	popomap.changeMapType(id);
}

function loadSign(id){
	if(getNavStatus()) return;
	var src=$('tdSign'+id);
	var value=false;
	if(src.className=='botton_unhit'){
		src.className='botton_hit_blue';
		value=true;
	}
	else{
		src.className='botton_unhit';
		value=false;
	}
	switch(id){
		case 1:
			break;
		case 2:
			if(value) popomap.loadSign('BusStation');
			else popomap.removeSign('BusStation');
			break;
		case 3:
			break;
		default:
			break;
	}
}


function changeUrl(flag1,flag2){
	if(flag1) menuSwitch('city');
	changePanel('divRightBody');
	if(flag2&&$('ifrCity').src!='maphelp.htm') 
		$('ifrCity').src='maphelp.htm';
	else if($('ifrCity').src!='shangjia.htm')
		$('ifrCity').src='shangjia.htm';
}

function changeComType(id,noExpand){
	if(!isNaN(id)) {
		comTypeId=id;
		$('ifrCity').src='/search.jspa?_flowId=unitListBySort&sort1='+comTypeId;
	}
	else{
		$('ifrCity').src='shangjia.htm';
	}
	changePanel('divRightBody');
	if(!noExpand&&!rightBodyShow[mainMenu]) showRightBody();
}

function changenews(id,noExpand){
	if(!isNaN(id)) boardid=id;
	if(id!=0)
		$('ifrNews').src='/mutual/message.jspa?_flowId=list&type='+boardid;
	else 
		$('ifrNews').src='/mutual/message.jspa?_flowId=list';
	if(!noExpand&&!rightBodyShow[mainMenu]) showRightBody();
}

function changePanel(id){
	$('divRightBody').style.display='none';
	$('divHistory').style.display='none';
	$(id).style.display='';
}

function mapResize(a,b){
	if(!a){
		mapRZ(0,0,bodyWidth,bodyHeight);
		return;
	}
	if(b){
		mapRZ(0,90,bodyWidth-rightMain_w-1,bodyHeight-88);
	}
	else{
		mapRZ(0,90,bodyWidth-rightToolBar_w-12,bodyHeight-88);
	}
}

function mapRZ(a,b,c,d){
	$('divMap').style.left=a+'px';
	$('divMap').style.top=b+'px';
	$('divMap').style.width=c+'px';
	$('divMap').style.height=d+'px';
}

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 getNavStatus(){
	if($('divMapNav').style.display=='')
		return true;
	else 
		return false;
}

function switchNavView(){
	with($('divMapNav').style){
		display=display==''?'none':'';
	}
}

function switchMapView(){
	with($('divMap').style){
		display=display==''?'none':'';
	}
}

function showRightBody()
{
	if(getNavStatus()) return;
	if(rightBodyShow[mainMenu]){
		mapResize(true,false);
		//slowmove($('divRightMain'),$('divRightMain').offsetLeft,0,rightBody_w,0,onmove1,onend1);
		$('divRightMain').style.left=$('divRightMain').offsetLeft+rightBody_w+'px';
		$('divFullScreen').style.left=$('divFullScreen').offsetLeft+rightBody_w+'px';
		rightMain_l[mainMenu]=$('divRightMain').offsetLeft;
		rightBodyShow[mainMenu]=false;
		$('divRightBody').style.display='none';
		$('menuSwitch1').src='images/xian.gif';
	}
	else if(!rightBodyShow[mainMenu]){
		$('divRightBody').style.display='';
		//slowmove($('divRightMain'),$('divRightMain').offsetLeft,0,0,0,onmove1,onend2);
		$('divRightMain').style.left=$('divRightMain').offsetLeft-rightBody_w+'px';
		$('divFullScreen').style.left=$('divFullScreen').offsetLeft-rightBody_w+'px';
		rightMain_l[mainMenu]=$('divRightMain').offsetLeft;
		rightBodyShow[mainMenu]=true;
		mapResize(true,true);
		$('menuSwitch1').src='images/yin.gif';
	}
}
function slowmove(target,x1,y1,x2,y2,onmove,onend){
	var sx=(x2-x1)/5;
	var sy=(y2-y1)/5;
	var mytimer=window.setInterval(fun,20);
	var stepnum=0;
	
	function fun(){
		if(stepnum++==5){
			window.clearInterval(mytimer);
			mytimer=null;
			if(onend) onend(target);
			return;
		}
		if(target.offsetLeft==x2) sx=0;
		if(target.offsetTop==y2) sy=0;
		if(Math.abs(x2-target.offsetLeft)<=Math.abs(sx)) sx=x2-target.offsetLeft;
		if(Math.abs(y2-target.offsetTop)<=Math.abs(sy)) sy=y2-target.offsetTop;
		target.style.left=(target.offsetLeft+sx)+'px';
		target.style.top=(target.offsetTop+sy)+'px';
		if(onmove)onmove(target);
	}
}


function showAll()
{
	if(allShow) return;
	$('divRightMain').style.display='';
	$('divTop').style.display='';
	$('divFullScreen').style.display='';
	switch(mainMenu){
		case 'city':
			$('divTB').style.display='';
			break;
		case 'bbs':
			$('divTB2').style.display='';
			break;
		case 'search':
			break;
		default:
			break;
	}
	topShow=true;
	rightShow=true;
	allShow=true;
	mapResize(allShow,rightBodyShow[mainMenu]);
	return;
}
function hiddenAll()
{
	if(getNavStatus()) return;
	if(!allShow) return;
	$('divRightMain').style.display='none';
	$('divTop').style.display='none';
	$('divFullScreen').style.display='none';
	switch(mainMenu){
		case 'city':
			$('divTB').style.display='none';
			break;
		case 'bbs':
			$('divTB2').style.display='none';
			break;
		case 'search':
			break;
		default:
			break;
	}
	topShow=false;
	rightShow=false;
	allShow=false;
	mapResize(false);
	//menuImgSwitch();
	return;
}

function downToolbar()
{
	if(parseInt($('divToolBar').style.top)>=16) return;
	$('divToolBar').style.top=parseInt($('divToolBar').style.top)+50+'px';
	//setTimeout('downToolbar()',10);
}
function upToolbar()
{
	if(parseInt($('divToolBar').style.top)+520<=500) return;
	$('divToolBar').style.top=parseInt($('divToolBar').style.top)-50+'px';
	//setTimeout('upToolbar()',10);
}


function killErrors() { 
return true; 
} 
//window.onerror = killErrors; 