var url_site ='/';

function zerarAbas()
{
	$("#aba_1").attr('class', 'aba_inactive');
	$("#aba_2").attr('class', 'aba_inactive');
	$("#aba_3").attr('class', 'aba_inactive');
	
	$("#aba_img_1").attr('class', 'img_inactive_inactive');
	$("#aba_img_2").attr('class', 'img_inactive_inactive');
	$("#aba_img_3").attr('class', 'img_inactive');
}

function selecionaAba(aba)
{
	zerarAbas();
	
	switch (aba)
	{		
		case 'aba_2':
			$("#aba_img_1").attr('class', 'img_inactive_active');
			$("#aba_2").attr('class', 'aba_active');
			$("#aba_img_2").attr('class', 'img_active_inactive');
			$("#abaTipoNegocio").attr('value', 'venda');
			break;

		case 'aba_3':
			$("#aba_img_2").attr('class', 'img_inactive_active');
			$("#aba_3").attr('class', 'aba_active');
			$("#aba_img_3").attr('class', 'img_active');
			$("#abaTipoNegocio").attr('value', 'lancamento');
			break;		

		case 'aba_1':
		default:
			$("#aba_1").attr('class', 'aba_active');
			$("#aba_img_1").attr('class', 'img_active_inactive');
			$("#abaTipoNegocio").attr('value', 'aluguel');
			break;
	}
	
	//changeRange();
}

function formEmpty(object, value, type){
	
	switch(type){
		case "focus":
			if(object.value==value)
				object.value=''
			else
				object.value=object.value
		break;
		case "blur":
			if(object.value=='')
				object.value=value
			else
				object.value=object.value
		break;
	}
	
}

function mostrar(id){
	
	doc = document.getElementById(id);
	
	if(doc.style.display=='none'){
		doc.style.display='';
	} else{
		doc.style.display='none';
	}
}

function showbox(e, texto) { 
 if (!e) 
   var e = window.event; 
   var linkID = e.srcElement? e.srcElement.id : this.id; 
   var helpbox = document.getElementById('helpbox'); 
 
   helpbox.innerHTML = texto; 
   helpbox.style.display = 'block'; 
 
   var posx = (typeof e.pageX!= 'undefined')? e.pageX : e.clientX + (document.documentElement? document.documentElement.scrollLeft  
: document.body.scrollLeft); 

 var posy = (typeof e.pageY!= 'undefined')? e.pageY  
: e.clientY + (document.documentElement? document.documentElement.scrollTop  
: document.body.scrollTop); 

helpbox.style.top = posy - 20 + 'px'; 
helpbox.style.left = posx + 10 + 'px'; 

} 


function hidebox() { 
 document.getElementById('helpbox').style.display = 'none'; 
} 

function avancarFoto(){
	if((atual+qPorVez)<=num_fotos){
		document.getElementById('foto'+atual).style.display='none';
		document.getElementById('foto'+(atual+qPorVez)).style.display='block';
		
		if((atual+qPorVez)==num_fotos) document.getElementById('clicRight').style.display='none';
		atual++;
		if(atual>1) document.getElementById('clicLeft').style.display='block';
	} else{}
}
function retrocederFoto(){
	if(atual>=1){
		document.getElementById('foto'+(atual-1)).style.display='block';
		document.getElementById('foto'+((atual+qPorVez)-1)).style.display='none';
		
		document.getElementById('clicRight').style.display='block';
		atual--;
		if(atual<=1) document.getElementById('clicLeft').style.display='none';
	} else{}
}

try{
    xmlhttp = new XMLHttpRequest();
}catch(ee){
    try{
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }catch(e){
        try{
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }catch(E){
            xmlhttp = false;
        }
    }
}

ajaxocupado = function() {
    estadoAtual = this.xmlhttp.readyState;
    return (estadoAtual && (estadoAtual < 4));
}

/*function loadImage(id,imovelid){
	//Abre a url
	xmlhttp.open("GET", url_site+"imovel_foto.php?id="+id+"&imovelid="+imovelid,true);
	div = document.getElementById('divImgFoto');
	//div.innerHTML='<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td width="20"><img src="imagens/load.gif" width="16" height="16" /></td><td>Aguarde enquanto o aplicativo é carregado!</td></tr></table>';
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4){
			div.innerHTML=xmlhttp.responseText;
		}
	}
	xmlhttp.send(null)
	
	//return false;
}*/

