DivSearchOnMouse = false;
function BuscaIncremental(fOwner, fTipoPesquisa, fRetorno)
  {
  	DivSearchOnMouse = false;
  	document.getElementById(fRetorno).value = '';
  	HiddenCombobox(true);
  	CriaDivSearch(fOwner);
  	 var oldfnc=( fOwner.onblur)? fOwner.onblur:function(){}
    fOwner.onblur = function() { oldfnc();  var div_search = document.getElementById('div_search'); if( (DivSearchOnMouse == false) && (div_search != null) ) { div_search.parentNode.removeChild(div_search); HiddenCombobox(false); }  }	
  	
  	IniciaPesquisaJSon(fOwner, fTipoPesquisa, fRetorno);
  	
  }
  
function HiddenCombobox(fHidden)
  {
  	for(var campos = document.getElementsByTagName('select'), i=0;i<campos.length;i++)
  	  {
  	  	if(fHidden == true)
  	  	  campos[i].style.visibility = 'hidden';
  	  	if(fHidden == false)
  	  	  campos[i].style.visibility = 'visible';
  	  }
  }
function IniciaPesquisaJSon(fOwner, fTipoPesquisa, fRetorno)
  { 
    InitializeAjax();
    var DivSearch = document.getElementById('div_search');
    DivSearch.innerHTML = '';
	xmlhttp.open("GET", 'include/json.pesquisa.php?'+'tipo='+fTipoPesquisa+'&valor='+fOwner.value+'&field_return='+fRetorno+'&field_display='+fOwner.id+'&aleat='+aleatorio(),true);
    xmlhttp.onreadystatechange=function() 
	  {
	    if (xmlhttp.readyState==4)
		  {
			var texto=xmlhttp.responseText
			
			try
			  { eval( 'obj_Json = '+texto) }
			  catch(e) { var ErroConsulta =  true }
			if(ErroConsulta != true) 
			  {
			    for(i=0; i<obj_Json.length;i++ )
				  {
					//DivSearch.innerHTML += '<a href="#" onclick="InformaSelecao('+fOwner+', \''+fRetorno+ '\');">'+obj_Json[i]['descricao'] +'</a>'+ '<br />';
					DivSearch.innerHTML += '<a href="#" onclick="InformaSelecao(\''+fOwner.id+'\',\''+fRetorno+'\', \''+obj_Json[i]['id'] +'\', \''+obj_Json[i]['descricao']+ '\'); HiddenCombobox(false); return false;">'+obj_Json[i]['descricao'] +'</a>';
				  }	
			  }
			
	      }
      }
     xmlhttp.send(null)
  }
  
function InformaSelecao(fFieldDisplay, fFieldReturn, ValueReturn, ValueDisplay)
  {
  	var field_return = document.getElementById(fFieldReturn);
  	var field_display = document.getElementById(fFieldDisplay);
  	field_return.value = ValueReturn;
  	field_display.value = ValueDisplay;
  	var div_search = document.getElementById('div_search');
  	div_search.parentNode.removeChild(div_search);
  	
  }
function CriaDivSearch(fOwner)
  {
	
    if (document.getElementById('div_search') == null)
      {
        var div_search = document.createElement('div');
	  	var corpo = document.getElementsByTagName('body');
	  	with( div_search )
	  	  {
	  	  	id='div_search';
	  	  	style.top = (getPosition(fOwner).y+20)+'px';
	  	  	style.left = (getPosition(fOwner).x)+'px';
	  	  }
	  	corpo[0].appendChild(div_search);
      }
    else
      {
      	div_search = document.getElementById('div_search');
      	with( div_search )
	  	  {
	  	  	id='div_search';
	  	  	style.top = (getPosition(fOwner).y+20)+'px';
	  	  	style.left = (getPosition(fOwner).x)+'px';
	  	  }
      }
    div_search.onmouseout =  function() { DivSearchOnMouse = false }
    div_search.onmouseover =  function() { DivSearchOnMouse = true }
  }
  
function ExibeOcultaElemento(fElement)
    {
      var element = document.getElementById(fElement);
      if(element.style.display == 'none')        
        element.style.display='block';        	
      else
        element.style.display='none';	
	
	  return false
    }

function ExibeOcultaElementoManual(fElement, fDisplay)
  {
    document.getElementById(fElement).style.display = fDisplay;	
  }
