if (document.layers) { // Netscape
   document.captureEvents(Event.MOUSEMOVE);
   document.onmousemove = captureMousePosition;
} else if (document.all) { // Internet Explorer
   document.onmousemove = captureMousePosition;
} else if (document.getElementById) { // Netcsape 6
   document.onmousemove = captureMousePosition;
}
// Global variables
xMousePos = 0; // Horizontal position of the mouse on the screen
yMousePos = 0; // Vertical position of the mouse on the screen
xMousePosMax = 0; // Width of the page
yMousePosMax = 0; // Height of the page


function Browser() {
	var b=navigator.appName;
	if (b=="Microsoft Internet Explorer" && navigator.userAgent.indexOf('Opera') == -1 && navigator.appVersion.indexOf("Mac")==-1) this.b="ie";
  else {this.b="other";}
}
is = new Browser();
//alert(is.b);


function captureMousePosition(e) {
   if (document.layers) {
       xMousePos = e.pageX;
       yMousePos = e.pageY;
       xMousePosMax = window.innerWidth+window.pageXOffset;
       yMousePosMax = window.innerHeight+window.pageYOffset;
   } else if (document.all) {
       /*
	   xMousePos = window.event.x+document.body.scrollLeft;
       yMousePos = window.event.y+document.body.scrollTop;
       xMousePosMax = document.body.clientWidth+document.body.scrollLeft;
       yMousePosMax = document.body.clientHeight+document.body.scrollTop;
	   */
   	   xMousePos = document.body.scrollLeft;
       yMousePos = document.body.scrollTop;
       xMousePosMax = document.body.clientWidth+document.body.scrollLeft;
       yMousePosMax = document.body.clientHeight+document.body.scrollTop;

   } else if (document.getElementById) {
       // Netscape 6 behaves the same as Netscape 4 in this regard 
       xMousePos = e.pageX;
       yMousePos = e.pageY;
       xMousePosMax = window.innerWidth+window.pageXOffset;
       yMousePosMax = window.innerHeight+window.pageYOffset;
   }

}
			
			
function display(){
    //eu não sei se isto funciona
    //location.replace(this.href);
    //
  var left,top;
  var wit=225;
  var hei=160;
  if(is.b!="other"){
    var range = document.selection.createRange();
		var str = range.text;
		range.move("word",1);
		range.expand("word");
		range.select();
		var depois= range.text;
		range.move("word",1);
		range.expand("word");
		range.select();
		depois = depois + " " + range.text;	
	
		range.move("word",-3);
		range.expand("word");
		range.select();
	  var antes= range.text;
	
		range.move("word",-1);
		range.expand("word");
		range.select();
	  antes= range.text + " " +antes;
	
		range.move("word",2);
		range.expand("word");
		range.select();

		//left=(xMousePos + window.screenLeft);
		left=window.event.x + document.body.scrollLeft;
		if((left+wit)>document.body.clientWidth) {
			left=left - wit;
		}
		//top=((yMousePos + window.screenTop + 10));


		//alert("posicao do y" +yMousePos+"##"+document.body.clientHeight +"bodyheight##"+ document.body.clientWidth+"bodywidth##" + left + "LEFT" + "##scrolltop->"+document.body.scrollTop);
		top=window.event.y + document.body.scrollTop +10;
    //alert(top);
		if((top + hei)>document.body.clientHeight) {
			top=top - hei -18;
  		if((top - hei)<0) {
    		top=window.event.y + document.body.scrollTop +10;
  		}
  	}

    var urlPage="hiperligacao.jsp?p=" + escape(str) + "&a=" + escape(antes) + "&d=" + escape(depois);	
    document.all['scrollTextFrame'].src=urlPage;
		document.all['sc'].style.left=left;
		document.all['sc'].style.top=top;
		document.all['sc'].style.visibility = 'visible';
  }
  else {
      //alert("fdfd" + self.document.getSelection());
      var str= document.getSelection();
      var otherparam="other=sim";
      var urlPage="hiperligacao.jsp?p=" + escape(str) + "&a=&d=&" + otherparam;
      window.open(urlPage,'anotacao','resizable=no,status=no,menubar=no,width=' + wit + ',height=' + (hei+20));
  }
}


function abre_artigo(id_artigo){
 /*   alert("x->" +  e0topo.TGetProperty("/",0));
    alert("y->" + e0topo.TGetProperty("/",1));
    alert("x->" +  e0topo.TGetProperty("/",2));
    alert("y->" + e0topo.TGetProperty("/",3));

    alert("xmouse->" + e0topo.GetVariable("_xmouse"));
    alert("ymouse->" + e0topo.GetVariable("_ymouse"));
*/
		var left,top,top1;
		var wit=275;
		var hei=320;
    if(is.b!="other"){
      var meio=(document.body.clientWidth - 775)/2;
      left =e0topo.GetVariable("_xmouse")-0 + meio;
      if((left+wit)>document.body.clientWidth) {
         left=left - wit;
      }
      top=e0topo.GetVariable("_ymouse") -0 + 10;
      if((top + hei)>document.body.clientHeight) {
        top1=top - hei;
        if((top - hei)<0) {
          top=10;
        }
        else{
          top=top1;
        }
      }
      //alert("left=" + left + "top=" + top);
      document.all['anotacaoTextFrame'].src="resumo_iframe.jsp?id="+ id_artigo;
      document.all['anotacao'].style.left=left;
      document.all['anotacao'].style.top=top;
      document.all['anotacao'].style.visibility = 'visible';
    }
    else{ //netscape
      //alert("rui");
      var otherparam="other=sim";
      var urlPage="resumo_iframe.jsp?id="+ id_artigo + "&" + otherparam;
      window.open(urlPage,'anotacao','resizable=no,status=no,menubar=no,width=' + wit + ',height=' + (hei+20));
    }

}



