// JavaScript Document
function openAjax() {
	var ajax;
	try {
		ajax = new XMLHttpRequest();
	} catch(ee) {
		try {
			ajax = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try {
				ajax = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(E) {
				ajax = false;
			}
		}
	}
	return ajax;
}

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){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	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;
	}
	
	return {pageX:pageWidth, pageY:pageHeight, windowX:windowWidth, windowY:windowHeight};
}

function getObjSize(e) {
	if (typeof e == 'string') e = document.getElementById(e);
	return {x:e.offsetWidth, y:e.offsetHeight};
}


var posicao_top = true;
function contato() {
	
	if (posicao_top) {		
		posicao_top = false;
		
		var tela = getPageSize();
		var objeto = getObjSize('contato');		
		var posicaoX = (tela.pageX/2) - (objeto.x/2);
		document.getElementById('contato').style.left = posicaoX+'px';
		document.getElementById("telefones").style.display = 'block';
		$('#contato').animate({									
			top: '+=600'
		}, 500, null);

	} else {
		document.getElementById("telefones").style.display = 'none';
		posicao_top = true;
		$('#contato').animate({
			top: '-=600'
		}, 500, null);
	}
	
	return false;
}

function enviar_contato(form) {
	var obj_ajax = openAjax();
	if (obj_ajax == null) {
		alert ("Seu navegador não da suporte a este tipo de ação!");
		return false;
	}
	var datahora = new Date();
	var dia 	 = datahora.getDay();
	var mes 	 = datahora.getMonth();
	var ano 	 = datahora.getYear();
	var hora 	 = datahora.getHours();
	var minuto 	 = datahora.getMinutes();
	var segundos = datahora.getSeconds();
	var id_link  = ano+mes+dia+hora+minuto+segundos;
	
	var params = "id_link="+id_link;
	params = params + "&nome="+form.nome.value;
	params = params + "&email="+form.email.value;
	params = params + "&telefone="+form.telefone.value;
	params = params + "&mensagem="+form.mensagem.value;
	obj_ajax.open("GET", "enviar.php?"+params, true);
	obj_ajax.onreadystatechange = function() {
		if (obj_ajax.readyState == 4) {
			alert("Mensagem enviada com sucesso!");
			contato();
		}
	}
	obj_ajax.send(null);
	return false;	
}
