// JavaScript Document
function hospitalar11(id,tam){
	for(x=1;x<=tam;x++){
		if(x==1){
			stringVetor = x; 
		}else{
			stringVetor += ','+x;
		}
	}
	
	var ids = stringVetor.split(",");
	
	for(i=0;i<ids.length;i++){
		var some = "hospitalar11_"+ids[i];
		if(id != (i + 1)){
			document.getElementById(some).style.display = "none";
		}else{
			document.getElementById("hospitalar11_"+id).style.display = "block";
		}
	}
}

function exporevestir(id,tam){
	for(x=1;x<=tam;x++){
		if(x==1){
			stringVetor = x; 
		}else{
			stringVetor += ','+x;
		}
	}
	
	var ids = stringVetor.split(",");
	
	for(i=0;i<ids.length;i++){
		var some = "exporevestir"+ids[i];
		if(id != (i + 1)){
			document.getElementById(some).style.display = "none";
		}else{
			document.getElementById("exporevestir"+id).style.display = "block";
		}
	}
}

function confraternizacao(id,tam){
	for(x=1;x<=tam;x++){
		if(x==1){
			stringVetor = x; 
		}else{
			stringVetor += ','+x;
		}
	}
	
	var ids = stringVetor.split(",");
	
	for(i=0;i<ids.length;i++){
		var some = "confraternizacao"+ids[i];
		if(id != (i + 1)){
			document.getElementById(some).style.display = "none";
		}else{
			document.getElementById("confraternizacao"+id).style.display = "block";
		}
	}
}

function hospitalar10(id,tam){
	for(x=1;x<=tam;x++){
		if(x==1){
			stringVetor = x; 
		}else{
			stringVetor += ','+x;
		}
	}
	
	var ids = stringVetor.split(",");
	
	for(i=0;i<ids.length;i++){
		var some = "hospitalar10_"+ids[i];
		if(id != (i + 1)){
			document.getElementById(some).style.display = "none";
		}else{
			document.getElementById("hospitalar10_"+id).style.display = "block";
		}
	}
}

function office10(id,tam){
	for(x=1;x<=tam;x++){
		if(x==1){
			stringVetor = x; 
		}else{
			stringVetor += ','+x;
		}
	}
	
	var ids = stringVetor.split(",");
	
	for(i=0;i<ids.length;i++){
		var some = "office10_"+ids[i];
		if(id != (i + 1)){
			document.getElementById(some).style.display = "none";
		}else{
			document.getElementById("office10_"+id).style.display = "block";
		}
	}
}

function revestir10(id,tam){
	for(x=1;x<=tam;x++){
		if(x==1){
			stringVetor = x; 
		}else{
			stringVetor += ','+x;
		}
	}
	
	var ids = stringVetor.split(",");
	
	for(i=0;i<ids.length;i++){
		var some = "revestir10_"+ids[i];
		if(id != (i + 1)){
			document.getElementById(some).style.display = "none";
		}else{
			document.getElementById("revestir10_"+id).style.display = "block";
		}
	}
}

function business(id){
	var ids = new Array("1","2","3","4"); 
	for(i=0;i<ids.length;i++){
		var some = "business"+ids[i];
		if(id != (i + 1)){
			document.getElementById(some).style.display = "none";
		}else{
			document.getElementById("business"+id).style.display = "block";
		}
	}
}

function ABDEH(id){
	var ids = new Array("1","2","3","4","5","6","7","8"); 
	for(i=0;i<ids.length;i++){
		var some = "ABDEH"+ids[i];
		if(id != (i + 1)){
			document.getElementById(some).style.display = "none";
		}else{
			document.getElementById("ABDEH"+id).style.display = "block";
		}
	}
}

function hospitalar(id){
	var ids = new Array("1","2","3","4","5","6","7","8","9","10","11","12","13"); 
	for(i=0;i<ids.length;i++){
		var some = "hospitalar"+ids[i];
		if(id != (i + 1)){
			document.getElementById(some).style.display = "none";
		}else{
			document.getElementById("hospitalar"+id).style.display = "block";
		}
	}
}

