/***************************************************************************/
/*  			Biblioteca de Scripts BCK Design - Versão 1.1             */
/* 		By Edvaldo da Rosa - www.bck.com.br - contato@bck.com.br           */
/***************************************************************************/

/* CONTA-CARACTERES TEXTEAREA */
function contaChars(obj, field, limite){
    if
	(!limite) limite = 300;
    if(field.value.length > limite){
        field.value = field.value.substr(0,limite);
    }
    document.getElementById(obj).innerHTML = limite - field.value.length;
}

/* MOSTRA/ESCONDE TEXTO CAMPOS FORM */
function mascaraMostraSome(campo, textoDefault) {
	if (document.getElementById(campo).value == textoDefault) {
		document.getElementById(campo).value = "";
	} else if (document.getElementById(campo).value == "") {
		document.getElementById(campo).value = textoDefault;
	}
}

/* VALIDAÇÃO DE FORMULÁRIOS */
//Verifica se o campo obrigatório está preenchido
function campoPreenchido(campo, nomeLabel, valorDefault){
	if(campo.value == "" || campo.value == valorDefault) {
		alert('O preenchimento do campo ' + nomeLabel + ' é obrigatório!');
		campo.focus();
		return false;
	}
	return true;
}
//Verifica se o campo está preenchido com email valido
function campoEmail(campo, nomeLabel, caso){ /* caso (1=obrigatorio e 0=não obrigatório)*/
	endEmail = campo.value;
  	var valMail = new RegExp;
  	valMail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if(campo.value != "") {
		if (valMail.exec(endEmail) == null) {
    	alert('Preencha o campo ' + nomeLabel + ' com um email válido!');
		campo.focus();
		return false;
 		}
	} else {
		if (caso == 1) {
			alert('O preenchimento do campo ' + nomeLabel + ' é obrigatório!');
			campo.focus();
			return false;
		}
	}
	return true;
}
//Verifica se numero maximo de caracteres foi ultrapassado
function maxCaracteres(campo, nomeLabel, maxChar){
	if(campo.value.toString().length > maxChars) {
		alert('Preencha o campo ' + nomeLabel + ' com no máximo ' + maxChar + ' caracteres!');
		campo.focus();
		return false;
	}
	return true;
}

/* REDENDERIZAÇÃO DE ARQUIVOS SWF NAS PAGINAS */
/* Flash Tag Write Object v1.5 - by Lucas Ferreira - www.lucasferreira.com	*/
if(Browser == undefined){
	var Browser = {
		isIE: function(){ return (window.ActiveXObject && document.all && navigator.userAgent.toLowerCase().indexOf("msie") > -1  && navigator.userAgent.toLowerCase().indexOf("opera") == -1) ? true : false; }
	}
}

