$j = jQuery.noConflict();

project_root = "/usuario/elizabeth/";
function addLoadding(){

	var tmp = $('blackout');

	if(!tmp){

		var div = this.addTagId('blackout');

		if(!this.goodBrowser())

			div.style.position= 'absolute';

		else

			div.style.position	= 'fixed';

		div.style.top			= '0px';

		div.style.left			= '0px';

		div.style.width			= '100%';

		div.style.height		= '100%';

		div.style.color			= '#FFFFFF';

		div.style.zIndex		= '1000';

		div.style.background	= '#000000';

		this.transparent(div,"65");

	}

	/**/
	var txt = "<div class=\"divLoader\">";
	txt += "	<h3 class=\"h3Loader\">Carregando</h3>";
	txt += "	<center><img src=\""+project_root+"/images/loader.gif\" /></center>";
	txt += "</div>";
	var inner = this.addDivId ('loadding',null,txt);

	//var inner = this.addDivId ('loadding','blackout');

	if(!this.goodBrowser())

		inner.style.position= 'absolute';

	else

		inner.style.position= 'fixed';

	inner.style.top			= '44%';

	inner.style.left		= '44%';

	inner.style.width		= '100px';

	inner.style.height		= '20px';

	inner.style.color		= '#FFFFFF';

	inner.style.fontWeight	= '900';

	inner.style.zIndex		= '1100';

	/**/
	document.body.appendChild(inner);
}



function addBlackout(){

	var tmp = $('blackout');

	if(!tmp){

		var div = this.addTagId('blackout');

		if(!this.goodBrowser())

			div.style.position= 'absolute';

		else

			div.style.position	= 'fixed';

		div.style.top			= '0px';

		div.style.left			= '0px';

		div.style.width			= '100%';

		div.style.height		= '100%';

		div.style.color			= '#FFFFFF';

		div.style.zIndex		= '1000';

		div.style.background	= '#000000';

		

		this.transparent(div,"65");

		
/*
		var inner = this.addDivId ('loadding','blackout','');

		if(!this.goodBrowser())

			inner.style.position= 'absolute';

		else

			inner.style.position= 'fixed';

		inner.style.top			= '10%';

		inner.style.left		= '10%';

		inner.style.width		= '800px';

		inner.style.height		= '60px';

		inner.style.color		= '#FFFFFF';

		inner.style.fontWeight	= '900';

		inner.style.zIndex		= '1010';
*/

	}

}



function removeLoadding(){

	this.removeTagId('loadding');

	this.removeTagId('blackout');

}



function addTagId(id,str){

	var tag = document.getElementsByTagName("body")[0];

	if(tag!=null){

		var div = document.createElement("div");

		div.setAttribute('id',id);

	

		var corpo = "";

		if(str!=null)

			corpo = str;

			

		removeTagId(id);

		div.innerHTML = corpo;

		tag.appendChild(div);

		

		return div;

	}

	return null;

}

function removeTagId(id){

	var div = document.getElementById(id);	

	if (div != null)

		div.parentNode.removeChild(div);



	return true;

}

function addDivId (id,localTag,str,classe){

	var div = document.createElement("div");

	div.setAttribute('id',id);

	if(classe != null)

		div.setAttribute("class", classe);



	var corpo = "";

	if(str!=null)

		corpo = str;

		

	removeTagId(id);

	div.innerHTML = corpo;

	

	if(localTag!=null){

		tag = document.getElementById(localTag);

		tag.appendChild(div);

	}

	return div;

}

function my_contato(txt){
	if(txt){
		var contact = document.getElementById("contato");
		if(contact == null){
			
			var blackout = document.createElement("div");
			blackout.setAttribute("id","blackout");
			
			if(!this.goodBrowser())
				blackout.style.position= 'absolute';
			else
				blackout.style.position	= 'fixed';

			blackout.style.top			= '0px';
			blackout.style.left			= '0px';
			blackout.style.width		= '100%';
			blackout.style.height		= '100%';
			blackout.style.color		= '#FFFFFF';
			blackout.style.zIndex		= '1000';
			blackout.style.background	= '#000000';
			this.transparent(blackout,"65");
			
			topo = document.createElement("div");
			topo.setAttribute("id","contatoTopo");
			topo.innerHTML = "Contato";
			
			divTxt = document.createElement("div");
			divTxt.setAttribute("id","contatoTxt");
			divTxt.innerHTML = txt;
			
			input = document.createElement("input");
			input.setAttribute("id","contatoButton");
			input.setAttribute("value","Sair");
			input.setAttribute("type","button");
			input.setAttribute("onClick","removeTagId('contato');removeTagId('blackout');",0);
			
			div = document.createElement("div");
			div.setAttribute("id","contato");
			div.appendChild(topo);
			div.appendChild(divTxt);
			div.appendChild(input);
			
			document.body.appendChild(blackout);
			document.body.appendChild(div);
		}
	}
}
function removeTagId(id){
	var div = document.getElementById(id);	
	if (div != null)
		div.parentNode.removeChild(div);

	return true;
}
function transparent(div,opacity){
	try{
		div.style.filter 		= "alpha(opacity="+opacity+")";
		div.style.opacity 		= ""+(opacity/100);
		div.style.MosOpacity	= ""+(opacity/100);
		div.style.KhtmlOpacity	= ""+(opacity/100);
	}catch(Exception){}
}
function goodBrowser(){
	var versao = navigator.appVersion;
	var pos = versao.indexOf("MSIE");
	if(pos>=0){		
		var tmp = versao.substring(pos);
		tmp = tmp.replace("MSIE","");
		tmp = tmp.substring(0,tmp.indexOf(";"));
		tmp = parseInt(this.trim(tmp));
		if(tmp<7)
			return false;
	}
	return true;
}
function trim(str){
	return str.replace(/^\s+|\s+$/g,"");
}

function renderPage(url,id,_params){	
	var params = "";
	if(_params)
		params = _params;
	
	var myId = $(id);
	new Ajax.Updater(
		myId, 
		url, 
		 {
			evalScripts:true,
			metod: 'GET',
			parameters: params,
			onLoading:function(resp){addLoadding()},
			onComplete:function(resp){removeLoadding()}
		 }
	);
}

