var wikilinkno;
var xmlHttp;
var currentPos = null;
var FLAG = "/wiki/";
//显示词条内容中有效的词条内部链接的摘要        
var firstimgData;
var firstimg;
var headp;
var dataDiv;
var dataTable;
var dataTableBody;
var summary;
var curX=0,curY=0;
var gDivMoveFlag = false;//是否需要移动DIV
var gDisplayFlag = false;//是否需要钉住DIV
var gUpdateFlag = true;//是否需要更新DIV中的数据
var gDoctitle = null;//当前词条的标题
var gCurWidth=0,gCurHeight=0;//鼠标和DIV的坐标的差值。
var gMouseOverFlag = false;//鼠标在DIV中
var gMouseOutFlag = true;//鼠标在文字中
window.onload=initVars;

function send_request(url) {
  xmlHttp = false;
  createXMLHttpRequest();
  xmlHttp.onreadystatechange = processRequest;
  xmlHttp.open("GET", url, true);
  xmlHttp.send(null);
}
// 处理返回信息的函数
  function processlinks(){
      var links=document.links;
      var total=links.length;
      for (i=0;i<total;i++){
         var vhref=null;
         try{
           vhref=links[i].href;
           if(IE){cssName=links[i].getAttribute("className");}else{cssName=links[i].getAttribute("class");}
           if(cssName!="innerlink")continue;
         } catch (e){
           continue;
         }
         if(vhref!=null){
           if (vhref.indexOf("/wiki/")!=-1){
                wikilinkno="wikilink"+i;  
             if(IE){
               links[i].onmouseover=handle_mouseover_IE;
               links[i].setAttribute("target","_blank");
               links[i].onmouseout=function (){setTimeout("closeDiv()",500);gUpdateFlag = true;gMouseOutFlag = true;}
             }else{
               links[i].setAttribute("target","_blank");
               links[i].setAttribute("id",wikilinkno);
               links[i].onmouseover = handle_mouseover;
               links[i].onmouseout=function (){setTimeout("closeDiv()",500);gUpdateFlag = true;gMouseOutFlag = true;}
             }
           }
         }
      }
  }
function handle_mouseover_IE()
{gMouseOutFlag = false;
  if (!gUpdateFlag)  return;
  showDocSummary_IE(this);
  gUpdateFlag = false;
}
function handle_mouseover()
{gMouseOutFlag = false;
  if (!gUpdateFlag)  return;
  showDocSummary();
  gUpdateFlag = false;
}


