function ajaxInit() {
  var req;
  try {
    req = new ActiveXObject("Microsoft.XMLHTTP");
  } catch(e) {
      try {
        req = new ActiveXObject("Msxml2.XMLHTTP");
      } catch(ex) {
          try {
            req = new XMLHttpRequest();
          } catch(exc) {
              alert("Esse browser não tem recursos para uso do Ajax");
              req = null;
            }
        }
    }
 return req;
}

function ajaxpost(url, campos, idinfo){
  ajax = ajaxInit();
	ajax.open("POST", url+'?'+Math.ceil(Math.random()*100000), true);
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8?");
	if (idinfo!=''){
    document.getElementById(idinfo).style.display='';
  	ajax.onreadystatechange = function (){
  	  if (ajax.readyState == 4) {
        if (ajax.status == 200) {
  			  document.getElementById(idinfo).style.display='none';
					if(ajax.responseText.length>0){
					  alert(ajax.responseText);
						document.getElementById(idinfo).style.display='none';
						if (ajax.responseText.indexOf('Obrigado')>-1){
						  document.form_comentarios.reset(); 
						}
					}
        }
      }
		}
	}
	ajax.send(campos);
}


//Pega todos os campos de um formulário e monta numa string
function mandaform(formname){
  var formulario = document.getElementById("formname"); 
  var tamanho = formulario.elements.length; 
  var conteudoformulario = "";
  var sepcampos;
  sepcampos = "";
  for (var i=0; i <= formulario.elements.length-1;i++) { 
    conteudoformulario += sepcampos+formulario.elements[i].name+'='+(formulario.elements[i].value); 
    sepcampos="&";
  }
	return conteudoformulario;
}

function ajaxget(arqdados,iddestino) {
 texto = '';
 if(iddestino){
   document.getElementById(iddestino).innerHTML = "Carregando...";
 }
 ajax = ajaxInit();
 if(ajax) {
   ajax.open("GET", arqdados, true);
   ajax.onreadystatechange = function() {
     if(ajax.readyState == 4) {
       if(ajax.status == 200) {
			   if(iddestino){
           document.getElementById(iddestino).innerHTML = ajax.responseText;
				 }else{
					 texto = ajax.responseText;
				 }
       } else {
         alert(ajax.statusText);
       }
     }
   }
   ajax.send(null);
	 return texto;
 }
}


//Funções abaixo usar somente com a funcao digigacao, pois é síncrona =======================================
function getBrowser() {  
  var XMLHttpRequestObject = false;  
  if(window.XMLHttpRequest) {  
    XMLHttpRequestObject = new XMLHttpRequest();  
  } else if(window.ActiveXObject) {  
      XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");  
    }  
    return XMLHttpRequestObject;  
}  
 
function ajaxgetdigitacao(data) {  
xmlHttp = getBrowser();  
xmlHttp.open("GET", data, false);  
xmlHttp.send(null);  
return xmlHttp.responseText;  
}

function selecionatexto(obj,texto,seq){
	objeto = obj;
	var sequencia = seq
	objeto.innerHTML = texto;
}



elementos = 0;
tammarquee = 475;
function marquee(obj){
	document.getElementById('ultima').style.left = 875;
	//document.getElementById('ultima').style.left = 300;
  var texto = ajaxgetdigitacao('../ajaxsources/ultima.asp?&'+Math.ceil(Math.random()*100000),'');  //O random eh pra naum pegar cache
  objeto = document.getElementById(obj);
	objeto.innerHTML = texto;
	if (texto.indexOf('Publicidade')>0){
	  elementos = 6;
	}else{
	  elementos = 5;
	}
	testy();
}

function testy(){
  obj = document.getElementById('ultima');
  if(parseInt(obj.style.left)*-1<tammarquee*elementos){ 
    obj.style.left=parseInt(obj.style.left)-2;
		setTimeout(function(){
		  testy()
		},30);
	}else{
	  marquee(obj.id);
	}
}
//==========================================================================