function viewFotos(npixeis){
	var pos_left = findPos(document.getElementById('div_buttons'))[0];	
	var pos_top = findPos(document.getElementById('div_buttonstop'))[1];	

	if(npixeis > 0){
		window.scrollTo("0", "425");
		showBlockDiv();
		document.getElementById('div_imovel_fotos').style.top = pos_top + "px";
		document.getElementById('div_imovel_fotos').style.left = pos_left + "px";	
	}else{	
		document.getElementById('div_imovel_fotos').style.top = npixeis + "px";
		document.getElementById('div_imovel_fotos').style.left = npixeis + "px";	
	}

	showFoto(0);
	
	Drag.init(document.getElementById("div_imovel_fotos"));
}

function viewRecomendar(npixeis){
	document.getElementById("divEnvFeedback").innerHTML = "";	
	document.getElementById("divButtonRecomendar").style.visibility = "visible";
	
	var pos_left = findPos(document.getElementById('div_buttons'))[0];	
	
	if(npixeis > 0){
		showBlockDiv();
		document.getElementById('div_recomendar').style.left = pos_left + "px";	
		document.getElementById('div_recomendar').style.top = "310px";
		window.scrollTo("0", "50");
	}else{	
		document.getElementById('div_recomendar').style.top = npixeis + "px";
		document.getElementById('div_recomendar').style.left = npixeis + "px";	
	}
}

function closeRecomendar(){
	hideBlockDiv();	
	viewRecomendar(-10000);
}

function donothing(){
	i=0;
}

function closeFotos(){
	hideBlockDiv();
	
	viewFotos(-10000);
	stopSlideShow();
	document.getElementById('index').value = -1;
}

function showFoto(index){
	document.getElementById('foto').src = arrFotos[index];	
	if(arrLegendas[index] == null || arrLegendas[index] == "null") arrLegendas[index] = "";
	document.getElementById('legenda').innerHTML = arrLegendas[index];

	document.getElementById('link_previous').className = "link12green";
	document.getElementById('link_previous').href = "javascript:previousFoto(); stopSlideShow();";
	
	if(document.getElementById('n_fotos').value > 1){	
		document.getElementById('link_next').className = "link12green";
		document.getElementById('link_next').href = "javascript:nextFoto(); stopSlideShow();";
	}
		
	document.getElementById("numFotos").innerHTML = (index+1) +" de " + document.getElementById('n_fotos').value;
	
}

function nextFoto(){
	next_index = parseInt(document.getElementById('index').value) + 1;
	
	if(next_index > document.getElementById('n_fotos').value - 1){
		next_index = 0;
	}
	
	if(next_index <= document.getElementById('n_fotos').value - 1){
		showFoto(next_index);
	}
	
	document.getElementById('index').value = next_index;	
}

function previousFoto(){
	previous_index = parseInt(document.getElementById('index').value) - 1;
	n_fotos = document.getElementById('n_fotos').value;
	
	if(previous_index < 0){
		previous_index = n_fotos - 1; 
	}
	
	if(previous_index >= 0){
		showFoto(previous_index);
	}
	document.getElementById('index').value = previous_index;
}

function startSlideShow(){
	if (intervId == 0){
		intervId = self.setInterval('slidePic()', 4000);
		document.getElementById("link_slide").href = "javascript:stopSlideShow();";
		document.getElementById("link_slide").innerHTML = "Slide Show [&nbsp;||&nbsp;]";
	}
}
																				
function stopSlideShow(){
	if (intervId != 0){
		self.clearInterval(intervId);
		document.getElementById("link_slide").href = "javascript:startSlideShow();";
		document.getElementById("link_slide").innerHTML = "Slide Show [&nbsp;>&nbsp;]";
		intervId = 0;
	}
}																							


function slidePic() { 
	if (document.getElementById('index').value >= arrFotos.length -1 )
		document.getElementById('index').value = -1;
		
	nextFoto();
}

function showBlockDiv() { 
	document.getElementById('div_block').style.left = "0px";
	document.getElementById('div_block').style.top = "0px";
	document.getElementById('div_block').style.width = screen.width + "px";
	document.getElementById('div_block').style.height = (screen.height * 2.5) + "px";
}

