//////////// POP-UP ////////////
function popup(url, nome, width, height) {
  window.open(url, nome, 'width='+width+', height='+height+', top=2, left=2, scrollbars=no, status=no, toolbar=no, location=no, directories=no, menubar=no, resizable=no, fullscreen=no');
}

//////////// SHOW - HIDE ////////////
function show_hide(acao, ID) {
	if (acao == ''){
		if (document.getElementById(ID).style.display == "none") {
			document.getElementById(ID).style.display = "";
		}else {
		   document.getElementById(ID).style.display = "none";
		}
	}else{
		if(acao == 's'){
			document.getElementById(ID).style.display = "";
		}else{
			document.getElementById(ID).style.display = "none";
		}
	}
}

//////////// CONTA CARACTERES ////////////
function max(txarea){ 
	total = 500; 
	tam = txarea.value.length; 
	str = ""; 
	str=str+tam; 
	Restante.innerHTML = total - str;

	if (tam > total){ 
		aux = txarea.value; 
		txarea.value = aux.substring(0,total); 
		Restante.innerHTML = 0;
	}
}

//////////// CONFIRMA REMOÇÃO ////////////
function confirma_remocao(){
	if(!confirm('Deseja remover os registros selecionados?')){
		return false;
	}
}

//////////// ACENTOS ////////////
function acentos(e){
    var acentos = new String('àâêôûãõáéíóúçüÀÂÊÔÛÃÕÁÉÍÓÚÇÜ´~,!@#$%¨&()+={[}]^?/\;:>< ');      
    var k= "";
    if (e.which){
		k = e.which;
    }else{
		if (e.keyCode){
	        k = e.keyCode;
    	}
	}
    
    var rxp = new RegExp(String.fromCharCode(k))
    var pos = acentos.search(rxp);

    if (pos > -1){
        alert('Você digitou um caractere inválido.\rPor favor, reveja o texto.');
		return false;
    }else{
		return true;
    }
}

//////////// VALIDA CAMPOS ////////////
// SINTAX: valida(campos)
// campos -> nomes dos campos a serem 
//			 validados, separados por virgulas

function tokenizer(str,captura){
    var tokens = new Array();
    indiceTokens = 0;
    fimStr = str.length;
    pos = 0;
    for (i=0; i<fimStr; i++){
	 	if(str.charAt(i) == captura){
			tokens[indiceTokens] = str.substring(pos,i);
	     	pos = i + 1;
    	 	indiceTokens++;
	 	}
	}
    return tokens;
}

function valida(campos){
	var campos = tokenizer(campos+',',',');
	for(var i in campos){
		if(document.getElementById(campos[i]).value == ""){
			document.getElementById(campos[i]).style.border = "#990000 1px solid";
			document.getElementById(campos[i]).focus();
			return false;
		}
	}
}

//////////// NOT FOUND ////////////
function notfound(imagem){
	imagem.src="http://www.progbr.com/imagens/imagem_notfound.gif";
}

//////////// FOCO ////////////
function sf(ID){
	document.getElementById(ID).focus();
}

//////////// POP IMAGEM ////////////
function PopupPic(sPicURL){
	window.open( "http://progbr.com/pop_imagem.htm?"+sPicURL, "", "resizable=1,HEIGHT=200,WIDTH=200,scrollbars=yes,status=yes");
}

var arrTemp=self.location.href.split("?");
var picUrl = (arrTemp.length>0)?arrTemp[1]:"";
var NS = (navigator.appName=="Netscape")?true:false;

function FitPic() {
	iWidth = (NS)?window.innerWidth:document.body.clientWidth;
	iHeight = (NS)?window.innerHeight:document.body.clientHeight;
	iWidth = document.images[0].width - iWidth;
	iHeight = document.images[0].height - iHeight;
	window.resizeBy(iWidth, iHeight);
	self.focus();
};