function TrocaCorLabelFor(fCampoFor, fStyle)
  {
  	var labels = document.getElementsByTagName('label');
  	for(j=0;j<labels.length;j++)
  	  {
  	  	var labelfor=labels[j].getAttribute('for')?labels[j].getAttribute('for'):labels[j].getAttribute('htmlFor');
  	  	if(labelfor == fCampoFor)
  	      {
  	        labels[j].setAttribute('className',fStyle); 	
  	        labels[j].setAttribute('class',fStyle); 	
  	      }
  	  }
  }
  

function VerificaForm(fForm)
  {
    var verificacao = true; 
    var conta_campos = 0;
  	var campos_input = fForm.getElementsByTagName('input');
  	for(i=0;i < campos_input.length;i++)
  	  {
  	  	if( (campos_input[i].getAttribute('obrigatorio') == 'S') && (campos_input[i].value.length <= 0) && (campos_input[i].disabled != true) && (campos_input[i].parentNode.style.display != 'none') )
  	  	  {
  	  	  	verificacao = false;
  	  	  	var campo = campos_input[i];
  	  	  	if(conta_campos == 0)
  	  	  	  var primeiro_campo = campos_input[i];
  	  	  	
  	  	  	TrocaCorLabelFor(campo.id, 'label_obrigatorio_nao_preenchido');
  	  	  	
  	  	  	var oldfnc=( campo.onblur)? campo.onblur:function(){}
	        campo.onblur = function() { oldfnc();  if(this.value.length > 0) { TrocaCorLabelFor(this.id, 'label_obrigatorio');   } }	
  	  	  	
  	  	  	conta_campos++;
  	  	  }
  	  }
  	var campos_select = fForm.getElementsByTagName('select');
  	for(i=0;i < campos_select.length;i++)
  	  	if( (campos_select[i].getAttribute('obrigatorio') == 'S') && (campos_select[i].selectedIndex == 0) && (campos_select[i].disabled != true) && (campos_select[i].parentNode.style.display != 'none') )
  	  	  {
  	  	    verificacao = false;
  	  	    var campo = campos_select[i];
  	  	    TrocaCorLabelFor(campo.id, 'label_obrigatorio_nao_preenchido');
  	  	    
			var oldfnc=(campo.onchange)? campo.onchange:function(){}
	        campo.onchange = function() { oldfnc();  if(campo.selectedIndex != 0 ) TrocaCorLabelFor(this.id, 'label_obrigatorio'); }
  	  	    
  	  	    if(conta_campos == 0)
  	  	  	  var primeiro_campo = campo;  
  	  	    conta_campos++
  	  	  }
  	var campos_textarea = fForm.getElementsByTagName('textarea');
  	for(i=0;i < campos_textarea.length;i++)
  	  {
  	    if( (campos_textarea[i].getAttribute('obrigatorio') == 'S') && (campos_textarea[i].value.length <= 0) && (campos_textarea[i].disabled != true) && (campos_textarea[i].parentNode.style.display != 'none') )
  	  	  {
  	  	    verificacao = false;
  	  	    var campo = campos_textarea[i];
  	  	    TrocaCorLabelFor(campo.id, 'label_obrigatorio_nao_preenchido');
  	  	    
  	  	    var oldfnc=( campo.onblur)? campo.onblur:function(){}
	        campo.onblur = function() { oldfnc();  if(campo.value.length > 0 ) TrocaCorLabelFor(this.id, 'label_obrigatorio'); }
	        
  	  	    
  	  	    if(conta_campos == 0)
  	  	  	  var primeiro_campo = campo;
  	  	    conta_campos++
  	  	  }	
  	  }  
    if(verificacao == false)
      {
        alert('Campos marcados em vermelho são obrigatórios e não foram preenchidos.')
        primeiro_campo.focus();
      }
      
  	return verificacao;
  }
  
