var dict_is_ie = true;
var dict_host = 'http://www.agri.com.cn/';
var test_host='http://www.baidu.com/baidu?select=1&tn=richardmeng_pg&word=';
var dict_help = 'http://www.agri.com.cn/host/province/china.htm';
var dict_partner = '';
var dict_enable = true;
var dict_old_word = "";
var dict_moving = 0;
var dict_onmove = 0;
var dict_onlayer = 0;
var dict_startx = 0;
var dict_starty = 0;
var dict_cx = 0;
var dict_cy = 0;
var dict_x = 0;
var dict_y = 0;
var dict_layer;
var dict_iframe;

function dictInit(){
var agt = navigator.userAgent.toLowerCase();
  dict_is_ie = (agt.indexOf("msie")!=-1 && document.all);
  var h = '<div id="dict_layer" style="position:absolute;z-index:6000;display:none;background-color:#FFF;filter:Alpha(Opacity=96);"><table width="240" cellspacing="0" cellpadding="0" ';
  h += 'style="border-top:1px solid #7E98D6;border-left:1px solid #7E98D6;';
  h += 'border-right:1px solid #7E98D6;border-bottom:1px solid #7E98D6;';
  h += '"><tr><td>';
  h += '<div width="100%" style="cursor:move;background-color:#C8DAF3;border:0px;" onmouseover="dict_onmove=1;" onmouseout="dict_onmove=0;">' ;
  h += '<table width="100%"><tr><td align="left" width="95%" style="background-color:#C8DAF3; "  background="http://www.agri.com.cn/news/images/bgtop1.gif" >';

  h += '</td>';
  h += '<td align="right" style="background-color:#C8DAF3;">';
  
  h += '<a href="javascript:dictClose()" title="&#20851;&#38381;">';
  h += '<img src="'+dict_host+'images/close.gif" style="border:none;display:inline;" align="absmiddle">';
  h += '</a>';
  h += '</td></tr></table>';
  h += '</div>';
  
  h += '<table border="0" cellspacing="2" cellpadding="3" width="100%" align="center" onmouseover="dict_onlayer=1;" onmouseout="dict_onlayer=0;">';
  h += '<tr><td><fieldset color="#00c0ff">';  
  h += '<table border="0" cellspacing="0" cellpadding="0" width="100%" align="center" onmouseout=javascript:dictClose()>';
  h += '<tr><td width="100%">';
  h += '<iframe id="dictFrame" name="dictFrame" HEIGHT="120" src="about:blank" FRAMEBORDER="0" width="100%"></iframe>';
  h += '</td></tr></table></fieldset></td></tr></table>';
  h += '</td></tr></table></div>';
  document.write(h);

  dict_layer = document.getElementById('dict_layer');
  dict_iframe = document.getElementById('dictFrame');
  dictClose();
  if (dictRCookie("dictstate") == '1' && dict_enable) dict_enable = false;
  dictUpdateStatus();

  
  if (dict_is_ie) {
    document.attachEvent("onmousemove", dictMove);
    document.attachEvent("ondblclick", dictQuery);
    document.attachEvent("onmouseup", dictQuery);
     
    window.attachEvent("onload", dictUpdateStatus);
  }else {
    document.addEventListener("mousemove", dictMove, true);
    document.addEventListener("dblclick", dictQuery, true);
    document.addEventListener("mouseup", dictQuery, true);
 
    window.addEventListener("load", dictUpdateStatus, true);
  }
  var img = new Image();
  img.src = dict_host+"img/loading.gif";
}

 

function dictGetPos(event){
  if (dict_is_ie) {
    dict_x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
    dict_y = window.event.clientY + document.documentElement.scrollTop
      + document.body.scrollTop;
  }else {
    dict_x = event.clientX + window.scrollX;
    dict_y = event.clientY + window.scrollY;
  }
}


 
 

function dictQuery(e)  {
    if(dict_moving == 1){
        if (dict_is_ie) {
            window.event.cancelBubble = true;
            window.event.returnValue = false;
        }else{
            e.preventDefault();
        }
        return false;
    }
    if(dict_moving == 2) {
        dict_cx = dict_x;
        dict_cy = dict_y;
        dict_moving = 1;
        return false;
    }

    dictGetPos(e);
    if (!dict_enable) return true;

    var word = dictGetSel();
    if(dict_is_ie) word=word.replace(/^\s*|\s*$/g,"");
    word=""+word;
    if(word == "" || word.length > 16 || word == dict_old_word) return true;

    dictShow(word);

}

