function resetaForm(variavel){

	if(variavel == "veiculacao"){
		document.mercadorias.Produto1.options.selectedIndex=0;
		document.mercadorias.Praca1.options.selectedIndex=0;
		document.mercadorias.Qtd1.value="";
		document.mercadorias.Preco1.value="";
		document.mercadorias.Data_Inicio1.value="";
		document.mercadorias.Montagem1.options.selectedIndex=0;
		document.mercadorias.Obs1.value="";
	}else{
		document.mercadorias.Produto.options.selectedIndex=0;
		document.mercadorias.Qtd.value="";
		document.mercadorias.Preco.value="";
		document.mercadorias.Obs.value="";
	}
}


function marca(formNome) {
	for (x = 0; x < document.pesquisa.elements.length; x++) {
		document.pesquisa.elements[x].checked = true;
	}
}

function limpaCamposForm(){}

function desmarca(formNome) {
	for (x = 0; x < document.pesquisa.elements.length; x++) {
		document.pesquisa.elements[x].checked = false;
	}
}
function marca1() {
	for (x = 0; x < document.validar_pesquisa.elements.length; x++) {
		document.validar_pesquisa.elements[x].checked = true;
	}
}

function desmarca1() {
	for (x = 0; x < document.validar_pesquisa.elements.length; x++) {
		document.validar_pesquisa.elements[x].checked = false;
	}
}

var objetos = new Array();
var totalObjetos = 0;
function callBackPadrao1(response, layerName) {
	document.getElementById(layerName).innerHTML = response;
	var cal = new Zapatec.Calendar.setup({
	showsTime      : false,//mostrar hora ou não
	range          : [1900.01, 2999.12],//data inicial e final
	singleClick    : true,//selecionar data com um único click
	inputField     : "Data",//nome do campo que irá receber a data
	button         : "botao",//botão que irá chamar a função da data
	ifFormat       : "%d/%m/%Y"//formata que irá ser mostrado
	});
}

function ajaxPadraoFormUnique(valor, metodo, url) {
	objAjax = new AjaxObject(metodo, url);
	objAjax.addRequestValue('key',valor);
	objAjax.setCallBackFunction(callBackAlert, new Array());
	objAjax.setExceptionFunction(exceptionPadrao);
	objAjax.load();
}

function ajaxPadraoUnique(valor, metodo, url,layer) {
	objAjax = new AjaxObject(metodo, url);
	objAjax.addRequestValue('key',valor);
	objAjax.setCallBackFunction(callbackPadrao, new Array(layer));
	objAjax.setExceptionFunction(exceptionPadrao);
	objAjax.load();
}

function callBackAlert(response) {
	alert(response);
}

function loading(){
		layerName = this.callBackArguments[0];
		document.getElementById(layerName).innerHTML = "<font face=verdana size=3><div align=center><b><br><br>Carregando...</b></div></font>";	
}

function exceptionPadrao(cod, status) {
	alert(cod + ": " + status);
}

function ajaxPadraoForm(formulario, metodo, url) {
	objAjax = new AjaxObject(metodo, url);
	objAjax.addAllRequestObjects(document.forms[formulario]);
	objAjax.setCallBackFunction(callBackAlert, new Array());
	objAjax.load();
}

function ajaxPadrao(formulario, metodo, url, layer) {
	var objAjax = new AjaxObject(metodo, url);
	for (x = 0; x < document.forms[formulario].elements.length; x++) {
		objAjax.addRequestObject(document.forms[formulario].elements[x]);
	}
	objAjax.setCallBackFunction(callbackPadrao, new Array(layer));
	objAjax.load();	
}
		
function vesovi(cod, texto) {
	alert(cod + " - " + texto);
}

function callbackPadrao(response, layerName) {
	document.getElementById(layerName).innerHTML = response;
}

function Veiculo(valor1) {
	this.codigoVeiculo = valor1;
	this.req = null;
}

		function ajaxPadraoUnique1(valor, metodo, url,layer) {
			objAjax = new AjaxObject(metodo, url);
			objAjax.setLoadingFunction(loading);
			objAjax.addRequestValue('key',valor);
			objAjax.setCallBackFunction(callBackPadrao1, new Array(layer));
			objAjax.setExceptionFunction(exceptionPadrao);
			objAjax.load();
		}
