// JavaScript Document

/***********************************************
* Dynamic Ajax Content- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

function toggle_visibility(id) {
   var e = document.getElementById(id);
   if(e.style.display == 'block')
	  e.style.display = 'none';
   else
	  e.style.display = 'block';
}

var bustcachevar=1 //bust potential caching of external pages after initial request? (1=yes, 0=no)
var loadedobjects=""
var rootdomain="http://"+window.location.hostname
var bustcacheparameter=""
var containerid="include"


function incluir(url){
	par = url
	url = "php/include.php?opc="+par
	var page_request = false
	if (window.XMLHttpRequest) // if Mozilla, Safari etc
		page_request = new XMLHttpRequest()
	else if (window.ActiveXObject){ // if IE
		try {
		page_request = new ActiveXObject("Msxml2.XMLHTTP")
		} 
		catch (e){
			try{
			page_request = new ActiveXObject("Microsoft.XMLHTTP")
			}
			catch (e){}
			}
	}
	else
		return false
	page_request.onreadystatechange=function(){
	loadpage(page_request, containerid)
	}
	if (bustcachevar) //if bust caching of external page
		//bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
	page_request.open('POST', url+bustcacheparameter, true)
	page_request.send(null)
}
/*
function incluiCAT(div,url,par){
	msg = new Ajax.Updater(div,"php/"+url+".php",{
	asynchronous: true,
	method		: 'POST',
	onLoading	: loading2(div),
	parameters	: 'opc='+url+'&id='+par
	})
}
*/
function incluiCAT(div,url,par){
	url = "php/"+url+".php?opc="+url+"&id="+par
	var page_request = false
	if (window.XMLHttpRequest) // if Mozilla, Safari etc
		page_request = new XMLHttpRequest()
	else if (window.ActiveXObject){ // if IE
		try {
		page_request = new ActiveXObject("Msxml2.XMLHTTP")
		} 
		catch (e){
			try{
			page_request = new ActiveXObject("Microsoft.XMLHTTP")
			}
			catch (e){}
			}
	}
	else
		return false
	page_request.onreadystatechange=function(){
	loadpage(page_request, div)
	}
	if (bustcachevar) //if bust caching of external page
		//bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
	page_request.open('POST', url, true)
	page_request.send(null)
}

function loadpage(page_request, containerid){
	if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
	document.getElementById(containerid).innerHTML=page_request.responseText
}

/*
function incluir(url){
	lnk = new Ajax.Updater("include","php/include.php",{
	asynchronous: true,
	method		: 'POST',
	onLoading	: loading(),
	parameters	: 'opc='+url
	})
}
*/
function incluirDIV(div,url){
	msg = new Ajax.Updater(div,url,{
	asynchronous: true,
	method		: 'POST',
	onLoading	: loading2(div),
	parameters	: 'opc='+url
	})
}
function incluirMSG(div,url,par){
	msg = new Ajax.Updater(div,url,{
	asynchronous: true,
	method		: 'POST',
	onLoading	: loading2(div),
	parameters	: par
	})
}

function requestId(url,prm){
	url = "php/include.php?opc="+url+"&id="+prm
	var page_request = false
	if (window.XMLHttpRequest) // if Mozilla, Safari etc
		page_request = new XMLHttpRequest()
	else if (window.ActiveXObject){ // if IE
		try {
		page_request = new ActiveXObject("Msxml2.XMLHTTP")
		} 
		catch (e){
			try{
			page_request = new ActiveXObject("Microsoft.XMLHTTP")
			}
			catch (e){}
			}
	}
	else
		return false
	page_request.onreadystatechange=function(){
	loadpage(page_request, containerid)
	}
	if (bustcachevar) //if bust caching of external page
		//bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
	page_request.open('POST', url+bustcacheparameter, true)
	page_request.send(null)
}

