﻿jQuery(document).ready(function() {	

		abrirModal();
	
	
});

jQuery(function(){
if(jQuery('ul#menuServicos a#dnn_USER_cmdRegister').text().length > 13){
usuario = jQuery('ul#menuServicos a#dnn_USER_cmdRegister').html() ;

jQuery('ul#menuServicos a#dnn_USER_cmdRegister').html(usuario.substring(0,10)+'...') ;
}





});

/*
   function onExcluirFavorito(codImovel) {
	   if( jQuery('#divGridFavoritos .lista').length == 1 ){
		jQuery('#mask').hide();
		jQuery('.window').hide();
		}
        if (_codTipoProduto == 1) {
            SnapSystems.SnapBroker.Modulo.ImoveisFavoritos.WebService.RemoverImovelFavorito(codImovel, _user, _codTipoProduto,
         function(resultado) {
             _pvFavoritos.set_pageIndex(0);
             carregarFavoritos();
         }, onFavoritosErro)
        }
    }
	*/
	
function abrirModal()
{

	jQuery('a[name=modal]').unbind().click( function(e) {      

if(typeof SnapSystems.SnapBroker.Modulo.Seminovos !="undefined")	
{
SnapSystems.SnapBroker.Modulo.Seminovos.WebService.CarregarContato(_userID,_codPortal, onCarregarContatoSolicitarSucesso, onErro);
}
if(typeof SnapSystems.SnapBroker.Modulo.Empreendimento !="undefined")	
{
SnapSystems.SnapBroker.Modulo.Empreendimento.WebService.CarregarContato(_userID,_codPortal, onCarregarContatoSolicitarSucesso, onErro);
}


		var id = jQuery(this).attr('href');
		jQuery(id).appendTo('form');
	
		var maskHeight = jQuery(document).height();
		var maskWidth = jQuery(window).width();
	
		jQuery('#mask').css({'width':maskWidth,'height':maskHeight});

		jQuery('#mask').fadeIn(1000);	
		jQuery('#mask').fadeTo("slow",0.8);	
	
		//Get the window height and width
		var winH = jQuery(window).height();
		var winW = jQuery(window).width();
              
		jQuery(id).css('top',  winH/2-jQuery(id).height()/2);
		jQuery(id).css('left', winW/2-jQuery(id).width()/2);
	
		jQuery(id).fadeIn(2000); 
		
		return false;
	
	});

	
	jQuery('.window .close').click(function (e) {
		e.preventDefault();
		
		jQuery('#mask').hide();
		jQuery('.window').hide();
	});		
	
	jQuery('.fechar').click(function (e) {
		e.preventDefault();
		
		
	});	
	
	jQuery('#mask').click(function () {
		jQuery(this).hide();
		jQuery('.window').hide();
	});		
}
	
 function onExcluirFavorito(codImovel) {     
    if( jQuery('#divGridFavoritos .lista').length == 1 ){
		jQuery('#mask').hide();
		jQuery('.window').hide();
		}
            SnapSystems.SnapBroker.Modulo.ImoveisFavoritos.WebService.RemoverImovelFavorito(codImovel, _user, _codTipoProduto,
         function(resultado) {
             _pvFavoritos.set_pageIndex(0);
             carregarFavoritos();
         }, onFavoritosErro);
		$get("spnRemover").style.display = "none";
        $get("spnAdicionar").style.display = "";
    }
	
	
	
	function onCarregarFavoritos(resultado)
    {
			
        var imoveis = Sys.Serialization.JavaScriptSerializer.deserialize(resultado["Imoveis"]);
        setText($get("lnkMeusFavoritos"), "Meus imóveis (" + resultado.Count + ")");
        _pvFavoritos.set_recordCount(resultado.Count);
        _gvFavoritos.set_dataSource(imoveis);
        _gvFavoritos.dataBind();    
		
		if ( resultado.Count == 0 ){
			//alert( 'zero' );
			jQuery( 'a#lnkMeusFavoritos' ).unbind().click(function(){
				return false;													   
			});;
		} else {
			//alert( 'maior que zero' );
			abrirModal();
		}
    }
	