﻿/* **************************************************************
		INICIAR OBJETOS E VARIAVEIS PRINCIPAIS
************************************************************** */



// Objetos Básicos
var xGet = new XHtmlGet(); // OBJECT 
var xDoc = new XHtmlDocument(); // OBJECT 
var xIEsupport = null; // OBJECT 
// Requisições Assíncronas
var RequestConfig = new objXmlHttpRequestConfig();  // OBJECT 
var XmlHttp = new objXmlHttpRequest(RequestConfig);  // OBJECT 
var xjs_isApplicationXml = true; // BOOLEAN --> Se Requisições Assincronas devem Retornar XML


// Configuração dos Objetos e Eventos
var xjs_IDPrincipal = 'divPrincipal'; // STRING --> ID do container principal da Tela
var xjs_isLayoutVazado = false; // BOOLEAN --> Use 'true' Para Layouts Vazados, configure a function 
var xjs_resizeDelay = 200; // INTEGER --> Delay entre cada Operação do Evento OnResize [milessegundos]
var xjs_onEndResize = null; // Variavel de Cotrole do Evento OnResize
var xjs_newWindowMimeType = 'doc,docx,xls,xlsx,pdf'; // STRING --> Extensão de Arquivos que Abrirão em outra janela


// PlugIn Flash Player
var xjs_isFlashSuport = xDoc.isFlashPlayer(); // BOOLEAN -> Se Há ou Não Suporte ao Flash no Browser
var xjs_GetFlashLink = document.createElement('a');
	xjs_GetFlashLink.href = 'http://www.adobe.com/go/getflash/';
	xjs_GetFlashLink.innerHTML = 'Get Adobe Flash Player';


// Layout - Modal
var xjs_isModalOpen = false; // BOOLEAN --> Se Modal está Aberto Ou Não
var xjs_IDModalOpen = null; // STRING --> Nome da ID do Modal que Está Aberto no Momento
var xjs_ModalOnLoadH = 100; // INTEGER --> Altura Padrão Minima Para o Modal
var xjs_ModalOnLoadW = 200; // INTEGER --> Largura Padrão Minimo Para o Modal
var xjs_ModalY = 'middle'; // 'middle' ou INTEGER --> Distancia que o Modal deve ser Colocado do Topo
var xjs_ModalX = 'middle'; // 'middle' ou INTEGER --> Distancia que o Modal deve ser Colocado da Esquerda
var xjs_ModalErrorMessage = 'Aconteceu um erro ao carregar esta janela e ela será fechada';
var xjs_isModalDebug = true; // BOOLEAN --> se true, mostra mensagens técnicas de erro.



/* **************************************************************
	FORMULÁRIOS 

	- Métodos de Validação
	isEmpty			- Se Input está Vazio
	isData			- Se é uma Data
	isEmail			- Se é um E-mail
	isLink			- Se é um Link
	isSelected		- Se Select está Selecionado
	isRadioSelect	- Se Algum Radio Button da Coleção
	isCheckSelect	- Se Algum CheckBox da Coleção
	isCPF			- Se é um CPF 
	isCNPJ			- Se é um CNPJ
************************************************************** */
var xjs_LastKeyDown = null; // INTEGER -> Armazena Código da Última Tecla Pressionada Pelo Usuário
var xjs_isMonitoreEnter = false; // BOOLEAN --> Se Tecla Enter Está Sendo Moniturada [se true, dispara evento definido]
var xjs_isExecuteOnEnter = false; // BOOLEAN -> Se Enter Deve Ou Não Disparar Evento Pré Definido ExecuteOnEnter


// Configuração do Objeto de Validação de Formulários
var xjs_DateSpace = '.'; // Completa a Mascada de data identificando o seu separador
var xjs_DefaultFieldString = '*?*'; // String que será trocada nas mensagens pelo nome do campo
var xjs_DefaultTitleAlert = 'Foram encontrados os seguintes erros:';
var xjs_DefaultEmptyInput = 'O Campo *?* deve ser preenchido.';
var xjs_DefaultWrongValue = 'O Campo *?* está incorreto.';
var xjs_DefaultNotSelected = 'Escolha uma das Opções do Campo *?*.';











