//*****************************************************************************
//Objetivo:					Encapsular funcionalidades do Site BSM
//Autor:					Erika Ishii
//Motivo:					
//*****************************************************************************
//*****************************************************************************
// DECLARAÇÃO DAS VARIÁVEIS
//*****************************************************************************
var garrIDDocNew = {ID:new Array()} // objeto Array
var gstrCookie  = {Nome:'',Valor:''} // objeto Array

//============================================================================================
// objetivo........: Abre e Fecha do Menu 
// Premissas.......:
// Entradas........: intCatalogo quantidade de itens do menu
//				   : objNome nome do objeto 
// Retorno.........:
//============================================================================================	
function checkExpand(intCatalogo,objNome) 
{ 
	ComprimeMenu(intCatalogo,objNome); 
		strId = objNome + "Sub";
		objEl = document.getElementById(strId);
//		document.getElementById('a'+strId.substr(0,strId.indexOf("S"))).style.color = "white";
		if (null!=objEl) objEl.style.display = "none" == objEl.style.display ? "" : "none" 
			
			return (false);
		
}
//============================================================================================
// objetivo........: Função comprime Menu
// Premissas.......:
// Entradas........:	intCatalogo
// Retorno.........:
//============================================================================================
function ComprimeMenu(intCatalogo,objNome) 
{ 
        var strItemMenu = "";		// composiçao do nome do submenu
        var strAux = "I";			// Variavel auxiliar para incremento do submenu
        var intMax = intCatalogo;	// Numero de menu	
        var intInd;					// Variavel usada no laço for
		
		for(intInd=1;intInd<=intMax;intInd++) 
        { 
                strItemMenu = objNome.substring(0,1) + strAux + "Sub"; 
                document.getElementById(strItemMenu).style.display = "none"; 
				//document.getElementById('a'+strItemMenu.substr(0,strItemMenu.indexOf("S"))).style.color = "gray";
                strAux = strAux + "I"; 
	            
        }
}

// ============================================================================================
// Objetivo  : Seleciona Item do Menu
// Premissas : Nenhuma
// Entradas  : strMetodo -- Método get/post
//           : strUrl    -- Url   
//           : blnModo   -- true or false   
//           : arrParametro -- parmetros
// Retorno   : Nenhum
// ============================================================================================

function ConfigMenu(strId,arrID)
{
    var intMenuAux;
    var arrMenuId = arrID.split('|')
    
    for (intMenuAux=0;intMenuAux<arrMenuId.length;intMenuAux++)
    {
        if(arrMenuId[intMenuAux]!='')
        {
            document.getElementById(arrMenuId[intMenuAux]).style.display='none';
        }
    }
    insereCookieUsua('MENU',strId);
    insereCookieUsua('MENU1',arrID);
    
    if(strId!='')
    {
        document.getElementById(strId).style.display='block';
    }
}

//============================================================================================
// objetivo........: Muda Tamanho da Fonte
// Premissas.......:
// Entradas........:
// Retorno.........:
//============================================================================================
function TamFonte(num, id)
{
	document.getElementById(id).className = "ft"+num;
}

//============================================================================================
// objetivo........: Muda Tamanho da Fonte
// Premissas.......:
// Entradas........:
// Retorno.........:
//============================================================================================
function mudaFonte(tipo){

	var intTamFonte = document.frmForm.hdnTamanho.value;
	if (intTamFonte == "" || intTamFonte == "NaN") {
		intTamFonte = 12;
	}
	
	if (tipo=="mais") {
		if(intTamFonte<16) intTamFonte=parseInt(intTamFonte)+1;
		document.frmForm.hdnTamanho.value = parseInt(intTamFonte);
	} 
	if (tipo =="menos") {
		if(intTamFonte>10) intTamFonte-=2;
		document.frmForm.hdnTamanho.value=parseInt(intTamFonte);
	}
	createCookie("Tamanho",parseInt(intTamFonte),365);
	document.getElementById('divConteudo').style.fontSize = intTamFonte+'px';
}

