var divInsereResposta = new Array(30)
var w_url_get = new Array(30)
var w_url_post = new Array(30)
var valorRetorno = new Array(30)
var xmlhttp = new Array(30)


function ajaxGet( nomeUrl, divRetorno , get_value, w_count)
{    
    
    divInsereResposta[w_count] = document.getElementById( divRetorno );   
       
    meuAjax(w_count);   
    xmlhttp[w_count].abort();   
    w_url_get[w_count] = nomeUrl + '?' + get_value
    
    
    w_url_get[w_count] = antiCacheRand(w_url_get[w_count])    
  
    
    xmlhttp[w_count].open("GET", w_url_get[w_count],true);   
       
    xmlhttp[w_count].setRequestHeader("Content-Type", "text/html; charset=iso-8859-1");   
    xmlhttp[w_count].onreadystatechange = function() 
    {   
            if  ( xmlhttp[w_count].readyState == 1) 
            { 
            	divInsereResposta[w_count].innerHTML = "<font face='Verdana' size='1' color='#666666'>Carregando...</font>";
		  	}
            if( xmlhttp[w_count].readyState == 4 )
            {                
   		    	var previneCache = new Date().getTime();
				valorRetorno =unescape(xmlhttp[w_count].responseText.replace(/\+/g," "));
           		divInsereResposta[w_count].innerHTML=valorRetorno;
           		extraiScript(valorRetorno);
            }   
    }   
       
	xmlhttp[w_count].send( null );   
  
}   
var w_foco
function ajaxPost( nomeUrl, divRetorno , post_value, w_count , w_focus)
{    
    if (w_count == "")
	{    
		w_count = 1
    }
    w_foco = w_focus
    divInsereResposta[w_count] = document.getElementById( divRetorno );   
//    alert(divInsereResposta[w_count]) 
    //alert(w_count)  
    meuAjax(w_count);   
    xmlhttp[w_count].abort();   
    w_url_post[w_count] = nomeUrl + '?' + post_value
    
    
    w_url_post[w_count] = antiCacheRand(w_url_post[w_count])    
    xmlhttp[w_count].open("POST", w_url_post[w_count],true);   
       
    xmlhttp[w_count].setRequestHeader("Content-Type", "text/html; charset=iso-8859-1");   
    xmlhttp[w_count].onreadystatechange = function() 
    {   
            if  ( xmlhttp[w_count].readyState == 1) 
            { 
            	divInsereResposta[w_count].innerHTML = "<br>&nbsp;&nbsp;<img border='0' src='imagens/indicator.gif'>"

		  	}
            if( xmlhttp[w_count].readyState == 4 )
            {             
   		     	var previneCache = new Date().getTime();
           		valorRetorno =unescape(xmlhttp[w_count].responseText.replace(/\+/g," "));
           		divInsereResposta[w_count].innerHTML=valorRetorno;
           		extraiScript(valorRetorno);
            }   
    }   
	xmlhttp[w_count].send( null );  
	if (w_focus != null)
	{
		//setTimeout("espera()", 500); 
	}
}   

function ajaxPostCombo( nomeUrl, divRetorno , post_value, w_count , w_focus)
{    
    if (w_count == "")
	{    
		w_count = 1
    }
    w_foco = w_focus
    divInsereResposta[w_count] = document.getElementById( divRetorno );   
//    alert(divInsereResposta[w_count]) 
    //alert(w_count)  
    meuAjax(w_count);   
    xmlhttp[w_count].abort();   
    w_url_post[w_count] = nomeUrl + '?' + post_value
    
    
    w_url_post[w_count] = antiCacheRand(w_url_post[w_count])    
    xmlhttp[w_count].open("POST", w_url_post[w_count],true);   
       
    xmlhttp[w_count].setRequestHeader("Content-Type", "text/html; charset=iso-8859-1");   
    xmlhttp[w_count].onreadystatechange = function() 
    {   
            if  ( xmlhttp[w_count].readyState == 1) 
            { 
            //divInsereResposta[w_count].innerHTML = "<font face='Verdana' size='1' color='#666666'></font>";
//            	divInsereResposta[w_count].innerHTML = "<br>&nbsp;&nbsp;<img border='0' src='../../imagens/indicator.gif'>"

		  	}
            if( xmlhttp[w_count].readyState == 4 )
            {             
   		     	var previneCache = new Date().getTime();
           		valorRetorno =unescape(xmlhttp[w_count].responseText.replace(/\+/g," "));
           		divInsereResposta[w_count].innerHTML=valorRetorno;
           		extraiScript(valorRetorno);
            }   
    }   
	xmlhttp[w_count].send( null );  
	if (w_focus != null)
	{
		//setTimeout("espera()", 500); 
	}
}  


