// bloqueia letras em campo de formulário
function numero(objEvent) 
{
  var ie = (typeof window.ActiveXObject != 'undefined');   
	var iKeyCode;  
	 
	if (ie) {  
	  iKeyCode = objEvent.keyCode;   
	} else {
	  iKeyCode = objEvent.which; 
	}   
  if(iKeyCode>=48 && iKeyCode<=57) return true;
  return false;
}

function decimal(objEvent) 
{
  var ie = (typeof window.ActiveXObject != 'undefined');   
	var iKeyCode;  
	 
	if (ie) {  
	  iKeyCode = objEvent.keyCode;   
	} else {
	  iKeyCode = objEvent.which; 
	}
  if((iKeyCode>=48 && iKeyCode<=57) || (iKeyCode==46) || (iKeyCode==44)) return true;
  return false;
}




//-------------------------------------------------------------------------------------------------------------------
	<!--
	function MM_preloadImages() { //v3.0
	var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
	}
	
	function MM_swapImgRestore() { //v3.0
	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
	}
	
	function MM_findObj(n, d) { //v4.01
	var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	if(!x && d.getElementById) x=d.getElementById(n); return x;
	}
	
	function MM_swapImage() { //v3.0
	var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
	}
	//-->
//-------------------------------------------------------------------------------------------------------------------
	<!--
	function sair() {
		parent.location.href = "index.php"
	}

	//-->	
//-------------------------------------------------------------------------------------------------------------------
<!--	
function Stat(s)
 {
 window.status = s;
 return true
 }
//-->	
	
//-------------------------------------------------------------------------------------------------------------------
	<!--

	function objDatas(cod, dt) {
		this.CodDis = cod;
		this.Datas = dt;
	}

	//-->
//-------------------------------------------------------------------------------------------------------------------
	<!--

	function Exportar() {
			var table = pegaObjeto("Container");
			var html = table.outerHTML;
			pegaObjeto("inpExportacao").value = html;
			pegaObjeto("frm").target = "NewWindow";
			pegaObjeto("frm").action = "detExportar.asp";			
			pegaObjeto("frm").submit();
		}

	//-->
//-------------------------------------------------------------------------------------------------------------------
	<!--

		function Imprimir(t) {
			
			var table = pegaObjeto("Container");
			var html = table.outerHTML;
			var h, w
			
			if(t=="retrato") {
				w = "600";
				h = "400";
			}else if(t=="paisagem") {
				w = "800";
				h = "400";			
			}
				
			var win = window.open("about:blank", "NewWindow","width=" + w + ",height=" + h + ",scrollbars=yes,resizable=no,menubar=yes,status=yes");
			pegaObjeto("inpExportacao").value = html;
			pegaObjeto("inpExpNomeRelatorio").value = pegaObjeto("NomeRelatorio").innerText;
			pegaObjeto("inpExpNomeHospital").value = pegaObjeto("inpCodHospital")[pegaObjeto("inpCodHospital").selectedIndex].text;

			pegaObjeto("frm").target = "NewWindow";
			pegaObjeto("frm").action = "detImprimir.asp";			
			pegaObjeto("frm").submit();
		}

	//-->
//-------------------------------------------------------------------------------------------------------------------
	<!--

	function Upload(pPasta,pCampo) {
		var str = "../Upload/frmUpload.asp?strDestino=../ADMUpload/ADMUpload.asp&acao=NOVO&inpDsPasta=" + pPasta + "&inpDsCampo=" + pCampo;
		window.open(str,'Upload', 'width=300,height=150, status=yes');	
	}

	//-->
//-------------------------------------------------------------------------------------------------------------------
	<!--

	function trim(inputString) {
			
		if (typeof inputString != "string") { return inputString; }
			var retValue = inputString;
			var ch = retValue.substring(0, 1);

			while (ch == " ") { // Check for spaces at the beginning of the string
				retValue = retValue.substring(1, retValue.length);
				ch = retValue.substring(0, 1);
			}
			ch = retValue.substring(retValue.length-1, retValue.length);

			while (ch == " ") { // Check for spaces at the end of the string
				retValue = retValue.substring(0, retValue.length-1);
				ch = retValue.substring(retValue.length-1, retValue.length);
			}

			while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
				retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
			}

			return retValue; // Return the trimmed string back to the user
		}

	//-->
//-------------------------------------------------------------------------------------------------------------------
	<!--

	function testaCheckBox (obj) {

		if(obj.length != undefined){		
			var i, j
		    var ret = false;
			j=0;
		    
			for (var i = 0; i < obj.length; i++) {
				if (obj[i].checked) {
					return true;
	            }
		    }
		}
		else { 
			if (obj.checked) return true
		}
			
		return false;
    }

	//-->
