function miniwin2(theURL) { 
 var1 = screen.width-(screen.width-screen.availWidth);
 var2 = screen.height-(screen.height-screen.availHeight);
 args = "top=1,left=1,toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=" + var1 + ",height=" + var2;
 window.open(theURL,'janela',args);
}
function montaFlash(swf, vars, width, height, id, wmode, cache) {
	noCache = cache || cache == undefined ? "" : "?" + new Date();
	monta_swf = "";
	monta_swf += "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0\" id=\""+ id +"\" width=\""+ width +"\" height=\""+ height +"\" title=\"\">";
	monta_swf += "<param name=\"movie\" value=\""+ swf + noCache +"\" />";
	monta_swf += "<param NAME=FlashVars value=\""+ vars +"\" />";
	monta_swf += "<param name=\"quality\" value=\"high\" />";
	monta_swf += "<param name=\"menu\" value=\"false\" />";
	monta_swf += "<param name=\"wmode\" value=\""+ wmode +"\" />";
	monta_swf += "<embed src=\""+ swf + noCache +"\"  FlashVars=\""+ vars + "\" quality=\"high\" menu=\"false\" wmode=\""+ wmode +"\"  pluginspage=\"http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"application/x-shockwave-flash\" id=\""+ id +"\" width=\""+ width +"\" height=\""+ height +"\"></embed>";
	monta_swf += "</object>";
	document.write(monta_swf);
}

function popWin(URL,NAME,WIDTH,HEIGHT,RESIZE,SCROLL) {
   winId = window.open(URL,NAME,'width='+WIDTH+',height='+HEIGHT+',resizable='+RESIZE+',scrollbars='+SCROLL+',menubar=no,toolbar=no,location=no,directories=no,status=no');
	var clientWidth = screen.availWidth;
	var clientHeight = screen.availHeight;
	var xPos = (clientWidth - WIDTH)/2;
	var yPos = (clientHeight - HEIGHT)/2;
	winId.moveTo(xPos,yPos);
}

function CheckMail(str){
	var testresults
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(str)) testresults=false
	else testresults=true
	return (testresults)
}

function str_replace(search, replace, subject) {
    var s = subject;
    var ra = r instanceof Array, sa = s instanceof Array;
    var f = [].concat(search);
    var r = [].concat(replace);
    var i = (s = [].concat(s)).length;
    var j = 0;
    
    while (j = 0, i--) { if (s[i]) { while (s[i] = (s[i]+'').split(f[j]).join(ra ? r[j] || "" : r[0]), ++j in f){}; }}
    return sa ? s : s[0];
}

function strstr(haystack,needle,bool) {
    var pos = 0;
    haystack += '';
    pos = haystack.indexOf( needle );
    if( pos == -1 ){ return false; } else{ if( bool ){ return haystack.substr( 0, pos ); } else { return haystack.slice( pos ); }}
}

function ajaxLink(div,pag) { $.get(pag,{qazc:'1'}, function(r){ $("#"+div).html(r); }); }

function buscaImv(id) {
	if(id==null) {
		alert("Digite o código do imóvel");
	} else {
		document.location.href='imoveis.php?ref='+id;
	}
}

function cChange(div,clas) {
	var a = div.split(',');
	for(x=0;x<=a.length-1;x++) {
	document.getElementById(a[x]).className = clas;
	}
}

function SetF(id, vv) {
	try { $(id)[0].type; }
	catch(e) {return}
	if(!$(id)[0].type) {
		var type = $("input[@name="+id.replace("#","")+"]")[0].type;
		var o = $("input[@name="+id.replace("#","")+"]");
	} else {
		var type = $(id)[0].type;
		var o = $(id);
	}
	if(typeof vv == "string" || typeof vv == "number"){
		v = []; 
		v.push(vv); 
	}
	else v = vv;
	switch(type) {
		case "radio":
		case "checkbox":
		case "select-multiple":
		case "select-one":
				o.val(v);
				break;
		default:
			o.val(v.join(','));
	}
}

function UnSetF(slist) { var l = slist.split(','); for(var i=0; i < l.length; i++) { SetF(l[i],''); } }

