/**
 * Insere o conteudo dentro de um div, utilizando pre-loader para o usuário ver
 * que o conteúdo esta sendo carregado
 *
 */

function ajax(url, divzinho, action) 
{
	div = divzinho;
	
	if (document.getElementById(div).style.display == "none")
	{
		document.getElementById(div).style.display = "";
	}
		
	var newImg=document.createElement('img');
	
	if(action) 
	{
		switch(action)
		{
			case 'option' : 
				document.getElementById(div).innerHTML='<select><option>CARREGANDO...</option></select>';
			break;
			case 'hotel'  :
				document.getElementById(div).innerHTML='<div style="width:800px; border:1px solid #c3c1b4; float:left; margin:0 10px 10px 0;"><div style="padding:5px; font-size:14px;">Aguarde. Carregando...</div></div>';
			break;
		}
	}
	
	//newImg.setAttribute('src','tema/imagens/carregando.gif');
	//newImg.setAttribute('id', 'preloader');
	//document.getElementById(div).appendChild(newImg);
	
	//document.getElementById('loader_ajax').style.display = '';
	//document.getElementById('loader_ajax').innerHTML = 'Carregando...';

	req = null;
	if (window.XMLHttpRequest) 
	{

		req = new XMLHttpRequest();
		req.onreadystatechange = processReqChange;
		req.open("GET", url, true);
		req.send(null);

	} 
	else if (window.ActiveXObject) 
	{
		req = new ActiveXObject("Microsoft.XMLHTTP");
		if (req) 
		{
			req.onreadystatechange = processReqChange;
			req.open("GET", url, true);
			req.send(null);
		}
	}
}

function processReqChange() 
{
	if (req.readyState == 4) 
	{
		if (req.status == 200) 
		{
			document.getElementById(div).innerHTML = req.responseText;
			//document.getElementById('loader_ajax').style.display = 'none';
		} 
		/*else 
		{
			alert("Nenhum dado encontrado.");
		}*/
	}
}

/**********************************************************************************************/

