// JavaScript Document

$(function() {
				$("#contato_form").hide();

				$("#contato_click").click(function(){
							 if($("#contato_form").css("display")=="none") {
								 $("#contato_form").slideDown();
								 $("#contato_click").html("<font face=\"arial\" color=\"#999\" size=\"2\"><b>Contato Direto Com O Fotógrafo:</b></font>");
								 return true;
							 } else {
								 $("#contato_form").slideUp();
								 $("#contato_click").html("<font face=\"arial\" color=\"#999\" size=\"2\"><b>Contato Direto Com O Fotógrafo:&nbsp;&nbsp;<font color=\"#333\" size=\"1\">(clique aqui)</font></b></font>");
								 return true;
							 }
				});
				
				$("#contato_enviar").click(function(){
							fotContatoEnviar();
		   		});
				
				
				$("#contato2_form").hide();

				$("#contato2_click").click(function(){
							 if($("#contato2_form").css("display")=="none") {
								 $("#contato2_form").slideDown();
								 $("#contato2_click").html("<font face=\"arial\" color=\"#999\" size=\"2\"><b>Contato Direto Com O Salão:</b></font>");
								 return true;
							 } else {
								 $("#contato2_form").slideUp();
								 $("#contato2_click").html("<font face=\"arial\" color=\"#999\" size=\"2\"><b>Contato Direto Com O Salão:&nbsp;&nbsp;<font color=\"#333\" size=\"1\">(clique aqui)</font></b></font>");
								 return true;
							 }
				});
				
				$("#contato2_enviar").click(function(){
							fotContatoEnviar2();
		   		});
				
});

function fotContatoEnviar2() {
	var nome=document.getElementById('nome').value;
	var email=document.getElementById('email').value;
	var telefone=document.getElementById('telefone').value;
	var assunto=document.getElementById('assunto').value;
	var msg=document.getElementById('msg').value;
	var email_fot=document.getElementById('email_fot').value;
	if(nome=="") {
		alert("Por favor preencha o campo NOME!");
		return false;
	} else if(email=="") {
		alert("Por favor preencha o campo E-MAIL!");
		return false;
	} else if(assunto=="") {
		alert("Por favor preencha o campo ASSUNTO!");
		return false;
	} else if(msg=="") {
		alert("Por favor preencha o campo MENSAGEM!");
		return false;
	}
	var aux="";
	for(var i = 0; i<=msg.length;i++) aux += msg.substring(i,(i+1)).charCodeAt()==10 ? "|%PL%|" : msg.substring(i,(i+1));
	msg = aux;
	AjaxRequest();
	if(!Ajax) {
		alert("Erro na chamada");
		return;
	}
	document.getElementById("contato2_form_status").innerHTML='<center><font face=verdana size=2><b>Enviando... Por favor aguarde...</b></font></center>';
	Ajax.onreadystatechange = fotContatoEnviarProc2;
	Ajax.open('GET', 'jquery/salao_envia.php?executa=lucianomorais.com.br&nome='+nome+'&email='+email+'&telefone='+telefone+'&assunto='+assunto+'&msg='+msg+'&email_fot='+email_fot, true);
	Ajax.send(null);
}
function fotContatoEnviarProc2() {
	if(Ajax.readyState == 4) {
		if(Ajax.status == 200) {
			var respo = Ajax.responseText;
			if(respo==1)
				document.getElementById("contato2_form_status").innerHTML='<center><font face=verdana size=2 color=#ff0000><b>Algum erro ocorreu durante o envio. Por favor tente novamente!</b></font></center>';
			else
				document.getElementById("contato2_form_status").innerHTML='<center><font face=verdana size=2 color=green><b>Contato enviado com sucesso!</b></font></center>';
		} else {
			alert("Erro: "+Ajax.statusText);
		}
	}
}


