
/*
|----------------------------------------------------------------------------------------------------|
|          Projeto: WebSite da KOPENHAGEN                                     |
|        Descrição: Arquivo de funções JS usadas nas páginas internas |
|           Criado: 07/08/2006 | Por: Rafael Une/Victor Leonardo             |
|       Modificado: __/__/____ | Por:                                                   |
|----------------------------------------------------------------------------------------------------|
*/

/*
|----------------------------------------------------------------------------------------------------|
|           Função: VersaoParaImpressao()                                                            |
|        Descrição: Abre popup com o texto sem formatação.                                           |
|  ================================================================================================  |
|       Parâmetros: nenhum                                                                           |
|           Evento: onclick                                                                          |
|  Tipo de Retorno: booleam                                                                          |
|  ================================================================================================  |
|           Criado: 07/08/2006 | Por: Mauro Willian                                                  |
|       Modificado: __/__/____ | Por:                                                                |
|----------------------------------------------------------------------------------------------------|
*/
function VersaoParaImpressao(L_ROOT)
{
    //Configurando as dimensões da janela
	var inteWindowWidth		= 700;
	var inteWindowHeight	= 500;
	//Recuperando a resolução do clienye
	var inteWidth					= screen.width;
	var inteHeight				= screen.height;
	//Configurando a posição da janela
	var inteWindowTop			= ((inteHeight - inteWindowHeight)/2);
	var inteWindowLeft		= ((inteWidth - inteWindowWidth)/2);
	//Abrindo a janela com as configurações anteriores
	var oPopup	= window.open(L_ROOT + 'tools/Imprimir.aspx', 'VersaoParaImpressao', 'top='+ inteWindowTop +', left='+ inteWindowLeft +', width='+ inteWindowWidth +', height='+ inteWindowHeight +', scrollbars=1');
	oPopup.focus();
	
	return false;
}

/*
|----------------------------------------------------------------------------------------------------|
|           Função: VersaoParaImpressao()                                                            |
|        Descrição: Abre popup com o texto sem formatação.                                           |
|  ================================================================================================  |
|       Parâmetros: nenhum                                                                           |
|           Evento: onclick                                                                          |
|  Tipo de Retorno: booleam                                                                          |
|  ================================================================================================  |
|           Criado: 07/08/2006 | Por: Mauro Willian                                                  |
|       Modificado: __/__/____ | Por:                                                                |
|----------------------------------------------------------------------------------------------------|
*/
function EnviarPagina(L_ROOT, page)
{
    //Configurando as dimensões da janela
	var inteWindowWidth		= 420;
	var inteWindowHeight	= 405;
	//Recuperando a resolução do clienye
	var inteWidth					= screen.width;
	var inteHeight				= screen.height;
	//Configurando a posição da janela
	var inteWindowTop			= ((inteHeight - inteWindowHeight)/2);
	var inteWindowLeft		= ((inteWidth - inteWindowWidth)/2);
	//Abrindo a janela com as configurações anteriores
	var oPopup	= window.open(L_ROOT + 'tools/EnviarPagina.aspx?page=' + page, 'EnviarPagina', 'top='+ inteWindowTop +', left='+ inteWindowLeft +', width='+ inteWindowWidth +', height='+ inteWindowHeight +', scrollbars=1');
	oPopup.focus();
	
	return false;
}

