function question( pergunta )
{
	if ( confirm( pergunta ) ) {
		return true;
	} else {
		return false;
	}
}

// Imovel busca --
function checkPostBuscaIm()
{
	var objForm  = document.f;
	var building = objForm.building.value;
	var business = objForm.business.value;
	var num      = objForm.num.value;
	var keyword  = objForm.keyword.value;
	
	if ( building=="" && business=="" && num=="0" && keyword=="" ) {
		alert( 'Você deve escolher ao menos um filtro para a busca de imóveis ( Tipo ou Negócio ou Número de Quartos ou Palavra chave )\n Por favor tente novamente.' );
		return false;
	} else {
		return true;
	}
	
}
// ------------------------

// ------------ SCRIPS PARA PÁGINAS --------------------

var oldId = '';
function openFolder( id )
{
	oldId = id;
	var obj = document.getElementById( id );
	obj.style.display = ( obj.style.display == '' )? "none" : "";
}

function newFolder()
{
	var id = oldId.replace( 'f_','' );
	location = '/admin/pages/?show=editFolder&sub=5&id_fk_folder='+id;
}

function newPage()
{
	var id = oldId.replace( 'f_','' );
	location = '/admin/pages/?show=editPage&sub=5&id_fk_folder='+id;
}

function newLink()
{
	var id = oldId.replace( 'f_','' );
	location = '/admin/pages/?show=editLink&sub=5&id_fk_folder='+id;
}

function showPages()
{
	var id = oldId.replace( 'f_','' );
	location = '/admin/pages/?show=index&sub=5&id_fk_folder='+id;
}

function sendUrl( url )
{
	window.opener.document.getElementById( 'f_href' ).value = url;
	window.close();
}

// -------- Fim scrips Páginas ---------------------------


// Abre uma janela popup
function popup ( url, nome, largura, altura, posicao, resize, barras ) {
	if ( posicao == 0 ) {
		posleft = 20;
		postop  = ( screen.height ) ? ( screen.height - altura ) / 2 - 50 : 100;
	} else if ( posicao == 1 ) {
		posleft = ( screen.width ) ? ( screen.width - largura ) / 2 : 100;
		postop  = ( screen.height ) ? ( screen.height - altura ) / 2 - 50 : 100;
	} else if (posicao == 2 ) {
		posleft = ( screen.width ) ? ( screen.width - largura ) - 28 : 100;
		postop  = ( screen.height ) ? ( screen.height - altura ) / 2 - 50 : 100;
	}
	opBarras = ( barras ) ? "yes" : "no";
	opResize = ( resize ) ? "yes" : "no";

	settings = 'z-lock=yes, width=' + largura + ', height=' + altura + ', top=' + postop + ', left=' + posleft + ', scrollbars=' + opBarras + ', location=no, directories=no, status=no, menubar=no, toolbar=no, resizable=' + opResize;
	window.open( url, nome, settings );
}

// -------------- Script de News --------------------

var toScroll=new Array()
var ie=document.all
var dom=document.getElementById
var firstNews_obj;
var secondNews_obj;

function newsScroll(name){
  var c=this; c.name=name; c.mc=0; c.i=2;
  return this;
}

newsScroll.prototype.addItem = function(text,link,font,fontSize,fontStyle){
  var c = this;
  if (link !=''){
    if (font != '')
      toScroll[c.mc]="<a href='"+link+"'><font face='"+font+"' size='"+fontSize+"' Class='"+fontStyle+"'>"+text+"</font></a>";
    else
      toScroll[c.mc]="<a href='"+link+"'><font Class='"+fontStyle+"'>"+text+"</font></a>";
  }
  else { 
    if (font != '')
      toScroll[c.mc]="<font face='"+font+"' size='"+fontSize+"' Class='"+fontStyle+"'>"+text+"</font>";
    else
      toScroll[c.mc]="<font Class='"+fontStyle+"'>"+text+"</font>";
  }
  c.mc++;
}

newsScroll.prototype.construct = function(){
  var c = this; theWidth = c.scrollerwidth; theHeight=c.scrollerheight; thebgColor = c.scrollerbgcolor; theBackground =c.scrollerbackground; theDelay=c.scrollerdelay;
  scroll_obj=eval(c.name);        
  if (ie||dom){
    document.writeln('<div id="main2" style="position:relative;width:'+theWidth+';height:'+theHeight+';overflow:hidden;background-color:'+thebgColor+' ;background-image:url('+theBackground+')">')
    document.writeln('<div style="position:absolute;width:'+theWidth+';height:'+theHeight+';clip:rect(0 '+theWidth+' '+theHeight+' 0);left:0;top:0">')
    document.writeln('<div id="firstNews" style="position:absolute;width:'+theWidth+';left:0;top:1">')
    document.write(toScroll[0])
    document.writeln('</div>')
    document.writeln('<div id="secondNews" style="position:absolute;width:'+theWidth+';left:0;top:0;visibility:hidden">')
    document.write(toScroll[dyndetermine=(toScroll.length==1)? 0 : 1])
    document.writeln('</div>')
    document.writeln('</div>')
    document.writeln('</div>')
  }
}

