// JavaScript Document
//*******************************
// DIV
//*******************************
/***************************************************************/
/* tem que ter isso em todas as paginas:
/* <div id="footer_div"></div>
/* antes da linha </body></html>
/***************************************************************/
function opnDivAjax(url,width,height,namediv) {
	var left = (screen.availWidth-width)/2;
	var top = (screen.availHeight-height)/2;
	var footerPageLeftTop = findPos($('footer_div'));
	var pageH = (footerPageLeftTop[1])+10; // pega a altura do footer div
	//var pageH = document.body.scrollHeight; // outro metodo
	var pageW = document.body.scrollWidth;

	
	if (pageH < screen.availHeight-height) {
		pageH = screen.availHeight-height;
	}

	if (document.getElementById("div_"+namediv) == null) {
		var p=document.createElement('div');
		var p2=document.createElement('div');
		var i=document.createElement('iframe');
		
		var transp = 70; // alpha
		/*--------------------------------------------------------------------------------------*/
		//i.src					= '';
		i.style.filter			= "progid:DXImageTransform.Microsoft.Alpha(opacity = "+transp+");";
		i.style.filter			= "alpha(opacity=" + transp + ")"; // For IE filter to work, obj MUST have layout
		i.style.KHTMLOpacity	= transp / 100; // Safari and Konqueror
		i.style.MozOpacity		= transp / 100; // Old Mozilla and Firefox
		i.style.opacity			= transp / 100; // CSS3 opacity for browsers that support it
		i.id					= "ifr_"+namediv;

		i.style.position		= 'absolute';
		i.style.margin			= 0 + 'px';

		if (navigator.appName == "Microsoft Internet Explorer"){
			i.style.width			= pageW + 'px'; //100 + '%';
		}
		i.style.height			= pageH + 'px';

		i.style.top				= 0 + 'px';
		i.style.left			= 0 + 'px';
		Element.hide(i);
		/*--------------------------------------------------------------------------------------*/
		document.body.appendChild(i);

		p2.style.filter			= "progid:DXImageTransform.Microsoft.Alpha(opacity = "+transp+");";
		p2.style.filter			= "alpha(opacity=" + transp + ")"; // For IE filter to work, obj MUST have layout
		p2.style.KHTMLOpacity	= transp / 100; // Safari and Konqueror
		p2.style.MozOpacity		= transp / 100; // Old Mozilla and Firefox
		p2.style.opacity		= transp / 100; // CSS3 opacity for browsers that support it
		p2.id					= "div2_"+namediv;
		p2.style.position		= 'absolute';
		p2.style.top			= 0 + 'px';
		p2.style.left			= 0 + 'px';
		p2.style.width			= pageW + 'px'; //100 + '%';
		p2.style.height			= pageH + 'px';
		
		document.body.appendChild(p2);
		
		p.id				= "div_"+namediv;
		p.style.position	= 'absolute';
		p.style.top			= top + 'px';
		p.style.left		= left + 'px';
		p.style.width		= width + 'px';
		p.style.height		= height + 'px';
		p.style.zindex		= '200';
		
		document.body.appendChild(p);
		
	}
	else {
		p2 = document.getElementById("div2_"+namediv);
		p2.style.width			= pageW + 'px'; //100 + '%';
		p2.style.height			= pageH + 'px';
		
		p = document.getElementById("div_"+namediv);
		p.style.width		= width + 'px';
		p.style.height		= height + 'px';
		
		i = document.getElementById("ifr_"+namediv);
		if (navigator.appName == "Microsoft Internet Explorer"){
			i.style.width			= pageW + 'px'; //100 + '%';
		}
		i.style.height			= pageH + 'px';
	}
	


	// mostra
	p2.style.display = "block";
	p.style.display = "block";
	i.style.display = "block";

	// coloca camada em profundiade 10
	p2.style.zIndex = "10";
	p2.style.background ='#FFFFFF';
	
	// coloca conteudo em profundiade 11
	p.style.zIndex = "11";
	//p.style.background ='#FFFFFF';
	

	//p.innerHTML = "<div id=''></div>";
	//Loader(url,"div_"+namediv);
	PostWithPrototype(url, "", "div_"+namediv, "get");
}

function CloseDivAjax(namediv) {
	if (document.getElementById("div_"+namediv) == null) {
	}
	else {
		p2 = document.getElementById("div2_"+namediv);
		p = document.getElementById("div_"+namediv);
		i = document.getElementById("ifr_"+namediv);
		p2.style.display = "none";
		p.style.display = "none";
		i.style.display = "none";
		
		p.innerHTML = "";
	}
}

function ShowHideDiv(id) {
	f = document.getElementById(id);
	if (f.style.display == "none") {
		f.style.display = "block";
	}
	else {
		f.style.display = "none";
	}
}

function ShowDiv(id) {
	f = document.getElementById(id);
	f.style.display = "block";
}

function HideDiv(id) {
	f = document.getElementById(id);
	f.style.display = "none";
}
// position de um div ou objeto
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}


// prototype
function Loader(url,div) {
	new Ajax.Updater(div, url, {
		encoding: 'UTF-8'
	});
}

function LoaderJS(url,div) {
	new Ajax.Updater(div, url, {
		encoding: 'UTF-8',
		evalScripts: true
	});
}

function PostWithPrototype(url, values, div, method) {
	if (method==undefined) {
		method = "post";
	}

	new Ajax.Request(url, { 
		onSuccess : function(resp) { 
			//alert("The response from the server is: " + resp.responseText); 
			Element.update(div, resp.responseText);
		}, 
		onFailure : function(resp) { 
			alert("Oops, there's been an error."); 
		}, 
		parameters : values,
		method: method,
		encoding: 'UTF-8' 
	});
}