function InsereValidacao()
  {
    
    for( var fForms = document.getElementsByTagName('form'),i=0;i<fForms.length;i++)
      {
        var oldfnc=( fForms[i].onsubmit)? fForms[i].onsubmit:function(){}
        fForms[i].onsubmit = function() { oldfnc();  return VerificaForm(this);  }	
        /* Verifica se existem elementos do subtipo data */  
      }
    var fCamposInput = document.getElementsByTagName('input');  
    for(j=0;j<fCamposInput.length;j++)
      {
		var campo_alvo = fCamposInput[j];
      	if( campo_alvo.getAttribute('subtipo') == 'data')
      	  {
			with( campo_alvo ) 
			  {
			  	size=10;
			  	maxLength=10;
			  }
			
      	    /* Cria imagem*/
      	    var img_calendario = document.createElement('img');
      	    img_calendario.src = 'img/calendario.gif';
      	    //img_onclick = (function() { displayCalendar(campo_data,'dd/mm/yyyy',this); return false; } ) 
      	    /* cria link */
      	    var link_calendario = document.createElement('a');
      	    link_calendario.href = '#';
      	    link_calendario.id = 'calend_'+aleatorio();;
      	    link_calendario.title = 'Exibir calendário';

      	    
      	    var target = campo_data;
      	    
      	    link_calendario.onclick = (function() { displayCalendar(this,'dd/mm/yyyy',this); return false; } )

      	    campo_alvo.onblur = function() { FormataCampoData(this); }
      	    campo_alvo.parentNode.insertBefore(link_calendario, campo_alvo.nextSibling);

      	    
      	    link_calendario.appendChild(img_calendario);
      	  }
      	/* Se campo for do tipo hora */  
      	else if((campo_data = fCamposInput[j]).getAttribute('subtipo') == 'hora')
      	  {
			campo_data.size = 6; 
			campo_data.maxLength = 5;
			var oldfnc=( campo_data.onblur)? campo_data.onblur:function(){}
	        campo_data.onblur = function() {   FormataCampoHora(this) }	
      	  }
      	  
      }
    MarcaCamposObrigatorios();
	
  }
  
  
/*var fCampos = document.getElementsByTagName('input');
for(var a, i = 0; i < fCampos.length; i++)
  {
	if((a = fCampos[i]).type == "submit")
	  {
	  	alert("Achou submit. Nome do form:" + fCampos[i].form.id);
	  	(function(a)
	  	  {
	  		var oldfnc = a.onclick || function(){};
	  		a.onclick = function()
	  		  {
	  		  	return oldfnc(), VerificaForm(this.form);
	  		  }
	  	  }
	  	  )(a);
      }
  }
  */
function FormataCampoData(fOwner)  
  {
    var valor = fOwner.value.trim();
    data_corrente = new Date();
    if(valor.length > 0)
      {
      	if(valor.length == 8)
      	  {
      	    valor = valor.substring(0,2)+'/'+ valor.substring(2,4)+'/'+valor.substring(4,8);	
      	  }
      	else if(valor.length == 6)
      	  {
      	    valor = valor.substring(0,2)+'/'+ valor.substring(2,4)+'/20'+valor.substring(4,8);	
      	  }
      	else if(valor.length == 4)
      	  {
      	    valor = valor.substring(0,2)+'/'+ valor.substring(2,4)+'/'+data_corrente.getFullYear();
      	  }
      	  
      	var data_explode = valor.split('/');
      	
      	if(  isDate(data_explode[2], data_explode[1], data_explode[0]) == false )
      	  {
      	    alert('Data inválida: '+valor);
      	    fOwner.focus();
      	  }

      	
      	
      	fOwner.value = valor;
      }
    
  }
function FormataCampoHora(fOwner)  
  {
    var valor = fOwner.value.trim();
    if(valor.length > 0)
      {
        if(valor.length  == 2)
	      valor += ':00';
	    else if(valor.length  == 4)
	      valor = valor.substring(0,2)+':'+ valor.substring(2, 5);
	    else if(valor.length == 5)  
	      valor = valor;
	    padrao_hora = /([01][0-9]|2[0-3]):[0-5][0-9]/;
	    expressao_hora = new RegExp(padrao_hora); 
	    fOwner.value = valor;
	    
	    var teste = expressao_hora.test(valor)
	    if(teste == false )
	      {
	      	alert('Horário inválido: '+valor);
	      	fOwner.select();
	      	//fOwner.value.selectAll;
	      }	
      }

  }
function DisableFields(fFieldId, fDisabled)
  {
  	var Field = document.getElementById(fFieldId);
  	Field.disabled = fDisabled;
  }