function office(id){
	var ids = new Array("1","2","3","4","5","6"); 
	for(i=0;i<ids.length;i++){
		var some = "office"+ids[i];
		if(id != (i + 1)){
			document.getElementById(some).style.display = "none";
		}else{
			document.getElementById("office"+id).style.display = "block";
		}
	}
}

function congresso(id){
	var ids = new Array("1","2","3","4","5","6","7","8","9","10","11","12","13","14","15"); 
	for(i=0;i<ids.length;i++){
		var some = "congresso"+ids[i];
		if(id != (i + 1)){
			document.getElementById(some).style.display = "none";
		}else{
			document.getElementById("congresso"+id).style.display = "block";
		}
	}
}

function hospitalar09(id,tam){
	for(x=1;x<=tam;x++){
		if(x==1){
			stringVetor = x; 
		}else{
			stringVetor += ','+x;
		}
	}
	
	var ids = stringVetor.split(",");
	
	for(i=0;i<ids.length;i++){
		var some = "hospitalar09_"+ids[i];
		if(id != (i + 1)){
			document.getElementById(some).style.display = "none";
		}else{
			document.getElementById("hospitalar09_"+id).style.display = "block";
		}
	}
}

function contemporaneo(id,tam){
	for(x=1;x<=tam;x++){
		if(x==1){
			stringVetor = x; 
		}else{
			stringVetor += ','+x;
		}
	}
	
	var ids = stringVetor.split(",");
	
	for(i=0;i<ids.length;i++){
		var some = "contemporaneo"+ids[i];
		if(id != (i + 1)){
			document.getElementById(some).style.display = "none";
		}else{
			document.getElementById("contemporaneo"+id).style.display = "block";
		}
	}
}

function arquitetura(id,tam){
	for(x=1;x<=tam;x++){
		if(x==1){
			stringVetor = x; 
		}else{
			stringVetor += ','+x;
		}
	}
	
	var ids = stringVetor.split(",");
	
	for(i=0;i<ids.length;i++){
		var some = "arquitetura"+ids[i];
		if(id != (i + 1)){
			document.getElementById(some).style.display = "none";
		}else{
			document.getElementById("arquitetura"+id).style.display = "block";
		}
	}
}

function simposio(id,tam){
	for(x=1;x<=tam;x++){
		if(x==1){
			stringVetor = x; 
		}else{
			stringVetor += ','+x;
		}
	}
	
	var ids = stringVetor.split(",");
	
	for(i=0;i<ids.length;i++){
		var some = "simposio"+ids[i];
		if(id != (i + 1)){
			document.getElementById(some).style.display = "none";
		}else{
			document.getElementById("simposio"+id).style.display = "block";
		}
	}
}

function santacasa(id,tam){
	for(x=1;x<=tam;x++){
		if(x==1){
			stringVetor = x; 
		}else{
			stringVetor += ','+x;
		}
	}
	
	var ids = stringVetor.split(",");
	
	for(i=0;i<ids.length;i++){
		var some = "santacasa"+ids[i];
		if(id != (i + 1)){
			document.getElementById(some).style.display = "none";
		}else{
			document.getElementById("santacasa"+id).style.display = "block";
		}
	}
}

function stc(id,tam){
	for(x=1;x<=tam;x++){
		if(x==1){
			stringVetor = x; 
		}else{
			stringVetor += ','+x;
		}
	}
	
	var ids = stringVetor.split(",");
	
	for(i=0;i<ids.length;i++){
		var some = "stc"+ids[i];
		if(id != (i + 1)){
			document.getElementById(some).style.display = "none";
		}else{
			document.getElementById("stc"+id).style.display = "block";
		}
	}
}

function construcao_salvador(id,tam){
	for(x=1;x<=tam;x++){
		if(x==1){
			stringVetor = x; 
		}else{
			stringVetor += ','+x;
		}
	}
	
	var ids = stringVetor.split(",");
	
	for(i=0;i<ids.length;i++){
		var some = "construcao_salvador"+ids[i];
		if(id != (i + 1)){
			document.getElementById(some).style.display = "none";
		}else{
			document.getElementById("construcao_salvador"+id).style.display = "block";
		}
	}
}