function detalheVeiculo(veiculo,valores,motivo) {
	if (!veiculo) {
		alert("Preencha o campo corretamente!");
	} else {
		agora = new Date();
		auth = agora.getTime();
		url = 'relatorio/detalheVeiculo.php?veiculo=' + veiculo + '&motivo=' + motivo + '&auth=' + auth;

		requisicao = new Veiculo(valores); 
		// Procura por um objeto nativo (Mozilla) 
		if (window.XMLHttpRequest) {
			requisicao.req = new XMLHttpRequest();
			requisicao.req.valor = veiculo;
			requisicao.req.onreadystatechange = retornoVeiculo; 
			requisicao.req.open("GET", url, true); 
			requisicao.req.send(null); 
		// Procura por uma versão ActiveX (IE) 
		} else if (window.ActiveXObject) { 
			requisicao.req = new ActiveXObject("Microsoft.XMLHTTP"); 
			if (requisicao.req) { 
				requisicao.req.onreadystatechange = retornoVeiculo; 
				requisicao.req.open("GET", url, true); 
				requisicao.req.send(); 
			} 
		} 
	}
}
function ajaxPadrao2(formulario, metodo, url, layer) {
	var objAjax = new AjaxObject(metodo, url);
	objAjax.setLoadingFunction(loading);
	objAjax.setCallBackFunction(callbackPadrao, new Array(layer));
	objAjax.load();
}
function retornoVeiculo() {
    // apenas quando o estado for "completado" 
    if (requisicao.req.readyState == 4) { 
        // apenas se o servidor retornar "OK" 
        if (requisicao.req.status == 200) { 

            document.getElementById('Veiculo' + requisicao.codigoVeiculo).innerHTML = requisicao.req.responseText; 

        } else { 
            alert("Serviço indisponível no momento!\nTente novamente mais tarde."); 
        } 
    } 
}


function MM_reloadPage(init) {  //reloads the window if Nav4 resized

if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {

document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}

else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();

}

MM_reloadPage(true);

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_showHideLayers() { //v6.0

var i,p,v,obj,args=MM_showHideLayers.arguments;

for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];

if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }

obj.visibility=v; }

}



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_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_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 MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

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_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function carregarCalendario(mes, ano) { 
    req = null; 
    req2 = null; 
url = 'carregarCalendario.php?mes=' + mes + '&ano=' + ano;
    document.getElementById('calendario').innerHTML = calendarioCarregando();
url2 = 'carregarCalendario2.php?mes=' + mes + '&ano=' + ano;
    document.getElementById('calendario2').innerHTML = calendarioCarregando();
 
    // Procura por um objeto nativo (Mozilla) 
    if (window.XMLHttpRequest) { 
        req = new XMLHttpRequest(); 
        req.onreadystatechange = processReqChange; 
        req.open("GET", url, true); 
        req.send(null); 
        req2 = new XMLHttpRequest(); 
        req2.onreadystatechange = processReqChange; 
        req2.open("GET", url2, true); 
        req2.send(null); 
    // Procura por uma versão ActiveX (IE) 
    } else if (window.ActiveXObject) { 
        req = new ActiveXObject("Microsoft.XMLHTTP"); 
        if (req) { 
            req.onreadystatechange = processReqChange; 
            req.open("GET", url, true); 
            req.send(); 
        } 
        req2 = new ActiveXObject("Microsoft.XMLHTTP"); 
        if (req2) { 
            req2.onreadystatechange = processReqChange; 
            req2.open("GET", url2, true); 
            req2.send(); 
        } 
    } 
} 

function processReqChange() { 
    // apenas quando o estado for "completado" 
    if (req.readyState == 4) { 
        // apenas se o servidor retornar "OK" 
        if (req.status == 200) { 
            // procura pela div id="calendario" e insere o conteudo 
            // retornado nela, como texto HTML 
            document.getElementById('calendario').innerHTML = req.responseText; 
            document.getElementById('calendario2').innerHTML = req2.responseText; 
        } else { 
            alert("Problemas para carregar o calendário!\nTente novamente mais tarde."); 
        } 
    } 
} 

function carregarCalendarioMesAno() {
	document.getElementById('calendario_mes_ano').innerHTML = ' ' + meses[mes] + ' ' + ano + ' '; 
}