function hideBlockDiv() { 
	document.getElementById('div_block').style.left = "-10000px";
	document.getElementById('div_block').style.top = "-10000px";
	document.getElementById('div_block').style.width = "0px";
	document.getElementById('div_block').style.height = "0px";
}

function viewFaqConcurso(npixeis){
	var pos_left = findPos(document.getElementById('div_concurso'))[0];	
	var pos_top = findPos(document.getElementById('div_concurso'))[1];	

	if(npixeis > 0){
		showBlockDiv();
		document.getElementById('div_faq_concurso').style.top = pos_top + "px";
		document.getElementById('div_faq_concurso').style.left = pos_left + "px";	
	}else{
		document.getElementById('div_faq_concurso').style.top = npixeis + "px";
		document.getElementById('div_faq_concurso').style.left = npixeis + "px";	
	}
	showFoto(0);
	
	Drag.init(document.getElementById("div_faq_concurso"));
}

function closeFaqConcurso(){
	hideBlockDiv();
	viewFaqConcurso(-10000);
}

function viewFaqLeilao(npixeis){
	var pos_left = findPos(document.getElementById('div_leilao'))[0];	
	var pos_top = findPos(document.getElementById('div_leilao'))[1];	

	if(npixeis > 0){
		showBlockDiv();
		document.getElementById('div_faq_leilao').style.top = pos_top + "px";
		document.getElementById('div_faq_leilao').style.left = pos_left + "px";	
	}else{
		document.getElementById('div_faq_leilao').style.top = npixeis + "px";
		document.getElementById('div_faq_leilao').style.left = npixeis + "px";	
	}
	showFoto(0);
	
	Drag.init(document.getElementById("div_faq_leilao"));
}

function closeFaqLeilao(){
	hideBlockDiv();
	viewFaqLeilao(-10000);
}

function viewFaqCaixaArrendamento(npixeis){
	var pos_left = findPos(document.getElementById('div_caixa_arrendamento'))[0];	
	var pos_top = findPos(document.getElementById('div_caixa_arrendamento'))[1];	

	if(npixeis > 0){
		showBlockDiv();
		document.getElementById('div_faq_caixa_arrendamento').style.top = pos_top + "px";
		document.getElementById('div_faq_caixa_arrendamento').style.left = pos_left + "px";	
	}else{
		document.getElementById('div_faq_caixa_arrendamento').style.top = npixeis + "px";
		document.getElementById('div_faq_caixa_arrendamento').style.left = npixeis + "px";	
	}
	showFoto(0);
	
	Drag.init(document.getElementById("div_faq_caixa_arrendamento"));
}

function closeFaqCaixaArrendamento(){
	hideBlockDiv();
	viewFaqCaixaArrendamento(-10000);
}

//PEDIDOS DE CONTACTO
function pedidoSent() {
	document.getElementById("divFeedback").innerHTML = 
	"<center><span style=\"color:#2a7800;\">O seu pedido de contacto foi enviado com sucesso.</span></center>";	
}

function pedidoError() {		
	document.getElementById("divFeedback").innerHTML = 
		"<center>Lamentamos mas não foi possível enviar o seu pedido!<br/>" +
		"Por favor aguarde um momento e tente novamente.</center><br/>" + document.getElementById("divFeedback").innerHTML;
}	

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function showResposta(campo, num_reposta, bool_new){
	for(i=1; i!=6; i++){
		if(i != num_reposta && num_reposta > 0){			
			try{
				if(bool_new){
					document.getElementById(campo + i).innerHTML = "";
					document.getElementById(campo + i).height = "0px";
				}
			}catch(e){}
		}else{
			try{
				document.getElementById(campo + i).innerHTML = document.getElementById("hidden_" +campo + i).value;
			}catch(e){}
		}
	}
}

function viewImovel(imovel_id, rs_offset_imo) {
	document.getElementById('rs_offset').value = rs_offset_imo;
	document.getElementById('frmPagination').action = "/comprar-alugar/casa-apartamento-andar-imovel.jsp?id=" + imovel_id;
	document.getElementById('frmPagination').submit();
}
