// Detecta o Browser
var xjs_isFlashSuport = true;
/* **************************************************************
Retorna um objeto "browser" com a propriedade "type" para determinar 
o browser que o usuario utiliza.
Retorna também uma propriedade "version"
************************************************************** */
function objBrowser() {
	strTipo = '';
	strVersao = '';
	
	// Detecta se é IE
	if(document.all) { 
		strTipo = 'IE'; 
		if(window.XMLHttpRequest) { strVersao = '7'; }
		else if(document.compatMode) { strVersao = '6'; }
	}
	// Detecta de é Opera
	if(window.opera) { strTipo = 'Opera'; }
	// Detecta Gecko
	if(document.getBoxObjectFor != null) { strTipo = 'Gecko'; }
	// Detecta Safari
	if((document.childNodes) && (!document.all) && (!navigator.taintEnabled) && (!navigator.accentColorName)) { 
		strTipo = 'Safari'; 
	}

	this.type = strTipo;
	if (strTipo == 'IE') { this.version = strVersao; }
	else { this.version = ''; }
}

browser = new objBrowser();


arrMenyLiSub = new Array();
allSubMenus = new Array();
onload = execOnLoad;
function execOnLoad() { 
	abreLinksExternos();
	aplicLinkHover();
	ajustRodape();

	// Banner Natal 2009
	ShowNatal2009();    
}


onresize = execOnResize;
function execOnResize() { ajustRodape(); }

function ajustRodape()
{
	rodDiv = document.getElementById('RodapeFloat')
	getW = document.documentElement.clientWidth;
	if (getW < 1015 && getW > 770)
	{
		aj = getW - 770;
		resto = aj%2;
		if (resto != 0)
		{
			aj++;
		}
		ajf = aj/2;
		rodDiv.style.left = ajf + 'px';
	}
	else if (getW < 770)
	{
		rodDiv.style.left = '0px';
	}
	else {rodDiv.style.left = '120px';}

}




function abreLinksExternos() {
    
	// Pega todos os links
	var getLinks = document.getElementsByTagName('a');
	
	// Verifica um por um e aplica o target _blank nos que tiverem o atributo 
	// rel="externo"
	for(var i=0; i<getLinks.length; i++) {
		var anchor = getLinks[i];
		if(anchor.getAttribute("href") && anchor.getAttribute('rel')=='externo') {
			anchor.target = '_blank';
		}
	}
}




// SETA OS EVENTOS DE MOUSEOVER PARA OS BOTOES IDENTIFICADOS
function aplicLinkHover()
{
	var sufixHover = '_hover.';
	var sufixNoHover = '_nhover.';
	// Pega todos os Links da Página
	getIMGs = document.getElementsByTagName('img');

	for(var i=0; i<getIMGs.length; i++)
	{
		getSRC = getIMGs[i].src;
		// Se encontrar sufixo, aplica atributos OnMouseHover e OnMouseOut
		if (getSRC.indexOf(sufixNoHover) != -1)
		{
			// Adiciona Evento para IE
			if (browser.tipo == 'IE')
			{
				getIMGs[i].attachEvent("onmouseover", linkHover);
				getIMGs[i].attachEvent("onmouseout", linkHover);
			}
			// Adiciona Evento para Outros Browsers
			else 
			{
				getIMGs[i].setAttribute('onMouseOver', 'linkHover(this)');
				getIMGs[i].setAttribute('onMouseOut', 'linkHover(this)');
			}
		}
	}
}




// TROCA AS IMAGENS EM CASO DE MOUSEOVER/OUT
function linkHover(obj)
{
	var ie_var = "srcElement"; // Para Pegar Objeto do IE sem ter um parametro this

	var sufixHover = '_hover.';
	var sufixNoHover = '_nhover.';

	if (browser.tipo == 'IE') {	
		getSRC = obj[ie_var]['src']; 

		if (getSRC.indexOf(sufixNoHover) != -1)	{ obj[ie_var]['src'] = getSRC.replace(sufixNoHover, sufixHover); }
		else if (getSRC.indexOf(sufixHover) != -1) { obj[ie_var]['src'] = getSRC.replace(sufixHover, sufixNoHover); }
	}

	else { 
		getSRC = obj.src; 

		if (getSRC.indexOf(sufixNoHover) != -1)	{ obj.src = getSRC.replace(sufixNoHover, sufixHover); }
		else if (getSRC.indexOf(sufixHover) != -1) { obj.src = getSRC.replace(sufixHover, sufixNoHover); }
	}
}




