function ById(id){return document.getElementById(id);}
function getBrowser(){if(window.XMLHttpRequest){return "mozilla";}else if(window.ActiveXObject){return "ie";}}

/*Função para os links de ofertas*/
function abreOferta(url){window.open(url);}

function salaImprensaLogin()
{
	if(ById('cmdFrmImpLogin').style.display=='none')
	{
		ById('cmdFrmImpLogin').style.display='block';
		definePosMapa();
	}
	else
	{
		ById('cmdFrmImpLogin').style.display='none';
		definePosMapa();
	}	
}
function OverCell(id,cor)
{
	ById(id).style.backgroundColor=cor;
}

// ativa ou desativa o botao de cadastro
function checkAceito()
{
	if(document.frmRepreAdd.aceito.value == "yes")
	{
		document.frmRepreAdd.Enviar.disabled = true;
		document.frmRepreAdd.aceito.value = "no";
	}else{
		document.frmRepreAdd.Enviar.disabled = false;
		document.frmRepreAdd.aceito.value = "yes";
	}
}
/* ============ */


/* ====================================================== */
//Contador de caracteres nos campos de inserção de novo anuncio
function textCounter(field,cntfield,maxlimit) {
if (field.value.length > maxlimit)
field.value = field.value.substring(0, maxlimit);
else
cntfield.value = maxlimit - field.value.length;
}
/* ====================================================== */

/*CHECAGEM DO FORMULÁRIO DE PRE-INSCRICAO*/
function ckFrmPreCad(){
	var nome = document.frmPreCad.nome.value;
	var email = document.frmPreCad.email.value;
	
	nome = replaceAll(nome," ","");
	email = replaceAll(email," ","");
	
	if(nome == ""){	
		alert("Campo Requerido [ Razão Social ]!")
		document.frmPreCad.nome.focus();	
	}else if(email == ""){
		alert("Campo Requerido [ E-Mail ]!");
		document.frmPreCad.email.focus();
	}else if(!eh_email(email)){
		alert("E-mail inválido!");
		document.frmPreCad.email.focus();	
	}else{
		document.frmPreCad.submit();
	}
}
/*FIM DA CHECAGEM DO FORMULÁRIO DE PRE-INSCRICAO*/


/*Funções para as págnas de listagem ou detslhae do produto*/
function vaiParaListProd(id){window.location.href='sis.produtos.cat.prodlist.asp?pasta=1&pagina=2&cid='+id;}
function vaiParaDataProd(id){window.location.href='sis.produtos.cat.proddata.asp?pasta=1&pagina=2&pid='+id;}
/*yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy*/

function enviarCurr(){
	var nome 		= ById('nome').value;
		nome 		= replaceAll(nome," ","");
	var email 		= ById('email').value;
		email		= replaceAll(email," ","");
	var arq 		= ById('fotoCurr').value;
	var aArq		= arq.split(".")
	
	//Retorna a cor de back normal dos campos.
	ById('nome').style.backgroundColor='#FFFFFF';
	ById('email').style.backgroundColor='#FFFFFF';
	ById('fotoCurr').style.backgroundColor='#FFFFFF';

	var FormData = new Boolean("true");
	var ConteudoErro = "Foram detectados os seguintes erros:\n\n";

	if(nome==""){
		ConteudoErro+="- Campo requerido [NOME] .\n";
		ById('nome').style.backgroundColor='#FFFFCC';
		FormData=false;
	}
	if(email == "")
	{
		ConteudoErro+="- Campo requerido [E-mail] .\n";
		ById('email').style.backgroundColor='#FFFFCC';
		FormData=false;
	}
	if(!eh_email(email))
	{
		ConteudoErro+="- E-mail inválido ["+email+"] .\n";
		ById('email').style.backgroundColor='#FFFFCC';
		FormData=false;
	}
	if(arq != "" && aArq[aArq.length-1] != 'jpg')
	{

		ConteudoErro+="- Você deve selecionar um arquivo .JPG .\n";
		ById('fotoCurr').style.backgroundColor='#FFFFCC';
		FormData=false;
	}
	
	if(FormData)
	{
		ById('frmCurriculo').submit();
	}
	else
	{
		alert(ConteudoErro);
	}
}


