// JavaScript Document

var map, point, marker, isSubmitsRead;

function mapLoad(cenx, ceny, cenz){		  
  isSubmitsRead = 0;
  map = new BMap.Map("container");
  point = new BMap.Point(Number(cenx), Number(ceny));
  map.centerAndZoom(point, Number(cenz));
  map.enableScrollWheelZoom();
  map.addControl(new BMap.NavigationControl());
  map.addControl(new BMap.ScaleControl());
  map.addControl(new BMap.OverviewMapControl({isOpen:1}));
  var myCopyright = new BMap.CopyrightControl({ offset: new BMap.Size(185, 0) }) //设置版权信息偏移量    
  map.addControl(myCopyright); //为地图添加版权控件    
  myCopyright.addCopyright({ id: 1, 
  content: '<a href="http://www.www.workyi.com" target="_blank" style="color:#000000;"><img src="http://www.workyi.com/images/logo.gif" border="0" /> 工作易人才系统，为大型招聘网站及政府人事局所推荐的专业安全的人才系统平台。</a>' })
  map.addEventListener("zoomend", function(){Coordinate();isSubmits();}); // 地图深度改变时
  map.addEventListener("moveend", function(){Coordinate();isSubmits();}); // 地图移动后
  map.addEventListener("dragend", function(){Coordinate();isSubmits();}); // 停止拖拽地图时触发
  Coordinate();
}

function Coordinate(){
	document.getElementById("minX").value = map.getBounds().getSouthWest().lng;
	document.getElementById("maxX").value = map.getBounds().getNorthEast().lng;
	document.getElementById("minY").value = map.getBounds().getSouthWest().lat;
	document.getElementById("maxY").value = map.getBounds().getNorthEast().lat;
    document.getElementById("cenx").value = map.getCenter().lng;
	document.getElementById("ceny").value = map.getCenter().lat;
	document.getElementById("cenz").value = map.getZoom();
}

function isSubmits(){
	if(isSubmitsRead == 0){
	  isSubmitsRead = 1;
	  document.form1.submit();
	}
}


//function show_search(id, name, x, y, z){
//  myIcon = new BMap.Icon("images/home.gif", new BMap.Size(20, 15), {});
//  marker = new BMap.Marker(new BMap.Point(Number(x), Number(y)), {icon: myIcon});
//  map.addOverlay(marker);
//  label = new BMap.Label(name+"",{"offset":new BMap.Size(20,0)});
//  label.setStyle({
//	border:"0px solid white",	
//	background:"#39d15a",
//	color : "white",
//	padding:"1px 1px 1px 1px",
//	fontSize : "12px",
//	cursor:"pointer"
//  })
//  marker.setLabel(label);
//  label.setTitle(name+"");
//  marker.setTitle(name+"");
//  
//  label.addEventListener("click", function(){OpenList(id)});
//  var infoWindow = new BMap.InfoWindow("<p style='font-size:14px;'>"+name+"</p><p style='font-size:14px;'>"+name+"</p>");
//  marker.addEventListener("click", function(){this.openInfoWindow(infoWindow);});
//}