/*
|----------------------------------------------------------------------------------------------------|
|           Função: ModificarTamanhoDaFonte()                                                        |
|        Descrição: Altera o tamanho da fonte do site.                                               |
|  ================================================================================================  |
|       Parâmetros: nenhum                                                                           |
|           Evento: onclick                                                                          |
|  Tipo de Retorno: booleam                                                                          |
|  ================================================================================================  |
|           Criado: 07/08/2006 | Por: Mauro Willian                                                  |
|       Modificado: __/__/____ | Por:                                                                |
|----------------------------------------------------------------------------------------------------|
*/
var __font_size;
function ModificarTamanhoDaFonte(tamanho)
{
    var font_size = '';
    switch (parseInt(tamanho, 10))
    {
        case 2:
            font_size = '13px';
            break;
        case 3:
            font_size = '15px';
            break;
        default:
            font_size = '11px';
            break;
    }
    __font_size = (document.getElementById('texto').style.fontSize.length > 0) ? document.getElementById('texto').style.fontSize : "11px";
    document.getElementById('texto').style.fontSize = font_size;
    
    if (window.ActiveXObject == null)
    {
        if (parseInt(document.getElementById('conteudo').offsetHeight, 10) < parseInt(document.getElementById('recurso_lateral').offsetHeight, 10))
        {
            AjustarDiv('conteudo', 'texto');
        }
        else
        {
            document.getElementById('conteudo').style.height = '';
            AjustarDiv('conteudo', 'recurso_lateral');
        }
    }
    else
    {
        var oListas = document.getElementsByTagName('ul');
        var oLista;
        
        for (var i = 0; i < oListas.length; i++)
        {
            if (oListas[i].className == 'menu_recursos menu_recursos_bottom')
            {
                oLista = oListas[i];
                i = oListas.length;
            }
        }
        
        if (parseInt(document.getElementById("conteudo").offsetHeight, 10) < parseInt(document.getElementById("recurso_lateral").offsetHeight, 10))
        {
            document.getElementById("conteudo").style.height = document.getElementById("recurso_lateral").offsetHeight + 'px';
        }
        else
        {
            if (parseInt(__font_size.substr(0, __font_size.length-2), 10) > parseInt(font_size.substr(0, font_size.length-2), 10))
                document.getElementById("conteudo").style.height = document.getElementById("recurso_lateral").offsetHeight + 'px';
            else if (parseInt(__font_size.substr(0, __font_size.length-2), 10) < parseInt(font_size.substr(0, font_size.length-2), 10))
                document.getElementById("conteudo").style.height = (parseInt(document.getElementById("conteudo").offsetHeight, 10)-10) + 'px';
            else
                document.getElementById("conteudo").style.height = (parseInt(document.getElementById("conteudo").offsetHeight, 10)-20) + 'px';
        }
        //oLista.style.bottom = '5px';
    }
    
    return false;
}

/*
|----------------------------------------------------------------------------------------------------|
|           Função: Zoom()                                                                           |
|        Descrição: Exibe/esconde a imagem grande                                                    |
|  ================================================================================================  |
|       Parâmetros: id             = id do objeto a ser exibido.                                     |
|                   arquivo_grande = arquivo que será aberto no zoom da imagem.                      |
|                   id_imagem      = id da tag img onde será colocada a imagem grande.               |
|           Evento: onclick                                                                          |
|  Tipo de Retorno: boolean                                                                          |
|  ================================================================================================  |
|           Criado: 18/08/2006 | Por: Flávio Henrique                                                |
|       Modificado: 01/09/2006 | Por: Mauro Willian                                                  |
|----------------------------------------------------------------------------------------------------|
*/
function Zoom(id, arquivo_grande, id_imagem){
    var oImg = document.getElementById(id);
    var oImgGrande = (id_imagem == null || id_imagem == "") ? null : document.getElementById(id_imagem);

    if( oImg.style.visibility != "visible")
        oImg.style.visibility = "visible";
    else
        oImg.style.visibility = "hidden";
    
    if ((arquivo_grande != null && arquivo_grande != "") && oImgGrande != null)
        oImgGrande.src = arquivo_grande;
}

/*
|----------------------------------------------------------------------------------------------------|
|           Função: Request()                                                              |
|        Descrição: Solicita a página via Ajax                                       |
|  ================================================ |
|       Parâmetros: url : string   														|
|           Evento: onclick                                                                  |
|  Tipo de Retorno: string                                                                |
|  ================================================  |
|           Criado: 21/01/2008 | Por: Rafael Une					                |
|----------------------------------------------------------------------------------------------------|
*/
function Request(url_send, class_name)
{
    new Ajax(url_send, {
		method: 'post',
		update: $('update_content'),
		postBody: {pal: $('txtPalavraChave').value}, 
		//evento realizado apos obter uma resposta a solicitação
		onComplete: function() {
			//some com a imagem de carregando
			$('updating').className = 'display_none';
			//chama a função que carrega o css.
			fctCss();
		},
		onFailure: function() {
			//some com a imagem de carregando
			$('updating').className = 'display_none';
		}
	}).request();
	//exibe a imagem de carregando
	$('updating').className = 'ajax_loading_block ' + class_name;
    $$('.ajax_loading_block').setStyles({
        'position':'absolute'
    });
}

