var divInsereResposta = new Array(30)
var w_url_get = new Array(30)
var valorRetorno = new Array(30)
var xmlhttp = new Array(30)


function moveDstProduto()
{
	//document.getElementById("centralDiv").style.zIndex = 1
}

function abreSistema()
{
	//window.open('http://www.habeas.com.br/dataquim/default.asp?telaEnvio=site','','scrollbars=no width=787,height=600,top=0,left=0')	
	window.open("http://www.associquim.org.br/dataquim/login.asp")
}


function abreSiteTerceiro(w_site_str)
{
	//alert(w_site_str)
	window.open('http://' + w_site_str,'','') //scrollbars=no width=787,height=600,top=0,left=0')	
}


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])    
  
    
    
    
    //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='#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 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 abreTeste()
{
	w_filtro = "cdiitemSecao_int=0" 
	w_filtro = w_filtro + "&dstIdioma_str=" + document.getElementById("dstIdioma_str").value
	ajaxGet('teste.asp', 'idConteudo' , w_filtro, 1)
}


function abreDiretoria(w_cdiEntidade_int)
{
	w_filtro = "cdiEntidade_int=" + w_cdiEntidade_int + "&dstIdioma_str=" + document.getElementById("dstIdioma_str").value
	ajaxGet('qd/qdDiretoria_pgc.asp', 'idConteudo' , w_filtro, 1)
}


function abreDiretoriaLista(w_cdiEntidade_int)
{
	
	w_filtro = "cdiEntidade_int=" + w_cdiEntidade_int
	w_filtro = w_filtro + "&dstIdioma_str=" + document.getElementById("dstIdioma_str").value
	ajaxGet('qd/qdDiretoria_pgp.asp', 'idLista_pgp' , w_filtro, 1)
}

/*-------------------------------------------------------------------------------
Função usada para abrir apenas os itens que forem usar o menu comum, ou seja, 
aqueles que vierem do editor comum
*/
function abreMenuComum(w_cdiItemSecao_int)
{
	w_filtro = "cdiitemSecao_int=" + w_cdiItemSecao_int 
	w_filtro = w_filtro + "&dstIdioma_str=" + document.getElementById("dstIdioma_str").value
	ajaxGet('qc/qcPagina_pgc.asp', 'idConteudo' , w_filtro, 1)
}

function voltaHome()
{
	w_filtro = "cdiProduto_int=0" 
	w_filtro = w_filtro + "&dstIdioma_str=" + document.getElementById("dstIdioma_str").value
	ajaxGet('defaultConteudo.asp', 'idConteudo' , w_filtro, 1)	
}


function abreListaAssociados()
{
	w_filtro = "cdiEntidade_int=0"
	w_filtro = w_filtro + "&dstIdioma_str=" + document.getElementById("dstIdioma_str").value	
	ajaxGet('qe/qeListaAssociados_pgc.asp', 'idConteudo' , w_filtro, 1)
}

function abreListaProdutos(w_cdiItemSecao_int)
{
	w_filtro = "cdiitemSecao_int=" + w_cdiItemSecao_int
	w_filtro = w_filtro + "&dstIdioma_str=" + document.getElementById("dstIdioma_str").value	
	ajaxGet('qe/qeProdutos_pgc.asp', 'idConteudo' , w_filtro, 1)
}

function mudaCorLinha(w_nmLinha_str, w_bgColor)
{
	document.getElementById(w_nmLinha_str).bgColor = w_bgColor;
}

function abreResultadoDiv()
{
	document.getElementById("resultado_div").style.visibility = 'visible'
	document.getElementById("resultado1_div").style.visibility = 'visible'
}

function fechaResultadoDiv()
{
	document.getElementById("resultado_div").style.visibility = 'hidden'
	document.getElementById("resultado1_div").style.visibility = 'hidden'
}

function abreContato()
{
	w_filtro = "cdiPessoa_int=0"
	w_filtro = w_filtro + "&dstIdioma_str=" + document.getElementById("dstIdioma_str").value	
	ajaxGet('qt/qtContato_pgc.asp', 'idConteudo' , w_filtro, 1)
}

function abreAssociado(w_cdiPessoa_int, w_ingProduto_bol)
{
	if (w_ingProduto_bol == 1)
	{
		abreResultadoDiv()
		document.getElementById("resultado_div").innerHTML = ""
		w_filtro = "cdiPessoa_int=" + w_cdiPessoa_int
		w_filtro = w_filtro + "&dstIdioma_str=" + document.getElementById("dstIdioma_str").value
		ajaxGet('qe/qeAssociado_pgc.asp', 'conteudo1_div' , w_filtro, 1)
	}
}

function abreListaProduto_lay(w_value_str)
{
	MM_showHideLayers('qeProdutos_lay','','show')	
	w_filtro = "value_str=" + w_value_str 
	w_filtro = w_filtro + "&dstIdioma_str=" + document.getElementById("dstIdioma_str").value
	ajaxGet('qe/qeProdutos_pgx.asp', 'qeProdutos_lay' , w_filtro, 1)
}

function enviarMensagem()
{
	w_envia = true
	if (document.getElementById("nmcContato_str").value == "")
	{
		alert("O campo nome não pode estar vazio.")
		document.getElementById("nmcContato_str").focus()
		w_envia = false
	}
	else if (document.getElementById("dscEmail_str").value == "")
	{
		alert("O campo e-mail não pode estar vazio.")
		document.getElementById("dscEmail_str").focus()
		w_envia = false
	}
	else if (document.getElementById("dscAssunto_str").value == "")
	{
		alert("O campo assunto não pode estar vazio.")
		document.getElementById("dscAssunto_str").focus()
		w_envia = false
	}	
	else if (document.getElementById("dscTexto_str").value == "")
	{
		alert("O campo texto não pode estar vazio.")
		document.getElementById("dscTexto_str").focus()
		w_envia = false
	}
	if (w_envia == true)
	{	
		w_filtro = "nmcContato_str=" + document.getElementById("nmcContato_str").value 
		w_filtro = w_filtro + "&dscEmail_str=" + document.getElementById("dscEmail_str").value 
		w_filtro = w_filtro + "&dscAssunto_str=" + document.getElementById("dscAssunto_str").value 
		w_filtro = w_filtro + "&dscTexto_str=" + document.getElementById("dscTexto_str").value 
		ajaxGet('qt/qtContato_pgg.asp', 'idConteudo' , w_filtro, 1)
	}
}	

function abreProdir()
{
	window.open("http://www.associquim.com.br/publicador/adminconteudo/index.asp")
}
function returnValueProduto(w_dstProduto_str, w_cdiProduto_int)
{
	document.getElementById("dstProduto_str").value = w_dstProduto_str
	closeLayers()
	w_filtro = "cdiProduto_int=" + w_cdiProduto_int 
	w_filtro = w_filtro + "&dstIdioma_str=" + document.getElementById("dstIdioma_str").value	
	ajaxGet('qe/qeProdutos_pgp.asp', 'idLista_pgc' , w_filtro, 1)
}

function closeLayers()
{
	MM_showHideLayers('qeProdutos_lay','','hide')	
}

//************ VISUALIAR LAYER ********************************
function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; 
    }
}

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_findObjAtr(n,d.layers[i].document);
  	if(!x && d.getElementById)
  		x=d.getElementById(n); 
		return x;
}

//************ VISUALIAR LAYER ********************************
function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; 
    }
}

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_findObjAtr(n,d.layers[i].document);
  	if(!x && d.getElementById)
  		x=d.getElementById(n); 
		return x;
}