function showtxt(campoId,msgToShow){
	var varShow = ById(campoId);

	if(varShow.value == '')
	{
		varShow.value = msgToShow
	}
}

function hidetxt(campoId,msgToHide){
var varHide = ById(campoId);

	if(varHide.value == msgToHide)
	{
		varHide.value='';
	}
}

function checkEvento(){
	var nome 			= ById('nome').value;
	var sobrenome 		= ById('sobrenome').value;
	var empresa 		= ById('empresa').value;
	var email 			= ById('email').value;
	var endereco 		= ById('endereco').value;
	var cep 			= ById('cep').value;
	var cidade 			= ById('cidade').value;
	var estado 			= ById('estado').value;
	var pais 			= ById('pais').value;
	var telefone 		= ById('telefone').value;
	var fax 			= ById('fax').value;
	var data_chegada 	= ById('data_chegada').value;
	var data_saida 		= ById('data_saida').value;
	var observacoes 	= ById('observacoes').value;
	var declaro			= ById('declaro').checked;
	
	nome 			= replaceAll(nome," ","");
	sobrenome 		= replaceAll(sobrenome," ","");
	empresa 		= replaceAll(empresa," ","");
	email 			= replaceAll(email," ","");
	cep 			= replaceAll(cep," ","");
	telefone 		= replaceAll(telefone," ","");
	fax			 	= replaceAll(fax," ","");
	
	ById('nome').style.backgroundColor='#FFFFFF';
	ById('sobrenome').style.backgroundColor='#FFFFFF';
	ById('empresa').style.backgroundColor='#FFFFFF';
	ById('email').style.backgroundColor='#FFFFFF';
	ById('endereco').style.backgroundColor='#FFFFFF';
	ById('cep').style.backgroundColor='#FFFFFF';
	ById('cidade').style.backgroundColor='#FFFFFF';
	ById('estado').style.backgroundColor='#FFFFFF';
	ById('pais').style.backgroundColor='#FFFFFF';
	ById('telefone').style.backgroundColor='#FFFFFF';
	ById('data_chegada').style.backgroundColor='#FFFFFF';
	ById('data_saida').style.backgroundColor='#FFFFFF';
	ById('observacoes').style.backgroundColor='#FFFFFF';
	
	var FormData = new Boolean("true");
	var ConteudoErro = "Foram detectados os seguintes erros:\n\n";
	
	if(nome==""){
		ConteudoErro+="- Campo requerido [NOME] .\n";
		ById('nome').style.backgroundColor='#FFFFCC';
		FormData=false;
	}
	if(sobrenome==""){
		ConteudoErro+="- Campo requerido [SOBRENOME] .\n";
		ById('sobrenome').style.backgroundColor='#FFFFCC';
		FormData=false;
	}
	if(!eh_email(email)){
		ConteudoErro+="- E-mail inválido ["+email+"] .\n";
		ById('email').style.backgroundColor='#FFFFCC';
		FormData=false;
	}
	if(empresa==""){
		ConteudoErro+="- Campo requerido [EMPRESA] .\n";
		ById('empresa').style.backgroundColor='#FFFFCC';
		FormData=false;
	}
	if(endereco==""){
		ConteudoErro+="- Campo requerido [ENDEREÇO] .\n";
		ById('endereco').style.backgroundColor='#FFFFCC';
		FormData=false;
	}
	if(cep==""){
		ConteudoErro+="- Campo requerido [CEP] .\n";
		ById('cep').style.backgroundColor='#FFFFCC';
		FormData=false;
	}
	if(cidade==""){
		ConteudoErro+="- Campo requerido [CIDADE] .\n";
		ById('cidade').style.backgroundColor='#FFFFCC';
		FormData=false;
	}
	if(estado==""){
		ConteudoErro+="- Campo requerido [ESTADO] .\n";
		ById('estado').style.backgroundColor='#FFFFCC';
		FormData=false;
	}
	if(pais==""){
		ConteudoErro+="- Campo requerido [PAÍS] .\n";
		ById('pais').style.backgroundColor='#FFFFCC';
		FormData=false;
	}
	if(telefone==""){
		ConteudoErro+="- Campo requerido [TELEFONE] .\n";
		ById('telefone').style.backgroundColor='#FFFFCC';
		FormData=false;
	}
	if(fax==""){
		ConteudoErro+="- Campo requerido [FAX] .\n";
		ById('fax').style.backgroundColor='#FFFFCC';
		FormData=false;
	}
	
	if(data_chegada!="")
	{
		if(!isDate(data_chegada))
		{
			ConteudoErro+="- A data de publicação deve ser válida e no formato [ dd/mm/aaaa ] .\n";
			ById('data_publicacao').style.backgroundColor='#FFFFCC';
			FormData=false;
		}
	}
	
	if(data_saida!="")
	{
		if(!isDate(data_saida))
		{
			ConteudoErro+="- A data de expiração deve ser válida e no formato [ dd/mm/aaaa ] .\n";
			ById('data_expiracao').style.backgroundColor='#FFFFCC';
			FormData=false;
		}
	}
	
	if((FormData)&&((data_chegada!="")&&(data_saida!=""))){
		var cvdtPublic = data_chegada.split( "/" )[2].toString() + data_chegada.split( "/" )[1].toString() + data_chegada.split( "/" )[0].toString();
		var cvdtExpira = data_saida.split( "/" )[2].toString() + data_saida.split( "/" )[1].toString() + data_saida.split( "/" )[0].toString();
	}

	if(parseInt(cvdtExpira)<parseInt(cvdtPublic)){
		ConteudoErro+="- Selecione um intervalo de datas válido.\n";
		FormData=false;
	}
	
	if(!declaro){
		ConteudoErro+="- Você deve aceitar a norma vigente de segurança de dados pessoais.\n";
		FormData=false;
	}

	if(FormData)
	{
		ById('frmEventos').submit();
		//alert('tudo ok')
	}
	else
	{
		alert(ConteudoErro);
	}
}


