function vd_noErrorMessages () { return true; }
window.onerror = vd_noErrorMessages;

if( (typeof vd_dictcolor == "undefined") || (vd_dictcolor == ""))
{
	var vd_dictcolor = "";
}
else
{
	vd_dictcolor = 'color:#' + vd_dictcolor;
}

if ( (typeof vd_quickclick == "undefined")  || (vd_quickclick == "") )
{
	var vd_quickclick = true;
}

if ( (typeof vd_boxwidth == "undefined") || (vd_boxwidth == "") || (vd_boxwidth < 150) )
{
	var vd_boxwidth = 260;
}

vd_boxwidthless60 = vd_boxwidth - 60;

var vd_quickDown = 0;
var vd_isFocused = 0;
var vd_isHovered = 0;
var vd_isLong = '';
var vd_ImagePaths =
{
	vd_searchBox_bg 		: "http://js.vdict.com/searchform/widgetInputBB.png",
	vd_roundedLeftEnd 	 	: "http://js.vdict.com/searchform/widgetInputL2.png",
	vd_searchButton_over  	: "http://js.vdict.com/searchform/widgetInputRF.png",
	vd_searchButton_down 	: "http://js.vdict.com/searchform/widgetInputRFd.png",
	vd_searchButton_up  	: "http://js.vdict.com/searchform/widgetInputRU.png",
	vd_vdictLogo     		: "http://js.vdict.com/searchform/vdictsearch.png"
}
var vd_searchButton_down 		= new Image(29,24);
	vd_searchButton_down.src	= vd_ImagePaths.vd_searchButton_down;
var vd_searchButton_over 		= new Image(29,24);
	vd_searchButton_over.src	= vd_ImagePaths.vd_searchButton_over;
	var vd_searchButton_up = new Image(29,24);
		vd_searchButton_up.src = vd_ImagePaths.vd_searchButton_up;
	var vd_searchBox_bg = new Image();
        vd_searchBox_bg.src= vd_ImagePaths.vd_searchBox_bg;
	var vd_roundedLeftEnd = new Image(13,24);
        vd_roundedLeftEnd.src = vd_ImagePaths.vd_roundedLeftEnd;
	var vd_vdictLogo = new Image();
		vd_vdictLogo.src = vd_ImagePaths.vd_vdictLogo;
function vd_attachBehaviors()
{
	var e;
	if( e = document.getElementById('vd_searchButton') )
	{
		e.onmousedown = function()
							{
								vd_quickDown = 1;
								this.src  = vd_ImagePaths.vd_searchButton_down;
								vd_isFocused = 0;
							};
		
		e.onmouseup = function()
							{
								vd_quickDown = 0;
								this.src = vd_ImagePaths.vd_searchButton_over;
							}
		
		e.onmouseover = function()
						{
							if( vd_isFocused==0 && vd_isHovered==0 )
							{
								this.src = vd_ImagePaths.vd_searchButton_over;
								vd_isHovered=1;
							}
						}
		
		e.onmouseout = 	function()
						{
							if(vd_isFocused==0)
							{
								
                            this.src = vd_ImagePaths.vd_searchButton_up;

								vd_isHovered=0;
								if( vd_quickDown==1 )
								{
									vd_quickDown=0;
									document.getElementById('vd_searchInput').onblur();
								}
							}
						}
	}
	if( e = document.getElementById('vd_searchInput') )
	{
		e.onfocus = function()
					{
                    this.className='focused';                    
                    document.getElementById('vd_searchButton').src = vd_ImagePaths.vd_searchButton_over;
                    vd_isFocused=1;
					}
		
		e.onblur = 	function()
					{
						if(vd_quickDown==0)
						{
                        if(this.value=='')
                            this.className='blurred';
                        document.getElementById('vd_searchButton').src = vd_ImagePaths.vd_searchButton_up;
                        vd_isFocused=0;
						}
					}
	}
}
function vd_startList() {
	if (document.all&&document.getElementById) {
		vd_cssdropdownRoot = document.getElementById("vd_cssdropdown");
		for (x=0; x<vd_cssdropdownRoot.childNodes.length; x++) {
			node = vd_cssdropdownRoot.childNodes[x];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className+=" over";
				}
				node.onmouseout=function() {
					this.className=this.className.replace(" over", "");
				}
			}
		}
	}
}