function fotContatoEnviar() {
	var nome=document.getElementById('nome').value;
	var email=document.getElementById('email').value;
	var telefone=document.getElementById('telefone').value;
	var assunto=document.getElementById('assunto').value;
	var msg=document.getElementById('msg').value;
	var email_fot=document.getElementById('email_fot').value;
	if(nome=="") {
		alert("Por favor preencha o campo NOME!");
		return false;
	} else if(email=="") {
		alert("Por favor preencha o campo E-MAIL!");
		return false;
	} else if(assunto=="") {
		alert("Por favor preencha o campo ASSUNTO!");
		return false;
	} else if(msg=="") {
		alert("Por favor preencha o campo MENSAGEM!");
		return false;
	}
	var aux="";
	for(var i = 0; i<=msg.length;i++) aux += msg.substring(i,(i+1)).charCodeAt()==10 ? "|%PL%|" : msg.substring(i,(i+1));
	msg = aux;
	AjaxRequest();
	if(!Ajax) {
		alert("Erro na chamada");
		return;
	}
	document.getElementById("contato_form_status").innerHTML='<center><font face=verdana size=2><b>Enviando... Por favor aguarde...</b></font></center>';
	Ajax.onreadystatechange = fotContatoEnviarProc;
	Ajax.open('GET', 'jquery/fotografo_envia.php?executa=lucianomorais.com.br&nome='+nome+'&email='+email+'&telefone='+telefone+'&assunto='+assunto+'&msg='+msg+'&email_fot='+email_fot, true);
	Ajax.send(null);
}
function fotContatoEnviarProc() {
	if(Ajax.readyState == 4) {
		if(Ajax.status == 200) {
			var respo = Ajax.responseText;
			if(respo==1)
				document.getElementById("contato_form_status").innerHTML='<center><font face=verdana size=2 color=#ff0000><b>Algum erro ocorreu durante o envio. Por favor tente novamente!</b></font></center>';
			else
				document.getElementById("contato_form_status").innerHTML='<center><font face=verdana size=2 color=green><b>Contato enviado com sucesso!</b></font></center>';
		} else {
			alert("Erro: "+Ajax.statusText);
		}
	}
}
function _Legend(){
	_Legend.defaultX = 20;
	_Legend.defaultY = 0;

	//PosiÃ§Ãµes
	_Legend.x = 0;
	_Legend.y = 0;

	this.show = function(text, pX, pY){
		
		_Legend.x = (pX === undefined)?_Legend.defaultX:pX;
		_Legend.y = (pY === undefined)?_Legend.defaultY:pY;
		document.getElementById('contentLegend').innerHTML = text;
			document.getElementById('contentLegend').style.backgroundColor = '#FFFADD';
			document.getElementById('contentLegend').style.color = '#333333';
			document.getElementById('contentLegend').style.border = '1px solid #FCE8B5';
			

		document.onmousemove = this.mouseMoving;
	};

	this.hide = function(){
		_Legend.setVisible(false);
	};

	_Legend.setVisible = function(pBool){
		if (pBool){
			document.getElementById('contentLegend').style.visibility = "visible";
		} else {
			document.getElementById('contentLegend').style.left = 0;
			document.getElementById('contentLegend').style.top = 0;
			document.getElementById('contentLegend').style.visibility = "hidden";
			document.onmousemove = null;
		}
	};

	//Captura o movimento do mouse
	this.mouseMoving = function(e) {
		var posx = 0; // posiÃ§Ã£o x
		var posy = 0; // posiÃ§Ã£o y
		if (!e){
			var e = window.event; // Captura o evento do mouse
		}
		if (e.pageX || e.pageY) 	{ // Verifica a existÃªncia da pageX ou pageY
			posx = e.pageX; // Atribui a posiÃ§Ã£o x
			posy = e.pageY; // Atribui a posiÃ§Ã£o y
		} else if (e.clientX || e.clientY) { // Verifica a existï¿½ncia do clienteX e clienteY
			posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
			posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
		}

		//Se visibilidade
		_Legend.setVisible(true);

		//Seta os movimentos do objeto
		_Legend.setMove(posx + _Legend.x, posy + _Legend.y);
	};

	//Altera movimento do objeto
	_Legend.setMove = function(pLeft, pTop){
		document.getElementById('contentLegend').style.left = pLeft+'px';
		document.getElementById('contentLegend').style.top = pTop+'px';
	};
}
var Legend = new _Legend();