/*CHECAGEM DO FORMULÁRIO DE CONTATO*/
function checkContato(){

	var nome 		= document.frmContato.nome.value;
		nome 		= replaceAll(nome," ","");
	var snome 		= document.frmContato.sobrenome.value;
		snome 		= replaceAll(nome," ","");
	var email 		= document.frmContato.email.value;
		email		= replaceAll(email," ","");
	var telefone 	= document.frmContato.telefone.value;
		telefone	= replaceAll(telefone," ","");
	var cidade 		= document.frmContato.cidade.value;
		cidade		= replaceAll(cidade," ","");
	var mensagem 	= document.frmContato.mensagem.value;
		mensagem	= replaceAll(mensagem," ","");
	var declaro		= document.frmContato.declaro.checked;
	
	
	//Retorna a cor de back normal dos campos.
	document.frmContato.nome.style.backgroundColor='#FFFFFF';
	document.frmContato.sobrenome.style.backgroundColor='#FFFFFF';
	document.frmContato.email.style.backgroundColor='#FFFFFF';
	document.frmContato.telefone.style.backgroundColor='#FFFFFF';
	document.frmContato.cidade.style.backgroundColor='#FFFFFF';
	document.frmContato.mensagem.style.backgroundColor='#FFFFFF';

	var FormData = new Boolean("true");
	var ConteudoErro = "Foram detectados os seguintes erros:\n\n";

	if(nome==""){
		ConteudoErro+="- Campo requerido [NOME] .\n";
		document.frmContato.nome.style.backgroundColor='#FFFFCC';
		FormData=false;
	}
	if(snome==""){
		ConteudoErro+="- Campo requerido [SOBRE NOME] .\n";
		document.frmContato.sobrenome.style.backgroundColor='#FFFFCC';
		FormData=false;
	}
	if(!eh_email(email)){
		ConteudoErro+="- E-mail inválido ["+email+"] .\n";
		document.frmContato.email.style.backgroundColor='#FFFFCC';
		FormData=false;
	}
	
	if(telefone==""){
		ConteudoErro+="- Campo requerido [TELEFONE] .\n";
		document.frmContato.telefone.style.backgroundColor='#FFFFCC';
		FormData=false;
	}

	if(cidade==""){
		ConteudoErro+="- Campo requerido [CIDADE-UF] .\n";
		document.frmContato.cidade.style.backgroundColor='#FFFFCC';
		FormData=false;
	}

	if(mensagem==""){
		ConteudoErro+="- Campo requerido [MENSAGEM] .\n";
		document.frmContato.mensagem.style.backgroundColor='#FFFFCC';
		FormData=false;
	}

	if(!declaro){
		ConteudoErro+="- Você deve aceitar a norma vigente de segurança de dados pessoais.\n";
		FormData=false;
	}

	if(FormData)
	{
		document.frmContato.submit();
	}
	else
	{
		alert(ConteudoErro);
	}

}