function vd_init()
{
	vd_attachBehaviors();
	vd_startList();
	var e = document.getElementById('vd_searchInput');
	e.onblur();
}

if (window.attachEvent)
window.attachEvent("onload", vd_init)
else
window.onload=vd_init;

function writeJS(){
var str='';
str+='<style type="text\/css">';
str+='form, input, div {';
str+='	margin:0px;';
str+='	padding:0px;';
str+='}';
str+='form.vd_searchForm {';
str+='	display:block;';
str+='	margin-left:0px;';
str+='	margin-top:0px;';
str+='	margin-right:0px;';
str+='	height:24px;';
str+='	min-width:100px;';
str+='	width:100%;';
str+='	background:url(http:\/\/js.vdict.com\/searchform\/widgetInputL2.png) no-repeat top left !important;';
str+='}';
str+='div.vd_inputHolder {';
str+='	top:0px;';
str+='	height:24px;';
str+='	margin-left:13px;';
str+='	margin-right:0px;';
str+='	background:url(http:\/\/js.vdict.com\/searchform\/widgetInputBB.png);';
str+='	zoom:1;';
str+='	float:left;';
str+='}';
str+='input#vd_searchButton {';
str+='	margin:0px;';
str+='	display:block;';
str+='	width:29px;';
str+='	height:24px;';
str+='	margin-right:0px;';
str+='	outline:none;';
str+='	cursor:pointer;';
str+='}';
str+='div.vd_buttonHolder {';
str+='	float:left;';
str+='	height:24px;';
str+='	zoom:1;';
str+='}';
str+='input#vd_searchInput {';
str+='	display:block;';
str+='	top:0px;';
str+='	border:none;';
str+='	font-size:16px;';
str+='	line-height:20px;';
str+='	padding:2px 0px 1px;';
str+='	background-color:transparent;';
str+='	vertical-align:middle;';
str+='	width:' + vd_boxwidthless60 + 'px;';
str+='}';
str+='input#vd_searchInput:focus,';
str+='input#vd_searchInput:active {';
str+='	outline:none;';
str+='}';
str+='input#vd_searchInput.focused {';
str+='	background-image:none !important;';
str+='}';
str+='input#vd_searchInput.blurred {';
str+='	background:url(http:\/\/js.vdict.com\/searchform\/vdictsearch.png) no-repeat;';
str+='}';
str+='vd_hidden {';
str+='display:none;';
str+='}';
str+='#vd_cssdropdown, #vd_cssdropdown ul {';
str+='padding: 0;';
str+='margin: 0;';
str+='list-style: none;';
str+='}';
str+='#vd_cssdropdown li {';
str+='float: left;';
str+='position: relative;';
str+='}';
str+='.vd_subuls{';
str+='display: none;';
str+='position: absolute;';
str+='margin-top: 5px;';
str+='right: 0px;';
str+='border: 1px solid #333333;';
str+='background-color: #FFFFFF;';
str+='font-family:Arial, Helvetica, sans-serif;';
str+='font-size: 12px;';
str+='width: 220px;';
str+='}';
str+='.vd_subuls li{';
str+='width: 215px;';
str+='padding-left: 5px;';
str+='padding-bottom: 2px;';
str+='padding-top: 2px;';
str+='padding-right: 0px;';
str+='}';
str+='.vd_subuls li:hover, .vd_subuls li.over{';
str+='background-color:#CCFF99;';
str+='}';
str+='.vd_subuls li a, .vd_subuls li a:hover, .vd_subuls li a:visited{';
str+='text-decoration: none;';
str+='color:#0000FF;';
str+='}';
str+='.vd_subuls li a:hover{';
str+='background-color:#CCFF99';
str+='}';
str+='#vd_cssdropdown li>ul { \/* to override top and left in browsers other than IE, which will position to the top right of the containing li, rather than bottom left *\/';
str+='top: auto;';
str+='left: auto;';
str+='}';
str+='#vd_cssdropdown li:hover ul, li.over ul { \/* lists nested under hovered list items *\/';
str+='display: block;';
str+='}';
str+='#vd_dictionaryholder {';
str+='float:right;';
str+='margin-left: 10px;';
str+='margin-right: 20px;';
str+='clear:both;';
str+='}';
str+='#vd_wrapper{';
str+='width: ' + vd_boxwidth + 'px;';
str+='margin:0;';
str+='padding:0;';
str+='display:block;';
str+='}';
str+='#vd_dictname, #vd_downarrow{';
str+='font-family: Verdana, Arial, Helvetica, sans-serif;';
str+='font-size:11px;';
str+='float:left; ' + vd_dictcolor ;
str+='}';
str+='<\/style>';
str+='<br \/>';
str+='<div id="vd_wrapper" >';
str+='  <form name="vd_searchForm" id="vd_searchForm" class="vd_searchForm" action="http:\/\/vdict.com\/" target="_blank" accept-charset="UTF-8">';
str+='    <div class="vd_hidden">';
str+='      <input type="hidden" name="dict" id="dict" value="1" \/>';

str+='    <\/div>';
str+='    <div class="vd_inputHolder">';
str+='      <input name="word" id="vd_searchInput" class="blurred" type="text">';
str+='    <\/div>';

str+='    <div class="vd_buttonHolder">';
str+='      <input src="http://js.vdict.com/searchform/widgetInputRU.png" id="vd_searchButton" value="Search" class="vd_searchButton" type="image">';
str+='    <\/div>';
str+='    <br \/>';
str+='    <div id="vd_dictionaryholder">';
str+='      <ul id="vd_cssdropdown"><div id="vd_dictname">English Vietnamese dictionary<\/div>';
str+='        <li class="mainitems"><div id="vd_downarrow"> &#9660;<\/div>';
str+='          <ul class="vd_subuls"  id="vd_subuls">';
str+='            <li>Click to select dictionary...<\/li>';
str+='            <li onClick="getElementById(\'vd_dictname\').innerHTML=\'English Vietnamese dictionary\'; getElementById(\'dict\').value=\'1\';"><a href="#">English Vietnamese dictionary<\/a><\/li>';
str+='            <li onClick="getElementById(\'vd_dictname\').innerHTML=\'Vietnamese English dictionary\'; getElementById(\'dict\').value=\'2\';"><a href="#">Vietnamese English dictionary<\/a><\/li>';
str+='            <li onClick="getElementById(\'vd_dictname\').innerHTML=\'Vietnamese Vietnamese dictionary\'; getElementById(\'dict\').value=\'3\';"><a href="#">Vietnamese Vietnamese dictionary<\/a><\/li>';
str+='            <li onClick="getElementById(\'vd_dictname\').innerHTML=\'Vietnamese French dictionary\'; getElementById(\'dict\').value=\'4\';"><a href="#">Vietnamese French dictionary<\/a><\/li>';
str+='            <li onClick="getElementById(\'vd_dictname\').innerHTML=\'French Vietnamese dictionary\'; getElementById(\'dict\').value=\'5\';"><a href="#">French Vietnamese dictionary<\/a><\/li>';
str+='            <li onClick="getElementById(\'vd_dictname\').innerHTML=\'Computing dictionary\'; getElementById(\'dict\').value=\'6\';"><a href="#">Computing dictionary<\/a><\/li>';
str+='            <li onClick="getElementById(\'vd_dictname\').innerHTML=\'English English dictionary\'; getElementById(\'dict\').value=\'7\';"><a href="#">English English dictionary<\/a><\/li>';
str+='            <li onClick="getElementById(\'vd_dictname\').innerHTML=\'Chinese Vietnamese dictionary\'; getElementById(\'dict\').value=\'8\';"><a href="#">Chinese Vietnamese dictionary<\/a><\/li>';
str+='            <li onClick="getElementById(\'vd_dictname\').innerHTML=\'Russian Vietnamese dictionary\'; getElementById(\'dict\').value=\'9\';"><a href="#">Russian Vietnamese dictionary<\/a><\/li>';
str+='          <\/ul>';
str+='        <\/li>';
str+='      <\/ul>';
str+='    <\/div>';
str+='  <\/form>';
str+='<\/div>';
str+='<br \/>';
document.write(str);
}
writeJS();

