/*************OPACIDADE****************************/
/*
w3Opacity (1.0) - 15/01/2007
Por Leandro Vieira Pinho - http://leandro.w3invent.com.br

Para informações sobre o w3Opacity viste:
http://leandro.w3invent.com.br/labs/

Dúvidas, sugestões, bugs?
http://leandro.w3invent.com.br/labs/forum
*/
var w3Opacity = {
	/**
	* Método que realiza o fadeOut e fadeIn
	* @param strObjId {string} - Nome do atributo ID do objeto que receberá o efeito
	* @param intOpacityStart {number} - Número inicial para o efeito
	* @param intOpacityEnd {number} - Número final para o efeito
	* @param intMillisecond {number} - Número (em milisegundos) para o tempo de duração do efeito
	* @param fnOnFinish {} - Função a ser chamada quando o efeito terminar
	* Exemplos:
	* Não chamar uma função ao terminar o efeito: w3Opacity.fading("obj_id",0,100,400);
	* Chamar uma função ao terminar o efeito: w3Opacity.fading("obj_id",100,0,400,nome_da_funcao);
	*/
	fading: function(strObjId,intOpacityStart,intOpacityEnd,intMillisecond,fnOnFinish) {
		var intSpeed = Math.round(intMillisecond / 100);
		var intTimer = 0;
		// Processo para o FadeOut
		if ( intOpacityStart > intOpacityEnd ) {
			for ( i = intOpacityStart; i >= intOpacityEnd; i-- ) {
				if ( intTimer == 100 && typeof(fnOnFinish) != "undefined" ) {
					setTimeout("w3Opacity.change_opacity('" + strObjId + "'," + i +"," + fnOnFinish + ")",(intTimer * intSpeed));
				} else {
					setTimeout("w3Opacity.change_opacity('" + strObjId + "'," + i +")",(intTimer * intSpeed));
				}
				intTimer++;
			}
			// Processo para o FadeIn
		} else if ( intOpacityStart < intOpacityEnd ) {
			for ( i = intOpacityStart; i <= intOpacityEnd; i++ ) {
				if ( intTimer == 100 && typeof(fnOnFinish) != "undefined" ) {
					setTimeout("w3Opacity.change_opacity('" + strObjId + "'," + i +"," + fnOnFinish + ")",(intTimer * intSpeed));
				} else {
					setTimeout("w3Opacity.change_opacity('" + strObjId + "'," + i +")",(intTimer * intSpeed));
				}
				intTimer++;
			}
		}
	},
	/**
	* Método que verifica a opacidade do objeto e realiza um fadeOut ou fadeIn :)
	* @param strObjId {string} - Nome do atributo ID do objeto que receberá o efeito
	* @param intMillisecond {number} - Número (em milisegundos) para o tempo de duração do efeito
	* Exemplos:
	* w3Opacity.toggle("obj_id",400);
	*/
	toggle: function(strObjId,intMillisecond) {
		if ( this.get_opacity(strObjId) < 1 ) {
			// fadeIn
			this.fading(strObjId,0,101,intMillisecond);
		} else {
			// fadeOut
			this.fading(strObjId,101,0,intMillisecond);
		}
	},
	/**
	* Método que define uma opacidade para o objeto
	* @param strObjId {string} - Nome do atributo ID do objeto que receberá o efeito
	* @param intOpacity {number} - Número inteiro que será o valor da opacidade
	*/
	set: function(strObjId,intOpacity) {
		this.change_opacity(strObjId,intOpacity);
	},
	/**
	* Método interno, utilizado para alterar a opacidade do objeto
	*/
	change_opacity: function(strObjId,intOpacity,hasFnOnFinish) {
		if (typeof(hasFnOnFinish) != "undefined") {
			hasFnOnFinish();
		}
		var objStyle = this.$(strObjId).style;
		objStyle.opacity = (intOpacity / 101);
		objStyle.MozOpacity = (intOpacity / 101);
		objStyle.KhtmlOpacity = (intOpacity / 101);
		objStyle.filter = "alpha(opacity=" + intOpacity + ")";
	},
	$: function(strObjId) {
		return document.getElementById(strObjId);
	},
	get_style: function(strObjId,strStyleProperty) {
		var objToGetStyle = this.$(strObjId), styleValue;
		// Para o Internet Explorer
		if ( objToGetStyle.currentStyle ) {
			styleValue = objToGetStyle.currentStyle[strStyleProperty];
			// Para o Firefox, Opera, ...
		} else if ( window.getComputedStyle ) {
			styleValue = document.defaultView.getComputedStyle(objToGetStyle,null).getPropertyValue(strStyleProperty);
		}
		return styleValue;
	},
	get_opacity: function(strObjId) {
		var opacity;
		if ( opacity = this.get_style(strObjId,'opacity') ) {
			return parseFloat(opacity);
		}
		if ( opacity = (this.get_style(strObjId,'filter') || '').match(/alpha\(opacity=(.*)\)/) ) {
			if ( opacity[1] ) {
				return parseFloat(opacity[1]) / 100;
			} else {
				return 1.0;
			}
			// Caso não seja aplicado ao objeto um filter... será retornado undefined. Então, considero como o objeto está visível: 100
		} else {
			return 1.0;
		}
	}
};
/*************OPACIDADE[FIM]***********************/