function MarcaCamposObrigatorios()
  {
    var campos_input = document.getElementsByTagName('input');
  	for(i=0;i < campos_input.length;i++)
  	  {
  	  	if( (campos_input[i] != null) && (campos_input[i].getAttribute('obrigatorio') == 'S') )
  	  	  {
  	  	  	//campos_input[i].getAttribute('obrigatorio')
  	  	  	TrocaCorLabelFor(campos_input[i].id, 'label_obrigatorio');
  	  	  }
  	  }
  	var campos_select = document.getElementsByTagName('select');
  	for(i=0;i < campos_select.length;i++)
  	  	if( (campos_select[i] != null) && (campos_select[i].getAttribute('obrigatorio') == 'S') )
  	  	  {
  	  	    TrocaCorLabelFor(campos_select[i].id, 'label_obrigatorio');
  	  	  }
  	var campos_textarea = document.getElementsByTagName('textarea');
  	for(i=0;i < campos_textarea.length;i++)
  	  	if( campos_textarea[i].getAttribute('obrigatorio') == 'S')
  	  	  {
  	  	    TrocaCorLabelFor(campos_textarea[i].id, 'label_obrigatorio');
  	  	  }	
  }
function TabelaHover()
  {
  	var tabelas = document.getElementsByTagName('table');

  	for(i=0;i<tabelas.length;i++)
  	  {
  	  	var efeitomouse = tabelas[i].getAttribute('efeitomouse');
		if(efeitomouse != 'no')
		  {
			var tabela_body = tabelas[i].getElementsByTagName('tbody');
	  	  	var tabela_celulas = tabela_body[0].getElementsByTagName('td');
	  	  	for(j=0; j < tabela_celulas.length; j++)
	  	  	  {
	  	  	  	tabela_celulas[j].onmouseover = function() { CorLinhaTabela(this, this.parentNode.sectionRowIndex, 'table_mouseover'); }
	  	  	  	tabela_celulas[j].onmouseout = function() { CorLinhaTabela(this, this.parentNode.sectionRowIndex, ''); }
	  	  	  }  	
		  }
  	  	
  	  } 
  }
function CorLinhaTabela(fLinha, fIndexLinha, fClass)
  {
    var tabela = fLinha.parentNode.parentNode;
    var linha = tabela.rows[fIndexLinha];
    var celulas = linha.getElementsByTagName('td');
    for(k=0;k<celulas.length;k++)
      {
      	celulas[k].className = fClass;
      }
  }
  
  
function MostraListaDocumentos(fOwner)
  {
  	var lista_filha = fOwner.parentNode.getElementsByTagName('ul');
  	for(i=0; i<lista_filha.length;i++)
  	  {
  	  	if(lista_filha[i].style.display == 'block')
  	  	  lista_filha[i].style.display = 'none';
  	  	else
  	  	  lista_filha[i].style.display = 'block';
  	  }
  }
  