/* **************************************************************
	ONLOAD
- Seta thisPage com propriedades da Pagina atual
- Adiciona Links Externos
- Adiciona Evento Link Hover
- Se browser for IE Anexa Javascripts Auxiliares
************************************************************** */
function executeOnLoad(){
	xDoc.InitiUserAgentInformation(); // Resgata Informações do User Agent
	xDoc.InitiPageInformation(); // Resgata Informações da Pagina Atual
	xDoc.GetPageDimensions(xjs_IDPrincipal); // Resgata Informações das Dimensões da Tela Atual
	xDoc.docIsLoad = true; // Informa que o Documento foi Carregado Completamente
	//xDoc.setTargetBlank();
	xDoc.setImgChangeOnOver('xDoc');

	// Carrega CSS para Safari
	if(xDoc.userBrowser == 'Safari') { xDoc.loadCSS('../../css/browsers/styles-safari.css'); }

	// Se for um Layout Vazado Ajusta Divs
	if(xjs_isLayoutVazado == true) { layoutVazado(); }

	// Aplica Iframe Em Nodes Com a Classe Definida
	if(xDoc.userBrowser == 'IE'&& xDoc.userBrowserVersion == '6'){
		xIEsupport = new XHtmlIESupport('ie6IFrame');
		xIEsupport.iframeNodesParent = xGet.get('div.iFrame');
		xIEsupport.setIframe();
	}
	if(xDoc.userBrowser == 'IE') {

	    isTableMusic = xGet.get('.tableComum');
		if(isTableMusic != null) {
		    lastTD = xGet.get('.tableComum tr td:last-child');
			xGet.setClass('last-child');
			lastTR = xGet.get('.tableComum tr:last-child');
			xGet.setClass('last-child');			
		}
	}

	/* --- Espaço para Adição de Novos Scripts --- */
	setMenuProgramacao();
	/* --- // ----------------------------- // --- */

    // Variavel Usada para Concatenar Métodos Adicionados 'On demannd'
	if (onLoadExecuteThis != '') { eval(onLoadExecuteThis); }



	// Ajusta tamanho do Node Principal
	SetHPrincipal();
};
onload = executeOnLoad;
var onLoadExecuteThis = '';




/* **************************************************************
	ONRESIZE
- Atualiza propriedades da Pagina atual
- Se modal estiver aberto, redimensiona a 'sombra' e respectivo	iframe(IE6)
************************************************************** */
function executeOnResize(){ 
	if(xjs_onEndResize == null) { 
		xDoc.GetPageDimensions('divPrincipal');
		// Só executa Os Scripts Abaixo ao Final de determinado Prazo. Isto evita o excesso de chamadas do IE à Este método
		xjs_onEndResize = setTimeout('executeOnResizeEnd()', xjs_resizeDelay);
	}
};
/* Adicione aqui Ações a Serem Executadas ao Final do OnResize */ 
function executeOnResizeEnd() {
	// Se for um Layout Vazado Ajusta Divs
	if(xjs_isLayoutVazado == true) { layoutVazado(); }
	// Se modal está Aberto, reposiciona Shadow e o Próprio Modal
	if(xjs_isModalOpen == true) { showHideShadow('show'); setModalCoords(); }
	// Recalcula Dimensão de Iframe Em Nodes Com a Classe Definida
	if(xDoc.userBrowser == 'IE' && xDoc.userBrowserVersion == '6'){ 
		xIEsupport.resizeIframes(); 
	}


	/* --- Espaço para Adição de Novos Scripts --- */
	SetHPrincipal();
	/* --- // ----------------------------- // --- */


	// Variavel Usada para Concatenar Métodos Adicionados 'On demannd'
	if(onResizeExecuteThis != '') { eval(onResizeExecuteThis); }
	xjs_onEndResize = null;
};
onresize = executeOnResize;
var onResizeExecuteThis = '';





/* **************************************************************
	ONKEYDOWN
	- Ao final do ato de pressionar uma tecla, o código correspondente
	à mesma fica 'assinado' na variavel 'xDoc.lastKeyDown'
************************************************************** */
function executeOnKeyDown(e) {
	xDoc.getKeyCode(e);
	if(xjs_isExecuteOnEnter == true && xjs_LastKeyDown == 13){ ExecuteOnEnter(); }
};
document.onkeydown = executeOnKeyDown;