/*
|----------------------------------------------------------------------------------------------------|
|           Função: textCaracteres()                                                         |
|        Descrição: Valida a quantidade de caracteres digitados
							num input					                                       |
|  ================================================ |
|       Parâmetros: url : string   														|
|           Evento: onclick                                                                  |
|  Tipo de Retorno: string                                                                |
|  ===============================================  |
|           Criado: 21/01/2008 | Por: Rafael Une					                |
|----------------------------------------------------------------------------------------------------|
*/
function textCaracteres(field, maxlimit) {
	if( $(field).value.length > maxlimit )
		$(field).value = $(field).value.substring(0, maxlimit);
}

//--------------------------------------------------------------------//
// RequestArea()                                                    //
// Carrega a pagina solicitada dentro do elemento		//
// informado															//
// Criado por: Rafael Une				Data: 21/01/2008  //
// Modificado por:                 Em: __/__/____    //
//----------------------------------------------------------------//
function RequestArea(url_send, area_id)
{
	try
	{
		new Ajax(url_send, {
			method: 'get',
			update: $(area_id),
			//evento realizado apos obter  uma resposta a solicitação
			onComplete: function() {
				$(area_id).className = '';
				$(area_id).style.display = 'block';
			},
			onFailure: function() {
				$(area_id).className = '';
			}
		}).request();
		//exibe a imagem de carregando
		$(area_id).className = 'loading_ajax_block';
	}
	catch (er)
	{
	}

}

//--------------------------------------------------------------------//
// Fechar()                                                    //
// Fecha a popup zerando o HTML que está 		//
// dentro do elemento informado						//
// Criado por: Rafael Une				Data: 21/01/2008  //
// Modificado por:                 Em: __/__/____    //
//----------------------------------------------------------------//
function Fechar(area_id)
{
	$(area_id).innerHTML = '';
	$(area_id).style.display = 'none';
}


//--------------------------------------------------------------------//
// Listas()                                                    //
// Move os elementos que estão dentro da lista 		//
// Criado por: Rafael Une				Data: 21/01/2008  //
// Modificado por:                 Em: __/__/____    //
//----------------------------------------------------------------//
function Listas(id_container,id_lista, btn_avancar, btn_voltar)
{
	var oListaItem = 0;
	var oLista = new Fx.Scroll(id_container, {
		wait: false,
		duration: 1250,
		transition: Fx.Transitions.Quad.easeInOut
	});

	/* LISTA */
	$(btn_voltar).addEvent('click', function(e) {
		e = new Event(e).stop();
		if(oListaItem == 0)
			return;

		oListaItem--;

		oLista.toElement($ES('li', id_lista)[oListaItem]);
	});
	$(btn_avancar).addEvent('click', function(e) {
		e = new Event(e).stop();

		if(oListaItem == $ES('li', id_lista).length-1)
				return;

		oListaItem++;

		oLista.toElement($ES('li', id_lista)[oListaItem]);
	});
}

function SubstituirCaracteres(texto)
{
	var caracteresesp=new Array("Á","á","Â","â","À","à","Å","å","Ã","ã","É","é","Ê","ê","È","è","Í","í","Î","î","Ì","ì","Ó","ó","Ô","ô","Ò","ò","Õ","õ","Ú","ú","Û","û","Ù","ù","Ü","ü","Ç","ç");
	var caracteresasc = new Array("&Aacute;","&aacute;","&Acirc;","&acirc;","&Agrave;","&agrave;","&Aring;","&aring;","&Atilde;","&atilde;","&Eacute;","&eacute;","&Ecirc;","&ecirc;","&Egrave;","&egrave;","&Iacute;","&iacute;","&Icirc;","&icirc;","&Igrave;","&igrave;","&Oacute;","&oacute;","&Ocirc;","&ocirc;","&Ograve;","&ograve;","&Uacute;","&uacute;","&Ucirc;","&ucirc;","&Ugrave;","&ugrave;","&Uuml;","&uuml;","&Ccedil;","&ccedil;");

	alert(caracteresesp.length);
	alert(caracteresasc.length);
	for(i=0; i < caracteresesp.length; i++)
	{
		texto = texto.replace(caracteresesp[i], caracteresasc[i]);
	}	

	return texto;
}