function workshop(id,tam){
	for(x=1;x<=tam;x++){
		if(x==1){
			stringVetor = x; 
		}else{
			stringVetor += ','+x;
		}
	}
	
	var ids = stringVetor.split(",");
	
	for(i=0;i<ids.length;i++){
		var some = "workshop"+ids[i];
		if(id != (i + 1)){
			document.getElementById(some).style.display = "none";
		}else{
			document.getElementById("workshop"+id).style.display = "block";
		}
	}
}

function checaContato(){
	var obj = document.orcamento;
	if(obj.empresaNome.value == "") {
		alert('Preencha o campo Empresa');
		obj.empresaNome.focus();
		return (false);
	}
	else if(obj.email.value == "") {
		alert('Preencha o campo Email');
		obj.email.focus();
	}
	else if(obj.email.value.indexOf('@') < 1 ){
		alert('Email incorreto!');
		obj.email.focus();
	}
	else if(obj.atividade.value == "") {
		alert('Preencha o campo Atividade');
		obj.atividade.focus();
	}
	else if(obj.endereco.value == "") {
		alert('Preencha o campo Endereço');
		obj.endereco.focus();
	}
	else if(obj.cidade.value == "") {
		alert('Preencha o campo Cidade!');
		obj.cidade.focus();
	}
	else if(obj.estado.value == "") {
		alert('Preencha o campo Estado!');
		obj.estado.focus();
	}
	else if(obj.ddd.value == ""){
		alert('Informe o DDD');
		obj.ddd.focus();
	}
	else if(obj.telefone.value == ""){
		alert('Informe o Telefone!');
		obj.telefone.focus();
	}
	else if(obj.contato.value == ""){
		alert('Preencha o campo Contato!');
		obj.contato.focus();
	/*}
	else if(obj.enderecoObra.value == ""){
		alert('Preencha o campo Endereço da obra!');
		obj.enderecoObra.focus();
	}
	else if(obj.bairroObra.value == ""){
		alert('Informe o Bairro da obra!');
		obj.bairroObra.focus();
	}
	else if(obj.cidadeObra.value == ""){
		alert('Preencha o campo Cidade da obra!');
		obj.cidadeObra.focus();
	}
	else if(obj.metragemObra.value == ""){
		alert('Informe a Metragem!');
		obj.metragemObra.focus();
	}
	else if(obj.modelo1Produtos.value == ""){
		alert('Informe o Modelo!');
		obj.modelo1Produtos.focus();
	}
	else if(obj.cor1Produtos.value == ""){
		alert('Informe a Cor!');
		obj.cor1Produtos.focus();
	}
	else if(obj.cor1Produtos.value == ""){
		alert('Informe a Cor!');
		obj.cor1Produtos.focus();*/
	}else{
		init();
	}
}
function $(e) {
	return document.getElementById(e);
}

function addEvent(obj, evType, fn) { //Função adaptada da original de Christian Heilmann, em http://www.onlinetools.org/articles/unobtrusivejavascript/chapter4.html
	if (typeof obj == "string") {
		if (null == (obj = document.getElementById(obj))) {
			throw new Error("Elemento HTML não encontrado. Não foi possível adicionar o evento.");
		}
	}
	if (obj.attachEvent) {
		return obj.attachEvent(("on" + evType), fn);
	} else if (obj.addEventListener) {
		return obj.addEventListener(evType, fn, true);
	} else {
		throw new Error("Seu browser não suporta adição de eventos.");
	}
}

function init() {
	/*
	msgbox_show('Título', 'Data inválida!', 'alert'); //alert com função padrão
	msgbox_show('Título', 'Data inválida!', 'alert', funcao1); //alert passando a função que será executada no botão OK
	msgbox_show('Título', 'Data inválida!', 'confirm'); //confirm com botões padrão
	msgbox_show('Título', 'Data inválida!', 'confirm', funcao1); //confirm passando a função que será executada no botão SIM e deixando o botão NÃO padrão*/
	msgbox_show('Confirmação de envio', 'Deseja nos enviar informações mais detalhadas para obtermos um orçamento mais preciso?', 'confirm'); //confirm passando a função que será executada no botão SIM (funcao1) e no botão NÃO (funcao2)
	// msgbox_show('Título', 'Deseja nos enviar um orçamento mais detalhado?!', 'alert'); //alert com função padrão*/
	$('fechar').href = '#';
	addEvent('fechar', 'click', msgbox_hide);
	
	$('fundo').style.display = "block";
}