function AgendaMostraQuadro(fOwner, fItemAgenda)
  {
  	
  	/* se Owner for do tipo td */
  	if(fOwner.tagName == 'DIV')
  	  {
  	    var data_agenda = fOwner.parentNode.getAttribute('data');
	  	var hora_agenda = fOwner.parentNode.getAttribute('hora');
	  	var quadro_agenda = document.getElementById('quadro_agenda_compromisso_rapido');
	  	var altura_table = fOwner.parentNode.parentNode.parentNode.parentNode.offsetTop;
	  	var left_table = fOwner.parentNode.parentNode.parentNode.parentNode.offsetLeft;
	  	with (quadro_agenda)
	  	  {
	  	  	style.top = (fOwner.parentNode.offsetTop+altura_table)+'px';
	  	  	style.left = (fOwner.parentNode.offsetLeft+left_table)+'px';
	  	  	style.display = 'block';
	  	  }
	  	//horário
	  	var horario_split = hora_agenda.split(':');
	
	  	document.getElementById('owner_compromisso').value = fOwner.parentNode.id;
	  	document.getElementById('data_compromisso').value = data_agenda;
	  	document.getElementById('hora_inicio').value = hora_agenda;
	  	document.getElementById('compromisso_opcoes_avancadas').style.display = 'none';
	  	document.getElementById('texto_compromisso').value = '';
	  	document.getElementById('texto_compromisso').focus();
	  	
	  	if(parseInt(horario_split[1]) == 0)
	  	  var hora_final = horario_split[0]+':30';
	
	  	else
	  	  {
	  	    var hora_final = (parseInt(horario_split[0]))+1+':00' 	
	  	  }
		document.getElementById('hora_final').value = hora_final;
	 	var label_data = document.getElementById('quadro_agenda_data');
	 	label_data.innerHTML =  data_agenda+" às "+hora_agenda+" - "+hora_final;	
  	  }
  	else if(fOwner.tagName == 'A')
  	  { 
  	    document.getElementById('div_engloba_tabela').style.display = 'none';
	  	document.getElementById('quadro_agenda_compromisso_completo').style.display = 'block';
  	    
  	    var obj_ajax = InitializeAjax();
  	    var agenda_completo = document.getElementById('quadro_agenda_compromisso_completo');

		obj_ajax.open("GET", 'include/equipe/equipe.agenda.php?'+'busca_item_json='+fItemAgenda+'&aleat='+aleatorio(),true);
	    obj_ajax.onreadystatechange=function() 
		  {
		    if (obj_ajax.readyState==4)
			  {
				var texto=xmlhttp.responseText
				var span_opcoes_compromisso_detalhe = document.getElementById('opcoes_compromisso_detalhe');
				span_opcoes_compromisso_detalhe.innerHTML = '<button onclick="ExibeOcultaElementoManual(\'div_engloba_tabela\', \'block\'); ExibeOcultaElementoManual(\'quadro_agenda_compromisso_completo\', \'none\');">Voltar</button>';

				eval( 'obj_Json = '+texto)
				document.getElementById('texto_compromisso_completo').value = urldecode(obj_Json.compromisso);
				document.getElementById('hora_inicio_completo').value = obj_Json.hora_inicial;
				document.getElementById('hora_final_completo').value = obj_Json.hora_final;
				document.getElementById('periodo_alerta_completo').value = obj_Json.periodo_alerta;
				if(obj_Json.suporte_relacionado > 0)
				  document.getElementById('linka_suporte_relacionado').innerHTML = '<a href="internal.php?main=6&amp;submenu=28&amp;exibe_item='+obj_Json.suporte_relacionado+'&amp;hash='+obj_Json.md5+'">'+obj_Json.suporte_relacionado+'</a>';
				else
				  document.getElementById('linka_suporte_relacionado').innerHTML = 'Nenhum';
				if(obj_Json.concluido == 'S')
				  {
				  	document.getElementById('exibe_status_compromisso').innerHTML = 'Concluído em '+obj_Json.data_conclusao+' às '+obj_Json.hora_conclusao;
//				  	/span_opcoes_compromisso_detalhe.innerHTML += 'Marcado como concluído em '+obj_Json.data_conclusao+' às '+obj_Json.hora_conclusao;
				  }
				else
				  {
				    document.getElementById('exibe_status_compromisso').innerHTML = 'Pendente.';
				    
				    with (span_opcoes_compromisso_detalhe) 
				      {
				      	innerHTML += '<form method="post" style="display: inline" action="internal.php"><input type="hidden" name="main" value="6" /><input type="hidden" name="submenu" value="59" /><input type="hidden" name="action_db" value="marca_concluido" /><input type="hidden" name="compromisso" value="'+obj_Json.id+'" /><input type="submit" value="Marcar como concluído" /></form>';
				      }
				    
				    
				  }
				  
				
		      }
	      }
	     obj_ajax.send(null)
  	    
  	  }
  	

  }
function AgendaCriarCompromisso()
  {
  	var owner_compromisso = document.getElementById('owner_compromisso');
  	var celula = document.getElementById(owner_compromisso.value);
  	var conteudo = document.getElementById('texto_compromisso').value;
  	celula.innerHTML = '<div class="agenda_destaque_compromisso">'+conteudo+'</div>';
  	
  	document.getElementById('quadro_agenda_compromisso_rapido').style.display= 'none';
  }