/*function requestId(url,prm){
	lnk = new Ajax.Updater("include","php/include.php",{
	asynchronous: true,
	method		: 'POST',
	onLoading	: loading(),
	parameters	: 'opc='+url+'&id='+prm
	})
}*/
function query(url,prm){
	lnk = new Ajax.Updater("resulta",url,{
	asynchronous: true,
	method		: 'POST',
	parameters	: prm
	})
}
/*
function requisita(url,prm){
	lnk = new Ajax.Updater("include",url,{
	asynchronous: true,
	method		: 'POST',
	parameters	: prm
	})
}
*/
function requisita(url,par){
	div = "include"
	url = url+"?"+par
	var page_request = true
	if (window.XMLHttpRequest) // if Mozilla, Safari etc
		page_request = new XMLHttpRequest()
	else if (window.ActiveXObject){ // if IE
		try {
		page_request = new ActiveXObject("Msxml2.XMLHTTP")
		} 
		catch (e){
			try{
			page_request = new ActiveXObject("Microsoft.XMLHTTP")
			}
			catch (e){}
			}
	}
	else
		return false
	page_request.onreadystatechange=function(){
	loadpage(page_request, div)
	}
	if (bustcachevar) //if bust caching of external page
		//bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
	page_request.open('GET', url, true)
	page_request.send(null)
}

function request(url,param){
	requ = new Ajax.Request(url,{
	asynchronous: true,
	encoding    : 'UTF-8',
	method		: 'POST',
	onLoading	: loading(),
	onComplete  : function carrega() {
	document.getElementById('include').innerHTML = requ.transport.responseText;
	},
	onFailure   : function erro() {
	document.getElementById('include').innerHTML = 'Atenção ocorreu um erro ao carregar a página!';
	},
	postBody	: param
	})
}

function loading2(dv) {
	document.getElementById(dv).innerHTML = '<br><br><br><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="61.75" height="74.05"><param name="movie" value="../flash/carga.swf" /><param name="wmode" value="transparent" /><param name="quality" value="high" /><embed src="../flash/carga.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="61" height="74" wmode="transparent"></embed></object>';
}

function loading() {
	document.getElementById('include').innerHTML = '<br><br><br><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="61.75" height="74.05"><param name="movie" value="../flash/carga.swf" /><param name="wmode" value="transparent" /><param name="quality" value="high" /><embed src="../flash/carga.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="61" height="74" wmode="transparent"></embed></object>';
}
function url_encode(str) {  
	var hex_chars = "0123456789ABCDEF";  
	var noEncode = /^([a-zA-Z0-9\_\-\.])$/;  
	var n, strCode, hex1, hex2, strEncode = "";  

	for(n = 0; n < str.length; n++) {  
		if (noEncode.test(str.charAt(n))) {  
			strEncode += str.charAt(n);  
		} else {  
			strCode = str.charCodeAt(n);  
			hex1 = hex_chars.charAt(Math.floor(strCode / 16));  
			hex2 = hex_chars.charAt(strCode % 16);  
			strEncode += "%" + (hex1 + hex2);  
		}  
	}  
	return strEncode;  
}  

// url_decode version 1.0  
function url_decode(str) {
	var n, strCode, strDecode = "";

	for (n = 0; n < str.length; n++) {
		if (str.charAt(n) == "%") {
			strCode = str.charAt(n + 1) + str.charAt(n + 2);
			strDecode += String.fromCharCode(parseInt(strCode, 16));
			n += 2;
		} else {
			strDecode += str.charAt(n);
		}
	}

	return strDecode;
}

function reloadBanner()
{
	document.getElementById("LinkBanner1").reload;
	document.getElementById("LinkBanner2").reload;
	document.getElementById("LinkBanner3").reload;
	setInterval('reloadBanner()',10000);
}

