 //controla a fila de carregamento das solicitações
//Tenta criar o objeto xmlHTTP
try{
    xmlhttp = new XMLHttpRequest();
}catch(ee){
    try{
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }catch(e){
        try{
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }catch(E){
            xmlhttp = false;
        }
    }
}

//Fila de conexões
fila=[]
ifila=0

//Carrega via XMLHTTP a url recebida e coloca seu valor
//no objeto com o id recebido

function ajaxHTMLOff(id,url){//sem o carregando
    //Carregando...
    //document.getElementById(id).innerHTML="<table width='90%' border='0' align='center' cellpadding='0' cellspacing='0'> <tr> <td><img src='images/time.gif' width='13' height='22' /></td></tr></table>"
    //Adiciona à fila
    fila[fila.length]=[id,url]
    //Se não há conexões pendentes, executa
    if((ifila+1)==fila.length)ajaxRun()
}
function ajaxHTMLtxt(id,url){//sem o carregando
    //Carregando...
   document.getElementById(id).innerHTML="carregando..."
    //Adiciona à fila
    fila[fila.length]=[id,url]
    //Se não há conexões pendentes, executa
    if((ifila+1)==fila.length)ajaxRun()
}



function ajaxHTML(id,url){//sem o carregando
    //Carregando...
    document.getElementById(id).innerHTML="<div align=center><br><br><img src='images/loader.gif' width='32' height='32' /></div>"
    //Adiciona à fila
    fila[fila.length]=[id,url]
    //Se não há conexões pendentes, executa
    if((ifila+1)==fila.length)ajaxRun()
}

//Executa a próxima conexão da fila
function ajaxRun(){
    //Abre a conexão
    xmlhttp.open("GET",fila[ifila][1],true);
    //Função para tratamento do retorno
    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4){
            //Mostra o HTML recebido
            retorno=unescape(xmlhttp.responseText.replace(/\+/g," "))
            document.getElementById(fila[ifila][0]).innerHTML=retorno
            //Roda o próximo
            ifila++
            if(ifila<fila.length)setTimeout("ajaxRun()",20)
        }
    }
    //Executa
    xmlhttp.send(null)
}



//CHAMDAS DO CONTROLE
function carregaMenu(caminho){
	var caminho;
	ajaxHTML('conteudoPrincipal',caminho);
	
	
	
	
	}

function BuscaFilial(id){
		var id;
		ajaxHTML('listafilial','indexInternas.php?secao=empresa&modulo=filiallista&id_filial='+id);
		
	}
function buscaMapa(uf){
		
		ajaxHTML('divmapa','indexInternas.php?secao=empresa&modulo=mapa&uf='+uf);
		
	}
	
//fim do controle de carregamento




function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}



function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function TrocaClass(obj,classe){
	obj.className=classe;
}

function VaiPara(link){
	this.window.location.href=link;
	return false;
}

function TrocaCor(tr,cor){
	tr.style.backgroundColor=cor;
}
		
function AbreJanela(theURL,winName,features) { //v2.0
  	window.open(theURL,winName,features);
}


function teclaPress(e,formulario){
    var e,formulario;
	
    if(e.keyCode==13){
		document.getElementById(formulario).submit();
	}
	
}

function Seleciona(id){
	var id;
	
	document.getElementById(id).style.background = '#FFFFCC';
	}
function DesSeleciona(id){
	var id;
	
	document.getElementById(id).style.background = '#EDEDED';
	}

function fonte(classe){
	document.getElementById('divTexto').className = classe;
	
	}
	


//SEGURADOS

function SorteioMensal(valor){
		ajaxHTML('resultadosorteio','indexInternas.php?secao=ajax&modulo=sorteiomensal&data_sorteio='+valor);
	}      

function SorteioSemanal(valor){
		ajaxHTML('resultadosorteio','indexInternas.php?secao=ajax&modulo=sorteiosemanal&data_sorteio='+valor);
	}      

function SelecionouGrupo(grupo){
		ajaxHTML('lista_cidades','indexInternas.php?secao=ajax&modulo=listacidades&grupo='+grupo);
		
	}

function SelecionouEstado(estado){
		ajaxHTML('lista_cidades','indexInternas.php?secao=ajax&modulo=listacidades&estado='+estado+'&grupo='+document.getElementById("grupo").value);
		
	}
	