function initVars() {
  if (document)
    dataTableBody = document.getElementById("summaryDataBody");           
    //dataTable = document.getElementById("summaryData");
    dataDiv = document.getElementById("popup");
    headp = document.getElementById("headp");
    if(dataDiv!=null)
    {
	    dataDiv.onmouseleave = onMouseLeave;  
	    dataDiv.onmousedown = onMouseDown;
	    dataDiv.onmouseup = onMouseUp;
	    dataDiv.onmouseover = onMouseOver;
	    document.onmousemove = onMouseMove;
	    processlinks();
    }
}
//当鼠标进入DIV中时，打开标记
function onMouseOver(){
	gMouseOverFlag = true;
}
//当鼠标离开时，除钉住或正在移动外，关闭DIV
function onMouseLeave(){
  gMouseOverFlag = false;
  if (gDisplayFlag || gDivMoveFlag || !gMouseOutFlag) return ; 
    clearData();
}
//当鼠标离开内链接文字时，除钉住或正在移动外，关闭DIV
function closeDiv(){
  if (gDisplayFlag || gDivMoveFlag || gMouseOverFlag || !gMouseOutFlag) return ; 
    clearData();
}
//当鼠标在DIV中按下时，1.移动DIV标记打开，2.记录鼠标和DIV的坐标的差值，3.更改鼠标的形状，4.禁止鼠标选中对象
function onMouseDown(){
  gDivMoveFlag = true;
  if(IE==true)
    getCursor(event);
  else {  
    try {
     window.constructor.prototype.__defineGetter__("event", window_prototype_get_event);
    }catch(e) {}
  
    curX = event.pageX;
    curY = event.pageY; 
  }
  gCurWidth = curX - parseInt(dataDiv.style.left);
  gCurHeight = curY - parseInt(dataDiv.style.top);//alert(gCurWidth+"  "+gCurHeight);
  dataDiv.style.cursor="hand";
  document.onselectstart=new Function("event.returnValue=false");
}
//当鼠标在DIV中松开时，1.移动DIV标记关闭，2.更改鼠标的形状，3.取消禁止鼠标选中对象
function onMouseUp(){
  gDivMoveFlag = false;
  dataDiv.style.cursor="default";
  document.onselectstart=new Function("event.returnValue=true");
} 
//当鼠标移动并且移动DIV标记打开时，移动DIV
function onMouseMove(){       
  if (!gDivMoveFlag)
    return ; 
  if(IE==true)
    getCursor(event);
  else {  
    try {
     window.constructor.prototype.__defineGetter__("event", window_prototype_get_event);
    }catch(e) {}
  
    curX = event.pageX;
    curY = event.pageY; 
  }
  dataDiv.style.left = (curX-gCurWidth) + "px";
  dataDiv.style.top = (curY-gCurHeight) + "px";
}
function showDocSummary(){
  try {
   window.constructor.prototype.__defineGetter__("event", window_prototype_get_event);
  }catch(e) {}

  curX = event.pageX;
  curY = event.pageY;
   var tempObj = event.target;
	var docTitle=tempObj.firstChild.data;
	if (0 == docTitle.Trim().length) return;
	while(tempObj.nodeName.toUpperCase() != "A"){
		tempObj = tempObj.parentNode;
	}  
  createXMLHttpRequest();
  var docTitle = 	tempObj.innerText;
  gDoctitle = docTitle;
  var url = "/validateDocSummary.do?doc_title="+encodeURI(docTitle);
  xmlHttp.open("GET", url, true);
  xmlHttp.onreadystatechange = callback;
  xmlHttp.send(null);
}
        
function window_prototype_get_event()
{
 var func = arguments.callee.caller; 
 var evt; 
 while(func != null){
  evt = func.arguments[0]; 
  if(evt && (evt.constructor == Event || evt.constructor == MouseEvent)) return evt; 
  func = func.caller; 
 } 
 return null; 
}       
      
function showDocSummary_IE(element,event) {
    getCursor(event);           
    createXMLHttpRequest();
	docTitle=element.innerText;
	if (docTitle==gDoctitle && dataDiv.style.visibility == "visible")	return;
	gDoctitle = docTitle;  
    var url = "/validateDocSummary.do?doc_title="+encodeURI(gDoctitle);
    xmlHttp.open("GET", url, true);
    xmlHttp.onreadystatechange = callback;
    xmlHttp.send(null);
}
        
function callback() {
   if (xmlHttp.readyState == 4) {
     if (xmlHttp.status == 200) {
         try{setData(xmlHttp.responseXML);
          }catch(e){}
     }
   }
}
        

