// JavaScript Document

function identificaNavegador(){
var b = navigator.appName;
var ua = navigator.userAgent.toLowerCase();

var Browser = {};

Browser.safari = ua.indexOf('safari') > -1;
Browser.opera = ua.indexOf('opera') > -1;
Browser.ns = !Browser.opera && !Browser.safari && b == 'Netscape';
Browser.ie = !Browser.opera && b == 'Microsoft Internet Explorer';
Browser.gecko = ua.indexOf('firefox') > -1;
Browser.Chrome = ua.indexOf("applewebkit") != -1
delete b;
delete ua;

if(Browser.ie) {
	return "IE";
	//alert(navegador);
}

if(Browser.gecko) {
	return  "FIREFOX";
	//alert(navegador);
}
if(Browser.Chrome) {
	return  "CHROME";
	//alert(navegador);
}
}

function ajaxFunction()
{
	var xmlHttp;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	
		//alert('xmlHttp=new XMLHttpRequest();');
	}
	catch (e)
	{
	// Internet Explorer
		try
		{
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		//alert('xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");');
		}
		catch (e)
		{
			try
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
				//alert('xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");');
			}
			catch (e)
			{
				//alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	return xmlHttp;
}

function Send(url,params,objImgLoading, funcResultado)
{
	
	if(objImgLoading!= null)
		objImgLoading.style.display = "";
	xmlHttp = ajaxFunction();
	xmlHttp.open("POST", url, true);
	
	//Send the proper header information along with the request
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
	xmlHttp.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
	xmlHttp.setRequestHeader("Pragma", "no-cache");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.onreadystatechange = funcResultado;
	xmlHttp.send(params);
	
	//alert('xmlHttp.send(params);');
}

function objAjax() 
{
	this.xmlHttp = ajaxFunction();
	this.params = null;
	this.func = null;
	this.Send =	function(url,params,objImgLoading, funcResultado)
		{
			//alert(funcResultado);
			if(objImgLoading!= null)
				objImgLoading.style.display = "";
			this.xmlHttp.open("POST", url, true);
			
			//Send the proper header information along with the request
			this.xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			this.xmlHttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
			this.xmlHttp.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
			this.xmlHttp.setRequestHeader("Pragma", "no-cache");
			this.xmlHttp.setRequestHeader("Content-length", params.length);
			this.xmlHttp.onreadystatechange = funcResultado;
			this.xmlHttp.send(params);
			
			//alert('xmlHttp.send(params);');
		}	
}

function objAjaxNew() 
{
	this.xmlHttp = ajaxFunction();
	this.params = null;
	this.func = null;
	this.url = null;
	this.method = "POST";
	this.Send =	function(objImgLoading)
		{
			//alert(funcResultado);
			if(objImgLoading!= null)
				objImgLoading.style.display = "";
			this.xmlHttp.open(this.method, this.url, true);
			
			//Send the proper header information along with the request
			this.xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			this.xmlHttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
			this.xmlHttp.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
			this.xmlHttp.setRequestHeader("Pragma", "no-cache");
			this.xmlHttp.setRequestHeader("Content-length", this.params.length);
			this.xmlHttp.onreadystatechange = this.func;
			this.xmlHttp.send(this.params);
			
			//alert('xmlHttp.send(params);');
		}	
}

function getObj(objname)
{
	return document.getElementById(objname);
}

function logErro(tipo_log, nomePagina, mensageErro)
{
		var url = "/intranet/classes/php/logErro/logErro.php";
		var func = function()
		{

		}
		var parametro = "pagina=" + nomePagina;
		parametro += "&mensagem=" + mensageErro;
		Send(url,parametro,null,func);	
}
function tempo()
{
	
	this.idObj = null;
	this.func = function() { };
	this.cont = 15;
	this.maximo = 0;
	this.minimo = 0;
	this.crescente = true;
	this.timer = null;
	this.velocidade = 50;
	this.conta = function()
	{
		if(this.crescente)
		{
			if(this.cont >this.minimo)
				this.cont--;
			else
				return false;
		}
		else
		{
			if(this.cont <this.maximo)
				this.cont++;
			else
				return false;
		}
		return true;
		
	}
	this.start = function()
	{
		var thisObj = this;
		var faz = function() { thisObj.start() };
		this.timer = setTimeout(faz, this.velocidade); 
		this.func();
		if(!this.conta()) clearTimeout(this.timer);	
		
	}
	this.intToHexa = function(d) {return d.toString(16).toUpperCase(); }
	//function h2d(h) {return parseInt(h,16);}
}
var timer = new Array();
function realca(id, v)
{	
	if(v)
	{
		if(timer[id] == null)
		{
			timer[id] = new tempo();
			timer[id].minimo = 0;
			timer[id].maximo = 15;
			timer[id].idObj = id;
			timer[id].crescente = true;
			timer[id].velocidade = 10;
			timer[id].func =  function()
			{
				getObj(timer[id].idObj).style.backgroundColor = "#"+timer[id].intToHexa(timer[id].cont)+""+timer[id].intToHexa(timer[id].cont)+"FF"+timer[id].intToHexa(timer[id].cont)+""+timer[id].intToHexa(timer[id].cont);
			}
			timer[id].start();
		}
		else
		{
			timer[id].velocidade = 10;
			timer[id].crescente = true;
			timer[id].start();			
		}
	}
	else
	{
		if(timer[id] != null)
		{
			timer[id].velocidade = 50;
			timer[id].crescente = false;
			timer[id].start();	
		}	
	}
}
var time = null, cont = 0;
function ativarBlack()
{
	time = setTimeout("ativarBlack()", 20);
	if(cont<20)
	{
		cont += 3;
				if(identificaNavegador() == "CHROME")
				{
					getObj("blackGround").style.opacity = cont/50;
					//getObj("blackGround").style.filter = "alpha(opacity=" + cont + ")";
					//alert("CHROME");
				}
				
				else if(identificaNavegador() == "IE")
				{
					//getObj("blackGround").style.opacity = cont/100;
					getObj("blackGround").style.filter = "alpha(opacity=" + cont*2 + ")";
					//alert("IE");
				}
				
				else (identificaNavegador() == "FIREFOX")
				{
					getObj("blackGround").style.opacity = cont/50;
					//getObj("blackGround").style.filter = "alpha(opacity=" + cont + ")";
					//alert("IE");
				}
	}
	else
	{
		clearTimeout(time);	
		cont = 0;
	}
}
function showWindownBackBlack(src, width, height)
{	
	showWindownBackBlackAll(src, width, height, (clientWidth()*2/5), 300);
	
}
function showWindownBackBlackAll(src, width, height, left, top)
{
	createBackBlack();
	if(getObj("iframe1")!= null)	
	{
		getObj("blackGround").removeChild(getObj("iframe1"));	
	}
	window.scrollTo(0,0);	
	//document.body.scroll = 'no';
	//document.body.style.overflowY='hidden';
	getObj("blackGround").style.width = (clientWidth() + "px");
	getObj("blackGround").style.height = (clientHeight() + "px");
	getObj("blackGround").style.display = "";
	
		var iframe = document.createElement("iframe");
	iframe.setAttribute("id","iframe1");
	iframe.setAttribute("name","iframe1");
	iframe.setAttribute("align","middle");
	iframe.setAttribute("frameborder","0");
	
	getObj("blackGround1").appendChild(iframe);
	getObj("blackGround1").style.display = "";
	//getObj("iframe1").width = (width == null ? (clientWidth()*3/5) : width);
	getObj("iframe1").height = (height == null ? (clientHeight()*0) : height);
	//getObj("iframe1").src = src;
	
	getObj("blackGround1").style.top = (top == null ? "10px" : top+"px");
	getObj("blackGround1").style.left = (top == null ? (clientWidth()*1/5) + "px" : left+"px");;
	ativarBlack();
	
}
function finalizaBlack()
{
	clearTimeout(timer);
	destroiBackBlack();	
	document.body.style.overflowY='';
	document.body.scroll = 'yes';
}
function createBackBlack()
{
	var blackGround = document.createElement("div");
	blackGround.setAttribute("id", "blackGround");
	blackGround.id = "blackGround";
	blackGround.setAttribute("name","blackGround");
	blackGround.style.display = 'none';
	blackGround.style.position = 'absolute';
	blackGround.style.backgroundColor = '#000';
	blackGround.style.zIndex = '2';
	blackGround.style.filter = 'alpha(opacity=0)';
	blackGround.style.opacity = '0';
	blackGround.style.top = '0px';
	blackGround.style.left = '0px';
//	blackGround.style.border = '3px solid #000000';
	
	var blackGround1 = document.createElement("div");
	blackGround1.setAttribute("id", "blackGround1");
	blackGround1.setAttribute("name","blackGround1");
	blackGround1.style.display = 'none';
	blackGround1.style.position = 'absolute';
	blackGround1.style.backgroundColor = '#FFF';
	blackGround1.style.zIndex = '3';
	blackGround1.style.border = '3px solid #ccc';
	
	blackGround1.innerHTML =
			'<center>' +
				'<div id="loading">' +
					'<br><img alt="carregando..." src="/uteis/imagens/icones/ico_loading.gif" border="0" /><br><h4>Carregando dados...<br>Aguarde...</h4>' +
				'</div>'
			'</center>';
			
	//blackGround1.innerHTML = 
   // '   <table>' +
//    '        <tr>' +
//    '            <td valign="middle">' +
//    '            <strong>' +
//    '            	<a href="javascript:destroiBackBlack();"><img src="/intranet/figuras/ico_voltar.jpg" border="0"  alt="Voltar" title="Voltar"/> Voltar</a>' +
//    '            </strong>' +
//    '            </td>' +
//    '        </tr>' +
//    '    </table>';
	
	document.body.appendChild(blackGround);
	document.body.appendChild(blackGround1);
	
}
function destroiBackBlack()
{
	if(getObj("blackGround")!= null)	
	{
		document.body.removeChild(getObj("blackGround"));	
	}
	if(getObj("blackGround1")!= null)	
	{
		document.body.removeChild(getObj("blackGround1"));	
	}
}
function clientWidth()
{  
	//alert('clientWidth() = ' + document.documentElement.clientWidth);
	return document.documentElement.clientWidth;  
}  
function clientHeight()
{  
	//alert('clientHeight() = ' + document.documentElement.clientHeight);	
	return document.documentElement.clientHeight;  
} 


function montaSelect(idDestino, conteudo)
{
	seleciones = conteudo.split("@@"); 
	eSelect = document.getElementById(idDestino);
	//alert(seleciones);
	segu = 0;
	while(eSelect.hasChildNodes())
	{
		eSelect.removeChild(eSelect.firstChild);
		if(segu > 100)
			break;
		segu++;	
	}
	for(i=0; i< seleciones.length; i++)
	{	
		 
		valores = seleciones[i].split("@");
		//alert(valores);
		eOption = document.createElement("option"); // Elemento Option  
		textoOption = document.createTextNode(valores[1]); // Texto do option  
		 //Elemento Select  
		
		eOption.setAttribute("value", valores[0]);  
		eOption.appendChild(textoOption);  
		  
		eSelect.appendChild(eOption); 
	}
}