function iniciarCalendario(iDia, iMes, iAno) {
	meses = new Array('', 'Janeiro',  'Fevereiro', 'Março', 'Abril', 'Maio', 'Junho',
					  'Julho', 'Agosto', 'Setembro', 'Outubro', 'Novembro', 'Dezembro');
	dia = iDia;
	mes = iMes;
	ano = iAno;
	carregarCalendarioMesAno(mes, ano);
	carregarCalendario(mes, ano);
}
function trocarCalendario(valor) {
	// se o novo mes até 12 (jan = 1, dez = 12)
	if ((mes + valor) <= 12) {
		if (mes + valor > 0) {
			mes += valor;
		// se o novo mês for menor que zero
		} else {
			mes = 12;
			ano -= 1;
		}
	// se o novo mês passar de 12 (1 a 12)
	} else {
		mes = 1;
		ano += 1;
	}
	carregarCalendario(mes, ano);
	carregarCalendarioMesAno(mes, ano);
}
var meses, data, mes, ano;

function calendarioCarregando() {
	return '<table border="0"><tr><td width="168" align="center" valign="middle" height="115">\n'+
'	 <table width="150"  border="0" cellspacing="0" cellpadding="0">\n' +
'	  <tr>\n' +
'		<td colspan="3" align="right" background="imagens/topo_div_bg.gif"><table width="100%" cellpadding="0" cellspacing="0">\n' +
'			<tr><td><img src="imagens/topo_div_canto.gif"></td><td><img src="imagens/topo_div_resto.gif"></td></tr></table></td>\n' +
'	  </tr>\n' +
'	  <tr>\n' +
'		<td bgcolor=cccccc width="1"></td>\n' +
'		<td background="imagens/bg_div.jpg" height="18" align="right" nowrap class="texto_destaque">\n' +
'			<b> Carregando ... &nbsp; </b></td>\n' +
'		<td bgcolor="#cccccc" width="1"></td>\n' +
'	  </tr>\n' +
'	 </table></td></tr></table>\n';
}

function carregarCampo() {
	objTabela = document.forms[0].Tabela;
	er = /^[a-z0-9._-]+@[a-z0-9_-]+\.[a-z0-9._-]+$/i;
	if (objTabela.value == "") {
		alert("Preencha o campo Tabela corretamente para receber a senha!");
	} else {
		agora = new Date();
		auth = agora.getTime();
		url = 'carregarCampo.php?tabela=' + objTabela.value + '&auth=' + auth;
		
		// Procura por um objeto nativo (Mozilla) 
		if (window.XMLHttpRequest) { 
			req = new XMLHttpRequest(); 
			req.onreadystatechange = retornoCarregarCampo; 
			req.open("GET", url, true); 
			req.send(null); 
		// Procura por uma versão ActiveX (IE) 
		} else if (window.ActiveXObject) { 
			req = new ActiveXObject("Microsoft.XMLHTTP"); 
			if (req) { 
				req.onreadystatechange = retornoCarregarCampo; 
				req.open("GET", url, true); 
				req.send(); 
			} 
		} 
	}
}

function carregarCarro() {
	objTabela = document.forms[0].Cliente;
	er = /^[a-z0-9._-]+@[a-z0-9_-]+\.[a-z0-9._-]+$/i;
	if (objTabela.value == "") {
		alert("Preencha o campo Cliente corretamente para receber a senha!");
	} else {
		agora = new Date();
		auth = agora.getTime();
		url = 'ordem_servico/carregarCarro.php?result=' + objTabela.value + '&auth=' + auth;
		
		// Procura por um objeto nativo (Mozilla) 
		if (window.XMLHttpRequest) { 
			req = new XMLHttpRequest(); 
			req.onreadystatechange = retornoCarregarCarro; 
			req.open("GET", url, true); 
			req.send(null); 
		// Procura por uma versão ActiveX (IE) 
		} else if (window.ActiveXObject) { 
			req = new ActiveXObject("Microsoft.XMLHTTP"); 
			if (req) { 
				req.onreadystatechange = retornoCarregarCarro; 
				req.open("GET", url, true); 
				req.send(); 
			} 
		} 
	}
}