function msgbox_hide() {
	$('msgbox').className = 'hidden';
	$('fundo').style.display = "none";
}

function msgbox_show(titulo, msg, tipo) {
	$('msgbox').className = 'visible';
	$('ptit').firstChild.data = titulo;
	$('pmsg').firstChild.data = msg;
    if (tipo == 'alert') {
		$('pOk').className = 'visible';
		$('pSN').className = 'hidden';
		$('btnOk').href = '#';
		if (arguments[3] == undefined) {
			addEvent('btnOk', 'click', msgbox_hide);
		} else {
			addEvent('btnOk', 'click', arguments[3]);
		}
    } else if (tipo == 'confirm') {
		$('pOk').className = 'hidden';
		$('pSN').className = 'visible';
		//$('btnSim').href = '?email=orc2';
		//$('btnNao').href = '?email=ok';
		if (arguments[3] == undefined) {
			addEvent('btnSim', 'click', msgbox_hide);
		} else {
			addEvent('btnSim', 'click', arguments[3]);
			if (arguments[4] == undefined) {
				addEvent('btnNao', 'click', msgbox_hide);
			} else {
				addEvent('btnNao', 'click', arguments[3]);
			}
		}
    } else {
		$('msgbox').className = 'hidden';
    }
}
//addEvent(window, 'load', init);
function submit(){
	document.orcamento.submit();
}
function opendiv(){
	document.getElementById("orc1").style.display = "none";
	document.getElementById("orc2").style.display = "block";
	document.getElementById("formOrc1").style.display = "none";
	document.getElementById("formOrc2").style.display = "block";
}

function checaContato2(){
	var obj = document.orcamento;
	if(obj.enderecoObra.value == ""){
		alert('Preencha o campo Endereço da obra!');
		obj.enderecoObra.focus();
	}
	else if(obj.bairroObra.value == ""){
		alert('Informe o Bairro da obra!');
		obj.bairroObra.focus();
	}
	else if(obj.cidadeObra.value == ""){
		alert('Preencha o campo Cidade da obra!');
		obj.cidadeObra.focus();
	}
	else if(obj.metragemObra.value == ""){
		alert('Informe a Metragem!');
		obj.metragemObra.focus();
	}
	else if(obj.modelo1Produtos.value == ""){
		alert('Informe o Modelo!');
		obj.modelo1Produtos.focus();
	}
	else if(obj.cor1Produtos.value == ""){
		alert('Informe a Cor!');
		obj.cor1Produtos.focus();
	}
	else if(obj.cor1Produtos.value == ""){
		alert('Informe a Cor!');
		obj.cor1Produtos.focus();
	}else{
		obj.submit();
	}
}

function faleConosco(){
	var obj = document.faleconosco;
	if(obj.nome.value == "") {
		alert('Preencha o campo  Nome');
		obj.nome.focus();
	}
	else if(obj.empresa.value == "") {
		alert('Preencha o campo Empresa');
		obj.empresa.focus();
	}
	else if(obj.email.value == "") {
		alert('Preencha o campo Email');
		obj.email.focus();
	}
	else if(obj.email.value.indexOf('@') < 1 ){
		alert('Email incorreto!');
		obj.email.focus();
	}
	else if(obj.profissao.value == "") {
		alert('preencha o campo Profissão!');
		obj.profissao.focus();
	}
	else if(obj.ramoAtividade.value == ""){
		alert('Informe o Ramo de Atividade!');
		obj.ramoAtividade.focus();
	}
	else if(obj.ddd.value == ""){
		alert('Informe o DDD');
		obj.ddd.focus();
	}
	else if(obj.telefone.value == ""){
		alert('Informe o Telefone!');
		obj.telefone.focus();
	}
	else if(obj.mensagem.value == ""){
		alert('Preencha o campo Mensagem!');
		obj.mensagem.focus();
	}else{
		obj.submit();
	}
}