//============================================================================================
// objetivo........: Muda Tamanho da Fonte
// Premissas.......:
// Entradas........:
// Retorno.........:
//============================================================================================
function mudaFonteGd(tipo){

	var intTamFonte = document.frmForm.hdnTamanho.value;
	if (intTamFonte == "" || intTamFonte == "NaN") {
		intTamFonte = 12;
	}
	
	if (tipo=="mais") {
		if(intTamFonte<16) intTamFonte=parseInt(intTamFonte)+1;
		document.frmForm.hdnTamanho.value = parseInt(intTamFonte);
	} 
	if (tipo =="menos") {
		if(intTamFonte>10) intTamFonte-=2;
		document.frmForm.hdnTamanho.value=parseInt(intTamFonte);
	}
	createCookie("Tamanho",parseInt(intTamFonte),365);
	document.getElementById('divConteudoGde').style.fontSize = intTamFonte+'px';
}

//============================================================================================
// objetivo........: Cria cookie
// Premissas.......:
// Entradas........: name - Nome cookie
//                 : value - Valor que será armazenado
//                 : days - dias para expiração
// Retorno.........:
//============================================================================================
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	} else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

//============================================================================================
// objetivo........: Faz a leitura cookie
// Premissas.......:
// Entradas........: name - Nome cookie
// Retorno.........:
//============================================================================================
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

//============================================================================================
// objetivo........: Verifica o tamanho da fonte definido
// Premissas.......:
// Entradas........:
// Retorno.........:
//============================================================================================
function VerificarTamanhoFonte(){
    document.frmForm.hdnTamanho.value = parseInt(readCookie("Tamanho"));
    mudaFonte();
}

//============================================================================================
// objetivo........: Verifica o tamanho da fonte definido
// Premissas.......:
// Entradas........:
// Retorno.........:
//============================================================================================
function VerificarTamanhoFonteGd(){
    document.frmForm.hdnTamanho.value = parseInt(readCookie("Tamanho"));
    mudaFonteGd();
}


var undefined;
//============================================================================================
// objetivo........: isUndefined
// Premissas.......:
// Entradas........:
// Retorno.........:
//============================================================================================
function isUndefined(property) {
	return (typeof property == 'undefined');
}


//============================================================================================
// objetivo........: Grava cookie na maquina do usuário
// Premissas.......: valido somente na seção
// Entradas........: strNome - Nome da variavel
//.................: strValor - Valor da variavel
// Retorno.........: 
//============================================================================================		
function insereCookieUsua (strNome,strValor)
{
	
	
	DeleteCookieUsua(strNome);
	var dtHoje = new Date(); // objeto do tipo datetime
	document.cookie = strNome +"="+ strValor;
	
	
}

//============================================================================================
// objetivo........: Recupera cookie na maquina do usuário
// Premissas.......: valido somente na seção
// Entradas........: strNome - Nome da variavel
// Retorno.........: 
//============================================================================================		
function GetCookieUsua(strNome) 
{
    try
    {	
        var intEnd	// Posição final no cookie
        var intStart = document.cookie.indexOf( strNome + "=" );
        var intLen = intStart + strNome.length + 1;
        
        if ( ( !intStart ) && ( strNome != document.cookie.substring( 0, strNome.length ) ) )
        {
            return null;
        }
        
        if ( intStart == -1 ) return null;
        
        intEnd = document.cookie.indexOf( ";", intLen );
        if (intEnd == -1) intEnd = document.cookie.length;
        
        return unescape( document.cookie.substring( intLen, intEnd ) );
    }
    catch(objEx)
	{
		alert(objEx.message);
	}   
}
//============================================================================================
// objetivo........: Delete cookie na maquina do usuário
// Premissas.......: valido somente na seção
// Entradas........: strNome - Nome da variavel
// Retorno.........: 
//============================================================================================		
function DeleteCookieUsua(strNome)
{
    try
    {
        if (GetCookie(strNome))
        {
            document.cookie = strNome +"="+ '';";path=/;expires=Thu, 01-Jan-1970 00:00:01 GMT";
            document.cookie = strNome +"="+ '';";expires=Thu, 01-Jan-1970 00:00:01 GMT";
        }
    }
	catch(objEx)
	{
		alert(objEx.message);
	}    
}