function SelecionouCidade(cidade){
		ajaxHTMLtxt('lista_especialidades','indexInternas.php?secao=ajax&modulo=listaespecialidades&estado='+document.getElementById("estado").value+'&cidade='+cidade+'&grupo='+document.getElementById("grupo").value);
		
	}
function GerarListaMedicos(){
		MM_openBrWindow('indexInternas.php?secao=segurados&modulo=listamedicos&conteudo=true&estado='+document.getElementById("estado").value+'&cidade='+document.getElementById("cidade").value+'&nome='+document.getElementById("nome").value+'&grupo='+document.getElementById("grupo").value,'','status=yes,scrollbars=yes,resizable=yes,width=780,height=550')
		
	}
	
//FIM SEGURADOS

function indiqueAmigo(){
	
	ajaxHTMLOff('divAmigo','templates/indiqueAmigo.htm');
	
	}
function Limpa(id){
	var id;
	ajaxHTMLOff(id,'templates/blank.htm');
	
	}
function resolucao(){
	
	total = screen.width;
	if(total > 800){
		valor = Math.round(((100-(77000/total))/2));
		
		document.getElementById('tabDireita').style.width = valor + '%';
	}
	}
	
	
function formContato(){
		MM_openBrWindow('indexInternas.php?secao=formularios&modulo=faleconosco','','status=yes,scrollbars=yes,resizable=yes,width=600,height=550')
		
	}
function formTrabalhe(){
		MM_openBrWindow('indexInternas.php?secao=formularios&modulo=trabalhe','','status=yes,scrollbars=yes,resizable=yes,width=630,height=550')
		
	}



function formSolCartao(){
		MM_openBrWindow('http://www.previsul.com.br/portal/cartao.php?secao=segurados&modulo=solicitacartao','','status=yes,scrollbars=yes,resizable=yes,width=630,height=550')
		
	}
		
function formContatoLink(id){
		MM_openBrWindow('indexInternas.php?secao=formularios&modulo=faleconosco&id_assunto='+id,'','status=yes,scrollbars=yes,resizable=yes,width=600,height=550')
		
	}		
function formIndique(secao,modulo){
		MM_openBrWindow('indexInternas.php?secao=formularios&modulo=indique&link1='+secao+'&link2='+modulo,'','status=yes,scrollbars=yes,resizable=no,width=600,height=420')
		
	}			
	
<!-- Início da Funçao FormataReais -->

function FormataReais(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;

key = String.fromCharCode(whichCode);// Valor para o código da Chave

if (strCheck.indexOf(key) == -1) return false; // Chave inválida

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;

}

function txtBoxFormat(objForm, strField, sMask, evtKeyPress) {
var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;

if(document.all) { // Internet Explorer
nTecla = evtKeyPress.keyCode; }
else if(document.layers) { // Nestcape
nTecla = evtKeyPress.which;
} else if(document.getElementById) { // FireFox
nTecla = evtKeyPress.which;
}

sValue = objForm[strField].value;

// Limpa todos os caracteres de formataçao que
// já estiverem no campo.
sValue = sValue.toString().replace( "-", "" );
sValue = sValue.toString().replace( "-", "" );
sValue = sValue.toString().replace( ".", "" );
sValue = sValue.toString().replace( ".", "" );
sValue = sValue.toString().replace( "/", "" );
sValue = sValue.toString().replace( "/", "" );
sValue = sValue.toString().replace( "(", "" );
sValue = sValue.toString().replace( "(", "" );
sValue = sValue.toString().replace( ")", "" );
sValue = sValue.toString().replace( ")", "" );
sValue = sValue.toString().replace( " ", "" );
sValue = sValue.toString().replace( " ", "" );
fldLen = sValue.length;
mskLen = sMask.length;

i = 0;
nCount = 0;
sCod = "";
mskLen = fldLen;

while (i <= mskLen) {
bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/"))
bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))

if (bolMask) {
sCod += sMask.charAt(i);
mskLen++; }
else {
sCod += sValue.charAt(nCount);
nCount++;
}

i++;
}

objForm[strField].value = sCod;

if (nTecla != 8) { // backspace
if (sMask.charAt(i-1) == "9") { // apenas números...
return ((nTecla > 47) && (nTecla < 58)); } // números de 0 a 9
else { // qualquer caracter...
return true;
} }
else {
return true;
}
}


function abrePromocao(){
		MM_openBrWindow('rodadepremios/index.php','','')
		
	}
function abrePREVICOR(){
		MM_openBrWindow('../previcor/index.php','','')
		
	}