function openPopup(url, name, w, h, scrollbars, resize) 
{
    window.open(url, name, 'Width=' + w + ', Height=' + h + ', scrollbars=' + scrollbars + ', resizable=' + resize);
}


function validLogin()
{
    login = document.getElementById('includeConceitual_inptLogin').value;
    senha = document.getElementById('includeConceitual_inptSenha').value;
    if (login == '' || senha == '')
    {
        alert('Preencha todos os campos de Login');
        return false;
    }
    else
    {
        return true;
    }
}


function validPageLogin()
{
    login = document.getElementById('inptLogin').value;
    senha = document.getElementById('inptSenha').value;
    if (login == '' || senha == '')
    {
        alert('Preencha todos os campos de Login');
        return false;
    }
    else
    {
        return true;
    }
}









/* **************************************************************
Retorna uma tag para inserir um Flash.
O Uso de flashvars pode ser feito incrementanto mais argumentos
alem dos minimos usando a seguinte sintaxe: nomevar=valor
************************************************************** */
function createFlashTag(srcSWF, thisID, thisClass, thisTitle, thisQuality, width, height, isTransparent)
{
	strObject = '<object ';
	strObject += 'classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ';
	strObject += 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" ';
	if (thisID != '') { strObject += 'id="' + thisID + '" '; }
	if (thisClass != '') { strObject += 'class="' + thisClass + '" '; }
	if (thisTitle != '') { strObject += 'title="' + thisTitle + '" '; }

	strObject += 'width="' + width + '" ';
	strObject += 'height="' + height + '" ';
	strObject += '>';

	param = '<param name="allowScriptAccess" value="sameDomain" />';
	param = '<param name="movie" value="' + srcSWF + '" />';
	param += '<param name="quality" value="'+ thisQuality +'" />';
	if (isTransparent == 'true') { param += '<param name="wmode" value="transparent">'; }

	// Verifica existencia de flashvars
	flashvars = '';
	tArgs = arguments.length;
	if (tArgs > 8) {
		for(i=8; i<tArgs; i++) {
			if(i==8){ flashvars += arguments[i]; }
			else{ flashvars += "&" + arguments[i]; }
		}
		param += '<param name="flashvars" value="' + flashvars + '" />';
	}

	strEmbed = '<embed ';
	strEmbed += 'pluginspage="http://www.macromedia.com/go/getflashplayer" ';
	strEmbed += 'type="application/x-shockwave-flash" ';
	strEmbed += 'allowScriptAccess="sameDomain" ';
	strEmbed += 'src="' + srcSWF + '" ';
	strEmbed += 'quality="'+ thisQuality +'" ';
	strEmbed += 'width="' + width + '" ';
	strEmbed += 'height="' + height + '" ';
	if (isTransparent == 'true') { strEmbed += 'wmode="transparent" '; }
	if (flashvars != '') { strEmbed += 'flashvars="' + flashvars + '" '; }
	strEmbed += '></embed>';

	tag = strObject + param + strEmbed + '</object>';
	return tag;
}





/* **************************************************************
Escreve a Tag de Flash Gerada pela createFlashTag()
************************************************************** */
function writeFlash(tagWrite){ document.write(tagWrite); }





/* **************************************************************
A partir do conjunto de uma tag com uma classe, encontra toda ocorrencia
de ambas para substituir o conteudo da tag por um flash determinado
************************************************************** */
function fontReplace(srcSWF, thisID, thisClass, thisQuality, width, height, isTransparent, getTagByClass, searchTag)
{
	getTag = new Array;
	getTag = getElementsByClassName(getTagByClass, searchTag);
	for (f=0; f<getTag.length; f++)
	{
		content = getTag[f].innerHTML;
		thisTitle = content;
		flashvar = 'taginside=' + content;
		newTag = createFlashTag(srcSWF, thisID, thisClass, thisTitle, thisQuality, width, height, isTransparent, flashvar);
		getTag[f].innerHTML = newTag;
		getTag[f].style.visibility = 'visible';
	}
}




