/* **************************************************************
	ONLOAD
- Seta thisPage com propriedades da Pagina atual
- Adiciona Links Externos
- Adiciona Evento Link Hover
- Se browser for IE Anexa Javascripts Auxiliares
************************************************************** */
function executeOnLoad(){
	xjsBool_DOMisLoad = true;
    xjs_thisPage = new objPageInfo(xjsStr_Location);
	//setTargetBlank();
	setTargetBlank2();
	setLinkHover();

	if(xjs_browser.type == 'IE'&& xjs_browser.version == '6'){
        if(xjsStr_Location.indexOf('Newsletter.aspx') == -1) {
	        addHoverSuport_byID('ulMenuPrincipal', 'li');
		    searchAndInsertIframe('div', 'iFrame'); 
		    autoResizeIframes();
		    if(id('paginacaoBottom')) { iePagBottomAjust(); } // Ajusta box de Paginação para IE6
		}
	}
	initiDHTMLSelects(); // <- Para Selects DHTML
	
	if(execOnLoad != '') { eval(execOnLoad); }
}
onload = executeOnLoad;
var execOnLoad = '';




/* **************************************************************
	ONRESIZE
- Atualiza propriedades da Pagina atual
- Se modal estiver aberto, redimensiona a 'sombra' e respectivo
	iframe(IE6)
************************************************************** */
function executeOnResize(){ 
	xjs_thisPage = new objPageInfo(xjsStr_Location);
	if(xjsBool_ModalIsOpen == true) { 
		extendToNode('divShadow', 'Screen', 'yes', 'yes'); 
		if(xjs_browser.type == 'IE' && xjs_browser.version == '6') { 
		    autoResizeIframes(); 
		}
	}
}
onresize = executeOnResize;





/* **************************************************************
	ONKEYDOWN
- Atualiza 'xjsLastKeyDown' ao apertar alguma tecla
- Há uma lista de testes com endereços de telas onde, se a tecla
	pressionada for 'enter', irá disparar a função activeOnEnter()
************************************************************** */
function executeOnKeyDown(e) { 
    xjsInt_LastKeyDown = checkKeycode(e); 
  /*  if(xjsStr_Location.indexOf('exemplos/ModeloContato.htm') != -1){ if(xjsLastKeyDown == 13) { activeOnEnter(); } }*/
}
document.onkeydown = executeOnKeyDown;





/* **************************************************************
	ONKEYPRESS
- Inibe o Som Produzido pelo IE ao Pressionar Enter
************************************************************** */
function executeOnKeyPress() {
	/*if(MonitoreEnter == true){
	    if(browser.type == 'IE' && xjsLastKeyDown == 13) { return false; }
}*/ }
document.onkeypress = executeOnKeyPress;





/* **************************************************************
	ONMOUSEDOWN
- Percebe quando o Mouse for Clicado
************************************************************** */
function executeOnMouseDown() {
	setTimeout("closeDHTMLSelect()", 100); // <- Para Selects DHTML
}
document.onmousedown = executeOnMouseDown;





/* **************************************************************
	ONMOUSEUP
- Percebe quando o Mouse for Clicado
************************************************************** */
function executeOnMouseUp() {
}
//document.onmouseup = executeOnMouseUp;








/* **************************************************************
Declaração de javascripts especifícos
- SCRIPTS DO TEASER
************************************************************** */
var isHorizonBarr = false;
function setHBarr() {
	var setValue = '';
	if(xjs_thisPage.windowW > 900) { setValue = 'hidden'; }
	else { setValue = 'scroll'; }

	if(xjs_browser.type != 'IE') { document.body.style.overflowX = setValue; }
	else { 
		getHTML = tag('html')[0];
		getHTML.style.overflowX = setValue; 
	}
}
/* FIM SCRIPTS DO TEASER */

function  iePagBottomAjust() { 
	newTop = xjs_thisPage.bodyH - 192;
	id('paginacaoBottom').style.top = newTop + 'px';
}