//--------------------------------------------------------------------//
// BuscarProdutos()                                                    //
// Função que monta a querystring para realizar a
// busca dos produtos												//
// Criado por: Rafael Une				Data: 24/01/2008  //
// Modificado por:                 Em: __/__/____    //
//----------------------------------------------------------------//

function BuscarProdutos(checkbox_id, text_id, url_request)
{
	if($(checkbox_id) != null)
	{ 
		if($(checkbox_id).checked)
		{
			var url = window.location.toString();
			categoria = fct_lastIndex(url);

			url_request = url_request + "?pid=" + categoria;
		}
		else
		{
			var url = window.location.toString();
			url_request = url_request + "?";
		}
	}
	else
	{
		var url = window.location.toString();
		url_request = url_request + "?";

		var ingc = "";
		var ingnc = "";

		if(classes != null)
		{	
			for(i = 0; i < classes.length; i++)
			{
				if(classes[i] == "op_contem")
					ingc = ingc + ";" + categorias[i];
				if(classes[i] == "op_nao_contem")
					ingnc = ingnc + ";" + categorias[i];
			}
		}
		
		//Request(url_request);
		divbusca = document.getElementById('divBusca');
		debugger;
		if(divbusca != null)
		    divbusca.style.visibility = "hidden";
		    
	   divMenuTopo1 = document.getElementById('kphMenuTop_floatTop');
		if(divMenuTopo1 != null)
		    divMenuTopo1.style.marginTop   = "269px";
		    
		
		fctCss();
		
	}

	url_request = url_request + "&bus=1";

	new Ajax(url_request, {
		method: 'post',
		update: $('update_content'),
		postBody: {pal: $('txtPalavraChave').value, ic: ingc, inc : ingnc}, 
		//evento realizado apos obter uma resposta a solicitação
		onComplete: function() {
			//some com a imagem de carregando
			$('updating').className = 'display_none';
			//chama a função que carrega o css.
			fctCss();
		},
		onFailure: function() {
			//some com a imagem de carregando
			$('updating').className = 'display_none';
		}
	}).request();
	//exibe a imagem de carregando
	$('updating').className = 'ajax_loading_block ';
    $$('.ajax_loading_block').setStyles({
        'position':'absolute'
    });
}

//--------------------------------------------------------------------//
// BuscarReceitas()                                                    //
// Função que monta a querystring para realizar a
// busca das receitas													//
// Criado por: Rafael Une				Data: 24/01/2008  //
// Modificado por:                 Em: __/__/____    //
//----------------------------------------------------------------//
function BuscarReceitas(url_request)
{
	url_request = url_request + "?";

	tipo_receita = "";
	if($("rbNossaReceita").checked)
		tipo_receita = $("rbNossaReceita").value;
	
	if($("rbSuaReceita").checked)
		tipo_receita = $("rbSuaReceita").value;

	if(tipo_receita != "")
		url_request =  url_request + "&tr=" + tipo_receita;

	var categoriacontem = "";
	var categorianaocontem = "";

	if(classes != null)
	{
		for(i = 0; i < classes.length; i++)
		{
			if(classes[i] == "op_contem")
				categoriacontem = categoriacontem + ";" + categorias[i];
			
			if(classes[i] == "op_nao_contem")
				categorianaocontem = categorianaocontem + ";" + categorias[i];
		}
	}


	url_request = url_request + "&bus=1&mv=0";
	new Ajax(url_request, {
		method: 'post',
		update: $('update_content'),
		postBody: {pal: $('txtPalavraChave').value, ord: $("ddlOrdenacao").selectedIndex.toString(), ctc : categoriacontem, ctnc:categorianaocontem }, 
		//evento realizado apos obter uma resposta a solicitação
		onComplete: function() {
			//some com a imagem de carregando
			$('updating').className = 'display_none';
			//chama a função que carrega o css.
			fctCss();
		},
		onFailure: function() {
			//some com a imagem de carregando
			$('updating').className = 'display_none';
		}
	}).request();
	//exibe a imagem de carregando
	$('updating').className = 'ajax_loading_block receitas_area';
    $$('.ajax_loading_block').setStyles({
        'position':'absolute'
    });
}