function setData(courseData) {          
	var ind = dataTableBody.childNodes.length;            
	for (var i = ind - 1; i >= 0 ; i--) {
	    dataTableBody.removeChild(dataTableBody.childNodes[i]);       
	}

	dataDiv.style.visibility ="visible";
	var flag = xmlHttp.responseXML.getElementsByTagName("flag")[0].firstChild.data;
	var doctitle = xmlHttp.responseXML.getElementsByTagName("doctitle")[0].firstChild.data;
	var docid = xmlHttp.responseXML.getElementsByTagName("docid")[0].firstChild.data;
	 summary=xmlHttp.responseXML.getElementsByTagName("summary")[0].firstChild.data;
	 firstimg=xmlHttp.responseXML.getElementsByTagName("firstimg")[0].firstChild.data;
	var doctitleData = "";
	var summaryData = "";
	var firstimgData="";

	//Add head information
	closeData = constructHead();
	headp.innerHTML=closeData;
	//dataTableBody.appendChild(createRow(closeData));

	//Add content information
	if(flag=="false"){
	 // dataTable.setAttribute("width", "200");
	  //dataTableBody.setAttribute("width", "280px");            
    //dataDiv.setAttribute("width", "290px"); 
	  setOffsets();
	  doctitleData="<tr><td width=\"300\" bgcolor=\"#F9F7F7\" align=\"center\"><br><br><a href=\"/createDocAuth.do?doc_title="+encodeURI(gDoctitle)+"\"><font size='2' color='red' >词条不存在,请点击创建!</font></a><br><br><br></td></tr>";
	    dataTableBody.innerHTML="<p style=\"padding:5px; margin:0;\"><a href=\"/createDocAuth.do?doc_title="+encodeURI(gDoctitle)+"\"><font size='2' color='red' >词条不存在,请点击创建!</font></a></p>"; 
	  //dataTableBody.appendChild(createRow(constructContent(doctitleData, "")));
	} 

	if(flag=="true"){
	 // dataTable.setAttribute("width", "300");
	 	//dataTableBody.setAttribute("width", "280px");            
   // dataDiv.setAttribute("width", "290px"); 
	  setOffsets();
	  //Add image information
	  if(firstimg!="null"){
	    firstimgData = constructIamge(firstimg);
	  }
	  
	  //Add content information            
	   summaryData = constructSummary(firstimgData+summary);  
	   dataTableBody.innerHTML= summaryData;     			
	  //dataTableBody.appendChild(createRow(constructContent(firstimgData, summaryData)));
	}
}
        //Add head information