function residencial(){
		document.getElementById("residencial").style.display = "block";
		document.getElementById("comercial").style.display = "none";
}
function comercial(){
		document.getElementById("residencial").style.display = "none";
		document.getElementById("comercial").style.display = "block";
}


function zerar(campo, texto){
	if (campo.value==texto){
		campo.value="";
	}
}
function campoVazio(campo, texto){
	if (campo.value==""){
		campo.value=texto;
	}
}

function checaNewsletter(){
	var obj = document.newsletter;
	if(obj.nomeNewsletter.value == "Nome") {
		alert('Preencha o campo Nome');
		obj.nomeNewsletter.focus();
		return (false);
	}
	else if(obj.emailNewsletter.value == "E-mail") {
		alert('Preencha o campo Email');
		obj.emailNewsletter.focus();
	}
	else if(obj.emailNewsletter.value.indexOf('@') < 1 ){
		alert('Email incorreto!');
		obj.emailNewsletter.focus();
	}else{
		obj.submit();
		 }
}


function checaAreaRestrita(){
	var obj = document.areaRestrita;
	if(obj.login.value == "Login") {
		alert('Preencha o campo Login');
		obj.login.focus();
		return (false);
	}
	else if(obj.senha.value == "Senha") {
		alert('Preencha o campo Senha');
		obj.senha.focus();
	}else{
		obj.submit();
		 }
}

function index(espaco){
	self.location.href=espaco+"index.php";
}
function quem_somos(espaco){
	self.location.href=espaco+"quem_somos.php";
}
function servicos(espaco){
	self.location.href=espaco+"servicos.php";
}
function produtos(espaco){
	self.location.href=espaco+"produtos.php";
}
function sustentabilidade(espaco){
	self.location.href=espaco+"sustentabilidade.php";
}
function projetos(espaco){
	self.location.href=espaco+"projetos.php";
}
function eventos(espaco){
	self.location.href=espaco+"eventos.php";
}
function orcamentos(espaco){
	self.location.href=espaco+"orcamentos.php";
}
function fale_conosco(espaco){
	self.location.href=espaco+"fale_conosco.php";
}

function trabalheConosco(){
	var obj = document.trabalhe;
	if(obj.nome1.value == "") {
		alert('Preencha o campo  Nome');
		obj.nome1.focus();
	}
	else if(obj.email1.value == "") {
		alert('Preencha o campo Email');
		obj.email1.focus();
	}
	else if(obj.email1.value.indexOf('@') < 1 ){
		alert('Email incorreto!');
		obj.email1.focus();
	}
	else if(obj.cidade1.value == "") {
		alert('Preencha o campo Cidade!');
		obj.cidade1.focus();
	}
	else if(obj.estado1.value == "") {
		alert('Preencha o campo Estado!');
		obj.estado1.focus();
	}
	else if(obj.cargo1.value == ""){
		alert('Preencha o campo Cargo!');
		obj.cargo1.focus();
	}
	else if(obj.ddd1.value == ""){
		alert('Informe o DDD');
		obj.ddd1.focus();
	}
	else if(obj.telefone1.value == ""){
		alert('Informe o Telefone!');
		obj.telefone1.focus();
	}
	else if(obj.arquivo.value == ""){
		alert('Faça o upload do curriculum!');
		obj.arquivo.focus();
	}else{
		obj.submit();
	}
}

function abas(id,tam){
	for(x=1;x<=tam;x++){
		if(x==1){
			stringVetor = x; 
		}else{
			stringVetor += ','+x;
		}
	}
	
	var ids = stringVetor.split(",");
	
	for(i=0;i<ids.length;i++){
		var some = "item"+ids[i];
		var abas = "aba"+ids[i];
		try{
			if(id != (i + 1)){
				document.getElementById(some).style.display = "none";
				document.getElementById(abas).className = "off";
			}else{
				document.getElementById("item"+id).style.display = "block";
				document.getElementById("aba"+id).className = "atual";
			}
		}catch(ex){
			//nada aqui	
		}
	}
}

