﻿function enableElement(idElement){
	document.getElementById(element).disabled = false;
}
function setShow(objLayer){
    var objLayers = objLayer.split(',');
    for(i=0; i<objLayers.length; i++){
        if(document.getElementById(objLayers[i]).style.display=="none"){
            document.getElementById(objLayers[i]).style.display="block";
        }
    }
}
function setVisible(objLayer){
    var objLayers = objLayer.split(',');
    for(i=0; i<objLayers.length; i++){
        if(document.getElementById(objLayers[i]).style.visibility=="hidden"){
            document.getElementById(objLayers[i]).style.visibility="visible";
            document.getElementById(objLayers[i]).style.position="";
        }
    }
}
function setShow2(objLayer){
    var objLayers = objLayer.split(',');
    for(i=0; i<objLayers.length; i++){
        if(document.getElementById(objLayers[i]).style.display=="none"){
            document.getElementById(objLayers[i]).style.display="";
        }
    }
}

function setHide(objLayer){
    var objLayers = objLayer.split(',');
    for(i=0; i<objLayers.length; i++){
        if(document.getElementById(objLayers[i]).style.display=="block"||document.getElementById(objLayers[i]).style.display==""){
            document.getElementById(objLayers[i]).style.display="none";
        }
    }
}

function setHidden(objLayer){
    var objLayers = objLayer.split(',');
    for(i=0; i<objLayers.length; i++){
        if(document.getElementById(objLayers[i]).style.visibility=="visible"||document.getElementById(objLayers[i]).style.visibility==""){
            document.getElementById(objLayers[i]).style.visibility="hidden";
            document.getElementById(objLayers[i]).style.position="absolute";
        }
    }
}

function setVisibleFalse(objLayer){
    document.getElementById(objLayer).style.visibility="hidden";

}

function setVisibleTrue(objLayer){
    document.getElementById(objLayer).style.visibility="visible";
}

function disable(objLayer){
    document.getElementById(objLayer).readOnly = true;
    document.getElementById(objLayer).style.background = "#D1D1D1";
}

function enable(objLayer){
    document.getElementById(objLayer).readOnly = false;
    document.getElementById(objLayer).style.background = "";
}

function enableAll(objLayer){
    var objLayers = objLayer.toString().split(',');
    for(i=0; i<objLayers.length; i++){
        document.getElementById(objLayers[i]).readOnly = false;
        document.getElementById(objLayers[i]).style.background = "";
    }
}

function disableAll(objLayer){
    var objLayers = objLayer.toString().split(',');
    for(i=0; i<objLayers.length; i++){
        document.getElementById(objLayers[i]).readOnly = true;
        document.getElementById(objLayers[i]).style.background = "#D1D1D1";
    }
}

function enableCamposCasa(objLayer){
    var idx = objLayer.selectedIndex;
    var selectedValue = objLayer.options[idx].value;
    if(selectedValue == 'condominio'){
        enableAll('vl_condominio,nome_condominio,qtd_casa');
    }else if(selectedValue == 'vila'){
        enableAll('vl_condominio,qtd_casa');
        disableAll('nome_condominio');
    }else{
        disableAll('vl_condominio,nome_condominio,qtd_casa');
    }
}

function enableCamposTerreno(objLayer){
    var idx = objLayer.selectedIndex;
    var selectedValue = objLayer.options[idx].value;
    if(selectedValue == 'condominio'){
        enableAll('nome_condominio');
    }else{
        disableAll('nome_condominio');
    }
}


function trocaClassMapa(obj, classe)
{
	document.getElementById(obj).className = classe;
}

function trocaClassLogged(obj, block){
    if(document.getElementById(block).style.display == 'block'){
        document.getElementById(block).style.display = 'none';
    }else{
        document.getElementById(block).style.display = 'block';
    }
}

function trocarBackground(obj, cor){
    document.getElementsByName(obj).style.background = cor;
}

function ajustaBackgroundModal(objs, obj, qtd){

    tam = document.getElementById(obj).offsetWidth;
    document.getElementById(obj).style.width = "auto";
    var objLayers = objs.toString().split(',');
    for(i=0; i<objLayers.length; i++){
        document.getElementById(objLayers[i]).style.width = (tam-qtd)+"px";
    }
}

function openModal(id){
	openModalGeral(id, '#mask');
}
function openModalGeral(id, idMask){	
	//Area da Mascara
	var maskWidth = jQuery(window).width();
	var maskHeight = jQuery(document).height();
	
	//Get the window height and width
	var winW = jQuery(window).width();
	var winH = jQuery(window).height();
	
	jQuery(idMask).css({'width':maskWidth,'height':maskHeight});
	jQuery(idMask).fadeIn(400);	
	jQuery(idMask).fadeTo("slow",0.7);	

	jQuery(id).css('top',  winH/2 - jQuery(id).height()/2 + jQuery(window).scrollTop());
	jQuery(id).css('left', winW/2-jQuery(id).width()/2);
	jQuery(id).css('position', 'absolute');       
	jQuery(id).fadeIn(2000);
	
	//Atualiza a posição do modal de acordo com o scroll da página (Necessário para funcionar no IE6)
	jQuery(window).scroll(function() {
		
		jQuery(id).css("top", winH/2-jQuery(id).height()/2 + jQuery(window).scrollTop() + "px");
	});
} 

function openModalStatus(id){
	openModalGeral(id, '#maskStatus');
	
}