function constructHead() { 
    var closeData = "";
    var doctitle = (gDoctitle.length > 10)? (gDoctitle.substring(0, 10)+"...") : gDoctitle;
	var imgscr = (gDisplayFlag == true)? "http://www.hudong.com/images/momo/tudinged_normal.gif" :"http://www.hudong.com/images/momo/tuding_normal.gif";
    if (IE)
    	//closeData = "<td><table width=\"315\"  border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\"><tr><td width=\"4\" bgcolor=\"#D1E7FC\"></td><td width=\"19\" bgcolor=\"#D1E7FC\"><div align=\"center\"><img src=\"http://www.hudong.com/images/momo/momo_3.gif\" width=\"13\" height=\"13\" /></div></td><td width=\"252\" bgcolor=\"#D1E7FC\" class=\"momozth\"><a href=\"http://www.hudong.com/wiki/"+encodeURI(gDoctitle)+"\"><font color=\"#ff0000\">"+ doctitle+"</font></a></td><td width=\"145\" bgcolor=\"#D1E7FC\">&nbsp;</td><td width=\"21\" bgcolor=\"#D1E7FC\"><img src=\""+ imgscr +"\" onmouseover=\"changImgholdStatus_IE(this)\" onmouseout=\"changImgholdStatus_IE(this)\" onclick=\"changImgholdType_IE(this);\" width=\"12\" height=\"10\" /></td><td width=\"23\" bgcolor=\"#D1E7FC\"><img src=\"http://www.hudong.com/images/momo/guanbi_normal.gif\" onmouseover=\"changImgcloseStatus_IE(this)\" onmouseout=\"changImgcloseStatus_IE(this)\" onclick=\"clearData()\" width=\"14\" height=\"14\" /></td><td width=\"4\" bgcolor=\"#D1E7FC\"></td></tr></table></td>";
    closeData = "<span style=\"float:left; font-size:12px; margin-left:5px;\"><img src=\"http://www.hudong.com/images/momo/momo_3.gif\" align=\"absmiddle\" /><a href=\"http://www.hudong.com/wiki/"+encodeURI(gDoctitle)+"\"target=\"_blank\" style=\" color:#FF0000; text-decoration: none;\">"+ doctitle+"</a></span><span style=\"float:right; margin-right:5px;\"><img src=\"http://www.hudong.com/images/momo/guanbi_normal.gif\" border=\"0\"onmouseover=\"changImgcloseStatus_IE(this)\" onmouseout=\"changImgcloseStatus_IE(this)\" onclick=\"clearData()\" width=\"14\" height=\"14\" /></span>";
    else  
       // closeData = "<td><table width=\"315\"  border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\"><tr><td width=\"4\" bgcolor=\"#D1E7FC\"></td><td width=\"19\" bgcolor=\"#D1E7FC\"><div align=\"center\"><img src=\"http://www.hudong.com/images/momo/momo_3.gif\" width=\"13\" height=\"13\" /></div></td><td width=\"152\" bgcolor=\"#D1E7FC\" class=\"momozth\"><a href=\"http://www.hudong.com/wiki/"+encodeURI(gDoctitle)+"\"><font color=\"#ff0000\">"+doctitle+"</font></a></td><td width=\"145\" bgcolor=\"#D1E7FC\">&nbsp;</td><td width=\"21\" bgcolor=\"#D1E7FC\"><img src=\""+ imgscr +"\" onmouseover=\"changImgholdStatus()\" onmouseout=\"changImgholdStatus()\" onclick=\"changImgholdType();\" width=\"12\" height=\"10\" /></td><td width=\"23\" bgcolor=\"#D1E7FC\"><img src=\"http://www.hudong.com/images/momo/guanbi_normal.gif\" onmouseover=\"changImgcloseStatus()\" onmouseout=\"changImgcloseStatus()\" onclick=\"clearData()\" width=\"14\" height=\"14\" /></td><td width=\"4\" bgcolor=\"#D1E7FC\"></td></tr></table></td>";
     closeData = "<span style=\"float:left; font-size:12px; margin-left:5px;\"><img src=\"http://www.hudong.com/images/momo/momo_3.gif\" align=\"absmiddle\" /><a href=\"http://www.hudong.com/wiki/"+encodeURI(gDoctitle)+"\"target=\"_blank\" style=\" color:#FF0000; text-decoration: none;\">"+ doctitle+"</a></span><span style=\"float:right; margin-right:5px;\"><img src=\"http://www.hudong.com/images/momo/guanbi_normal.gif\" border=\"0\" onmouseover=\"changImgcloseStatus()\" onmouseout=\"changImgcloseStatus()\" onclick=\"clearData()\" width=\"14\" height=\"14\" /></span>";
    return closeData;
    
}
function constructIamge(v_imgscr) { 
  if(v_imgscr != "null"){
  	firstimgData ="<a href=\"http://www.hudong.com/wiki/"+encodeURI(gDoctitle)+"\" target=\"_blank\"><img src=\""+v_imgscr+"\" width=\"98\" height=\"74\" border=\"0\" style=\"float:left; margin:5px;\" /></a>";
  	//firstimgData ="<tr><td colspan=\"2\" bgcolor=\"#F9F7F7\"  align=\"center\"><img src=\""+ v_imgscr +"\" width=\"84\" height=\"64\" vspace=\"10\" /></td></tr>";
  }
  return firstimgData
}
function constructSummary(v_summary) {
  var summaryData=""; 
  if(v_summary == "null") 
    // summaryData = "<tr><td width=\"4\" bgcolor=\"#F9F7F7\"></td><td bgcolor=\"#F9F7F7\" class=\"momozt12\"><br>&nbsp;&nbsp;&nbsp;&nbsp;<b>摘要：</b>无</td></tr>";
    summaryData = "<p style=\"padding:5px; margin:0;\">摘要：无</p>";
  else   
     //summaryData = "<tr><td width=\"4\" bgcolor=\"#F9F7F7\"></td><td bgcolor=\"#F9F7F7\" class=\"momozt12\"><br>&nbsp;&nbsp;&nbsp;&nbsp;<b>摘要：</b>"+ v_summary +"...</td></tr>";
  summaryData="<p style=\"padding:5px; margin:0;\">"+v_summary+"<a href=\"http://www.hudong.com/wiki/"+encodeURI(gDoctitle)+"\" target=\"_blank\" style=\"color:#0033CC;\">查看详情&gt;&gt;</a></p>";
  return summaryData;    
} 
function constructContent(v_img, v_summary) {
	var head = "<tr><td colspan=\"8\" valign=\"top\" background=\"http://www.hudong.com/images/momo/momobg.gif\"><table width=\"98%\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\"><tr><td height=\"3\"></td></tr><tr><td><table class=\"biankuangmomo\" width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";
		var end = "<tr><td height=\"4\" colspan=\"2\" bgcolor=\"#F9F7F7\"></td></tr></table></td></tr><tr><td height=\"2\"></td></tr></table></td>";
		return head+v_img+v_summary+end;
}               
function createRow(v_data) {            
    var row, cell, txtNode;
    row = document.createElement("tr");
    cell = document.createElement("td");
    cell.innerHTML=v_data;
    row.appendChild(cell);
    return row;  
}
        
