function dc(fl)
{
  var x,y;
  if (self.innerHeight)
  {// all except Explorer
    x = self.innerWidth;
    y = self.innerHeight;
  }
  else 
  if (document.documentElement && document.documentElement.clientHeight)
  {// Explorer 6 Strict Mode
   x = document.documentElement.clientWidth;
   y = document.documentElement.clientHeight;
  }
  else
  if (document.body)
  {// other Explorers
   x = document.body.clientWidth;
   y = document.body.clientHeight;
  }

	var el=document.getElementById('loader');
	if(null!=el)
	{
		var top = (y/2) - 50;
		var left = (x/2) - 150;
		if( left<=0 ) left = 10;

		el.style.visibility = (fl==1)?'visible':'hidden';
		el.style.display = (fl==1)?'block':'none';
		el.style.left = left + "px"
		el.style.top = top + "px";
		el.style.zIndex = 50;
	}
}

function createCookie(name,value,days){
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

try{
	xmlhttp = new XMLHttpRequest();
}catch(ee){
	try{
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	}catch(e){
		try{
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}catch(E){
			xmlhttp = false;
		}
	}
}

try{
	xmlhttp2 = new XMLHttpRequest();
}catch(ee){
	try{
		xmlhttp2 = new ActiveXObject("Msxml2.XMLHTTP");
	}catch(e){
		try{
			xmlhttp2 = new ActiveXObject("Microsoft.XMLHTTP");
		}catch(E){
			xmlhttp2 = false;
		}
	}
}

fila=[];
ifila=0;

function ajaxHTML(id,url,id_pag,sessao,lingua){
	mostraWait();
//Adiciona à fila
	fila[fila.length]=[id,url,id_pag,sessao,lingua];
	//Se não há conexões pendentes, executa
	if((ifila+1)==fila.length)ajaxRun();
}

function ajaxRun(){
	//Abre a conexão
	xmlhttp.open("POST",fila[ifila][1],true);
	post = fila[ifila][2];
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8"); 
	//Função para tratamento do retorno
	xmlhttp.onreadystatechange=function() {
	if (xmlhttp.readyState==4){
		retorno=unescape(xmlhttp.responseText.replace(/\+/g," "))
		var r = document.getElementById(fila[ifila][0]).innerHTML=retorno
		var loading = document.getElementById('loading');
		
		if (fila[ifila][3] == 'Alt_destaques') {
			selCal(fila[ifila][4],'altAgenda','altag_display');
		}
		if(fila[ifila][3] == 'Rem_clientes'){
			selCase(fila[ifila][4],'excCase','exCasedisplay')	
		}
		if(fila[ifila][3] == 'Rem_destaques'){
			selCal(fila[ifila][4],'exCal','exCaldisplay');	
		}
		
		
		if(loading != null && loading.style.display == ""){
			setTimeout("hideMail('loading')",2000);	
		}
		//alert(retorno);
	//Roda o próximo
		ifila++
		if(ifila<fila.length)setTimeout("ajaxRun()",20)
		}else{
			 hideWait();
		}
	}
//Executa
xmlhttp.send(post);
}

function selFab(form,elem){
	xmlhttp.open("GET", "sel_fab.php", true);
	xmlhttp.onreadystatechange = function(){
		var campo_select = document.forms[form].elements[elem]; 
			if (xmlhttp.readyState == 4) {
				campo_select.options.length = 0;
				results = xmlhttp.responseText.split(",");
				total = results.length-1
				for(i = 0; i < total; i++ ){ 
					string = results[i].split( "|" );
					campo_select.options[i] = new Option( string[0], string[1] );
				}
			}
	}
    xmlhttp.send(null);
}

function pagina(form,acao){
	var form = document.forms[form];
	form.action = acao;
	form.submit();
}

function abr(){
	window.open("abre.htm",null,"height=500,width=300,status=yes,toolbar=no,menubar=no,location=no");	
}