var Flash = function(movie, id, width, height, title, initParams){

	this.html = "";
	this.attributes = this.params = this.variables = null;
	
	this.variables = new Array();
	this.attributes = {
		"classid": "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000",
		"codebase": "http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab#version=7,0,0,0",
		"type": "application/x-shockwave-flash",
		"title": title
	}
	this.params = { "pluginurl": "http://www.macromedia.com/go/getflashplayer_br" };
	
	if(movie) {
		this.addAttribute("data", movie);
		this.addParameter("movie", movie);
	}
	
	if(id && id != null) this.addAttribute("id", id);
	if(width) this.addAttribute("width", width);
	if(height) this.addAttribute("height", height);
	
	if(initParams != undefined){
		for(var i in initParams){
			this.addParameter(i.toString(), initParams[i]);
		}
	}
	
}
Flash.version = "1.2b";
Flash.getObjectByExceptions = function(obj, excep){
	var tempObj = {};
	for(var i in obj){
		var inclui = true;
		for(var j=0; j<excep.length; j++)
			if(excep[j] == i.toString()) { inclui = false; break; };
		if(inclui) tempObj[i] = obj[i];
	}
	return tempObj;
}
Flash.prototype.addAttribute = function(prop, val){ this.attributes[prop] = val; }
Flash.prototype.addParameter = function(prop, val){ this.params[prop] = val; }
Flash.prototype.addVariable = function(prop, val){ this.variables.push([prop, val]); }
Flash.prototype.getFlashVars = function(){
	var tempString = new Array();
	
	for(var i=0; i<this.variables.length; i++)
		tempString.push(this.variables[i].join("="));
		
	return tempString.join("&");
}
Flash.prototype.toString = function(){
	
	this.params.flashVars = this.getFlashVars();
	if(Browser.isIE()){
		//IE
		this.html = "<ob" + "ject";
		var attr = Flash.getObjectByExceptions(this.attributes, ["type", "data"]);
		for(var i in attr) if(i.toString() != "extend") this.html += " " + i.toString() + " = \"" + attr[i] + "\"";
		this.html += "> ";
		var params = Flash.getObjectByExceptions(this.params, ["pluginurl", "extend"]);
		for(var i in params) if(i.toString() != "extend") this.html += "<param name=\"" + i.toString() + "\" value=\"" + params[i] + "\" /> ";
		this.html += " </obj" + "ect>";
	} else {
		//non-IE
		this.html = "<!--[if !IE]> <--> <obj" + "ect";
		var attr = Flash.getObjectByExceptions(this.attributes, ["classid", "codebase"]);
		for(var i in attr) if(i.toString() != "extend") this.html += " " + i.toString() + " = \"" + attr[i] + "\"";
		var params = Flash.getObjectByExceptions(this.params, ["extend"]);
		for(var i in params) if(i.toString() != "extend") this.html += "<param name=\"" + i.toString() + "\" value=\"" + params[i] + "\" /> ";
		this.html += " </obj" + "ect> <!--> <![endif]-->";
	}

	return this.html;
	
}
Flash.prototype.write = Flash.prototype.outIn = Flash.prototype.writeIn = function(w){
	if(typeof w == "string" && document.getElementById) var w = document.getElementById(w);
	if( w != undefined && w ) w.innerHTML = this.toString();
	else document.write( this.toString() );
}

//fun??es de automatiza??o...
Flash.correctAll = function(){
	
	if(!/MSIE (5|6)/.test(navigator.userAgent) || !document.getElementsByTagName) return false;

	for (var i = 0, objects = document.getElementsByTagName("OBJECT");
			i < objects.length; (objects[i].outerHTML ? (objects[i].outerHTML = objects[i].outerHTML, objects[i].style.visibility = "visible") : null), i++);

}
Flash.automatic = function(r){
	
	if(r && window.attachEvent){
	
		for (var i = 0, objects = document.getElementsByTagName("OBJECT");
				i < objects.length; (objects[i].style.visibility = "hidden"), i++);
		
		window.attachEvent("onload", Flash.correctAll);
		window.attachEvent("onunload", function(){	window.detachEvent("onload", Flash.correctAll);	});
		
	} else {
		Flash.correctAll();
	}

}// JavaScript Document

// Função que força a abertura das páginas externas em outra janela 
var Trocar = new Object();
Trocar.verify = function () {
var nav = navigator.appName;
	if(nav != "Microsoft Internet Explorer"){
	document.addEventListener("DOMContentLoaded", Trocar.trocar, false);
	} else {
		try {
		// If IE is used, use the trick by Diego Perini
		// http://javascript.nwbox.com/IEContentLoaded/
		document.documentElement.doScroll("left");
		} catch( error ) {
		setTimeout( Trocar.trocar, 0 );
		return;
		}
	}
}
Trocar.trocar = function () {
	if (document.getElementsByTagName) {
		links = document.getElementsByTagName('a');
		for (k = 0; k < links.length; k++) {
			if (links[k].getAttribute('href') && links[k].getAttribute('target') == "_blank" || links[k].getAttribute('rel') == "paginaExterna"){
			links[k].target = '_blank';
			links[k].rel = 'paginaExterna';
			}
		}
	}
}