//-------------------------------------------------------------------------------------------------------------------
	<!--

	function checkAll (obj1, obj) {
		if(!obj1.checked) {
			if(obj.length != undefined){		
				var i, j
			    var ret = false;
				j=0;
			    
				for (var i = 0; i < obj.length; i++) {
					obj[i].checked = false;
			    }
			}
			else { 
				obj.checked = false;
			}		
		}
		else {
			if(obj.length != undefined){		
				var i, j
			    var ret = false;
				j=0;
			    
				for (var i = 0; i < obj.length; i++) {
					obj[i].checked = true;
			    }
			}
			else {
				obj.checked = true;
			}		
		}
    }

	//-->
//-------------------------------------------------------------------------------------------------------------------
	<!--
		
	function SumRowAcumulated(objN, title, i, y, oClassName) {
	
		var tbl = document.getElementById(objN);
		var bln = true;
		if(tbl!=null) {

			var row = tbl.insertRow(i);
			if(oClassName != undefined){
				row.className = oClassName;
			}
			var cel1 = row.insertCell(0);

			cel1.className = "label"
			cel1.innerHTML = title;
			var body = tbl.childNodes(2);
			var rowEx = body.childNodes(y-1);
			var cel;
			var x, y;
			var value = 0;
			var op = 0;
			for(x=1; x< rowEx.childNodes.length;x++) {
				cell = row.insertCell(x);
				if(rowEx.childNodes(x).innerText==" " || rowEx.childNodes(x).innerText=="") {
					bln = false;
				}
				if(bln) {
					op = rowEx.childNodes(x).innerText
					op = ReplaceAll(op,".","");
					op = ReplaceAll(op,",",".");
					value+= parseFloat(op);
					cell.innerText = value;
				}else {
					cell.innerText = " ";
				}
				cell.innerText  = FormataNumero(cell.innerText,2, true, true, true);
				bln = true
			}
			row.childNodes(x-1).innerText = " ";
		}
	}

	//-->
//-------------------------------------------------------------------------------------------------------------------
	<!--

	function SumRow(objN, title, i, arr, oClassName) {
		
		var tbl = document.getElementById(objN);
		if(tbl!=null) {
			var row = tbl.insertRow(i);
			if(oClassName != undefined){
				row.className = oClassName;
			}
			var cel1 = row.insertCell(0);

			cel1.className = "label"
			cel1.innerHTML = title;
			var body = tbl.childNodes(2);
			var rowEx = body.childNodes(0);			
			var cel;
			var x, y;
			
			for(x=1; x< rowEx.childNodes.length;x++) {
				cel = row.insertCell(x);
				cel.innerText = 0;
			}
		
			for(x=0;x<arr.length;x++) {

				var tmp = body.childNodes(arr[x]-1);
				
				for(var y=1; y<tmp.childNodes.length;y++) {
					if(SomenteNumeros(tmp.childNodes(y).innerHTML)) {				
						row.childNodes(y).innerText = parseInt(row.childNodes(y).innerText) + parseInt(tmp.childNodes(y).innerHTML);
					}
				}
			}
		}
	}

	//-->
//-------------------------------------------------------------------------------------------------------------------
	<!--

	function SumCol(objN, title, i, arr, oClassName) {

		var tbl = document.getElementById(objN);

		if(tbl!=null) {
			var head = tbl.childNodes(1);
			var body = tbl.childNodes(2);
			var cel;
			var x, y;

			cell = head.childNodes(0).insertCell(i);
			if(oClassName != undefined){
				cell.className = oClassName;
			}
			
			
			cell.innerHTML = title;

			//Loop nas rows
			for(x=0;x<body.childNodes.length;x++) {
				row = body.childNodes(x);
				cell = row.insertCell(i);
				if(oClassName != undefined){
				   cell.className = oClassName;
			    }
				cell.innerText = 0;
				
				//Loop nas colunas
				for(y=0;y<arr.length;y++) {


					value = row.childNodes(arr[y]-1).innerHTML;
					value = ReplaceAll(value,".","");
					value = ReplaceAll(value,",",".");
					if(SomenteNumeros(value) && value!="") {

						value = parseFloat(value);
						value = parseFloat(row.childNodes(i).innerText) + value;
						row.childNodes(i).innerText = value;//parseInt(row.childNodes(i).innerText) + parseInt(row.childNodes(arr[y]).innerHTML);
					}
				}
				row.childNodes(i).innerText = FormataNumero(row.childNodes(i).innerText,2, true, true, true);
			}
			
			
			/*
			for(y=0;y<arr.length;y++) {

					value = row.childNodes(arr[y]).childNodes(0).value;
					value = value = ReplaceAll(value,".","");
					value = value = ReplaceAll(value,",",".");

					if(SomenteNumeros(value) && value!="") {						

						value = parseFloat(value);
						value = parseFloat(row.childNodes(i).childNodes(0).value) + value;
						row.childNodes(i).childNodes(0).value = value
					}
				}
				row.childNodes(i).childNodes(0).value = ReplaceAll(row.childNodes(i).childNodes(0).value,".",",");
			*/
			
			
			
			
		}
	}

	//-->
