
// MOSTRA DIV COM UMA MENSAGEM TEMPORÁRIA
//USO: iAjax_msg({tempo:5, status:'ok', mensagem:'mensagem', titulo:'titulo' })
function iAjax_msg(parametros){

	var tempo = parametros["tempo"];
	var status = parametros["status"];
	var mensagem = parametros["mensagem"];
	var titulo = parametros["titulo"];
	
	var iAjax_msg = document.getElementById("mensagem");
	var iAjax_imagem = document.getElementById("mensagem_imagem");
	var mensagem_texto = document.getElementById("mensagem_texto");
	var mensagem_titulo = document.getElementById("mensagem_titulo");
	//tratamentos
	tempo = parseInt(tempo);
	
	// se o tempo nao for passado, padrão de 3 segundos
	if(tempo == ""){
		tempo = 3000
	}else{
		tempo = tempo*1000
	}
	
	// se o tempo nao for passado, padrão de 3 segundos
	if(status == "ok"){
		corFundo = "#87C53C";
		corTexto = "#000";
		imagem = "ico_msg_ok.png";
		if(titulo == undefined || titulo == "") titulo = "Sucesso";
	}else if(status == "erro"){
		corFundo = "#BE3F3F";
		corTexto = "#FFF";
		imagem = "ico_msg_erro.png";
		if(titulo == undefined || titulo == "") titulo = "Erro";
	}else if(status == "normal"){
		corFundo = "#D7D7D7";
		corTexto = "#FFF";
		imagem = "ico_msg_normal.png";
		if(titulo == undefined || titulo == "") titulo = "Alerta";
	}

	$('#mensagem').slideDown();
	iAjax_msg.style.backgroundColor = corFundo;
	mensagem_texto.style.color = corTexto;
	mensagem_titulo.style.color = corTexto;
	
	$('#mensagem_imagem').slideDown();
	iAjax_imagem.style.background="url('../../../LIB/IMG/site/"+imagem+"') no-repeat"; 
	
	$('#mensagem_titulo').html(titulo);
	$('#mensagem_texto').html(mensagem);
	
	setTimeout(" $('#mensagem').fadeOut('slow');$('#mensagem_imagem').fadeOut('slow');", tempo);
}
	

// MOSTRA DIV COM UMA MENSAGEM TEMPORÁRIA
//USO: msg_google({tempo:5, status:'ok', mensagem:'mensagem' })
function msg_google(parametros){

	var tempo = parametros["tempo"];
	var status = parametros["status"];
	var mensagem = parametros["mensagem"];
	var msg_google = document.getElementById("msg_google");
	
	//tratamentos
	tempo = parseInt(tempo);
	
	// se o tempo nao for passado, padrão de 3 segundos
	if(tempo == ""){
		tempo = 3000
	}else{
		tempo = tempo*1000
	}
	
	// se o tempo nao for passado, padrão de 3 segundos
	if(status == "ok"){
		cor = "#006600";
		mensagem_padrao = "";
	}else if(status == "erro"){
		cor = "#B74A4A";
		mensagem_padrao = "Erro: ";
	}else{
		cor = "#666666";
	}
	
	msg_google.style.display = "block";
	msg_google.style.backgroundColor = cor;
	msg_google.innerHTML = mensagem_padrao+mensagem;
	
	setTimeout(" $('#msg_google').fadeOut('slow');", tempo);
}

function cria_abaPersonalizada(mainLinkTag,hiddenContentClass,showDefaultTab){
	
	$.jtabber({
		mainLinkTag: mainLinkTag, // much like a css selector, you must have a 'title' attribute that links to the div id name
		activeLinkClass: "selected", // class that is applied to the tab once it's clicked
		hiddenContentClass: hiddenContentClass, // the class of the content you are hiding until the tab is clicked
		showDefaultTab: showDefaultTab, // 1 will open the first tab, 2 will open the second etc.  null will open nothing by default
		showErrors: true, // true/false - if you want errors to be alerted to you
		effect: 'fade', // null, 'slide' or 'fade' - do you want your content to fade in or slide in?
		effectSpeed: 'fast' // 'slow', 'medium' or 'fast' - the speed of the effect
	})
	
}

function cria_aba(){
	
	$.jtabber({
		mainLinkTag: "#nav a", // much like a css selector, you must have a 'title' attribute that links to the div id name
		activeLinkClass: "selected", // class that is applied to the tab once it's clicked
		hiddenContentClass: "hiddencontent", // the class of the content you are hiding until the tab is clicked
		showDefaultTab: 1, // 1 will open the first tab, 2 will open the second etc.  null will open nothing by default
		showErrors: true, // true/false - if you want errors to be alerted to you
		effect: 'fade', // null, 'slide' or 'fade' - do you want your content to fade in or slide in?
		effectSpeed: 'fast' // 'slow', 'medium' or 'fast' - the speed of the effect
	})
	
}