function show_search(id, name, x, y, z, pname) {
  myIcon = new BMap.Icon("images/none.png", new BMap.Size(0, 0), {});
  marker = new BMap.Marker(new BMap.Point(Number(x), Number(y)), {icon: myIcon});
  map.addOverlay(marker);

  var str = "<table onMouseEnter=\"this.rows[0].cells[0].innerHTML='<img src=images/b1.png>'; this.rows[0].cells[1].style.background='url(images/b2.png)'; this.rows[0].cells[1].innerHTML='<a href=/Company_Lookzl/pn-" + pname + ".html target=_blank class=wz>" + name + "</a>'; this.rows[0].cells[2].innerHTML='<img src=images/b3.png>'; this.rows[1].cells[0].innerHTML='<img src=images/b4.png>';\" onMouseLeave=\"this.rows[0].cells[0].innerHTML='<img src=images/a1.png>'; this.rows[0].cells[1].style.background='url(images/a2.png)'; this.rows[0].cells[1].innerHTML='" + name + "'; this.rows[0].cells[2].innerHTML='<img src=images/a3.png>'; this.rows[1].cells[0].innerHTML='<img src=images/a4.png>';\" border='0' cellpadding='0' cellspacing='0'><tr><td><img src='images/a1.png'></td><td style='background:url(images/a2.png); color:white; font-size:12px; white-space:nowrap;'>" + name + "</td><td><img src='images/a3.png'></td></tr><tr><td colspan='3' style='text-align:left;'><img src='images/a4.png'></td></tr></table>";
  
  var label = new BMap.Label(str,{offset:new BMap.Size(0,0)});
  label.setStyle({
	background:"transparent",
	border:"none"	
  });
  
  marker.setLabel(label);
  //mouseover  mouseout    onMouseEnter   onMouseLeave
//  label.addEventListener("click", function(){
//	OpenList(id);
//  });

}


function OpenList(id){
  document.getElementById("HTML_window").style.display = "block";
  var a = parseInt(document.documentElement.scrollWidth)/2;
  var b = parseInt(document.getElementById("HTML_window").style.width)/2;
  document.getElementById("HTML_window").style.left = (a-b)+"px";
  a = parseInt(document.documentElement.clientHeight)/2;
  b = parseInt(document.getElementById("HTML_window").style.height)/2;
  document.getElementById("HTML_window").style.top = (a+document.documentElement.scrollTop+document.body.scrollTop-b)+"px";
  
  var xmlhttp = false;
  try{
	xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  }catch (e){
	try{
	  xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}catch(E){
	  xmlhttp = false;
	}
  }
  if((!xmlhttp) && (typeof XMLHttpRequest != 'undefined')){
	 xmlhttp = new XMLHttpRequest();
  }
  if(!xmlhttp){alert("您的浏览器不支持该ajax，部分功能失效。");} 
  
  
  xmlhttp.open("POST", "ajax.aspx", false);
  xmlhttp.onreadystatechange = function(){
    if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
	  var rText = xmlhttp.responseText;
      document.getElementById("HTML_Content").innerHTML = rText;
	}
  }
  xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); 
  xmlhttp.send("id="+id+"");
  xmlhttp.close;
  
}

function html_close_window(){
  document.getElementById('HTML_window').style.display = 'none';
}

function clearAll(cenx, ceny, cenz){
  mapLoad(cenx, ceny, cenz)
}

mapLoad("118.652639", "39.638148", "5")

function search(xType, xValue) { 
  document.getElementById(xType).value = xValue;
  document.form1.submit();
  switch (xType){
    case "txtLeiXing":
	  document.getElementById("DIVleixingTitle").innerHTML = xValue;
	  break;	   
    case "txtXueli":
	  document.getElementById("DIVxueliTitle").innerHTML = xValue;
	  break;	   
  }
  var links = document.all.tags("A");
  var total = links.length;
  var url;
  var arr;
  for (i=0;i<total;i++){
	url = links[i].href;
	if(url.indexOf("javascript:search")>=0){
	  url = url.replace("javascript:search('", "");
	  url = url.replace("');", "");
	  arr = url.split("', '");
	  links[i].className = (document.getElementById(arr[0]).value == arr[1]) ? "hrefChecked" : "hrefDefault";
	} 
  }
  document.write("<font size='2'>"+str+"</font>")
}

function DivShowToHide(xName){
  if(document.getElementById("DIV"+xName+"Title").className == "DivTitle1"){
	document.getElementById("DIV"+xName+"Title").className = "DivTitle0";	
	document.getElementById("DIV"+xName+"").style.display = "none";
  }else{
	document.getElementById("DIV"+xName+"Title").className = "DivTitle1";	
	document.getElementById("DIV"+xName+"").style.display = "block";
  }
} 

function select2_onchange(city){
  map.centerAndZoom(city);
  //map.centerAndZoom(new BMap.Point(Number(x), Number(y)), Number(z));
}
document.form1.submit();		  