function retornoCarregarCampo() {
    // apenas quando o estado for "completado" 
    if (req.readyState == 4) { 
        // apenas se o servidor retornar "OK" 
        if (req.status == 200) { 

            document.getElementById('combo').innerHTML = req.responseText; 

        } else { 
            alert("Serviço indisponível no momento!\nTente novamente mais tarde."); 
        } 
    } 
}
function retornoCarregarCarro() {
    // apenas quando o estado for "completado" 
    if (req.readyState == 4) { 
        // apenas se o servidor retornar "OK" 
        if (req.status == 200) { 

            document.getElementById('Carro').innerHTML = req.responseText; 

        } else { 
            alert("Serviço indisponível no momento!\nTente novamente mais tarde."); 
        } 
    } 
}
function carregarProduto() {
	objTabela = document.forms[0].Produto;
	er = /^[a-z0-9._-]+@[a-z0-9_-]+\.[a-z0-9._-]+$/i;
	if (objTabela.value == "") {
		alert("Preencha o campo Produto corretamente para receber a senha!");
	} else {
		agora = new Date();
		auth = agora.getTime();
		url = 'item_produto/carregarProduto.php?result=' + objTabela.value + '&auth=' + auth;
		
		// Procura por um objeto nativo (Mozilla) 
		if (window.XMLHttpRequest) { 
			req = new XMLHttpRequest(); 
			req.onreadystatechange = retornoCarregarProduto; 
			req.open("GET", url, true); 
			req.send(null); 
		// Procura por uma versão ActiveX (IE) 
		} else if (window.ActiveXObject) { 
			req = new ActiveXObject("Microsoft.XMLHTTP"); 
			if (req) { 
				req.onreadystatechange = retornoCarregarProduto; 
				req.open("GET", url, true); 
				req.send(); 
			} 
		} 
	}
}

function retornoCarregarProduto() {
    // apenas quando o estado for "completado" 
    if (req.readyState == 4) { 
        // apenas se o servidor retornar "OK" 
        if (req.status == 200) { 

            document.getElementById('produtos').innerHTML = req.responseText; 

        } else { 
            alert("Serviço indisponível no momento!\nTente novamente mais tarde."); 
        } 
    } 
}function carregarServico() {
	objTabela = document.forms[0].Servico;
	er = /^[a-z0-9._-]+@[a-z0-9_-]+\.[a-z0-9._-]+$/i;
	if (objTabela.value == "") {
		alert("Preencha o campo Serviço corretamente para receber a senha!");
	} else {
		agora = new Date();
		auth = agora.getTime();
		url = 'item_servico/carregarServico.php?result=' + objTabela.value + '&auth=' + auth;
		
		// Procura por um objeto nativo (Mozilla) 
		if (window.XMLHttpRequest) { 
			req = new XMLHttpRequest(); 
			req.onreadystatechange = retornoCarregarServico; 
			req.open("GET", url, true); 
			req.send(null); 
		// Procura por uma versão ActiveX (IE) 
		} else if (window.ActiveXObject) { 
			req = new ActiveXObject("Microsoft.XMLHTTP"); 
			if (req) { 
				req.onreadystatechange = retornoCarregarServico; 
				req.open("GET", url, true); 
				req.send(); 
			} 
		} 
	}
}

function retornoCarregarServico() {
    // apenas quando o estado for "completado" 
    if (req.readyState == 4) { 
        // apenas se o servidor retornar "OK" 
        if (req.status == 200) { 

            document.getElementById('servicos').innerHTML = req.responseText; 

        } else { 
            alert("Serviço indisponível no momento!\nTente novamente mais tarde."); 
        } 
    } 
}
function showDiv(valor){

		oDiv0 = document.getElementById("tipo0");
		oDiv1 = document.getElementById("tipo1");
	
		if (valor=='0')
		{
			oDiv0.style.display = "block";
			oDiv1.style.display = "none";
		}
		if (valor=='1')
		{
			oDiv1.style.display = "block";
			oDiv0.style.display = "none";
		}

}

var ajaxObj;
function move(s1, s2) {
      i = s1.selectedIndex;
      if ( i != -1 ) {
        if ( s1.options[i].selected ) {
            for ( j = 0; j < s2.options.length; j++ ) {
              if ( s2.options[j].value == s1.options[i].value ) break;
              if ( s2.options[j].text > s1.options[i].text ) {
                for ( z = s2.options.length; z > j ; z-- ) {
                  s2.options[z] = new Option(s2.options[z-1].text, s2.options[z-1].value, false, false);
                }
                break;
              }
            }
            s2.options[j] = new Option(s1.options[i].text, s1.options[i].value, false, true);
            s1.options[i] = null;
        }
      }
	  // lógica de chamada ao Ajax
	  if (arguments[2] != null) {
		  if (arguments[3] == "vai") {
			sourceObject = arguments[1];  
		  } else if (arguments[3] == "volta") {
			sourceObject = arguments[0];  
		  }
		  params = new Array();
		  values = new Array();
		  for (x = 0; x < sourceObject.options.length; x++) {
			  params[x] = "param" + x;
			  values[x] = sourceObject.options[x].value;
		  }
		  ajaxObj = new EspeciAjax(params, values, "http://localhost/rota/relatorio/ajax_veiculo_disponivel.php",
						 montarComboAjax, arguments[2]);
	  }
    }