/***************************************************/

var bustcachevar=1 //bust potential caching of external pages after initial request? (1=yes, 0=no)
var loadstatustext="<table width=\"100%\" height=\"100%\" align=\"center\"><tr><td><center><img src='../imagens/loading.gif' /><br><br></td></tr></table>"
var loadstatustext3="<table width=\"100%\" height=\"100%\" align=\"center\"><tr><td><center><img src='imagens/hip_load.gif' /><br><br></td></tr></table>"
var loadstatustext1="<table width=\"100%\" height=\"100%\" align=\"center\"><tr><td><center>Aguarde...</center></td></tr></table>"
var loadstatustext2="<table width=\"100%\" height=\"100%\" align=\"center\"><tr><td><center><img src='../imagens/loading.gif' /><br><br></td></tr></table>"
var loadstatustext4="<table width=\"100%\" align=\"center\"><tr><td><center><img src='imagens/load_bar.gif' /></center></td></tr></table>"

////NO NEED TO EDIT BELOW////////////////////////
var loadedobjects=""
var defaultcontentarray=new Object()
var bustcacheparameter=""

//*** ajaxpage()
function ajaxpage(url, containerid, loadtext){
	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
	if (url.indexOf("#default")!=-1){ //if simply show default content within container (verus fetch it via ajax)
		document.getElementById(containerid).innerHTML=defaultcontentarray[containerid]
		return
	}

	if(loadtext == 'bolinha'){
		document.getElementById(containerid).innerHTML=loadstatustext;
	}

	if(loadtext == 'texto'){
		document.getElementById(containerid).innerHTML=loadstatustext1;
	}

	if(loadtext == 'barra'){
		document.getElementById(containerid).innerHTML=loadstatustext4;
	}

	if(loadtext == 'abrepop'){
		document.getElementById(containerid).innerHTML=loadstatustext3;
	}

	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('GET', url+bustcacheparameter, true)
	page_request.send(null)
}

// loadpage()
function loadpage(page_request, containerid){
	if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)){
		//w3Opacity.set(containerid,0);
		//w3Opacity.fading(containerid,0,100,800);
		document.getElementById(containerid).innerHTML=page_request.responseText;
		extraiScript(page_request.responseText);
	}
}

function enviarFormPost(url, campos, destino) {

	//Atribui à variável 'elemento' o elemento que irá receber a página postada
	var elemento = document.getElementById(destino);

	//Executa XMLHttpRequest
	if (window.XMLHttpRequest) // if Mozilla, Safari etc
	xmlhttp = new XMLHttpRequest()
	else if (window.ActiveXObject){ // if IE
		try {
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP")
		}
		catch (e){
			try{
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP")
			}
			catch (e){
			}
		}
	}
	else{
		return false
	}


	//Se o objeto de 'xmlhttp' não estiver true
	if (!xmlhttp) {

		//Insere no 'elemento' o texto atribuído
		elemento.innerHTML = 'Impossível iniciar o objeto XMLHttpRequest.';

		return;

	} else {

		//Insere no 'elemento' o texto atribuído
		elemento.innerHTML = "<table width=\"100%\" height=\"100%\" align=\"center\"><tr><td><center><img src='../imagens/loading.gif' /><br><font style=\"font-size:11px; color:#DFDFDF\">Verificando e enviando...</font></center><br><br></td></tr></table>";

	}

	xmlhttp.onreadystatechange = function () {

		//Se a requisição estiver completada
		if (xmlhttp.readyState == 4 || xmlhttp.readyState == 0) {

			//Se o status da requisição estiver OK
			if (xmlhttp.status == 200) {

				//Insere no 'elemento' a página postada
				elemento.innerHTML = xmlhttp.responseText;
				
				extraiScript(xmlhttp.responseText);

			} else {

				//Insere no 'elemento' o texto atribuído
				elemento.innerHMTL = 'Página não encontrada!';

			}

		}

	}

	//Abre a página que receberá os campos do formulário
	xmlhttp.open('POST', url+'?'+campos, true);

	//Envia o formulário com dados da variável 'campos' (passado por parâmetro)
	xmlhttp.send(campos);

}

function extraiScript(texto){
	// inicializa o inicio ><
	var ini = 0;
	// loop enquanto achar um script
	while (ini!=-1){
		// procura uma tag de script
		ini = texto.indexOf('<script', ini);
		// se encontrar
		if (ini >=0){
			// define o inicio para depois do fechamento dessa tag
			ini = texto.indexOf('>', ini) + 1;
			// procura o final do script
			var fim = texto.indexOf('</script>', ini);
			// extrai apenas o script
			codigo = texto.substring(ini,fim);
			// executa o script
			eval(codigo);
		}
	}
}