function openModalAdvertisementHome(id, idObj){
	var maskHeight = jQuery(window).height();
	var maskWidth = jQuery(window).width();


	jQuery('#mask').fadeIn(1000);	
	jQuery('#mask').fadeTo("slow",0.7);	

	//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('top',  winH/2-jQuery(id).height()/2);
	jQuery(id).css('left', winW/2-jQuery(id).width()/2);
	jQuery(id).css('position', 'absolute');         

	jQuery(id).fadeIn(2000);
	
	jQuery(window).scroll(function() {
		jQuery(id).css("top", winH/2-jQuery(id).height()/2 - jQuery(window).scrollTop() + "px");
	});
} 

//function openModalPosicionado(id, objFixo){
//	var maskHeight = jQuery(document).height();
//	var maskWidth = jQuery(window).width();
////	left = (getPosicaoElemento(objFixo).left-10);
//    top = (getPosicaoElemento(objFixo).top+10);
//
//	jQuery('#mask').css({'width':maskWidth,'height':maskHeight});
//
//	jQuery('#mask').fadeIn(1000);	
//	jQuery('#mask').fadeTo("slow",0.7);	
//
//	//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('top',  top-jQuery(id).height()/2);
//	jQuery(id).css('position', 'fixed');         
//	jQuery(id).css('top',  winH/2-$(id).height()/2);
//	jQuery(id).css('left', winW/2-jQuery(id).width()/2);
//	
////	jQuery(id).css('top',  top);
////	jQuery(id).css('left', left);
//	
//
//	jQuery(id).fadeIn(2000); 
//	//setPosicaoElement(objFixo, objPosicionar);
//}

function getPosicaoElemento(elemID){
    var offsetTrail = document.getElementById(elemID);
    var offsetLeft = 0;
    var offsetTop = 0;
    while (offsetTrail) {
        offsetLeft += offsetTrail.offsetLeft;
        offsetTop += offsetTrail.offsetTop;
        offsetTrail = offsetTrail.offsetParent;
    }
    if (navigator.userAgent.indexOf("Mac") != -1 &&
        typeof document.body.leftMargin != "undefined") {
        offsetLeft += document.body.leftMargin;
        offsetTop += document.body.topMargin;
    }
    return {left:offsetLeft, top:offsetTop};
}


//function openModal(id,top){
//	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.7);	
//
//	//Get the window height and width
//	var winH = jQuery(window).height();
//	var winW = jQuery(window).width();
//	jQuery(id).css('position', 'fixed');         
//	jQuery(id).css('top',  winH/2-$(id).height()/2);
//	jQuery(id).css('left', winW/2-jQuery(id).width()/2);
//	
//
//	jQuery(id).fadeIn(2000); 
//	setTimeout("jCarousePictures()",10000);
//}
	

function closeModal(){
	jQuery('#mask').hide();
	jQuery('.window').hide();
}

function closeModalStatus(){
	jQuery('#maskStatus').hide();
	jQuery('.windowStatus').hide();
}

function openProfile(caminho){
	jQuery("#modalTerms").load(caminho);
}
function enter(button,key)
{	
	var pStr = window.event ? key.keyCode : key.which;
	if (pStr == 13){
		 document.getElementById(button).click();
		return false;

	}
}

function buscarCep(event){//45 - 13 - 0
	var key = window.event ? event.keyCode : event.which;
	//BackSpace, Delete, Setas
	if (key == 8) {
        return true;
    }
	if (key > 47 && key < 58) {
        return true;
    }else
    	return false;
}

function autoValidate(button,key,campo){
	var field = document.getElementById(campo).value;
	if (field.length >= 9 && field.indexOf("_")==-1)
		document.getElementById(button).click();
}

function changeFieldPhone(obj, idOther){
	if (obj.value.length == 2 && obj.value.indexOf("_")==-1)
		document.getElementById(idOther).focus();
}


function count_length(textarea, limit){
	var text = textarea.value;
	var textlength = text.length;
	if (textlength > limit) {
		textarea.value = text.substr(0, limit);
		return false;
	}
	else
	{
		size = textarea.value.length;
		sp = document.getElementById('remaining');//.innerHTML = 'teste';// (500 - (size + 1));
		sp.innerHTML = (limit - (parseInt(size)));
		return true;
	}
}

function count_length2(textarea, limit, id){
		
	var text = textarea.value;
	var textlength = text.length;
	if (textlength > limit) {
		textarea.value = text.substr(0, limit);
		return false;
	}
	else
	{
		size = textarea.value.length;
		sp = document.getElementById(id);//.innerHTML = 'teste';// (500 - (size + 1));
		sp.innerHTML = (limit - (parseInt(size)));
		return true;
	}
}

function recordWaitingStatusTop(data){
	if (data.status == 'begin'){
		document.getElementById("genericStatusTop").innerHTML = "Aguarde...";
		openModalStatus("#topModalStatus");
	}else {
		closeModalStatus("#topModalStatus");
	}
}
function recordWaitingAvalieImovelTop(data){
	if (data.status == 'begin'){
		document.getElementById("genericStatusTop").innerHTML = "Enviando Avaliação...";
		openModalStatus("#topModalStatus");
	}else {
		closeModalStatus("#topModalStatus");
		if (data.status == 'success' &&
				(document.getElementById("avalieCondominio:ErrorAvalie")==null || document.getElementById("avalieCondominio:ErrorAvalie").innerHTML=='') ){
			openModal("#modalCloseAvalie");
		}
	}
}
function pRecordStatusInicioTop(description){
	document.getElementById("genericStatusTop").innerHTML = description;
	openModalStatus("#topModalStatus");
}
function pRecordStatusFimTop(){
	closeModalStatus("#topModalStatus");
}

function openAutenticacaoTwitter(link) {
	window.location.href = link;	
}