//============================================================================================
// objetivo........: Recupera cookie na maquina do usuário
// Premissas.......: valido somente na seção
// Entradas........: strNome - Nome da variavel
// Retorno.........: 
//============================================================================================		
function GetCookie(strNome) 
{
    try
    {	
        return gstrCookie.Valor;
    }
    catch(objEx)
	{
		alert(objEx.message);
	}   
}
//============================================================================================
// objetivo........: Configura o menu inicial
// Premissas.......:
// Entradas........: 
// Retorno.........:
//============================================================================================	
function ConfigurarMenu(){
    if (GetCookieUsua('MENU')!='' && GetCookieUsua('MENU')!=null) {
        ConfigMenu(GetCookieUsua('MENU'),GetCookieUsua('MENU1'));
        if (GetCookieUsua('SUBMENU')!='' && GetCookieUsua('SUBMENU')!=null) {
            document.getElementById(GetCookieUsua('SUBMENU')).className = 'divSelect';
        }
    } 
}

//============================================================================================
// objetivo........: Delete Cookies da máquina do usuário
// Premissas.......:
// Entradas........: 
// Retorno.........:
//============================================================================================	
function DeletaCookiesMenu(){
    document.cookie = "MENU=";
    document.cookie = "MENU1=";
    document.cookie = "SUBMENU=";
}

//============================================================================================
// objetivo........: Imprimir
// Premissas.......:
// Entradas........: strId - ID do elemento e strPagina - Página que irá abrir
// Retorno.........:
//============================================================================================	
function Imprimir(strID, strPagina) {
    var objPrint;       //Objeto print
    var objJan;         //Objeto Janela
    objPrint = window.document.getElementById(strID).innerHTML;
    
    objJan = window.open(strPagina);
    objJan.document.write(objPrint);

    //objJan.history.go();
    //objJan.window.print();
}


//============================================================================================
// objetivo........: Delete Cookies da máquina do usuário
// Premissas.......:
// Entradas........: 
// Retorno.........:
//============================================================================================	
function DeletaCookiesMenu(){
    document.cookie = "MENU=";
    document.cookie = "MENU1=";
    document.cookie = "SUBMENU=";
}

//============================================================================================
// objetivo........: Valida o formulário de contato
// Premissas.......:
// Entradas........: objFrm - objeto formulário
// Retorno.........:
//============================================================================================	
function ValidaFormContato(objFrm){
    if(objFrm.txtNome.value == ""){
        alert("Informe o nome.");
        objFrm.txtNome.focus();
        return false;
    }
    if(objFrm.txtEmail.value == ""){
        alert("Informe o e-mail.");
        objFrm.txtEmail.focus();
        return false;
    }
    if (!ValidarEmail(objFrm.txtEmail.value)){
		alert("E-mail inválido.");
		objFrm.txtEmail.focus();
		return false;								
	}
    if(objFrm.txtMensagem.value == ""){
        alert("Informe a mensagem.");
        objFrm.txtMensagem.focus();
        return false;
    }
    objFrm.submit();
}

//============================================================================================
// objetivo........: Imprimir
// Premissas.......:
// Entradas........: strId - ID do elemento e strPagina - Página que irá abrir
// Retorno.........:
//============================================================================================	
function Imprimir(strID, strPagina) {
    var objPrint;       //Objeto print
    var objJan;         //Objeto Janela
    objPrint = window.document.getElementById(strID).innerHTML;
    
    objJan = window.open(strPagina);
    objJan.document.write(objPrint);

    //objJan.history.go();
    //objJan.window.print();
}

/******************************************************************************
/ Objetivo  : Acessar endereço existente em combo
/ Premissas : Nenhuma
/ Entradas  : objCombo - Instância do objeto combo
/ Retorno   : 
/******************************************************************************/
function AcessarEnderecoCombo(objCombo){
	
	if (objCombo.value.length > 0){
		if (objCombo.value.indexOf("javascript") > -1){
			eval(objCombo.value);
		}
		else if (objCombo.value.indexOf("http://") > -1){
			window.open(objCombo.value)
		}
		else {
			parent.frames["bottom"].location.href = objCombo.value;
		}
	}
	objCombo.options[0].selected=true;
}
/******************************************************************************
/ Objetivo  : Acessar endereço existente em combo
/ Premissas : Nenhuma
/ Entradas  : objCombo - Instância do objeto combo
/ Retorno   : 
/******************************************************************************/
function AcessarEnderecoComboNovaJan(objCombo){
	
	if (objCombo.value.length > 0){
		if (objCombo.value.indexOf("javascript") > -1){
			
			window.open(objCombo.value);
		}
		else if (objCombo.value.indexOf("http://") > -1){
			
			window.open(objCombo.value)
		}
		else {
			window.open(objCombo.value);
		}
	}
	objCombo.options[0].selected=true;
}