function setOffsets() {
	if (gDisplayFlag)
    	return;
    //返回相对于当前用户点击位置那一块面积最大，弹出框就显示在那里0:左上1：右上2：左下3：右下
   // alert(summary.length);
   if(summary.length>30&&firstimg!="null"){
  switch(biggestArea()){
  	case 0:
  		dataDiv.style.left = (curX-320) + "px";
  		dataDiv.style.top = curY-202+ "px";
  	break;
  	case 1:
  		dataDiv.style.left = curX +20+ "px";
  		dataDiv.style.top = curY -202+ "px";
  	break;
  	case 2:
  		dataDiv.style.left = (curX-320) + "px";
  		dataDiv.style.top = curY-5+ "px";
  	break;
  	case 3:
  		dataDiv.style.left = (curX+30) + "px";
  		dataDiv.style.top = curY -5+ "px";
  	break;
  }
}else if(summary.length>30&&firstimg=="null"){
	switch(biggestArea()){
  	case 0:
  		dataDiv.style.left = (curX-320) + "px";
  		dataDiv.style.top = curY-165+ "px";
  	break;
  	case 1:
  		dataDiv.style.left = curX +20+ "px";
  		dataDiv.style.top = curY -155+ "px";
  	break;
  	case 2:
  		dataDiv.style.left = (curX-320) + "px";
  		dataDiv.style.top = curY-5+ "px";
  	break;
  	case 3:
  		dataDiv.style.left = (curX+30) + "px";
  		dataDiv.style.top = curY -5+ "px";
  	break;
  }
	}else{
	switch(biggestArea()){
  	case 0:
  		dataDiv.style.left = (curX-320) + "px";
  		dataDiv.style.top = curY-84+ "px";
  	break;
  	case 1:
  		dataDiv.style.left = curX +15+ "px";
  		dataDiv.style.top = curY -88+ "px";
  	break;
  	case 2:
  		dataDiv.style.left = (curX-300) + "px";
  		dataDiv.style.top = curY-5+ "px";
  	break;
  	case 3:
  		dataDiv.style.left = (curX+25) + "px";
  		dataDiv.style.top = curY -5+ "px";
  	break;
	}
}
}
        