/*FIM DA CHECAGEM DO FORMULÁRIO DE CONTATO*/


/*CHECAGEM DO FORMULÁRIO DE CHEKIN*/
function checkCheckin(){

	var nome_completo 		= document.frmCheckin.nome_completo.value;
		nome_completo 		= replaceAll(nome_completo," ","");
		
	var numero 				= document.frmCheckin.numero.value;
		numero		 		= replaceAll(numero," ","");
		
	var tipo 				= document.frmCheckin.tipo.value;
		tipo		 		= replaceAll(tipo," ","");
	
	var email 		= document.frmCheckin.email.value;
		email		= replaceAll(email," ","");
	
	
	//Retorna a cor de back normal dos campos.
	document.frmCheckin.nome_completo.style.backgroundColor='#FFFFFF';
	document.frmCheckin.email.style.backgroundColor='#FFFFFF';

	var FormData = new Boolean("true");
	var ConteudoErro = "Foram detectados os seguintes erros:\n\n";

	if(nome_completo==""){
		ConteudoErro+="- Campo requerido [NOME] .\n";
		document.frmCheckin.nome_completo.style.backgroundColor='#FFFFCC';
		FormData=false;
	}
	
	if(numero==""){
		ConteudoErro+="- Campo requerido [Número do Documento de Identidade] .\n";
		document.frmCheckin.numero.style.backgroundColor='#FFFFCC';
		FormData=false;
	}
	
	if(tipo==""){
		ConteudoErro+="- Campo requerido [Tipo do Documento de Identidade] .\n";
		document.frmCheckin.tipo.style.backgroundColor='#FFFFCC';
		FormData=false;
	}
	
	if(!eh_email(email)){
		ConteudoErro+="- E-mail inválido ["+email+"] .\n";
		document.frmCheckin.email.style.backgroundColor='#FFFFCC';
		FormData=false;
	}

	if(FormData)
	{
		document.frmCheckin.submit();
	}
	else
	{
		alert(ConteudoErro);
	}

}

/*FIM DA CHECAGEM DO FORMULÁRIO DE CHEKIN*/





//Checa se uma data é válida