function espera()
{
	//document.getElementById(w_foco).focus()
	w_foco = ""
}


function ajaxSalvaRegistro( nomeUrl, divRetorno , get_value, w_count )
{    
    divInsereResposta[w_count] = document.getElementById( divRetorno );   
       
    meuAjax(w_count);   
    xmlhttp[w_count].abort();   
    w_url_get[w_count] = nomeUrl + '?' + get_value
    
    
    w_url_get[w_count] = antiCacheRand(w_url_get[w_count])    
  
    
    
    
    //alert(w_url_get[w_count])
    
    
    
    xmlhttp[w_count].open("GET", w_url_get[w_count],true);   
       
    xmlhttp[w_count].setRequestHeader("Content-Type", "text/html; charset=iso-8859-1");   
    xmlhttp[w_count].onreadystatechange = function() 
    {   
            if  ( xmlhttp[w_count].readyState == 1) 
            { // Quando estiver carregando, exibe: carregando...
		  	divInsereResposta[w_count].innerHTML = "<font face='Verdana' size='1' color='#FF6600'></font>";
		  }
            if( xmlhttp[w_count].readyState == 4 )
            {             
			//if(xmlhttp[w_count].status == 200)
			//{
         		     
         		     var previneCache = new Date().getTime();


            		valorRetorno =unescape(xmlhttp[w_count].responseText.replace(/\+/g," "));
            		divInsereResposta[w_count].innerHTML=valorRetorno;
            		    
            		    
            		//alert(valorRetorno)
            		
            		
            		extraiScript(valorRetorno);
            	//}	
               
            }   
    }   
       
	xmlhttp[w_count].send( null );   
  
}   


function meuAjax(w_count)
{   
    try
    {   
        xmlhttp[w_count] = new XMLHttpRequest();   
    }catch(ee)
    {   
        try
        {   
            xmlhttp[w_count] = new ActiveXObject("Msxml2.XMLHTTP");   
        }
        catch(e)
        {   
            try
            {   
                xmlhttp[w_count] = new ActiveXObject("Microsoft.XMLHTTP");   
            }
            catch(E)
            {   
                xmlhttp[w_count] = false;   
            }   
        }   
    }   
} 


function extraiScript(texto){
//Maravilhosa função feita pelo SkyWalker.TO do imasters/forum
//http://forum.imasters.com.br/index.php?showtopic=165277&
    // inicializa o inicio ><
    var ini = 0;
    // loop enquanto achar um script
    while (ini!=-1){
        // procura uma tag de script
        ini = texto.indexOf('<script', ini);
        // se encontrar
        if (ini >=0)
        {
            // define o inicio para depois do fechamento dessa tag
            ini = texto.indexOf('>', ini) + 1;
            // procura o final do script
            var fim = texto.indexOf('</script>', ini);
            // extrai apenas o script
            codigo = texto.substring(ini,fim);
            // executa o script
            //eval(codigo);
            /**********************
            * Alterado por Micox - micoxjcg@yahoo.com.br
            * Alterei pois com o eval não executava funções.
            ***********************/
            novo = document.createElement("script")
            novo.text = codigo;
            
            
            //alert(novo.text)
            
            
            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 mostraBlocoProfissinais(w_idImg, w_idBloco, w_numBloco, w_qtdeRegistro) {

    
    if (document.getElementById(w_idImg).src.indexOf("maisMiniatura.gif") > 0) {
        var y;
        //Verifica se tem algum bloco aberto e fecha
        for (y = 1; y <= parseInt(w_qtdeRegistro); y++) {
            
            if (y != parseInt(w_numBloco)) {
                
                document.getElementById(w_idBloco + y).style.display = 'none'
                document.getElementById('imagem_' + y).src = "imagens/maisMiniatura.gif"
            }
        }
        document.getElementById(w_idImg).src = "imagens/menosMiniatura.gif"
        document.getElementById(w_idBloco + w_numBloco).style.display = "block";
        document.getElementById(w_idImg).scr = "menosMiniatura.gif"        
    }
    else {
        document.getElementById(w_idBloco + w_numBloco).style.display = 'none'
        document.getElementById(w_idImg).src = "imagens/maisMiniatura.gif"
    }
}