function sortearImg(imgs){
	var imagens = new Array(imgs);
	//alert(imagens);
	var num = Math.floor(Math.random()*2);
	var img = Math.round(num);
	//alert(imagens[img]);
	document.images["ImgLogo"].src = imagens[img];
	window.setTimeout("sortearImg(\"" + imagens + "\")",10000);
}
function photoslide(a, btn) {
	var img = a.getElementsByTagName("img"), def = {
		background: "",
		color: "#A8A8A8",
		font: "bold 20px arial",
		textLeft: "<img src='../site/imagens/fleche1.png'/>",
		textRight: "<img src='../site/imagens/fleche2.png'/>",
		top: "75%",
		width: "38px"
	};

	if (btn)
		for (k in btn)
			def[k] = btn[k];

	if (!(wdt = parseInt(a.style.width.replace("px", "")))) {
		wdt = img[0].width;
		a.style.width = wdt + "px";
	}
	if (!(hgt = parseInt(a.style.height.replace("px", "")))) {
		hgt = img[0].height;
		a.style.height = hgt + "px";
	}

	var twd = img.length * wdt;

	a.style.position = "relative";
	a.style.overflow = "hidden";

	for (var i=0; i < img.length; i++) {
		img[i].style.cssFloat = "left";
		img[i].style.width = wdt + "px";
	}

	// cointainer
	var c = document.createElement("div");
	c.style.position = "absolute";
	c.style.top = "0px";
	c.style.left = "0px";
	c.style.width = twd + "px";
	c.style.height = hgt + "px";
	c.innerHTML = a.innerHTML.replace(/\s+</g, "<").replace(/>\s+/, ">");
	a.innerHTML = "";
	a.appendChild(c);

	// controls
	var prv = document.createElement("div");
	var nex = document.createElement("div");
	prv.style.display = nex.style.display = "none";
	prv.style.position = nex.style.position = "absolute";
	prv.style.backgroundColor = nex.style.backgroundColor = def.background;
	prv.style.font = nex.style.font = def.font;
	prv.style.color = nex.style.color = def.color;
	prv.style.cursor = nex.style.cursor = "pointer";
	prv.style.width = nex.style.width = def.width;
	prv.style.top = nex.style.top = def.top;
	prv.style.left = "0px";
	nex.style.left = "100%";
	nex.style.marginLeft = "-" + def.width;
	prv.innerHTML = def.textLeft;
	nex.innerHTML = def.textRight;
	nex.style.textAlign = "right";

	prv.onclick = nex.onclick = function() {
		var tg = this.parentNode.getElementsByTagName("div")[0];
		var tm = wdt;
		var dr = this === nex ? -1 : 1;
		var m1 = wdt * .1;
		var m2 = m1 * dr;

		var intv = window.setInterval(function() {
			var lf = parseInt(tg.style.left.replace("px", ""));

			if (lf >= 0 && dr == 1 || (dr * lf) + wdt >= twd && dr == -1) {
				window.clearTimeout(intv);
				return;
			}

			tm -= m1;
			if (tm <= 0)
				window.clearTimeout(intv);
			tg.style.left = (lf + m2) + "px";
		}, 25);
	}

	a.appendChild(prv);
	a.appendChild(nex);

	a.onmouseover = a.onmouseout = function(ev) {
		var ev = ev || window.event;
		var dp = ev.type == "mouseout" ? "none" : "";
		var crl = this.getElementsByTagName("div");
		for (var i=1; i < crl.length; i++)
			crl[i].style.display = dp;
	}
}

function mostra(el) {

	$(el).setOpacity(0);
	$(el).setStyle({visibility: 'visible'});
	new Effect.Opacity(
	   el, { 
		  from: 0.0, 
		  to: 0.5,
		  duration: 1.0
	   }
	);

}
function esconde(el) {

	$(el).setOpacity(1.0);
	new Effect.Opacity(
	   el, { 
		  from: 1.0, 
		  to: 0.0,
		  duration: 1.0
	   }
	);
	$(el).setStyle({visibility: 'hidden'});

}