function abre_artigo_html(id_artigo){
		var left,top,top1;
		var wit=275;
		var hei=320;
    //alert("left=" + left + "top=" + top);
    if(is.b!="other"){
      left=window.event.x + document.body.scrollLeft;
      if((left+wit)>document.body.clientWidth) {
         left=left - wit;
      }
      top=window.event.y + document.body.scrollTop +10;
      if((top + hei)>document.body.clientHeight) {
        top1=top - hei;
        if((top - hei)<0) {
          top=10;
        }
        else{
          top=top1;
        }
      }
      document.all['anotacaoTextFrame'].src="resumo_iframe.jsp?id="+ id_artigo;
      document.all['anotacao'].style.left=left;
      document.all['anotacao'].style.top=top;
      document.all['anotacao'].style.visibility = 'visible';  
    }
    else{ //netscape
      //alert("rui");
      var otherparam="other=sim";
      var urlPage="resumo_iframe.jsp?id="+ id_artigo + "&" + otherparam;
      window.open(urlPage,'anotacao','resizable=no,status=no,menubar=no,width=' + wit + ',height=' + (hei+20));
    }
}


function abre_artigo_url(url){
		var left,top,top1;
		var wit=275;
		var hei=320;
    //alert("dsds");
    if(is.b!="other"){
      left=window.event.x + document.body.scrollLeft;
      if((left+wit)>document.body.clientWidth) {
         left=left - wit;
      }
      top=window.event.y + document.body.scrollTop +10;
      if((top + hei)>document.body.clientHeight) {
        top1=top - hei;
        if((top - hei)<0) {
          top=10;
        }
        else{
          top=top1;
        }
      }
      document.all['anotacaoTextFrame'].src=url;
      document.all['anotacao'].style.left=left;
      document.all['anotacao'].style.top=top;
      document.all['anotacao'].style.visibility = 'visible';
    }
    else{ //netscape
      //alert("rui");
      //var urlPage="resumo_iframe.jsp?id="+ id_artigo;
      var otherparam="other=sim";
      var urlother="";
      if(url.indexOf('?') == -1) {//não tem parametros
        urlother= url + "?" + otherparam;
      }
      else {// ja tem parametros
        var urlother="";
        if(url.indexOf('?') == -1) {//não tem parametros
          urlother= url + "?" + otherparam;
        }
        else {// ja tem parametros
          urlother= url + "&" + otherparam;
        }
        urlother= url + "&" + otherparam;
      }
      window.open(urlother,'anotacao','resizable=no,status=no,menubar=no,width=' + wit + ',height=' + (hei+20));
    }

}


function abre_url(url){
		var left,top;
		var wit=275;
		var hei=320;
    if(is.b!="other"){
      left=window.event.x + document.body.scrollLeft;
      if((left+wit)>document.body.clientWidth) {
        left=left - wit;
      }
      top=window.event.y + document.body.scrollTop +10;
      if((top + hei)>document.body.clientHeight) {
        if(top-hei<0){
          top=10;
        }
        else{
          top=top - hei -18;
        }
      }
      //alert("left->" + left+ "top->" +top );
      document.all['anotacaoTextFrame'].src=url;
      document.all['anotacao'].style.left=left;
      document.all['anotacao'].style.top=top;
      document.all['anotacao'].style.visibility = 'visible';
    }
    else{ //netscape
      //alert("rui");
      var urlother="";
      var otherparam="other=sim";
      if(url.indexOf('?') == -1) {//não tem parametros
        urlother= url + "?" + otherparam;
      }
      else {// ja tem parametros
        urlother= url + "&" + otherparam;
      }
      window.open(urlother,'anotacao','resizable=no,status=no,menubar=no,width=' + wit + ',height=' + (hei+20));
    }
}


function abre_url_peq(url){
    //alert(2332);
		var left,top;
		var wit=220;
		var hei=160;
    if(is.b!="other"){
      left=window.event.x + document.body.scrollLeft;
      if((left+wit)>document.body.clientWidth) {
        left=left - wit;
      }
      top=window.event.y + document.body.scrollTop +10;
      if((top + hei)>document.body.clientHeight) {
        if(top-hei<0){
          top=10;
        }
        else{
          top=top - hei -18;
        }
      }
      //alert("left->" + left+ "top->" +top );
      document.all['scrollTextFrame'].src=url;
      document.all['sc'].style.left=left;
      document.all['sc'].style.top=top;
      document.all['sc'].style.visibility = 'visible';
    }
    else{ //netscape
      //alert("rui");
      var urlother="";
      var otherparam="other=sim";
      if(url.indexOf('?') == -1) {//não tem parametros
        urlother= url + "?" + otherparam;
      }
      else {// ja tem parametros
        urlother= url + "&" + otherparam;
      }     
      window.open(urlother,'anotacaopeq','resizable=no,status=no,menubar=no,width=' + wit + ',height=' + (hei+20));
    }
}