function autotab(elemento){
	if (elemento.value.length<elemento.getAttribute("maxlength")) return;
	var formulario = elemento.form;
	var els = formulario.elements;
	var x, autotab;
	
	for (var i = 0, len = els.length; i<len; i++){
	 x = els[i];
	 if (elemento == x && (autotab = els[i+1])){
	  if (autotab.focus) autotab.focus();
	 }
	}
}


//include
function include_css(arquivo){
	//By Fabrício Magri e Micox
	//http://elmicox.blogspot.com/2006/12/include-em-javascript.html
	var novo = document.createElement('link');
	novo.setAttribute('rel', 'stylesheet');
	novo.setAttribute('type', 'text/css');
	novo.setAttribute('media', 'screen');
	novo.setAttribute('href', arquivo);
	document.getElementsByTagName('head')[0].appendChild(novo);
	//apos a linha acima o navegador inicia o carregamento do arquivo
	//portanto aguarde um pouco até o navegador baixá-lo. :)
}

function include_js(arquivo){
	var novo = document.createElement('script');
	novo.setAttribute('type', 'text/javascript');
	novo.setAttribute('src', arquivo);
	document.getElementsByTagName('head')[0].appendChild(novo);
}


// Envia um form para ser processado em uma página
// uso: ajax(nomeForm, urlDestino, divRetorno, textoCarregando, callback)
// uso: ajax("form_name", "pagDestino.asp?id=30&fk_cliente=90", "div_recebeEditar", "Carregando Pax", "funcaoRetorno")
function ajax(nomeForm, urlDestino, divRetorno, textoCarregando, callback) {
	
	// texto padrão do carregando
	if (textoCarregando == "") { textoCarregando = "Carregando..."; }

	if (callback != '') {
		ajaxGo({
			form: nomeForm,
			url: urlDestino,
			loading: "<div style='width:400px;'><img src='../../LIB/IMG/icones/loading.gif'style='vertical-align:middle;'/> "+textoCarregando+"</div>",
			elem_return: divRetorno,
			callback: callback
		})
	} else {
		ajaxGo({
			form: nomeForm,
			url: urlDestino,
			loading: "<div style='width:400px;'><img src='../../LIB/IMG/icones/loading.gif'style='vertical-align:middle;'/> "+textoCarregando+"</div>",
			elem_return: divRetorno
		})
	}

}


// Envia um form para ser processado em uma página
// uso: formSubmit(formCadastro,'iForm','pagDestino.asp');
function formSubmit(objForm,target,URL) {
	objForm.target = target;
	objForm.action = URL;
	objForm.submit();
}

//retira os acentos
function retira_acentos(palavra) {  
	  com_acento = '."áàãâäéèêëíìîïóòõôöúùûüçÁÀÃÂÄÉÈÊËÍÌÎÏÓÒÕÖÔÚÙÛÜÇ';  
	  sem_acento = '."aaaaaeeeeiiiiooooouuuucAAAAAEEEEIIIIOOOOOUUUUC';  
	  nova='';  
	  for(i=0;i<palavra.length;i++) {  
		  if (com_acento.search(palavra.substr(i,1))>=0) {  
		  nova+=sem_acento.substr(com_acento.search(palavra.substr(i,1)),1);  
		  }  
		  else {  
		  nova+=palavra.substr(i,1);  
		  }  
	  }  
	  return nova;  
}  

// Abre um pop-up centralizado (sem Scroll)
function openPopUp(url,parametros,nomeJanela,largura,altura){
	var left = (screen.width-largura)/2;
	var top = (screen.height-altura)/2;
	top = top - 30;
	var atributos = "left="+left+",top="+top+",width="+largura+",height="+altura;
	url = url + parametros
	window.open(url,nomeJanela,atributos);
}

// Abre um pop-up centralizado
//COM SCROLLBAR
function openPopUp2(url,parametros,nomeJanela,largura,altura,scrollbars){
	var left = (screen.width-largura)/2;
	var top = (screen.height-altura)/2;
	top = top - 30;
	var atributos = "left="+left+",top="+top+",width="+largura+",height="+altura+",scrollbars=yes";
	url = url + parametros
	window.open(url,nomeJanela,atributos);
}

//Aplica a classe necessária para os campos passados
function adiciona_classe(id_campo, classe){
	$('#' + id_campo).addClass(classe)
}


//Dá um innerHTML "" na div pedida
//SEMPRE PASSAR
function limpaDiv(div){
	$("#" + div).html("")
}

