/* **************************************************************
	ONKEYPRESS
- Inibe o Som Produzido pelo IE ao Pressionar Enter
************************************************************** */
function executeOnKeyPress() {
    if(xjs_isMonitoreEnter == true){ if(xDoc.userBrowser == 'IE' && xjs_LastKeyDown == 13) { return false; } }
};
document.onkeypress = executeOnKeyPress;





/* **************************************************************
	ONMOUSEDOWN
- Percebe quando o Mouse for Clicado
************************************************************** */
function executeOnMouseDown() {};
document.onmousedown = executeOnMouseDown;





/* **************************************************************
	ONMOUSEUP
- Percebe quando o Mouse for Clicado
************************************************************** */
function executeOnMouseUp() {};
//document.onmouseup = executeOnMouseUp;








/* **************************************************************
Declaração de javascripts especifícos
************************************************************** */
function setMenuProgramacao() {
	// Seta ZIndex nos LI para que BoxInfo Não se Sobreponham àos Itens da Lista Abaixo
	allLI = xGet.get('#boxMenuProgramacao ul li');
	if(allLI != null) {
		zIndexAtual = allLI.length;
		for(i=0; i<allLI.length; i++) {
			allLI[i].style.zIndex = zIndexAtual;
			zIndexAtual--;
		}
	}

	xGet.get('#boxMenuProgramacao ul li .datainfo');
	xGet.setEvent('mouseover', 'openEvent');
	xGet.setEvent('mouseout', 'closeEvent');

	xGet.get('#boxMenuProgramacao ul li .boxInfo');
	xGet.setEvent('mouseover', 'openThisBoxInfo');
	xGet.setEvent('mouseout', 'closeThisBoxInfo');
};

function openEvent(obj) {
	if (document.attachEvent) {	var obj = (obj.srcElement) ? obj.srcElement : obj.target; }
	parentLI = obj.parentNode;
	if(parentLI.className == '') { parentLI.className = 'open'; }
};
isNotClose = false;
function closeEvent(obj) {
	if (document.attachEvent) {	var obj = (obj.srcElement) ? obj.srcElement : obj.target; }
	parentLI = obj.parentNode;
	if(isNotClose == false) {
		parentLI.className = '';
	}
};

function openThisBoxInfo(obj) {
	isNotClose = true;
	if (document.attachEvent) {	
		var obj = (obj.srcElement) ? obj.srcElement : obj.target; 
		nodeT = obj; 
		while(nodeT != 'LI') { obj = obj.parentNode; nodeT = obj.tagName; }
		parentLI = obj;
	}
	else { parentLI = obj.parentNode.parentNode; }
	parentLI.className = 'open';
	setTimeout('isNotClose = false;', 50);
};
function closeThisBoxInfo(obj) {
	if (document.attachEvent) {	
		var obj = (obj.srcElement) ? obj.srcElement : obj.target; 
		nodeT = obj; 
		while(nodeT != 'LI') { obj = obj.parentNode; nodeT = obj.tagName; }
		parentLI = obj;
	}
	else { parentLI = obj.parentNode.parentNode; }
	parentLI.className = '';
};


function SetHPrincipal() {
    totalH = xDoc.windowH;
    instDivH = xGet.get('#divPrincipal').clientHeight;
    rodapeH = xGet.get('#boxRodape').clientHeight;

    if (instDivH < totalH) {
        xGet.get('#divPrincipal').style.height = totalH + 'px';
    }
};



/* IMPEDE AÇÃO DO BOTÃO CONTRÁRIO */
//function click() { if (event.button==2||event.button==3) { oncontextmenu='return false'; } };
//document.onmousedown=click
document.oncontextmenu = new Function("return false;");




/* VALIDAR OSPA NEWS */
function ValidOSPANews() {
    var formContato = new objFormValidation();

    var isSend = 0;
    formContato.addField(xGet.get('#inputEmail'), 'isEmail', 'Email');

    if (formContato.checkForm()) {
        var obj = null;
        obj = document.createElement('iframe');
        obj.src = '../home/ospanews.aspx?email=' + xGet.get('#inputEmail').value;
        obj.width = 1;
        obj.height = 1;
        obj.frameBorder = 0;
        obj.scrolling = 'no';
        xGet.get('#modalAlert').appendChild(obj);
        

        xGet.get('#modalAlert').innerHTML = 'Seu e-mail foi cadastrado com sucesso, Obrigado.';
        xGet.get('#inputEmail').value = '';
    }
}