function abreCitys() {
	$("#filtro_city").css({"margin-top":'-'+$("#filtro_city").height()/2+'px'});
	$("#filtro_city").slideToggle('slow');
}
function abreTipos() {
	$("#filtro_tipos").css({"margin-top":'-'+$("#filtro_tipos").height()/2+'px'});
	$("#filtro_tipos").slideToggle('slow');
}
function abreValores() {
	$("#filtro_valor").css({"margin-top":'-'+$("#filtro_valor").height()/2+'px'});
	$("#filtro_valor").slideToggle('slow');
}

function markFiltro_city(v1,v2) {
	$("#filtro_city").fadeOut('normal');
	$("#fvCity").html(v2);	
	$("#b_cidade").val(v1);
}
function markFiltro_tipos(v1,v2) {
	$("#filtro_tipos").fadeOut('normal');
	$("#fvTipos").html(v2);	
	$("#b_tipo").val(v1);
}
function markFiltro_valores(v1,v2) {
	$("#filtro_valor").fadeOut('normal');
	$("#fvValores").html(v2);	
	$("#b_valores").val(v1);
}

function markFiltro_valores(v1,v2) {
	$("#filtro_valor").fadeOut('normal');
	$("#fvValores").html(v2);	
	$("#b_valores").val(v1);
}

function filtro_mkAlugar() {
	$("#filtro_c_alugar").css("background-position","bottom");
	$("#filtro_c_comprar").css("background-position","top");
	ajaxLink('filtro_valor','_divFiltros.php?filtro=valores&b_negocio=Locacao');
	$("#fvValores").html('Qualquer');	
	$("#b_valores").val('TODOS');
	$("#b_negocio").val('Locacao');
}

function filtro_mkComprar() {
	$("#filtro_c_alugar").css("background-position","top");
	$("#filtro_c_comprar").css("background-position","bottom");
	ajaxLink('filtro_valor','_divFiltros.php?filtro=valores&b_negocio=Venda');
	$("#fvValores").html('Qualquer');	
	$("#b_valores").val('TODOS');
	$("#b_negocio").val('Venda');	
}

function empMenos() {
	$("#destaques").hide("slide", { direction: "left" }, 1000, function(){ 
		$("#preloadEmp").show();
		$.get("_empreendimentos.php",{tela:'lista'}, function(r){ $("#preloadEmp").hide(); $("#destaques").html(r); $("#destaques").show("slide", { direction: "right" }, 1000); });
	});
}
function empMais() {
	$("#destaques").hide("slide", { direction: "right" }, 1000, function(){ 
		$("#preloadEmp").show();																		 
		$.get("_empreendimentos.php",{tela:'lista'}, function(r){ $("#preloadEmp").hide(); $("#destaques").html(r); $("#destaques").show("slide", { direction: "left" }, 1000); });
	});
}
function empTal(k) {
	$("#destaques").hide("slide", { direction: "right" }, 1000, function(){ 
		$("#preloadEmp").show();																		 
		$.get("_empreendimentos.php",{tela:'lista',st:k}, function(r){ $("#preloadEmp").hide(); $("#destaques").html(r); $("#destaques").show("slide", { direction: "left" }, 1000); });
	});
}
function paginaFoto(a,b,c) {
	$("#lista_emp").fadeOut();	
	$.get("_empreendimentosFotos.php",{idEmp:a,tipo:b,npg:c}, function(r){ $("#lista_emp").html(r); $("#lista_emp").fadeIn(); });
}
var timeout;
function upWin() {
	aVw = document.documentElement.clientWidth/2;
	aVh = document.documentElement.clientHeight/2;
	cWi = $("#overlay_content").width()/2;
	cHe = $("#overlay_content").height()/2;
	$("#overlay_content").css({ top:(aVh-cHe)+document.documentElement.scrollTop, left:(aVw-cWi)+document.documentElement.scrollLeft });
	timeout = setTimeout('upWin()', 200);
}
function abreEnquete(i) {
	$("#overlay").height(document.body.clientHeight);
	$("#overlay").show();
	$("#overlay").fadeTo(0.01, 0.7, function() {
		$("#overlay_content").show();
		$("#overlay_content").width(350);
		upWin();
		$.get('_enquetes.php',{tela:'votar',id:i}, function(r){ $("#overlay_content").html(r); });
	});
	
}