function EspeciAjax(params, values, url, returnFunction, targetObject) {
	this.url = url + "?timestamp=" + new Date().getTime();
	for (x = 0; x < params.length; x++) {
		this.url += "&" + params[x] + "=" + values[x];
	}
	this.targetObject = targetObject;
	this.execReturnFunction = returnFunction;

	if(window.XMLHttpRequest) {
    	try {
			this.req = new XMLHttpRequest();
        } catch(e) {
			this.req = false;
        }
    } else if(window.ActiveXObject) {
       	try {
        	this.req = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		this.req = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		this.req = false;
        	}
		}
    }
	if(this.req) {
		this.req.onreadystatechange = returnFunction;
		this.req.open("GET", this.url, true);
		this.req.send();
	}
}

function montarComboAjax() {
	alert(ajaxObj);
}

function setSelectOptions(the_form, the_select, do_check) {
    var selectObject = document.forms[the_form].elements[the_select];
    var selectCount  = selectObject.length;
	
    for (var i = 0; i < selectCount; i++) {
        selectObject.options[i].selected = do_check;
    } // end for
    document.forms[the_form].submit();
    return true;
}

function setSelectOptions2(the_form, the_select, do_check) {
    var selectObject = document.forms[the_form].elements[the_select];
    var selectCount  = selectObject.length;

    for (var i = 0; i < selectCount; i++) {
        selectObject.options[i].selected = do_check;
    } // end for
    //document.forms[the_form].submit();
    return true;
}

function passamouse(src,cor,sentido){

  if (sentido == "entra") {

   // if(!src.contains(event.fromElement)){

      src.style.cursor='hand';src.bgColor=cor;

    //}

  }

  if (sentido == "sai") {

    //if(!src.contains(event.toElement)){

      src.style.cursor='default';src.bgColor=cor;

    //}

  }

}



function cliquemouse(src){

  if(event.srcElement.tagName=='TD'){

    src.children.tags('A')[0].click();

  }

}

function submeter(acao,arquivo_url) {

	

	switch (acao) {

	case 0: //Atualizar



           	document.edicao.action = arquivo_url;

		break;



	case 1: //Excluir

		if (!confirm('Deseja excluir o(s) item(ns) selecionado(s) ?')) return(false);

		document.edicao.action = arquivo_url;

		break;



	case 2: //Imprimir

		document.edicao.action = arquivo_url;

		break;

	}



	document.edicao.submit();

	return(true);

}



function currencyFormat(fld, milSep, decSep, e) {

var sep = 0;

var key = '';

var i = j = 0;

var len = len2 = 0;

var strCheck = '0123456789';

var aux = aux2 = '';

var whichCode = (window.Event) ? e.which : e.keyCode;

if (whichCode == 13) return true;  // Enter
if (whichCode == 8) return true;  // Backspace
if (whichCode == 0) return true;  // whichCode==0 faz com que seja possivel usar todas as teclas como delete, setas, etc

//alert(whichCode);

key = String.fromCharCode(whichCode);  // Get key value from key code

if (strCheck.indexOf(key) == -1) return false;  // Not a valid key

len = fld.value.length;

for(i = 0; i < len; i++)

if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;

aux = '';

for(; i < len; i++)

if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);

aux += key;

len = aux.length;

if (len == 0) fld.value = '';

if (len == 1) fld.value = '0'+ decSep + '0' + aux;

if (len == 2) fld.value = '0'+ decSep + aux;

if (len > 2) {

aux2 = '';

for (j = 0, i = len - 3; i >= 0; i--) {

if (j == 3) {

aux2 += milSep;

j = 0;

}

aux2 += aux.charAt(i);

j++;

}

fld.value = '';

len2 = aux2.length;

for (i = len2 - 1; i >= 0; i--)

fld.value += aux2.charAt(i);

fld.value += decSep + aux.substr(len - 2, len);

}

return false;

}

