/*
	//* functions.js: Funcoes genericas em JavaScript.
	//* 
	//* <br>
	//* <br>
	//* Informacoes do CVS<br>
	//* $Source: /home/bdpa-web/bdpa/WebContent/web/js/functions.js,v $<br>
	//* $Name:  $<br>
	//* $Revision: 1.1 $<br>
	//* $Author: isaque $<br>
	//* $Date: 2006/04/17 16:28:01 $<br>
	//*
	//* EMBRAPA/CNPTIA, Equipe AINFO, <A HREF="mailto:isaque@cnptia.embrapa.br">Isaque Vacari</A>
*/
function EmBranco(str) {
    var string = new String(str);
    var retorno = true;

    for (var i=0;i<string.length;i++) {
       	if (string.substr(i,1) != " ") {
            retorno = false;
            break;
           }
    }
    return retorno;
}

function MailValido(email) {
		if(email.indexOf("@") < 2) {
		  return false;
		}

		if(email.indexOf("@",email.indexOf("@") + 1) != -1) {
    	  return false;
		}

		if(email.indexOf(".") < 1) {
    	  return false;
		}

		if(email.indexOf(" ") != -1) {
   		  return false;
		}

		if(email.indexOf(".@") > 0) {
          return false;
 		}

		if(email.indexOf("@.") > 0) {
          return false;
		}

		if(email.indexOf(".com.br.") > 0) {
    	  return false;
		}

		if(email.indexOf("/") > 0) {
			return false;
		}

		if(email.indexOf("[") > 0) {
			return false;
		}

		if(email.indexOf("]") > 0) {
			return false;
		}

		if(email.indexOf("(") > 0) {
			return false;
		}

		if(email.indexOf(")") > 0) {
			return false;
		}

		if(email.indexOf("..") > 0) {
			return false;
		}

        return true;
}

function SomenteNumero(e)
{
	if (window.event) { 
		var tecla = e.keyCode; 
	}
	else if (e.which) 
	{ 
		var tecla = e.which; 
	}	
	
	if ( (tecla == undefined) || (tecla == 13) ) {
		return true;
	}
	
	if (tecla > 47 && tecla < 58) { // numeros de 0 a 9
		return true;
	}	
	else {
		if (tecla != 8) { // backspace
			//event.keyCode = 0;
			return false;
			
		}	
		else {
		
			return true;
		}	
	}
}

function PopUp(theUrl, winName) {
	window.open(theUrl,winName,"top=0,left=0,status=yes,scrollbars=yes,menubar=yes,width=600,height=450,toolbar=yes,resizable=yes");
}

function ToPrinting(){
	if (!window.print){
		alert("Use o Netscape  ou Internet Explorer \n nas vers?es 4.0 ou superior!");
		return;
	}
	window.print();
}

function Fechar() {
	window.close();
}

function MudaSortReverse()
{
	var i;
	var opcao;
	opcao = document.formFiltro.fieldSort.options[0].selected;
	
	document.formFiltro.sortReverse.length = 0;
	document.formFiltro.sortReverse.length = 2;

	document.formFiltro.sortReverse.options[0].value = "ASC";	
	document.formFiltro.sortReverse.options[0].text  = "Ascendente";

	if (!opcao) {
		document.formFiltro.sortReverse.options[1].value = "DES";	
		document.formFiltro.sortReverse.options[1].text  = "Descendente";
	}
	else {
		document.formFiltro.sortReverse.length = 1;
	}
}

function TrocaFraseBusca() {
	document.formFiltro.fraseBusca.value = document.formBusca.fraseBusca.value;
}