function openPopup(url, width, height, resizable) {
	var width2 = window.screen.availWidth;
	var height2 = window.screen.availHeight;
	
	var left = ((width2 - width) / 2);
	var top = ((height2 - height) / 2);
	
	var params = "top=" + top + ",left=" + left + ",width=" + width + ",height=" + height + ",resizable=" + resizable;
	
	var windowPopup = window.open(url, "", params);
	
	windowPopup.focus();
}

function fAbrePesquisaDocumento(google, idUserGc) {

	var campoPesquisa = document.getElementById("campoPesquisa");
	
	if ( campoPesquisa.value.length <= 2 ) {
		alert('Informe no mínimo 3 letras para a Pesquisa.');
		campoPesquisa.focus();
		return;
	}
	
    openPopup('/GestaoDoc/pesquisa/resultPesquisa_documentosResumoPortal_frames.jsp?aPCTodas='+escape(campoPesquisa.value)+'&usuarioGC='+idUserGc, 700, 400, 'yes,scrollbars=yes');
    
    if (google) {
    	openPopup('http://www.google.com.br/search?q='+escape(campoPesquisa.value), 700, 400, 'yes,scrollbars=yes');
    }
	
}

function fAbreIdeia(idUserGc) {
	openPopup('/GestaoDoc/tabelas/documento/insere_documento_frames.jsp?aTipoDocumento=19&tipoChamada=cadastroDireto&acao=insereDadosIdeia&usuarioGC='+idUserGc, 630, 480, 'no');
}

function fLoginMutuo(abvModulo) {
	
	var login = document.getElementById('login').value;
	var senha = document.getElementById('senha').value;
	
    Popup = window.open('', 'JanelaMutuo', 'width = 800, height = 600, top = 0, left = 0, scrollbars = yes, status = yes, toolbar = yes, location = no, directories = no, menubar = no, resizable = yes, fullscreen = no');
	Popup.document.open();
	Popup.document.write("<html>");
	Popup.document.write("<meta http-equiv='Content-Type' content='text/html;charset=UTF-8'>");
	Popup.document.write("	 <form name=\"form1\" method=\"post\" action=\"/Mutuo/\" target=\"_top\">");
	Popup.document.write(" 	    <input type=\"hidden\" name=\"mtu_acesport\" value=\"true\">");
	Popup.document.write(" 	    <input type=\"hidden\" name=\"abvModulo\" value=\""+abvModulo+"\">");
	Popup.document.write("		<input type=\"hidden\" value=\""+login+"\"  name=\"mtu_log_user\">");
	Popup.document.write("		<input type=\"hidden\" value=\""+senha+"\" name=\"mtu_sen_user\">");
	Popup.document.write(" 	    <input type=\"hidden\" name=\"mtu_abv_modulo\" value=\""+abvModulo+"\">");
	Popup.document.write("	 </form>");
	Popup.document.write("</html>");
	Popup.document.close();
	Popup.document.forms[0].submit();
	
}

function fLoginGC() {
	
	var login = document.getElementById('login').value;
	var senha = document.getElementById('senha').value;
	
  	Popup = window.open('', 'JanelaGC', 'width = 800, height = 600, top = 0, left = 0, scrollbars = yes, status = yes, toolbar = yes, location = no, directories = no, menubar = no, resizable = yes, fullscreen = no');
	Popup.document.open();
	Popup.document.write("<html>");
	Popup.document.write("<meta http-equiv='Content-Type' content='text/html;charset=UTF-8'>");
	Popup.document.write("	 <form name=\"form1\" method=\"post\" action=\"/GestaoDoc/AutenticaUsuario\" target=\"_top\">");
	Popup.document.write("		<input type=\"hidden\" value=\""+login+"\"  name=\"usuario\" size=\"30\" maxlength=\"50\" class=\"inputText\"></td>");
	Popup.document.write("		<input type=\"hidden\" value=\""+senha+"\" name=\"senha\"   size=\"30\" maxlength=\"20\" class=\"inputText\"></td>");
	Popup.document.write(" 	    <input type=\"hidden\" name=\"acao\" value=\"autenticar\">");
	Popup.document.write("	 </form>");
	Popup.document.write("</html>");
	Popup.document.close();
	
	Popup.document.forms[0].submit();	
}


function fLoginGP() {	
	
	var login = document.getElementById('login').value;
	var senha = document.getElementById('senha').value;
	
  	Popup = window.open('', 'JanelaGP', 'width = 800, height = 600, top = 0, left = 0, scrollbars = yes, status = yes, toolbar = yes, location = no, directories = no, menubar = no, resizable = yes, fullscreen = no');
	Popup.document.open();
	Popup.document.write("<html>");
	Popup.document.write("<meta http-equiv='Content-Type' content='text/html;charset=UTF-8'>");
	Popup.document.write("	 <form name=\"form1\" method=\"post\" action=\"/GestaoProj/AutenticaUsuario\" target=\"_top\">");
	Popup.document.write("		<input type=\"hidden\" value=\""+login+"\"  name=\"usuario\" size=\"30\" maxlength=\"50\" class=\"inputText\"></td>");
	Popup.document.write("		<input type=\"hidden\" value=\""+senha+"\" name=\"senha\"   size=\"30\" maxlength=\"20\" class=\"inputText\"></td>");
	Popup.document.write(" 	    <input type=\"hidden\" name=\"acao\" value=\"autenticar\">");
	Popup.document.write("	 </form>");
	Popup.document.write("</html>");
	Popup.document.close();
	
	Popup.document.forms[0].submit();
}

function fApontGP() {
	openPopup('http://gep.ctc.com.br/', 750, 500, 'yes,scrollbars=yes');
}

function fLoginClima() {	
	openPopup('/Clima/index.jsp', 580, 590, 'yes,scrollbars=yes');	
}

function fLoginBancoUsinas() {	
	openPopup('/Locais/', 580, 590, 'yes,scrollbars=yes');	
}

function fLoginRoyalties() {	
	openPopup('/Royalties/', 580, 590, 'yes,scrollbars=yes');
}

function fLoginEntMudas() {	
	openPopup('/EntMudas/' ,580, 590, 'yes,scrollbars=yes');	
}

function fLoginLims() {
	openPopup('http://srv-web2:8080/lims/', 800, 600, 'yes,scrollbars=yes');
}

function fEnviaEmailGestor() {

	var campoEmail = document.getElementById("campoEmail");
	
    openPopup('Util!faleComSeuGerente.action?email='+escape(campoEmail.value), 200, 200, 'no');
	
}

function fAbreDocumento(idDoc, idUserGc) {
	openPopup('/GestaoDoc/ManutencaoDocumentos?acao=downloadPublic&idDocumento='+idDoc+'&usuarioGC='+idUserGc, 750, 550, 'yes');	
}

function fPesquisaDocumentos(codLocal, codTipos, idUserGc) {
	openPopup('/GestaoDoc/PesquisaDocumentoServlet?&acao=pesquisaPortal&aUsina='+codLocal+'&tiposSelecionados='+codTipos+'&usuarioGC='+idUserGc, 750, 550, 'yes');		
}

function arrumaTamanhoDivs(tipo){
	w = screen.width;

	if (parseInt(navigator.appVersion)>3) {
		if (navigator.appName=="Netscape") {
			w = window.innerWidth;
		}
		if (navigator.appName.indexOf("Microsoft")!=-1) {
			w = document.body.offsetWidth;
		}
	}

	if (tipo == 1) {
		w1 = (w - 450);
	} else {
		w1 = (w - 300);
	}
	document.getElementById('content').style.width = w1+'px';
}

window.resize = arrumaTamanhoDivs;