﻿var mouseonwordid = null;
var mouseonlang = null;
var mouseonwordrow = null;
var trustedtranslator = 0;
var mouseX = 0;
var mouseY = 0;

function LoadTranslateInfo()
{
    document.write('<div id="translateinfo" style="z-index: 500; DISPLAY: none; POSITION: absolute"><table cellSpacing="0" cellPadding="0" border="0" style="background-color: #592331; border-right: #461C27 thin solid; border-bottom: #38161F thin solid; border-left: #7A3245 thin solid; border-top: #9C3E56 thin solid; margin: 0px; overflow: hidden; font-family: Verdana; font-size: 8pt; color: #ffffff;"><tr><td width="300" style="text-align: center;">Press T to correct or approve the translation</td></tr></table></div>');
}

function WordOver(obj, wordid, langid)
{
    mouseonwordid = wordid;
    mouseonlang = langid;
    mouseonwordrow = obj;
    
    setTimeout("WordOverAfterTimeout(" + wordid + ", " + langid + ");", 500);
}

function DropDownListWordOver(listid)
{
    var list = document.getElementById(listid);
    mouseonwordid = eval(listid + list.options[list.selectedIndex].value + 'a');
    mouseonlang = eval(listid + list.options[list.selectedIndex].value + 'b');
    
    setTimeout("WordOverAfterTimeout(" + mouseonwordid + ", " + mouseonlang + ");", 500);
}

function WordOverAfterTimeout(wordid, langid)
{
    if (mouseonwordid == wordid && mouseonlang == langid)
    {
        translateinfo.style.display = "";
    	translateinfo.style.left = mouseX - 145;
	    translateinfo.style.top = mouseY - 20;
    }
}

function WordOut()
{
    mouseonwordid = null;
    mouseonlang = null;
    translateinfo.style.display = "none";
}

function openWindow(url, w, h)
{
    var options = "width=" + w + ",height=" + h + ",resizable=no,scrollbars=yes,status=no,menubar=no,toolbar=no,location=no,directories=no";
    var newWin = window.open(url, 'Translation', options);
    newWin.focus();
}

function findX(obj)
{
    var curleft = 0;
    if(obj.offsetParent)
    while(1)
    {
        curleft += obj.offsetLeft;
        if(!obj.offsetParent)
            break;
        obj = obj.offsetParent;
    }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
}

function findY(obj)
{
    var curtop = 0;
    if(obj.offsetParent)
    while(1)
    {
        curtop += obj.offsetTop;
        if(!obj.offsetParent)
            break;
        obj = obj.offsetParent;
    }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
}

function BodyKeyPress(e)
{
    var keynum;
    if (window.event)
        keynum = e.keyCode;
    else
        keynum = e.which;
    if ((keynum == 84 || keynum == 116) && mouseonwordid != null && mouseonlang != null)
    {
        if (trustedtranslator == 1)
            mouseonwordrow.parentElement.parentElement.style.display = "none";
        openWindow("translate.aspx?langid=" + mouseonlang + "&wordid=" + mouseonwordid, 450, 600);
    }
    return true;
}

function BodyMouseMove(e)
{
	if (!e)
	    var e = window.event;
	if (e.pageX || e.pageY)
	{
		mouseX = e.pageX;
		mouseY = e.pageY;
	}
	else if (e.clientX || e.clientY)
	{
		mouseX = e.clientX + document.body.scrollLeft;
		mouseY = e.clientY + document.body.scrollTop;
	}
}