var divInsereResposta = new Array(30)
var w_url_get = 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) 
            { // Quando estiver carregando, exibe: carregando...
		  	divInsereResposta[w_count].innerHTML = "<font face='Verdana' size='1' color='#666666'>Carregando...</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 ajaxPost( 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("POST", 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='#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 );   
}   



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 TrocaConteudo(p1,p2,p3, p4)
{
	if (document.getElementById(p1 + 'ID').value == 1)
	{

		document.getElementById(p4).src = "img/icone_retornar.gif"  
		document.getElementById(p4).alt = "retornar"
		w_filtro = "label=" + p1 + "&id=" + p2
		ajaxGet('pag_complemento.asp', p3 , w_filtro, 1)		
		document.getElementById(p1+ 'ID').value = 0
	}
	else
	{
		document.getElementById(p4).src = "img/icone_adicionar.gif"  
		document.getElementById(p3 + 'TD').innerHTML = "<div align='center' id=" + p3 + "></div>"
		document.getElementById(p1 + 'ID').value = 1
		document.getElementById(p4).alt = "adicionar"
	}
}

/*
		document.getElementById("atualiza_div").style.visibility = 'visible'
		w_filtro = "cdiOcorre_int=" + document.getElementById("jsMan4_cdiOcorre_int").value
		w_filtro = w_filtro + "&cdiSS_int=" + document.getElementById("jsMan4_cdiSS_int").value		
		w_filtro = w_filtro + "&dtrOcorre_dte=" + document.getElementById("jsMan4_dtrOcorre_dte").value
		w_filtro = w_filtro + "&tpeOcorre_str=" + document.getElementById("jsMan4_tpeOcorre_str").value
		w_filtro = w_filtro + "&txgOcorre_str=" + document.getElementById("jsMan4_txgOcorre_str").value
		w_filtro = w_filtro + "&enmOcorre_str=" + document.getElementById("jsMan4_enmOcorre_str").value
		w_filtro = w_filtro + "&tpAcao_obj=Gravar"
		ajaxPost('../../k/c/kcOcorre_pgg.asp', 'atualiza_id' , w_filtro)

*/

function carregacid(p1,p2)
{
	w_filtro = "uf=" + p1 + "&cidade=" + p2
	ajaxGet('pag_cbocidades.asp', 'cidadeTD' , w_filtro, 1)

}
function carregauf(p1,p2)
{
	w_filtro = "tp=" + p1 + "&uf=" + p2
	ajaxGet('pag_cboufs.asp', 'ufTD' , w_filtro, 1)

}

function carregaassoc(p1,p2)
{
	w_filtro = "cidade=" + p1 + "&ida=" + p2
	ajaxGet('pag_cboassociados.asp', 'associadoTD' , w_filtro, 1)

}

function TrocaFoto(p1,p2)
{
	w_filtro = "idi=" + p1 + "&idg=" + p2
	ajaxGet('imagens.asp', 'galeriaimg' , w_filtro, 1)

}
function CarregaFoto(p1,p2)
{
	w_filtro = "idi=" + p1 + "&idg=" + p2
	ajaxGet('mainimg.asp', 'imagem' , w_filtro, 1)

}

function TrocaVideo(p1,p2)
{
	w_filtro = "idv=" + p1 + "&idg=" + p2
	ajaxGet('mainvideo.asp', 'video' , w_filtro, 1)

}
function TrocaCampanha(p1,p2)
{
	w_filtro = "idv=" + p1 + "&idg=" + p2
	ajaxGet('maincampanha.asp', 'video' , w_filtro, 1)

}