//-------------------------------------------------------------------------------------------------------------------
	<!--

	function SumRowOnline(objN, i, arr) {

		var tbl = document.getElementById(objN);
		if(tbl!=null) {

			var body = tbl.childNodes(2);
			var rowEx = body.childNodes(0);
			var row = body.childNodes(i-1);
			var cel;
			var x, y;

			
			for(x=1; x< row.childNodes.length;x++) {
				cel = row.childNodes(x)
				cel.childNodes(0).value = 0;
			}

			for(x=0;x<arr.length;x++) {

				var tmp = body.childNodes(arr[x]-1);

				for(var y=1; y<tmp.childNodes.length;y++) {

					if(tmp.childNodes(y).childNodes(0)!=null) {
					
						value = tmp.childNodes(y).childNodes(0).value;
						value = ReplaceAll(value,".","");
						value = ReplaceAll(value,",",".");

						if(SomenteNumeros(value) && value!="") {				

							if(tmp.childNodes(y).childNodes(0).type != "hidden") {
									value = parseFloat(value);
									row.childNodes(y).childNodes(0).value = parseFloat(row.childNodes(y).childNodes(0).value) + value;
							}
						}
					}
				}
			}
			for(x=1; x< row.childNodes.length;x++) {
				cel = row.childNodes(x)
				cel.childNodes(0).value = FormataNumero(cel.childNodes(0).value,2, true, true, true);
			}			
		}
	}

	//-->
//-------------------------------------------------------------------------------------------------------------------
	<!--

	function MinusRowOnline(objN, i, arr) {

		var tbl = document.getElementById(objN);
		if(tbl!=null) {

			var body = tbl.childNodes(2);
			var rowEx = body.childNodes(0);
			var row = body.childNodes(i-1);
			var cel;
			var x, y;

			for(x=1; x< row.childNodes.length;x++) {
				cel = row.childNodes(x)
				cel.childNodes(0).value = 0;
			}

			//loop no array
			for(x=0;x<arr.length;x++) {
				//pega a TR
				var tmp = body.childNodes(arr[x]-1);
				//loop nas TD
				for(var y=1; y<tmp.childNodes.length;y++) {

					if(tmp.childNodes(y).childNodes(0)!=null) {
					
						value = tmp.childNodes(y).childNodes(0).value;
						value = ReplaceAll(value,".","");
						value = ReplaceAll(value,",",".");

						if(SomenteNumeros(value) && value!="") {

							if(tmp.childNodes(y).childNodes(0).type != "hidden") {
									value = parseFloat(value);

									if(row.childNodes(y).childNodes(0).value!=0)
										row.childNodes(y).childNodes(0).value = parseFloat(row.childNodes(y).childNodes(0).value) - value;
									else
										row.childNodes(y).childNodes(0).value = value;

							}
						}
					}
				}
			}
			for(x=1; x< row.childNodes.length;x++) {
				cel = row.childNodes(x)
				cel.childNodes(0).value = FormataNumero(cel.childNodes(0).value,2, true, true, true);
			}
		}
	}

	//-->
//-------------------------------------------------------------------------------------------------------------------
	<!--

	function SumColOnline(objN, i, arr) {

		var tbl = document.getElementById(objN);

		if(tbl!=null) {
			var head = tbl.childNodes(1);
			var body = tbl.childNodes(2);

			var cel;
			var x, y;

			cell = head.childNodes(0).childNodes(i);
			for(x=0;x<body.childNodes.length;x++) {

				row = body.childNodes(x);
				cell = row.childNodes(i);

				cell.childNodes(0).value = 0
				
				
				for(y=0;y<arr.length;y++) {

					value = row.childNodes(arr[y]).childNodes(0).value;
					value = value = ReplaceAll(value,".","");
					value = value = ReplaceAll(value,",",".");

					if(SomenteNumeros(value) && value!="") {						

						value = parseFloat(value);
						value = parseFloat(row.childNodes(i).childNodes(0).value) + value;
						row.childNodes(i).childNodes(0).value = value
					}
				}
				row.childNodes(i).childNodes(0).value = FormataNumero(row.childNodes(i).childNodes(0).value,2,true,true,true);
			}
		}
	}

	//-->
//-------------------------------------------------------------------------------------------------------------------
	<!--

	function escreveCookie(nome, valor) {
	        var expira;
	        //Atribue null
	        expira = null;
	        expira = new Date(2500, 12, 31);
	        parent.document.cookie = nome + "=" + escape(valor) + "; expires=" + expira.toGMTString();
	}
	
	//-->
//-------------------------------------------------------------------------------------------------------------------
	<!--	

	function leCookie(Nome) {
	        var busca = Nome + "=";
	        if (parent.document.cookie.length > 0) { // se existir cookies
	            offset = parent.document.cookie.indexOf(busca)
	            if (offset != -1) { // se existe cookie
	                offset += busca.length
	                // index = começo do valor
	                end = parent.document.cookie.indexOf(";", offset)
	                // index = fim do valor
	                if (end == -1) {
	                    end = parent.document.cookie.length
	                }
	                return unescape(parent.document.cookie.substring(offset, end))
	            }
	        }
	}
	
	//-->