function EnviarForm(fForm, fParametroAdicional)
  {
  	var obj_ajax = InitializeAjax();
  	
  	var destino_ajax = CriaDestinoAjax('div_destino_form');
  	var top_destino = document.getElementById('conteudo_meio').offsetTop;
  	var left_destino = document.getElementById('conteudo_meio').offsetLeft;
  	destino_ajax.style.top = (top_destino+20)+'px';
  	destino_ajax.style.left = (left_destino+20)+'px';
  	destino_ajax.innerHTML = 'Enviando form teste';
  	
  	var form = document.getElementById(fForm);
  	
  	with (obj_ajax)
	  {
		open("POST", ""+form.action, true);
		setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
		setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
		setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
		setRequestHeader("Pragma", "no-cache"); 
		send(MontaValores(form.id, ''));	
	  }
	obj_ajax.onreadystatechange=function()
	  {
	     texto=obj_ajax.responseText;
	     destino_ajax.innerHTML = texto;
	     if(texto.length > 0)
	       {
	         eval( 'obj_Json = '+texto)
	         destino_ajax.innerHTML = obj_Json.mensagem;
	         if(obj_Json.result == true)
	           AgendaCriarCompromisso();   
	       }
	  }
	 

  }
function CriaDestinoAjax(fIdElemento)
  {
  	var corpo = document.getElementsByTagName('body');
  	var elemento = document.createElement('div');
  	with (elemento)
  	  {
  	    id = fIdElemento;	
  	  }
  	corpo[0].appendChild(elemento);
  	
  	return elemento;
  }
  
  
function CriaComboFuncionariosAgenda()
  {
  	var div_combo = document.getElementById('combo_listagem_usuarios_agenda');
  	var posicao_link = getPosition( document.getElementById('link_alterna_usuario_agenda'));
  	div_combo.style.display = 'block';
  	var posicao_div_combo = getPosition(div_combo);
  	div_combo.style.left = (posicao_link.x-posicao_div_combo.w+posicao_link.w)+'px';
  	div_combo.style.top = (posicao_link.y+posicao_link.h)+'px';
  	
  	
  	InitializeAjax();
    var DivSearch = document.getElementById('div_search');
    div_combo.innerHTML = '';
	xmlhttp.open("GET", 'include/json.pesquisa.php?'+'tipo=funcionario&valor=%%&sem_limite=S&field_return=usuario_consulta_agenda&field_display='+div_combo.id+'&aleat='+aleatorio(),true);
    xmlhttp.onreadystatechange=function() 
	  {
	    if (xmlhttp.readyState==4)
		  {
			var texto=xmlhttp.responseText
			
			try
			  { eval( 'obj_Json = '+texto) }
			  catch(e) { var ErroConsulta =  true }
			if(ErroConsulta != true) 
			  {
			    div_combo.innerHTML += '<a href="#" onclick="InformaSelecaoUsuarioAgenda(\'usuario_consulta_agenda\',\'ALL\'); HiddenCombobox(false); return false;"><strong>Todos os usuários</strong></a> <br />';
			    for(i=0; i<obj_Json.length;i++ )
				  {
					//DivSearch.innerHTML += '<a href="#" onclick="InformaSelecao('+fOwner+', \''+fRetorno+ '\');">'+obj_Json[i]['descricao'] +'</a>'+ '<br />';
					div_combo.innerHTML += '<a href="#" onclick="InformaSelecaoUsuarioAgenda(\'usuario_consulta_agenda\',\''+obj_Json[i]['id'] +'\'); HiddenCombobox(false); return false;">'+obj_Json[i]['descricao'] +'</a> <br />';
				  }	
			  }
			
	      }
      }
     xmlhttp.send(null)
  	
  	
  	
  }
  
function InformaSelecaoUsuarioAgenda(fFieldReturn, ValueReturn)
  {
  	var field_return = document.getElementById(fFieldReturn);

  	field_return.value = ValueReturn;
  	
  	document.getElementById('form_escolhe_usuario_agenda').submit();
  	
  }
  
  
