function retornaAjax(data, target){	
	target = document.getElementById(target);
  //alert(data);
	target.innerHTML = data;

}

function callAjaxJQuery(divName, myValue, url, loadingClass){
	
	//alert ('callAjax('+divName+', '+myValue+', '+url+')');

  if (loadingClass==undefined)
    var loadingClass = '';

  $("#"+divName).html('<div class="'+loadingClass+'"><img src="./_img/loading.gif" /></div>');
	
	$.get(url+myValue, function(data){
			retornaAjax(data, divName);
		}
	);
	
}


function callAjaxAndReturnValue(url){
$.get(url, function(data){
			//alert(data);
			if  (data == "false")
				goAjax('geraCaptcha.asp', 'GET', 'true', 'captchaSpan', '')
				
				
		}
	);
}


function goAjax(url, metodo, modo, tagRetorno, parametros) {


        $('#'+tagRetorno).html('Aguarde...<br /><br />');
        
        var xmlhttp = false;
				/*
				if (window.XMLHttpRequest)
						req = new XMLHttpRequest();
				else
						req = new ActiveXObject("Microsoft.XMLHTTP");
				*/
				
				if (window.XMLHttpRequest) {    
					xmlhttp = new XMLHttpRequest();   
				}else if(window.ActiveXObject) {    
					try {     
						xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");    
					} catch (e) {
						try {
							xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");     
						} catch (e) {
							xmlhttp = false;
						}    
					}   
				} 				
				

        //document.getElementById(tagRetorno).innerHTML='<div align="center" class="carregando"><img src="../images/carregando.gif"><br /><br />carregando...</div>'

				
				// Verifica se coloca ? ou & na URL
				var concat;
				if (url.indexOf("?")!=-1){
					concat = "&";
				}else{
					concat = "?";
				}
				
				
            if(metodo == "GET") {
                xmlhttp.open("GET", url+concat+"nocache="+Math.random(), modo);
            } else {        
                xmlhttp.open("POST", url, modo);
                xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=iso-8859-1");
                xmlhttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
                xmlhttp.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
                xmlhttp.setRequestHeader("Pragma", "no-cache");
            }    
            
            xmlhttp.onreadystatechange = function() {
						
                if(xmlhttp.readyState == 4) {
                    retorno=xmlhttp.responseText
										//alert(retorno);
                    document.getElementById(tagRetorno).innerHTML=retorno
                    //findScript(retorno)
                }
            }
						
            if(metodo == "GET") {
                xmlhttp.send(null);
            } else {        
                xmlhttp.send(parametros);
            }
}

function goAjaxFinal(url, metodo, modo, tagRetorno, parametros) {


        var xmlhttp = false;
				/*
				if (window.XMLHttpRequest)
						req = new XMLHttpRequest();
				else
						req = new ActiveXObject("Microsoft.XMLHTTP");
				*/
				
				if (window.XMLHttpRequest) {    
					xmlhttp = new XMLHttpRequest();   
				}else if(window.ActiveXObject) {    
					try {     
						xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");    
					} catch (e) {
						try {
							xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");     
						} catch (e) {
							xmlhttp = false;
						}    
					}   
				} 				
				

        //document.getElementById(tagRetorno).innerHTML='<div align="center" class="carregando"><img src="../images/carregando.gif"><br /><br />carregando...</div>'

				
				// Verifica se coloca ? ou & na URL
				var concat;
				if (url.indexOf("?")!=-1){
					concat = "&";
				}else{
					concat = "?";
				}
				
				
            if(metodo == "GET") {
                xmlhttp.open("GET", url+concat+"nocache="+Math.random(), modo);
            } else {        
                xmlhttp.open("POST", url, modo);
                xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=iso-8859-1");
                xmlhttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
                xmlhttp.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
                xmlhttp.setRequestHeader("Pragma", "no-cache");
            }    
            
            xmlhttp.onreadystatechange = function() {
						
                if(xmlhttp.readyState == 4) {
                    retorno=xmlhttp.responseText
										//alert(retorno);
                    document.getElementById(tagRetorno).innerHTML=retorno
                    //findScript(retorno)
										
										validaForm();
                }
            }
						
            if(metodo == "GET") {
                xmlhttp.send(null);
            } else {        
                xmlhttp.send(parametros);
            }
}

