function abreJanela(url,nome,params){
	 myWindow = window.open(url, nome, params)
}

function popup1(url)
{
	popup = window.open(url,'popup1','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,menubar=no,width=450,height=280');
}

//Maximiza a janela, para ser implementado deve ser chamado no onLoad do BODY
function maximiza(){
	top.window.moveTo(0,0);
	if (document.all) {
  		top.window.resizeTo(screen.availWidth,screen.availHeight);
	}
	else if (document.layers||document.getElementById) {
			if (top.window.outerHeight<screen.availHeight||top.window.outerWidth<screen.availWidth){
				top.window.outerHeight = screen.availHeight;
				top.window.outerWidth = screen.availWidth;
			}
		  }
}

//Centraliza a janela
function centraliza(width, height){
    ptop = 0;
    pleft = 0;
	pleft = ( screen.availWidth - width ) / 2;
	ptop = ( screen.availHeight - height ) / 2;
	top.window.moveTo(pleft, ptop);
	if (document.all) {
  		top.window.resizeTo(width, height);
	}
	else if (document.layers||document.getElementById) {
		top.window.outerHeight = height;
		top.window.outerWidth = width;
    }
}

// valida a quantidade de caracteres em um campo e trunca caso maior que o limite.
function qtdeCaracteres(obj, limite) {
	texto=obj.value;
	if (texto.length > limite) {
		alert("Este campo não pode ter mais que " + limite + " caracteres.\nSeu valor será truncado!");
		obj.value = obj.value.substr(0,limite);
	}
}


// troca caracteres invalidos no textarea por caracteres validos.
function validaConteudoTextArea(obj){
	valorAlterado ="";
	valorInvalido ="";
	letra ="";
	caracteresInvalidos = '“”—–•'; 
	caracteresValidos = '""---'; 
	total = 0;
	for (var loop=0; loop < obj.value.length; loop++){
		letra = obj.value.substr(loop,1);
		
		posicao = caracteresInvalidos.indexOf(letra);
		if (posicao==-1){
			valorAlterado += letra;
		}else{
			valorAlterado += caracteresValidos.substr(posicao,1);
			valorInvalido += letra;
			total = total+1;
		}
	}
	obj.value = valorAlterado;
	obj.returnValue = true;
}


// so digita valor numerico sem os sinais, ponto e virgula
function valorNumerico(obj){
  if (event.keyCode < 48 || event.keyCode > 57){
    event.returnValue = false; 
  }
}

// so digita caracteres 
function validaTeclaData(obj){
//alert(obj.keyCode);
 if (obj.keyCode < 47 || obj.keyCode > 57){
   obj.returnValue = false; 
  }
}

function integersOnly(e) {
e = (e) ? e : event;
var  charCode =  (e.intCode) ? e.intCode : 
((e.keyCode) ? e.keyCode : 
((e.which) ? e.which : 0));
if (intCode > 31 && 
(intCode < 48 || intCode > 57)) {
  alert("Digite apenas números.");
  return false;
}
return true;
}

function alpha(e) {
  var k;
  document.all ? k = e.keyCode : k = e.which;
  return ((k > 64 && k < 91) || (k > 96 && k < 123) || k == 8);
}

function alphaComEspaco(e) {
  var k;
  document.all ? k = e.keyCode : k = e.which;
  return ((k > 64 && k < 91) || (k > 96 && k < 123) || (k == 8) || (k == 32));
}

function alphaNumerico(e) {
  var k;
  document.all ? k = e.keyCode : k = e.which;
  return ((k > 64 && k < 91) || (k > 96 && k < 123) || (k == 8) || !( k > 31 && (k < 48 || k > 57)) );
}

function alphaNumericoComEspaco(e) {
  var k;
  document.all ? k = e.keyCode : k = e.which;
  //alert(k);
  return ((k > 64 && k < 91) || (k > 96 && k < 123) || (k == 8) || (k == 32) || !( k > 31 && (k < 48 || k > 57)) );
}


   function quantidadeMinima(elem,nome,qtde){
   		if (elem.value.length<qtde){
   			alert("Preencha o campo "+ nome + " com no mínimo "+ qtde +" caracteres." )
   			elem.focus();
   			return false;
   		}
   		return true;
   }


//validara data
function ValidaData(edit){ 
var err=0;
var psj=0;
	a=edit.value
if (a.length !=0) {
if (a.length != 10) err=1
	d = a.substring(0, 2)// month
	c = a.substring(2, 3) 
	b = a.substring(3, 5)// day
	e = a.substring(5, 6)
	f = a.substring(6, 10)// year
if (b<1 || b>12) err = 1
if (c != "/") err = 1
if (d<1 || d>31) err = 1
if (e != "/") err = 1
if (f<0 || f>9999) err = 1
if (b==4 || b==6 || b==9 || b==11){
	if (d==31) err=1
}
if (b==2){
var g=parseInt(f/4)
	if (isNaN(g)) {
		err=1
		}
	if (d>29) err=1
	if (d==29 && ((f/4)!=parseInt(f/4))) err=1
	}
if (err==1){
	edit.value = ""
	alert("Digite a data no formado solicitado!(DD/MM/YYYY)")
	edit.focus();
	return false;
	}
  return true;}
else 
 return false;
}

function preenchido (edit) {
  if (edit.value.length > 0) {
    return true;
  } else {
    return false;
  }
}

function preenchidoNome (edit, nome) {
  if (preenchido (edit)) {
    return true;
  } else {
    alert ('Campo [' + nome + '] não preenchido');
    edit.focus();
    return false;
  }
}

function preenchidoEmail (edit, nome) {
  if (echeck (edit.value)) {
    return true;
  } else {
    alert ('Favor digitar um Email válido');
    edit.focus();
    return false;
  }
}

/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false
		 }

 		 return true					
	}
