//<!-- Active Dictionary functions by Chris Greaves -->


var msg;
var browser;
var versionIE;
function BrowserCheck() {
	var b = navigator.appName
	this.mac = (navigator.appVersion.indexOf('Mac') != -1)
	if (b=="Netscape") this.b = "ns"
	else if (b=="Microsoft Internet Explorer") this.b = "ie"
	else this.b = b
	this.version = navigator.appVersion
	this.v = parseInt(this.version)
	this.ns = (this.b=="ns" && this.v>=4)
	this.ns4 = (this.b=="ns" && this.v==4)
	this.ns5 = (this.b=="ns" && this.v==5)
	this.ie = (this.b=="ie" && this.v>=4)
	this.ie4 = (this.version.indexOf('MSIE 4')>0)
	this.ie5 = (this.version.indexOf('MSIE 5')>0)
	this.ie6 = (this.version.indexOf('MSIE 6')>0)
	this.ie7 = (this.version.indexOf('MSIE 7')>0)
	this.min = (this.ns||this.ie)
browser=this.b;
if(this.ie4==true)
versionIE=4;
else if(this.ie5==true)
versionIE=5;
else if(this.ie6==true)
versionIE=6;
else if(this.ie7==true)
versionIE=7;

}

is = new BrowserCheck()

var CanShow = true;
if (is.v<4){CanShow=false;}
if ((is.mac==true)&&((is.ie4==true)||(is.ie5==true))){
alert("The Active dictionary functions do not work on the Mac in IE. Use Netscape instead if you want to use this feature.");
}
if (CanShow==false){
	alert('WARNING: Your browser version cannot show this page.');
	history.back();
}
if(browser=="ns"){
if(!window.event && window.captureEvents) {
  if (is.mac==true){
	window.captureEvents(Event.MOUSEUP);
  	window.onmouseup = doLookupN;
  	window.event = new Object;
}
  else{
  window.captureEvents(Event.DBLCLICK);
  window.ondblclick = doLookupN;
  window.event = new Object;
}
}
}

function doLookupN(e) {
var sel = document.getSelection();
 var lookup=new String("http://www.edict.com.hk/scripts/cgi-bin/lexicon.exe?SearchStr=");
  var find=new String(lookup.concat(sel));
msg=window.open(find,"msg","location=yes,scrollbars=yes,resizable=yes,height=200,width=400 ");
//msg.location.href=find;
if(msg)msg.focus();
  if ( routeEvent(e) == false ) {
    return false;
  } else {
    return true;
  }
}
function doLookupIE()
{

lookMeUpIE5();

}
function lookMeUpIE5() {
var oSource = window.parent.frames("second").window.event.srcElement;


if(oSource.name=="StudentName"||oSource.name=="B1")return;
//alert(oSource.name);
var parent=oSource.parentTextEdit;
if(parent!=null){
var txtRnge=parent.createTextRange();
txtRnge.moveToPoint(window.parent.frames("second").window.event.x, window.parent.frames("second").window.event.y);//+txtRnge.offsetTop-14);
txtRnge.collapse();  
  txtRnge.expand("word");
txtRnge.select();

var s=txtRnge.text;
//alert(s);
if(s!=""){
var lookup=new String("http://www.edict.com.hk/scripts/cgi-bin/lexicon.exe?SearchStr=");
var find=new String(lookup.concat(s));
if(msg)msg.close();
msg=window.open(find,"msg","location=yes,scrollbars=yes,resizable=yes,height=200,width=400 ");
if(msg)msg.focus();
//window.parent.frames("Text").document.location.href=find;


}
}
}
function lookMeUpIE4() {
  var txtRnge=window.parent.frames("Text").document.body.createTextRange();

  txtRnge.moveToPoint(window.parent.frames("Text").window.event.x, window.parent.frames("Text").window.event.y+txtRnge.offsetTop-14);

  txtRnge.collapse();  
  txtRnge.expand("word");
  txtRnge.select();

  var s=txtRnge.text;
if(s!=""){
  var lookup=new String("http://www.edict.com.hk/scripts/cgi-bin/lexicon.exe?SearchStr=");
  var find=new String(lookup.concat(s));
//if(msg)msg.close();
//msg=window.open(find,"msg","location=yes,scrollbars=yes,resizable=yes,height=200,width=400 ");
window.parent.frames("Text").document.location.href=find;

}
}

