try {
	ajax = new ActiveXObject("Microsoft.XMLHTTP");
} 
catch(e) {
	try {
		ajax = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(ex) {
		try {
			ajax = new XMLHttpRequest();
		}
		catch(exc) {
			alert("Esse browser não tem recursos para uso do Ajax");
			ajax = null;
		}
	}
}

function EfeitoMenu(caminho,id){
	document.getElementById(id).src=caminho;	
}

function FadeAparece(id,ini,fim,tempo){
w3Opacity.fading(id,ini,fim,tempo);
}

function FadeSome(id,ini,fim,tempo){
w3Opacity.fading(id,ini,fim,tempo);
}
function AbrePagina(url,id,bloco){
	ajax.open("POST",url, true);
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.onreadystatechange = function() {
		if(ajax.readyState == 1) {
			document.getElementById(id).innerHTML =  "Abrindo pagina...";
		}
		if(ajax.readyState == 2) {
			document.getElementById(id).innerHTML =  "Abrindo pagina...";
		}
		if(ajax.readyState == 3) {
			document.getElementById(id).innerHTML =  "Abrindo pagina...";
		}
		if(ajax.readyState == 4) {
			document.getElementById(id).innerHTML =  ajax.responseText;
		}
	}	
	ajax.send(null);
}
function DeletaBloco(id){
	var corpo = document.body;
	var bloco = document.getElementById(id);
	var transp = document.getElementById('transp');
	corpo.removeChild(bloco);
	corpo.removeChild(transp);
}
function FechaBloco(id){
	FadeSome(id,100,0,800);
	FadeSome("transp",100,0,800);
	var inte = window.setInterval("DeletaBloco('"+id+"')", 1000);
	window.setTimeout("clearInterval("+inte+")", 1000);
}
function AbreBloco(url,divnova){
	getPageSize();
	var divtrans = document.createElement("div");
	divtrans.setAttribute('id', 'transp');
	divtrans.className="transparencia";
	divtrans.style.width = arrayPageSize[0]+"px";
	divtrans.style.height = arrayPageSize[1]+"px";
	
	var div = document.createElement("div");
	div.setAttribute("id",divnova);
	div.className="bloco";
	var tamanhonav = arrayPageSize[0];
	var margem = (tamanhonav - 327) / 2;
	div.style.marginLeft = margem+"px";
	div.style.marginRight = margem+"px";
	
	var divcima = document.createElement("div");
	divcima.className="cima";
	divcima.innerHTML = "<img onclick=FechaBloco('"+divnova+"'); src='media/imagens/"+divnova+".gif'>";
	
	var divmeio = document.createElement("div");
	divmeio.className="meio";
	
	var iframe = document.createElement("iframe");
	iframe.setAttribute("name","cont");
	iframe.setAttribute("id","cont");
	iframe.setAttribute("src",url);
	iframe.setAttribute("frameBorder","0");
	iframe.setAttribute("scrolling","no");
	iframe.style.border = 0+"px";
	iframe.style.margin = 3+"px";
	iframe.style.width = 320+"px";
	
	var divbaixo = document.createElement("div");
	divbaixo.className="baixo";
	divbaixo.innerHTML = "<img src='media/imagens/baixo.gif'>";
	
	var divtudo = document.getElementById("tudo");
	
	document.body.insertBefore(divtrans,divtudo);
	w3Opacity.set("transp",70);
	
	document.body.insertBefore(div,divtrans);
	w3Opacity.set(divnova,0);
	FadeAparece(divnova,0,100,800);
	
	div.appendChild(divcima);
	div.appendChild(divmeio);
	divmeio.appendChild(iframe);
	div.appendChild(divbaixo);
}
function EnviaContato(url,form){
	var nome = form.nome.value;
	var email = form.email.value;
	var assunto = form.assunto.value;
	var texto = form.texto.value;

	var conteudobloco = document.getElementById("conteudobloco");
	var loading = document.createElement("div");
	loading.setAttribute('id','load');
	
	var tamanhonav = screen.width;
	var diferenca = tamanhonav - 188;
	var margem = diferenca / 2;
	loading.style.marginLeft = margem+"px";
	loading.style.marginRight = margem+"px";
	
	alturanav = document.body.offsetHeight;
	var difaltura = alturanav - 74;
	var margemalt = difaltura / 2;
	loading.style.marginTop = margemalt+"px";
	
	loading.style.position = "absolute";
	loading.innerHTML = "<img src='media/imagens/preloader.gif' alt='0' />";
	loading.style.display = "none";
	loading.style.zIndex = 10000;
	var divtudo = document.getElementById("tudo");
	document.body.insertBefore(loading,divtudo);
	ajax.open("POST", url, true);
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.onreadystatechange = function(){
		if(ajax.readyState == 1){
			loading.style.display = "block";
		}
		if(ajax.readyState == 4){
			document.body.removeChild(document.getElementById("load"));
			if(ajax.responseText == "sim"){
				alert("Contato recebido com sucesso, estaremos respondendo o mais breve possivel.");
				FechaBloco('blococontato');
			}else{
				alert("Erro no envio do contato, verifique se seu email está digitado corretamente!");
			}
		}
	}
	var parametros = "nome="+nome+"&email="+email+"&assunto="+assunto+"&texto="+texto;
	ajax.send(parametros);
}
function AbreServicos(id){
	var div = "servico"+id;
	var acento = "ico"+id;
	var span = "spanico"+id;
	var imgico = new Image(11,11);
	if(document.getElementById(div).style.display == ""){
		document.getElementById(span).innerHTML = "";
		imgico.src = "media/imagens/bloco_menos.gif";
		document.getElementById(span).appendChild(imgico);
		document.getElementById(div).style.display = "block";
	}else{
		document.getElementById(span).innerHTML = "";
		imgico.src = "media/imagens/bloco_mais.gif";
		document.getElementById(span).appendChild(imgico);
		document.getElementById(div).style.display = "";
	}
	window.parent.cont.EnviaTamanhoIframe();
}
function Valida(url,local){
	if(local.name == "form_contato"){
		var form = document.form_contato;
		if(form.nome.value == ""){
			alert("O campo NOME precisa ser preenchido!");
			form.nome.focus();
			return false;
		}
		if(form.email.value == ""){
			alert("O campo EMAIL é importante por isso precisa ser preenchido!");
			form.email.focus();
			return false;
		}
		parte1 = form.email.value.indexOf("@");
		parte2 = form.email.value.indexOf(".");
		parte3 = form.email.value.length;
		if (!(parte1 >= 3 && parte2 >= 6 && parte3 >= 9)) {
			alert("O campo EMAIL deve ser conter um endereco eletronico!");
			form.email.focus();
			return false;
		}
		if(form.assunto.value == ""){
			alert("O campo ASSUNTO deve ser preenchido!");
			form.assunto.focus();
			return false;
		}
		if(form.texto.value == ""){
			alert("O campo TEXTO deve ser preenchido!");
			form.texto.focus();
			return false;
		}
		EnviaContato(url,local);
	}
}
function ArrumaIframe(largura,altura){
	var iframe = document.getElementById("cont");
	iframe.style.height = altura+"px";
}
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {    
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else {
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) {
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}    
	
	
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){    
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
}
