function showPopup(div) {
	var vardiv = div;
	var wind = document.getElementById(vardiv);
	if (document.getElementById('bgWind') != null) {
		var bg = document.getElementById('bgWind');
		bg.style.display = 'block';
		bg.onclick = hidePopup;
	} else {
		ShowBgWind(hidePopup);
	};
	
	wind.style.display = 'block';
}

function hidePopup(div) {
	var vardiv = div;
	var bg = document.getElementById('bgWind');
	var wind = document.getElementById(vardiv);
	bg.style.display = 'none';
	wind.style.display = 'none';
}

window.onload = function() {
	
};

function fctLimparCampos() {
	try {
		var pop_nome = document.getElementById('pop_nome');
		var pop_email = document.getElementById('pop_email');
		var pop_porque = document.getElementById('pop_porque');
		pop_nome.value = '';
		pop_email.value = '';
		pop_porque.value = '';
		pop_porque.innerHTML = '';
	} catch(e) {
		
	};
};

function fctEnviar() {
	if (document.getElementById('pop_nome').value == "") {
		alert('Por favor, preencha corretamente o campo Nome.');
		document.getElementById('pop_nome').focus();
		return;
	};
	if (document.getElementById('pop_email').value == "") {
		alert('Por favor, preencha corretamente o campo E-Mail.');
		document.getElementById('pop_email').focus();
		return;
	};
	if (document.getElementById('pop_porque').value == "") {
		alert('Por favor, preencha corretamente o campo da Mensagem.');
		document.getElementById('pop_porque').focus();
		return;
	};

	var objeAjax = new Ajax();
	objeAjax.oParametros.Adicionar(new Parametro("Nome",document.getElementById('pop_nome').value));
	objeAjax.oParametros.Adicionar(new Parametro("Email",document.getElementById('pop_email').value));
	objeAjax.oParametros.Adicionar(new Parametro("PorQue",document.getElementById('pop_porque').value));
	objeAjax.oParametros.Adicionar(new Parametro("intePassos",2));
	objeAjax.metodo = "POST";
	objeAjax.callBack = fctEnviar_CallBack;
	objeAjax.url = "http_request/web_enviar_dados.asp";
	objeAjax.Enviar();
};

function fctEnviar_CallBack(objeAjax) {
	if (objeAjax.VerificarStatus() != 4)
		return;
		
		if (objeAjax.getText == 'true') {
			hidePopup();
			fctLimparCampos();
			alert('Obrigado por sua colaboração. Entraremos em contato em breve.');
		} else {
			alert('Não foi possivel enviar sua mensagem.\nTente novamente mais tarde.')
		};
};



function ShowBgWind(HideFunction) {
	var isIE = (window.attachEvent != undefined)?true:false;
	var oPopupBg;
	var oBody = document.getElementsByTagName('body')[0];
	oPopupBg = document.createElement('div');
	oPopupBg.id = 'bgWind';
	oPopupBg.className = "bgWind";
	oPopupBg.onclick = function() { HideFunction() };
	oBody.appendChild(oPopupBg);
	
	if(isIE) {
		oPopupBg.style.height = (document.getElementsByTagName('html')[0].offsetHeight + 30) +'px';
	} else {
		//oPopupBg.style.height = (document.getElementsByTagName('html')[0].offsetHeight + 30) +'px';
	};
};



function fctCarregarXML(varcFile) {
	var xmlDoc;
	
	if (window.ActiveXObject) {
		xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async=false;
		xmlDoc.load("noticias/" + varcFile);
		fctShowNoticia(xmlDoc);
	} else if (document.implementation && document.implementation.createDocument) {
		xmlDoc=document.implementation.createDocument("","",null);
		xmlDoc.load("noticias/" + varcFile);
		xmlDoc.onload= function() {
			fctShowNoticia(xmlDoc);
		};
	} else {
		alert('Seu browser não suporta esta operação.');
	}
}

function fctShowNoticia(xmlDoc) {
	var titulo 	= xmlDoc.getElementsByTagName("titulo")[0].childNodes[0].nodeValue + '<img src="images/icon_news.gif" />';
	var texto 	= xmlDoc.getElementsByTagName("texto")[0].childNodes[0].nodeValue;
	document.getElementById('noticia_titulo').innerHTML = titulo;
	document.getElementById('noticia_texto').innerHTML = texto;
	
	var wind = document.getElementById('popup_wind');
	if (document.getElementById('bgWind') != null) {
		var bg = document.getElementById('bgWind');
		bg.style.display = 'block';
		bg.onclick = hideNoticia;
	} else {
		ShowBgWind( hideNoticia );
	};	
	
	document.getElementById('noticia_popup').style.display = 'block';
}


function hideNoticia() {
	var bg = document.getElementById('bgWind');
	var wind = document.getElementById('noticia_popup');
	bg.style.display = 'none';
	wind.style.display = 'none';
}