//-------------------------------------------------------------------------------------------------------------------
	<!--		
	
	function showHide(gName, func){
		var o = document.getElementById(gName);
		if(o.style.display == 'block'){
			o.style.display = 'none';
			escreveCookie(gName, "0")
		}else{
			o.style.display = 'block';
			escreveCookie(gName, "1")
		}
	}

	//-->
//-------------------------------------------------------------------------------------------------------------------
	<!--		

	function controlSubMenu(gName) {
		var o = pegaObjeto(gName);
		if(leCookie(gName)==0) {
			o.style.display = 'none';
		}else {
			o.style.display = 'block';
		}
	}	
	//-->
//-------------------------------------------------------------------------------------------------------------------
	<!--		

	function HoverTableRows(oTr,oClass){

		if(oTr.classRule == undefined){
			oTr.classRule = oTr.className
		}

		if(oClass != undefined){
			oTr.className = oTr.classRule + " " + oClass;
		}else{
			oTr.className = oTr.classRule;
		}
	
	}
	
	//-->
//-------------------------------------------------------------------------------------------------------------------
	<!--		

	function ShowHideMenu(selector){
		var menu = pegaObjeto('DIVMenuDefault')
		var selector = pegaObjeto('selector')
		if(menu.style.display == 'none'){
			OpenMenu(menu, selector) 	
		}else{
			CloseMenu(menu, selector) 
		}
	}

	//-->
//-------------------------------------------------------------------------------------------------------------------
	<!--			

	function OpenMenu(menu, selector) {
		menu.style.display = 'block';
		selector.style.left = 155;
		selector.style.backgroundColor = "transparent";
		escreveCookie("menuPrincipal", "1");
	}

	//-->
//-------------------------------------------------------------------------------------------------------------------
	<!--			

	function CloseMenu(menu, selector) {
		menu.style.display = 'none';
		selector.style.left = 1;
		selector.style.backgroundColor = "#f2f2f2"
		escreveCookie("menuPrincipal", "0");
	}

	//-->
//-------------------------------------------------------------------------------------------------------------------
	<!--		

	function controlMenu(gName) {

		var menu = document.getElementById('DIVMenuDefault')
		if(leCookie(gName)==0) {		
			CloseMenu(menu, selector) 	
		}else {
			OpenMenu(menu, selector) 
		}
	}

	//-->
//-------------------------------------------------------------------------------------------------------------------
	<!--			

	function DataValida(data) {
		var temp = String(data);
		if (temp.length != 10) return false;		
		if (temp.charAt(2)!="/" || temp.charAt(5)!="/") return false
		
		// Dia		
		var dia
		if (temp.substr(0, 2)=="08" || temp.substr(0, 2)=="09")
			dia = parseInt(temp.substr(1, 1));
		else
			dia = parseInt(temp.substr(0, 2));

		// Mes
		var mes
		if (temp.substr(3, 2)=="08" || temp.substr(3, 2)=="09")
			mes = parseInt(temp.substr(4, 1));
		else
			mes = parseInt(temp.substr(3, 2));
		
		// Ano
		var ano = parseInt(temp.substr(6, 4));

		if (ano < 1900) return false;
		if (mes < 1 || mes > 12) return false;
		if (dia < 1) return false;

		if (mes==1 || mes==3 || mes==5 || mes==7 || mes==8 || mes==10 || mes==12) {
			//meses com 31 dias
			return dia <= 31;
		}
		else {
			if (mes==4 || mes==6 || mes==9 || mes==11) {
				//meses com 30 dias
				return dia <= 30 && dia >=1;
			}
			else {
				//fevereiro				
				if (ano%4==0) {					
					//ano bissexto
					return dia <= 29 && dia >=1;
				}
				else {
					//ano normal
					return dia <= 28 && dia >=1;				
				}
			}
		}
	}
	
	//-->
//-------------------------------------------------------------------------------------------------------------------
	<!--				

	function formataData(campo,teclapress) {
		var tecla = teclapress.keyCode;
		vr = document.frm[campo].value;
		vr = vr.replace( ".", "" );
		vr = vr.replace( "/", "" );
		vr = vr.replace( "/", "" );
		tam = vr.length + 1;
	
		if ( tecla != 9 && tecla != 8 ){
			if ( tam > 2 && tam < 5 )
				document.frm[campo].value = vr.substr( 0, tam - 2  ) + '/' + vr.substr( tam - 2, tam );
				if ( tam >= 5 && tam <= 10 )
					document.frm[campo].value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 ); }
	}

	//-->
//-------------------------------------------------------------------------------------------------------------------
	<!--

	var dateCalendar;
	function openCalendar(pObj){	
		dateCalendar = pObj;
		newwin = window.open('../../include/bibliotecaJS/calendario.php ','CalendarioWin','toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,copyhistory=no,width=175,height=140,left=500,top=375');
	}

	//-->
//-------------------------------------------------------------------------------------------------------------------
	<!--

	function setDateCalendar(vcampo){	
		dateCalendar.value = vcampo;
	}

	//-->
