function semerro(){
return true;
}
window.onerror=semerro;

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}


// JavaScript Document

//CAMPO COM SOMENTE NUMEROS, SEM PONTO, BARRA, TRAÇO

	function campo_numerico2(){
			if (event.keyCode < 45 || event.keyCode > 57) event.returnValue = false;
			if (event.keyCode == 46) event.returnValue = false;
			if (event.keyCode == 47) event.returnValue = false;
			if (event.keyCode == 45) event.returnValue = false;
	}



// SEGUNDA OPÇÃO DE PASSAR OS CAMPOS USANDO O ENTER 
 // JavaScript Document
 function handleEnter (field, event) {
   var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
 	if (keyCode == 13) {
 	  var i;
 	  for (i = 0; i < field.form.elements.length; i++)
 	    if (field == field.form.elements[i])
 		  break;
 	  i = (i + 1) % field.form.elements.length;
 	  while (field.form.elements[i].type == "hidden")
 	    i = (i + 1) % field.form.elements.length;
 	  field.form.elements[i].focus();
 	  return false;
 	} 
 	else
 	  return true;
 }     
    
 function pular(){
   if (window.event.srcElement.type != 'submit' && window.event.srcElement.type != 'button' && window.event.srcElement.type != 'reset' && window.event.srcElement.type != 'textarea'){
 	 var ele = window.event.srcElement;
     var index = ele.sourceIndex;
	 return handleEnter(ele, event);
   }
   
 }
   
 document.onkeypress = pular;



function semerro(){
return true;
}
window.onerror=semerro;

//ABRE UMA POP UP DE CADA VEZ NO CENTRO DA TELA

var winhandle = null;
function  popUpCentro(url,largura,altura,nomeJanela){ 
  if ((winhandle != null) && (! winhandle.closed)){
      winhandle.location.replace(url);
    //winhandle.resizeTo(aWidth,aHeight);
  }else{
	  var minimo = screen.width/4; // esta será a largura e a altura mínima    evitando uma  
	  var maximo = screen.height - 100; // esta será a largura e a altura máxima 
	  var w = ( ( ( (largura>minimo)?largura:minimo )<maximo )?largura:maximo); 
	  var h = ( ( ( ( altura>minimo )?altura:minimo )<maximo )?altura:maximo); 
	  var l = (screen.width/2) - w/2;    // valor para a posição na horizontal 
	  var t = (screen.height/2) - h/2;    // valor para a posição na vertical 
	  var argumentos = 'copyhistory=yes,width='+w+',height='+h+',left='+l+',top='+t+',screenX='+l+',screenY='+t; 
	  winhandle= window.open(url,nomeJanela,argumentos); 
     // winhandle=window.open(aURL, "imagewin", 'width=' + eval(aWidth) + ',height=' + eval(aHeight) + ',scrollbars=no'); 
  }
	 winhandle.focus();
} 


// FORMATAR CAMPOS

	function formatar(src, mask) {
		var i = src.value.length;
		var saida = mask.substring(0,1);
		
		var texto = mask.substring(i)
		
		if (texto.substring(0,1) != saida) {
			src.value += texto.substring(0,1);
		}
	}



// COMPLETA TELEFONE
 function completaTelefone(campo) 
 { 
      qtdcaracteres = (campo.value).length; 

      if(qtdcaracteres == '') 
        campo.value = campo.value + "("; 

     if(qtdcaracteres == 3) 
        campo.value = campo.value + ")"; 

     if(qtdcaracteres == 8) 
        campo.value = campo.value + "-"; 
 } 
//


// MASCARA PARA O CAMPO CEP
function maskCep(campo){
  
  if(campo.value.length==0){
    campo.className = "muda  mascara_cep";
  }else if(campo.value.length==1){
    campo.className = 'muda mascara_cep mascara_cep2';
  }else if(campo.value.length==2){
    campo.className = 'muda mascara_cep mascara_cep3';
  }else if(campo.value.length==3){
    campo.className = 'muda mascara_cep mascara_cep4';
  }else if(campo.value.length==4){
    campo.className = 'muda mascara_cep mascara_cep5';
  }else if(campo.value.length==5){
    campo.className = 'muda mascara_cep mascara_cep6';
  }else if(campo.value.length==6){
    campo.className = 'muda mascara_cep mascara_cep7b';
  }else if(campo.value.length==7){
    campo.className = 'muda mascara_cep mascara_cep7';
  }else if(campo.value.length==8){
    campo.className = 'muda mascara_cep mascara_cep8';
  }else if(campo.value.length==9){
    campo.className = 'muda mascara_cep mascara_cep9';
  }

}