//--------------------------------------------------------------------//
// fct_lastIndex()                                                    //
// Função que recupera o valor da ultima querystring//
// Criado por: Rafael Une				Data: 24/01/2008  //
// Modificado por:                 Em: __/__/____    //
//----------------------------------------------------------------//
function fct_lastIndex(str_url){
    var arra = str_url.split("=");
    lastindex = arra.length - 1; 

	if(arra.length >= 2)
		return arra[lastindex];
	else
		return null;
}

//--------------------------------------------------------------------//
// ValidarEmail()                                                    //
// Função que valida o formulário de envio de e-mail //
// Criado por: Rafael Une				Data: 28/01/2008  //
// Modificado por:                 Em: __/__/____    //
//----------------------------------------------------------------//
function ValidarEmail()
{
    if(document.getElementById('txtNomeRemetente').value == "")
    {
        alert('Por favor, informe seu nome');
        document.getElementById('txtNomeRemetente').focus();
        return false;
    }
    
    if(document.getElementById('txtEmailRemetente').value == "")
    {
        alert('Por favor, informe seu e-mail')
        document.getElementById('txtEmailRemetente').focus();
        return false;
    }
    else
    {
        if(!document.getElementById('txtEmailRemetente').value.isValidEmail())
        {
            alert('Por favor, informe um e-mail válido')
            document.getElementById('txtEmailRemetente').select();
            return false;
        }
    }
    
    
    if(document.getElementById('txtNomeDestinatario1').value == "")
    {
        alert('Por favor, informe o nome do destinatário');
        document.getElementById('txtNomeDestinatario1').focus();
        return false;
    }
    
    if(document.getElementById('txtEmailDestinatario1').value == "")
    {
        alert('Por favor, informe o e-mail do destinatário');
        document.getElementById('txtEmailDestinatario1').focus();
        return false;
    }
    else
    {
        if(!document.getElementById('txtEmailDestinatario1').value.isValidEmail())
        {
            alert('Por favor, informe um e-mail válido')
            document.getElementById('txtEmailDestinatario1').select();
            return false;
        }
    }
    
   
   if(document.getElementById('txtNomeDestinatario2').value != "" && document.getElementById('txtEmailDestinatario2').value=="")
    {
        alert('Por favor, informe o e-mail do segundo destinatário');
        document.getElementById('txtEmailDestinatario2').focus();
        return false;
    }
    else
    {
        if(document.getElementById('txtNomeDestinatario2').value == "" && document.getElementById('txtEmailDestinatario2').value!="")
        {
            alert('Por favor, informe o nome do segundo destinatário');
            document.getElementById('txtNomeDestinatario2').focus();
            return false;
        }
        else
        {
             if(document.getElementById('txtNomeDestinatario2').value != "" && document.getElementById('txtEmailDestinatario2').value!="")
            {
                
                if(!document.getElementById('txtEmailDestinatario2').value.isValidEmail())
                {
                    alert('Por favor, informe um e-mail válido')
                    document.getElementById('txtEmailDestinatario2').select();
                    return false;
                }
            }
        }
    } 
   
 
  if(document.getElementById('txtNomeDestinatario3').value != "" && document.getElementById('txtEmailDestinatario3').value=="")
    {
        alert('Por favor, informe o e-mail do terceiro destinatário');
        document.getElementById('txtEmailDestinatario3').focus();
        return false;
    }
    else
    {
        if(document.getElementById('txtNomeDestinatario3').value == "" && document.getElementById('txtEmailDestinatario3').value!="")
        {
            alert('Por favor, informe o nome do terceiro destinatário');
            document.getElementById('txtNomeDestinatario3').focus();
            return false;
        }
        else
        {
             if(document.getElementById('txtNomeDestinatario3').value != "" && document.getElementById('txtEmailDestinatario3').value!="")
            {
                
                if(!document.getElementById('txtEmailDestinatario3').value.isValidEmail())
                {
                    alert('Por favor, informe um e-mail válido')
                    document.getElementById('txtEmailDestinatario3').select();
                    return false;
                }
            }
        }
    } 
}

// Criado por Leonard Hofmann
function AcaoJuridicaCheck(id, pos)
{   
    var oObj = document.getElementById(id);     
    var i=0;
    
    for (i=0;i<= 3;i++)
    {
        if(document.getElementById(id) != document.getElementById(id.replace('_'+ pos +'', '_'+ i +'')))
        {
             var oObj = document.getElementById(id.replace('_'+ pos +'', '_'+ i +''));
            oObj.checked = false;
        }
    }    
}