//-------------------------------------------------------------------------------------------------------------------
	<!--

	function mudarParametrosGET() {
		var objFormulario = pegaObjeto("frm")
		var strAction = '';
		var i;
			
		for (i = 0; i < objFormulario.elements.length; i ++) {
			strAction+= objFormulario.elements[i].name + "=" + objFormulario.elements[i].value + "&"
		}
			
		return strAction;
	}

	//-->
//-------------------------------------------------------------------------------------------------------------------
	<!--

	function MascaraDecimal(obj,teclapres) {

		var tecla = teclapres.keyCode;

		var tammax = 13;
		vr = obj.value;
		vr = vr.replace( "/", "" );
		vr = vr.replace( "/", "" );
		vr = vr.replace( ",", "" );
		vr = vr.replace( ".", "" );
		vr = vr.replace( ".", "" );
		vr = vr.replace( ".", "" );
		vr = vr.replace( ".", "" );
	
		tam = vr.length;

		//if (tecla == 8 ){	tam = tam - 1 ;}
		
			if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
				if ( tam <= 2 ){ 
			 		obj.value = vr ; }
		 		if ( (tam > 2) && (tam <= 5) ){
	
		 			obj.value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ) ; }
			 	if ( (tam >= 6) && (tam <= 8) ){
	
			 		obj.value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
			 	if ( (tam >= 9) && (tam <= 11) ){
		 			obj.value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
			 	if ( (tam >= 12) && (tam <= 14) ){
			 		obj.value = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
			 	if ( (tam >= 15) && (tam <= 17) ){
		 			obj.value = vr.substr( 0, tam - 14 ) + '.' + vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ;}
			}
	}

	//-->
//-------------------------------------------------------------------------------------------------------------------
	<!--

	function MascaraInteiro(obj,teclapres) {

		var tecla = teclapres.keyCode;

		var tammax = 13;
		vr = obj.value;
		vr = vr.replace( "/", "" );
		vr = vr.replace( "/", "" );
		vr = vr.replace( ",", "" );
		vr = vr.replace( ".", "" );
		vr = vr.replace( ".", "" );
		vr = vr.replace( ".", "" );
		vr = vr.replace( ".", "" );
	
		tam = vr.length;

		//if (tecla == 8 ){	tam = tam - 1 ;alert("asd");}
		
			if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
				if ( tam <= 3 ){ 
			 		obj.value = vr ; }
				
		 		if ( (tam > 3) && (tam <= 6) ){
	
		 			obj.value = vr.substr( 0, tam - 3 ) + '.' + vr.substr( tam - 3, tam ) ; }

			 	if ( (tam >= 7) && (tam <= 9) ){
			 		obj.value = vr.substr( 0, tam - 6 ) + '.' + vr.substr( tam - 6, 3 ) + '.' + vr.substr( tam - 3, tam ) ; }
					
			 	if ( (tam >= 10) && (tam <= 12) ){
					obj.value = vr.substr( 0, tam - 9 ) + '.' + vr.substr( tam - 9, 3 ) + '.' + vr.substr( tam - 6, 3 ) + '.' + vr.substr( tam - 3, tam ) ; }

			 	if ( (tam >= 13) && (tam <= 15) ){
					obj.value = vr.substr( 0, tam-12 ) + '.' + vr.substr( tam-12, 3 ) + '.' + vr.substr( tam - 9, 3 ) + '.' + vr.substr( tam - 6, 3 ) + '.' + vr.substr( tam - 3, tam ) ; }				
			}
	}

	//-->
//-------------------------------------------------------------------------------------------------------------------
	<!--

	function SomenteDecimal(teclapres) {
		var tecla = teclapres.keyCode;

		if (!( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 || tecla==9  )){		
			teclapres.returnValue=false
		}			
	}

	//-->
//-------------------------------------------------------------------------------------------------------------------
	<!--

	function SomenteInteiro(teclapres) {
		var tecla = teclapres.keyCode;		
		if (!( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 || tecla==9 || tecla==13)){		
			teclapres.returnValue=false
		}	
	}

	//-->
//-------------------------------------------------------------------------------------------------------------------
	<!--

	function FormataCelulaEntrada(obj) {
		if(obj.parentNode.className=='onchanged'){ 
			obj.parentNode.className='onchanged onfocus' 
		}
		else{ 
			obj.parentNode.className='onfocus'
		}
		if(obj.value=="0") {
			obj.value = "";
		}
	}

	//-->
//-------------------------------------------------------------------------------------------------------------------
	<!--

	function FormataCelulaSaida(obj) {
		if(obj.parentNode.className.indexOf('onchanged') > -1){ 
			obj.parentNode.className='onchanged'
		}
		else{
			obj.parentNode.className=''
		}
		MontarTotalizador();
	}

	//-->
//-------------------------------------------------------------------------------------------------------------------
	<!--

	function BlockFieldEdit(obj, e) {
		if(e.keyCode!=9 && e.keyCode!=13) {
			window.event.returnValue=false
		}

		SimulateTab(obj, e)		
	}

	
	function SimulateTab(obj, e) {
	
		if(e.keyCode==13) {

			for(var i=0;i<document.frm.elements.length;i++) {
				if(document.frm.elements[i].name == obj.name) {
					index = i;
				}
			}

			while(document.frm.elements[index+1].type=="hidden" || document.frm.elements[index+1].disabled==true) {
				index++;
			}
			document.frm.elements[index+1].focus();
		}	
	}
	
	//-->
