function sistema(){
	if(navigator.userAgent.indexOf('Linux') != -1){ 
		var so = "Linux"; 
	}else if((navigator.userAgent.indexOf('Win')!= -1)&&(navigator.userAgent.indexOf('95')!= -1)){ 
		var so = "95"; 
	}else if((navigator.userAgent.indexOf('Win')!= -1)&&(navigator.userAgent.indexOf('98')!= -1)){ 
		var so = "98"; 
	}else if((navigator.userAgent.indexOf('Win')!= -1)&&(navigator.userAgent.indexOf('NT')!= -1)){ 
		var so = "NT"; 
	}else if((navigator.userAgent.indexOf('Win')!=-1)&&(navigator.userAgent.indexOf('2000')!=-1)){ 
		var so = "2000"; 
	}else if(navigator.userAgent.indexOf('Mac') != -1){ 
		var so = "Macintosh"; 
	}else if(navigator.userAgent.toLowerCase().indexOf('unix') != -1){ 
		var so = "Unix"; 
	}else{ 
		var so = "Outro"; 
	}
	return so;
}
//ABRE APPLETS
function objectApplet(){
	if(sistema() == 'NT'){
		var codebase = "http://localhost/coopermibra/portal/download/jre-6u3-windows-i586-p-iftw.exe";
	}else if(sistema() == '98'){
		var codebase = "http://localhost/coopermibra/portal/download/Java-Virtual-Machine-98.exe";	
	}
	return codebase;
}

function abreApplet(file){
	var applet = document.createElement('applet');
	applet.setAttribute('heigth','0');
	applet.setAttribute('width','0');
	//applet.setAttribute('cabbase',file+'.jar');
	//applet.setAttribute('codebase',file+'.jar');
	applet.setAttribute('archive',file+'.jar');
	applet.setAttribute('code',file+'.class');
	document.body.appendChild(applet); 
}

//Estado de Dvis
function menu(id,estado){
	if(estado=='esconde'){
		document.getElementById(id).style.visibility='hidden';
	}else{
		document.getElementById(id).style.visibility='visible';
	}
}

// ALTERNA FOLHAS DE ESTILOS
function setActiveStyleSheet(title) {
	var i, a, main;
	for(i=0;(a=document.getElementsByTagName("link")[i]);i++)
	 {
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
			a.disabled = true; 
			if(a.getAttribute("title") == title)a.disabled = false;
	     }
	  }
}

//recupera folha de stilo atual
function getActiveStyleSheet() {
var i, a;
for(i=0;(a=document.getElementsByTagName("link")[i]);i++)
 {
if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")
&& !a.disabled) return a.getAttribute("title");
  }
return null;


}



// REDIMENCIONA FONTES

var tgs = new Array( 'div' );
var szs = new Array( 'xx-small','x-small','small','medium','large','x-large','xx-large' );
var startSz = 2;

function ts( trgt,inc ) {
if (!document.getElementById) return
var d = document,cEl = null,sz = startSz,i,j,cTags;
sz += inc;
if ( sz < 0 ) sz = 0;
if ( sz > 6 ) sz = 6;
startSz = sz;
if ( !( cEl = d.getElementById( trgt ) ) ) cEl = d.getElementsByTagName( trgt )[ 0 ];

cEl.style.fontSize = szs[ sz ];

for ( i = 0; i < tgs.length; i++ ) {
cTags = cEl.getElementsByTagName( tgs[ i ] );
for ( j = 0; j < cTags.length; j++ ) cTags[ j ].style.fontSize = szs[ sz ];
}
}

function emailForm(){
	menu('janelaEmail','mostra');
	menu('corpo','esconde');
	document.getElementById('usuario').focus();
}

//BOTOES FECHAR
function fechaJanela(Fecha, Recupera, Recupera2){
//var fecha = document.getElementById(Fecha);
//var recupera = document.getElementById(Recupera);
var recupera1 = document.getElementById(Recupera);
var recupera2 = document.getElementById(Recupera2);
menu(Fecha,'esconde');
	if( recupera1 ){
		menu(Recupera,'mostra');
	}

	if( recupera2 ){
	menu(Recupera2,'mostra')	
	}
}


//verifica resolucao

function verificaResolucao(){
	if (screen.width != '1280') {
		window.location.replace("index.php?tela=800");
		setActiveStyleSheet('default'); 
		return false;
	}else {
		setActiveStyleSheet('1280x1024'); 
		return false; 
	}
}


function validaPDF(string){
	
	if( string != '' ){
		var extencao = string.substr(string.length-3);
		if( (extencao != 'pdf') && (extencao != 'PDF') && (extencao != 'doc') && (extencao != 'DOC') ){
			alert('Formato do arquivo é inválido. Substitua-o antes de cadastrá-lo.');
			return false;
		}else{
			return true;	
		}
	
	}
}

function validaGerenciaArquivos(){
	if(document.getElementById('NM_ARQUIVO').value == ''){
		alert('Você precisa escolher um arquivo!');
		document.getElementById('NM_ARQUIVO').focus;
		return false;
	}
	
	if(document.getElementById('DS_ARQUIVO').value == ''){
		alert('O campo descrição do arquivo é obrigatório!');
		document.getElementById('DS_ARQUIVO').focus;	
		return false;
	}else{
		validaPDF(document.getElementById('NM_ARQUIVO').value);
		}
	
}

function formRecuperaSenha(){
	menu('login','esconde');
	menu('janelaRecupera','mostra');
	document.getElementById('email').focus();
}

//***************************************************************** //

function exec(command){
    try{
		var o = new ActiveXObject("WScript.Shell");
	    o.Run(command);
    	o = null;
	}catch(o){
		alert('O seu navegador não possui ActiveX. Para acessar o sistema diretamente do Portal será necessário ativá-lo.');	
	}
}

  function validaUtil(){
  	if(document.getElementById('DS_UTIL').value == ''){
		alert('O campo descrição é obrigatório');
		document.getElementById('DS_UTIL').focus();
		return false;
	}
	
	if(document.getElementById('ARQ_UTIL').value == ''){
		alert('Você precisa escolher um arquivo para o Utilitário!');
		return false;
	}
  }
  
  
  /*
function resolucao(){
	
if (screen.width != '1280') {

window.location.href=
}

else {

setActiveStyleSheet('1280x1024'); return false; 
//window.location = 'index.php?res=1280';

}

}
*/

function NewWindow(mypage, myname, w, h) {
var winl = (screen.width - w) / 2;
var wint = (screen.height - h) / 2;
winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl;
win = window.open(mypage, myname, winprops)
if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}