function clearData() {         
    var ind = dataTableBody.childNodes.length;            
    for (var i = ind - 1; i >= 0 ; i--) {
        dataTableBody.removeChild(dataTableBody.childNodes[i]);       
    }
    dataDiv.style.visibility ="hidden";
    gDisplayFlag =false;
}        


      
function changImgcloseStatus_IE(v_scr)
{
	var imgScr = v_scr.src;
	var head = imgScr.substring(0, imgScr.lastIndexOf("/")+1);

	if (imgScr.substring(imgScr.lastIndexOf("/")+1, imgScr.length) == "guanbi_normal.gif")
		v_scr.src = head + "guanbi_over.gif";
	else
		v_scr.src = head + "guanbi_normal.gif";
}
function changImgholdStatus_IE(v_scr)
{
	var imgScr = v_scr.src;
	var head = imgScr.substring(0, imgScr.lastIndexOf("_")+1);

	if (imgScr.substring(imgScr.lastIndexOf("_")+1, imgScr.length) == "normal.gif")
		v_scr.src = head + "over.gif";
	else
		v_scr.src = head + "normal.gif";
}
function changImgholdType_IE(v_scr)
{
	gDisplayFlag = (gDisplayFlag == true)? false :true;
	
	var imgScr = v_scr.src;
	var head = imgScr.substring(0, imgScr.lastIndexOf("/")+1);
  var imgName = imgScr.substring(imgScr.lastIndexOf("/")+1, imgScr.length);
	if (imgName == "tudinged_over.gif")
		v_scr.src = head + "tuding_over.gif";
	else
		v_scr.src = head + "tudinged_over.gif";
}
function changImgcloseStatus()
{
  try {
   window.constructor.prototype.__defineGetter__("event", window_prototype_get_event);
  }catch(e) {} 
  var v_scr = event.target;
   
	var imgScr = v_scr.src;
	var head = imgScr.substring(0, imgScr.lastIndexOf("/")+1);

	if (imgScr.substring(imgScr.lastIndexOf("/")+1, imgScr.length) == "guanbi_normal.gif")
		v_scr.src = head + "guanbi_over.gif";
	else
		v_scr.src = head + "guanbi_normal.gif";
}
function changImgholdStatus()
{
	try {
	window.constructor.prototype.__defineGetter__("event", window_prototype_get_event);
	}catch(e) {} 
	var v_scr = event.target;
	var imgScr = v_scr.src;
	var head = imgScr.substring(0, imgScr.lastIndexOf("_")+1);
	if (imgScr.substring(imgScr.lastIndexOf("_")+1, imgScr.length) == "normal.gif")
		v_scr.src = head + "over.gif";
	else
		v_scr.src = head + "normal.gif";
}
function changImgholdType()
{
	gDisplayFlag = (gDisplayFlag == true)? false :true;
	try {
	 window.constructor.prototype.__defineGetter__("event", window_prototype_get_event);
	}catch(e) {} 
	var v_scr = event.target;
	var imgScr = v_scr.src;
	var head = imgScr.substring(0, imgScr.lastIndexOf("/")+1);
	var imgName = imgScr.substring(imgScr.lastIndexOf("/")+1, imgScr.length);
	if (imgName == "tudinged_over.gif")
		v_scr.src = head + "tuding_over.gif";
	else
		v_scr.src = head + "tudinged_over.gif";
}

 
 
//词条投票处理
//var xmlHttp;
function doDig(doc_id_en){
  digURL='/digDoc.do?doc_id_en='+encodeURI(doc_id_en);
  //xmlHttp = createXMLHttpRequestByObject(xmlHttpdoDig);
  createXMLHttpRequest();
  xmlHttp.open("GET", digURL, true);
  xmlHttp.onreadystatechange = callbackdig;
  xmlHttp.send(null);  
}
        
function callbackdig() {
   if (xmlHttp.readyState == 4) {
      if (xmlHttp.status == 200) {
        setDig(xmlHttp.responseXML);
        xmlHttp=null;
      }
  }
}
    