function loadImage(src,srcFull,id,title){
	preImg = new Image();
	preImg.src = src;
	
	document.getElementById(id).src = preImg.src;
	document.getElementById(id+'Link').href = srcFull;
	document.getElementById(id+'Link').title = title;
}

function FormataReais(fld, milSep, decSep, e) {
	var sep = 0;
	var key = '';
	var i = j = 0;
	var len = len2 = 0;
	var strCheck = '0123456789';
	var aux = aux2 = '';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	if (whichCode == 13) return true;
		key = String.fromCharCode(whichCode);  // Valor para o código da Chave
	if (strCheck.indexOf(key) == -1) return false;  // Chave inválida
		len = fld.value.length;
		for(i = 0; i < len; i++)
			if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;
			aux = '';
		for(; i < len; i++)
		if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
			aux += key;
			len = aux.length;
		if (len == 0) fld.value = '';
		if (len == 1) fld.value = '0'+ decSep + '0' + aux;
		if (len == 2) fld.value = '0'+ decSep + aux;
		if (len > 2) {
			aux2 = '';
			for (j = 0, i = len - 3; i >= 0; i--) {
			if (j == 3) {
		aux2 += milSep;
	j = 0;
	}
	aux2 += aux.charAt(i);
	j++;
	}
	fld.value = '';
	len2 = aux2.length;
	for (i = len2 - 1; i >= 0; i--)
	fld.value += aux2.charAt(i);
	fld.value += decSep + aux.substr(len - 2, len);
	}
	return false;
}

function mascara(o,f){
    v_obj=o
    v_fun=f
    setTimeout("execmascara()",1)
}

function execmascara(){
    v_obj.value=v_fun(v_obj.value)
}
 
function Mleech(v){
    v=v.replace(/o/gi,"0")
    v=v.replace(/i/gi,"1")
    v=v.replace(/z/gi,"2")
    v=v.replace(/e/gi,"3")
    v=v.replace(/a/gi,"4")
    v=v.replace(/s/gi,"5")
    v=v.replace(/t/gi,"7")
    return v
}
 
function MsoNumeros(v){
    return v.replace(/\D/g,"")
}
 
function Mtelefone(v){
    v=v.replace(/\D/g,"")                 //Remove tudo o que não é dígito
    v=v.replace(/^(\d\d)(\d)/g,"($1) $2") //Coloca parênteses em volta dos dois primeiros dígitos
    v=v.replace(/(\d{4})(\d)/,"$1-$2")    //Coloca hífen entre o quarto e o quinto dígitos
    return v
}
 
function Mcpf(v){
    v=v.replace(/\D/g,"")                    //Remove tudo o que não é dígito
    v=v.replace(/(\d{3})(\d)/,"$1.$2")       //Coloca um ponto entre o terceiro e o quarto dígitos
    v=v.replace(/(\d{3})(\d)/,"$1.$2")       //Coloca um ponto entre o terceiro e o quarto dígitos
                                             //de novo (para o segundo bloco de números)
    v=v.replace(/(\d{3})(\d{1,2})$/,"$1-$2") //Coloca um hífen entre o terceiro e o quarto dígitos
    return v
}
 
function Mcep(v){
    v=v.replace(/D/g,"")                //Remove tudo o que não é dígito
    v=v.replace(/^(\d{5})(\d)/,"$1-$2") //Esse é tão fácil que não merece explicações
    return v
}
 
function Mcnpj(v){
    v=v.replace(/\D/g,"")                           //Remove tudo o que não é dígito
    v=v.replace(/^(\d{2})(\d)/,"$1.$2")             //Coloca ponto entre o segundo e o terceiro dígitos
    v=v.replace(/^(\d{2})\.(\d{3})(\d)/,"$1.$2.$3") //Coloca ponto entre o quinto e o sexto dígitos
    v=v.replace(/\.(\d{3})(\d)/,".$1/$2")           //Coloca uma barra entre o oitavo e o nono dígitos
    v=v.replace(/(\d{4})(\d)/,"$1-$2")              //Coloca um hífen depois do bloco de quatro dígitos
    return v
}
 
