// SISTEMA OS
// SISTEMA OS
// SISTEMA OS

var v_deptoID;
var v_clienteID=0;
var v_deptoID_obrigatorio;
var v_clienteID_obrigatorio;
var opc_relatorio;
var ss;
var segundosparaReload;
var QTDmenu;
var cor_anterior;
var itens;var entrou;
var intval=""
var destino_reload;
var nStr1 = new Array();
var nStr = new Array();
var Data1ouData2;
var data1; 
var data2; 
QTDmenu=0;
var array_solicitacao_lancamento=new Array();
var qtd_solicitacao_lancamento;
qtd_solicitacao_lancamento=0;
var qtd;
var cont;
var primeiro;
var iti_branco;
var qtd_linha;
var abriu_iti;
var menuAtual;
abriu_iti=0
function os_cons_tudo(){
	for(i=1;i<qtd_linha;i++){
		if(abriu_iti==0){
		document.getElementById('TR'+i).style.display ='inline';
		document.getElementById('a'+i).style.display ='none';
		document.getElementById('f'+i).style.display  ='inline';
		}else{
		document.getElementById('TR'+i).style.display ='none';
		document.getElementById('a'+i).style.display ='inline';
		document.getElementById('f'+i).style.display  ='none';
		}
	}
	if(abriu_iti==0){abriu_iti=1}else{abriu_iti=0}
}


function f_printer(ender){open(ender)}

function end_dj_busca(ID,clienteID){
if(ID!=''){
ajaxGet('codigos.asp?local=T&A='+ ID +'&B=' + clienteID , 'NovaSolicitacao_msg');}
}

function Cep_djj_busca(ID,CEP){
if(CEP!=''){
ajaxGet('codigos.asp?local=S&A='+ ID +'&B=' + CEP, 'NovaSolicitacao_msg');}
}

function solic_lanc_delete(ID){
	for(i=0;i<array_solicitacao_lancamento.length;i++){
		if(array_solicitacao_lancamento.slice(i,i+1)==ID){
			de_fora = array_solicitacao_lancamento.splice(i,1,"-1");
			document.getElementById('Div_destinoOK' + ID).innerHTML='';
	}}
	asdsgqpOqS4_tblCor();
}


function asdsgqpOqS4_tblCor(){
	qtd=1;cont=0;primeiro=0;
	for(i=0;i<array_solicitacao_lancamento.length;i++){
		if(array_solicitacao_lancamento.slice(i,i+1)!=-1){
			cont += 1;
			document.getElementById('div_end' + array_solicitacao_lancamento.slice(i,i+1)).innerHTML="Endereço: " +cont;
			
			
			if (primeiro==0){primeiro=i+1;}
			if (qtd==1){document.getElementById('tbl_lan_'+ array_solicitacao_lancamento.slice(i,i+1)).style.backgroundColor="#F2F2EC";qtd=2}else{document.getElementById('tbl_lan_'+ array_solicitacao_lancamento.slice(i,i+1)).style.backgroundColor="#EDEDE4";qtd=1}
}}
	if (cont==1){document.getElementById('exc'+primeiro).style.display  ='none';}else{document.getElementById('exc'+primeiro).style.display  ='inline';}
}



function hahauCond_log(){
if (document.getElementById('funcionarioID').value==""){document.getElementById('DIV_usuario_condutor').innerHTML='Necessário selecionar o código do condutor';return false;} 

txt_str =  'codigos.asp?local=Q';
txt_str = txt_str + '&A=' + document.getElementById('funcionarioID').value;
ajaxGet(txt_str, 'DIV_usuario_condutor');

}

function Gfempt16gLl() {
txt_str =  'codigos.asp?local=O';
txt_str = txt_str + '&A=' + document.getElementById('EmpresaNome').value;
txt_str = txt_str + '&B=' + document.getElementById('EmpresaEndereco').value;
txt_str = txt_str + '&C=' + document.getElementById('EmpresaBairro').value;
txt_str = txt_str + '&D=' + document.getElementById('EmpresaCidade').value;
txt_str = txt_str + '&E=' + document.getElementById('EmpresaEstado').value;
txt_str = txt_str + '&F=' + document.getElementById('EmpresaCEP').value;
txt_str = txt_str + '&G=' + document.getElementById('EmpresaTelefone1').value;
txt_str = txt_str + '&H=' + document.getElementById('EmpresaTelefone2').value;
txt_str = txt_str + '&I=' + document.getElementById('site').value;
txt_str = txt_str + '&J=' + document.getElementById('EmpresaEmail').value;
txt_str = txt_str + '&K=' + document.getElementById('EmailAutomaticoAtivar').value;
txt_str = txt_str + '&L=' + document.getElementById('EmailAutomaticoCopia').value;
txt_str = txt_str + '&M=' + document.getElementById('EmpresaClienteID').value;
txt_str = txt_str + '&N=' + document.getElementById('mostrarOBS').value;


ajaxGet(txt_str, 'corpo');
}