// FIRM MASCARA O CAMPO CEP


// MASCARA PARA O CAMPO TELEFONE
function maskTelefone(campo){
	for(i=1;i<=13;i++){
		 if(campo.value.length==i){
		   campo.className = "muda  mascara_tel"+(i);
		 }
     }
}
// FIM MASCASRA CAMPO TELEFONE



//-----------------------------------
<!-- MASCARA DATA E VALIDA
function amf2005_valid_date(l,dd,mm,yy) 
{ 
    z='err'; 
    if (l == 6 || l == 8) 
    { 
        xx=yy; 
        if (dd >= 1 && dd <= 31) 
        { 
            if (mm == 2 || mm == 4 || mm == 6 || mm == 9 || mm == 11) 
            { 
                if (dd <= 30) 
                { 
                    if (mm == 2) 
                    { 
                        if (dd <= 28) 
                        { 
                            z='ok'; 
                        } 
                        else 
                        { 
                            if (dd == 29) 
                            { 
                                bb=xx%4;    // 4 by 4 
                                if (bb == 0) 
                                { 
                                    cc=xx%100;    // 100 by 100 
                                    if (cc == 0) 
                                    { 
                                        qq=xx%400;    // 400 by 400 
                                        if (qq == 0) 
                                        { 
                                            z='ok'; 
                                        }; 
                                    } 
                                    else 
                                    { 
                                        z='ok'; 
                                    };     
                                }; 
                            }; 
                        }; 
                    } 
                    else 
                    { 
                        z='ok'; 
                    }; 
                }; 
            } 
            else 
            { 
                if (mm >= 1 && mm <= 12) { z='ok'; }; 
            }; 
        }; 
    }; 
    ii=200;        // inner parameter 
    if (xx < 1600 || xx > 2400 || xx < 2005 - ii || xx > 2005 + ii) { z='err'; }; 
    return z; 
}; 

function amf2005_consist_date(dat) 
{ 
    n='0123456789'; 
    d=dat.value; 
    l=d.length; 
    s=''; 
    for (i=0; i<l; i++) 
    { 
        c=d.charAt(i); 
        if (n.indexOf(c) >= 0) 
        { 
            s+=c; 
        }; 
    }; 
    l=s.length; 
    xx='0000'; 
    r=s; 
    if (l > 8) 
    { 
        r=s.substr(0,8); 
        s=r; 
        l=8; 
    }; 
    if (l == 6) 
    { 
        dd=s.substr(0,2); 
        mm=s.substr(2,2); 
        yy=s.substr(4,2); 
        if (yy < 50) 
        { 
            xx='20'+yy; 
        } 
        else 
        { 
            xx='19'+yy; 
        }; 
        ww=dd+'/'+mm+'/'+yy; 
    }; 
    if (l == 8) 
    { 
        dd=s.substr(0,2); 
        mm=s.substr(2,2); 
        yy=s.substr(4,4); 
        xx=yy; 
        ww=dd+'/'+mm+'/'+yy; 
    }; 
    if (l == 6 || l == 8) 
    { 
        z=amf2005_valid_date(l,dd,mm,xx); 
        if (z == 'ok') { r=ww; }; 
    }; 
    dat.value=r; 
    return 'ok'; 
}; 

function amf2005_update_date(dat) 
{ 
    n='0123456789'; 
    d=dat.value; 
    l=d.length; 
    s=''; 
    for (i=0; i<l; i++) 
    { 
        c=d.charAt(i); 
        if (n.indexOf(c) >= 0) 
        { 
            s+=c; 
        }; 
    }; 
    l=s.length; 
    if (l == 6) 
    { 
        dd=s.substr(0,2); 
        mm=s.substr(2,2); 
        yy=s.substr(4,2); 
        if (yy < 50) 
        { 
            yy='20'+yy; 
        } 
        else 
        { 
            yy='19'+yy; 
        }; 
        ww=dd+'/'+mm+'/'+yy; 
    }; 
    if (l == 8) 
    { 
        dd=s.substr(0,2); 
        mm=s.substr(2,2); 
        yy=s.substr(4,4); 
        ww=dd+'/'+mm+'/'+yy; 
    }; 
    rr=''; 
    if (l == 6 || l == 8) 
    { 
        z=amf2005_valid_date(l,dd,mm,yy); 
        if (z == 'ok') 
        {  
            rr=ww; 
        }; 
    }; 
    dat.value=rr; 
    return 'ok'; 
}; 
<!-- FIM MASCARA DATA E VALIDA