//-------------------------------------------------------------------------------------------------------------------
	<!--

	function AutoTab(t1, l1, t2)
	{
       if(t1.value.length==l1)
           pegaObjeto(t2).focus();
	}

	//-->
//-------------------------------------------------------------------------------------------------------------------
	<!--

	function ValidarMesAno(mes, ano) {
			
			if(mes.value=="") {
				mes.focus();
				alert("Por favor, digite o número do mês para a montagem do relatório.")
				return false;				
			}
			else if(!SomenteNumeros(mes.value)) {
				mes.focus();
				alert("O mês digitado não é um número válido.")
				return false;								
			} else if(parseInt(mes.value)>12) {
				mes.focus();				
				alert("O mês digitado não é um número válido.")
				return false;								
			}			
			if(ano.value=="") {
				ano.focus();
				alert("Por favor, digite o número do ano para a montagem do relatório.")
				return false;				
			} else if (!SomenteNumeros(ano.value)) {
				ano.focus();
				alert("O ano digitado não é um número válido.")
				return false;				
			}else if (ano.value.length<4) {
				ano.focus();
				alert("O ano digitado deve estar no formato AAAA")
				return false;				
			}
			return true;
	}

	//-->
//-------------------------------------------------------------------------------------------------------------------
	<!--

	function SomenteNumeros(string, possible) {
	    var possible = "0123456789.-";
	    possible = String(possible);
	    for (var i = 0; i < string.length; i++) {
			if(string.charAt(i)!=9 && string.charAt(i)!=8) {
		        if (possible.indexOf(string.charAt(i)) == -1 ) {
	    	        return false;
		        }
			}
	    }
	    return true;
	}

	//-->
//-------------------------------------------------------------------------------------------------------------------
	<!--

	function ReplaceAll(string, find, replace) {
	    return String(string).split(find).join(replace);
	}

	//-->
//-------------------------------------------------------------------------------------------------------------------
	<!--

	function FormataNumero(num,decimalNum,bolLeadingZero,bolParens,bolCommas)
	{ 

        if (!SomenteNumeros(parseFloat(num))) return "NaN";

		var tmpNum = num;
		var iSign = num < 0 ? -1 : 1;		// Get sign of number
	
		// Adjust number so only the specified number of numbers after
		// the decimal point are shown.
		tmpNum *= Math.pow(10,decimalNum);
		tmpNum = Math.round(Math.abs(tmpNum))
		tmpNum /= Math.pow(10,decimalNum);
		tmpNum *= iSign;					// Readjust for sign
	
		// Create a string object to do our formatting on
		var tmpNumStr = new String(tmpNum);

		// See if we need to strip out the leading zero or not.
		if (!bolLeadingZero && num < 1 && num > -1 && num != 0)
			if (num > 0)
				tmpNumStr = tmpNumStr.substring(1,tmpNumStr.length);
			else
				tmpNumStr = "-" + tmpNumStr.substring(2,tmpNumStr.length);
		
		// See if we need to put in the commas
		if (bolCommas && (num >= 1000 || num <= -1000)) {
			var iStart = tmpNumStr.indexOf(".");
			if (iStart < 0)
				iStart = tmpNumStr.length;

			iStart -= 3;
			while (iStart >= 1) {
				tmpNumStr = tmpNumStr.substring(0,iStart) + "," + tmpNumStr.substring(iStart,tmpNumStr.length)
				iStart -= 3;
			}		
		}

		// See if we need to use parenthesis
		if (bolParens && num < 0)
			tmpNumStr = "-" + tmpNumStr.substring(1,tmpNumStr.length);

		return ReplaceAll(ReplaceAll(ReplaceAll(tmpNumStr,",","@"),".",","),"@",".");
	}

	//-->
//-------------------------------------------------------------------------------------------------------------------
	<!--

//--------------------------------
// Inclui um traço "-" no Telefone
//--------------------------------
function FormataTelefone(Campo)
{
	tam = Campo.value.length;
	valor = Campo.value.substring(0,1);
	str = "";
		
	for(x=0;x<=tam;x++)
	{
		if (Campo.value.substring(x,x+1)!="-")
			str+=Campo.value.substring(x,x+1);
	} 
	
	aux=str.substring(0,3);
	aux1=str.substring(0,4);
	aux2=str.substring(0,2);
	
	if (valor == 0) {
		alert("O primeiro número não pode ser zero");
		Campo.focus();
		Campo.value="";
		return (false);		
	}
  	
	if (tam==7) {
	   if (str.length>3) {
	   	  aux = aux + "-";
		  }
	Campo.value=aux+str.substring(3,7);
	}
	
	if (tam==8) {
	   if (str.length>4) {
	   	  aux1 = aux1 + "-";
		  }
	Campo.value=aux1+str.substring(4,8);
	}
	
	if (tam==9) {
	    if (str.length>2) {
		  aux2 = "(" + aux2 + ")" + "";
		  }
    Campo.value=aux2+str.substring(2,9);
    }		 

	if (tam==10) {
	   if (str.length>2) {
	      aux2 = "(" + aux2 + ")" + "";
		  }
     Campo.value=aux2+str.substring(2,10);
	 }
}
	//-->