function Mromanos(v){
    v=v.toUpperCase()             //Maiúsculas
    v=v.replace(/[^IVXLCDM]/g,"") //Remove tudo o que não for I, V, X, L, C, D ou M
    //Fonte: http://www.diveintopython.org/refactoring/refactoring.html
    while(v.replace(/^M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$/,"")!="")
        v=v.replace(/.$/,"")
    return v
}
 
function Msite(v){
    v=v.replace(/^http:\/\/?/,"")
    dominio=v
    caminho=""
    if(v.indexOf("/")>-1)
        dominio=v.split("/")[0]
        caminho=v.replace(/[^\/]*/,"")
    dominio=dominio.replace(/[^\w\.\+-:@]/g,"")
    caminho=caminho.replace(/[^\w\d\+-@:\?&=%\(\)\.]/g,"")
    caminho=caminho.replace(/([\?&])=/,"$1")
    if(caminho!="")dominio=dominio.replace(/\.+$/,"")
    v="http://"+dominio+caminho
    return v
}

function number_format( number, decimals, dec_point, thousands_sep ) {
    // %        nota 1: Para 1000.55 retorna com precisão 1 no FF/Opera é 1,000.5, mas no IE é 1,000.6
    // *     exemplo 1: number_format(1234.56);
    // *     retorno 1: '1,235'
    // *     exemplo 2: number_format(1234.56, 2, ',', ' ');
    // *     retorno 2: '1 234,56'
    // *     exemplo 3: number_format(1234.5678, 2, '.', '');
    // *     retorno 3: '1234.57'
    // *     exemplo 4: number_format(67, 2, ',', '.');
    // *     retorno 4: '67,00'
    // *     exemplo 5: number_format(1000);
    // *     retorno 5: '1,000'
    // *     exemplo 6: number_format(67.311, 2);
    // *     retorno 6: '67.31'
 
    var n = number, prec = decimals;
    n = !isFinite(+n) ? 0 : +n;
    prec = !isFinite(+prec) ? 0 : Math.abs(prec);
    var sep = (typeof thousands_sep == "undefined") ? ',' : thousands_sep;
    var dec = (typeof dec_point == "undefined") ? '.' : dec_point;
 
    var s = (prec > 0) ? n.toFixed(prec) : Math.round(n).toFixed(prec); //fix for IE parseFloat(0.55).toFixed(0) = 0;
 
    var abs = Math.abs(n).toFixed(prec);
    var _, i;
 
    if (abs >= 1000) {
        _ = abs.split(/\D/);
        i = _[0].length % 3 || 3;
 
        _[0] = s.slice(0,i + (n < 0)) +
              _[0].slice(i).replace(/(\d{3})/g, sep+'$1');
 
        s = _.join(dec);
    } else {
        s = s.replace('.', dec);
    }
 
    return s;
}

function indicar(){
	
	form = document.indicarForm;
	div = document.getElementById('indiqueDiv');
	
	//mensagem = form.mensagem.value;
	amigos = form.amigos.value;
	nome = form.nome.value;
	imovelid = form.imovelid.value;
	//seguranca = form.seguranca.value;
	
	if(amigos=='' || amigos=='Separar os endereços de email por ponto e vírgula'){
		alert('Para enviar suas indicações é necessário que você escreva os e-mails dos seus amigos na lista, separando-os com ponto-vírgula, ex:\n\nfulano@provedor.com.br;ciclano@provedor.com.br');
		return false;
	} else{}
	
	if(nome==''){
		alert("Para enviar suas indicações é necessário que você escreva o seu nome");
		return false;
	} else{}
	
	/*if(seguranca==''){
		alert("Para enviar suas indicações é necessário que você informe o que está escrito na imagem de segurança abaixo do campo nome!");
		return false;
	} else{}*/
			  
	
	div.innerHTML='<div style="text-align:center; padding-top:20px "><img src="'+url_site+'imgs/load.gif" /><br>Aguarde enquanto enviamos sua indicação!</div>'
	
	//Abre a url
    xmlhttp.open("GET", url_site+"enviar_indicacao.php?amigos="+amigos+"&nome="+nome+"&imovelid="+imovelid,true);
	xmlhttp.onreadystatechange=function() {
    if (xmlhttp.readyState==4){
		div.innerHTML = xmlhttp.responseText;
    }
}
xmlhttp.send(null)
	
}
