var searchtext ="";var str; var poppedUp = 0; 
var nav4 = window.Event ? true : false;
var detect = navigator.userAgent.toLowerCase(); 
var OS,browser,total,thestring; var version = 0;

if (checkIt('konqueror')) {browser = "Konqueror";OS = "Linux";}
else if (checkIt('safari')) browser = "Safari";
else if (checkIt('omniweb')) browser = "OmniWeb";
else if (checkIt('opera')) browser = "Opera";
else if (checkIt('webtv')) browser = "WebTV";
else if (checkIt('icab')) browser = "iCab";
else if (checkIt('msie')) browser = "Internet Explorer";
else if (checkIt('chrome')) browser = "Chrome";
else if (!checkIt('compatible')) {browser = "Netscape"; version = detect.charAt(8);}
else browser = "Unknown browser";

if (!version) version = detect.charAt(place + thestring.length);
if (!OS) {
 if (checkIt('linux')) OS = "Linux";
 else if (checkIt('x11')) OS = "Unix";
 else if (checkIt('mac')) OS = "Mac"
 else if (checkIt('win')) OS = "Windows"
 else OS = "an unknown operating system";
}
function checkIt(string) {
 place = detect.indexOf(string) + 1; 
 thestring = string;
 return place;
}

function popwin(file,x,y,name,z,r) {
	var browserName = navigator.appName;
	Version=navigator.appVersion;
	var msgWindow=null;

	if (x==null) x=330;
	if (y==null) {
		if (browser == "Safari") {y=440;}
		else {y=400;}
	} 

	if (name==null) name="EdusoftOnline";
	if (z==null) z="auto";
	if (r==null) r="yes";

	if (browserName == "Netscape") {
		msgWindow=window.open(file,name,"toolbar=no,scrollbars="+z+",directories=no, status=no,menubar=no,resizable="+r+",width="+x+",height="+y+",screenX=20,screenY=0")
	} 
	else {
		msgWindow=window.open(file,name,"toolbar=no,scrollbars="+z+",directories=no, status=no,menubar=no,resizable="+r+",width="+x+",height="+y+",left=20,top=0")
	}

	if ( (Version.substring(0,1) >= 3) && (Version.indexOf("MSIE") == -1)) {
		msgWindow.focus();
	}
}



if (browser != "Safari") {

	if (nav4) {  
 	document.captureEvents(Event.DBLCLICK);
 	document.captureEvents(Event.KEYPRESS);
	}
	document.ondblclick = display;
	if (window.Event) document.captureEvents(Event.MOUSEUP);
	if (OS == "Mac")  { document.onmouseup = display;} 

}

function display() {
  if (document.getSelection) {
    var str = document.getSelection();
    if (window.RegExp) {
      var regstr = unescape("%20%20%20%20%20");
      var regexp = new RegExp(regstr, "g");
      str = str.replace(regexp, "");
    }
  } else if (document.selection && document.selection.createRange) {
    var range = document.selection.createRange();
    var str = range.text;
  } else  {
    var str = "Impossible";
  }

  if (str.substr(0,5) == "Email") { str = "Email";}
  
  else {

  	re = /'s/g; str=str.replace(re, "");
  	re = /s'/g; str=str.replace(re, "");
       
  	re = /\./g; str=str.replace(re, "");
  	re = /\,/g; str=str.replace(re, "");

 	 re = /'/g; str=str.replace(re, "");
  	re = /"/g; str=str.replace(re, "");
  	re = /\?/g; str=str.replace(re, "");
  	re = /\!/g; str=str.replace(re, "");
  	re = /:/g; str=str.replace(re, "");
  	re = /;/g; str=str.replace(re, "");
  	re = /\(/g; str=str.replace(re, "");
  	re = /\)/g; str=str.replace(re, "");
  	re = /\]/g; str=str.replace(re, "");
  }
  searchtext = str;
  if (searchtext) {dict_lookup(str);}
}
function dict_lookup() { 

  	args=dict_lookup.arguments;

	thedict = "1";
  	if (poppedUp) {
    		if (!dict.closed) {dict.close();}	
  	} 
  	else {poppedUp = 0;}	
  		dict = window.open("http://www.edusoft.vn/live/blocks/dictionary_mc/dic/search.php?dict="+thedict+"&word="+args[0]+"", "dict","width=634,height=420,resizable=yes,scrollbars=auto,status=no");

  	dict.focus;

}

function KeyPressHandle(e) {
  var modPressed = (nav4) ? e.modifiers & Event.SHIFT_MASK : e.shiftKey;
  var whichCode = (nav4) ? e.which : e.keyCode;
  if (modPressed && whichCode==13) { LookupSelection(e); return false;}
  return true;
}


function checkOpt() {
if (document.eduDict.dict[0].selected == true) {
	document.eduDict.dict[0].selected = true}
}




function checkDict() {
if (checkOpt() == false) return false;
theword = document.eduDict.word.value;
thedict = document.eduDict.dict.value;
if (theword == "") {alert("Dictionaries & Reference Books\n \nPlease enter a search word"); document.eduDict.word.focus(); return false;} 
else {
thelink = "http://www.edusoft.vn/live/blocks/dictionary_mc/dic/search.php?word=" + theword + "&dict=" + thedict;
popwin(thelink,634,420,'dict','yes','yes'); return false;} 
}


function goDict() {
	theword = document.eduDict.word.value;

	if (theword == "") {
		alert("Please enter a word");
		document.eduDict.word.focus();
		return false;
	} 
	else {
		thelink = "http://www.edusoft.vn/live/blocks/dictionary_mc/dic/search.php?word=" + theword + "&dict=" + thedict;
		popwin(thelink,634,420,'dict','yes','yes');
		return false;
	} 
}