function showHideNews(imgIdName, boxIdName) {
	var newClass = '';
	var srcImg = '';
	if(id(boxIdName).className == 'hidePost') { 
		newClass = 'openPost'; 
		srcImg = '../../img/ico_quadro_menos.gif';
	}
	else if (id(boxIdName).className == 'openPost') { 
		newClass = 'hidePost'; 
		srcImg = '../../img/ico_quadro_mais.gif';
	}
	id(boxIdName).className = newClass;
	id(imgIdName).src = srcImg;
}


function showHideElement(idName, value){
    if(id(idName)) { setDisplay(idName, value); }
}



/* ATLETAS */
function hideAllAbas() {
    id('boxAtletaVideo').style.display = 'none';
    id('menuAbaVideo').src = '../../img/atletas/btn_aba_videos_off.gif';
    id('boxAtletaGaler').style.display = 'none';
    id('menuAbaGaler').src = '../../img/atletas/btn_aba_galeria_de_fotos_off.gif';
    xjs_thisPage = new objPageInfo(xjsStr_Location);
}


function showVideoAtletas() {
    hideAllAbas();
    id('boxAtletaVideo').style.display = 'block';
    id('menuAbaVideo').src = '../../img/atletas/btn_aba_videos_on.gif';
    xjs_thisPage = new objPageInfo(xjsStr_Location);
}


function showFotosAtletas() {
    hideAllAbas();
    id('boxAtletaGaler').style.display = 'block';
    id('menuAbaGaler').src = '../../img/atletas/btn_aba_galeria_de_fotos_on.gif';
    xjs_thisPage = new objPageInfo(xjsStr_Location);
}

function changeVideoSWF(ttlVideo, index){
    var videoDiv = getTagsChildOfID('videoContainer', 'div');
    for(i=0; i<videoDiv.length; i++) { videoDiv[i].style.display = 'none'; }

    var idName = 'swfContainer_' + index;
    id('ttlVideo').innerHTML = ttlVideo;
    id(idName).style.display = 'block';
}

















/* FUNÇÕES PARA O MODAL DA NEWSLETTER */
function openModalNewsLetter() {
    var isNome = isEmpty('inptNewsletter_Nome');
    var isEmaill = isEmail('inptNewsletter_Email');
    var msg = 'Foram encontrados os Seguintes Erros: \n';
    
    if(isNome != 0 || id('inptNewsletter_Nome').value == 'Seu nome') { msg += 'Nome não declarado \n'; }
    if(isEmaill != 0 || id('inptNewsletter_Email').value == 'E-mail') { msg += 'E-mail declarado não é válido \n'; }
    
    if(isNome != 0 || isEmaill != 0 || id('inptNewsletter_Nome').value == 'Seu nome') { alert(msg); }
    else { 
        strNome = id('inptNewsletter_Nome').value;
        strMail = id('inptNewsletter_Email').value;
        strParam = 'nome=' + strNome + '&email=' + strMail;
        
        if(xjs_browser.type == 'IE' && xjs_browser.version == '6') {
            strParam += '&isPop=true';
            var newsPop = new objPopUp('../modal/Newsletter.aspx?' + strParam, 'NewsLetter', 'no', 'no');
            newsPop.setDimencion(false, 420, 392);
            newsPop.setPosition(true, '', '');
            newsPop.openThis();
        }
        else {
            showHideModal('show', 'Newsletter', strParam);
        }
    }
}



// Adiciona Evento 'showHideUFModal' ao Selecionar o Pais
function setSelectModal(strID) {
    var AllLIs = getTagsChildOfID(strID, 'li');
    for(i=0; i<AllLIs.length; i++) {
        setEvent(AllLIs[i], 'mousedown', 'showHideUFModal');
    }
}
    // Evento que esconde ou mostra Modal de Estados
    function showHideUFModal(obj) {						        
        if(document.attachEvent) { var obj = (obj.srcElement) ? obj.srcElement : obj.target; }
        var Pais = obj.title;		                        
        if(Pais == 'brasil'){ id('divUFModal').style.display = 'block'; }
        else { id('divUFModal').style.display = 'none'; }
    }