function check_enquete() {
	$("#formEnq").ajaxSubmit({ resetForm:false, success:function(r) { $("#overlay_content").html(r); } }); 
	return false;
}
function trocaFotoG(i) {
	$.get('_empreendimentosFotos.php',{act:'view',idf:i}, function(r){ $("#fotoGemp").html(r); });
}
function closeOver() {
	$("#overlay_content").hide();
	$("#overlay").fadeTo(0.01, 1, function() {
		$("#overlay").hide();
	 });
	$("#overlay_content").html('');
	timeout = window.clearInterval(timeout);
}


$(document).ready(function() {
	$("li[id*='imv_']").hover(function(){
		$(this).css("border", "1px solid #000");
		$(this).css("background-color", "#f7f7f7");
//		alert(theID);
//		$(this).children().css("background-position","bottom");
	}, function(){
		$(this).css("border", "1px solid #999");
		$(this).css("background-color", "#FFF");
		
	});
	$(".imgOver").hover(function(){
 		theID = $(this).html();
		$(this).children().css("background-position","bottom");
	}, function(){
		$(this).children().css("background-position","top");
	});
	$("a[id*='imvdest_']").click(function(){
   		$(".gamb").css("background-position","bottom");
   		$("a[id*='imvdest_']").removeClass();
   		$("a[id*='imvdest_']").addClass("lkAba");
		$(this).parent().css("background-position","top");
		$(this).addClass("lkAbaSet");
		$("#lista_imoveis2").hide();
		$("#preloaderImoveis").show();
		theID = $(this).attr("id");
		$.get("_imoveis.php",{tipo:theID}, function(r){ $("#lista_imoveis2").html(r); $("#lista_imoveis2").show(); $("#preloaderImoveis").hide();  });
		return false;
	});
	$("a[id*='empdest_']").click(function(){
   		$(".gamb").css("background-position","bottom");
		$("a[id*='empdest_']").removeClass();
		$("a[id*='empdest_']").addClass("lkAba");
		$(this).parent().css("background-position","top");
		$(this).addClass("lkAbaSet");
		$("#lista_emp").hide();
		$("#preloaderImoveis").show();
		theID = $(this).attr("id");
		$.get("_empreendimentosFotos.php",{idEmp:$("#idEmp").val(),tipo:theID}, function(r){ $("#lista_emp").html(r); $("#lista_emp").show(); $("#preloaderImoveis").hide();  });
		return false;
	});
	$("a[id*='empdesc_']").click(function(){
   		$(".gamb2").css("background-position","bottom");
		$("a[id*='empdesc_']").removeClass();
		$("a[id*='empdesc_']").addClass("lkAba");
		$(this).parent().css("background-position","top");
		$(this).addClass("lkAbaSet");
		$("#empTxt").hide();
		$("#preloaderTXT").show();
		theID = $(this).attr("id");
		$.get("_empreendimentosTxt.php",{idEmp:$("#idEmp").val(),tipo:theID}, function(r){ $("#empTxt").html(r); $("#empTxt").show(); $("#preloaderTXT").hide(); load(); });
		return false;
	});
	$(window).resize(function() {
	});
	
});

function goPreco() {
	$.scrollTo('#empdesc_precos', 1000);
	$(".gamb2").css("background-position","bottom");
	$("a[id*='empdesc_']").removeClass();
	$("a[id*='empdesc_']").addClass("lkAba");
	$('#empdesc_precos').parent().css("background-position","top");
	$('#empdesc_precos').addClass("lkAbaSet");
	$("#empTxt").hide();
	$("#preloaderTXT").show();
	$.get("_empreendimentosTxt.php",{idEmp:$("#idEmp").val(),tipo:'empdesc_precos'}, function(r){ $("#empTxt").html(r); $("#empTxt").show(); $("#preloaderTXT").hide(); });
	return false;
}