//-------------------------------------------------------------------------------------------------------------------


/********************************************************************
Funções de validação de formulário
*********************************************************************/

function valida_form(nome_form, method){
	var obj_form = document.forms[nome_form];
	var obj_check = null;
	var check = 0;
	var msg = "";
	var post = "";
	for(i=0; i< obj_form.length; i++){
		if(obj_form.elements[i].type == "checkbox"){
			if(obj_form.elements[i].checked == false && check != 2){
				obj_check = obj_form.elements[i];
				obj_form.elements[i].focus();
				check = 1;
			}else if(obj_form.elements[i].checked == true){
				post += obj_form.elements[i].name +';'+ obj_form.elements[i].value+';'; 
				check = 2; // Se estiver um ao menos marcado
			}
		}else{
			if(obj_form.elements[i].alt != "" && (obj_form.elements[i].value == obj_form.elements[i].alt || obj_form.elements[i].value == "")){
				if(obj_form.elements[i].type == "textarea"){
					msg+= obj_form.elements[i].alt+"\n";
				}else{
					msg+= "Preencha o campo " + obj_form.elements[i].alt+"\n";
				}
				obj_form.elements[i].focus();
			}else if(obj_form.elements[i].alt == "E-mail"){
				var vet_email = obj_form.elements[i].value;
				var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
				if(!filter.test(vet_email)){
					msg+= "E-mail invalido, "+vet_email+"\n";
					obj_form.elements[i].focus();
				}else{
					post += obj_form.elements[i].name +';'+ obj_form.elements[i].value+';'; 
				}		
			}else{
				post += obj_form.elements[i].name +';'+ obj_form.elements[i].value+';'; 
			}		
		}
	}
	if(check == 1){
		msg = "Preencha o campo " + obj_check.alt +"\n"+msg;
	}
	if(msg == "" && (method == "" || method == "submit")){
		obj_form.submit();
	}else if(msg == "" && method == "ajax"){
		x_insertObj(post, result);
	}else if(msg != ""){
		alert(msg);
	}
}

/////////////////////////////////////////////////////////////////////
// Mascara
/////////////////////////////////////////////////////////////////////
//-----> LEGENDA DAS FUNÇÕES:

//

// v_... = validação ...

// m_... = máscara ...

//-----> somente números:

function v_NR(tecla)

{

if(typeof(tecla) == 'undefined')

var tecla = window.event;

var codigo = (tecla.which ? tecla.which : tecla.keyCode ? tecla.keyCode : tecla.charCode);



// permite números, 8=backspace, 46=del e 9=tab

if ( (codigo >= 48 && codigo <= 57) || (codigo >= 96 && codigo <= 105) || codigo == 8 || codigo == 46 || codigo == 9 )

{ return true; }
else
{ alert("Apenas números são permitidos !"); return false; } 

}







//-----> máscara cnpj:

function m_CNPJ(campo,tammax) {



var vr = campo.value;

vr = vr.replace( "-", "" );

vr = vr.replace( "/", "" );

vr = vr.replace( ".", "" );

vr = vr.replace( ".", "" );

var tam = vr.length;



if (tam < tammax) { tam = vr.length + 1 ; }



tam = tam - 1;

if ( (tam > 2) && (tam <= 5) ) {

vr = vr.substr( 0, tam - 1 ) + '-' + vr.substr( tam - 1, tam ) ; }

if ( (tam >= 6) && (tam <= 8) ) {

vr = vr.substr( 0, tam - 5 ) + '/' + vr.substr( tam - 5, 4 ) + '-' + vr.substr( tam - 1, tam ) ; }

if ( (tam >= 9) && (tam <= 11) ) {

vr = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '/' + vr.substr( tam - 5, 4 ) + '-' + vr.substr( tam - 1, tam ) ; }

if ( (tam >= 12) && (tam < 14) ) {

vr = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '/' + vr.substr( tam - 5, 4 ) + '-' + vr.substr( tam - 1, tam ) ; }



campo.value = vr; 

}







//-----> máscara cpf: 

function m_CPF(campo,tammax) {



var vr = campo.value;

vr = vr.replace( "-", "" );

vr = vr.replace( ".", "" );

vr = vr.replace( ".", "" );

var tam = vr.length;



if (tam < tammax) { tam = vr.length + 1; }



tam = tam - 1;

if ( (tam > 2) && (tam <= 11) ) {

vr = vr.substr( 0, tam - 1 ) + '-' + vr.substr( tam - 1, tam ); }

if ( (tam == 10) ) {

vr = vr.substr( 0, tam - 7 ) + '.' + vr.substr( tam - 7, 3 ) + '.' + vr.substr( tam - 4, tam ); }



campo.value = vr;

}