function MontaValores(fOrdemForm, fParametroAdicional) 
  { 	
	var queryString = ""; 
	var form = document.getElementById(fOrdemForm);
    for (var i = 0; i < form.elements.length; i++) 
      { 
	    //alert('teste'+form.elements[i].name+''+form.elements[i].value);
        if ( (form.elements[i].type == "text" || form.elements[i].type == "password" || 
            form.elements[i].type == "textarea" || form.elements[i].type == "TEXTAREA" || form.elements[i].type == "combobox" ||form.elements[i].type == "select-one" || form.elements[i].type == "hidden" ) &&  (form.elements[i].getAttribute('readonly') != true))  
          { 
             queryString = queryString + form.elements[i].name + "=" + url_encode(form.elements[i].value.replace(/^\ /, '')) + "&"; 
          } 
        if (form.elements[i].type == "checkbox") 
          { 
            queryString = queryString + form.elements[i].name + "=" + form.elements[i].checked + "&"; 
          } 
        if (form.elements[i].type == "radio") 
          { 
            if (form.elements[i].checked == true) 
              { 
                queryString = queryString + form.elements[i].name + "=" + form.elements[i].value + "&"; 
              } 
          } 
      }
    return queryString;
  }
function url_encode(str) 
  {  
	var hex_chars = "0123456789ABCDEF";  
    var noEncode = /^([a-zA-Z0-9\_\-\.])$/;  
    var n, strCode, hex1, hex2, strEncode = "";  

    for(n = 0; n < str.length; n++) {  
      if (noEncode.test(str.charAt(n))) {  
                strEncode += str.charAt(n);  
            } else {  
          strCode = str.charCodeAt(n);  
          hex1 = hex_chars.charAt(Math.floor(strCode / 16));  
          hex2 = hex_chars.charAt(strCode % 16);  
          strEncode += "%" + (hex1 + hex2);  
        }  
      }  
    return strEncode;  
  }  

    // url_decode version 1.0  
    function url_decode(str) {  
        var n, strCode, strDecode = "";  

        for (n = 0; n < str.length; n++) {  
            if (str.charAt(n) == "%") {  
                strCode = str.charAt(n + 1) + str.charAt(n + 2);  
                strDecode += String.fromCharCode(parseInt(strCode, 16));  
                n += 2;  
            } else {  
                strDecode += str.charAt(n);  
            }  
        }  

        return strDecode;  
    }
    
function urlencode(str) 
  {
    str = escape(str);
    str = str.replace('+', '%2B');
    str = str.replace('%20', '+');
    str = str.replace('*', '%2A');
    str = str.replace('/', '%2F');
    str = str.replace('@', '%40');
    return str;
  }
function urldecode(str) 
  {
    str = str.replace('+', ' ');
	str = unescape(str);
	return str;
  }

      
function moveOption(name_select1, name_select2)
  {
	objs_add = document.getElementsByName(name_select1)
    objs_remove = document.getElementsByName(name_select2)
    obj_remove = objs_remove[0];
    obj_add = objs_add[0];
    var ary_temp_options = new Array();
    var x = 0;
    for (var i = 0; i < obj_add.length; i++) 
      {
    	if (obj_add.options[i].selected) 
    	  {
            var int_remove = obj_remove.length++;
            obj_remove.options[int_remove].text = obj_add.options[i].text;
            obj_remove.options[int_remove].value = obj_add.options[i].value;
          }
        else 
          {
            var obj_temp = new Object();
            obj_temp.text = obj_add.options[i].text;
            obj_temp.value = obj_add.options[i].value;
            ary_temp_options[x] = obj_temp;
            x++;
          }
        }
      obj_add.length = ary_temp_options.length;
      for (var j = 0; j < ary_temp_options.length; j++) {
        obj_add.options[j].text = ary_temp_options[j].text;
        obj_add.options[j].value = ary_temp_options[j].value;
        obj_add.options[j].selected = false;
      }
  }
         
function selectAllOptions(select)
  {
    s=document.getElementsByName(select);
    for(var i=0; i < s[0].length; i++)
      {
        s[0].options[i].selected = true;
      }
  }
  
addEvent = function(o, e, f, s){
    var r = o[r = "_" + (e = "on" + e)] = o[r] || (o[e] ? [[o[e], o]] : []), a, c, d;
    r[r.length] = [f, s || o], o[e] = function(e){
        try{
            (e = e || event).preventDefault || (e.preventDefault = function(){e.returnValue = false;});
            e.stopPropagation || (e.stopPropagation = function(){e.cancelBubble = true;});
            e.target || (e.target = e.srcElement || null);
            e.key = (e.which + 1 || e.keyCode + 1) - 1 || 0;
        }catch(f){}
        for(d = 1, f = r.length; f; r[--f] && (a = r[f][0], o = r[f][1], a.call ? c = a.call(o, e) : (o._ = a, c = o._(e), o._ = null), d &= c !== false));
        return e = null, !!d;
    }
}