// Função que faz a Validação dos Dados enviados para Gerar um Cadastro na
// Newsletter
function returnIsValidFormModal(idNome, idMail, idFone, idPais, idUF, nameRadio) {
    var formContato = new objFormValidation();
    formContato.setOutPut('alert', '');

    var isSend = 0;
    
    formContato.addField(idNome, 'isEmpty', 'Nome');
    formContato.addField(idMail, 'isEmail', 'Email');

    formContato.addField(idFone, 'isEmpty', 'Fone');
    formContato.addField(idPais, 'isDHTMLSelected', 'Pais');
    
    if(id(idPais + '_Text').value == 'Brasil' || id(idPais + '_Value').value == 'brasil') {
        formContato.addField(idUF, 'isDHTMLSelected', 'Estado');
    }
    formContato.addField(nameRadio, 'isRadioSelect', 'Gênero');
    
    isSend = checkButtonsModal();
    
    if(isSend == 0) { return formContato.checkForm(); }
    else { return false;}
}

    // Checa se há algum Perfil Selecionado
    function checkButtonsModal(){
        allInputs = getTagsChildOfID('divCheckPerfilModal', 'input');

        var Checkeds = 0;
        for(i=0; i<allInputs.length; i++) {
            if(allInputs[i].checked == true) { Checkeds++; }
        }
        if(Checkeds == 0) { alert('Você deve escolher ao menos uma opção de Perfil'); return 1;}
        else { return 0;}
    }

    // Função de Validação de Select DHTML Corrijida
    function isDHTMLSelected(idName){ 
        inptText = id(idName + '_Text').value;
        inptValue = id(idName + '_Value').value;

        allOptions = getTagsChildOfID(idName, 'li');
        isErro = 0;
        for(i=1; i<allOptions.length; i++) {
            liText = allOptions[i].innerHTML;
            liValue = allOptions[i].title;
            if(inptText == liText && inptValue == liValue) { return 0; }
        }
        return 3;
    }


/*
    Quando um Modal Newsletter estiver Enviando Dados para Cadastro
    A função abaixo validará os dados e se corretos, re-envia pedido de modal
    Desta vez com o Parametro 'isMPB=true' indicando que deve ser retornado
    HTML de retorno.
*/
function SendDataNewsletter(idNome, idMail, idFone, idPais, idUF, nameRadio) {

    if(returnIsValidFormModal(idNome, idMail, idFone, idPais, idUF, nameRadio)) {

        var param = 'isMPB=true';
        param += '&nome=' + id(idNome).value;
        param += '&email=' + id(idMail).value;
        param += '&fone=' + id(idFone).value;
        param += '&pais=' + id(idPais + '_Text').value;
        if(id(idPais + '_Text').value == 'Brasil') {
            param += '&estado=' + id(idUF + '_Text').value;
        }
        else {
            param += '&estado=none';
        }
        
        var getRadio = getTagsChildOfID('divModalGender', 'input');
        var gender = '';
        for(i=0;i<getRadio.length; i++){
            if(getRadio[i].checked == true) { gender = getRadio[i].value; break;}
        }
        param += '&genero=' + gender;
        param += '&' + GetPerfils();
        
        //alert(param);
        showHideModal('show', 'Newsletter', param);
    }   
}


// Retorna Parametros baseados nos Perfils Escolhidos
function GetPerfils() {
    var strReturn = '';
    allInputs = getTagsChildOfID('divCheckPerfilModal', 'input');
    if(allInputs[0].checked == true) { strReturn += 'isConsumidor=true'; }
    else { strReturn += 'isConsumidor=false'; }
    if(allInputs[1].checked == true) { strReturn += '&isFornecedor=true'; }
    else { strReturn += '&isFornecedor=false'; }
    if(allInputs[2].checked == true) { strReturn += '&isCliente=true'; }
    else { strReturn += '&isCliente=false'; }
    if(allInputs[3].checked == true) { strReturn += '&isColaborador=true'; }
    else { strReturn += '&isColaborador=false'; }
    if(allInputs[4].checked == true) { strReturn += '&isAtleta=true'; }
    else { strReturn += '&isAtleta=false'; }
    if(allInputs[5].checked == true) { strReturn += '&isAmador=true'; }
    else { strReturn += '&isAmador=false'; }
    if(allInputs[6].checked == true) { strReturn += '&isRepresentante=true'; }
    else { strReturn += '&isRepresentante=false'; }
    
    return strReturn;
}