//-----> máscara cep:

function m_CEP(campo,tammax) {



var vr = campo.value;

vr = vr.replace( "-", "" );

vr = vr.replace( ".", "" );

var tam = vr.length;



if (tam < tammax) { tam = vr.length + 1; }



tam = tam - 1;

if ( (tam > 2) && (tam <= 8) ) {

vr = vr.substr( 0, tam - 2 ) + '-' + vr.substr( tam - 2, tam ); }

if ( (tam == 7) ) {

vr = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, tam ); }



campo.value = vr;

}







//-----> máscara data:

function m_DATA(campo,tammax,tecla) {



if(typeof(tecla) == 'undefined')

var tecla = window.event;

var codigo = (tecla.which ? tecla.which : tecla.keyCode ? tecla.keyCode : tecla.charCode);



var vr = campo.value;

vr = vr.replace( "/", "" );

vr = vr.replace( "/", "" );

var tam = vr.length;



if (tam < tammax) { tam = vr.length + 1; }

if (codigo == 8) { tam = tam - 1; }



tam = tam - 1;

if ( (tam >= 2) && (tam < 3) ) {

vr = vr.substr( 0, tam - 0 ) + '/' + vr.substr( tam - 0, 2 ); }

if ( (tam >= 3) && (tam < 4) ) {

vr = vr.substr( 0, tam - 1 ) + '/' + vr.substr( tam - 1, 2 ); }

if (tam == 4) {

vr = vr.substr( 0, tam - 2 ) + '/' + vr.substr( tam - 2, 2 ) + '/' + vr.substr( tam - 0, 5 ); }

if (tam == 5) {

vr = vr.substr( 0, tam - 3 ) + '/' + vr.substr( tam - 3, 2 ) + '/' + vr.substr( tam - 1, 6 ); }

if (tam == 6) {

vr = vr.substr( 0, tam - 4 ) + '/' + vr.substr( tam - 4, 2 ) + '/' + vr.substr( tam - 2, 7 ); }

if (tam == 7) {

vr = vr.substr( 0, tam - 5 ) + '/' + vr.substr( tam - 5, 2 ) + '/' + vr.substr( tam - 3, 8 ); }



campo.value = vr;

}







//-----> máscara hora:

function m_HORA(campo,tammax,tecla) {



if(typeof(tecla) == 'undefined')

var tecla = window.event;

var codigo = (tecla.which ? tecla.which : tecla.keyCode ? tecla.keyCode : tecla.charCode);



var vr = campo.value;

vr = vr.replace( ":", "" );

vr = vr.replace( ":", "" );

var tam = vr.length;



if (tam < tammax) { tam = vr.length + 1; }

if (codigo == 8) { tam = tam - 1; }



tam = tam - 1;

if ( (tam >= 2) && (tam < 3) ) {

vr = vr.substr( 0, tam - 0 ) + ':' + vr.substr( tam - 0, 2 ); }

if ( (tam >= 3) && (tam < 4) ) {

vr = vr.substr( 0, tam - 1 ) + ':' + vr.substr( tam - 1, 2 ); }

if (tam == 4) {

vr = vr.substr( 0, tam - 2 ) + ':' + vr.substr( tam - 2, 2 ) + ':' + vr.substr( tam - 0, 5 ); }

if (tam == 5) {

vr = vr.substr( 0, tam - 3 ) + ':' + vr.substr( tam - 3, 2 ) + ':' + vr.substr( tam - 1, 6 ); }



campo.value = vr;

}

/////////////////////////////////////////////////////////////////////////////////////////
//--------------------------------
// Inclui um traço "-" no cpf  
//--------------------------------
function FormataCPF(Campo)
{
	tam = Campo.value.length;
	str = "";
	//valor = Campo.value.substring(8,11);
	
	if (tam!=11) {
		alert ("Favor informar o CNPJ correto");
		Campo.focus();
		Campo.value="";
		return (false);
	}
	for(x=0;x<=tam;x++)
	{
		//if (Campo.value.substring(x,x+1)!="-")
			str+=Campo.value.substring(x,x+1);
	} 
	aux=str.substring(0,3);
	aux2=str.substring(3,6);
	aux3=str.substring(6,9);
	aux4=str.substring(9,11);
		
    Campo.value=aux+"."+aux2+"."+aux3+"-"+aux4
} 
//////////////////////////////////////////////////////////////////////////////////////////
//--------------------------------
// Inclui um traço "-" no cnpj   
//--------------------------------
function FormataCNPJ(Campo)
{
	tam = Campo.value.length;
	str = "";
		
	for(x=0;x<=tam;x++)
	{
		if (Campo.value.substring(x,x+1)!="/")
			str+=Campo.value.substring(x,x+1);
	} 
	
	aux=str.substring(0,2);
	aux2=str.substring(2,5);
	aux3=str.substring(5,8);
	aux4=str.substring(8,12);
	aux5=str.substring(12,14);
	
    Campo.value=aux+"."+aux2+"."+aux3+"/"+aux4+"-"+aux5
} 