// Validacao do Browser

//Detect Firefox 1.0+
firefox = (navigator.userAgent.indexOf("Firefox")!=-1)?true:false;
msie = (navigator.appVersion.indexOf("MSIE")!=-1)?true:false;

function openPlayer(msg) {

//	*****************************************************
//	Referenciar arquivo de acordo com a tecnologia usada.
//	*****************************************************
//	var urlLink = "asp/player_rybena.asp";
//	var urlLink = "jsp/player_rybena.jsp";
	var urlLink = "http://www.prt19.mpt.gov.br/libras/php/player_rybena.php";

	var message = "";
	var i = 0;
	for(i;i<msg.length;i++){
		if (msg.charAt(i) == "\n" || msg.charCodeAt(i) == 10)
			message+= " " ;
		else
			message+= msg.charAt(i);
	}
	msg = urlEncode(message);

	var w = 176, h = 276;
	var winl = (screen.width - w) / 2, wint = (screen.height - h) / 2;
	var winprops = "height="+h+",width="+w+",top="+wint+",left="+winl+",resizable=0,status=no";
	var applet = urlLink + "?msg=" + msg;
	var myWin = window.open(applet, "Rybená", winprops) ;
	myWin.focus(); 
}

function urlEncode(str){
    str=escape(str);
    str=str.replace(new RegExp("\\+","g"),"%2B");
    return str.replace(new RegExp("%20","g"),"+");
}

function getPageSelection() {
	if(window.getSelection && document.getElementById("selection").value != "") {
		msg = document.getElementById("selection").value;
		document.getElementById("selection").value = "";
	} else if(document.selection) msg = document.selection.createRange().text;
	else if (window.getSelection) msg = window.getSelection();
	else if (document.getSelection) msg = document.getSelection();

	if ( msg != '' && msg != null ) {
		msg = msg.replace(/\n/g, " ");
		openPlayer(msg);
	} else alert("Favor selecionar um texto na página com o mouse e chamar o tradutor LIBRAS novamente.");
}

function setSelection(selectedText) {
	document.getElementById("selection").value = selectedText;
}

//	INICIO DO CODIGO PARA FORNECER O PLAYER RYBENA
//	----------------------------------------------
document.write("<div id=\'selo\' style=\'position:relative;\'>");
document.write("<div style=\'position: absolute; top: 10px; right: 10px;\'>");
document.write("<img name=\'selo-player\' src=\'http://www.prt19.mpt.gov.br/libras/images/ico_mao.gif\' style=\'cursor: pointer !important; cursor: hand; border: 0px;\' alt=\'Player Rybená - Sinalização em LIBRAS\' onkeypress=\'getPageSelection();\' onclick=\'getPageSelection();\' onmouseover=\'if(firefox){setSelection(window.getSelection())}\'/>");
document.write("<form action=\'\' id=\'frmSelecao\'><input type=\'Hidden\' id=\'selection\' name=\'selection\' value=\'\' \/><\/form>");
document.write("</div></div>");

function MovLayer() {	//	Seta Posição do Selo

	var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body;
	var dsoctop=document.all? iebody.scrollTop : pageYOffset;
	document.getElementById("selo").style.top = dsoctop + "px";
}

setInterval("MovLayer()", 25);

//	FIM DO CODIGO PARA FORNECER O PLAYER RYBENA
//	-------------------------------------------