//-------------------------------------


//EXIBIR E ESCONDER CARREGADOR DE PAGINAS

	//exibe e esconde layers no ie e ns
	function mostra(obj)
	{
		if (document.layers)
		{
			if (typeof(document.layers[obj]) == 'object')
			{
				document.layers[obj].position='relative';
				document.layers[obj].visibility='show';
			}
		}
		else
		{
			if (document.all)
			{
				if (typeof(document.all[obj]) == 'object')
				{
					document.all[obj].style.position='relative';
					document.all[obj].style.visibility='visible';
				}
			}
			else
			{
				if (typeof(document.getElementById(obj)) == 'object')
				{
					document.getElementById(obj).style.position='relative';
					document.getElementById(obj).style.visibility='visible';
				}
			}
		}
	}
		

	function esconde(obj)
	{
		if (document.layers)
		{
			if (typeof(document.layers[obj]) == 'object')
			{
				document.layers[obj].position='absolute';
				document.layers[obj].visibility='hide';
			}
		}
		else
		{
			if (document.all)
			{
				if (typeof(document.all[obj]) == 'object')
				{
					document.all[obj].style.position='absolute';
					document.all[obj].style.visibility='hidden';
				}
			}
			else
			{
				if (typeof(document.getElementById(obj)) == 'object')
				{
					document.getElementById(obj).style.position='absolute';
					document.getElementById(obj).style.visibility='hidden';
				}
			}
		}
	}



//CAMPO COM SOMENTE NUMEROS, SEM PONTO, BARRA, TRAÇO

	function campo_numerico2(){
			if (event.keyCode < 45 || event.keyCode > 57) event.returnValue = false;
			if (event.keyCode == 46) event.returnValue = false;
			if (event.keyCode == 47) event.returnValue = false;
			if (event.keyCode == 45) event.returnValue = false;
	}


