
// --------------------------------------------------------------------
// Universaltranslator
// 09.04.2004, Deutsche Welle, JH
//
// Use this Universaltranslator in Webpages like this:
// <SCRIPT LANGUAGE="JavaScript1.2" SRC="klingon_translator.js"></SCRIPT>


//Set Source Language (mainly Klingon) here. ISO Codes goes here!
var source_language = "kli";
//Set Destination Language (mainly English, German) here. ISO Codes goes here!
//All
var dest_language = "en,de";
//Link or Button for the Translator
var mrCheckButton = "<IMG BORDER=0 SRC=../img/mr_klingon.gif>";


//DO NOT CHANGE THINGS BELOW THIS!


var mrCheckOB;
mrCheckOB = 0;
var mrc_url;

	// *** PLATFORM ***
var agt=navigator.userAgent.toLowerCase();
var is_mac = (agt.indexOf("mac")!=-1);


	// *** Variablen Definitionen
var mrCheckPattern = "";
var mrCheckWin;
var mrCheckWhitespace = new RegExp('([ \\n\\t\\v\\r\\f]|%0D|%0A|%20)+', 'g');
var mrc_url = "";

        // ** parse all browser windows for a text selection.
function mrCheckFindSelection (w)
{
	var pattern;
	var TextRange;
	try{
		if (is_mac){
			pattern = escape(w.document.getSelection());
		}else{
			pattern = escape(w.document.selection.createRange().text);
		}
 		if (pattern) {
			return (pattern);
		}
	}catch(e){
		pattern = "";
	}
		for (var i=0; i<w.frames.length; i++) {
			pattern = mrCheckFindSelection (w.frames[i]);
			if (pattern) {
				return (pattern);
			}
		}
	return ("");
}

function mrCheckGetSelection()
{
        mrCheckPattern = mrCheckFindSelection(window.top);
        if (mrCheckPattern.length > 0) {
                //mrcStatusText = 'Status: Button dr\u00FCcken und "' + unescape(mrCheckPattern) + '" \u00FCbersetzen.';
				mrcStatusText = 'Highlight one word and click the button -- Ein Wort markieren und Button klicken!';
        } else {
                mrcStatusText = 'Highlight one word and click the button -- Ein Wort markieren und Button klicken!';

        }
	setTimeout("window.top.status=mrcStatusText",0);
        return true;
}


        // ** onMouseOut-Message
function mrCheckOnOut() {
        mrcStatusText = "";
	setTimeout("window.top.status=mrcStatusText",0);
        return true;
}


        // ** run Query against Database and start a new window
function mrCheckStartQuery()
{

	

	
	if (mrCheckPattern.length > 0)
	{
		if(mrCheckPattern.length > 100)
		{
			alert ("The highlighted text is too long! \n -------- \nDer markierte Text ist zu lang!");
		}
		else
		{
			mrc_url = 'klingon_translator.php?source=' + source_language + '&dest=' + dest_language + '&pattern=' + mrCheckPattern;

        	
        	if (!mrCheckWin || mrCheckWin.closed)
			{
			
        		mrCheckWin = window.open (mrc_url,'KlingonTranslator','width=270,height=320,directories=0,fullscreen=0,location=0,menubar=0,resizable=0,scrollbars=0,status=0,toolbar=0');
        	}
			else
			{
			
        		mrCheckWin.location.href = mrc_url;
        	}

        	if(mrCheckWin)
			{
			
        		mrCheckWin.focus();
        	}
		}
	}
	else
	{
    	alert ("You have to highlight a word first and then click the button. \n -------- \nSie m"+"\u00FC"+"ssen zuerst ein Wort markieren und anschlie"+"\u00DF"+"end den Button anklicken.");
    }
    return false;
}


// Scroll-Effekt
					  var ie = document.all ? true : false;
					  var ns = document.layers ? true : false;
					  var offset=50;
					  setTimeout('glue()',1000);

						function glue()
						{
					    	if (ns)
				    		{
					      		var pos = document.anchors['dummy'];
					      		var posi = pos.y;
			  		    		var posix = pos.x;
		  				  		document.layers['sticker'].pageX = posix;
					      		if(window.pageYOffset + offset > posi)
			  		    		{
			  		    			document.layers['sticker'].pageY = window.pageYOffset + offset; //NN
	  		        			}
							  	else
							  	{
							  		document.layers['sticker'].pageY = posi;
							  	}
				    		}
	 						if (ie)
					 		{
								var pos = document.all.dummy;
								posi = getTop(pos);
								posx = getLeft(pos);
								document.all['sticker'].style.posLeft = posx;

								if(document.body.scrollTop  + offset > posi)
								{
									document.all['sticker'].style.posTop =	document.body.scrollTop  + offset; //IE
								}
								else
								{	document.all['sticker'].style.posTop = posi;	}
							}
							setTimeout('glue()',50);
						}

						function getLeft(l)
						{
						  if (l.offsetParent) return (l.offsetLeft + getLeft(l.offsetParent));
						  else return (l.offsetLeft);
						}

						function getTop(l)
						{
							if (l.offsetParent) return (l.offsetTop + getTop(l.offsetParent));
							else return (l.offsetTop);
						}
// Scroll-Effekt Ende




	// ** Print mrCheck-Button
if(mrCheckOB == 0) {
	document.write ('<p align="left"><a name="dummy"></a></p><div name="sticker" id="sticker" style="position:absolute;"><a href="' + mrc_url + '" onFocus="this.blur();" onMouseOver="return mrCheckGetSelection();" onMouseOut="return mrCheckOnOut();" onClick="return mrCheckStartQuery();">' + mrCheckButton + '</a></div>');
}