if (vd_quickclick)
{
	if(typeof dictionaries == "undefined") 
	{
		var dictionaries = "eng2vie_vie2eng_foldoc";
	}
	document.write("<div id='addVdictOnYourWeb'  style='position: absolute;left: -300px;width: 300px;border: 1px solid black;padding: 2px;background-color: lightyellow;visibility: hidden;z-index: 100;'>VDict quick lookup</div>");
	var vdict_offsetfromcursorX=12 //Customize x offset of tooltip
	var vdict_offsetfromcursorY=10 //Customize y offset of tooltip
	var vdict_ie=document.all
	var vdict_ns6=document.getElementById && !document.all
	var vdict_enabletip=false
	if (vdict_ie||vdict_ns6)
	var vdict_tipobj=document.all? document.all["addVdictOnYourWeb"] : document.getElementById? document.getElementById("addVdictOnYourWeb") : ""
	
	function vdict_ietruebody(){
		return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
	}
	//////////////////////////////////////////
	//////////////////move mouse///////////////////////////////////////////////
	///////////////////////////////////////////////////////////////////////////
	function vdict_positiontip(e){
		if (vdict_enabletip){
			var nondefaultpos=false
			var curX=(vdict_ns6)?e.pageX : event.clientX+vdict_ietruebody().scrollLeft;
			var curY=(vdict_ns6)?e.pageY : event.clientY+vdict_ietruebody().scrollTop;
			//Find out how close the mouse is to the corner of the window
			var winwidth=vdict_ie&&!window.opera? vdict_ietruebody().clientWidth : window.innerWidth-20
			var winheight=vdict_ie&&!window.opera? vdict_ietruebody().clientHeight : window.innerHeight-20
			
			var rightedge=vdict_ie&&!window.opera? winwidth-event.clientX-vdict_offsetfromcursorX : winwidth-e.clientX-vdict_offsetfromcursorX
			var bottomedge=vdict_ie&&!window.opera? winheight-event.clientY-vdict_offsetfromcursorY : winheight-e.clientY-vdict_offsetfromcursorY
			
			var leftedge=(vdict_offsetfromcursorX<0)? vdict_offsetfromcursorX*(-1) : -1000
			
			//if the horizontal distance isn't enough to accomodate the width of the context menu
			if (rightedge<vdict_tipobj.offsetWidth){
				//move the horizontal position of the menu to the left by it's width
				vdict_tipobj.style.left=curX-vdict_tipobj.offsetWidth+"px"
				nondefaultpos=true
			}
			else if (curX<leftedge)
					vdict_tipobj.style.left="5px"
				else{
					//position the horizontal position of the menu where the mouse is positioned
					vdict_tipobj.style.left=curX+vdict_offsetfromcursorX+"px"
				}
			
			//same concept with the vertical position
			if (bottomedge<vdict_tipobj.offsetHeight){
				vdict_tipobj.style.top=curY-vdict_tipobj.offsetHeight-vdict_offsetfromcursorY+"px"
				nondefaultpos=true
			}
			else{
				vdict_tipobj.style.top=curY+vdict_offsetfromcursorY+"px"
			}
			vdict_tipobj.style.visibility="visible"
		}
	}
	///////////////////////////////
	//////////////////////////////
	/////////////////////////////////////////
	var base_url = "http://vdict.com/";
	var text = "";
	function calldict(word, dict ){
		//window.open(base_url+'gateway.php?word='+word+'&dictionaries='+dict,'Vdict','toolbar=no,status=no,scrollbars=yes,location=no,menubar=no,directories=no,titlebar=no,width=620,height=400')
		vdict_url	=	base_url+'fsearch.php?word='+word+'&dictionaries='+dict;
		//create iframe
		str	=	"<div style='float: left; border-bottom: 1px solid #000000; background: #ffffff;'>";
		str	+=	" <div style='float:left;'><a href='"+base_url+"' target='_blank'><img src='"+base_url+"small_logo.gif' border=0 /></a> <span name='vdict_dictionary_name' id='vdict_dictionary_name'></span> </div>";
		str	+=	" <div style='float:right;'><a href='#' onclick=\"doCloseVdict();return false;\"><img src='"+base_url+"close.gif' border=0 /></a></div>";
		str	+=	"</div>";
		str	+=	"<div>";
		str	+=	"<iframe id='myIframe' src='"+vdict_url+"' style='width: 100%; height: 200px; border: 0px;'></iframe>";
		str	+=	"</div>";
		document.getElementById('addVdictOnYourWeb').innerHTML = str;
	}
	function doCloseVdict()
	{
		document.getElementById('addVdictOnYourWeb').innerHTML='';
		document.getElementById('addVdictOnYourWeb').style.visibility="hidden";
	}
	
	function ctrlrightclick(evt) {
		evt = (evt) ? evt : ((window.event) ? window.event : "")
		if (!evt.ctrlKey) return true
	//	var x=document.body.createTextRange();
	//	var x=(document.all) ? document.body.createTextRange() : document.setSelectionRange();
	//	x.moveToPoint(evt.x, evt.y);
	//	x.expand("word");
	//	if (x.text)
	//	{
	//		calldict(x.text, dictionaries);
	//	}
		//text	=	
		return false
	}
	
	function detectKey(evt) 
	{
		evt = (evt) ? evt : ((window.event) ? window.event : "")
		if(evt.type == 'keydown' && ( (evt.keyCode == "A".charCodeAt(0)) || (evt.keyCode == "a".charCodeAt(0)) ) )
		{
			if ( (evt.ctrlKey) && (evt.shiftKey) )
			{
				text = (document.all) ? document.selection.createRange().text : document.getSelection();
				if (text.length > 1)
				{
					vdict_enabletip=true;
					vdict_positiontip(evt);
					calldict(text, dictionaries);
				}
			}
		}
		return true
	}
	function doDblClick(evt) 
	{
		evt = (evt) ? evt : ((window.event) ? window.event : "")
		text = (document.all) ? document.selection.createRange().text : document.getSelection();
		if (text.length > 1)
		{
			vdict_enabletip=true;
			vdict_positiontip(evt);
			calldict(text, dictionaries);
		}
		return true
	}
	
	
	///////////////////////////////
	///////////////////////////////
	///////////////////////////////
	function getWordFromEvent (evt) {
	  if (document.body && document.body.createTextRange) {
		var range = document.body.createTextRange();
		range.moveToPoint(evt.clientX, evt.clientY);
		range.expand('word');
		return range.text;
	  }
	  else if (evt.rangeParent && document.createRange) {
		var range = document.createRange();
		range.setStart(evt.rangeParent, evt.rangeOffset);
		range.setEnd(evt.rangeParent, evt.rangeOffset);
		expandRangeToWord(range);
		var word = range.toString();
		range.detach();
		return word;    
	  }
	  else {
		return null;
	  }
	}
	
	function expandRangeToWord (range) {
	  var startOfWord 	= 	/^\s\S+$/;
	  var endOfWord 	= 	/^\S+\s$/;
	  var whitespace 	= 	/^\s+$/;
	  // if offset is inside whitespace
	  range.setStart(range.startContainer, range.startOffset - 1);
	  while (whitespace.test(range.toString())) {
		range.setEnd(range.endContainer, range.endOffset + 1);
		range.setStart(range.startContainer, range.startOffset + 1);
	  }
	  while (!startOfWord.test(range.toString())) {
		range.setStart(range.startContainer, range.startOffset - 1);
	  }
	  range.setStart(range.startContainer, range.startOffset + 1);
	  while (!endOfWord.test(range.toString())) {
		range.setEnd(range.endContainer, range.endOffset + 1);
	  }
	  range.setEnd(range.endContainer, range.endOffset - 1);
	  return range.toString();
	}
	
	function testSelectText(evt)
	{
		evt = (evt) ? evt : ((window.event) ? window.event : "")
		text =	getWordFromEvent(evt);
		alert(text);
		vdict_enabletip=true;
		vdict_positiontip(evt);
		calldict(text, dictionaries);
	}
	
	document.ondblclick = 	doDblClick; //ctrlrightclick;
	document.onkeydown 	= 	detectKey;
	//document.onmousemove	=	vdict_positiontip;
}