function setDig(votedata){
 var flag =votedata.getElementsByTagName("flag")[0].firstChild.data;
 switch(parseInt(flag))
 {
 	 case 0:
 	    var prevotenum = parseInt(document.getElementById("votenum").innerHTML);
 	    var afvotenum = prevotenum+1;
 	    document.getElementById("votenum").innerHTML=afvotenum;
 	    var upbutton = document.getElementById("upbutton");
 	    upbutton.onclick=function(){
 	            var tip = document.getElementById("tip");
				tip.innerHTML="谢谢您的推荐";
				tip.className="thanks-up";
		}
		return;
        break;
 	 case 1:
 	 	  document.getElementById("tip").innerHTML="非法url";
 	 	  document.getElementById("tip").className="thanks-up";
 	 	  return;
 	 	    break;
 	 case 2:
 	 	  document.getElementById("tip").innerHTML="没有登录";
 	 	  document.getElementById("tip").className="thanks-up";
 	 	  return;
 	 	  break;
 	 case 3:
 	 	  document.getElementById("tip").innerHTML="非法url";
 	 	  document.getElementById("tip").className="thanks-up";
 	 	  return;
 	 	  break;
 	case 4:
 	 	  document.getElementById("tip").innerHTML="谢谢您的推荐";
 	 	  document.getElementById("tip").className="thanks-up";
 	 	  return;
 	 	  break;
 }   
}
//返回用户点击的条目位置为十字交叉原点，将屏幕分成四块，那一块面积最大
function biggestArea(){
	var H=curY-document.documentElement.scrollTop; //点击位置距上边距离;document.documentElement.scrollTop网页被卷去的上边距 
  var W=curX-document.documentElement.scrollLeft;//点击位置距左边距离；网页被卷去的左边距
  var JH=document.documentElement.clientHeight//-网页可见区域高
	var JW=document.documentElement.clientWidth// -网页可见区域宽:
	//比较得出最大面积是那个0:左上h*w; 1：右上h*(jw-w); 2：(jh-h)*w;左下 3：(jh-h)*(jw-w)右下
	var JWW=JW-W;
	var JHH=JH-H;
	var areaArray=[H*W,H*JWW,JHH*W,JHH*JWW];
  var maxArea=areaArray[0];
  var returnV=0;
  for(var i=1;i<areaArray.length;i++){
  	  if(maxArea>=areaArray[i]){
  	  	continue;
  	  	}else{
  	  		maxArea=areaArray[i];
  	  		returnV=i;
  	  		}
  }
	return returnV;	
	}
	
	function doOnTop(doc_id_en,state){
		createXMLHttpRequest();
		var url = "/doOnTopDoc.do?doc_id_en=" + doc_id_en  + "&is_ontop=" + state; 
		xmlHttp.open("POST", url, true);
		xmlHttp.onreadystatechange = ontop_callback;
		xmlHttp.send(null);
	}	
	
	function ontop_callback(){
		if (xmlHttp.readyState == 4){
		    if (xmlHttp.status == 200){
				var flag = xmlHttp.responseXML.getElementsByTagName("flag")[0].firstChild.data; 
				switch (flag) {// -2 不存在或已删除, -1 url 非法，0 用户权限不够，1 失败，2 成功，3 不需要改动,
			   		case "-2" :
					    alert("该话题不存在或已删除！");
					    break;
			   		case "-1" :
				   		alert("提交url不合法！");
				   		break;
			   		case "0" :
				   		alert("您没有操作向导文章置顶的权限！");
				   		break;
			   		case "1" :
				   		alert("向导文章置顶设置失败！");
				   		break;
			   		case "2" :
				   		var doontop = document.getElementById('doontop');
						var isontop = document.getElementById('isontop');
						var set_isontop = 1 - parseInt(isontop.value);
						isontop.value = set_isontop;
						if (set_isontop == 1) {
							doontop.innerHTML = "[取消置顶]";
							alert("向导文章置顶设置成功！");
						}
						if (set_isontop == 0) {
							doontop.innerHTML = "[设置置顶]";
							alert("向导文章置顶取消成功！");
						}
						doontop.onclick = function(){
							doOnTop(document.getElementById("doc_id_en_opt").value, '1', (1 - set_isontop));
						}
			   			break;
			   		case "3" :
				   		alert("向导文章置顶设置已经成功！");
				   		break;		
			   		default :   				   		
		   		}
			}
		}
	}
