function AlteraAcompanhe( campo_selecionado ) {
	url = 'cronograma.php?id=' + campo_selecionado.value;
	location=(url);
}

//Funcao para validacao de e-mail
function valida_email( email ) {
	//Expressao Regular utilizada para validar o endereco de email
	var ExpReg = /^[a-zA-Z0-9_\.-]{2,}@([A-Za-z0-9_-]{2,}\.)+[A-Za-z]{2,4}$/;
	if ( !ExpReg.test(email) ) {
		return false;
	}
	return true;
}

function $(s) {
	return document.getElementById(s);
}

function F(s) {
	return document.getElementById(s).value;
}

//Validacao de Contato
function valida_contato() {
	if ( document.getElementById('nome').value == "" ) {
		alert("O campo NOME é obrigatório!");
		document.getElementById('nome').focus();
		return false;
	}

	if ( document.getElementById('email').value == "" ) {
		alert("O campo E-MAIL é obrigatório!");
		document.getElementById('email').focus();
		return false;
	}

	if ( document.getElementById('email').value != "" ) {
		if ( !valida_email( document.getElementById('email').value ) ) {
			alert("Seu E-MAIL não é válido!");
			document.getElementById('email').focus();
			return false;
		}
	}
	
	if ( $('cliente_mo_s').checked == true ) {
		if ( F('nome_proprietario') == "" ) {
			alert("O campo NOME DO PROPRIETÁRIO é obrigatório!");
			$('nome_proprietario').focus();
			return false;
		}
		if ( F('empreendimento') == "" ) {
			alert("O campo EMPREENDIMENTO é obrigatório!");
			$('empreendimento').focus();
			return false;
		}
		if ( F('edificio') == "" ) {
			alert("O campo EDIFCIO é obrigatório!");
			$('edificio').focus();
			return false;
		}
		if ( F('apartamento') == "" ) {
			alert("O campo APARTAMENTO é obrigatório!");
			$('apartamento').focus();
			return false;
		}
	}

	if ( document.getElementById('mensagem').value == "" ) {
		alert("O campo MENSAGEM é obrigatório!");
		document.getElementById('mensagem').focus();
		return false;
	}
	return true;
}

function valida_data() {
	var date = document.getElementById('data').value;
	var array_data = new Array;
	//vetor que contem o dia o mes e o ano
	array_data = date.split("/");
	erro = false;
	//Valido se a data esta no formato dd/mm/yyyy
	if ( date.search("(0[1-9]|[12][0-9]|3[01])/(0[1-9]|1[012])/[12][0-9]{3}") == -1 )
		erro = true;
	//Valido os meses que nao tem 31 dias com execao de fevereiro
	if ( ( ( array_data[1] == 4 ) || ( array_data[1] == 6 ) || ( array_data[1] == 9 ) || ( array_data[1] == 11 ) ) && ( array_data[0] > 30 ) )
		erro = true;
	//Valido o mes de fevereiro
	if ( array_data[1] == 2 ) {
		//Valido ano que nao e bissexto
		if ( ( array_data[0] > 28 ) && ( ( array_data[2] % 4 ) != 0 ) )
			erro = true;
		//Valido ano bissexto
		if ( ( array_data[0] > 29 ) && ( ( array_data[2] % 4 ) == 0 ) )
			erro = true;
	}
	if ( erro ) {
		alert("Data Invlida");
		document.getElementById('data').focus();
	}
}

function amplia_imagem( imagem, title, desc ) {
	PositionX = 0;
	PositionY = 0;
	window.open('imagem.php?imagem=' + imagem + '&title=' + title + '&desc=' + desc, '', 'resizable=1,scrollbars=no,width=100,height=100,left='+PositionX+',top='+PositionY);
}


function abre_janela( janela, titulo, defaultWidth, defaultHeight ) {
	window.open(janela, titulo, 'scrollbars=yes,width='+defaultWidth+',height='+defaultHeight+'left=100,top=100');
}

function abre_hotsite(endereco, rolagem, width, height) {
	PositionX = ( screen.width - width ) / 2;
	PositionY = ( screen.height - height ) / 2;
	window.open( endereco + '?site=1', 'HOTSITE', 'resizable=0,scrollbars='+rolagem+',width='+width+',height='+height+',left='+PositionX+',top='+PositionY);
}

function init() {
	createExternalLinks();
}

function createExternalLinks() {
    if(document.getElementsByTagName) {
        var anchors = document.getElementsByTagName('a');
        for(var i=0; i<anchors.length; i++) {
            var anchor = anchors[i];
            if(anchor.getAttribute("href") && anchor.getAttribute('rel')=='externo') { // <--   necessrio inserir rel="externo" no link
                anchor.target = '_blank';
                var title = anchor.title + ' (Este link abre uma nova janela)'; // <-- Insere este texto no final do Title do link
                anchor.title = title;
            }
        }
    }
}

function addEvent(obj, evType, fn){
    if(obj.addEventListener){
        obj.addEventListener(evType, fn, false);
        return true;
    } else if (obj.attachEvent){
        var r = obj.attachEvent('on'+evType, fn);
        return r;
    } else {
        return false;
    }
}

addEvent(window, "load", init);