newsScroll.prototype.move = function(whichdiv){
  var c = this; theDelay = c.scrollerdelay; theHeight = c.scrollerheight; 
  scroll_obj=eval(c.name);
  tdiv=eval(whichdiv)

  if (parseInt(tdiv.style.top)>0&&parseInt(tdiv.style.top)<=5){
    tdiv.style.top=0+"px"
    setTimeout("scroll_obj.move(tdiv)",theDelay)
    setTimeout("scroll_obj.move2(secondNews_obj)",theDelay)
    //document.write('Got Milk?')
  return
  }
  if (parseInt(tdiv.style.top)>=tdiv.offsetHeight*-1){
    tdiv.style.top=parseInt(tdiv.style.top)-5+"px"
    setTimeout("scroll_obj.move(tdiv)",50)
  }
  else {
    tdiv.style.top=parseInt(theHeight)+"px"
    tdiv.innerHTML=toScroll[c.i]
    if (c.i==toScroll.length-1)
      c.i=0
    else
      c.i++
  }
}

newsScroll.prototype.move2 = function(whichdiv){
  var c = this; theDelay = c.scrollerdelay; theHeight= c.scrollerheight;
  scroll_obj=eval(c.name);
  tdiv2=eval(whichdiv)

  if (parseInt(tdiv2.style.top)>0&&parseInt(tdiv2.style.top)<=5){
    tdiv2.style.top=0+"px"
    setTimeout("scroll_obj.move2(tdiv2)",theDelay)
    setTimeout("scroll_obj.move(firstNews_obj)",theDelay)
    return
  }
  if (parseInt(tdiv2.style.top)>=tdiv2.offsetHeight*-1){
    tdiv2.style.top=parseInt(tdiv2.style.top)-5+"px"
    setTimeout("scroll_obj.move2(secondNews_obj)",50)
  }
  else {
    tdiv2.style.top=parseInt(theHeight)+"px"
    tdiv2.innerHTML=toScroll[c.i]
    if (c.i==toScroll.length-1)
      c.i=0
    else
      c.i++
  }
}

newsScroll.prototype.startScroll = function(){
  var c = this;
  scroll_obj=eval(c.name);        
  
  if (toScroll.length >2)
    c.i = 2;
  else
    c.i = 0;
  
  firstNews_obj=ie? firstNews : document.getElementById("firstNews")
  secondNews_obj=ie? secondNews : document.getElementById("secondNews")
  setTimeout("scroll_obj.move(firstNews_obj)",c.scrollerDelay);
  secondNews_obj.style.top=theHeight;
  secondNews_obj.style.visibility='visible'
}
// ---------------------------------------------

// Galeria --------------------------------
var id;
function triggerMenu( id_menu )
{
	var obj = document.getElementById( id_menu );
	
	// Esconde o id antigo
	hideMenu();
	
	obj.style.display = ( obj.style.display == 'none' ? '' : 'none' );
	id = id_menu;
}

function hideMenu()
{
	if ( id ) {
		document.getElementById( id ).style.display = 'none';
	}
	
}

function showNext( id )
{
	document.getElementById( 'item'+id ).style.display='';
}

function printPic( id )
{
	var obj   = document.getElementById( 'file'+id );
	var addrs = obj.value;
	
	if ( addrs ) {
		addrs = 'file://' + addrs;
		document.getElementById( 'pic'+id ).src = addrs;
	}
}

function cancelImage( id )
{
	var obj = document.getElementById( 'file' + id );
	obj.focus();
	obj.value.replace('C', '');
	
}

function editPic( id, pTop )
{
	// Trata posicao
	// Cria o numero
	var position  = pTop * 100;
	document.getElementById( 'divEdit' ).style.top  = ( 100 + position );
	
	document.getElementById( 'divEdit' ).style.display = '';
	var obj = document.getElementById( "iframEdit" );
	obj.src="?show=editPic&id_foto=" + id;
}

function closeEditPic()
{
	parent.document.getElementById( "iframEdit" ).src='';
	parent.document.getElementById('divEdit').style.display = 'none';
}

// ----------------------------------------