function adicionarSubdesign(Design){
	indiceLocal = $("#indiceSubdesign").val();
	$(".alterarSubdesign").append("<li><input type=\"text\" id=\"txtsubdesign-"+indiceLocal+"\" name=\"txtsubdesign-"+indiceLocal+"\" value=\"\" \"/></li>");
	indiceSubdesign = parseInt(indiceLocal)+1;
	$("#indiceSubdesign").attr("value",indiceSubdesign);
	$("#novoSubdesign").attr("value", "true");
}

function excluirSubdesign(Subdesign){
	var confirma = false;
	var perguntar= true;
	var indiceSubdesign = $("#indiceSubdesign").val();
	var strCodSubdesign = "";

	$(".checkbox").each(function(){
		if(this.checked){
			if(perguntar){
				confirma = confirm('Deseja realmente excluir os subdesigns selecionados?');
				perguntar = false;
			}
			if(confirma){
				id = this.id;
				nome = this.name;
				valor = this.value;
				arrayindice = id.split("-");
				indice = arrayindice[1];
				if(this.checked){
					strCodSubdesign += valor+"#";
					$("input").remove("."+id);
					$("a").remove("."+id);
					$("img").remove("."+id);
					$("span").remove("."+id);
					indiceSubdesign--;
				}
			}
		}
	});

	if(confirma){
		$.post('editar.php',{
				excluirSubdesign:strCodSubdesign
			},
			function(data){
				//alert(Trim(data));
				//$('#'+id).attr("src", img);
			}
		);
	}
	$("#indiceSubdesign").attr("value", indiceSubdesign);
}

function mudarSubdesign(produto,codSubdesign){
	$.post('index.php',{
			produto:produto, codSubdesign:codSubdesign, mudarSubdesign:true
		},
		function(data){
			//alert(Trim(data));
			//$('#'+id).attr("src", img);
		}
	);
}

function alterarSubdesign(Subdesign){
	var id = ""
	var nome = "";
	var valor = "";
	var indiceSubdesign = 0;
	$(".checkbox").each(function(){
		id = this.id;
		nome = this.name;
		valor = this.value;
		arrayindice = id.split("-");
		indice = parseInt(arrayindice[1]);
		conteudo = $("#span-"+indice).html();
		
		if(this.checked){
			if(!this.disabled){
				if($("#txtsubdesign-"+indice).length == 0){
					if($("#alteradoSubdesign-"+indice).length ==0){
					$(".alterarSubdesign").append("<li><input class=\""+id+"\" type=\"text\" id=\"alteradoSubdesign-"+indice+"\" name=\"alterarSubdesign-"+valor+"\" value=\""+conteudo+"\" \"/></li>");
					$("#alterarSubdesign").attr("value", "true");

					}
				}
			}
		}else{
			$("input").remove("#txtsubdesign-"+indice);
			$("#"+this.id).attr("disabled", false);
		}
		indiceSubdesign++;
	});
	$("#indiceSubdesign").attr("value", indiceSubdesign);
}

function editarDesign(){
	$(".checkbox").each(function(){
		this.checked=true;
	});
	$("#editar").submit();
}

function Trim(str){return str.replace(/^\s+|\s+$/g,"");}

function altera_status(Cod, codSubdesign, id, Status){
	$.post('editar.php',{
			codSubdesign:codSubdesign, Cod: Cod, Status:Status,
			alterarStatus:true
		},
		function(data){
			//alert(Trim(data));
			if(Trim(data)=='1'){
				var img = '../../Imagens/Ativo.png';
				var alt = 'Ativar';
			}else{
				var img = '../../Imagens/Inativo.png';
				var alt = 'Desativar';
			}

			id = id.replace("&&", "");
			id = id.replace("..", "");

			$('#'+id).attr("src", img);
			$('#'+id).attr("alt", alt);
		}
	);
}

function busca(){
	var obj = document.buscar;
	if(obj.tipo.value == "nome") {
//		alert(obj.tipo.value);
		location.href = "/consulta.php?nome="+obj.valor.value;
	}else if(obj.tipo.value == "cod") {
		location.href = "/consulta.php?cod="+obj.valor.value;
	}
}

function loadLink(link){
	location.href = link;
}