/**
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2078;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}


function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strDay=dtStr.substring(0,pos1)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("O formato da data terá de ser: dd/mm/aaaa")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Entre com um mês válido!")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Entre com um dia válido!")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Entre com um ano de quatro dígitos válido entre  "+minYear+" e "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Entre com uma data válida!");
		return false
	}
return true
}
/*xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/

/*
Função para validação de CPF
*/
function isCPF(st) {
if (st == "")
return (false);
l = st.length;

//aleterado para se usuário não digitar os zeros na frente do CPF, completar sozinho
if ((l == 9) || (l == 8))
{
for (i = l ; i < 10; i++)
{
st = '0' + st
}
}
l = st.length;
st2 = "";
for (i = 0; i < l; i++) {
caracter = st.substring(i,i+1);
if ((caracter >= '0') && (caracter <= '9'));
st2 = st2 + caracter;
}
if ((st2.length > 11) || (st2.length < 10))
return (false);
if (st2.length==10)
st2 = '0' + st2;
digito1 = st2.substring(9,10);
digito2 = st2.substring(10,11);
digito1 = parseInt(digito1,10);
digito2 = parseInt(digito2,10);
sum = 0; mul = 10;
for (i = 0; i < 9 ; i++) {
digit = st2.substring(i,i+1);
tproduct = parseInt(digit ,10) * mul;
sum += tproduct;
mul--;
}
dig1 = ( sum % 11 );
if ( dig1==0 || dig1==1 )
dig1=0;
else
dig1 = 11 - dig1;
if (dig1!=digito1)
return (false);
sum = 0;
mul = 11;
for (i = 0; i < 10 ; i++) {
digit = st2.substring(i,i+1);
tproduct = parseInt(digit ,10)*mul;
sum += tproduct;
mul--;
}
dig2 = (sum % 11);
if ( dig2==0 || dig2==1 )
dig2=0;
else
dig2 = 11 - dig2;
if (dig2 != digito2)
return (false);
return (true);
}
/*
Fim da Função para validação do CPF
*/

/*
Função para validação de e-mail
*/
function eh_email(mail){
	var ret = false;
	if (typeof(mail) != "undefined"){
		mail = mail.match(/(\w+)@(.+)\.(\w+)$/);
	if (mail != null){
		if ((mail[3].length==2) || (mail[3].length==3))
			ret = true;
		}
	}
	return ret;
}
/*
Fim da função de validação de e-mail
*/

/*
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Função para validação de preenchimento dos campos do formulário de cadastro
*/
function CheckCad(){

	var CADASTRO_NOME 				= ById('primeiro_nome').value;
	var CADASTRO_EMAIL 				= ById('email').value;

if (CADASTRO_NOME == ""){
		alert("Campo Requerido (Nome)!")
		ById('primeiro_nome').focus();
	}
	else if(CADASTRO_EMAIL == ""){
		alert("Campo Requerido (E-mail)!")
		ById('email').focus();
	}
	else if(!eh_email(CADASTRO_EMAIL)){
		alert("E-mail inválido!")
		ById('email').focus();
	}
	else{
		//alert("Tudo Ok!")
		ById('CadAdd').submit();
	}
}
/*
Fim da função de validação de preenchimento dos campos do formulário de cadastro
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*/
/* ====================================================== */
var cell
var colorCell

// funções para hover das ceculas
function CellOver(cell,colorCell)
{
	eval("document.all."+cell+".bgColor='"+colorCell+"';");
}
function CellOut(cell,colorCell)
{
	eval("document.all."+cell+".bgColor='"+colorCell+"';");
}
/* ====================================================== */



//Função Para Replace!
function replaceAll( str, from, to ) {
    var idx = str.indexOf( from );

    while ( idx > -1 ) {
        str = str.replace( from, to ); 
        idx = str.indexOf( from );
    }

    return str;
}


// getPageSize()
// Retorna um array com largura da página, altura e largura e altura da janela
// Código de - quirksmode.org
// Editado para Firefox Por pHaez
//
function getPageSize(){

	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}
// -----------------------------------------------------------------------------------

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};
}