function dictDisplay(){
    var dx=262;
    var dy=264;
    dict_y += 8;
    dict_x += 16;
    if(dict_is_ie){
        if (document.documentElement.offsetHeight && document.body.scrollTop+document.documentElement.scrollTop+document.documentElement.offsetHeight - dict_y < dy){
            dict_y = document.body.scrollTop+document.documentElement.scrollTop + document.documentElement.offsetHeight - dy;
            dict_x += 14;
        }
        if (document.documentElement.offsetWidth && document.body.scrollLeft+document.documentElement.scrollLeft+document.documentElement.offsetWidth - dict_x < dx){
            dict_x = document.body.scrollLeft+document.documentElement.scrollLeft + document.documentElement.offsetWidth - dx;
        }
    }else{
        dx-=1;
        dy+=11;
        if (self.innerHeight && document.body.scrollTop+document.documentElement.scrollTop + self.innerHeight - dict_y < dy) {
            dict_y = document.body.scrollTop+document.documentElement.scrollTop + self.innerHeight - dy;
            dict_x += 14;
        }
        if (self.innerWidth && document.body.scrollLeft+document.documentElement.scrollLeft + self.innerWidth - dict_x < dx) {
            dict_x = document.body.scrollLeft+document.documentElement.scrollLeft + self.innerWidth - dx;
        }
    }
    dict_cx = dict_x;
    dict_cy = dict_y;
    dict_startx = dict_x;
    dict_starty = dict_y;
    dict_layer.style.left = dict_cx+'px';
    dict_layer.style.top = dict_cy+'px';
    dict_layer.style.display="";
    dict_moving = 1;
}

function dictShow(word){
	
    dictDisplay();
 /*
    try{
        dict_iframe.src='about:blank';
        iframeWin = window.frames.dictFrame;
        iframeWin.document.open();
        iframeWin.document.write('<html><body><b><font color="#666666">ÏÂÔØÖÐ<font color="green">'+word+'</font> :</b></font><br></body></html>');
        iframeWin.document.close();
    }catch(x){
    }
	
*/
	
	
  // var u=dict_host+'mini.php?';
  //  if(dict_partner) u += 'id='+dict_partner+'&';
  //  u += 'q='+word;
  //  var u='http://www.agri.com.cn/ads/area.asp?id='+word;
    var u="";
    wids=word.split(",");
    iskey=wids[1];
    keyId=wids[0];
    if (iskey=="1"){
    	   u='http://www.agri.com.cn/ads/seed.asp?id='+keyId;
    	//u='http://www.agri.com.cn/ads/seed/'+keyId+'.htm';
    }else if(iskey=="0"){
    	 u='http://www.agri.com.cn/ads/area/'+keyId+'.htm';
    	 //  u='http://www.agri.com.cn/ads/area.asp?id='+keyId;
    }else{
    	u='http://www.agri.com.cn';
    }

 
    setTimeout(function(){dict_iframe.src=u;},250);
    return;
    dict_old_word = word;
}


 

function dictClose() {
    try
    {
        dict_moving = 0;
        dict_onmove = 0;
        dict_onlayer = 0;
    	dict_layer.style.display="none";
        setTimeout(function(){dict_old_word="";},500);
    	if(window.sf) sf();
    }
    catch (x)
    {
    }

}

function dictWCookie(name,value)
{
    var date=new Date();
    var now=date.getTime();
    date.setTime(now+365*24*60*60*1000);
    document.cookie=name+"="+value+"; path=/; expires="+date.toGMTString();
}

function dictRCookie(name)
{
    var cookie=String(document.cookie);
    var pos=cookie.indexOf(name+"=");
    if(pos!=-1){
        var end=cookie.indexOf("; ",pos);
        return cookie.substring(pos+name.length+1,end==-1?cookie.length:end);
    }
    return "";
}

 

 

function dispWord(word){
	    dictGetPos();
    if (!dict_enable) return true;

    if(word == "" || word.length > 20 || word == dict_old_word) return true;

    dictShow(word);
	
	}