/* Máscaras para campo telefone */
function telefone(campo) 
 { 
      caracteres = (campo.value).length; 

      if(caracteres == '') 
        campo.value = campo.value + "("; 

     if(caracteres == 3) 
        campo.value = campo.value + ")"; 

     if(caracteres == 8) 
        campo.value = campo.value + "-"; 
 } 
function TelefoneFormat(Campo, e) { 
    var key = ''; 
    var len = 0; 
    var strCheck = '0123456789'; 
    var aux = ''; 
    var whichCode = (window.Event) ? e.which : e.keyCode; 
     
    if (whichCode == 13 || whichCode == 8 || whichCode == 0) 
    { 
        return true;  // Enter backspace ou FN qualquer um que não seja alfa numerico 
    } 
    key = String.fromCharCode(whichCode); 
    if (strCheck.indexOf(key) == -1){ 
        return false;  //NÃO E VALIDO 
    } 
     
    aux =  Telefone_Remove_Format(Campo.value); 
     
    len = aux.length; 
    if(len>=10) 
    { 
        return false;    //impede de digitar um telefone maior que 10 
    } 
    aux += key; 
     
    Campo.value = Telefone_Mont_Format(aux); 
    return false; 
} 

function  Telefone_Mont_Format(Telefone) 
{ 
    var aux = len = ''; 
     
    len = Telefone.length; 
    if(len<=9) 
    { 
        tmp = 5; 
    } 
    else 
    { 
        tmp = 6; 
    } 
     
    aux = ''; 
    for(i = 0; i < len; i++) 
    { 
        if(i==0) 
        { 
            aux = '('; 
        } 
        aux += Telefone.charAt(i); 
        if(i+1==2) 
        { 
            aux += ')'; 
        } 
         
        if(i+1==tmp) 
        { 
            aux += '-'; 
        } 
    } 
    return aux ; 
} 

function  Telefone_Remove_Format(Telefone) 
{ 
    var strCheck = '0123456789'; 
    var len = i = aux = ''; 
    len = Telefone.length; 
    for(i = 0; i < len; i++) 
    { 
        if (strCheck.indexOf(Telefone.charAt(i))!=-1) 
        { 
            aux += Telefone.charAt(i); 
        } 
    } 
    return aux; 
}

function mascara(mascara,objeto) {
	if (objeto.value.length >= mascara.length){
		objeto.value = objeto.value.substring(0,objeto.value.length-1);
		return true;
	}
	var itemMascara	= '';
	var itemValue	= '';
	itemMascara = mascara.charAt(objeto.value.length);
	if (itemMascara !== '0') {
		objeto.value += itemMascara;
	}
}

function FormataCpf(campo,tammax,teclapres) {
 var tecla = teclapres.keyCode;
  
 vr = event.srcElement.value;
 vr = vr.replace( "/", "" );
 vr = vr.replace( "/", "" );
 vr = vr.replace( ",", "" );
 vr = vr.replace( ".", "" );
 vr = vr.replace( ".", "" );
 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 (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

 if (tecla == 8 ){ tam = tam - 1 ; }
  
 if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
  if ( tam <= 2 ){ 
    event.srcElement.value = vr ; }
   if ( (tam > 2) && (tam <= 5) ){
    event.srcElement.value = vr.substr( 0, tam - 2 ) + '-' + vr.substr( tam - 2, tam ) ; }
   if ( (tam >= 6) && (tam <= 8) ){
    event.srcElement.value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + '-' + vr.substr( tam - 2, tam ) ; }
   if ( (tam >= 9) && (tam <= 11) ){
    event.srcElement.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) ){
    event.srcElement.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) ){
    event.srcElement.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 FormataCNPJ(Campo, teclapres){

	var tecla = teclapres.keyCode;

	var vr = new String(Campo.value);
	vr = vr.replace(".", "");
	vr = vr.replace(".", "");
	vr = vr.replace("/", "");
	vr = vr.replace("-", "");

	tam = vr.length + 1 ;

	
	if (tecla != 9 && tecla != 8){
		if (tam > 2 && tam < 6)
			Campo.value = vr.substr(0, 2) + '.' + vr.substr(2, tam);
		if (tam >= 6 && tam < 9)
			Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,tam-5);
		if (tam >= 9 && tam < 13)
			Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,tam-8);
		if (tam >= 13 && tam < 15)
			Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,4)+ '-' + vr.substr(12,tam-12);
		}
}

function abre(foto){

    parent.window.open('../recibo.php?V1='+foto,foto+'fotos','scrolling:no,scrollbars=0');



}