removeEvent = function(o, e, f, s){
    for(var i = (e = o["_on" + e] || []).length; i;)
        if(e[--i] && e[i][0] == f && (s || o) == e[i][1])
            return delete e[i];
    return false;
}

String.prototype.trim = function()
  {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
  }

function aleatorio()
  { 
    var inferior = 1;
	var superior = 128472;
    numPossibilidades = superior - inferior 
    aleat = Math.random() * numPossibilidades 
    aleat = Math.floor(aleat) 
    return parseInt(inferior) + aleat 
  }
  
function getPosition(o)
  {
	for(var r = {x: o.offsetLeft, y: o.offsetTop, h: o.offsetHeight, w:o.offsetWidth}; 
	o = o.offsetParent; r.x += o.offsetLeft, r.y += o.offsetTop);
	return r;
  }
  
  
function isDate(y, m, d)
  {
	var o = new Date(y, --m, d);
	return o.getFullYear() == y && o.getMonth() == m && o.getDate() == d;
  }

/*function IsDate(day, month, year) {
    //IsDate(29, 2, 2005)
    //IsDate(29, 2, 2004)
    var date = new Date(year, month, day);
    var blnRet = false;
    var blnDay;
    var blnMonth;
    var blnYear;

    date.setFullYear(year, month -1, day);

    blnDay   = (date.getDate()  == day);
    blnMonth = (date.getMonth() == month -1);
    blnYear  = (date.getYear()  == year);

    if (blnDay && blnMonth && blnYear)
        blnRet = true;

    return blnRet;
} */
function InitializeAjax()
  {
    try
	  {
    	xmlhttp = new XMLHttpRequest();
	  }
	catch(ee)
	  {
        try
	      {
        	xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
      	  }
		catch(e)
	  	  {
        	try
		  	  {
            	xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
          	  }
			catch(E)
		  	  {
            	xmlhttp = false;
        	  }
    	  }
  	  }
  	return xmlhttp;
  }
   
function PegaDadosPedAlteracao(fOwner, fCodPedido)
  {
	InitializeAjax();
    var div_detalhes = document.getElementById('pedido_detalhes');
    var ancestral = fOwner.parentNode;
    
    div_detalhes.style.top = fOwner.parentNode.offsetTop+20+'px'; 
    div_detalhes.style.left = fOwner.offsetLeft+20+'px';
    div_detalhes.style.position = 'absolute';
	xmlhttp.open("GET", 'include/json.pesquisa.php?'+'tipo=detalhe_pedido_alteracao'+'&valor='+fCodPedido+'&field_return=x&field_display=x&aleat='+aleatorio(),true);
    xmlhttp.onreadystatechange=function() 
	  {
	    if (xmlhttp.readyState==4)
		  {
			var texto=xmlhttp.responseText
			
			try
			  { eval( 'obj_Json = '+texto) }
			  catch(e) { var ErroConsulta =  true }
			if(ErroConsulta != true) 
			  {
			    //alert(texto);
				for(i=0; i<obj_Json.length;i++ )
				  {
					document.getElementById('detalhe_cliente').innerHTML = obj_Json[i]['nome_cliente'];
					document.getElementById('detalhe_problema').innerHTML = obj_Json[i]['problema'];
					document.getElementById('detalhe_sistema').innerHTML = obj_Json[i]['sistema'];
					document.getElementById('detalhe_prioridade').innerHTML = obj_Json[i]['prioridade_nome'];
					document.getElementById('detalhe_prioridade').style.backgroundColor = obj_Json[i]['prioridade_cor'];
					document.getElementById('detalhe_codsuporte').value = obj_Json[i]['id'];
					document.getElementById('detalhe_empresa_ligacao').value = obj_Json[i]['empresa_ligacao'];
					document.getElementById('detalhe_status').innerHTML = obj_Json[i]['status_chamado'];
					document.getElementById('detalhe_status').style.backgroundColor = obj_Json[i]['status_cor'];
					
				  }
				div_detalhes.style.display = 'inline';
			  }
			
	      }
      }
     xmlhttp.send(null);
  }