/* **************************************************************
Extende uma Div por Toda a Area de Determinado Node
parentID - 'Screen' : usa toda a area visivel como referencia
setW e setH: seta quais propriedades devem ser alteradas
	'yes' ou 'no'
outros parametros devem ser ID de elementos a serem diminuidos
************************************************************** */
function extendToNode(thisID, parentID, setW, setH){
	var totalW;
	var totalH;
	if(parentID == 'Screen'){
	    totalW = screen.width;
		totalH = screen.height;
	}
	else {
		totalW = id(parentID).clientWidth;
		totalH = id(parentID).clientHeight;
		alert(totalH);
	}

	var tArgs = arguments.length;
	var decW = 0;
	var decH = 0;
	if (tArgs > 4) {
		for(i=4; i<tArgs; i++) {
			if(id(arguments[i])) {
			getW = id(arguments[i]).clientWidth;
			getH = id(arguments[i]).clientHeight;
			decW += getW; 
			decH += getH;
	} } }
	
	var finalW = totalW - decW;
	var finalH = totalH - decH;

	if(browser.type == 'IE' && browser.version == '6'){
		if(setW == 'yes'){ id(thisID).style.width = finalW + 'px'; }
		if(setH == 'yes'){ id(thisID).style.height = finalH + 'px'; }
	}
	else {
		if(setW == 'yes'){ id(thisID).style.minWidth = finalW + 'px'; }
		if(setH == 'yes'){ id(thisID).style.minHeight = finalH + 'px'; }
	}
}


// Retorna Elemento Pelo seu ID
function id(idName) { return document.getElementById(idName); }
// Retorna Array de Todos os Elementos Com Mesmo Nome de Tag
function tag(tagName) { return document.getElementsByTagName(tagName); }



function positionAtCenter()
{
	largElem = id('divModal').clientWidth;
	totalW = document.documentElement.clientWidth;
	leftPos = (totalW/2) - (largElem/2);
	id('divModal').style.left = leftPos + 'px';
}




function setZindexForAll() {
	// Seta todos zIndex dos LI com Sub para 1;
	allLIsInMenu = document.getElementById('bxMenuP').getElementsByTagName('li');
	for(i=0; i<allLIsInMenu.length; i++) { 
		if(allLIsInMenu[i].className.indexOf('sub') != -1) {
			allLIsInMenu[i].style.zIndex = 1; 
		}
	}
};

function setEvent(evType, evName, arrObj) {
	for(i=0; i<arrObj.length; i++) {
		node = arrObj[i];
		//if (document.attachEvent) {	node.attachEvent('on'+ evType, evName); }
		node.addEventListener(evType, evName, false);
	}
};


function openThisMenu(idMenu) {
	setZindexForAll();
	mMenu = document.getElementById(idMenu);
	mMenu.style.display = 'block';
	mMenu.style.zIndex = 3;
};
isNotClose = false;
function closeThisMenu(idMenu) {
	mMenu = document.getElementById(idMenu);
	if(isNotClose == false) { mMenu.style.display = ''; }
};

function openThisBox(obj) {
	isNotClose = true;
	obj.style.display = 'block';
	setTimeout('isNotClose = false;', 50);
};
function closeThisBox(obj) {
	obj.style.display = 'none';
};




function ShowNatal2009() {
    // Ajusta Shadow
    extendToNode('boxShadow', 'Screen', 'no', 'yes');
    if (browser.type == 'IE' && browser.version == '6') {
        aH = parseInt(id('boxShadow').style.height.replace('px', ''));
        id('boxShadow').style.height = (aH + 20) + 'px';
    }
    else {
        aH = parseInt(id('boxShadow').style.minHeight.replace('px', ''));
        id('boxShadow').style.minHeight = (aH + 20) + 'px';
    }

    // Esconde SWF
    id('targetFlash').style.visibility = 'hidden';
};

function fecharmsg() {
    // Esconde SWF
    id('targetFlash').style.visibility = 'visible';
    id('boxShadow').style.display = 'none';
    id('boxOverShadow').style.display = 'none';
};