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;
}

/**************************************************************************
Função para simular um Tab quando for pressionado a tecla Enter
Exemplo: onKeyDown="TABEnter()"
Funciona em TEXT BOX,RADIO BUTTON, CHECK BOX e menu DROP-DOWN
**************************************************************************/
function TABEnter(oEvent){
  var oEvent = (oEvent)? oEvent : event;
  var oTarget =(oEvent.target)? oEvent.target : oEvent.srcElement;
  if(oEvent.keyCode==13)
    oEvent.keyCode = 9;
  if(oTarget.type=="text" && oEvent.keyCode==13)
    //return false;
    oEvent.keyCode = 9;
  if (oTarget.type=="radio" && oEvent.keyCode==13)
    oEvent.keyCode = 9;
}

function cadastrar(){
var nome = document.getElementById('nome').value;
var email = document.getElementById('email').value;
z = ajaxInit();
temp = document.getElementById('cadastro').innerHTML;
j=0;
document.getElementById('cadastro').innerHTML='Verificando Base de Dados...';

z.open("GET", "comum/php/cadastro.php?nome="+ nome +"&email="+ email +"&acao=cadastrar", true);
	 

	if (z) {
    z.onreadystatechange = function() {
    if (z.readyState == 4 && z.status == 200) {
   	textoz=z.responseText;
	texto=unescape(textoz);

	if(texto=='ok'){
	document.getElementById('cadastro').innerHTML='Cadastro realizado com sucesso!!';
	window.setInterval("retorna_cadastro()", 1000);
	}
	else if(texto=='existe'){
	document.getElementById('cadastro').innerHTML='Este e-mail j&aacute; existe em nossa Base de Dados!!';
	window.setInterval("retorna_cadastro()", 1000);
	
		}
   else if(texto=='em_branco'){
	document.getElementById('cadastro').innerHTML='Campos Nome e/ou E-mail n&atilde;o podem ficar em branco!!';
	window.setInterval("retorna_cadastro()", 1000);
	
		}
   
   }
    }
	   z.send(null);
  }

}

function retorna_cadastro(){
	j=j+1;
	if(j==10){
		document.getElementById('cadastro').innerHTML=temp;
		document.getElementById('nome').value='nome';
		document.getElementById('email').value='e-mail';
}
}

function loadnoticias(categorias,subcat,local,numero){

z = ajaxInit();

document.getElementById(local).innerHTML='carregando...';

z.open("GET", "comum/php/noticias.php?categorias="+categorias+"&subcat="+subcat+"&limit="+numero, true);
	 

	if (z) {
    z.onreadystatechange = function() {
    if (z.readyState == 4 && z.status == 200) {
   	textoz=z.responseText;
	texto=unescape(textoz);
	
  document.getElementById(local).innerHTML=texto;
   
   }
    }
	   z.send(null);
  }

}

function loadnoticias_1(categorias,subcat,local,numero){

y = ajaxInit();

document.getElementById(local).innerHTML='carregando...';

y.open("GET", "comum/php/noticias.php?categorias="+categorias+"&subcat="+subcat+"&limit="+numero, true);
	 

	if (y) {
   y.onreadystatechange = function() {
    if (y.readyState == 4 && y.status == 200) {
   	textoz=y.responseText;
	texto=unescape(textoz);
	
  document.getElementById(local).innerHTML=texto;
   
   }
    }
	   y.send(null);
  }

}

function loadnoticias_2(categorias,subcat,local,numero){

x = ajaxInit();

document.getElementById(local).innerHTML='carregando...';

x.open("GET", "comum/php/noticias.php?categorias="+categorias+"&subcat="+subcat+"&limit="+numero, true);
	 
	if (x) {
    x.onreadystatechange = function() {
    if (x.readyState == 4 && x.status == 200) {
   	textoz=x.responseText;
	texto=unescape(textoz);
	
  document.getElementById(local).innerHTML=texto;
   
   }
    }
	   x.send(null);
  }

}