function checkList(obj,qry,destino) {
	var v_qtd = obj.value;
//	if(v_qtd.length > 2){
	ajaxGet('codigos_AutoCompl.asp?qry=' + qry + '&v=' + obj.value , 'DIV_index_carregar')
	if(destino=='clienteID'){v_clienteID = 0}
	if(destino=='deptoID'){v_deptoID = 0}
	
//	alert('codigos_AutoCompl.asp?qry=' + qry + '&v=' + obj.value);

	var k = event.keyCode;
	var T = findPosY(obj); //top
	var L = findPosX(obj); //left
	var list = document.getElementById('listHolder');

	if(!list) {
		var list = document.createElement('DIV');
		list.id = 'listHolder';
		document.body.appendChild(list);
	}
	
	list.style.top=(T+obj.offsetHeight);
	list.style.left=L;
	list.style.display='none';
	
	var txt=obj.value;
	
	if (txt) {
		var str='<select class="style6"'+
//				'onclick="v_clienteID=this.options[this.selectedIndex].value;setOption(\''+obj.id+'\',this.options[this.selectedIndex].text)"'+
//				'onkeyup="if(event.keyCode==13){v_clienteID=this.options[this.selectedIndex].value;setOption(\''+obj.id+'\','+
				'onclick="setOption(\''+obj.id+'\',this.options[this.selectedIndex].text,\''+destino+'\',this.options[this.selectedIndex].value)"'+
				'onkeyup="if(event.keyCode==13){;setOption(\''+obj.id+'\','+
				'this.options[this.selectedIndex].text,\''+destino+'\',this.options[this.selectedIndex].value)};if(event.keyCode==27){'+
				'document.getElementById(\'listHolder\').style.display=\'none\';'+
				'document.getElementById(\''+obj.id+'\').focus()};" id="selector" size="6">'
		var match=false
		for(a=0;a<nStr.length;a++){
		
	//		if(txt.toLowerCase()==nStr[a].toLowerCase().substring(0,txt.length)){
				match=true
				str+=('<option value="'+nStr1[a].replace(/\'/gi,'’')+'">'+nStr[a]+'</option>')
	//		}
		}
	
		str+='</select>'
		if(match){
			list.innerHTML=str
			list.style.display='block'
			var sel=document.getElementById('selector')
			if(k=='40') {
			   sel.focus()
			}
		
			if(k=='13'){
			   document.getElementById('listHolder').style.display='none'
			}
		}
	}
}

function setOption(obj,val,destino,valor){
	//NAO ESQUECE DE ZERAR TB A VARIAVEL NAO ESQUECE DE ZERAR TB A VARIAVEL NAO ESQUECE DE ZERAR TB A VARIAVEL NAO ESQUECE DE ZERAR TB A VARIAVEL 
	if(destino=='clienteID'){v_clienteID = valor}
	if(destino=='deptoID'){v_deptoID = valor}
	//NAO ESQUECE DE ZERAR TB A VARIAVEL NAO ESQUECE DE ZERAR TB A VARIAVEL NAO ESQUECE DE ZERAR TB A VARIAVEL NAO ESQUECE DE ZERAR TB A VARIAVEL 
	
	var obj=document.getElementById(obj);
	
	obj.value=val;
	obj.focus();
	document.getElementById('listHolder').style.display='none';
}

function findPosX(obj){
	var curleft=0;
	if(obj.offsetParent) {
	
		while(obj.offsetParent){
			curleft+=obj.offsetLeft
			obj=obj.offsetParent;
		}
	} else if(obj.x)
		curleft+=obj.x;
		return curleft;
}

function findPosY(obj){
	var curtop=0;
	if(obj.offsetParent){
		while(obj.offsetParent){
			curtop+=obj.offsetTop
			obj=obj.offsetParent;
		}
	} else if(obj.y)
		curtop+=obj.y;
		return curtop;
}













function Impressao(saida)
{
if (opc_relatorio=='0')
{
alert('É necessário selecionar um tipo de relatório');
return false;
}
if (opc_relatorio=='1'){
//alert(v_clienteID_obrigatorio);alert(document.getElementById('relatorio_clienteID').value);
	if ((v_clienteID_obrigatorio ==1) && (v_clienteID==0)){
		alert('É necessário selecionar um cliente');return false
	}else{txt_str =  'RelatorioOSanalitico.asp';}
}
if (opc_relatorio=='2'){txt_str =  'RelatorioOSsintetico.asp';}
if (opc_relatorio=='3'){
	if (document.getElementById('relatorio_Num_OS').value==''){
	alert('É necessário selecionar uma Ordem de Serviço');return false;
	}else{txt_str =  'RelatorioReimpressaoOS.asp';}
}
if (opc_relatorio=='4'){txt_str =  'RelatorioSinteticoCliente.asp';}
if (opc_relatorio=='5'){txt_str =  'RelatorioSinteticoCondutor.asp';}
if (opc_relatorio=='6'){txt_str =  'RelatorioSinteticoAnual.asp';}
if (opc_relatorio=='7'){txt_str =  'RelatorioSenhasClientes.asp';}
if (opc_relatorio=='8'){txt_str =  'RelatorioOSanaliticoModelo2.asp';}
if (opc_relatorio=='9'){txt_str =  'RelatorioOSsinteticoCentroCusto.asp';}
if (opc_relatorio=='10'){txt_str =  'RelatorioSenhasCondutores.asp';}
txt_str = txt_str + '?A=' + document.getElementById('DataIni').value;
txt_str = txt_str + '&B=' + document.getElementById('DataFim').value;
txt_str = txt_str + '&C=' + document.getElementById('relatorio_Num_OS').value;
txt_str = txt_str + '&D=' + saida;
txt_str = txt_str + '&E=' + v_clienteID;
txt_str = txt_str + '&F=' + document.getElementById('relatorio_DividiTipo').value;
txt_str = txt_str + '&G=' + document.getElementById('relatorio_ComIti').value;
//alert(txt_str);
open(txt_str);
}




function start_Int(){
	if(intval==""){intval=setInterval("start_clock()",1300)}
	//else{stop_Int()}
	}

function stop_Int(){
	if(intval!=""){clearInterval(intval);intval=""}}

function start_clock(){
	ss = ss-1;
    if(ss == -1){
		if(destino_reload==1){ajaxGet('SolicitacaoOnLine_PainelControle_Detalhe.asp', 'DIV_SolicitacaoOnLine_PainelControle_Detalhe');ss=segundosparaReload;}
		else{ajaxGet('SolicitacaoOnLineConsultaDetalhe.asp', 'div_SolicitacaoOnLineConsulta');ss=segundosparaReload;}
	}
	if(ss > -9){document.getElementById('cronometro_solicitacao').innerHTML = ss}}

function FillTerritory(oElem,oTarget,qry,ehlistabox){
	var objDDL = document.getElementById(oTarget);
    objDDL.options.length = 0;
	var option = new Option('---------AGUARDE-----------','0');
	objDDL.options.add(option,objDDL.options.length);
	if(ehlistabox==-1){var strValue = oElem.options[oElem.selectedIndex].value;}else{var strValue = oElem.value;}
    var url = 'codigos_xml.asp';
    var strParams = '?qry=' + qry +'&v=' + strValue + '&d=' + oTarget;
//	alert(url + strParams) ;
    strParams = antiCacheRand(strParams);
    var loader1 = new
    net.ContentLoader(url + strParams,FillDropDown,null,"GET",strParams);
}					
function FillDropDown(){
	var xmlDoc = this.req.responseXML.documentElement;
    var xSel = xmlDoc.getElementsByTagName('selectElement')[0];
    var strEName = xSel.childNodes[0].firstChild.nodeValue;
	var objDDL = document.getElementById(strEName);
    objDDL.options.length = 0;
	var option = new Option('---------Selecione-----------','0');
	objDDL.options.add(option,objDDL.options.length);

    var xRows = xmlDoc.getElementsByTagName('entry');
    for(i=0;i<xRows.length;i++){
    	var theText = xRows[i].childNodes[0].firstChild.nodeValue;
        var theValue = xRows[i].childNodes[1].firstChild.nodeValue;
        var option = new Option(theText,theValue);
        objDDL.options.add(option,objDDL.options.length);
     }
}



function insert_br(text)
{
var normalized_Enters1 = text.replace("&", "ee");
var normalized_Enters = normalized_Enters1.replace(/\r|\n/g, "\r\n");
var text_with_br = normalized_Enters.replace(/\r\n/g, "!@34783233#");
var text_with_br1 = text_with_br.replace(/!@34783233#!@34783233#/g, "<br/>");
return text_with_br1;
}


function cliente_habilitar(){
itens = "";
entrou = false;

var options = document.getElementById("clienteIDbloqueado").getElementsByTagName("option");
for(var i=0;i<options.length;i++){
	if (options[i].selected){itens= options[i].value +',' + itens; entrou=true}
}

if(entrou==false){alert('É necessário selecionar uma permissão');return false}else{
txt_str =  'codigos.asp?local=M';
txt_str = txt_str + '&C=' + itens;
ajaxGet(txt_str, 'DIV_SolicitacaoOnLine_Detalhe');
}
}
function cliente_bloquear(){
itens = "";
entrou = false;

var options = document.getElementById("clienteIDbloqueado1").getElementsByTagName("option");
for(var i=0;i<options.length;i++){
	if (options[i].selected){itens= options[i].value +',' + itens; entrou=true}
}

if(entrou==false){alert('É necessário selecionar uma permissão');return false}else{
txt_str =  'codigos.asp?local=N';
txt_str = txt_str + '&C=' + itens;
ajaxGet(txt_str, 'DIV_SolicitacaoOnLine_Detalhe');
}
}



function Config_salvar(){
if (document.getElementById('TempoEspera').value==""){alert('Tempo de espera não pode estar em branco');return false;} 
if (document.getElementById('SolicitacaoOnLineAtiva').value==""){alert('O campo Ativar Solicitação Online não pode ser em branco');return false;} 
if (document.getElementById('AvisoSonoro').value==""){alert('O campo Aviso Sonoro não pode ser em branco');return false;} 

txt_str =  'codigos.asp?local=L';
txt_str = txt_str + '&A=' + document.getElementById('TempoEspera').value;
txt_str = txt_str + '&B=' + document.getElementById('SolicitacaoOnLineAtiva').value;
txt_str = txt_str + '&C=' + document.getElementById('AvisoSonoro').value;
txt_str = txt_str + '&D=' + document.getElementById('HorarioLiberarSolicitacaoOnLineDATA').value;
txt_str = txt_str + '&E=' + document.getElementById('HorarioLiberarSolicitacaoOnLineHORA').value;

ajaxGet(txt_str, 'DIV_SolicitacaoOnLine_Detalhe');

}

function alterar_cor(ID,tipo,cor_origem)
{
	if (tipo==1){
	document.getElementById(ID).style.background= '#FFFFFF' ;
	}else{
	document.getElementById(ID).style.background= cor_origem ;
	}
}

function enviarParaOS(ID, conf){
if (document.getElementById('numeroOS').value==""){alert('É necessário digitar o Número da O.S.');return false;} 
txt_str =  'codigos.asp?local=K&';
txt_str = txt_str + 'A=' + ID;
txt_str = txt_str + '&B=7';
txt_str = txt_str + '&C=' + conf;
txt_str = txt_str + '&D=' + document.getElementById('numeroOS').value;
txt_str = txt_str + '&E=' + document.getElementById('hora').value;

ajaxGet(txt_str, 'DIV_SolicitacaoOnLine_Detalhe');

}

function thUsu_senhanova(onde){
if (document.getElementById('novo_login').value==""){
document.getElementById('login_Senha_alterar_msg').innerHTML = 'É necessário digitar um nome de usuário';
return false;} 
if (document.getElementById('senha_antiga').value==""){
document.getElementById('login_Senha_alterar_msg').innerHTML = 'É necessário digitar a senha antiga';
return false;} 
if (document.getElementById('Nova_senha').value==""){
document.getElementById('login_Senha_alterar_msg').innerHTML = 'É necessário digitar a nova senha';
return false;} 
if (document.getElementById('conf_senha').value==""){
document.getElementById('login_Senha_alterar_msg').innerHTML = 'É necessário digitar a Confirmação da Senha';
return false;} 
if (document.getElementById('conf_senha').value != document.getElementById('Nova_senha').value){
document.getElementById('login_Senha_alterar_msg').innerHTML = 'O Campo nova senha e confirma senha devem ter o mesmo valor';
return false;}

if (document.getElementById('novo_login').value.length <5){
document.getElementById('login_Senha_alterar_msg').innerHTML = 'O Login deve contar no mínimo 5 caracteres';
return false;} 

if (document.getElementById('Nova_senha').value.length <5){
document.getElementById('login_Senha_alterar_msg').innerHTML = 'A Senha deve contar no mínimo 5 caracteres';
return false;} 


txt_str =  'codigos.asp?local=' + onde +'&';
txt_str = txt_str + 'A=' + document.getElementById('novo_login').value;
txt_str = txt_str + '&B=' + document.getElementById('senha_antiga').value;
txt_str = txt_str + '&C=' + document.getElementById('Nova_senha').value;
txt_str = txt_str + '&D=' + document.getElementById('conf_senha').value;

ajaxGet(txt_str, 'login_Senha_alterar_msg');
}



function alterpass(ID,nome){
msg = 'O Sistema ira criar uma nova senha para o usuário ' + nome + ' confirma ???';
if(confirm(msg))
ajaxGet('codigos.asp?local=I&A='+ ID , 'DIV_usuario_nova_senha'+ID);
}


function usuario_HjjTeDee(ID, nome){

msg = 'Confirma a Exclusão do Usuário ' + nome + ' ???';
if(confirm(msg)){
txt_str =  'codigos.asp?local=H&';
txt_str = txt_str + 'KJR=' + ID;
ajaxGet(txt_str, 'DIV_usuarios');
}
}

function usuario_desabilitar(ID){
itens = "";
entrou = false;

var options = document.getElementById("PermissaoID1").getElementsByTagName("option");
for(var i=0;i<options.length;i++){
	if (options[i].selected){itens= options[i].value +',' + itens; entrou=true}
}

if(entrou==false){alert('É necessário selecionar uma permissão');return false}else{
txt_str =  'codigos.asp?local=G&';
txt_str = txt_str + 'KJR=' + ID;
txt_str = txt_str + '&C=' + itens;

ajaxGet(txt_str, 'DIV_usuarios_permissoes');
}
}
function usuario_habilitar(ID){
itens = "";
entrou = false;

var options = document.getElementById("PermissaoID").getElementsByTagName("option");
for(var i=0;i<options.length;i++){
	if (options[i].selected){itens= options[i].value +',' + itens; entrou=true}
}

if(entrou==false){alert('É necessário selecionar uma permissão');return false}else{
txt_str =  'codigos.asp?local=F&';
txt_str = txt_str + 'KJR=' + ID;
txt_str = txt_str + '&C=' + itens;
ajaxGet(txt_str, 'DIV_usuarios_permissoes');
}
}


function UsuarioNovo(){
if (document.getElementById('novo_login').value==""){
document.getElementById('login_Senha_alterar_msg').innerHTML = 'É necessário digitar um nome de usuário';
return false;
} 
if (document.getElementById('Nova_senha').value==""){
document.getElementById('login_Senha_alterar_msg').innerHTML = 'É necessário digitar a nova senha';
return false;
} 
if (document.getElementById('conf_senha').value==""){
document.getElementById('login_Senha_alterar_msg').innerHTML = 'É necessário digitar a Confirmação da Senha';
return false;
} 
if (document.getElementById('conf_senha').value != document.getElementById('Nova_senha').value){
document.getElementById('login_Senha_alterar_msg').innerHTML = 'O Campo nova senha e confirma senha devem ter o mesmo valor';
return false;
}

if (document.getElementById('novo_login').value.length <5){
document.getElementById('login_Senha_alterar_msg').innerHTML = 'O Login deve contar no mínimo 5 caracteres';
return false;} 

if (document.getElementById('Nova_senha').value.length <5){
document.getElementById('login_Senha_alterar_msg').innerHTML = 'A Senha deve contar no mínimo 5 caracteres';
return false;} 

txt_str =  'codigos.asp?local=E&';
txt_str = txt_str + 'A=' + document.getElementById('novo_login').value;
txt_str = txt_str + '&C=' + document.getElementById('Nova_senha').value;
txt_str = txt_str + '&D=' + document.getElementById('conf_senha').value;

ajaxGet(txt_str, 'login_Senha_alterar_msg');
}


function thsenhanova(){
if (document.getElementById('novo_login').value=="")
{
document.getElementById('login_Senha_alterar_msg').innerHTML = 'É necessário digitar um nome de usuário';
return false;
} 

if (document.getElementById('senha_antiga').value=="")
{
document.getElementById('login_Senha_alterar_msg').innerHTML = 'É necessário digitar a senha antiga';
return false;
} 
if (document.getElementById('Nova_senha').value=="")
{
document.getElementById('login_Senha_alterar_msg').innerHTML = 'É necessário digitar a nova senha';
return false;
} 
if (document.getElementById('conf_senha').value=="")
{
document.getElementById('login_Senha_alterar_msg').innerHTML = 'É necessário digitar a Confirmação da Senha';
return false;
} 
if (document.getElementById('conf_senha').value != document.getElementById('Nova_senha').value)
{
document.getElementById('login_Senha_alterar_msg').innerHTML = 'O Campo nova senha e confirma senha devem ter o mesmo valor';
return false;
}

if (document.getElementById('novo_login').value.length <5){
document.getElementById('login_Senha_alterar_msg').innerHTML = 'O Login deve contar no mínimo 5 caracteres';
return false;} 

if (document.getElementById('Nova_senha').value.length <5){
document.getElementById('login_Senha_alterar_msg').innerHTML = 'A Senha deve contar no mínimo 5 caracteres';
return false;} 

txt_str =  'codigos.asp?local=D&';
txt_str = txt_str + 'A=' + document.getElementById('novo_login').value;
txt_str = txt_str + '&B=' + document.getElementById('senha_antiga').value;
txt_str = txt_str + '&C=' + document.getElementById('Nova_senha').value;
txt_str = txt_str + '&D=' + document.getElementById('conf_senha').value;

ajaxGet(txt_str, 'login_Senha_alterar_msg');
}




function relatorio_esconder(data,OS,cli,tipo,iti){
if (data==1){document.getElementById('relatorio_data').style.display  ='inline';
}else{document.getElementById('relatorio_data').style.display  ='none';}

if (OS==1){document.getElementById('relatorio_OS').style.display  ='inline';
}else{document.getElementById('relatorio_OS').style.display  ='none';}

if (cli==1){document.getElementById('relatorio_cliente').style.display  ='inline';
}else{document.getElementById('relatorio_cliente').style.display  ='none';}

if (tipo==1){document.getElementById('DIV_relatorio_DividiTipo').style.display  ='inline';
}else{document.getElementById('DIV_relatorio_DividiTipo').style.display  ='none';}

if (iti==1){document.getElementById('DIV_relatorio_ComIti').style.display  ='inline';
}else{document.getElementById('DIV_relatorio_ComIti').style.display  ='none';}

}

contenido_textarea = "";
num_caracteres_permitidos = 1000;
function valida_longitud(){
	num_caracteres = document.getElementById("itinerario").value.length
	
	if (num_caracteres <= num_caracteres_permitidos){
		contenido_textarea = document.getElementById("itinerario").value	
		falta = Number(num_caracteres_permitidos) - Number(num_caracteres)
	}else{
		document.getElementById("itinerario").value = contenido_textarea
		falta = 0
	}
		document.getElementById("qtd").innerHTML="Restam " + falta + " caracteres";
}


function funcaoYBcxvazoqsS31a(){
    var campo = new Array;
	var iti_inclusao;
    campo[0] = document.getElementById('DataAgendamento');
    campo[1] = document.getElementById('HoraAgendamento');
    campo[2] = document.getElementById('MinutoAgendamento');
    campo[3] = document.getElementById('solicitante');
	
	if(v_deptoID_obrigatorio==1){
		if(v_deptoID==0){
            alert('Favor selecionar um Departamento / Centro de Custo');
            return false;
		}
	}

	for(var i = 0; i < 4; i++)    {		
       if(campo[i].value == '')        {
			if(i==3){
            alert('Favor preencher o campo Solicitante');return false;
			}
        }
    }
	
	iti_branco=false;
	for(i=0;i<array_solicitacao_lancamento.length;i++){
		if(array_solicitacao_lancamento.slice(i,i+1)!=-1){
			if (document.getElementById('itinerario'+ array_solicitacao_lancamento.slice(i,i+1)).value==''){iti_branco=true}
	}	}
	
	if(iti_branco==true){alert('Favor preencher o(s) campo(s) Descrição do Serviço');return false;}
	
    //iti_inclusao = insert_br(document.getElementById('itinerario').value);
	
	iti_inclusao = "";
	for(i=0;i<array_solicitacao_lancamento.length;i++){
		if(array_solicitacao_lancamento.slice(i,i+1)!=-1){
		
//		alert(document.getElementById('contato'+ array_solicitacao_lancamento.slice(i,i+1)).value);
		
			if (document.getElementById('tipo'+ array_solicitacao_lancamento.slice(i,i+1)).value != ''){
				iti_inclusao = iti_inclusao + document.getElementById('tipo'+ array_solicitacao_lancamento.slice(i,i+1)).value +' '}
			if (document.getElementById('endereco'+ array_solicitacao_lancamento.slice(i,i+1)).value != ''){
				iti_inclusao = iti_inclusao + ' ' + document.getElementById('endereco'+ array_solicitacao_lancamento.slice(i,i+1)).value +' '}
			if (document.getElementById('complemento'+ array_solicitacao_lancamento.slice(i,i+1)).value != ''){
				iti_inclusao = iti_inclusao  + document.getElementById('complemento'+ array_solicitacao_lancamento.slice(i,i+1)).value +' '}
			if (document.getElementById('bairro'+ array_solicitacao_lancamento.slice(i,i+1)).value != ''){
				iti_inclusao = iti_inclusao  + ' ' + document.getElementById('bairro'+ array_solicitacao_lancamento.slice(i,i+1)).value +' '}
			if (document.getElementById('cidade'+ array_solicitacao_lancamento.slice(i,i+1)).value != ''){
				iti_inclusao = iti_inclusao  + ' ' + document.getElementById('cidade'+ array_solicitacao_lancamento.slice(i,i+1)).value +' '}
			if (document.getElementById('cep'+ array_solicitacao_lancamento.slice(i,i+1)).value != ''){
				iti_inclusao = iti_inclusao  + ' ' + document.getElementById('cep'+ array_solicitacao_lancamento.slice(i,i+1)).value +' '}
			if (document.getElementById('contato'+ array_solicitacao_lancamento.slice(i,i+1)).value != ''){
				iti_inclusao = iti_inclusao  + ' Contato:' + document.getElementById('contato'+ array_solicitacao_lancamento.slice(i,i+1)).value +' '}
					
			iti_inclusao = iti_inclusao + ' <br>Descrição:' + document.getElementById('itinerario'+ array_solicitacao_lancamento.slice(i,i+1)).value  + '<br><br>'
	}	}
	

	var txt_str;
	txt_str='';
	txt_str = 'd=' + v_deptoID + '&';
   	for(var i = 0; i < 4; i++)
    {	
		txt_str =  txt_str + i + '=' + campo[i].value + '&';
	}
	txt_str =  txt_str + '4=' + iti_inclusao + '&';

	//alert(txt_str);
	ajaxGet('codigos.asp?local=B&' + txt_str, 'NovaSolicitacao_msg');
}

function LimparAgendamento(){
document.getElementById('DataAgendamento').value ='';
document.getElementById('HoraAgendamento').value ='';
document.getElementById('MinutoAgendamento').value ='';
}


//function fun_menu(var_menu){
//	stop_Int(); // para o cronometro
//    document.getElementById(menuAtual).className= 'menu_off';
//    document.getElementById(var_menu).className= 'menu_on';
//	menuAtual = var_menu;
//}
function fun_menu(var_menu)
{
	stop_Int() // para o cronometro
	//ss=-10;  // para parar o cronometro
   	for(var i = 0; i < QTDmenu; i++)
    {	
		if(var_menu == i)
		{
		document.getElementById('menu' + i).className = 'current';
		}
			else
		{
		document.getElementById('menu' + i).className = '';
		}

	}
}



meuAjax = function (){   
   try{   
        xmlhttp = new XMLHttpRequest(); 
    }catch(ee){   
        try{   
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");   
       }catch(e){   
            try{   
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");   
            }catch(E){   
                xmlhttp = false;   
            }   
        }   
   }   
} 





ajaxGet = function( nomeUrl, divRetorno ){ 
//	if (divRetorno == 'HomeDetalhe'){
		if (nomeUrl != 'SolicitacaoNovaExcel.asp'){
		   document.getElementById(divRetorno).innerHTML = '<br><div align="center"  class="style8" ><img src="path/aguarde.gif" width="32" height="32" vspace="2" /><span class="style4" >  Aguarde, Carregando...</span></div><br><br>';
	   }
//   }

   divInsereResposta = document.getElementById(divRetorno);   
	
    nomeUrl = antiCacheRand(nomeUrl);
      
    meuAjax();   
    xmlhttp.abort();   
    xmlhttp.open("GET", nomeUrl ,true);   
    xmlhttp.setRequestHeader("Content-Type", "text/html; charset=iso-8859-1");   
    xmlhttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
	xmlhttp.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
	xmlhttp.setRequestHeader("Pragma", "no-cache");
	
	
    xmlhttp.onreadystatechange = function() {   
           if( xmlhttp.readyState == 4 ){   
                var valorRetorno            = xmlhttp.responseText;   
                divInsereResposta.innerHTML = unescape(valorRetorno);   
					extraiScript(valorRetorno)
           }   
    }   
   
   
    xmlhttp.send( null )   
}  


function extraiScript(texto){

    var ini = 0;
    while (ini!=-1){
        ini = texto.indexOf('<script', ini);
        if (ini >=0){
            ini = texto.indexOf('>', ini) + 1;
            var fim = texto.indexOf('</script>', ini);
            codigo = texto.substring(ini,fim);
            //eval(codigo);
            novo = document.createElement("script")
            novo.text = codigo;
            document.body.appendChild(novo);
        }
    }
}




  function antiCacheRand(aurl){
        var dt = new Date();
        if(aurl.indexOf("?")>=0){// já tem parametros
            return aurl + "&" + encodeURI(Math.random() + "_" + dt.getTime());
        }else{ return aurl + "?" + encodeURI(Math.random() + "_" + dt.getTime());}
    }
	

function Mascara (formato, keypress, objeto){
campo = eval (objeto);
/////////////////////////////////////HTML: onkeypress="Mascara('cep', event.keyCode, this)
// cep
if (formato=='cep'){
separador = '-';
conjunto1 = 5;
if (campo.value.length == conjunto1){
campo.value = campo.value + separador;}
}

// cpf
if (formato=='cpf'){
separador1 = '.';
separador2 = '-';
conjunto1 = 3;
conjunto2 = 7;
conjunto3 = 11;
if (campo.value.length == conjunto1)
  {
  campo.value = campo.value + separador1;
  }
if (campo.value.length == conjunto2)
  {
  campo.value = campo.value + separador1;
  }
if (campo.value.length == conjunto3)
  {
  campo.value = campo.value + separador2;
  }
}

// nascimento
if (formato=='nascimento'){
separador = '/';
conjunto1 = 2;
conjunto2 = 5;
if (campo.value.length == conjunto1)
  {
  campo.value = campo.value + separador;
  }
if (campo.value.length == conjunto2)
  {
  campo.value = campo.value + separador;
  }
}

// telefone
if (formato=='telefone'){
separador1 = '(';
separador2 = ')';
separador3 = '-';
conjunto1 = 0;
conjunto2 = 3;
conjunto3 = 8;
if (campo.value.length == conjunto1){
campo.value = campo.value + separador1;
}
if (campo.value.length == conjunto2){
campo.value = campo.value + separador2;
}
if (campo.value.length == conjunto3){
campo.value = campo.value + separador3;
}
}


}
// apenas z-index
if (typeof document.attachEvent!='undefined') {
   window.attachEvent('onload',init);
   document.attachEvent('onmousemove',moveMouse);
   document.attachEvent('onclick',checkMove); }
else {
   window.addEventListener('load',init,false);
   document.addEventListener('mousemove',moveMouse,false);
   document.addEventListener('click',checkMove,false);
}

var oDv=document.createElement("div");
var dvHdr=document.createElement("div");
var dvBdy=document.createElement("div");
var windowlock,boxMove,fixposx,fixposy,lockX,lockY,fixx,fixy,ox,oy,boxLeft,boxRight,boxTop,boxBottom,evt,mouseX,mouseY,boxOpen,totalScrollTop,totalScrollLeft;
boxOpen=false;
ox=10;
oy=10;
lockX=0;
lockY=0;

function init() {
	oDv.appendChild(dvHdr);
	oDv.appendChild(dvBdy);
	oDv.style.position="absolute";
	oDv.style.visibility='hidden';
	document.body.appendChild(oDv);	
}

function defHdrStyle() {
	dvHdr.innerHTML='<img  style="vertical-align:middle"  src="info.gif">&nbsp;&nbsp;'+dvHdr.innerHTML;
	dvHdr.style.fontWeight='bold';
	dvHdr.style.width='150px';
	dvHdr.style.fontFamily='Verdana';
	dvHdr.style.border='1px solid #A5CFE9';
	dvHdr.style.padding='3';
	dvHdr.style.fontSize='19';
	dvHdr.style.color='#4B7A98';
	//dvHdr.style.background='#D5EBF9';
	dvHdr.style.background='#000099';
	dvHdr.style.filter='alpha(opacity=85)'; // IE
	dvHdr.style.opacity='0.85'; // FF
}

function defBdyStyle() {
	dvBdy.style.borderBottom='1px solid #A5CFE9';
	dvBdy.style.borderLeft='1px solid #A5CFE9';
	dvBdy.style.borderRight='1px solid #A5CFE9';
	dvBdy.style.width='150px';
	dvBdy.style.fontFamily='arial';
	dvBdy.style.fontSize='11';
	dvBdy.style.padding='3';
	dvBdy.style.color='#1B4966';
	dvBdy.style.background='#FFFFFF';
	dvBdy.style.filter='alpha(opacity=85)'; // IE
	dvBdy.style.opacity='0.85'; // FF
}

function checkElemBO(txt) {
if (!txt || typeof(txt) != 'string') return false;
if ((txt.indexOf('header')>-1)&&(txt.indexOf('body')>-1)&&(txt.indexOf('[')>-1)&&(txt.indexOf('[')>-1)) 
   return true;
else
   return false;
}

function scanBO(curNode) {
	  if (checkElemBO(curNode.title)) {
         curNode.boHDR=getParam('header',curNode.title);
         curNode.boBDY=getParam('body',curNode.title);
			curNode.boCSSBDY=getParam('cssbody',curNode.title);			
			curNode.boCSSHDR=getParam('cssheader',curNode.title);
			curNode.IEbugfix=(getParam('hideselects',curNode.title)=='on')?true:false;
			curNode.fixX=parseInt(getParam('fixedrelx',curNode.title));
			curNode.fixY=parseInt(getParam('fixedrely',curNode.title));
			curNode.absX=parseInt(getParam('fixedabsx',curNode.title));
			curNode.absY=parseInt(getParam('fixedabsy',curNode.title));
			curNode.offY=(getParam('offsety',curNode.title)!='')?parseInt(getParam('offsety',curNode.title)):10;
			curNode.offX=(getParam('offsetx',curNode.title)!='')?parseInt(getParam('offsetx',curNode.title)):10;
			curNode.fade=(getParam('fade',curNode.title)=='on')?true:false;
			curNode.fadespeed=(getParam('fadespeed',curNode.title)!='')?getParam('fadespeed',curNode.title):0.04;
			curNode.delay=(getParam('delay',curNode.title)!='')?parseInt(getParam('delay',curNode.title)):0;
			if (getParam('requireclick',curNode.title)=='on') {
				curNode.requireclick=true;
				document.all?curNode.attachEvent('onclick',showHideBox):curNode.addEventListener('click',showHideBox,false);
				document.all?curNode.attachEvent('onmouseover',hideBox):curNode.addEventListener('mouseover',hideBox,false);
			}
			else {// Note : if requireclick is on the stop clicks are ignored   			
   			if (getParam('doubleclickstop',curNode.title)!='off') {
   				document.all?curNode.attachEvent('ondblclick',pauseBox):curNode.addEventListener('dblclick',pauseBox,false);
   			}	
   			if (getParam('singleclickstop',curNode.title)=='on') {
   				document.all?curNode.attachEvent('onclick',pauseBox):curNode.addEventListener('click',pauseBox,false);
   			}
   		}
			curNode.windowLock=getParam('windowlock',curNode.title).toLowerCase()=='off'?false:true;
			curNode.title='';
			curNode.hasbox=1;
	   }
	   else
	      curNode.hasbox=2;   
}


function getParam(param,list) {
	var reg = new RegExp('([^a-zA-Z]' + param + '|^' + param + ')\\s*=\\s*\\[\\s*(((\\[\\[)|(\\]\\])|([^\\]\\[]))*)\\s*\\]');
	var res = reg.exec(list);
	var returnvar;
	if(res)
		return res[2].replace('[[','[').replace(']]',']');
	else
		return '';
}

function Left(elem){	
	var x=0;
	if (elem.calcLeft)
		return elem.calcLeft;
	var oElem=elem;
	while(elem){
		 if ((elem.currentStyle)&& (!isNaN(parseInt(elem.currentStyle.borderLeftWidth)))&&(x!=0))
		 	x+=parseInt(elem.currentStyle.borderLeftWidth);
		 x+=elem.offsetLeft;
		 elem=elem.offsetParent;
	  } 
	oElem.calcLeft=x;
	return x;
	}

function Top(elem){
	 var x=0;
	 if (elem.calcTop)
	 	return elem.calcTop;
	 var oElem=elem;
	 while(elem){		
	 	 if ((elem.currentStyle)&& (!isNaN(parseInt(elem.currentStyle.borderTopWidth)))&&(x!=0))
		 	x+=parseInt(elem.currentStyle.borderTopWidth); 
		 x+=elem.offsetTop;
	         elem=elem.offsetParent;
 	 } 
 	 oElem.calcTop=x;
 	 return x;
 	 
}

var ah,ab;
function applyStyles() {
	if(ab)
		oDv.removeChild(dvBdy);
	if (ah)
		oDv.removeChild(dvHdr);
	dvHdr=document.createElement("div");
	dvBdy=document.createElement("div");
	CBE.boCSSBDY?dvBdy.className=CBE.boCSSBDY:defBdyStyle();
	CBE.boCSSHDR?dvHdr.className=CBE.boCSSHDR:defHdrStyle();
	dvHdr.innerHTML=CBE.boHDR;
	dvBdy.innerHTML=CBE.boBDY;
	ah=false;
	ab=false;
	if (CBE.boHDR!='') {		
		oDv.appendChild(dvHdr);
		ah=true;
	}	
	if (CBE.boBDY!=''){
		oDv.appendChild(dvBdy);
		ab=true;
	}	
}

var CSE,iterElem,LSE,CBE,LBE, totalScrollLeft, totalScrollTop, width, height ;
var ini=false;

// Customised function for inner window dimension
function SHW() {
   if (document.body && (document.body.clientWidth !=0)) {
      width=document.body.clientWidth;
      height=document.body.clientHeight;
   }
   if (document.documentElement && (document.documentElement.clientWidth!=0) && (document.body.clientWidth + 20 >= document.documentElement.clientWidth)) {
      width=document.documentElement.clientWidth;   
      height=document.documentElement.clientHeight;   
   }   
   return [width,height];
}


var ID=null;
function moveMouse(e) {
   //boxMove=true;
	e?evt=e:evt=event;
	
	CSE=evt.target?evt.target:evt.srcElement;
	
	if (!CSE.hasbox) {
	   // Note we need to scan up DOM here, some elements like TR don't get triggered as srcElement
	   iElem=CSE;
	   while ((iElem.parentNode) && (!iElem.hasbox)) {
	      scanBO(iElem);
	      iElem=iElem.parentNode;
	   }	   
	}
	
	if ((CSE!=LSE)&&(!isChild(CSE,dvHdr))&&(!isChild(CSE,dvBdy))){		
	   if (!CSE.boxItem) {
			iterElem=CSE;
			while ((iterElem.hasbox==2)&&(iterElem.parentNode))
					iterElem=iterElem.parentNode; 
			CSE.boxItem=iterElem;
			}
		iterElem=CSE.boxItem;
		if (CSE.boxItem&&(CSE.boxItem.hasbox==1))  {
			LBE=CBE;
			CBE=iterElem;
			if (CBE!=LBE) {
				applyStyles();
				if (!CBE.requireclick)
					if (CBE.fade) {
						if (ID!=null)
							clearTimeout(ID);
						ID=setTimeout("fadeIn("+CBE.fadespeed+")",CBE.delay);
					}
					else {
						if (ID!=null)
							clearTimeout(ID);
						COL=1;
						ID=setTimeout("oDv.style.visibility='visible';ID=null;",CBE.delay);						
					}
				if (CBE.IEbugfix) {hideSelects();} 
				fixposx=!isNaN(CBE.fixX)?Left(CBE)+CBE.fixX:CBE.absX;
				fixposy=!isNaN(CBE.fixY)?Top(CBE)+CBE.fixY:CBE.absY;			
				lockX=0;
				lockY=0;
				boxMove=true;
				ox=CBE.offX?CBE.offX:10;
				oy=CBE.offY?CBE.offY:10;
			}
		}
		else if (!isChild(CSE,dvHdr) && !isChild(CSE,dvBdy) && (boxMove))	{
			// The conditional here fixes flickering between tables cells.
			if ((!isChild(CBE,CSE)) || (CSE.tagName!='TABLE')) {   			
   			CBE=null;
   			if (ID!=null)
  					clearTimeout(ID);
   			fadeOut();
   			showSelects();
			}
		}
		LSE=CSE;
	}
	else if (((isChild(CSE,dvHdr) || isChild(CSE,dvBdy))&&(boxMove))) {
		totalScrollLeft=0;
		totalScrollTop=0;
		
		iterElem=CSE;
		while(iterElem) {
			if(!isNaN(parseInt(iterElem.scrollTop)))
				totalScrollTop+=parseInt(iterElem.scrollTop);
			if(!isNaN(parseInt(iterElem.scrollLeft)))
				totalScrollLeft+=parseInt(iterElem.scrollLeft);
			iterElem=iterElem.parentNode;			
		}
		if (CBE!=null) {
			boxLeft=Left(CBE)-totalScrollLeft;
			boxRight=parseInt(Left(CBE)+CBE.offsetWidth)-totalScrollLeft;
			boxTop=Top(CBE)-totalScrollTop;
			boxBottom=parseInt(Top(CBE)+CBE.offsetHeight)-totalScrollTop;
			doCheck();
		}
	}
	
	if (boxMove&&CBE) {
		// This added to alleviate bug in IE6 w.r.t DOCTYPE
		bodyScrollTop=document.documentElement&&document.documentElement.scrollTop?document.documentElement.scrollTop:document.body.scrollTop;
		bodyScrollLet=document.documentElement&&document.documentElement.scrollLeft?document.documentElement.scrollLeft:document.body.scrollLeft;
		mouseX=evt.pageX?evt.pageX-bodyScrollLet:evt.clientX-document.body.clientLeft;
		mouseY=evt.pageY?evt.pageY-bodyScrollTop:evt.clientY-document.body.clientTop;
		if ((CBE)&&(CBE.windowLock)) {
			mouseY < -oy?lockY=-mouseY-oy:lockY=0;
			mouseX < -ox?lockX=-mouseX-ox:lockX=0;
			mouseY > (SHW()[1]-oDv.offsetHeight-oy)?lockY=-mouseY+SHW()[1]-oDv.offsetHeight-oy:lockY=lockY;
			mouseX > (SHW()[0]-dvBdy.offsetWidth-ox)?lockX=-mouseX-ox+SHW()[0]-dvBdy.offsetWidth:lockX=lockX;			
		}
		oDv.style.left=((fixposx)||(fixposx==0))?fixposx:bodyScrollLet+mouseX+ox+lockX+"px";
		oDv.style.top=((fixposy)||(fixposy==0))?fixposy:bodyScrollTop+mouseY+oy+lockY+"px";		
		
	}
}

function doCheck() {	
	if (   (mouseX < boxLeft)    ||     (mouseX >boxRight)     || (mouseY < boxTop) || (mouseY > boxBottom)) {
		if (!CBE.requireclick)
			fadeOut();
		if (CBE.IEbugfix) {showSelects();}
		CBE=null;
	}
}

function pauseBox(e) {
   e?evt=e:evt=event;
	boxMove=false;
	evt.cancelBubble=true;
}

function showHideBox(e) {
	oDv.style.visibility=(oDv.style.visibility!='visible')?'visible':'hidden';
}

function hideBox(e) {
	oDv.style.visibility='hidden';
}

var COL=0;
var stopfade=false;
function fadeIn(fs) {
		ID=null;
		COL=0;
		oDv.style.visibility='visible';
		fadeIn2(fs);
}

function fadeIn2(fs) {
		COL=COL+fs;
		COL=(COL>1)?1:COL;
		oDv.style.filter='alpha(opacity='+parseInt(100*COL)+')';
		oDv.style.opacity=COL;
		if (COL<1)
		 setTimeout("fadeIn2("+fs+")",20);		
}


function fadeOut() {
	oDv.style.visibility='hidden';
	
}

function isChild(s,d) {
	while(s) {
		if (s==d) 
			return true;
		s=s.parentNode;
	}
	return false;
}

var cSrc;
function checkMove(e) {
	e?evt=e:evt=event;
	cSrc=evt.target?evt.target:evt.srcElement;
	if ((!boxMove)&&(!isChild(cSrc,oDv))) {
		fadeOut();
		if (CBE&&CBE.IEbugfix) {showSelects();}
		boxMove=true;
		CBE=null;
	}
}

function showSelects(){
   var elements = document.getElementsByTagName("select");
   for (i=0;i< elements.length;i++){
      elements[i].style.visibility='visible';
   }
}

function hideSelects(){
   var elements = document.getElementsByTagName("select");
   for (i=0;i< elements.length;i++){
   elements[i].style.visibility='hidden';
   }
}



