//create a XMLHttpRequest object
function ajax_request(){
	
	var req = false;
	try { req = new XMLHttpRequest(); }
	catch (e) {
		try { req = new ActiveXObject("Msxml2.XMLHTTP"); }
		catch (e) {
			try { req = new ActiveXObject("Microsoft.XMLHTTP"); }
			catch (e) { req = false; }
		}
	}
	if (!req) {
		alert('O seu navegador está desatualizado e não possui suporte à tecnologia Ajax.\nPor favor, atualize seu browser. (http://www.getfirefox.com/)');
		return;
	}
	return req;
}

function showHide (elem){
	//alert(elem.style.display);
	if (elem.style.display == 'none' || elem.style.display == '') {
		elem.style.display = 'block' ;
		return true ;
	}
	else {
		elem.style.display = 'none' ;
		return false ;
	}
}

function Hide (elem, clean){
	elem.style.display = 'none' ;
	if (clean) elem.innerHTML = "" ;
}

function Show (elem){
	elem.style.display = 'block' ;
}



function setLoading(container){

	var img = document.createElement("img");
	img.src = "" ;
	
	
	container.innerHTML = "<center>carregando...<img src='/EAD/imgs/loading.gif' />" ;
	container.innerHTML += "</center>"
	
}

function HTMLDecode(encodedstring){
	var tmp = encodedstring;
	tmp = tmp.replace(/&quot;/ig, String.fromCharCode(34));
	tmp = tmp.replace(/&lt;/ig  , String.fromCharCode(60));
	tmp = tmp.replace(/&gt;/ig  , String.fromCharCode(62));
	tmp = tmp.replace(/&amp;/ig , String.fromCharCode(38));
	tmp = tmp.replace(/&nbsp;/ig, String.fromCharCode(32));
	for (var i=1; i<=255; i++){
		strTexto = new RegExp("&#" + i + ";","ig");
		tmp = tmp.replace(strTexto, String.fromCharCode(i));
	}
	return tmp;
}
function setRequestHeader(req){
	req.setRequestHeader('Content-Type',"application/x-www-form-urlencoded");
	req.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
	req.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
	req.setRequestHeader("Pragma", "no-cache");
	return req ;
}

function showDebug (content){
	
	if (document.getElementById("debug"))
		var debug = document.getElementById("debug") ;
	else{
		var debug = document.createElement("div");
		debug.id = 'debug';
	}
	
	debug.innerHTML = content ;
	
	document.body.appendChild(debug);
	
}