function MM_openBrWindow(theURL,winName,features) { //v2.0

  window.open(theURL,winName,features);

}

function sonumeros(s,campo,formulario) { 
	for (vlcont = 0 ; vlcont <= 12 ; vlcont++) {
		if (s.charAt(vlcont) == "") {
			var vlPosAtual = vlcont-1;
			break;
		}
	}

	var vlChar = s.charAt(vlPosAtual);
	var vaAux1 = ((vlChar >= "0") && (vlChar <= "9"));

	if(!vaAux1) {
		var vlNewChar = "";
		for (vlcont = 0 ; vlcont <= vlPosAtual ; vlcont++) {
			if (vlcont != vlPosAtual) {
				vlNewChar = vlNewChar + s.charAt(vlcont);
			}
		}

		eval("document." + formulario + "." + campo + ".value = vlNewChar");
		return false;
	}
	return true;
}

	// determinando as imagens
	arrayImagens = new Array();
	arrayImagens[0] = new Image();
	arrayImagens[0].src = "imagens/m.gif";
	arrayImagens[1] = new Image();
	arrayImagens[1].src = "imagens/p.gif";
	function exibirRespostas(imagem,layer) {
		// caso não ache o layer passado, retorna sem dar erro de script
		if (!(objeto = document.getElementById(layer))) return;
		// checando se o layer está visivel
		if (objeto.style.visibility == "hidden") {
			objeto.style.visibility = "inherit";
			objeto.style.position = "relative";
			objeto.outerHTML = objeto.outerHTML;
			imagem.src = arrayImagens[0].src;
			imagem.alt = "Ocultar as respostas a este comentário";
		} else {
			for (x=0;x<objeto.children.tags("DIV").length;x++) {
				if (objeto.children.tags("DIV")[x].style.visibility=="visible") {
					alert(objeto.children.tags("DIV")[x].id);
				}
			}
			objeto.style.visibility = "hidden";
			objeto.style.position = "absolute";
			imagem.src = arrayImagens[1].src;
			imagem.alt = "Expandir as respostas deste comentário";
		}
	}



function Verifica_campo_CPF(campo) {
var CPF = campo.value; // Recebe o valor digitado no campo

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

// Aqui começa a checagem do CPF
var POSICAO, I, SOMA, DV, DV_INFORMADO;
var DIGITO = new Array(10);
DV_INFORMADO = CPF.substr(9, 2); // Retira os dois últimos dígitos do número informado

// Desemembra o número do CPF na array DIGITO
for (I=0; I<=8; I++) {
  DIGITO[I] = CPF.substr( I, 1);
}

// Calcula o valor do 10º dígito da verificação
POSICAO = 10;
SOMA = 0;
   for (I=0; I<=8; I++) {
      SOMA = SOMA + DIGITO[I] * POSICAO;
      POSICAO = POSICAO - 1;
   }
DIGITO[9] = SOMA % 11;
   if (DIGITO[9] < 2) {
        DIGITO[9] = 0;
}
   else{
       DIGITO[9] = 11 - DIGITO[9];
}

// Calcula o valor do 11º dígito da verificação
POSICAO = 11;
SOMA = 0;
   for (I=0; I<=9; I++) {
      SOMA = SOMA + DIGITO[I] * POSICAO;
      POSICAO = POSICAO - 1;
   }
DIGITO[10] = SOMA % 11;
   if (DIGITO[10] < 2) {
        DIGITO[10] = 0;
   }
   else {
        DIGITO[10] = 11 - DIGITO[10];
   }

// Verifica se os valores dos dígitos verificadores conferem
DV = DIGITO[9] * 10 + DIGITO[10];
   
   if (CPF.length != 11 || CPF == "00000000000" || CPF == "11111111111" ||
           CPF == "22222222222" || CPF == "33333333333" || CPF == "44444444444" ||
           CPF == "55555555555" || CPF == "66666666666" || CPF == "77777777777" ||
           CPF == "88888888888" || CPF == "99999999999"){
	         alert('O CPF digitado é inválido!');
      campo.focus();

           return false;
   }
   if (DV != DV_INFORMADO) {
      alert('O CPF digitado é inválido!');
      campo.focus();
      return false;
   } 
}


function excluirRegistro( url ){
	
	if ( window.confirm("Deseja realmente excluir este registro?") ){
		location.href=url;
	}
	
}

function redirecionar(url){
	location.href = url;
}