// MASCARA CNPJ E CPF ****************************************************************************************

	function campo_numerico (){
			if (event.keyCode < 45 || event.keyCode > 57) event.returnValue = false;
	}


	/*function cnpj_cpf verifica qual das funcoes tem que chamar cpf ou cnpj*/
    // com select
	function cnpj_cpf(campo,documento,f,formi){

		form = formi;

		for (Count = 0; Count < 3; Count++){

			if (form.rad[Count].selected)
				break;
		}


		if (Count == 0){
		}
		else if(Count == 1){
             mascara_cnpj (campo,documento,f);			
		}
		else if (Count == 2){
			 mascara_cpf (campo,documento,f);
	    }else{
		}
	}

	
	
	function cnpj_cpf2(campo,documento,f,formi){

		form = formi;
		if (document.getElementById("rad").value == "CNPJ"){
             mascara_cnpj (campo,documento,f);			
		}
		else if(document.getElementById("rad").value == "CPF"){
			 mascara_cpf (campo,documento,f);
        }
	}
	

	function cnpj_cpf3(campo,documento,f,formi){
		form = formi;

		var m = document.forms[f].elements['rad'];

		for (Count = 0; Count <= 1; Count++){
			if (m[Count].checked)
				break;
		}

		if (Count == 0){
			mascara_cnpj(campo,documento,f);
		}
		else if(Count == 1){
		    mascara_cpf(campo,documento,f);
		}
	}


	
	function mascara_cnpj (campo,documento,f){
		var mydata = '';
		mydata = mydata + documento;

		if (mydata.length == 2){
			mydata   = mydata + '.';

			ct_campo = eval("document."+f+"."+campo+".value = mydata");
			ct_campo;
		}

		if (mydata.length == 6){
					mydata   = mydata + '.';

					ct_campo = eval("document."+f+"."+campo+".value = mydata");
					ct_campo;
		}

		if (mydata.length == 10){
			mydata 	  = mydata + '/';

			ct_campo1 = eval("document."+f+"."+campo+".value = mydata");
			ct_campo1;
		}

		if (mydata.length == 15){
					mydata 	  = mydata + '-';

					ct_campo1 = eval("document."+f+"."+campo+".value = mydata");
					ct_campo1;
		}

		if (mydata.length == 18){

			valida_cnpj(f,campo);
		}
	}


	function mascara_cpf (campo,documento,f){
			var mydata = '';
			mydata = mydata + documento;

			if (mydata.length == 3){
				mydata   = mydata + '.';

				ct_campo = eval("document."+f+"."+campo+".value = mydata");
				ct_campo;
			}

			if (mydata.length == 7){
						mydata   = mydata + '.';

						ct_campo = eval("document."+f+"."+campo+".value = mydata");
						ct_campo;
			}

			if (mydata.length == 11){
				mydata 	  = mydata + '-';

				ct_campo1 = eval("document."+f+"."+campo+".value = mydata");
				ct_campo1;
			}

			if (mydata.length == 14){

				valida_cpf(f,campo);
			}

	}


	function valida_cnpj(f,campo){

			pri = eval("document."+f+"."+campo+".value.substring(0,2)");
			seg = eval("document."+f+"."+campo+".value.substring(3,6)");
			ter = eval("document."+f+"."+campo+".value.substring(7,10)");
			qua = eval("document."+f+"."+campo+".value.substring(11,15)");
			qui = eval("document."+f+"."+campo+".value.substring(16,18)");

			var i;
			var numero;
			var situacao = '';

			numero = (pri+seg+ter+qua+qui);

			s = numero;


			c = s.substr(0,12);
			var dv = s.substr(12,2);
			var d1 = 0;

			for (i = 0; i < 12; i++){
				d1 += c.charAt(11-i)*(2+(i % 8));
			}

			if (d1 == 0){
				var result = "falso";
			}
				d1 = 11 - (d1 % 11);

			if (d1 > 9) d1 = 0;

				if (dv.charAt(0) != d1){
					var result = "falso";
				}

			d1 *= 2;
			for (i = 0; i < 12; i++){
				d1 += c.charAt(11-i)*(2+((i+1) % 8));
			}

			d1 = 11 - (d1 % 11);
			if (d1 > 9) d1 = 0;

				if (dv.charAt(1) != d1){
					var result = "falso";
				}


			if (result == "falso") {
				alert("CNPJ inválido!");
				aux1 = eval("document."+f+"."+campo+".focus");
				aux2 = eval("document."+f+"."+campo+".value = ''");
			}
	}


	function valida_cpf(f,campo){

			pri = eval("document."+f+"."+campo+".value.substring(0,3)");
			seg = eval("document."+f+"."+campo+".value.substring(4,7)");
			ter = eval("document."+f+"."+campo+".value.substring(8,11)");
			qua = eval("document."+f+"."+campo+".value.substring(12,14)");

			var i;
			var numero;

			numero = (pri+seg+ter+qua);

			s = numero;
			c = s.substr(0,9);
			var dv = s.substr(9,2);
			var d1 = 0;

			for (i = 0; i < 9; i++){
				d1 += c.charAt(i)*(10-i);
			}

			if (d1 == 0){
				var result = "falso";
			}

			d1 = 11 - (d1 % 11);
			if (d1 > 9) d1 = 0;

			if (dv.charAt(0) != d1){
				var result = "falso";
			}

			d1 *= 2;
			for (i = 0; i < 9; i++){
				d1 += c.charAt(i)*(11-i);
			}

			d1 = 11 - (d1 % 11);
			if (d1 > 9) d1 = 0;

			if (dv.charAt(1) != d1){
				var result = "falso";
			}


			if (result == "falso") {
				alert("CPF inválido!");
				aux1 = eval("document."+f+"."+campo+".focus");
				aux2 = eval("document."+f+"."+campo+".value = ''");

			}
	}

// FIM  MASCARA CNPJ E CPF ****************************************************************************************


// ************************abre janela modal no ie e no firefox********************************************

function openModal(pUrl, pWidth, pHeight) {
	if (window.showModalDialog) {
		return window.showModalDialog(pUrl, window,"dialogWidth:" + pWidth + "px;dialogHeight:" + pHeight + "px"+"edge: raised; center: Yes; help: No; resizable: No; status: No;scroll: Yes");
	} else {
		try {
			netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserWrite");
			window.open(pUrl, "wndModal", "width=" + pWidth+ ",height=" + pHeight + ",resizable=no,modal=yes,scroll=yes");
			return true;
		}
		catch (e) {
			alert("Script não confiável, não é possível abrir janela modal.");
			return false;
		}
	}
}
  
//******************************************************************************************
