$(document).ready(function() {
	$('#emailNews').focusin(function(){
		if($(this).attr('value')=='Email'){
			$(this).attr('value','');	
		}	
	});	
	
	$('#emailNews').focusout(function(){
		if($(this).attr('value')==''){
			$(this).attr('value','Email');	
		}		
	});
	
	$('#nomeNews').focusin(function(){
		if($(this).attr('value')=='Nome'){
			$(this).attr('value','');	
		}	
	});	
	
	$('#nomeNews').focusout(function(){
		if($(this).attr('value')==''){
			$(this).attr('value','Nome');	
		}		
	});
	
	getLancamentos();
	
	$('.setaEsqLanc').live('click',function(){
		var pgAtual = $('#pagAtualLanc').attr('value');
		var qtdPags = $('#pagAtualLanc').attr('class');
				
		pgAtual--;
		
		if(pgAtual<=0)
			pgAtual=qtdPags;	
				
		$('.lstlancamentos > a[class!="pg'+pgAtual+'"]').fadeOut('slow',function(){
			$('.pg'+pgAtual).fadeIn('slow');	
		});
						
		$('#pagAtualLanc').attr('value',pgAtual);		
	});
	
	$('.setaDirLanc').live('click',function(){
		var pgAtual = $('#pagAtualLanc').attr('value');
		var qtdPags = $('#pagAtualLanc').attr('class');
				
		pgAtual++;
		
		if(pgAtual>qtdPags)
			pgAtual=1;	
		
		$('.lstlancamentos > a[class!="pg'+pgAtual+'"]').fadeOut('slow',function(){
			$('.pg'+pgAtual).fadeIn('slow');	
		});
		
		$('#pagAtualLanc').attr('value',pgAtual);		
	});
});

function getLancamentos(){
	if($('#lancamentosHome').length){
		$.ajax({
		   url: "lancamentos.asp",
		   success: function(msg){
				$('#lancamentosHome').html(msg);   
		   }
		});	
	}
}


function AbreJanela(url, width, height, nome, scrollbars) {
	var top; var left;
	top = ( (screen.height/2) - (height/1.55) )
	left = ( (screen.width/2) - (width/2) )
	window.open(url, nome,'width='+width+',height='+height+',scrollbars='+scrollbars+',toolbar=no,location=no,status=no,menubar=no,resizable=no,left='+left+',top='+top);
}

function navegacao(pag){
	var ind = location.href.indexOf("&pag=");
	var url;
	
	if(ind > -1)	
		url = location.href.substring(0,ind);
	else
		url = location.href;
		
	location.href = url + "&pag=" + pag		
}

function checkMail(mail){
    var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
    if(typeof(mail) == "string"){
        if(er.test(mail)){ return true; }
    }else if(typeof(mail) == "object"){
        if(er.test(mail.value)){ 
                    return true; 
                }
    }else{
        return false;
        }
}

function vEmail(campo){
	if(checkMail(campo.value))
		return true;
	else{
		alert('Email inválido');
		campo.focus();
		return false;	
	}	
}


function vField(campo,msgErro){
	if(campo.value != "")
		return true;
	else{
		alert(msgErro);
		campo.focus();
		return false;	
	}	
}

function PesquisarRef(form, icForm){
	with(form){
		if(vField(txtRef,"Informe o referência"))
			location.href = "index.asp?pagina=busca&ref=" + txtRef.value;			
	}	
	if(icForm)
		return false;
}

function ImovelInserir(idImovel){
	var imovel = new DetalhesImovel();
  	imovel.Inserir('conteudoDetalhes',idImovel);
	imovel.Chat('videostreaming.com.br/millenniumimoveis/livezilla.php');
}

/*---OBJETOS DE MANIPULACAO VIA AJAX--*/
function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}

function getNewsletter(email_obj, nome_obj)
{
	var email = document.getElementById(email_obj);
	var nome = document.getElementById(nome_obj);
	if ((email.value != "")&&(nome.value != ""))
	{
		if(vEmail(email)){
			xmlHttp=GetXmlHttpObject();
			xmlHttp.onreadystatechange=function()
				{
					if(xmlHttp.readyState==4)
						{
							alert(xmlHttp.responseText);
							email.value = "Email";
							nome.value = "Nome";
						}
				}
			url = "insere_exclui_newsletter.asp?email="+email.value+"&acao=inclui&nome="+nome.value;
		
			xmlHttp.open("GET",url,true);
			xmlHttp.send(null);
		}
	}
	else
	{
		alert('Informe o seu nome e seu email!');
		nome.focus();
	}
}
